Browse Source

添加页面手动触发读码功能

zhifei 1 year ago
parent
commit
4da6cae248

+ 17 - 3
warewms-system/src/main/java/com/warewms/hailiang/contoller/DeviceController.java

@@ -1,12 +1,14 @@
 package com.warewms.hailiang.contoller;
 
+import cn.hutool.extra.spring.SpringUtil;
 import com.warewms.common.core.domain.R;
+import com.warewms.common.utils.StringUtils;
 import com.warewms.hailiang.domain.Device;
+import com.warewms.hailiang.domain.DeviceLog;
 import com.warewms.hailiang.service.DeviceService;
+import com.warewms.hailiang.service.ProcessRealizationService;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 import java.util.List;
 
@@ -22,8 +24,20 @@ public class DeviceController {
     @Autowired
     DeviceService deviceService;
 
+    @Autowired
+    ProcessRealizationService processRealizationService;
+
     @GetMapping("/list")
     public R<List<Device>> getList() {
         return R.ok(deviceService.getList());
     }
+
+    @PostMapping("/triggerCodeRead")
+    public R triggerCodeRead(@RequestBody Device device) {
+        R r = processRealizationService.CodeReadingProcess(device.getDeviceName());
+        if(R.isSuccess(r)){
+            SpringUtil.getApplicationContext().publishEvent(new DeviceLog(device.getDeviceId(), device.getDeviceName(), "手动触发读码", "1"));
+        }
+        return r;
+    }
 }

+ 2 - 0
warewms-system/src/main/java/com/warewms/hailiang/domain/Device.java

@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
 import com.warewms.common.core.domain.base.BaseEntity;
 import lombok.Data;
+import lombok.NoArgsConstructor;
 
 import java.io.Serializable;
 
@@ -14,6 +15,7 @@ import java.io.Serializable;
  * @TableName device
  */
 @Data
