From e6ca4536f16dc118b84bd577a8402eb314a24f7c Mon Sep 17 00:00:00 2001
From: tuqiang <437016993@qq.com>
Date: Thu, 22 May 2025 15:29:45 +0800
Subject: [PATCH] =?UTF-8?q?rev:=E4=BC=98=E5=8C=96=E6=89=8B=E5=8A=A8?=
 =?UTF-8?q?=E5=88=9B=E5=BB=BA=E6=8C=87=E4=BB=A4?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../org/nl/acs/task/service/TaskService.java  |   2 +-
 .../task/service/impl/TaskServiceImpl.java    | 187 +++++++++++++-----
 .../main/resources/config/application-dev.yml |   3 +-
 3 files changed, 141 insertions(+), 51 deletions(-)

diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/task/service/TaskService.java b/acs/nladmin-system/src/main/java/org/nl/acs/task/service/TaskService.java
index 44fbc41..55a0ce1 100644
--- a/acs/nladmin-system/src/main/java/org/nl/acs/task/service/TaskService.java
+++ b/acs/nladmin-system/src/main/java/org/nl/acs/task/service/TaskService.java
@@ -200,7 +200,7 @@ public interface TaskService {
      *
      * @param ids
      */
-    Instruction createInst(String ids) throws Exception;
+    void createInst(String ids) throws Exception;
 
     Instruction createInst(Instruction inst) throws Exception;
 
diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/task/service/impl/TaskServiceImpl.java b/acs/nladmin-system/src/main/java/org/nl/acs/task/service/impl/TaskServiceImpl.java
index 6863553..e268c7e 100644
--- a/acs/nladmin-system/src/main/java/org/nl/acs/task/service/impl/TaskServiceImpl.java
+++ b/acs/nladmin-system/src/main/java/org/nl/acs/task/service/impl/TaskServiceImpl.java
@@ -12,6 +12,7 @@ import com.alibaba.fastjson.JSONObject;
 import lombok.RequiredArgsConstructor;
 import lombok.Synchronized;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.ObjectUtils;
 import org.nl.acs.AcsConfig;
 import org.nl.acs.agv.server.XianGongAgvService;
 import org.nl.acs.auto.initial.ApplicationAutoInitial;
@@ -1085,65 +1086,146 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
         return instdto;
     }
 
