日志优化+PRODUCING到PRODUCT状态转化优化

This commit is contained in:
2026-01-21 14:29:12 +08:00
parent 53e4635506
commit 675dd43262
5 changed files with 66 additions and 31 deletions

View File

@@ -122,10 +122,14 @@ public enum L1OperateMatEnum implements IEnum<String>, IOperateMat<L1OperateMatF
private void syncPlanStatus(String planId, String matId) {
CrmPdiPlanService planClient = BeanFactory.getBean(CrmPdiPlanService.class);
planClient.changeStatus(ChangePlanStatusForm.builder()
boolean ok = planClient.changeStatus(ChangePlanStatusForm.builder()
.operation(this.name())
.id(planId)
.matId(matId)
.build());
if (!ok) {
throw new IllegalStateException(String.format("计划状态同步失败, operation=%s, planId=%s, matId=%s", this.name(), planId, matId));
}
}
}

View File

@@ -28,7 +28,7 @@ public interface CrmPdiPlanService extends IService<CrmPdiPlan> {
*/
CrmPdiPlan getFirstUnProducedCoil();
void changeStatus(ChangePlanStatusForm build);
boolean changeStatus(ChangePlanStatusForm build);
/**
* 获取当前正在线上的钢卷优先级ONLINE > PRODUCING > READY/NEW

View File

@@ -38,7 +38,8 @@ public class ExitCutHandler implements OpcMessageHandler<ExitCutMessage> {
MatmapDTO trMatmap = MatmapUtil.getMatmap(TR.getIdx());
if (trMatmap == null) {
log.error("卷取机不存在");
com.fizz.business.service.impl.BeanFactory.getBean(com.fizz.business.service.LogDataService.class)
.logInfo("EXIT_CUT", "卷取机不存在");
return;
}
@@ -60,6 +61,7 @@ public class ExitCutHandler implements OpcMessageHandler<ExitCutMessage> {
.planId(trMatmap.getPlanId())
.operation(L1OperateMatEnum.PRODUCT)
.build());
}
log.info("成功处理 EXIT_CUT 消息,已保存成品卷: " + exitCoilInfo.getExitMatId());

View File

@@ -10,6 +10,7 @@ import com.fizz.business.form.ChangePlanStatusForm;
import com.fizz.business.form.PlanQueryForm;
import com.fizz.business.mapper.CrmPdiPlanMapper;
import com.fizz.business.service.CrmPdiPlanService;
import com.fizz.business.service.LogDataService;
import com.fizz.business.vo.CrmPdiPlanVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@@ -21,6 +22,9 @@ import java.util.List;
@Service
public class CrmPdiPlanServiceImpl extends ServiceImpl<CrmPdiPlanMapper, CrmPdiPlan> implements CrmPdiPlanService {
@javax.annotation.Resource
private LogDataService logDataService;
/**
* 根据卷ID和操作员ID查询单个记录
@@ -150,23 +154,53 @@ public class CrmPdiPlanServiceImpl extends ServiceImpl<CrmPdiPlanMapper, CrmPdiP
}
@Override
public void changeStatus(ChangePlanStatusForm build) {
public boolean changeStatus(ChangePlanStatusForm build) {
if (build == null) {
if (logDataService != null) {
logDataService.logInfo("PLAN", "changeStatus 参数为空");
}
return false;
}
QueryWrapper<CrmPdiPlan> wrapper = new QueryWrapper<>();
if (StrUtil.isBlank(build.getMatId())) {
if (logDataService != null) {
logDataService.logInfo("PLAN", "changeStatus matId为空, planId={}, operation={}", build.getId(), build.getOperation());
}
return false;
}
wrapper.eq("coilid", build.getMatId());
wrapper.eq("planid", build.getId());
// planId 非空时matId + planId 精确匹配
// planId 为空时:仅用 matId 匹配coilid 唯一)
if (StrUtil.isNotBlank(build.getId())) {
wrapper.eq("planid", build.getId());
}
CrmPdiPlan pdiPlan = baseMapper.selectOne(wrapper);
if (pdiPlan == null) {
log.error("未找到ID为{}的计划记录", build.getId());
return;
if (logDataService != null) {
logDataService.logInfo("PLAN", "未找到计划记录, matId={}, planId={}, operation={}", build.getMatId(), build.getId(), build.getOperation());
}
return false;
}
pdiPlan.setStatus(build.getOperation());
baseMapper.updateById(pdiPlan);
log.info("计划状态更新成功ID: {}, 新状态: {}", build.getId(), build.getOperation());
int rows = baseMapper.updateById(pdiPlan);
if (rows <= 0) {
if (logDataService != null) {
logDataService.logInfo("PLAN", "计划状态更新失败, matId={}, planId={}, operation={}", build.getMatId(), build.getId(), build.getOperation());
}
return false;
}
log.info("计划状态更新成功, matId={}, planId={}, 新状态={}", build.getMatId(), build.getId(), build.getOperation());
return true;
}
/**

View File

@@ -79,7 +79,7 @@ public class SegmentTrackerService {
try {
trackCoilHeadPosition(coilId, entryLengthAtWelder, entry, exit);
} catch (Exception e) {
logDataService.logInfo("ERROR","coidId="+coilId+", e="+ e);
logDataService.logInfo("TRACK", "trackCoilHeadPosition异常, coilId={}, err={}", coilId, String.valueOf(e));
}
Long lastTime = lastLogTimeMap.get(coilId);
@@ -105,8 +105,7 @@ public class SegmentTrackerService {
Long lastTime1 = lastNewCoilLogTimeMap.get(coilId);
if (lastTime1 == null || now1 - lastTime1 > intervalTime) {
lastNewCoilLogTimeMap.put(coilId, now1);
log.info("WELDER检测到新钢卷或初始化 -> CoilId: {}", coilId);
logDataService.logInfo("WELDER", "Detected new coil or initialized -> CoilId: " + coilId);
logDataService.logInfo("WELDER", "检测到新钢卷或初始化, CoilId={}", coilId);
}
} else {
weldDev = entryLengthAtWelder.subtract(weldLength);
@@ -129,8 +128,7 @@ public class SegmentTrackerService {
// 5. 完成日志
log.info("TRACK-END】CoilId: {}, 当前长度: {}, 已生成段数: {}", coilId, entryLengthAtWelder, coilSegNum);
logDataService.logInfo("TRACK", "Process completed -> CoilId: " + coilId + ", CurrentLength: " + entryLengthAtWelder + ", SegmentCount: " + coilSegNum);
logDataService.logInfo("TRACK", "处理完成, CoilId={}, 当前长度={}, 已生成段数={}", coilId, entryLengthAtWelder, coilSegNum);
}
@@ -146,7 +144,7 @@ public class SegmentTrackerService {
BigDecimal weldDev) {
if (listSegment.isEmpty()) {
// === 【处理开始日志】===
log.warn("TRACK-TREAT】,listSegment为空直接返回");
logDataService.logWarn("TRACK", "treatSeg: listSegment为空直接返回, coilSegNum={}", coilSegNum);
return;
}
@@ -157,8 +155,7 @@ public class SegmentTrackerService {
// payOffReelNumber=1/2 代表当前跟踪的是哪一路开卷机入口。
// 这里做保护,避免 entry 为空或值异常导致误写 matmap。
// === 【处理开始日志】===
log.info("TRACK-TREAT】开始处理段数据共 {} 段,weldDev={}celLength = {}cxlLength = {}。 ", listSegment.size(), weldDev, celLength, cxlLength);
logDataService.logInfo("TRACK", "Start processing segments: count=" + listSegment.size() + ", weldDev=" + weldDev);
logDataService.logInfo("TRACK", "开始处理段数据, count={}, weldDev={}, celLength={}, cxlLength={}", listSegment.size(), weldDev, celLength, cxlLength);
Iterator<SegmentDTO> iterator = listSegment.descendingIterator();
while (iterator.hasNext()) {
@@ -184,14 +181,12 @@ public class SegmentTrackerService {
if (segment.getHeadPos().compareTo(BigDecimal.valueOf(currentDevicePos)) > 0 &&
segment.getTailPos().compareTo(BigDecimal.valueOf(currentDevicePos)) < 0) {
log.info("【TRACK-TREAT】段 {} 进入设备区域 [{}],当前设备长度:{}", segment.getSegNo(), device.name(), currentDevicePos);
logDataService.logInfo("TRACK",
"Segment " + segment.getSegNo() + " entered device area [" + device.name() + "], devicePos=" + currentDevicePos);
"段进入设备区域, segNo={}, device={}, devicePos={}", segment.getSegNo(), device.name(), currentDevicePos);
double currentSpeed = getSpeedForDevice(device, entry, coat, exit);
if (currentSpeed > LOWSPEEDLIMIT) {
log.info("【TRACK-TREAT】段 {} 速度大于基准速度, 进入设备区域 [{}],当前速度:{}", segment.getSegNo(), device.name(), currentSpeed);
logDataService.logInfo("TRACK",
"Segment " + segment.getSegNo() + " entered device area [" + device.name() + "], speed=" + currentSpeed);
"段速度满足条件并进入设备区域, segNo={}, device={}, speed={}", segment.getSegNo(), device.name(), currentSpeed);
for (String fieldName : device.getParamFields()) {
Object message = getMessageForDevice(device, entry, furnace, coat, exit);
if (message != null) {
@@ -206,10 +201,9 @@ public class SegmentTrackerService {
double exitPlantPos = stripPositionService.calculate(DeviceEnum.TR, celLength, cxlLength);
if (segment.getTailPos().compareTo(BigDecimal.valueOf(exitPlantPos)) >= 0) {
log.info("【TRACK-END】钢卷 {} 的段号 {} 已离开产线,开始持久化数据{}。",
segment.getEnCoilID(), segment.getSegNo(), JSONUtil.toJsonStr(segment.getTotalValues()));
logDataService.logInfo("SEGMENT",
"Coil " + segment.getEnCoilID() + " segment " + segment.getSegNo() + " left the line, start persisting data.");
"段离开产线并开始持久化, coilId={}, segNo={}, values={}",
segment.getEnCoilID(), segment.getSegNo(), JSONUtil.toJsonStr(segment.getTotalValues()));
segmentService.saveTotalSegment(segment); // 调用服务进行持久化
iterator.remove();
}
@@ -368,16 +362,15 @@ public class SegmentTrackerService {
public void trackCoilHeadPosition(String coilId, BigDecimal headPos,
AppMeasureEntryMessage entry, AppMeasureExitMessage exit) {
log.warn(">>> trackCoilHeadPosition 当前线程{}", Thread.currentThread().getName());
logDataService.logInfo("MATMAP-TRACK", "trackCoilHeadPosition 当前线程={}", Thread.currentThread().getName());
if (LogRateLimiter.shouldLog("TRACK:" + coilId, 5000)) {
log.info("焊缝位置匹配逻辑,当前焊缝长度{}", headPos);
logDataService.logInfo("MATMAP-TRACK", "CoilId=" + coilId + "Weld position matching logic, current weld length ="+headPos);
logDataService.logInfo("MATMAP-TRACK", "焊缝位置匹配逻辑, coilId={}, weldLen={}", coilId, headPos);
}
Integer payOffReelNumber = entry != null ? entry.getPayOffReelNumber() : null;
if (payOffReelNumber == null || payOffReelNumber < 1) {
log.warn("trackCoilHeadPosition: invalid payOffReelNumber={}, coilId={}", payOffReelNumber, coilId);
logDataService.logWarn("MATMAP-TRACK", "trackCoilHeadPosition: invalid payOffReelNumber={}, coilId={}", payOffReelNumber, coilId);
return;
}
@@ -394,7 +387,9 @@ public class SegmentTrackerService {
for (DeviceEnum d : DeviceEnum.values()) {
double dynPos = stripPositionService.calculate(d, celLength, cxlLength);
log.info("焊缝位置匹配逻辑,当前焊缝长度{},当前计算的设备长度:{}", headPos, dynPos);
if (LogRateLimiter.shouldLog("TRACK:DYNPOS:" + coilId, 5000)) {
logDataService.logInfo("MATMAP-TRACK", "焊缝位置匹配, coilId={}, headPos={}, device={}, dynPos={}", coilId, headPos, d.name(), dynPos);
}
boolean positionReached = headPos.compareTo(BigDecimal.valueOf(dynPos)) >= 0;
@@ -404,8 +399,8 @@ public class SegmentTrackerService {
if (d == DeviceEnum.WELDER && entry != null && entry.getStripSpeed() != null) {
if (entry.getStripSpeed().doubleValue() > LOWSPEEDLIMIT) {
welderIsMoving = true;
log.info("【WELDER-SPEED-TRIGGER】CoilId: {}, Speed: {} > {}, 触发状态变更",
coilId, entry.getStripSpeed().doubleValue(), LOWSPEEDLIMIT);
logDataService.logInfo("MATMAP-TRACK", "WELDER速度触发状态变更, coilId={}, speed={}, limit={}",
coilId, entry.getStripSpeed().doubleValue(), LOWSPEEDLIMIT);
}
}