瀏覽代碼

永湖需求变更

zhangxin 1 年之前
父節點
當前提交
80aa0befa7

+ 4 - 0
base_sql/pallet_sql/yonghu_ddl_20230921.sql

@@ -0,0 +1,4 @@
+DELETE FROM `sys_config` WHERE config_id = 10;
+DELETE FROM `sys_config` WHERE config_id = 11;
+INSERT INTO `sys_config` (`config_id`, `config_name`, `config_key`, `config_value`, `config_type`, `create_by`, `create_time`, `update_by`, `update_time`, `remark`) VALUES (10, '入库检测光栅', 'sys.guangshan.no5', 'Y', 'N', 'admin', '2023-10-19 15:16:10', NULL, NULL, '光栅是否开启【参数键值】condig_value(Y开启,N关闭)');
+INSERT INTO `sys_config` (`config_id`, `config_name`, `config_key`, `config_value`, `config_type`, `create_by`, `create_time`, `update_by`, `update_time`, `remark`) VALUES (11, '出库检测光栅', 'sys.guangshan.no6', 'Y', 'N', 'admin', '2023-10-19 15:16:10', NULL, NULL, '光栅是否开启【参数键值】condig_value(Y开启,N关闭)');

+ 37 - 0
ruoyi-admin/src/main/java/com/ruoyi/thread/ClientHandler.java

@@ -1,9 +1,16 @@
 package com.ruoyi.thread;
 
+import com.baomidou.mybatisplus.core.toolkit.IdWorker;
 import com.ruoyi.ams.agv.ndc.common.ByteUtil;
+import com.ruoyi.ams.agv.ndc.common.CRC16Util;
+import com.ruoyi.ams.agv.ndc.domain.AmsTask;
+import com.ruoyi.ams.agv.ndc.service.IAmsTaskService;
+import com.ruoyi.base.constant.Constant;
+import com.ruoyi.common.core.redis.RedisCache;
 import com.ruoyi.system.domain.SysConfig;
 import com.ruoyi.system.service.ISysConfigService;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
 
 import java.io.IOException;
 import java.io.InputStream;
@@ -27,6 +34,12 @@ public class ClientHandler {
     private final Socket socket;
     private ISysConfigService configService;
 
+    @Autowired
+    private IAmsTaskService amsTaskService;
+
+    @Autowired
+    private RedisCache redisCache;
+
     public ClientHandler(Socket socket, ISysConfigService configService) {
         this.socket = socket;
         this.configService = configService;
@@ -137,6 +150,18 @@ public class ClientHandler {
                             sysConfig.setUpdateTime(new Date());
                             configService.updateConfig(sysConfig);
                             break;
+                        case "3F00500D0A":
+                            //入库区域光栅检测到信号
+                            if (redisCache.checkIsExist(Constant.AREA_INFO.STORAGE_AREA.getKey())) break;
+                            insertAmsTask(Constant.AREA_INFO.STORAGE_AREA.getValue());
+                            redisCache.setCacheObject(Constant.AREA_INFO.STORAGE_AREA.getKey(), Boolean.TRUE);
+                            break;
+                        case "3F00600D0A":
+                            //出库区域光栅检测到信号
+                            if (redisCache.checkIsExist(Constant.AREA_INFO.EXIT_AREA.getKey())) break;
+                            insertAmsTask(Constant.AREA_INFO.EXIT_AREA.getValue());
+                            redisCache.setCacheObject(Constant.AREA_INFO.EXIT_AREA.getKey(), Boolean.TRUE);
+                            break;
                     }
                 }
             }
@@ -153,4 +178,16 @@ public class ClientHandler {
         }
     }
 
+    private void insertAmsTask(String op){
+        AmsTask amsTask = new AmsTask();
+        amsTask.setTaskNo(IdWorker.getIdStr());
+        amsTask.setIkey(Long.parseLong(String.valueOf(CRC16Util.calcCrc16(ByteUtil.string2byteArray(amsTask.getTaskNo())))));
+        amsTask.setStFrom(Integer.valueOf(Constant.LOC_MIDDLE_CACHE.toString()));
+        amsTask.setStTo(Integer.valueOf(Constant.LOC_SORTATION_CACHE.toString()));
+        amsTask.setPriority(1);
+        amsTask.setBusinessType(Constant.TASK_BUSINESS_TYPE.TASK_76.getValue());
+        amsTask.setExt1(op);
+        amsTaskService.insertAmsTask(amsTask);
+    }
+
 }