+//    @Override
+//    public Instruction createInst(String ids) throws Exception {
+//        TaskDto acsTask = this.findById(ids);
+//        if (acsTask == null) {
+//            throw new BadRequestException("被删除或无权限,操作失败!");
+//        }
+//        DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class);
+//        InstructionService instructionservice = SpringContextHolder.getBean("instructionServiceImpl");
+//        InstructionDto inst = instructionservice.findByTaskid(ids, "instruction_status < 2 ");
+//        if (inst != null) {
+//            throw new BadRequestException("有指令未完成!");
+//        }
+//
+//        String taskid = acsTask.getTask_id();
+//        String taskcode = acsTask.getTask_code();
+//        String vehiclecode = acsTask.getVehicle_code();
+//        String priority = acsTask.getPriority();
+//        String start_point_code = acsTask.getStart_point_code();
+//        String start_device_code = acsTask.getStart_device_code();
+//        String route_plan_code = acsTask.getRoute_plan_code();
+//        String vehicleType = acsTask.getVehicle_type();
+//        // 是否复合任务 =0非复合任务
+//        String compound_task = acsTask.getCompound_task();
+//        String next_point_code = acsTask.getNext_point_code();
+//        String next_device_code = acsTask.getNext_device_code();
+//        String start_point_code2 = acsTask.getStart_point_code2();
+//        String next_point_code2 = acsTask.getNext_point_code2();
+//        String agv_system_type = acsTask.getAgv_system_type();
+//        String task_type = acsTask.getTask_type();
+//        /** 开始平均分解校验 */
+//        String this_device_code =
+//                this.queryAssignedByDevice(acsTask.getStart_device_code(), acsTask.getNext_device_code());
+//        if (StrUtil.isEmpty(this_device_code)) {
+//            List<RouteLineDto> shortPathsList =
+//                    routeLineService.getShortPathLines(
+//                            start_device_code, acsTask.getNext_device_code(), route_plan_code);
+//            RouteLineDto routeLineDto = shortPathsList.get(0);
+//            String path = routeLineDto.getPath();
+//            String type = routeLineDto.getType();
+//            String[] str = path.split("->");
+//            List<String> pathlist = Arrays.asList(str);
+//            int index = 0;
+//            for (int m = 0; m < pathlist.size(); m++) {
+//                if (pathlist.get(m).equals(start_device_code)) {
+//                    index = m + 1;
+//                    break;
+//                }
+//            }
+//            next_device_code = pathlist.get(index);
+//        } else {
+//            next_device_code = this_device_code;
+//        }
+//
+//        if (StrUtil.equals(appService.findDeviceTypeByCode(next_device_code), "storage")) {
+//            next_point_code = next_device_code + "-" + acsTask.getTo_y() + "-" + acsTask.getTo_z();
+//        } else {
+//            next_point_code = next_device_code;
+//        }
+//
+//        Instruction instdto = new Instruction();
+//        instdto.setInstruction_type(task_type);
+//        instdto.setInstruction_id(IdUtil.simpleUUID());
+//        instdto.setRoute_plan_code(route_plan_code);
+//        instdto.setRemark(acsTask.getRemark());
+//        instdto.setMaterial(acsTask.getMaterial());
+//        instdto.setQuantity(acsTask.getQuantity());
+//        instdto.setTask_id(taskid);
+//        instdto.setTask_code(taskcode);
+//        instdto.setVehicle_code(vehiclecode);
+//        String now = DateUtil.now();
+//        instdto.setCreate_time(now);
+//        instdto.setCreate_by("auto");
+//        instdto.setStart_device_code(start_device_code);
+//        instdto.setNext_device_code(next_device_code);
+//        instdto.setStart_point_code(start_point_code);
+//        instdto.setNext_point_code(next_point_code);
+//        instdto.setPriority(priority);
+//        instdto.setInstruction_status("0");
+//        instdto.setExecute_device_code(start_point_code);
+//        instdto.setVehicle_type(vehicleType);
+//        instdto.setStart_point_code2(start_point_code2);
+//        instdto.setStart_device_code2(start_point_code2);
+//        instdto.setNext_device_code2(next_point_code2);
+//        instdto.setNext_point_code2(next_point_code2);
+//        instdto.setAgv_system_type(agv_system_type);
+//        instdto.setAgv_inst_type("1");
+//        instructionservice.create2(instdto);
+//
+//        //        acsTask.setTask_status("1");
+//        //        this.update(acsTask);
+//        return instdto;
+//    }
+
     @Override
