二级代码修复

This commit is contained in:
2025-12-18 09:45:25 +08:00
parent aeed29dbca
commit af941c2fd4
9 changed files with 73 additions and 47 deletions

View File

@@ -5,28 +5,31 @@ import com.baomidou.mybatisplus.annotation.IEnum;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import com.fizz.business.form.ChangePlanStatusForm;
import com.fizz.business.constants.enums.PlanStatusEnum;
import com.fizz.business.form.L1OperateMatForm;
import com.fizz.business.service.CrmPdiPlanService;
import com.fizz.business.comm.OPC.OpcMessageSend;
import com.fizz.business.service.TrackService;
import com.fizz.business.service.client.RedisCacheManager;
import com.fizz.business.service.impl.BeanFactory;
import com.fizz.business.utils.MatmapUtil;
import com.fizz.business.utils.WebSocketUtil;
import com.fizz.business.vo.CrmPdiPlanVO;
import com.google.common.collect.Lists;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
/**
* 钢卷操作
*
* @author chenhao
* @date 2023/04/24
*/
@Slf4j
@Getter
@AllArgsConstructor
public enum L1OperateMatEnum implements IEnum<String>, IOperateMat<L1OperateMatForm> {
@@ -56,15 +59,13 @@ public enum L1OperateMatEnum implements IEnum<String>, IOperateMat<L1OperateMatF
PRODUCING("生产中") {
@Override
public void operate(L1OperateMatForm form) {
PRODUCING.syncPlanStatus(form.getPlanId(),form.getEntryMatId());
// L1 指令将计划置为 PRODUCING 时,写入钢卷号到 OPC
try {
if (form.getEntryMatId() != null) {
BeanFactory.getBean(OpcMessageSend.class).sendCoilId(form.getEntryMatId());
}
} catch (Exception e) {
log.error("写入 OPC coilId 失败, coilId={}", form.getEntryMatId(), e);
}
WebSocketUtil.sendSignalMsg(form);
}
@@ -72,6 +73,8 @@ public enum L1OperateMatEnum implements IEnum<String>, IOperateMat<L1OperateMatF
PRODUCT("生产完成") {
@Override
public void operate(L1OperateMatForm form) {
log.error("==================================================================");
log.error("form.planId={},entryMatId={}", form.getPlanId(), form.getEntryMatId());
PRODUCT.syncPlanStatus(form.getPlanId(),form.getEntryMatId());
WebSocketUtil.sendSignalMsg(form);
}

View File

@@ -110,7 +110,6 @@ public enum WebOperateMatEnum implements IEnum<String>, IOperateMat<WebOperateMa
@Override
public void operate(WebOperateMatForm form) {
PRODUCING.syncPlanStatus(form.getPlanId(), form.getEntryMatId());
;
WebSocketUtil.sendSignalMsg(form);
}
},

View File

@@ -41,22 +41,27 @@ public class AppMeasureHandler implements OpcMessageHandler<AppMeasureMessage> {
WebSocketUtil.sendMeasureMsg(message);
BigDecimal lengthAtWelder = entry == null || entry.getStripLocation() == null ? BigDecimal.ZERO : entry.getStripLocation();
// 处理钢卷ID为空的情况
String coilId ="";
if (entry != null && entry.getEntryCoilId() != null){
coilId = entry.getEntryCoilId();
}else {
MatmapDTO matmapDTO =getCurrentRunningCoilId(entry);
coilId = matmapDTO.getMatId();
// if (entry != null && entry.getEntryCoilId() != null){
// coilId = entry.getEntryCoilId();
//
// }else {
if (entry != null) {
log.error("entry{}",entry.getPayOffReelNumber());
}
MatmapDTO matmapDTO =getCurrentRunningCoilId(entry);
coilId = matmapDTO.getMatId();
// }
if (StringUtils.isEmpty(coilId) || "".equals(coilId)){
log.error("钢卷号为空,无法执行焊缝跟踪!!!!!!");
return;
}
BigDecimal lengthAtWelder = entry == null || entry.getStripLocation() == null ? BigDecimal.ZERO : entry.getStripLocation();
// 每10次请求输出一次日志
int count = LOG_COUNTER.incrementAndGet();
@@ -64,6 +69,7 @@ public class AppMeasureHandler implements OpcMessageHandler<AppMeasureMessage> {
logDataService.logInfo("WELDER",
"接收到钢卷焊缝跟踪信号:当前焊缝长度 lengthAtWelder{} 当前钢卷信息 coilId{}",
lengthAtWelder, coilId);
}
// 核心逻辑处理
@@ -85,7 +91,7 @@ public class AppMeasureHandler implements OpcMessageHandler<AppMeasureMessage> {
private MatmapDTO getCurrentRunningCoilId(AppMeasureEntryMessage entry) {
return MatmapUtil.getMatmap(entry.getPayOffReelNumber());
return MatmapUtil.getMatmap(entry.getPayOffReelNumber()-1);
}
}

View File

@@ -44,7 +44,7 @@ public class EntryMovementHandler implements OpcMessageHandler<EntryMovementMess
if (action.contains("上卷")) {
CrmPdiPlan coilPlan = crmPdiPlanService.getFirstUnProducedCoil();
if (coilPlan != null) {
log.info("获取到未生产的钢卷: " + coilPlan.getCoilid());
log.info("获取到未生产的钢卷号={} " ,coilPlan.getCoilid());
trackService.l1OperateMat(L1OperateMatForm.builder()
.entryMatId(coilPlan.getCoilid())
.operation(L1OperateMatEnum.ONLINE)
@@ -87,4 +87,4 @@ public class EntryMovementHandler implements OpcMessageHandler<EntryMovementMess
}
return null;
}
}
}

View File

@@ -36,11 +36,11 @@ public class LogDataServiceImpl extends ServiceImpl<LogDataMapper, LogData> impl
LambdaQueryChainWrapper<LogData> lambdaQuery = lambdaQuery();
if(ObjectUtil.isNotEmpty(logDataForm.getStartTime())){
if (ObjectUtil.isNotEmpty(logDataForm.getStartTime())) {
LocalDateTime start = LocalDateTime.of(logDataForm.getStartTime().toLocalDate(), LocalTime.MIN);
lambdaQuery.ge(LogData::getTimestamp, start);
}
if(ObjectUtil.isNotEmpty(logDataForm.getEndTime())){
if (ObjectUtil.isNotEmpty(logDataForm.getEndTime())) {
LocalDateTime end = LocalDateTime.of(logDataForm.getEndTime().toLocalDate(), LocalTime.MAX);
lambdaQuery.le(LogData::getTimestamp, end);
}
@@ -69,17 +69,21 @@ public class LogDataServiceImpl extends ServiceImpl<LogDataMapper, LogData> impl
@Override
public void alarmAck(Integer seqid) {
lambdaUpdate()
.set(LogData::getConfirmTime, new Date())
.eq(LogData::getSeqid, seqid)
.update();
.set(LogData::getConfirmTime, new Date())
.eq(LogData::getSeqid, seqid)
.update();
}
@Override
public void logInfo(String module, String content, Object... args) {
if (args.length > 0) {
content = formatMessage(content, args);
try {
if (args.length > 0) {
content = formatMessage(content, args);
}
saveLogData("INFORMATION", module, content);
} catch (Exception e) {
log.error("没存进去,没事,{}",e);
}
saveLogData("INFORMATION",module, content);
}
@Override
@@ -87,9 +91,10 @@ public class LogDataServiceImpl extends ServiceImpl<LogDataMapper, LogData> impl
if (args.length > 0) {
content = formatMessage(content, args);
}
saveLogData("WARN",module, content);
saveLogData("WARN", module, content);
}
private void saveLogData(String logType,String module, String content){
private void saveLogData(String logType, String module, String content) {
LogData logData = new LogData();
logData.setModule(module);//设置模块名称
logData.setLogtext(content);//设置日志内容
@@ -130,4 +135,4 @@ public class LogDataServiceImpl extends ServiceImpl<LogDataMapper, LogData> impl
return sb.toString();
}
}
}

View File

@@ -120,7 +120,7 @@ public class PdoExCoilServiceImpl implements PdoExCoilService {
//准备的成品子卷号
//考虑依据数据库记录分卷,避免因为平台重启导致分卷丢失或错误
Long subNum = crmPdoExcoilService.getNumber(trCoilId
, trMatmap.getPlanNo(),
, trMatmap.getPlanId(),
0);
CrmPdiPlanVO plan = crmPdiPlanService.getByCoilIdAndOperId(trMatmap.getMatId());

View File

@@ -95,7 +95,7 @@ public class TrackServiceImpl implements TrackService {
.planId(Long.valueOf(matmap.getPlanId()))
.build();
}
String returnType = null;
double returnWt = 0;
if (Objects.equals(planVO.getStatus(), PlanStatusEnum.PRODUCING.name())) {
@@ -171,13 +171,15 @@ public class TrackServiceImpl implements TrackService {
Integer currPosIdx = currDevice.getIdx();
MatmapDTO target = MatmapUtil.getMatmap(targetPosIdx);
MatmapDTO curr = MatmapUtil.getMatmap(currPosIdx);
if (curr == null || target == null) {
log.warn("Matmap is null - curr: {}, target: {}, currPosIdx: {}, targetPosIdx: {}",
log.warn("Matmap is null - curr: {}, target: {}, currPosIdx: {}, targetPosIdx: {}",
curr, target, currPosIdx, targetPosIdx);
return;
}
if (Objects.equals(curr.getMatId(), target.getMatId())) {
return;
}
@@ -261,13 +263,13 @@ public class TrackServiceImpl implements TrackService {
log.warn("CoilPosition not found in Redis, creating empty position");
position = new CoilPositionDTO();
}
List<MatmapDTO> matmapList = redisCacheManager.getMatmapList();
if (matmapList == null) {
log.warn("MatmapList not found in Redis, using empty list");
matmapList = new ArrayList<>();
}
position.setMatMapList(matmapList);
return position;
}

View File

@@ -73,12 +73,21 @@ public class SegmentTrackerService {
AppMeasureExitMessage exit) {
long now = System.currentTimeMillis();
try {
log.warn(">>> trackCoilHeadPosition start, thread: {}, coilId: {}", Thread.currentThread().getName(), coilId);
trackCoilHeadPosition(coilId, entryLengthAtWelder, entry, exit);
} catch (Exception e) {
log.error("trackCoilHeadPosition 执行异常coilId=" + coilId, e);
}
Long lastTime = lastLogTimeMap.get(coilId);
if (lastTime == null || now - lastTime > intervalTime) {
lastLogTimeMap.put(coilId, now);
log.info("【TRACK-START】接收到测量数据 -> CoilId: {}, LengthAtWelder: {}", coilId, entryLengthAtWelder);
logDataService.logInfo("WELDER", "接收到测量数据 -> CoilId: " + coilId + ", LengthAtWelder: " + entryLengthAtWelder);
}
// 4. trackCoilHeadPosition 同步执行
// 1. 新卷或首次测量初始化
BigDecimal weldDev;
@@ -117,13 +126,6 @@ public class SegmentTrackerService {
// 3. 更新已有段
treatSeg(entry, furnace, coat, exit, weldDev);
// 4. trackCoilHeadPosition 同步执行
try {
log.warn(">>> trackCoilHeadPosition start, thread: {}, coilId: {}", Thread.currentThread().getName(), coilId);
trackCoilHeadPosition(coilId, entryLengthAtWelder, entry, exit);
} catch (Exception e) {
log.error("trackCoilHeadPosition 执行异常coilId=" + coilId, e);
}
// 5. 完成日志
log.info("【TRACK-END】CoilId: {}, 当前长度: {}, 已生成段数: {}", coilId, entryLengthAtWelder, coilSegNum);
@@ -343,6 +345,11 @@ public class SegmentTrackerService {
Set<DeviceEnum> prevReached = coilReachedDevices.computeIfAbsent(coilId,
k -> Collections.newSetFromMap(new ConcurrentHashMap<>()));
if (entry.getPayOffReelNumber()-1 == DeviceEnum.POR1.getIdx()) {
prevReached.remove(DeviceEnum.POR2);
} else {
prevReached.remove(DeviceEnum.POR1);
}
if (LogRateLimiter.shouldLog("TRACK:" + coilId, 5000)) {
logDataService.logInfo("MATMAP-TRACK", "构建的本地matmap缓存为=" + JSONUtil.toJsonStr(prevReached) + " ...");
@@ -357,9 +364,12 @@ public class SegmentTrackerService {
if (headPos.compareTo(BigDecimal.valueOf(dynPos)) >= 0 && !prevReached.contains(d)) {
MatmapDTO matmap = MatmapUtil.getMatmap(entry.getPayOffReelNumber()-1);
MatmapUtil.setMatId(d.getIdx(), coilId,matmap.getPlanId());
if (d == DeviceEnum.WELDER) {
logDataService.logInfo("MATMAP-TRACK", "钢卷到达焊机更新钢卷计划状态coil=" + coilId + "当前长度为:" + headPos);
MatmapDTO matmap = MatmapUtil.getMatmap(DeviceEnum.WELDER.getIdx());
log.info("matmap.planid={},coilid={}", matmap.getPlanId(), coilId);
trackService.l1OperateMat(L1OperateMatForm.builder()
.entryMatId(coilId)
.planId(matmap.getPlanId())
@@ -368,7 +378,6 @@ public class SegmentTrackerService {
.build());
} else {
logDataService.logInfo("MATMAP-TRACK", "钢卷:" + coilId + "到达设备:" + d.getDesc() + "当前长度为:" + headPos);
MatmapUtil.setMatId(d.getIdx(), coilId);
proMatmapService.flushMatmap();
WebSocketUtil.sendMatmapMsg();
}
@@ -381,4 +390,4 @@ public class SegmentTrackerService {
}
}

View File

@@ -69,15 +69,17 @@ public class MatmapUtil {
return Objects.nonNull(matmap) && Objects.nonNull(matmap.getMatId());
}
public static void setMatId(int index, String matId) {
public static void setMatId(int index, String matId, String planId) {
MatmapDTO matmap = getMatmap(index);
if (ObjectUtil.isNull(matmap)) {
return;
}
matmap.setPosIdx(index);
matmap.setMatId(matId);
matmap.setPlanId(planId);
log.info("钢卷焊缝跟踪matId{}位置id{}",matId,index);
logDataService.logInfo("MATMAP-SAVE","钢卷焊缝跟踪matId"+matId+"位置id"+index);
logDataService.logInfo("MATMAP-SAVE","钢卷焊缝跟踪matId"+matId+"位置id"+index,"planId="+planId);
redisCacheManager.setMatmap(index, matmap);
}