Quellcode durchsuchen

充电机业务代码逻辑完善

k vor 1 Jahr
Ursprung
Commit
028b1ee9e4

+ 17 - 1
warewms-ams/src/main/java/com/ruoyi/ams/agv/ndc/service/ChargerButtProxy.java

@@ -26,7 +26,9 @@ public class ChargerButtProxy {
     /**
      * 一辆车对应一把锁
      */
-    Map<Integer, Lock> lockMap = new ConcurrentHashMap<>();
+    Map<Integer, Lock> lockStartMap = new ConcurrentHashMap<>();
+    Map<Integer, Lock> lockCancelMap = new ConcurrentHashMap<>();
+    Map<Integer, Lock> lockEndMap = new ConcurrentHashMap<>();
 
     /**
      * 请求标识
@@ -46,6 +48,20 @@ public class ChargerButtProxy {
      * @param agvNo
      */
     public void theChargingSynchronizer(Integer index, Integer chargingSite, Integer agvNo, CHARGER_BUTT_REQUEST request) {
+        Map<Integer, Lock> lockMap = null;
+        switch (request) {
+            case START:
+                lockMap = lockStartMap;
+                break;
+            case CANCEL:
+                lockMap = lockCancelMap;
+                break;
+            case END:
+                lockMap = lockEndMap;
+                break;
+            default:
+                break;
+        }
         // 当前的锁
         Lock currentLock;
         if (lockMap.get(agvNo) == null) {

+ 53 - 36
warewms-ams/src/main/java/com/ruoyi/ams/agv/ndc/service/ChargerButtService.java

@@ -5,6 +5,7 @@ import cn.hutool.core.date.DateUtil;
 import cn.hutool.json.JSONUtil;
 import com.ruoyi.ams.task.domain.WcsTask;
 import com.ruoyi.ams.task.service.IWcsTaskService;
+import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.common.core.redis.RedisCache;
 import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.hard.modbus.tcp.ChargingMachineClient;
@@ -49,7 +50,7 @@ public class ChargerButtService {
     private ChargingMachineClient chargingMachineClient;
 
     // 创建一个线程池
-    private ExecutorService executorService = new ThreadPoolExecutor(2, 10
+    private ExecutorService executorService = new ThreadPoolExecutor(2, 20
             , 60L, TimeUnit.SECONDS
             , new SynchronousQueue<Runnable>());
 
@@ -98,15 +99,15 @@ public class ChargerButtService {
         /***
          * B
          */
-        B(1, 1),
+        B(2, 1),
         /***
          * 空
          */
-        C(1, 1),
+        C(3, 1),
         /***
          * 无
          */
-        D(1, 1);
+        D(4, 1);
         private Integer chargerNo;
         private Integer slaveId;
 
@@ -180,33 +181,32 @@ public class ChargerButtService {
         // 如果已经开始充电 不可重复请求
         if (agvInfoMap.get(KEY_AGV_STS) != null
                 && agvInfoMap.get(KEY_AGV_STS).toString().equals(AGV_CHARGING_STS.START.toString())) {
+            log.error("充电机已经开始充电,不可重复请求!车号:{},充电机号:{}", agvNo, chargingSite);
             return;
         }
         // 如果是TS创建的充电任务 是没有对应的WcsTask任务 需要创建 并且设置到Redis
+        // 不管是不是wms下发的充电任务,为了方便我们都重新生成一条wcstask任务
         if (agvInfoMap.get(KEY_TASK_NO) == null || StringUtils.isEmpty(agvInfoMap.get(KEY_TASK_NO).toString())) {
-            // todo
-//            R r = wcsTaskService.addChargingTask(agvNo, chargingSite, index);
-//            if (!r.isOk()) {
-//                return;
-//            }
-//            taskNo = (String) r.get("taskNo");
-//            agvInfoMap.put(KEY_TASK_NO, taskNo);
-//            agvInfoMap.put(KEY_AGV_STS, AGV_CHARGING_STS.READY.toString());
-//            redisUtils.set(KEY_PREFIX + agvNo, agvInfoMap);
+            AjaxResult ajaxResult = wcsTaskService.addChargingTask(agvNo, chargingSite, index);
+            if (!ajaxResult.isSuccess()) {
+                log.error(ajaxResult.getMsg());
+                return;
+            }
+            taskNo = (String) ajaxResult.get("data");
+            agvInfoMap.put(KEY_TASK_NO, taskNo);
+            agvInfoMap.put(KEY_AGV_STS, AGV_CHARGING_STS.READY.toString());
+            redisCache.setCacheMap(KEY_PREFIX + agvNo, agvInfoMap);
         } else {
             taskNo = agvInfoMap.get(KEY_TASK_NO).toString();
         }
 
         // WcsTask
         WcsTask wcsTask = wcsTaskService.selectWcsTaskByTaskNo(taskNo);
-        if (wcsTask == null) {
-            return;
-        }
 
-        // 充电机号 用true和false表示
+        // 充电机号
         Integer chargerNo = chargingSite;
-        boolean xx = chargerNo == 1;
-        // 从节点ID todo 默认为
+        boolean xx = chargerNo == 2;
+        // 从节点ID 充电机根据不同的ip地址区分,从节点地址默认都是1
         Integer slaveId = CHARGING_SLAVEID_MAPPING.getSlaveIdByChargerNo(chargingSite);
         // 确认是否故障
         boolean isFault = this.confirmChargerStatus(IS_FAULT, new Date(), true, xx);
@@ -275,13 +275,14 @@ public class ChargerButtService {
         }
         // 没有充电桩号没办法取消对应的充电机
         if (chargingSite == null) {
+            log.error("没有充电桩号没办法取消对应的充电机!");
             return;
         }
         String taskNo = "";
         WcsTask wcsTask = null;
         // 充电机号
         Integer chargerNo = chargingSite;
-        boolean xx = chargerNo == 1;
+        boolean xx = chargerNo == 2;
         // 从节点ID
         Integer slaveId = CHARGING_SLAVEID_MAPPING.getSlaveIdByChargerNo(chargingSite);
         // 从Redis拿到充电信息
@@ -307,10 +308,12 @@ public class ChargerButtService {
             this.feedbackTSLog(taskNo, index, FAULT, agvNo + ",确认信号:无压紧、无充电、归位,失败!", xx);
         }
         // 判断先前是否收到过4003消息的标识
-        boolean con = wcsTask != null ? wcsTask.getExt4().equals("1") : false;
-        if (!con) {
-            // 反馈TS结束充电
-            this.feedbackTSLog(taskNo, index, AGV_STOP, agvNo + ",AGV结束充电!", xx);
+        if (wcsTask != null) {
+            boolean con = wcsTask.getExt4().equals("1") ? true : false;
+            if (!con) {
+                // 反馈TS结束充电
+                this.feedbackTSLog(taskNo, index, AGV_STOP, agvNo + ",AGV结束充电!", xx);
+            }
         }
         // 下发一个TS101的任务
         feedbackTS.feedbackTS101(taskNo, index, agvNo);
@@ -335,7 +338,7 @@ public class ChargerButtService {
         String taskNo = "";
         WcsTask wcsTask;
         // 从redis拿到充电信息
-        Map<String, Object> agvInfoMap = redisCache.getCacheMap(KEY_PREFIX);
+        Map<String, Object> agvInfoMap = redisCache.getCacheMap(KEY_PREFIX + agvNo);
         // 拿到对应WcsTask任务号
         if (agvInfoMap != null && agvInfoMap.get(KEY_TASK_NO) != null
                 && StringUtils.isNotEmpty(agvInfoMap.get(KEY_TASK_NO).toString())) {
@@ -450,24 +453,38 @@ public class ChargerButtService {
                 WcsTask wcsTask = wcsTaskService.selectWcsTaskByTaskNo(taskNo);
 
                 // 查询充电机状态是否为完成(确认信号:无压紧、无充电、归位),充电机充电完成会自动停止放电 退回伸缩杆、归位
-                boolean isEnd = chargerButtService.confirmChargerStatus(IS_END, new Date(), false,xx);
+                boolean isEnd = chargerButtService.confirmChargerStatus(IS_END, new Date(), false, xx);
                 if (isEnd) {
                     // 判断先前是否收到过4003消息的标识
-                    boolean con = wcsTask != null ? wcsTask.getExt4().equals("1") : false;
-                    if (!con) {
-                        // 反馈TS结束充电
-                        chargerButtService.feedbackTSLog(taskNo, index, AGV_STOP, agvNo + "AGV充电结束!", xx);
+                    if (wcsTask != null) {
+                        boolean con = wcsTask.getExt4().equals("1") ? true : false;
+                        if (!con) {
+                            // 反馈TS结束充电
+                            chargerButtService.feedbackTSLog(taskNo, index, AGV_STOP, agvNo + "AGV充电结束!", xx);
+                        }
                     }
                     // 下发一个TS101的任务
                     feedbackTS.feedbackTS101(taskNo, index, agvNo);
+                    // 设置Redis充电状态为停止
+                    Map<String, Object> agvInfoMapU = redisCache.getCacheMap(KEY_PREFIX + agvNo);
+                    if (agvInfoMapU != null) {
+                        agvInfoMapU.put(KEY_AGV_STS, AGV_CHARGING_STS.STOP.toString());
+                        redisCache.setCacheMap(KEY_PREFIX + agvNo, agvInfoMapU);
+                    }
                     break;
                 }
                 // 查询充电机是否故障 关闭充电机 停止充电
-                boolean isFault = chargerButtService.confirmChargerStatus(IS_FAULT, new Date(), false,xx);
+                boolean isFault = chargerButtService.confirmChargerStatus(IS_FAULT, new Date(), false, xx);
                 if (isFault) {
                     chargerButtService.operation(STOP, xx);
                     // 反馈TS充电机故障
                     chargerButtService.feedbackTSLog(taskNo, index, FAULT, agvNo + ",充电机故障!", xx);
+                    // 设置Redis充电状态为停止
+                    Map<String, Object> agvInfoMapU = redisCache.getCacheMap(KEY_PREFIX + agvNo);
+                    if (agvInfoMapU != null) {
+                        agvInfoMapU.put(KEY_AGV_STS, AGV_CHARGING_STS.STOP.toString());
+                        redisCache.setCacheMap(KEY_PREFIX + agvNo, agvInfoMapU);
+                    }
                     break;
                 }
                 try {
@@ -586,11 +603,11 @@ public class ChargerButtService {
         // 待机
         boolean bit_04_0 = BIT_04_0.isTrue(status);
         // 在线
-        boolean bit_04_5 = BIT_04_5.isTrue(status);
+//        boolean bit_04_5 = BIT_04_5.isTrue(status);
 
 
         // 所有的是true 返回true
-        boolean result = Stream.of(bit_04_0, bit_04_5).allMatch(t -> t == true);
+        boolean result = Stream.of(bit_04_0/*, bit_04_5*/).allMatch(t -> t == true);
 
         return result;
     }
@@ -647,20 +664,20 @@ public class ChargerButtService {
         // 短路
         boolean bit_05_3 = BIT_05_3.isTrue(status);
         // 电池未接
-        boolean bit_05_4 = BIT_05_4.isTrue(status);
+//        boolean bit_05_4 = BIT_05_4.isTrue(status);
         // 电池反接
         boolean bit_05_5 = BIT_05_5.isTrue(status);
         // 模块通信故障
         boolean bit_05_6 = BIT_05_6.isTrue(status);
         // Can通信超时
-        boolean bit_05_7 = BIT_05_7.isTrue(status);
+//        boolean bit_05_7 = BIT_05_7.isTrue(status);
 
         // 伸缩故障
         boolean bit_06_5 = BIT_06_5.isTrue(status);
 
         // 如果任何一个是true 返回true
         boolean result = Stream.of(bit_04_1
-                , bit_05_0, bit_05_1, bit_05_2, bit_05_3, bit_05_4, bit_05_5, bit_05_6, bit_05_7
+                , bit_05_0, bit_05_1, bit_05_2, bit_05_3, /*bit_05_4,*/ bit_05_5, bit_05_6/*, bit_05_7*/
                 , bit_06_5).anyMatch(t -> t == true);
 
         return result;

+ 59 - 51
warewms-ams/src/main/java/com/ruoyi/ams/agv/ndc/service/FeedbackTS.java

@@ -1,8 +1,14 @@
 package com.ruoyi.ams.agv.ndc.service;
 
+import com.ruoyi.ams.agv.ndc.domain.AmsTask;
+import com.ruoyi.ams.business.BusinessServiceImpl;
+import com.ruoyi.base.constant.Constant;
+import com.ruoyi.common.utils.uuid.SnowflakeIdWorker;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.List;
+
 /**
  * @author JWK
  * @version 1.0
@@ -61,66 +67,68 @@ public class FeedbackTS {
      * @param tsStatus
      */
     public void feedbackTS(String taskNo, Integer index, FEEDBACK_TS_STATUS tsStatus) {
-//        AddTaskForm addTaskForm = new AddTaskForm();
-//        addTaskForm.setTaskNo(SnowflakeIdWorker.generateId().toString());
-//        addTaskForm.setBusinessType(Constant.TASK_BUSINESS_TYPE.TASK_m.getValue());
-//        addTaskForm.setExt1(index.toString());
-//        addTaskForm.setLocationFrom("998");
-//        addTaskForm.setLocationTo("999");
-//        addTaskForm.setPriority("1");
-//        addTaskForm.setRemark(taskNo);
-//        // 把第address位变为value
-//        addTaskForm.setExt2(tsStatus.getAddress());
-//        addTaskForm.setExt3(tsStatus.getValue());
-//
-//        // 如果ams_task已经有此任务的待接收m消息,则不生成新的m消息
-//        AmsTask amsTaskQuery = new AmsTask();
-//        amsTaskQuery.setAciAccept(0);
-//        amsTaskQuery.setIsDelete(0);
-//        amsTaskQuery.setRemark(taskNo);
-//        amsTaskQuery.setBusinessType(Constant.TASK_BUSINESS_TYPE.TASK_m.getValue());
-//        amsTaskQuery.setExt1(addTaskForm.getExt1());
-//        amsTaskQuery.setExt2(addTaskForm.getExt2());
-//        amsTaskQuery.setExt3(addTaskForm.getExt3());
-//        List<AmsTask> undoneList = amsTaskService.findByModel(amsTaskQuery);
-//        if (undoneList.size() > 0) {
-//            return;
-//        }
-//        amsTaskService.addTask(addTaskForm);
+        AmsTask addTaskForm = new AmsTask();
+        addTaskForm.setTaskNo(SnowflakeIdWorker.generateId().toString());
+        addTaskForm.setIkey((long) BusinessServiceImpl.geniKey(addTaskForm.getTaskNo()));
+        addTaskForm.setBusinessType(Constant.TASK_BUSINESS_TYPE.TASK_m.getValue());
+        addTaskForm.setStFrom(998);
+        addTaskForm.setStTo(999);
+        addTaskForm.setPriority(1);
+        addTaskForm.setRemark(taskNo);
+        addTaskForm.setExt1(index.toString());
+        // 把第address位变为value
+        addTaskForm.setExt2(tsStatus.getAddress());
+        addTaskForm.setExt3(tsStatus.getValue());
+
+        // 如果ams_task已经有此任务的待接收m消息,则不生成新的m消息
+        AmsTask amsTaskQuery = new AmsTask();
+        amsTaskQuery.setAciAccept(0);
+        amsTaskQuery.setIsDelete(0);
+        amsTaskQuery.setRemark(taskNo);
+        amsTaskQuery.setBusinessType(Constant.TASK_BUSINESS_TYPE.TASK_m.getValue());
+        amsTaskQuery.setExt1(addTaskForm.getExt1());
+        amsTaskQuery.setExt2(addTaskForm.getExt2());
+        amsTaskQuery.setExt3(addTaskForm.getExt3());
+        List<AmsTask> undoneList = amsTaskService.selectAmsTaskList(amsTaskQuery);
+        if (undoneList.size() > 0) {
+            return;
+        }
+        amsTaskService.insertAmsTask(addTaskForm);
     }
 
     /**
-     * 反馈TS:通过给参数address改值value来反馈
+     * 反馈TS
      *
      * @param taskNo 任务号 可以为空
      * @param index TS任务号 可以为空
      * @param agvNo
      */
     public void feedbackTS101(String taskNo, Integer index, Integer agvNo) {
-//        AddTaskForm addTaskForm = new AddTaskForm();
-//        addTaskForm.setTaskNo(SnowflakeIdWorker.generateId().toString());
-//        addTaskForm.setBusinessType(Constant.TASK_BUSINESS_TYPE.TASK_101.getValue());
-//        addTaskForm.setExt1(index.toString());
-//        addTaskForm.setLocationFrom("998");
-//        addTaskForm.setLocationTo("999");
-//        addTaskForm.setPriority("1");
-//        addTaskForm.setRemark(taskNo);
-//        // 固定写法
-//        addTaskForm.setExt2(agvNo.toString());
-//        addTaskForm.setExt3("0004");
-//
-//        // 如果ams_task已经有此任务的待接收消息,则不生成新的消息
-//        AmsTask amsTaskQuery = new AmsTask();
-//        amsTaskQuery.setAciAccept(0);
-//        amsTaskQuery.setIsDelete(0);
-//        amsTaskQuery.setBusinessType(Constant.TASK_BUSINESS_TYPE.TASK_101.getValue());
-//        amsTaskQuery.setExt2(addTaskForm.getExt2());
-//        amsTaskQuery.setExt3(addTaskForm.getExt3());
-//        List<AmsTask> undoneList = amsTaskService.findByModel(amsTaskQuery);
-//        if (undoneList.size() > 0) {
-//            return;
-//        }
-//        amsTaskService.addTask(addTaskForm);
+        AmsTask addTaskForm = new AmsTask();
+        addTaskForm.setTaskNo(SnowflakeIdWorker.generateId().toString());
+        addTaskForm.setIkey((long) BusinessServiceImpl.geniKey(addTaskForm.getTaskNo()));
+        addTaskForm.setBusinessType(Constant.TASK_BUSINESS_TYPE.TASK_101.getValue());
+        addTaskForm.setExt1(index.toString());
+        addTaskForm.setStFrom(998);
+        addTaskForm.setStTo(999);
+        addTaskForm.setPriority(1);
+        addTaskForm.setRemark(taskNo);
+        // 固定写法
+        addTaskForm.setExt2(agvNo.toString());
+        addTaskForm.setExt3("0004");
+
+        // 如果ams_task已经有此任务的待接收消息,则不生成新的消息
+        AmsTask amsTaskQuery = new AmsTask();
+        amsTaskQuery.setAciAccept(0);
+        amsTaskQuery.setIsDelete(0);
+        amsTaskQuery.setBusinessType(Constant.TASK_BUSINESS_TYPE.TASK_101.getValue());
+        amsTaskQuery.setExt2(addTaskForm.getExt2());
+        amsTaskQuery.setExt3(addTaskForm.getExt3());
+        List<AmsTask> undoneList = amsTaskService.selectAmsTaskList(amsTaskQuery);
+        if (undoneList.size() > 0) {
+            return;
+        }
+        amsTaskService.insertAmsTask(addTaskForm);
     }
 
 }

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

@@ -17,13 +17,10 @@ import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.SynchronousQueue;
-import java.util.concurrent.ThreadPoolExecutor;
-import java.util.concurrent.TimeUnit;
+import java.util.concurrent.*;
 
 import static com.ruoyi.ams.agv.ndc.service.ChargerButtService.*;
-import static com.ruoyi.ams.agv.ndc.service.impl.StatusUpdateServiceImpl.AGV_ACTION.*;
+import static com.ruoyi.ams.agv.ndc.service.ChargerButtProxy.CHARGER_BUTT_REQUEST.*;
 
 /**
  * Created by IntelliJ IDEA.
@@ -211,9 +208,7 @@ public class SocketBufferServiceImpl implements SocketBufferService {
                         log.info("aciIndex:" + aciIndex + "查询不到对应的60任务");
                     } else {
                         //解析卸货确认状态
-                        executorService.execute(() -> {
-                            statusUpdateService.confirmAnalysis(task60.getTaskNo(), aciIndex, PICKUP.getValue(), icarNo);
-                        });
+                        // agvUnloadingConfirmService.confirmAnalysis(task60.getTaskNo(), aciIndex, "unload", icarNo);
                     }
                     break;
                 case 115:
@@ -228,10 +223,8 @@ public class SocketBufferServiceImpl implements SocketBufferService {
                     if (task60Pick == null) {
                         log.info("aciIndex:" + aciIndexPick + "查询不到对应的60任务");
                     } else {
-                        //解析卸货确认状态
-                        executorService.execute(() -> {
-                            statusUpdateService.confirmAnalysis(task60Pick.getTaskNo(), aciIndexPick, UNLOAD.getValue(), icarNo);
-                        });
+                        //解析取货确认状态
+                        // agvUnloadingConfirmService.confirmAnalysis(task60Pick.getTaskNo(), aciIndexPick, "pickup", icarNo);
                     }
                     break;
                 case 122:
@@ -250,28 +243,28 @@ public class SocketBufferServiceImpl implements SocketBufferService {
                     }
                     break;
                 case 123:
-                    log.info("申请称重机!" + "-" + JSON.toJSONString(event));
-                    Integer index123 = Integer.parseInt(event.getLp1());
-                    AmsTask task123 = amsTaskService.selectAmsTaskByModel(index123);
-                    if (task123 != null) {
-                        executorService.execute(() -> {
-                            statusUpdateService.confirmAnalysis(task123.getTaskNo(), index123, icarNo
-                                    , "10", "0001");
-                        });
+                    //空托盘堆叠层数申请
+                    log.info("空托盘堆叠层数申请");
+                    Integer index130 = Integer.parseInt(event.getLp1());
+                    AmsTask task130 = new AmsTask();
+                    task130.setAciIndex(index130);
+                    task130 = amsTaskService.selectAmsTaskByModel(task130);
+                    if (task130 != null) {
+                        // agvUnloadingConfirmService.confirmEmptyPlate(task130.getTaskNo());
                     }
                     break;
-                case 126: // 中间卷帘门请求开启 定时请求
+                case 126: //600 中间卷帘门请求开启 定时请求
                     log.info("快速门-请求开启!" + "-" + JSON.toJSONString(event));
-                    String lp1_126 = event.getLp1();
+                    String lp3_126 = event.getLp3();
                     executorService.execute(() -> {
-                        statusUpdateService.openDoor(Integer.valueOf(lp1_126));
+                        statusUpdateService.openDoor(Integer.valueOf(lp3_126));
                     });
                     break;
-                case 127: // 中间卷帘门请求关闭 只请求一次
+                case 127: //601 中间卷帘门请求关闭 只请求一次
                     log.info("快速门-请求关闭!" + "-" + JSON.toJSONString(event));
-                    String lp1_127 = event.getLp1();
+                    String lp3_127 = event.getLp3();
                     executorService.execute(() -> {
-                        statusUpdateService.closeDoor(Integer.valueOf(lp1_127));
+                        statusUpdateService.closeDoor(Integer.valueOf(lp3_127));
                     });
                     break;
                 case 134:
@@ -317,7 +310,8 @@ public class SocketBufferServiceImpl implements SocketBufferService {
                     task139 = amsTaskService.selectAmsTaskByModel(task139);
                     // agvUnloadingConfirmService.agvError(event,task139);
                     break;
-                case 200://NDC eCode = 4001 | 5秒一次 | 4001消息:4001+充电站点+INDEX+车号
+                case 200://NDC eCode = 4001 | 5秒一次 | 4001消息:充电站点 + INDEX + 车号
+                    log.info("充电消息4001:AGV已经达到充电位置!" + "-" + JSON.toJSONString(event));
                     Integer chargingSite200 = Integer.parseInt(event.getLp1());// 充电站点
                     Integer index200 = Integer.parseInt(event.getLp2());// index
                     Integer agvNo200 = Integer.parseInt(event.getLp3());// 车号
@@ -339,10 +333,11 @@ public class SocketBufferServiceImpl implements SocketBufferService {
                   2.而index在TS系统里是循环使用的,所以很大概率会把错误的任务号查询出来。
                */
                     executorService.execute(() -> {
-//                        chargerButtProxy.theChargingSynchronizer(index200, chargingSite200, agvNo200, START);
+                        chargerButtProxy.theChargingSynchronizer(index200, chargingSite200, agvNo200, START);
                     });
                     break;
-                case 201://NDC eCode = 4002 | 5秒一次 | 4002消息:两种情况,第一种充电机报错情况下的4002消息——4002+0+0+0+车号,第二种正常充电情况下的4002消息——4002+0+0+1+车号;
+                case 201://NDC eCode = 4002 | 5秒一次 | 4002消息:两种情况,第一种充电机报错情况下的4002消息——0+0+0+车号,第二种正常充电情况下的4002消息——0+0+1+车号;
+                    log.info("充电消息4002:AGV充电任务被人为取消!" + "-" + JSON.toJSONString(event));
                     Integer agvNo201 = Integer.parseInt(event.getLp4()); // 车号
                     Map<String, Object> agvParamsMap01 = redisCache.getCacheMap(KEY_PREFIX + agvNo201);
                     if (agvParamsMap01.size() == 0) {
@@ -353,10 +348,11 @@ public class SocketBufferServiceImpl implements SocketBufferService {
                     log.info("充电消息4002:AGV充电任务被人为取消!车号:" + agvNo201 + ",充电桩:" + chargingSite201 + ",index:" + index201);
                     // 因为车体主动取消的任务是没有index号和充电桩站点号的,所以这里只能处理根据车号处理业务。
                     executorService.execute(() -> {
-//                        chargerButtProxy.theChargingSynchronizer(index201, chargingSite201, agvNo201, CANCEL);
+                        chargerButtProxy.theChargingSynchronizer(index201, chargingSite201, agvNo201, CANCEL);
                     });
                     break;
-                case 202://NDC eCode = 4003 | 4003消息:4003+车号
+                case 202://NDC eCode = 4003 | 4003消息:车号
+                    log.info("充电消息4003:AGV充电任务结束!" + "-" + JSON.toJSONString(event));
                     Integer agvNo202 = Integer.parseInt(event.getLp1()); // 车号
                     Map<String, Object> agvParamsMap02 = redisCache.getCacheMap(KEY_PREFIX + agvNo202);
                     if (agvParamsMap02.size() == 0) {
@@ -367,7 +363,7 @@ public class SocketBufferServiceImpl implements SocketBufferService {
                     log.info("充电消息4003:AGV充电任务结束!车号:" + agvNo202 + ",充电桩:" + chargingSite202 + ",index:" + index202);
                     // 因为车体主动取消的任务是没有index号和充电桩站点号的,所以这里只能处理根据车号处理业务。
                     executorService.execute(() -> {
-//                        chargerButtProxy.theChargingSynchronizer(index202, chargingSite202, agvNo202, END);
+                        chargerButtProxy.theChargingSynchronizer(index202, chargingSite202, agvNo202, END);
                     });
                     break;
                 default:

+ 7 - 0
warewms-ams/src/main/java/com/ruoyi/ams/task/service/IWcsTaskService.java

@@ -70,6 +70,13 @@ public interface IWcsTaskService {
      */
     int deleteWcsTaskByTaskNos(String[] taskNos);
 
+
+    /**
+     * 新增充电任务
+     * @return
+     */
+    AjaxResult addChargingTask(Integer agvNo, Integer chargingSite, Integer index);
+
     /**
      * 删除AGV任务信息
      *

+ 34 - 0
warewms-ams/src/main/java/com/ruoyi/ams/task/service/impl/WcsTaskServiceImpl.java

@@ -23,6 +23,7 @@ import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.common.core.redis.RedisCache;
 import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.common.utils.spring.SpringUtils;
+import com.ruoyi.common.utils.uuid.SnowflakeIdWorker;
 import com.ruoyi.hard.modbus.tcp.AutoDoorClient;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -164,6 +165,39 @@ public class WcsTaskServiceImpl implements IWcsTaskService {
         return wcsTaskMapper.deleteWcsTaskByTaskNos(taskNos);
     }
 
+    /**
+     * 增加充电任务(TS触发触发任务反馈)
+     * @param agvNo 车号
+     * @param chargingSite 充电桩号
+     * @param index TS任务号
+     * @return
+     */
+    @Override
+    public AjaxResult addChargingTask(Integer agvNo, Integer chargingSite, Integer index) {
+        WcsTask wcsTask = new WcsTask();
+        String taskNo = SnowflakeIdWorker.generateId().toString();
+        wcsTask.setTaskNo(taskNo);
+        wcsTask.setBusinessType(Constant.TASK_BUSINESS_TYPE.TASK_POWER.getValue());
+        wcsTask.setShopId(Constant.WAREHOUSE_ID.toString());
+        wcsTask.setLocationFrom("998");
+        wcsTask.setLocationTo("997");
+        wcsTask.setDeviceName(agvNo.toString());
+        wcsTask.setState(Constant.TASK_STS.TASK2.getValue().longValue());
+        wcsTask.setPriority(1L);
+        wcsTask.setTaskType("POWER");
+        wcsTask.setAgvNo(agvNo.toString());//车号
+        wcsTask.setRemark("充电任务!");
+        wcsTask.setExt1(chargingSite.toString());
+        wcsTask.setExt2(index.toString());
+        wcsTask.setCreateDate(new Date());
+        wcsTask.setCreateUser("TS");
+        int i = wcsTaskService.insertWcsTask(wcsTask);
+        if (i<=0) {
+            return AjaxResult.error("生成充电WcsTask任务失败!");
+        }
+        return AjaxResult.success(taskNo);
+    }
+
     /**
      * 删除AGV任务信息
      *