From 4960be53d0d86b12018b37383e51dc91b2b77c6f Mon Sep 17 00:00:00 2001
From: yanps <yps00312>
Date: Tue, 12 Dec 2023 14:02:55 +0800
Subject: [PATCH] =?UTF-8?q?add:=20=E6=96=B0=E5=A2=9E=E5=88=9B=E5=BB=BA?=
 =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E7=AD=96=E7=95=A5=E5=AE=9E=E7=8E=B0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 hd/nladmin-system/pom.xml                     | 23 +++++++++++++-
 .../nl/acs/device/rest/DeviceController.java  |  8 +++++
 .../nl/acs/device/service/DeviceService.java  |  8 +++++
 .../service/impl/DeviceServiceImpl.java       | 29 +++++++++++++++++-
 .../StandardInspectSiteDeviceDriver.java      |  1 +
 .../StandardOrdinarySiteDeviceDriver.java     |  5 ++--
 .../java/org/nl/acs/opc/DeviceManageDto.java  |  1 +
 .../task/service/impl/TaskServiceImpl.java    | 30 +++++++++++++++----
 8 files changed, 96 insertions(+), 9 deletions(-)

diff --git a/hd/nladmin-system/pom.xml b/hd/nladmin-system/pom.xml
index e13ce6e..ca72adb 100644
--- a/hd/nladmin-system/pom.xml
+++ b/hd/nladmin-system/pom.xml
@@ -8,7 +8,6 @@
         <version>1.0-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
-
     <artifactId>nladmin-system</artifactId>
     <name>核心模块</name>
 
@@ -28,6 +27,28 @@
             <groupId>org.openscada.utgard</groupId>
             <artifactId>org.openscada.opc.lib</artifactId>
             <version>1.5.0</version>
+            <exclusions>
+                <exclusion>
+                    <groupId>org.bouncycastle</groupId>
+                    <artifactId>bcprov-jdk15on</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+        <dependency>
+            <groupId>net.sf.json-lib</groupId>
+            <artifactId>json-lib</artifactId>
+            <version>2.4</version>
+            <classifier>jdk15</classifier>
+        </dependency>
+        <dependency>
+            <groupId>com.hynnet</groupId>
+            <artifactId>jxl</artifactId>
+            <version>2.6.12.1</version>
+        </dependency>
+        <dependency>
+            <groupId>org.bouncycastle</groupId>
+            <artifactId>bcprov-jdk15on</artifactId>
+            <version>1.50</version>
         </dependency>
         <dependency>
             <groupId>com.squareup.okhttp3</groupId>
diff --git a/hd/nladmin-system/src/main/java/org/nl/acs/device/rest/DeviceController.java b/hd/nladmin-system/src/main/java/org/nl/acs/device/rest/DeviceController.java
index 08404a5..2b5452b 100644
--- a/hd/nladmin-system/src/main/java/org/nl/acs/device/rest/DeviceController.java
+++ b/hd/nladmin-system/src/main/java/org/nl/acs/device/rest/DeviceController.java
@@ -441,4 +441,12 @@ public class DeviceController {
         return new ResponseEntity<>(HttpStatus.CREATED);
     }
 
+    @Log("惠氏任务生成选择终点")
+    @ApiOperation("惠氏任务生成选择终点")
+    @GetMapping(value = "/endPoint")
+    public ResponseEntity<Object> selectEndPoint(String start_code) throws Exception {
+        List<String> endPoints  = deviceService.selectEndPoint(start_code);
+        return new ResponseEntity<>(endPoints, HttpStatus.OK);
+    }
+
 }
diff --git a/hd/nladmin-system/src/main/java/org/nl/acs/device/service/DeviceService.java b/hd/nladmin-system/src/main/java/org/nl/acs/device/service/DeviceService.java
index 2583b1a..6714359 100644
--- a/hd/nladmin-system/src/main/java/org/nl/acs/device/service/DeviceService.java
+++ b/hd/nladmin-system/src/main/java/org/nl/acs/device/service/DeviceService.java
@@ -296,4 +296,12 @@ public interface DeviceService {
     List<Device> findCacheDevice();
 
     void updateBarcode(JSONObject json) throws Exception;
+
+    /**
+     * 查询设备终端
+     *
+     * @param start_code 设备标识
+     * @return
+     */
+    List<String> selectEndPoint(String start_code);
 }