+ 34 - 27
ruoyi-admin/src/main/java/com/ruoyi/thread/ServerGs.java

@@ -1,11 +1,11 @@
 package com.ruoyi.thread;
 
 import com.ruoyi.ams.agv.ndc.common.ByteUtil;
+import com.ruoyi.base.constant.Constant;
 import com.ruoyi.system.domain.SysConfig;
 import com.ruoyi.system.service.ISysConfigService;
-import com.ruoyi.system.service.impl.SysConfigServiceImpl;
 import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Autowired;
+import org.apache.commons.lang3.StringUtils;
 
 import java.io.IOException;
 import java.io.OutputStream;
@@ -83,34 +83,41 @@ public class ServerGs {
                             config.setConfigName("光栅");
                             config.setConfigValue("Y");
                             List<SysConfig> list = configService.selectConfigList(config);
-
-                            for (int i = 0; i < list.size(); i++) {
-                                //发送检测信号到光栅PLC
-                                switch (list.get(i).getConfigKey()) {
-                                    case "sys.guangshan.no1":
-                                        // 光栅1 发送检测信号
-//                                        log.info("------------光栅1 发送检测信号------------>");
-                                        os.write(ByteUtil.hexString2ByteArray("3F00010D0A"));
-                                        break;
-                                    case "sys.guangshan.no2":
-                                        // 光栅2 发送检测信号
-//                                        log.info("------------光栅2 发送检测信号------------>");
-                                        os.write(ByteUtil.hexString2ByteArray("3F00020D0A"));
-                                        break;
-                                    case "sys.guangshan.no3":
-                                        // 光栅3 发送检测信号
-//                                        log.info("------------光栅3 发送检测信号------------>");
-                                        os.write(ByteUtil.hexString2ByteArray("3F00030D0A"));
-                                        break;
-                                    case "sys.guangshan.no4":
-                                        // 光栅4 发送检测信号
-//                                        log.info("------------光栅4 发送检测信号------------>");
-                                        os.write(ByteUtil.hexString2ByteArray("3F00040D0A"));
-                                        break;
-                                }
+                            for (SysConfig sysConfig : list) {
+                                String detectionSignal = Constant.GRATING_DETECTION_SIGNAL.getValueByKey(sysConfig.getConfigKey());
+                                if (StringUtils.isBlank(detectionSignal)) continue;
+                                os.write(ByteUtil.hexString2ByteArray(detectionSignal));
                                 os.flush();
                                 Thread.sleep(200);
                             }
+
+//                            for (int i = 0; i < list.size(); i++) {
+//                                //发送检测信号到光栅PLC
+//                                switch (list.get(i).getConfigKey()) {
+//                                    case "sys.guangshan.no1":
+//                                        // 光栅1 发送检测信号
+////                                        log.info("------------光栅1 发送检测信号------------>");
+//                                        os.write(ByteUtil.hexString2ByteArray("3F00010D0A"));
+//                                        break;
+//                                    case "sys.guangshan.no2":
+//                                        // 光栅2 发送检测信号
+////                                        log.info("------------光栅2 发送检测信号------------>");
+//                                        os.write(ByteUtil.hexString2ByteArray("3F00020D0A"));
+//                                        break;
+//                                    case "sys.guangshan.no3":
+//                                        // 光栅3 发送检测信号
+////                                        log.info("------------光栅3 发送检测信号------------>");
+//                                        os.write(ByteUtil.hexString2ByteArray("3F00030D0A"));
+//                                        break;
+//                                    case "sys.guangshan.no4":
+//                                        // 光栅4 发送检测信号
+////                                        log.info("------------光栅4 发送检测信号------------>");
+//                                        os.write(ByteUtil.hexString2ByteArray("3F00040D0A"));
+//                                        break;
+//                                }
+//                                os.flush();
+//                                Thread.sleep(200);
+//                            }
                         } catch (Exception e) {
                             log.error("光栅客户端断开:" + e.getMessage());
                             //关闭连接

+ 62 - 37
ruoyi-admin/src/main/java/com/ruoyi/web/controller/warewms/wcs/WcsController.java

@@ -1,11 +1,11 @@
 package com.ruoyi.web.controller.warewms.wcs;
 
 import com.alibaba.fastjson.JSON;
+import com.baomidou.mybatisplus.core.toolkit.IdWorker;
 import com.ruoyi.ams.agv.ndc.common.ByteUtil;
 import com.ruoyi.ams.agv.ndc.common.CRC16Util;
 import com.ruoyi.ams.agv.ndc.domain.AmsTask;
 import com.ruoyi.ams.agv.ndc.service.IAmsTaskService;
-import com.ruoyi.ams.business.IBusinessService;
 import com.ruoyi.base.constant.Constant;
 import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.common.core.redis.RedisCache;
@@ -17,6 +17,8 @@ import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.util.HashMap;
+import java.util.Map;
 import java.util.concurrent.TimeUnit;
 
 @Slf4j
@@ -28,49 +30,72 @@ public class WcsController {
     private RedisCache redisCache;
     @Autowired
     private IAmsTaskService amsTaskService;
-    @Autowired
-    private IBusinessService businessService;
+
+    /**
+     * 按钮盒关闭交通管制
+     */
+    private final static String OPEN = "OPEN";
+
+    /**
+     * 按钮盒开启交通管制
+     */
+    private final static String CLOSE = "CLOSE";
+
+    /**
+     * 按钮盒对应出库区域ip
+     */
+    private final static String EXIT_AREA_IP = "192.168.77.105";
+
+    /**
+     * 按钮盒对应入库区域ip
+     */
+    private final static String STORAGE_AREA_IP = "192.168.77.104";
+
+    /**
+     * 按钮盒控制
+     */
+    private static final Map<String, String> buttonBoxControlMap= new HashMap<String, String>(){
+        {
+            put(OPEN, Constant.TASK_BUSINESS_TYPE.TASK_75.getValue());
+            put(CLOSE, Constant.TASK_BUSINESS_TYPE.TASK_74.getValue());
+        }
+    };
+
+    /**
+     * 按钮盒区域对应id
+     */
+    private static final Map<String, String> buttonBoxAreaMap= new HashMap<String, String>(){
+        {
+            put(EXIT_AREA_IP, Constant.AREA_INFO.EXIT_AREA.getValue());
+            put(STORAGE_AREA_IP, Constant.AREA_INFO.STORAGE_AREA.getValue());
+        }
+    };
 
     @PostMapping("/btnOp")
     public AjaxResult add(@RequestBody BtnOpForm btnOpForm) {
         log.info("按钮盒请求------------------------》" + JSON.toJSONString(btnOpForm));
         redisCache.setCacheObject(btnOpForm.getIp() + btnOpForm.getOpType(), btnOpForm.getOpType(), 15, TimeUnit.SECONDS);
 
-        log.info("交管操作执行");
-        //1: 192.168.77.105
-        //2: 192.168.77.104
-        String op = "";
-        String businessType = "";
-        if (btnOpForm.getOpType().equals("CLOSE")) {
-            businessType = "74";
-        } else if (btnOpForm.getOpType().equals("OPEN")) {
-            businessType = "75";
-        }
-        if (btnOpForm.getIp().equals("192.168.77.105")) {
-            op = "1";
-        } else if (btnOpForm.getIp().equals("192.168.77.104")) {
-            op = "2";
+        String op = buttonBoxAreaMap.get(btnOpForm.getIp());
+        String businessType = buttonBoxControlMap.get(btnOpForm.getOpType());
+        if (Constant.TASK_BUSINESS_TYPE.TASK_75.getValue().equals(businessType)
+                && redisCache.checkIsExist(Constant.AREA_INFO.getKeyByValue(op))) {
+            insertAmsTask(op, Constant.TASK_BUSINESS_TYPE.TASK_77.getValue());
+            redisCache.deleteObject(Constant.AREA_INFO.getKeyByValue(op));
         }
-//            WcsTask wcsTask = new WcsTask();
-//            wcsTask.setLocationFrom(Constant.LOC_MIDDLE_CACHE.toString());
-//            wcsTask.setLocationTo(Constant.LOC_SORTATION_CACHE.toString());
-//            wcsTask.setBusinessType(businessType);
-//            wcsTask.setPriority(1L);
-//            wcsTask.setExt1(op);
-//            wcsTask.setTaskNo(System.currentTimeMillis() + "");
-//            businessService.sendTask(wcsTask);
-
-        AmsTask addTaskForm = new AmsTask();
-        addTaskForm.setTaskNo(String.valueOf(System.currentTimeMillis()));
-        addTaskForm.setIkey(Long.parseLong(String.valueOf(CRC16Util.calcCrc16(ByteUtil.string2byteArray(addTaskForm.getTaskNo())))));
-        addTaskForm.setStFrom(Integer.valueOf(Constant.LOC_MIDDLE_CACHE.toString()));
-        addTaskForm.setStTo(Integer.valueOf(Constant.LOC_SORTATION_CACHE.toString()));
-        addTaskForm.setPriority(1);
-        addTaskForm.setBusinessType(businessType);
-        addTaskForm.setExt1(op);
-
-        amsTaskService.insertAmsTask(addTaskForm);
-
+        insertAmsTask(op, businessType);
         return AjaxResult.success("");
     }
+
+    private void insertAmsTask(String op, String businessType){
+        AmsTask amsTask = new AmsTask();
+        amsTask.setTaskNo(IdWorker.getIdStr());
+        amsTask.setIkey(Long.parseLong(String.valueOf(CRC16Util.calcCrc16(ByteUtil.string2byteArray(amsTask.getTaskNo())))));
+        amsTask.setStFrom(Integer.valueOf(Constant.LOC_MIDDLE_CACHE.toString()));
+        amsTask.setStTo(Integer.valueOf(Constant.LOC_SORTATION_CACHE.toString()));
+        amsTask.setPriority(1);
+        amsTask.setBusinessType(businessType);
+        amsTask.setExt1(op);
+        amsTaskService.insertAmsTask(amsTask);
+    }
 }

+ 8 - 8
ruoyi-common/src/main/java/com/ruoyi/common/core/redis/RedisCache.java

@@ -1,13 +1,6 @@
 package com.ruoyi.common.core.redis;
 
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.TimeUnit;
-
-import com.ruoyi.common.exception.ServiceException;
+import cn.hutool.core.util.ObjectUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.redis.core.BoundSetOperations;
 import org.springframework.data.redis.core.HashOperations;
@@ -15,6 +8,9 @@ import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.data.redis.core.ValueOperations;
 import org.springframework.stereotype.Component;
 
+import java.util.*;
+import java.util.concurrent.TimeUnit;
+
 /**
  * spring redis 工具类
  *
@@ -82,6 +78,10 @@ public class RedisCache {
         return isLock;
     }
 
+    public boolean checkIsExist(String key) {
+        return ObjectUtil.isNotNull(redisTemplate.opsForValue().get(key));
+    }
+
     /**
      * 缓存基本的对象,Integer、String、实体类等
      *

+ 0 - 9
warewms-ams/src/main/java/com/ruoyi/ams/agv/ndc/service/impl/StatusUpdateServiceImpl.java

@@ -4,18 +4,11 @@ import com.ruoyi.ams.agv.ndc.domain.AmsTask;
 import com.ruoyi.ams.agv.ndc.entity.CallbackResult;
 import com.ruoyi.ams.agv.ndc.service.IAmsTaskService;
 import com.ruoyi.ams.agv.ndc.service.StatusUpdateService;
-import com.ruoyi.ams.business.BusinessServiceImpl;
-import com.ruoyi.ams.business.IBusinessService;
-import com.ruoyi.ams.task.form.AddTaskForm;
 import com.ruoyi.ams.task.service.IWcsTaskService;
-import com.ruoyi.base.constant.Constant;
-import com.ruoyi.common.utils.uuid.SnowflakeIdWorker;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
-import java.util.List;
-
 @Slf4j
 @Component
 public class StatusUpdateServiceImpl implements StatusUpdateService {
@@ -24,8 +17,6 @@ public class StatusUpdateServiceImpl implements StatusUpdateService {
     private IAmsTaskService amsTaskService;
     @Autowired
     private IWcsTaskService wcsTaskService;
-    @Autowired
-    private IBusinessService businessService;
 
     @Override
     public void updateStatus(Long id, Integer carNo) {

+ 160 - 2
warewms-base/src/main/java/com/ruoyi/base/constant/Constant.java

@@ -1,5 +1,9 @@
 package com.ruoyi.base.constant;
 
+import cn.hutool.core.comparator.CompareUtil;
+
+import java.util.Arrays;
+
 /**
  * Created by IntelliJ IDEA.
  * User: andy.qu
@@ -113,7 +117,6 @@ public class Constant {
          * 反拣
          */
         FJ("FJ"),
-        /**
         /**
          * 库内理货
          */
@@ -318,8 +321,22 @@ public class Constant {
          * m
          */
         TASK_m("m"),
-        //交通管制
+        /**
+         * 按钮盒触发交通管制
+         */
         TASK_74("74"),
+        /**
+         * 按钮盒解除交通管制
+         */
+        TASK_75("75"),
+        /**
+         * 光栅触发交通管制
+         */
+        TASK_76("76"),
+        /**
+         * 光栅解除交通管制
+         */
+        TASK_77("77"),
         /**
          * 暂停
          */
@@ -603,5 +620,146 @@ public class Constant {
         }
     }
 
+    /**
+     * 光栅检测信号
+     */
+    public enum GRATING_DETECTION_SIGNAL {
+        /***
+         * 1号光栅
+         */
+        NO1("sys.guangshan.no1", "3F00010D0A"),
+        /***
+         * 2号光栅
+         */
+        NO2("sys.guangshan.no2", "3F00020D0A"),
+        /***
+         * 3号光栅
+         */
+        NO3("sys.guangshan.no3", "3F00030D0A"),
+        /***
+         * 4号光栅
+         */
+        NO4("sys.guangshan.no4", "3F00040D0A"),
+        /***
+         * 5号光栅
+         */
+        NO5("sys.guangshan.no5", "3F00510D0A"),
+        /***
+         * 6号光栅
+         */
+        NO6("sys.guangshan.no6", "3F00610D0A");
+
+        /**
+         * 光栅编号
+         */
+        private String key;
+
+        /**
+         * 检测信号
+         */
+        private String value;
 
+        GRATING_DETECTION_SIGNAL(String key, String value) {
+            this.key = key;
+            this.value = value;
+        }
+
+        /**
+         * 获取光栅编号
+         *
+         * @return
+         */
+        public String getKey() {
+            return key;
+        }
+
+        /**
+         * 获取检测信号
+         *
+         * @return
+         */
+        public String getValue() {
+            return value;
+        }
+
+        /**
+         * 根据光栅号获取检测信号
+         *
+         * @param key
+         * @return
+         */
+        public static String getValueByKey(String key) {
+            return Arrays.stream(values()).filter(item -> CompareUtil.compare(item.getKey(), key) == 0)
+                    .map(GRATING_DETECTION_SIGNAL::getValue).findFirst().orElseGet(() -> null);
+        }
+    }
+
+    /**
+     * 出入库区域信息
+     */
+    public enum AREA_INFO {
+        /***
+         * 入库区域
+         */
+        STORAGE_AREA("storageAreaControl", "2"),
+        /***
+         * 出库区域
+         */
+        EXIT_AREA("exitAreaControl", "1");
+
+        /**
+         * 区域缓存key
+         */
+        private String key;
+
+        /**
+         * 区域对接杭叉AGV LP0字段
+         */
+        private String value;
+
+        AREA_INFO(String key, String value) {
+            this.key = key;
+            this.value = value;
+        }
+
+        /**
+         * 获取区域缓存key
+         *
+         * @return
+         */
+        public String getKey() {
+            return key;
+        }
+
+        /**
+         * 获取区域对接杭叉AGV LP0字段
+         *
+         * @return
+         */
+        public String getValue() {
+            return value;
+        }
+
+        /**
+         * 根据区域缓存key获取区域对接杭叉AGV LP0字段
+         *
+         * @param key
+         * @return
+         */
+        public static String getValueByKey(String key) {
+            return Arrays.stream(values()).filter(item -> CompareUtil.compare(item.getKey(), key) == 0)
+                    .map(AREA_INFO::getValue).findFirst().orElseGet(() -> null);
+        }
+
+        /**
+         * 根据区域对接杭叉AGV LP0字段获取区域缓存key
+         *
+         * @param value
+         * @return
+         */
+        public static String getKeyByValue(String value) {
+            return Arrays.stream(values()).filter(item -> CompareUtil.compare(item.getValue(), value) == 0)
+                    .map(AREA_INFO::getKey).findFirst().orElseGet(() -> null);
+        }
+    }
 }