feat():电文信号模拟测试

This commit is contained in:
Allenxy
2025-11-01 18:32:20 +08:00
parent c2e9e15c36
commit 4524e9ef86
8 changed files with 38 additions and 31 deletions

View File

@@ -1,6 +1,5 @@
package com.fizz.business.comm.OPC;
import com.fizz.business.anno.MyLog;
import com.fizz.business.constants.enums.ExitCutTypeEnum;
import com.fizz.business.constants.enums.OpcMessageType;
import com.fizz.business.domain.msg.*;
@@ -10,7 +9,6 @@ import com.kangaroohy.milo.model.ReadWriteEntity;
import com.kangaroohy.milo.service.MiloService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.compress.utils.Lists;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
@@ -122,7 +120,7 @@ public class MessageSubscriptionRunner implements ApplicationRunner {
{
try {
ExitMeasureMessage msg = new ExitMeasureMessage();
writeMessage(msg,exitMoveIds);
writeMessage(msg,exitMeasureIds);
log.info("接收出口称重信号:重量 {} ", msg.getWeight());
logDataService.logInfo("TRACK","接收出口称重信号:重量 {} ", msg.getWeight());
opcReceiverHandler.onMessageReceived(OpcMessageType.EXIT_MEASURE,msg);

View File

@@ -12,7 +12,6 @@ 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.fizz.business.vo.PdiPlanVO;
import com.google.common.collect.Lists;
import lombok.AllArgsConstructor;
import lombok.Getter;
@@ -33,7 +32,7 @@ public enum L1OperateMatEnum implements IEnum<String>, IOperateMat<L1OperateMatF
ONLINE("上线") {
@Override
public void operate(L1OperateMatForm form) {
ONLINE.syncPlanStatus(form.getPlanId());
ONLINE.syncPlanStatus(form.getPlanId(),form.getEntryMatId());
MatmapUtil.setMatmap(form.getPorIdx(), form.getEntryMatId(), form.getPlanId(), form.getPlanNo());
// 钢卷上线时, 缓存工艺规程
// BeanFactory.getBean(RedisCacheManager.class).setCoilSetup(form.getPlanId());
@@ -56,7 +55,7 @@ public enum L1OperateMatEnum implements IEnum<String>, IOperateMat<L1OperateMatF
PRODUCING("生产中") {
@Override
public void operate(L1OperateMatForm form) {
PRODUCING.syncPlanStatus(form.getPlanId());
PRODUCING.syncPlanStatus(form.getPlanId(),form.getEntryMatId());
WebSocketUtil.sendSignalMsg(form);
}
@@ -64,7 +63,7 @@ public enum L1OperateMatEnum implements IEnum<String>, IOperateMat<L1OperateMatF
PRODUCT("生产完成") {
@Override
public void operate(L1OperateMatForm form) {
PRODUCT.syncPlanStatus(form.getPlanId());
PRODUCT.syncPlanStatus(form.getPlanId(),form.getEntryMatId());
WebSocketUtil.sendSignalMsg(form);
}
},
@@ -110,12 +109,13 @@ public enum L1OperateMatEnum implements IEnum<String>, IOperateMat<L1OperateMatF
*
* @param planId 计划id
*/
private void syncPlanStatus(String planId) {
private void syncPlanStatus(String planId, String matId) {
CrmPdiPlanService planClient = BeanFactory.getBean(CrmPdiPlanService.class);
planClient.changeStatus(ChangePlanStatusForm.builder()
.operation(this.name())
.id(planId)
.matId(matId)
.build());
}
}

View File

@@ -2,7 +2,6 @@ package com.fizz.business.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@@ -27,7 +26,7 @@ public class ProMatmap implements Serializable {
private String positionNameCn;
@Schema(description = "计划id")
private Long planId;
private String planId;
@Schema(description = "计划号")
private String planNo;

View File

@@ -1,5 +1,6 @@
package com.fizz.business.service.hanle;
import cn.hutool.json.JSONUtil;
import com.fizz.business.anno.OpcMessageHandlerType;
import com.fizz.business.constants.enums.L1OperateMatEnum;
import com.fizz.business.constants.enums.OpcMessageType;
@@ -33,10 +34,11 @@ public class ExitCutHandler implements OpcMessageHandler<ExitCutMessage> {
MatmapDTO trMatmap = MatmapUtil.getMatmap(TR.getIdx());
if (trMatmap == null) {
log.error("卷取机s.");
log.error("卷取机不存在");
return;
}
log.info("接受到出口剪切信号:{}", JSONUtil.toJsonStr(message));
// 2. 根据剪切类型,生成产出卷信息
ExitCoilInfoDTO exitCoilInfo = pdoExCoilService.genExitCoilInfo(trMatmap, message.getCutType());

View File

@@ -7,26 +7,28 @@ import com.fizz.business.service.CrmPdoExcoilService;
import com.fizz.business.service.OpcMessageHandler;
import com.fizz.business.utils.MatmapUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import static com.fizz.business.constants.enums.DeviceEnum.TR;
import static com.fizz.business.constants.enums.DeviceEnum.WEIGHT;
@Component
@OpcMessageHandlerType(OpcMessageType.EXIT_MEASURE)
@RequiredArgsConstructor
@Slf4j
public class ExitMeasureHandler implements OpcMessageHandler<ExitMeasureMessage> {
private final CrmPdoExcoilService crmPdoExcoilService;
@Override
public void handle(ExitMeasureMessage message) {
System.out.println("处理 EXIT_MEASURE 消息: " + message);
// 1. 获取卷取机 (TR) 上的成品卷号
String exitMatId = MatmapUtil.getMatId(TR.getIdx());
log.info("获取到钢卷称重信息:{}.",message);
String exitMatId = MatmapUtil.getMatId(WEIGHT.getIdx());
if (exitMatId == null) {
System.err.println("TR device has no coil. Cannot process ExitMeasureMessage.");
log.error("TR device has no coil. Cannot process ExitMeasureMessage.");
return;
}

View File

@@ -6,23 +6,28 @@ import com.fizz.business.constants.enums.OpcMessageType;
import com.fizz.business.domain.msg.ExitMovementMessage;
import com.fizz.business.dto.MatmapDTO;
import com.fizz.business.service.OpcMessageHandler;
import com.fizz.business.service.ProMatmapService;
import com.fizz.business.utils.MatmapUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
@Component
@Slf4j
@OpcMessageHandlerType(OpcMessageType.EXIT_MOVEMENT)
@RequiredArgsConstructor
public class ExitMovementHandler implements OpcMessageHandler<ExitMovementMessage> {
@Resource
ProMatmapService proMatmapService;
@Override
public void handle(ExitMovementMessage message) {
System.out.printf("处理 EXIT_MOVEMENT 消息: %d -> %d%n", message.getExSrc(), message.getExDesc());
// 1. 获取源位置的物料信息
int srcIndex = message.getExSrc() -1 ;
int srcIndex = message.getExSrc() ;
MatmapDTO srcMatmap = MatmapUtil.getMatmap(srcIndex);
if (ObjectUtil.isNull(srcMatmap) || ObjectUtil.isNull(srcMatmap.getMatId())) {
@@ -36,9 +41,11 @@ public class ExitMovementHandler implements OpcMessageHandler<ExitMovementMessag
log.info("成功清空源位置 {} 的物料信息。{}", srcIndex,srcMatmap.getMatId());
// 3. 将物料信息设置到目标位置
int destIndex = message.getExDesc() - 1;
int destIndex = message.getExDesc();
MatmapUtil.setMatmap(destIndex, srcMatmap.getMatId(), srcMatmap.getPlanId(), srcMatmap.getPlanNo());
log.info("成功设置目标位置 {} 的物料信息为钢卷 {}", destIndex, srcMatmap.getMatId());
proMatmapService.flushMatmap();
}

View File

@@ -4,7 +4,6 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fizz.business.domain.CrmPdoExcoil;
import com.fizz.business.domain.PdoExcoil;
import com.fizz.business.form.CrmPdoExcoilForm;
import com.fizz.business.mapper.CrmPdoExcoilMapper;
import com.fizz.business.service.CrmPdoExcoilService;
@@ -32,7 +31,7 @@ public class CrmPdoExcoilServiceImpl extends ServiceImpl<CrmPdoExcoilMapper, Crm
*/
public CrmPdoExcoil getByExcoilId(String excoilid) {
QueryWrapper<CrmPdoExcoil> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("exit_coilid", excoilid);
queryWrapper.eq("exit_mat_id", excoilid);
return this.getOne(queryWrapper);
}

View File

@@ -2,9 +2,7 @@ package com.fizz.business.service.impl;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.fizz.business.constants.enums.ExitCutTypeEnum;
import com.fizz.business.domain.PdoExcoil;
import com.fizz.business.dto.ExitCoilInfoDTO;
import com.fizz.business.dto.MatmapDTO;
import com.fizz.business.dto.PdoExCoilDTO;
@@ -109,12 +107,14 @@ public class PdoExCoilServiceImpl implements PdoExCoilService {
* 半卷回退上报产出
* 1. 头部卷产出时原料卷号A01, 产出卷号: A01-1, 分卷标识: true, 尾卷标识: false
* 2. 尾部卷产出时原料卷号A01产出卷号: A01-2
*
* @param trMatmap
* @param cutType
* @return ExitCoilInfoDTO
*/
@Override
public ExitCoilInfoDTO genExitCoilInfo(MatmapDTO trMatmap, ExitCutTypeEnum cutType) {
log.info("触发出口分卷信号:{},剪切类型为:{}",trMatmap,cutType);
String trCoilId = trMatmap.getMatId();
//准备的成品子卷号
//考虑依据数据库记录分卷,避免因为平台重启导致分卷丢失或错误
@@ -149,6 +149,6 @@ public class PdoExCoilServiceImpl implements PdoExCoilService {
@Override
public void deleteExistPdo(String coilId, String planId) {
crmPdoExcoilService.deleteCrmPdoExcoil(coilId,planId);
crmPdoExcoilService.deleteCrmPdoExcoil(coilId, planId);
}
}