diff --git a/hd/nladmin-system/src/main/java/org/nl/acs/device/service/impl/DeviceServiceImpl.java b/hd/nladmin-system/src/main/java/org/nl/acs/device/service/impl/DeviceServiceImpl.java
index 19a6804..cd0c443 100644
--- a/hd/nladmin-system/src/main/java/org/nl/acs/device/service/impl/DeviceServiceImpl.java
+++ b/hd/nladmin-system/src/main/java/org/nl/acs/device/service/impl/DeviceServiceImpl.java
@@ -34,6 +34,8 @@ import org.nl.acs.device_driver.yzja_special.YzjaSpecialDeviceDriver;
 import org.nl.acs.opc.Device;
 import org.nl.acs.opc.DeviceAppService;
 import org.nl.acs.opc.DeviceAppServiceImpl;
+import org.nl.acs.route.service.RouteLineService;
+import org.nl.acs.route.service.dto.RouteLineDto;
 import org.nl.acs.task.service.TaskService;
 import org.nl.exception.BadRequestException;
 import org.nl.modules.system.util.CodeUtil;
@@ -75,6 +77,8 @@ public class DeviceServiceImpl implements DeviceService, ApplicationAutoInitial
     private final AcsConfigService acsConfigService;
     @Autowired
     TaskService taskService;
+    @Autowired
+    RouteLineService routeLineService;
 
     List<StorageCellDto> storageCells = new ArrayList<>();
     private Map<String, Integer> storage_address = new HashMap();
@@ -496,7 +500,7 @@ public class DeviceServiceImpl implements DeviceService, ApplicationAutoInitial
     @Override
     public JSONArray selectDeviceListThree() {
         //设备基础信息表【acs_device】
-        JSONArray arr = WQLObject.getWQLObject("acs_device").query("is_delete= '0' AND is_active= '1' AND region = '1'", "seq_num").getResultJSONArray(0);
+        JSONArray arr = WQLObject.getWQLObject("acs_device").query("is_delete= '0' AND is_active= '1' AND region IN ('1', '6')", "seq_num").getResultJSONArray(0);
         JSONArray result = new JSONArray();
         for (int i = 0; i < arr.size(); i++) {
             JSONObject obj = arr.getJSONObject(i);
@@ -515,6 +519,7 @@ public class DeviceServiceImpl implements DeviceService, ApplicationAutoInitial
                 json.put("remark", standardOrdinarySiteDeviceDriver.getRemark());
                 json.put("islock",standardOrdinarySiteDeviceDriver.getIslock());
                 json.put("hasGood",standardOrdinarySiteDeviceDriver.getHasGoods());
+                json.put("next_code",standardOrdinarySiteDeviceDriver.getNext_code());
             }
             if (device.getDeviceDriver() instanceof StandardInspectSiteDeviceDriver) {
                 standardInspectSiteDeviceDriver = (StandardInspectSiteDeviceDriver) device.getDeviceDriver();
@@ -523,6 +528,7 @@ public class DeviceServiceImpl implements DeviceService, ApplicationAutoInitial
                 json.put("remark", standardInspectSiteDeviceDriver.getRemark());
                 json.put("islock",standardInspectSiteDeviceDriver.getIslock());
                 json.put("hasGood",standardInspectSiteDeviceDriver.getHasGoods());
+                json.put("next_code",standardInspectSiteDeviceDriver.getNext_code());
             }
             result.add(json);
         }
@@ -1243,6 +1249,7 @@ public class DeviceServiceImpl implements DeviceService, ApplicationAutoInitial
         //物料类型
         String material_type = form.optString("material_type");
         String remark = form.optString("remark");
+        String next_code = form.optString("next_code");
         Integer hasGoods = 0;
         if (!StrUtil.equals(material_type,"")) {
             hasGoods = 2;
@@ -1256,10 +1263,12 @@ public class DeviceServiceImpl implements DeviceService, ApplicationAutoInitial
             standardOrdinarySiteDeviceDriver.setMaterial(material_type);
             standardOrdinarySiteDeviceDriver.setRemark(remark);
             standardOrdinarySiteDeviceDriver.setHasGoods(hasGoods);
+            standardOrdinarySiteDeviceDriver.setNext_code(next_code);
             device.setMaterial_type(material_type);
             device.setQuantity(quantity);
             device.setRemark(remark);
             device.setHas_goods(hasGoods);
+            device.setNext_code(next_code);
         }
         if (device.getDeviceDriver() instanceof StandardInspectSiteDeviceDriver) {
             standardInspectSiteDeviceDriver = (StandardInspectSiteDeviceDriver) device.getDeviceDriver();
@@ -1267,10 +1276,12 @@ public class DeviceServiceImpl implements DeviceService, ApplicationAutoInitial
             standardInspectSiteDeviceDriver.setMaterial(material_type);
             standardInspectSiteDeviceDriver.setRemark(remark);
             standardInspectSiteDeviceDriver.setHasGoods(hasGoods);
+            standardInspectSiteDeviceDriver.setNext_code(next_code);
             device.setMaterial_type(material_type);
             device.setQuantity(quantity);
             device.setRemark(remark);
             device.setHas_goods(hasGoods);
+            device.setNext_code(next_code);
         }
 
     }