-    public Instruction createInst(String ids) throws Exception {
+    @Transactional(rollbackFor = Exception.class)
+    public void createInst(String ids) throws Exception {
         TaskDto acsTask = this.findById(ids);
-        if (acsTask == null) {
-            throw new BadRequestException("被删除或无权限,操作失败!");
-        }
-        DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class);
+        if (acsTask == null) throw new BadRequestException("被删除或无权限,操作失败!");
         InstructionService instructionservice = SpringContextHolder.getBean("instructionServiceImpl");
         InstructionDto inst = instructionservice.findByTaskid(ids, "instruction_status < 2 ");
         if (inst != null) {
             throw new BadRequestException("有指令未完成!");
         }
-
         String taskid = acsTask.getTask_id();
         String taskcode = acsTask.getTask_code();
+        String task_type = acsTask.getTask_type();
         String vehiclecode = acsTask.getVehicle_code();
+        String storage_task_type = acsTask.getStorage_task_type();
         String priority = acsTask.getPriority();
-        String start_point_code = acsTask.getStart_point_code();
+        String is_send = acsTask.getIs_send();
+
         String start_device_code = acsTask.getStart_device_code();
-        String route_plan_code = acsTask.getRoute_plan_code();
-        String vehicleType = acsTask.getVehicle_type();
-        // 是否复合任务 =0非复合任务
-        String compound_task = acsTask.getCompound_task();
-        String next_point_code = acsTask.getNext_point_code();
+        String start_point_code = acsTask.getStart_point_code();
+
+        String put_device_code = acsTask.getPut_device_code();
+        String put_point_code = acsTask.getPut_point_code();
+
         String next_device_code = acsTask.getNext_device_code();
+        String next_point_code = acsTask.getNext_point_code();
+
         String start_point_code2 = acsTask.getStart_point_code2();
+        String start_device_code2 = acsTask.getStart_device_code2();
+
         String next_point_code2 = acsTask.getNext_point_code2();
+        String next_device_code2 = acsTask.getNext_device_code2();
+
+
+        String route_plan_code = acsTask.getRoute_plan_code();
+        String vehicleType = acsTask.getVehicle_type();
         String agv_system_type = acsTask.getAgv_system_type();
-        String task_type = acsTask.getTask_type();
-        /** 开始平均分解校验 */
-        String this_device_code =
-                this.queryAssignedByDevice(acsTask.getStart_device_code(), acsTask.getNext_device_code());
-        if (StrUtil.isEmpty(this_device_code)) {
-            List<RouteLineDto> shortPathsList =
-                    routeLineService.getShortPathLines(
-                            start_device_code, acsTask.getNext_device_code(), route_plan_code);
-            RouteLineDto routeLineDto = shortPathsList.get(0);
-            String path = routeLineDto.getPath();
-            String type = routeLineDto.getType();
-            String[] str = path.split("->");
-            List<String> pathlist = Arrays.asList(str);
-            int index = 0;
-            for (int m = 0; m < pathlist.size(); m++) {
-                if (pathlist.get(m).equals(start_device_code)) {
-                    index = m + 1;
-                    break;
-                }
-            }
-            next_device_code = pathlist.get(index);
-        } else {
-            next_device_code = this_device_code;
+        if (StrUtil.isEmpty(start_device_code)) {
+            throw new BadRequestException("起点设备为空,无法生成指令。");
         }
-
-        if (StrUtil.equals(appService.findDeviceTypeByCode(next_device_code), "storage")) {
-            next_point_code = next_device_code + "-" + acsTask.getTo_y() + "-" + acsTask.getTo_z();
-        } else {
-            next_point_code = next_device_code;
+        if (StrUtil.isEmpty(next_device_code)) {
+            throw new BadRequestException("终点设备为空,无法生成指令。");
         }
 
+
+
+
         Instruction instdto = new Instruction();
         instdto.setInstruction_type(task_type);
         instdto.setInstruction_id(IdUtil.simpleUUID());
@@ -1157,25 +1239,32 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
         String now = DateUtil.now();
         instdto.setCreate_time(now);
         instdto.setCreate_by("auto");
+
         instdto.setStart_device_code(start_device_code);
-        instdto.setNext_device_code(next_device_code);
         instdto.setStart_point_code(start_point_code);
+        instdto.setPut_device_code(put_device_code);
+        instdto.setPut_point_code(put_point_code);
+        instdto.setNext_device_code(next_device_code);
         instdto.setNext_point_code(next_point_code);
+
+        instdto.setStart_point_code2(start_point_code2);
+        instdto.setStart_device_code2(start_device_code2);
+        instdto.setNext_point_code2(next_point_code2);
+        instdto.setNext_device_code2(next_device_code2);
+
         instdto.setPriority(priority);
         instdto.setInstruction_status("0");
         instdto.setExecute_device_code(start_point_code);
         instdto.setVehicle_type(vehicleType);
-        instdto.setStart_point_code2(start_point_code2);
-        instdto.setStart_device_code2(start_point_code2);
-        instdto.setNext_device_code2(next_point_code2);
-        instdto.setNext_point_code2(next_point_code2);
         instdto.setAgv_system_type(agv_system_type);
         instdto.setAgv_inst_type("1");
-        instructionservice.create2(instdto);
 
-        //        acsTask.setTask_status("1");
-        //        this.update(acsTask);
-        return instdto;
+
+        try {
+            instructionService.create(instdto);
+        } catch (Exception e) {
+            acsTask.setRemark(e.getMessage());
+        }
     }
 
     @Override
diff --git a/acs/nladmin-system/src/main/resources/config/application-dev.yml b/acs/nladmin-system/src/main/resources/config/application-dev.yml
index cce6eb1..31e76d7 100644
--- a/acs/nladmin-system/src/main/resources/config/application-dev.yml
+++ b/acs/nladmin-system/src/main/resources/config/application-dev.yml
@@ -6,7 +6,8 @@ spring:
     druid:
       db-type: com.alibaba.druid.pool.DruidDataSource
       driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy
-      url: jdbc:log4jdbc:mysql://${DB_HOST:127.0.0.1}:${DB_PORT:3307}/${DB_NAME:gaosheng_acs}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true
+#      url: jdbc:log4jdbc:mysql://${DB_HOST:127.0.0.1}:${DB_PORT:3307}/${DB_NAME:gaosheng_acs}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true
+      url: jdbc:log4jdbc:mysql://${DB_HOST:127.0.0.1}:${DB_PORT:3306}/${DB_NAME:gaosheng_acs}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true&allowPublicKeyRetrieval=true
       username: ${DB_USER:root}
       password: ${DB_PWD:123456}
       # 初始连接数