Browse Source

编写退火上下料启动读码逻辑

zhifei 1 year ago
parent
commit
536d0cdd1f

+ 3 - 3
warewms-framework/src/main/java/com/warewms/framework/config/CreateAndUpdateMetaObjectHandler.java

@@ -49,9 +49,9 @@ public class CreateAndUpdateMetaObjectHandler implements MetaObjectHandler {
                 Date current = new Date();
                 // 更新时间填充(不管为不为空)
                 baseEntity.setUpdateTime(current);
-                String username = SecurityUtils.getUsername();
-                // 当前已登录 更新人填充(不管为不为空)
-                if (StringUtils.isNotBlank(username)) {
+                // 当前已登录 更新人填充(为空进行填充)
+                if (StringUtils.isBlank(baseEntity.getUpdateBy())) {
+                    String username = SecurityUtils.getUsername();
                     baseEntity.setUpdateBy(username);
                 }
             }

+ 31 - 4
warewms-system/src/main/java/com/warewms/hailiang/connect/CodeReader13Connect.java

@@ -2,8 +2,12 @@ package com.warewms.hailiang.connect;
 
 import cn.hutool.extra.spring.SpringUtil;
 import com.github.rholder.retry.*;
+import com.warewms.hailiang.config.CodeReadProperties;
 import com.warewms.hailiang.connect.base.TCPConnectBase;
 import com.warewms.hailiang.domain.Device;
+import com.warewms.hailiang.domain.DeviceLog;
+import com.warewms.hailiang.domain.RetroactiveNow;
+import com.warewms.hailiang.service.RetroactiveNowService;
 import io.netty.bootstrap.Bootstrap;
 import io.netty.buffer.ByteBuf;
 import io.netty.channel.*;
@@ -25,7 +29,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
  * Date: 2023/8/9
  * Time: 15:45
  * To change this template use File | Settings | File Templates.
- * Description:倒角读码器连接
+ * Description:退火读码器连接
  **/
 @Slf4j
 public class CodeReader13Connect implements TCPConnectBase {
@@ -36,7 +40,7 @@ public class CodeReader13Connect implements TCPConnectBase {
 
     private final String deviceName ="CodeReader13";
 
-    private boolean enable = false;
+    private boolean enable = true;
 
     private ChannelFuture future;
 
@@ -46,6 +50,12 @@ public class CodeReader13Connect implements TCPConnectBase {
 
     private ChannelPipeline pipeline;
 
+    private RetroactiveNowService retroactiveNowService;
+
+    {
+        retroactiveNowService = SpringUtil.getBean(RetroactiveNowService.class);
+    }
+
     @Override
     public void init() throws InterruptedException {
         if (enable) {
@@ -137,11 +147,28 @@ public class CodeReader13Connect implements TCPConnectBase {
 
     @Override
     public ChannelPipeline getChannel() {
-        return null;
+        return pipeline;
     }
 
     @Override
     public void processMessages(String message) {
-
+        try {
+            log.info("退火上料读码器消息:{}", message);
+            if (CodeReadProperties.failureReturnInstruction.equals(message)) {
+                SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_TuiHuoShangLiao_DMQ-1-27.13", deviceName, "未识别到码", "2"));
+            } else {
+                //读取到批次号保存到数据库中
+                RetroactiveNow retroactiveNow = new RetroactiveNow();
+                retroactiveNow.setLotNo(message);
+                retroactiveNow.setStatus("6");
+                retroactiveNow.setDeviceId("Z1_TuiHuoShangLiao_DMQ-1-27.13");
+                retroactiveNowService.updateData(retroactiveNow);
+                //添加设备日志
+                SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_TuiHuoShangLiao_DMQ-1-27.13", deviceName, "识别到码:" + message, "1"));
+            }
+        }catch (Exception e){
+            log.error("退火上料读码任务执行异常,msg:{}",e.getMessage());
+            SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_TuiHuoShangLiao_DMQ-1-27.13", deviceName, "读码任务出错,msg:"+e.getMessage(), "2"));
+        }
     }
 }

+ 30 - 4
warewms-system/src/main/java/com/warewms/hailiang/connect/CodeReader14Connect.java

@@ -2,8 +2,12 @@ package com.warewms.hailiang.connect;
 
 import cn.hutool.extra.spring.SpringUtil;
 import com.github.rholder.retry.*;
+import com.warewms.hailiang.config.CodeReadProperties;
 import com.warewms.hailiang.connect.base.TCPConnectBase;
 import com.warewms.hailiang.domain.Device;
+import com.warewms.hailiang.domain.DeviceLog;
+import com.warewms.hailiang.domain.RetroactiveNow;
+import com.warewms.hailiang.service.RetroactiveNowService;
 import io.netty.bootstrap.Bootstrap;
 import io.netty.buffer.ByteBuf;
 import io.netty.channel.*;
@@ -25,7 +29,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
  * Date: 2023/8/9
  * Time: 15:45
  * To change this template use File | Settings | File Templates.
- * Description:倒角读码器连接
+ * Description:退火读码器连接
  **/
 @Slf4j
 public class CodeReader14Connect implements TCPConnectBase {
@@ -36,7 +40,7 @@ public class CodeReader14Connect implements TCPConnectBase {
 
     private final String deviceName ="CodeReader14";
 
-    private boolean enable = false;
+    private boolean enable = true;
 
     private ChannelFuture future;
 
@@ -46,6 +50,11 @@ public class CodeReader14Connect implements TCPConnectBase {
 
     private ChannelPipeline pipeline;
 
+    private RetroactiveNowService retroactiveNowService;
+
+    {
+        retroactiveNowService = SpringUtil.getBean(RetroactiveNowService.class);
+    }
     @Override
     public void init() throws InterruptedException {
         if (enable) {
@@ -137,11 +146,28 @@ public class CodeReader14Connect implements TCPConnectBase {
 
     @Override
     public ChannelPipeline getChannel() {
-        return null;
+        return pipeline;
     }
 
     @Override
     public void processMessages(String message) {
-
+        try {
+            log.info("退货下料读码器消息:{}", message);
+            if (CodeReadProperties.failureReturnInstruction.equals(message)) {
+                SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_TuiHuoXiaLiao_DMQ-1-27.14", deviceName, "未识别到码", "2"));
+            } else {
+                //读取到批次号保存到数据库中
+                RetroactiveNow retroactiveNow = new RetroactiveNow();
+                retroactiveNow.setLotNo(message);
+                retroactiveNow.setStatus("7");
+                retroactiveNow.setDeviceId("Z1_TuiHuoXiaLiao_DMQ-1-27.14");
+                retroactiveNowService.finishProduce(retroactiveNow);
+                //添加设备日志
+                SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_TuiHuoXiaLiao_DMQ-1-27.14", deviceName, "识别到码:" + message, "1"));
+            }
+        }catch (Exception e){
+            log.error("退货下料读码任务执行异常,msg:{}",e.getMessage());
+            SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_TuiHuoXiaLiao_DMQ-1-27.14", deviceName, "读码任务出错,msg:"+e.getMessage(), "2"));
+        }
     }
 }

+ 20 - 0
warewms-system/src/main/java/com/warewms/hailiang/enums/TuiHuoDownPlcEnum.java

@@ -0,0 +1,20 @@
+package com.warewms.hailiang.enums;
+
+public enum TuiHuoDownPlcEnum {
+    /**
+     * 读码信号
+     */
+    ISREAD("DB200.0.1");
+
+
+    private String metadata;
+
+
+    TuiHuoDownPlcEnum(String metadata) {
+        this.metadata = metadata;
+    }
+
+    public String getMetadata() {
+        return metadata;
+    }
+}

+ 20 - 0
warewms-system/src/main/java/com/warewms/hailiang/enums/TuiHuoUPPlcEnum.java

@@ -0,0 +1,20 @@
+package com.warewms.hailiang.enums;
+
+public enum TuiHuoUPPlcEnum {
+    /**
+     * 读码信号
+     */
+    ISREAD("DB200.0.1");
+
+
+    private String metadata;
+
+
+    TuiHuoUPPlcEnum(String metadata) {
+        this.metadata = metadata;
+    }
+
+    public String getMetadata() {
+        return metadata;
+    }
+}

+ 43 - 33
warewms-system/src/main/java/com/warewms/hailiang/job/TraceJob.java

@@ -9,6 +9,8 @@ import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
+import javax.annotation.Resource;
+
 /**
  * 溯源系統定時任務
  */
@@ -16,16 +18,16 @@ import org.springframework.stereotype.Component;
 @Slf4j
 public class TraceJob {
 
-    @Autowired
-    PlcConnectServiceRunner plcConnectServiceRunner;
+    @Resource
+    private PlcConnectServiceRunner plcConnectServiceRunner;
 
-    @Autowired
-    TcpServiceRunner tcpServiceRunner;
+    @Resource
+    private TcpServiceRunner tcpServiceRunner;
 
-    @Autowired
-    ProcessRealizationService processRealizationService;
+    @Resource
+    private ProcessRealizationService processRealizationService;
 
-    @Autowired
+    @Resource
     private RedisCache redisCache;
 
 
@@ -53,11 +55,11 @@ public class TraceJob {
      * 获取喷码信号
      */
     public void getTheChamferCompletionSignal() {
-        boolean b = plcConnectServiceRunner.getPlcServer(DeviceNameEnum.DAOJIAOPLC.getDeviceName()).readBoolean(DaoJiaoPlcEnum.CHECKFINISH.getMetadata());
-        log.info("喷码信号:{}", b);
-        if (b) {
+//        boolean b = plcConnectServiceRunner.getPlcServer(DeviceNameEnum.DAOJIAOPLC.getDeviceName()).readBoolean(DaoJiaoPlcEnum.CHECKFINISH.getMetadata());
+//        log.info("喷码信号:{}", b);
+//        if (b) {
             processRealizationService.DaoJiaoCodingCodeProcess();
-        }
+//        }
     }
 
     /**
@@ -65,44 +67,44 @@ public class TraceJob {
      */
 
     public void obtainTheChamferingMachineCodeReadingSignal (){
-        boolean b = plcConnectServiceRunner.getPlcServer(DeviceNameEnum.DAOJIAOPLC.getDeviceName()).readBoolean(DaoJiaoPlcEnum.READCODE.getMetadata());
-        log.info("倒角机读码信号,{}",b);
-        if (b) {
+//        boolean b = plcConnectServiceRunner.getPlcServer(DeviceNameEnum.DAOJIAOPLC.getDeviceName()).readBoolean(DaoJiaoPlcEnum.READCODE.getMetadata());
+//        log.info("倒角机读码信号,{}",b);
+//        if (b) {
             processRealizationService.CodeReadingProcess("CodeReader3");
-        }
+//        }
     }
 
     /**
      * 获取铣面读码信号
      */
     public void obtainTheMillingFaceReadingSignal() {
-        boolean b = plcConnectServiceRunner.getPlcServer(DeviceNameEnum.XIMIANPLC.getDeviceName()).readBoolean(XiMianPlcEnum.ISREAD.getMetadata());
-        log.info("铣面读码信号:{}", b);
-        if (b) {
+//        boolean b = plcConnectServiceRunner.getPlcServer(DeviceNameEnum.XIMIANPLC.getDeviceName()).readBoolean(XiMianPlcEnum.ISREAD.getMetadata());
+//        log.info("铣面读码信号:{}", b);
+//        if (b) {
             processRealizationService.CodeReadingProcess("CodeReader5");
-        }
+//        }
     }
 
     /**
      * 获取轧制读码信号
      */
     public void getARollingReadingSignal() {
-        boolean b = plcConnectServiceRunner.getPlcServer(DeviceNameEnum.ZHAZHIPLC.getDeviceName()).readBoolean(ZhaZhiPlcEnum.ISREAD.getMetadata());
-        log.info("轧制读码信号:{}", b);
-        if (b) {
+//        boolean b = plcConnectServiceRunner.getPlcServer(DeviceNameEnum.ZHAZHIPLC.getDeviceName()).readBoolean(ZhaZhiPlcEnum.ISREAD.getMetadata());
+//        log.info("轧制读码信号:{}", b);
+//        if (b) {
             processRealizationService.CodeReadingProcess("CodeReader6");
-        }
+//        }
     }
 
     /**
      * 获取行车1读码信号
      */
     public void getTheDriving1CodeReadingSignal() {
-        boolean b = plcConnectServiceRunner.getPlcServer(DeviceNameEnum.DASANPANPLC.getDeviceName()).readBoolean(DaSanPanPlcEnum.ISREAD_one.getMetadata());
-        log.info("大散盘1号行车读码信号:{}", b);
-        if (b) {
+//        boolean b = plcConnectServiceRunner.getPlcServer(DeviceNameEnum.DASANPANPLC.getDeviceName()).readBoolean(DaSanPanPlcEnum.ISREAD_one.getMetadata());
+//        log.info("大散盘1号行车读码信号:{}", b);
+//        if (b) {
             processRealizationService.CodeReadingProcess("CodeReader7");
-        }
+//        }
     }
 
     /**
@@ -123,24 +125,32 @@ public class TraceJob {
      * 获取行车4读码信号
      */
     public void getTheDriving4CodeReadingSignal() {
-        boolean b = plcConnectServiceRunner.getPlcServer(DeviceNameEnum.DASANPANPLC.getDeviceName()).readBoolean(DaSanPanPlcEnum.ISREAD_fourth.getMetadata());
-        log.info("大散盘4号行车读码信号:{}", b);
-        if (b) {
+//        boolean b = plcConnectServiceRunner.getPlcServer(DeviceNameEnum.DASANPANPLC.getDeviceName()).readBoolean(DaSanPanPlcEnum.ISREAD_fourth.getMetadata());
+//        log.info("大散盘4号行车读码信号:{}", b);
+//        if (b) {
             processRealizationService.CodeReadingProcess("CodeReader12");
-        }
+//        }
     }
 
     /**
      * 获取上料读码信号
      */
     public void obtainTheLoadingReadingSignal() {
-
+//        boolean b = plcConnectServiceRunner.getPlcServer(DeviceNameEnum.TUIHUOUPPLC.getDeviceName()).readBoolean(TuiHuoUPPlcEnum.ISREAD.getMetadata());
+//        log.info("大散盘4号行车读码信号:{}", b);
+//        if (b) {
+            processRealizationService.CodeReadingProcess("CodeReader13");
+//        }
     }
 
     /**
      * 获取下料读码信号
      */
     public void obtainTheUnloadingReadingSignal() {
-
+//        boolean b = plcConnectServiceRunner.getPlcServer(DeviceNameEnum.TuiHuoDownPcl.getDeviceName()).readBoolean(TuiHuoDownPlcEnum.ISREAD.getMetadata());
+//        log.info("大散盘4号行车读码信号:{}", b);
+//        if (b) {
+            processRealizationService.CodeReadingProcess("CodeReader14");
+//        }
     }
 }