@@ -1501,6 +1512,7 @@ public class DeviceServiceImpl implements DeviceService, ApplicationAutoInitial
                     standardOrdinarySiteDeviceDriver.setMaterial("");
                     standardOrdinarySiteDeviceDriver.setQty("");
                     standardOrdinarySiteDeviceDriver.setRemark("");
+                    standardOrdinarySiteDeviceDriver.setNext_code("");
                     JSONObject jsonjo = new JSONObject();
                     jsonjo.put("device_code", device_code);
                     jsonjo.put("hasGoodStatus", "0");
@@ -1511,6 +1523,7 @@ public class DeviceServiceImpl implements DeviceService, ApplicationAutoInitial
                     standardInspectSiteDeviceDriver.setMaterial("");
                     standardInspectSiteDeviceDriver.setQty("");
                     standardInspectSiteDeviceDriver.setRemark("");
+                    standardInspectSiteDeviceDriver.setNext_code("");
                 }
             }
         }
@@ -2043,4 +2056,18 @@ public class DeviceServiceImpl implements DeviceService, ApplicationAutoInitial
         }
 
     }
+
+
+    @Override
+    public List<String> selectEndPoint(String start_code) {
+        if(StrUtil.isEmpty(start_code)){
+            throw new RuntimeException("起点设备为空");
+        }
+        List<RouteLineDto> normal = routeLineService.getShortPathLinesByCode(start_code, "normal");
+        List<String> list = new ArrayList<>();
+        for (RouteLineDto routeLineDto : normal) {
+            list.add(routeLineDto.getNext_device_code());
+        }
+        return list;
+    }
 }
diff --git a/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/standard_inspect_site/StandardInspectSiteDeviceDriver.java b/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/standard_inspect_site/StandardInspectSiteDeviceDriver.java
index 5c20f1c..acd5b84 100644
--- a/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/standard_inspect_site/StandardInspectSiteDeviceDriver.java
+++ b/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/standard_inspect_site/StandardInspectSiteDeviceDriver.java
@@ -73,6 +73,7 @@ public class StandardInspectSiteDeviceDriver extends AbstractOpcDeviceDriver imp
     int last_task = 0;
     Boolean isonline = true;
     int hasGoods = 0;
+    String next_code = "";
     String message = null;
     Boolean iserror = false;
 
diff --git a/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/standard_ordinary_site/StandardOrdinarySiteDeviceDriver.java b/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/standard_ordinary_site/StandardOrdinarySiteDeviceDriver.java
index 7c2248f..f12164a 100644
--- a/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/standard_ordinary_site/StandardOrdinarySiteDeviceDriver.java
+++ b/hd/nladmin-system/src/main/java/org/nl/acs/device_driver/standard_ordinary_site/StandardOrdinarySiteDeviceDriver.java
@@ -47,6 +47,7 @@ public class StandardOrdinarySiteDeviceDriver extends AbstractDeviceDriver imple
     TaskService taskserver = SpringContextHolder.getBean("taskServiceImpl");
 
     Integer hasGoods = 0;
+    String next_code = "";
     int error = 0;
     Boolean iserror = false;
     Boolean islock = false;
@@ -107,8 +108,8 @@ public class StandardOrdinarySiteDeviceDriver extends AbstractDeviceDriver imple
         hasGoods = this.getDevice().getHas_goods();
         batch = this.getDevice().getBatch();
         devicecode = this.getDeviceCode();
