Browse Source

1.任务列表增加任务(增加转发选择)
2.Aciservice与ndc重连优化

k 2 years ago
parent
commit
c96bf1758b

+ 5 - 3
ruoyi-admin/src/main/java/com/ruoyi/init/StartService.java

@@ -2,10 +2,10 @@ package com.ruoyi.init;
 
 import com.ruoyi.ams.agv.ndc.AciService;
 import com.ruoyi.ams.agv.ndc.config.TestTagConfig;
+import com.ruoyi.ams.agv.ndc.thread.AciServiceThread;
 import com.ruoyi.ams.agv.ndc.thread.AutoTaskThread;
 import com.ruoyi.ams.business.IBusinessService;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
 import org.springframework.boot.CommandLineRunner;
 import org.springframework.stereotype.Component;
 
@@ -16,6 +16,8 @@ public class StartService implements CommandLineRunner {
     private IBusinessService businessService;
     @Autowired
     private TestTagConfig testTagConfig;
+    @Autowired
+    private AciService aciService;
 
     @Override
     public void run(String... args) throws Exception {
@@ -27,8 +29,8 @@ public class StartService implements CommandLineRunner {
 
         //ndc下发
         if (testTagConfig.getAciService()) {
-            AciService aciService = new AciService();
-            aciService.start();
+            Thread thread = new Thread(new AciServiceThread(aciService));
+            thread.start();
         }
     }
 }

+ 3 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/controller/warewms/ams/WcsTaskController.java

@@ -145,6 +145,9 @@ public class WcsTaskController extends BaseController {
         WcsTask wcsTask = new WcsTask();
         wcsTask.setTaskNo(System.currentTimeMillis() + "");
         wcsTask.setState(9L);
+        if (addTaskForm.getTaskType().equals(Constant.IS_YES.Y.toString())) {
+            wcsTask.setTaskType(Constant.TASK_TYPE.FORWARD.getValue());
+        }
         wcsTask.setBusinessType(addTaskForm.getBusinessType());
         wcsTask.setAreaFrom(addTaskForm.getAreaFrom());
         wcsTask.setLocationFrom(addTaskForm.getLocationFrom());

+ 17 - 5
ruoyi-admin/src/main/resources/application-dev.yml

@@ -13,9 +13,9 @@ spring:
             slave:
                 # 从数据源开关/默认关闭
                 enabled: false
-                url: 
-                username: 
-                password: 
+                url:
+                username:
+                password:
             # 初始连接数
             initialSize: 5
             # 最小连接池数量
@@ -35,7 +35,7 @@ spring:
             testWhileIdle: true
             testOnBorrow: false
             testOnReturn: false
-            webStatFilter: 
+            webStatFilter:
                 enabled: true
             statViewServlet:
                 enabled: true
@@ -54,4 +54,16 @@ spring:
                     merge-sql: true
                 wall:
                     config:
-                        multi-statement-allow: true
+                        multi-statement-allow: true
+
+
+# 是否开启服务
+testtag:
+    autosend: false
+    aciservice: false
+
+# 日志配置
+logging:
+    level:
+        com.ruoyi: debug
+        org.springframework: debug

+ 11 - 0
ruoyi-admin/src/main/resources/application-prod.yml

@@ -55,3 +55,14 @@ spring:
                 wall:
                     config:
                         multi-statement-allow: true
+
+# 是否开启服务
+testtag:
+    autosend: true
+    aciservice: true
+
+# 日志配置
+logging:
+    level:
+        com.ruoyi: info
+        org.springframework: info

+ 9 - 9
ruoyi-admin/src/main/resources/application.yml

@@ -42,7 +42,7 @@ spring:
   messages:
     # 国际化资源文件路径
     basename: i18n/messages
-  profiles: 
+  profiles:
     active: dev
   # 文件上传
   servlet:
@@ -65,7 +65,7 @@ spring:
     # 数据库索引
     database: 0
     # 密码
-    password: 
+    password:
     # 连接超时时间
     timeout: 10s
     lettuce:
@@ -87,7 +87,7 @@ token:
     secret: abcdefghijklmnopqrstuvwxyz
     # 令牌有效期(默认30分钟)
     expireTime: 3000
-  
+
 # MyBatis配置
 mybatis:
     # 搜索指定包别名
@@ -98,10 +98,10 @@ mybatis:
     configLocation: classpath:mybatis/mybatis-config.xml
 
 # PageHelper分页插件
-pagehelper: 
+pagehelper:
   helperDialect: mysql
   supportMethodsArguments: true
-  params: count=countSql 
+  params: count=countSql
 
 # Swagger配置
 swagger:
@@ -111,7 +111,7 @@ swagger:
   pathMapping: /dev-api
 
 # 防止XSS攻击
-xss: 
+xss:
   # 过滤开关
   enabled: true
   # 排除链接(多个用逗号分隔)
@@ -120,6 +120,6 @@ xss:
   urlPatterns: /system/*,/monitor/*,/tool/*
 
 # 是否开启服务
-testtag:
-  autosend: false
-  aciservice: false
+#testtag:
+#  autosend: true
+#  aciservice: true

+ 14 - 0
ruoyi-ui/src/views/ams/task/index.vue

@@ -220,6 +220,16 @@
             ></el-option>
           </el-select>
         </el-form-item>
+        <el-form-item label="是否转发" prop="businessType">
+          <el-select v-model="form.taskType" placeholder="请选择" clearable size="small" style="width: 100%">
+            <el-option
+              v-for="dict in taskTypeCombo"
+              :key="dict.value"
+              :label="dict.label"
+              :value="dict.value"
+            ></el-option>
+          </el-select>
+        </el-form-item>
         <el-form-item label="起始区域" prop="areaFrom">
           <el-select v-model="form.areaFrom" @change="locationZoneFromChange" placeholder="请选择库区" clearable
                      size="small" style="width: 100%">
@@ -415,6 +425,10 @@ export default {
       businessTypeCombo: [
         {'label':'普通任务','value':'01'}
       ],
+      taskTypeCombo: [
+        {'label':'是','value':'Y'},
+        {'label':'否','value':'N'}
+      ],
       locationFromCombo: [],
       locationToCombo: [],
       locationZoneCombo: []

+ 61 - 39
warewms-ams/src/main/java/com/ruoyi/ams/agv/ndc/AciService.java

@@ -14,6 +14,7 @@ import com.ruoyi.ams.agv.ndc.service.SocketBufferService;
 import com.ruoyi.base.constant.Constant;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
 
 import java.io.IOException;
 import java.net.InetSocketAddress;
@@ -29,15 +30,16 @@ import java.util.List;
  * Date: 2022/8/5
  */
 @Slf4j
+@Service
 public class AciService {
 
     private static final int TIMEOUT = 3000;
 
     private static final int BUFF_SIZE = 2048;
 
-    private static final String IP_ADDR = "192.168.0.105";
+    private static final String IP_ADDR = "192.168.1.58";
 
-    private static final int IP_PORT = 30001;
+    private static final int IP_PORT = 30002;
 
     @Autowired
     private SocketBufferService socketBufferService;
@@ -53,20 +55,23 @@ public class AciService {
         int ip_port = IP_PORT; //redisUtils.getInt(RedisEnum.NDC_PORT.getMessage());
 
         SocketChannel socketChannel = SocketChannel.open();
-
+        socketChannel.configureBlocking(false); // 解决了IO阻塞
         while (true) {
 
             try {
-
                 //链接服务端Socket
                 if (!socketChannel.isConnected()) {
-
                     if (!socketChannel.isOpen()) {
-
                         socketChannel = SocketChannel.open();
+                        socketChannel.configureBlocking(false); // 解决了IO阻塞
                     }
+                    // 非阻塞模式下 这段代码并不是等到连接建立之后再往下执行
                     SocketAddress socketAddress = new InetSocketAddress(ip_addr, ip_port);
                     socketChannel.connect(socketAddress);
+                    Thread.sleep(2000);
+                    if (socketChannel.isConnectionPending()) {
+                        socketChannel.finishConnect();
+                    }
                 }
 
                 ByteBuffer buffer = ByteBuffer.allocate(BUFF_SIZE);
@@ -135,7 +140,7 @@ public class AciService {
                             log.info("任务类型未定义------" + JSON.toJSONString(t));
                             continue;
                         }
-                        try {
+//                        try {
                             String order = amsHexdefineDetailService.concatOrder(t, basTask);
                             log.info("writeOrder:" + order);
                             if (t.getBusinessType().equals("m") ||
@@ -158,43 +163,50 @@ public class AciService {
                                 socketChannel.write(buffer);
                                 buffer.clear();
                             }
-                        } catch (Exception e) {
-                            e.printStackTrace();
-                            t.setServerAck(0);
-                            t.setAciAccept(1);
-                            t.setRoadway("程序异常自动ack");
-                            t.setIsDelete(null);
-                            amsTaskService.updateAmsTask(t);
-                        }
+//                        } catch (Exception e) {
+//                            e.printStackTrace();
+//                            t.setServerAck(0);
+//                            t.setAciAccept(1);
+//                            t.setRoadway("程序异常自动ack");
+//                            t.setIsDelete(null);
+//                            amsTaskService.updateAmsTask(t);
+//                        }
                     }
                 }
 
                 //从服务端读取
+                buffer.clear();
+                //因为设置了异步 这边不会阻塞 测试了一下 服务器断开这边会抛出异常 但是写的时候不会抛出异常 可能是设置了异步的原因
                 int readLenth = socketChannel.read(buffer);
-                buffer.flip();
-                byte[] bytes = new byte[readLenth];
-                buffer.get(bytes);
-                List<Order> bufferSeparators = socketBufferService.bufferSeparator(bytes);
-                for (Order order : bufferSeparators) {
+                if (readLenth == -1) {
+                    throw new IOException();
+                }
+                if (readLenth > 0) {
+                    buffer.flip();
+                    byte[] bytes = new byte[readLenth];
+                    buffer.get(bytes);
+                    List<Order> bufferSeparators = socketBufferService.bufferSeparator(bytes);
+                    for (Order order : bufferSeparators) {
 
 //                    log.info("消息类型:" + order.getMessageType() + ",消息参数:" + ByteUtil.byteArray2HexString(order.getParameters()));
-                    switch (order.getMessageType()) {
-
-                        case Aci.MSG_ORDER_STATUS://车体状态信息、位置信息
-                            socketBufferService.handleMsgOrderStatus(order.getParameters());
-                            break;
-                        case Aci.MSG_EVENT://任务反馈、自定义消息
-                            socketBufferService.handleMsgEvent(order.getParameters());
-                            break;
-                        case Aci.MSG_STOP://交通管制暂停
-                            socketBufferService.handleMsgStopStart(order.getParameters(), true);
-                            break;
-                        case Aci.MSG_START://启动信息
-                            socketBufferService.handleMsgStopStart(order.getParameters(), false);
-                            break;
-                        case Aci.MSG_ORDER_ACK://信息接收反馈
-                            socketBufferService.handleMsgOrderAck(order.getParameters());
-                            break;
+                        switch (order.getMessageType()) {
+
+                            case Aci.MSG_ORDER_STATUS://车体状态信息、位置信息
+                                socketBufferService.handleMsgOrderStatus(order.getParameters());
+                                break;
+                            case Aci.MSG_EVENT://任务反馈、自定义消息
+                                socketBufferService.handleMsgEvent(order.getParameters());
+                                break;
+                            case Aci.MSG_STOP://交通管制暂停
+                                socketBufferService.handleMsgStopStart(order.getParameters(), true);
+                                break;
+                            case Aci.MSG_START://启动信息
+                                socketBufferService.handleMsgStopStart(order.getParameters(), false);
+                                break;
+                            case Aci.MSG_ORDER_ACK://信息接收反馈
+                                socketBufferService.handleMsgOrderAck(order.getParameters());
+                                break;
+                        }
                     }
                 }
                 buffer.clear();
@@ -205,9 +217,19 @@ public class AciService {
                     e.printStackTrace();
                 }
 
-            } catch (Exception e) {
-                if (!socketChannel.isOpen()) {
+            }catch (IOException i) {
+                log.error("NDC通讯异常!" ,i);
+                try {
                     socketChannel.close();
+                } catch (Exception exception) {
+                    i.printStackTrace();
+                }
+            }catch (Exception e) {
+                e.printStackTrace();
+                try {
+                    socketChannel.close();
+                } catch (Exception exception) {
+                    e.printStackTrace();
                 }
             }
         }

+ 1 - 1
warewms-ams/src/main/java/com/ruoyi/ams/agv/ndc/service/impl/SocketBufferServiceImpl.java

@@ -402,4 +402,4 @@ public class SocketBufferServiceImpl implements SocketBufferService {
     public void handleMsgStopStart(byte[] parameters, boolean isStop) {
 
     }
-}
+}

+ 26 - 0
warewms-ams/src/main/java/com/ruoyi/ams/agv/ndc/thread/AciServiceThread.java

@@ -0,0 +1,26 @@
+package com.ruoyi.ams.agv.ndc.thread;
+
+import com.ruoyi.ams.agv.ndc.AciService;
+import lombok.extern.slf4j.Slf4j;
+
+@Slf4j
+public class AciServiceThread implements Runnable {
+
+    private AciService aciService;
+
+    public AciServiceThread(AciService aciService) {
+        this.aciService = aciService;
+    }
+
+    @Override
+    public void run() {
+        while (true) {
+            try {
+                aciService.start();
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+
+        }
+    }
+}

+ 12 - 3
warewms-ams/src/main/java/com/ruoyi/ams/business/BusinessServiceImpl.java

@@ -597,12 +597,12 @@ public class BusinessServiceImpl implements IBusinessService {
         AmsTask amsTask = new AmsTask();
         amsTask.setTaskNo(wcsTask.getTaskNo());
         if (wcsTask.getBusinessType() == null || wcsTask.getBusinessType().equals("")) {
-            amsTask.setBusinessType("01");
+            amsTask.setBusinessType(Constant.TASK_BUSINESS_TYPE.TASK_01.getValue());
         } else {
             amsTask.setBusinessType(wcsTask.getBusinessType());
         }
-        amsTask.setIsDelete(null);
-        amsTask.setAciAccept(null);
+        amsTask.setIsDelete(0);
+        amsTask.setAciAccept(0);
         amsTask.setIkey((long)geniKey(amsTask.getTaskNo()));
         amsTask.setPriority(wcsTask.getPriority().intValue());
         amsTask.setStFrom(locFrom.getId().intValue());
@@ -653,6 +653,15 @@ public class BusinessServiceImpl implements IBusinessService {
                     break;
                 }
 
+                //转发任务
+                if (StringUtils.isNotEmpty(wcsTask.getTaskType())
+                        &&wcsTask.getTaskType().equals(Constant.TASK_TYPE.FORWARD.getValue())) {
+                    sendTask(wcsTask);
+                    wcsTask.setState(10L);
+                    wcsTaskService.updateWcsTask(wcsTask);
+                    break;
+                }
+
                 try {
                     //任务下发判断
                     businessService.taskDispatchStack(wcsTask);

+ 2 - 0
warewms-ams/src/main/java/com/ruoyi/ams/task/form/AddTaskForm.java

@@ -16,4 +16,6 @@ public class AddTaskForm {
     private String locationTo;
     @NotBlank(message = "任务类型不能为空")
     private String businessType;
+    @NotBlank(message = "是否转发不能为空")
+    private String taskType;
 }

+ 10 - 7
warewms-ams/src/main/resources/mapper/ams/WcsTaskMapper.xml

@@ -3,7 +3,7 @@
 PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.ruoyi.ams.task.mapper.WcsTaskMapper">
-    
+
     <resultMap type="WcsTask" id="WcsTaskResult">
         <result property="taskNo"    column="task_no"    />
         <result property="businessType"    column="business_type"    />
@@ -91,7 +91,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 
     <select id="selectWcsTaskList" parameterType="WcsTask" resultMap="WcsTaskResult">
         <include refid="selectWcsTaskVo"/>
-        <where>  
+        <where>
             <if test="locationFrom != null  and locationFrom != ''"> and location_from = #{locationFrom}</if>
             <if test="areaFrom != null  and areaFrom != ''"> and area_from = #{areaFrom}</if>
             <if test="locationTo != null  and locationTo != ''"> and location_to = #{locationTo}</if>
@@ -135,12 +135,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         </where>
         order by t.create_date desc
     </select>
-    
+
     <select id="selectWcsTaskByTaskNo" parameterType="String" resultMap="WcsTaskResult">
         <include refid="selectWcsTaskVo"/>
         where task_no = #{taskNo}
     </select>
-        
+
     <insert id="insertWcsTask" parameterType="WcsTask">
         insert into wcs_task
         <trim prefix="(" suffix=")" suffixOverrides=",">
@@ -271,7 +271,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </delete>
 
     <delete id="deleteWcsTaskByTaskNos" parameterType="String">
-        delete from wcs_task where task_no in 
+        delete from wcs_task where task_no in
         <foreach item="taskNo" collection="array" open="(" separator="," close=")">
             #{taskNo}
         </foreach>
@@ -282,7 +282,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
      </select>
 
     <select id="selectWcsUnallocated" resultMap="WcsTaskResult" parameterType="Long">
-        select * from wcs_task where state = 9
+        select *
+        from wcs_task
+        where state = 9
+        order by priority desc,create_date
     </select>
 
     <select id="selectTaskByColNo" resultMap="WcsTaskDTOResult">
@@ -323,4 +326,4 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         order by priority
     </select>
 
-</mapper>
+</mapper>

+ 80 - 0
warewms-base/src/main/java/com/ruoyi/base/constant/Constant.java

@@ -107,6 +107,86 @@ public class Constant {
         }
     }
 
+    /**
+     * 任务类型
+     */
+    public enum TASK_TYPE {
+        /**
+         * 转发任务
+         */
+        FORWARD("FW");
+        private String value;
+
+        TASK_TYPE(String value) {
+            this.value = value;
+        }
+
+        public String getValue() {
+            return value;
+        }
+    }
+
+    /**
+     * 任务状态 State
+     */
+    public enum TASK_STS {
+        /**
+         * 下发AMS
+         */
+        TASK0(0),
+        /**
+         * 开始
+         */
+        TASK1(1),
+        /**
+         * 完成
+         */
+        TASK2(2),
+        /**
+         * 开始取货
+         */
+        TASK3(3),
+        /**
+         * 取货完成
+         */
+        TASK4(4),
+        /**
+         * 开始卸货
+         */
+        TASK5(5),
+        /**
+         * 卸货完成
+         */
+        TASK6(6),
+        /**
+         * 取消
+         */
+        TASK7(7),
+        /**
+         * 空叉取消
+         */
+        TASK8(8),
+        /**
+         * 队列等待
+         */
+        TASK9(9),
+        /**
+         * 已下发
+         */
+        TASK10(10);
+
+
+        private Integer value;
+
+        public Integer getValue() {
+            return value;
+        }
+
+        TASK_STS(Integer value) {
+            this.value = value;
+        }
+    }
+
     public enum ZONE_TYPE {
         /**
          * 入库区域