+@NoArgsConstructor
 public class Device extends BaseEntity implements Serializable {
 
     /**

+ 1 - 1
warewms-system/src/main/java/com/warewms/hailiang/service/DeviceLogService.java

@@ -17,6 +17,6 @@ public interface DeviceLogService extends IService<DeviceLog> {
 
     TableDataInfo<DeviceLog> getList(DeviceLog deviceLog, PageDomain pageDomain);
 
-    void crateLog(DeviceLog deviceLog);
+    void createLog(DeviceLog deviceLog);
 
 }

+ 3 - 1
warewms-system/src/main/java/com/warewms/hailiang/service/ProcessRealizationService.java

@@ -1,5 +1,7 @@
 package com.warewms.hailiang.service;
 
+import com.warewms.common.core.domain.R;
+
 /**
  * 工艺流程实现
  */
@@ -18,6 +20,6 @@ public interface ProcessRealizationService {
     /**
      * 读码触发实现
      */
-    void CodeReadingProcess(String codeReadName);
+    R CodeReadingProcess(String codeReadName);
 
 }

+ 4 - 4
warewms-system/src/main/java/com/warewms/hailiang/service/impl/DeviceServiceImpl.java

@@ -28,10 +28,10 @@ public class DeviceServiceImpl implements DeviceService {
         devices.add(new Device("Z1_DaSanPan_DMQ-2-27.8", "CodeReader8", "大散盘读码器2", "Z1", "172.20.27.8", 51236, "TCP", "2"));
         devices.add(new Device("Z1_DaSanPan_DMQ-3-27.9", "CodeReader9", "大散盘读码器3", "Z1", "172.20.27.9", 51236, "TCP", "2"));
         devices.add(new Device("Z1_DaSanPan_DMQ-4-27.12", "CodeReader12", "大散盘读码器4", "Z1", "172.20.27.12", 51236, "TCP", "2"));
-        devices.add(new Device("Z1_TuiHuoShangLiao_PLC-1-", "TuiHuoUPPlc", "退货上料plc", "Z1", "172.20.27.13", 51236, "s7", "2"));
-        devices.add(new Device("Z1_TuiHuoXiaLiao_PLC-1-", "TuiHuoDownPlc", "退货上料plc", "Z1", "172.20.27.13", 51236, "s7", "2"));
-        devices.add(new Device("Z1_TuiHuoShangLiao_DMQ-1-27.13", "CodeReader13", "退上料读码器", "Z1", "172.20.27.13", 51236, "TCP", "2"));
-        devices.add(new Device("Z1_TuiHuoXiaLiao_DMQ-1-27.14", "CodeReader14", "退下料读码器", "Z1", "172.20.27.14", 51236, "TCP", "2"));
+        devices.add(new Device("Z1_TuiHuoShangLiao_PLC-1-", "TuiHuoUPPlc", "退火上料PLC", "Z1", "172.20.27.13", 51236, "s7", "2"));
+        devices.add(new Device("Z1_TuiHuoXiaLiao_PLC-1-", "TuiHuoDownPlc", "退火下料PLC", "Z1", "172.20.27.13", 51236, "s7", "2"));
+        devices.add(new Device("Z1_TuiHuoShangLiao_DMQ-1-27.13", "CodeReader13", "退上料读码器", "Z1", "172.20.27.13", 51236, "TCP", "2"));
+        devices.add(new Device("Z1_TuiHuoXiaLiao_DMQ-1-27.14", "CodeReader14", "退下料读码器", "Z1", "172.20.27.14", 51236, "TCP", "2"));
     }
 
     @Override

+ 8 - 3
warewms-system/src/main/java/com/warewms/hailiang/service/impl/ProcessRealizationServiceImpl.java

@@ -2,12 +2,14 @@ package com.warewms.hailiang.service.impl;
 
 import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.extra.spring.SpringUtil;
+import com.warewms.common.core.domain.R;
 import com.warewms.common.core.redis.RedisCache;
 import com.warewms.common.utils.StringUtils;
 import com.warewms.hailiang.MES.MesService;
 import com.warewms.hailiang.config.CodeReadProperties;
 import com.warewms.hailiang.domain.DeviceLog;
 import com.warewms.hailiang.domain.RetroactiveNow;
+import com.warewms.hailiang.enums.DaoJiaoPlcEnum;
 import com.warewms.hailiang.enums.DeviceNameEnum;
 import com.warewms.hailiang.enums.WeighPlcEnum;
 import com.warewms.hailiang.init.PlcConnectServiceRunner;
@@ -94,16 +96,19 @@ public class ProcessRealizationServiceImpl implements ProcessRealizationService
                 SpringUtil.getApplicationContext().publishEvent(new DeviceLog("Z1_DaoJiao_PMQ-1-27.4", "InkjetPrinters", "喷码内容修改完成,内容为:" + retroactiveNow.getBatchNo(), "1"));
             }
             //回写plc信号进行喷码
+            plcConnectServiceRunner.getPlcServer(DeviceNameEnum.DAOJIAOPLC.getDeviceName()).writeInt32(DaoJiaoPlcEnum.CHECKFINISH.getMetadata(),8);
         }
     }
 
     @Override
-    public void CodeReadingProcess(String codeReadName) {
+    public R CodeReadingProcess(String codeReadName) {
+        System.out.println(codeReadName);
         if (redisCache.hasKey(codeReadName)) {
             log.info("读码器{}正在读码!", codeReadName);
-            return;
+            return R.fail("该读码器正在读码,请勿重复操作");
         }
         tcpServiceRunner.getTCPInstanceList(codeReadName).getChannel().writeAndFlush(Unpooled.copiedBuffer(CodeReadProperties.startTheCommand, CharsetUtil.UTF_8));
-        redisCache.expire(codeReadName, 30, TimeUnit.SECONDS);
+        redisCache.setCacheObject(codeReadName,codeReadName, 30, TimeUnit.SECONDS);
+        return R.ok();
     }
 }