-        if (branchProtocol != last_branchProtocol) {
-            requireSucess = false;
+        if("WLFZW05".equals(devicecode)){
+            hasGoods = 1;
         }
         switch (branchProtocol) {
             case 1:
diff --git a/hd/nladmin-system/src/main/java/org/nl/acs/opc/DeviceManageDto.java b/hd/nladmin-system/src/main/java/org/nl/acs/opc/DeviceManageDto.java
index afb9539..7a36db5 100644
--- a/hd/nladmin-system/src/main/java/org/nl/acs/opc/DeviceManageDto.java
+++ b/hd/nladmin-system/src/main/java/org/nl/acs/opc/DeviceManageDto.java
@@ -12,6 +12,7 @@ public class DeviceManageDto {
     private Boolean is_require_task;
     private String location;
     private Integer has_goods = 0;
+    private String next_code;
     private String material_type;
     private String quantity;
     private String remark;
diff --git a/hd/nladmin-system/src/main/java/org/nl/acs/task/service/impl/TaskServiceImpl.java b/hd/nladmin-system/src/main/java/org/nl/acs/task/service/impl/TaskServiceImpl.java
index 47bc594..66cdcbf 100644
--- a/hd/nladmin-system/src/main/java/org/nl/acs/task/service/impl/TaskServiceImpl.java
+++ b/hd/nladmin-system/src/main/java/org/nl/acs/task/service/impl/TaskServiceImpl.java
@@ -155,7 +155,7 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
         if (entity == null) throw new BadRequestException("被删除或无权限,操作失败!");
         InstructionService instructionservice = SpringContextHolder.getBean("instructionServiceImpl");
         InstructionDto instdto = instructionservice.findByTaskid(entity.getTask_id(), "instruction_status <2 ");
-        if(!ObjectUtil.isEmpty(instdto)){
+        if (!ObjectUtil.isEmpty(instdto)) {
             instructionService.cancel(instdto.getInstruction_id());
         }
 
@@ -282,7 +282,7 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
         WQLObject wo = WQLObject.getWQLObject("acs_task");
         JSONObject json = wo.query("task_code ='" + code + "'").uniqueResult(0);
         final TaskDto obj = (TaskDto) JSONObject.toBean(json, TaskDto.class);
-        if(ObjectUtil.isEmpty(obj)){
+        if (ObjectUtil.isEmpty(obj)) {
             return false;
         }
         return true;
@@ -626,7 +626,7 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
      */
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public void hssavetask(JSONObject json) throws Exception {
+    public synchronized void hssavetask(JSONObject json) throws Exception {
         JSONArray array = json.optJSONArray("data");
 
         if (array.size() == 0) {
@@ -673,11 +673,29 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
 //            if (ObjectUtil.isNotEmpty(this.findByStartCode(device_code))) {
 //                throw new RuntimeException("设备:" + device_code + " 已存在该起点的任务");
 //            }
+            list.sort(new Comparator<RouteLineDto>() {
+                @Override
+                public int compare(RouteLineDto o1, RouteLineDto o2) {
+                    String s1 = o1.getNext_device_code().substring(o1.getNext_device_code().length() - 2);
+                    String s2 = o2.getNext_device_code().substring(o2.getNext_device_code().length() - 2);
+                    return Integer.compare(Integer.parseInt(s1), Integer.parseInt(s2));
+                }
+            });
+            String next_code = arrjo.getString("next_code");
+            Boolean isFirst = true;
             StandardOrdinarySiteDeviceDriver standardOrdinarySiteDeviceDriver;
             StandardInspectSiteDeviceDriver standardInspectSiteDeviceDriver;
             for (int j = 0; j < list.size(); j++) {
                 RouteLineDto routeLineDto = list.get(j);
                 next_device_code = routeLineDto.getNext_device_code();
+                //包材接驳位策略
+                //包材取货位放到物料放置位的策略
+                String prefix = "BCQHW";
+                boolean result = StrUtil.startWithIgnoreCase(device_code, prefix);
+                if (result && StrUtil.isNotEmpty(next_code) && isFirst) {
+                    next_device_code = next_code;
+                }
+                //物料放置位货物放到成品放置位策略
                 Device device = deviceAppService.findDeviceByCode(next_device_code);
                 if (device.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) {
                     standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) device.getDeviceDriver();
@@ -688,6 +706,7 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
                         break;
                     } else {
                         next_device_code = "";
+                        isFirst = false;
                     }
                 }
                 if (device.getDeviceDriver() instanceof StandardInspectSiteDeviceDriver) {
@@ -723,7 +742,8 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
             try {
                 create(dto);
             } catch (Exception e) {
-                e.printStackTrace();
+                throw new RuntimeException("任务生成失败");
+                // e.printStackTrace();
             }
         }
     }
@@ -825,7 +845,7 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
             }
 
             if (ObjectUtil.isNotEmpty(this.findByStartCode(start_device_code))
-                 || ObjectUtil.isNotEmpty(this.findByNextCode(next_device_code))) {
+                    || ObjectUtil.isNotEmpty(this.findByNextCode(next_device_code))) {
                 throw new WDKException("已存在该起点或终点的任务!");
             }
             if (StrUtil.equals(material_type, "") || StrUtil.equals(quantity, "")) {