From 2db47e8cbc255d7cab647cf9df7fba3f61d2cb88 Mon Sep 17 00:00:00 2001 From: ludj Date: Fri, 3 Feb 2023 22:57:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8C=87=E4=BB=A4=E4=BB=BB=E5=8A=A1=E8=BF=AD?= =?UTF-8?q?=E4=BB=A3=E5=99=A8=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../standard_inspect/ReadUtil.java | 109 +- .../device/service/impl/ConveyorDevice.java | 58 - .../org/nl/acs/device/service/impl/Test.java | 18 - .../service/impl/InstructionServiceImpl.java | 49 +- .../nl/acs/opc/DeviceOpcProtocolRunable.java | 27 +- .../src/main/java/org/nl/acs/opc/OpcUtl.java | 25 - .../task/service/impl/TaskServiceImpl.java | 2904 +++++++++-------- 7 files changed, 1518 insertions(+), 1672 deletions(-) delete mode 100644 acs/nladmin-system/src/main/java/org/nl/acs/device/service/impl/ConveyorDevice.java delete mode 100644 acs/nladmin-system/src/main/java/org/nl/acs/device/service/impl/Test.java diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device/device_driver/standard_inspect/ReadUtil.java b/acs/nladmin-system/src/main/java/org/nl/acs/device/device_driver/standard_inspect/ReadUtil.java index 4ce2cdeff..cb22b1dbf 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device/device_driver/standard_inspect/ReadUtil.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device/device_driver/standard_inspect/ReadUtil.java @@ -21,93 +21,10 @@ import org.openscada.opc.lib.list.ServerList; import java.net.UnknownHostException; import java.util.*; import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; public class ReadUtil { - public static void main(String[] args) throws AlreadyConnectedException, JIException, UnknownHostException, NotConnectedException, DuplicateGroupException, AddFailedException, InterruptedException { - // 启动服务 - /* ItemProtocol ipl = new ItemProtocol(); - List list = ipl.getReadableItemDtos(); - List ls = new ArrayList<>(); - for (ItemDto dto : list) { - //ls.add("RD3.RD3.2265."+ dto.getCode()); - } - ls.add("DDJ1.DDJ1.DDJ1.heartbeat"); - ls.add("DDJ1.DDJ1.DDJ1.action"); - final Server server = getServer(); - Map map = read(ls, server); - *//*Map params=new HashMap<>(); - params.put("RD3.RD3.2265."+"mode","0"); - write(params, server);*//* - System.out.println(111);*/ - /* try { - test(); - } catch (InterruptedException e) { - e.printStackTrace(); - }*/ - - //List> maps = showAllOpcServer("192.168.81.207", "administrator", "123", ""); - - Server server = getServer(); - List itemString = new ArrayList(); - itemString.add("RD1.RD1.1005.test"); - Map map = read(itemString, server); - System.out.println(map.get("RD1.RD1.1005.test")); -// int[] a = (int[]) map.get("RD1.RD1.1005.test"); -// for(int i=0; i itemMap = new HashMap(); -// itemMap.put("RD1.RD1.1005.test", "1.2"); - - } - - /** - * 发布订阅测试 - */ - private static final int PERIOD = 100; - - private static final int SLEEP = 2000; - - public static void test() throws AlreadyConnectedException, JIException, UnknownHostException, AddFailedException, NotConnectedException, DuplicateGroupException, InterruptedException { - /*ConnectionInformation ci = new ConnectionInformation(); - ci.setHost("10.1.5.123"); - ci.setDomain(""); - ci.setUser("freud"); - ci.setPassword("password"); - ci.setClsid("F8582CF2-88FB-11D0-B850-00C0F0104305"); - - Server server = new Server(ci, - Executors.newSingleThreadScheduledExecutor());*/ - Server server = getServer(); - - // server.connect(); - - AccessBase access = new Async20Access(server, PERIOD, false); - - access.addItem("RD1.RD1.B21.mode", new DataCallback() { - - private int count; - - @SneakyThrows - public void changed(Item item, ItemState itemstate) { - System.out.println("[" + (++count) + "],ItemName:[" - + item.getId() + "],value:" + itemstate.getValue()); - System.out.println(itemstate.getValue().isArray()); - List listB = Arrays.asList(itemstate.getValue().toString()); - System.out.println(listB.get(0)); - - } - }); - - access.bind(); - Thread.sleep(SLEEP); - access.unbind(); - server.dispose(); - } public static Server getServer(String opc_id) { //OPC表【acs_opc】 @@ -134,28 +51,6 @@ public class ReadUtil { return server; } - public static Server getServer() { - //RD1.RD1.1028 - // 连接信息 - ConnectionInformation ci = new ConnectionInformation(); - ci.setHost("192.168.81.251"); - ci.setDomain(""); - ci.setUser("administrator"); - ci.setPassword("Huawei@123"); - ci.setClsid("7BC0CC8E-482C-47CA-ABDC-0FE7F9C6E729"); - final Server server = new Server(ci, Executors.newSingleThreadScheduledExecutor()); - try { - server.connect(); - } catch (UnknownHostException e) { - e.printStackTrace(); - } catch (JIException e) { - e.printStackTrace(); - } catch (AlreadyConnectedException e) { - e.printStackTrace(); - } - return server; - } - public static void write(Map strings, Server server) { try { //Group group = this.opcServerService.getServer(opcServiceCode); @@ -198,7 +93,6 @@ public class ReadUtil { public static Map read(List itemString, Server server) { HashMap map = new HashMap(); try { - //Group group = this.opcServerService.getServer(opcServiceCode); Group group = server.addGroup(); Map items = new LinkedHashMap(); Iterator is = itemString.iterator(); @@ -226,6 +120,7 @@ public class ReadUtil { } catch (Exception e) { e.printStackTrace(); } + return map; } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device/service/impl/ConveyorDevice.java b/acs/nladmin-system/src/main/java/org/nl/acs/device/service/impl/ConveyorDevice.java deleted file mode 100644 index 9a685f316..000000000 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device/service/impl/ConveyorDevice.java +++ /dev/null @@ -1,58 +0,0 @@ -package org.nl.acs.device.service.impl; - -import lombok.Data; -import lombok.SneakyThrows; -import org.nl.acs.instruction.service.dto.InstructionDto; -import org.nl.acs.opc.OpcUtl; -import org.nl.acs.task.service.TaskService; -import org.nl.acs.task.service.dto.TaskDto; -import org.nl.acs.task.service.impl.TaskServiceImpl; - -@Data -public class ConveyorDevice { - - String id; - - int jobNo = -1; - - int lastjobNo = -1; - - String palletNo; - - InstructionDto inst; - - RecvThread rt; - - public ConveyorDevice(String id) { - if (id == null) { - throw new NullPointerException("ID is null"); - } else { - this.id = id; - } - System.out.println("id:" + id); - rt = new RecvThread(); - rt.run(); - } - - public void adviseData() { - System.out.println("test"); - } - - private class RecvThread implements Runnable { - - @SneakyThrows - @Override - public void run() { - System.out.println("test"); - String MODE = "RD1.RD1." + id + ".mode"; - String code = OpcUtl.read(MODE); - if ("2".equals(code)) { - TaskService taskserver = new TaskServiceImpl(); - TaskDto dto = new TaskDto(); - dto.setStart_point_code(id); - dto.setNext_point_code("1002"); - taskserver.create(dto); - } - } - } -} diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device/service/impl/Test.java b/acs/nladmin-system/src/main/java/org/nl/acs/device/service/impl/Test.java deleted file mode 100644 index 8e73a4ec3..000000000 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device/service/impl/Test.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.nl.acs.device.service.impl; - -import java.util.ArrayList; -import java.util.List; - -public class Test { - - public static void main(String[] args) { - String device = "1001,1002"; - List list = new ArrayList<>(); - list.add("1001"); - list.add("1002"); - for (int i = 0; i < list.size(); i++) { - ConveyorDevice condev = new ConveyorDevice(list.get(i).toString()); - } - - } -} diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/instruction/service/impl/InstructionServiceImpl.java b/acs/nladmin-system/src/main/java/org/nl/acs/instruction/service/impl/InstructionServiceImpl.java index 4c688395a..f3901dfd0 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/instruction/service/impl/InstructionServiceImpl.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/instruction/service/impl/InstructionServiceImpl.java @@ -1089,12 +1089,14 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu @Override public Instruction findByLinkNumSend(String code) { - for (int i = 0; i < this.instructions.size(); i++) { - Instruction inst = instructions.get(i); + Iterator it = instructions.iterator(); + while (it.hasNext()){ + Instruction inst = it.next(); if (StrUtil.equals(code, inst.getLink_num()) && StrUtil.equals(inst.getIs_send(), "1")) { return inst; } } + return null; } @@ -1102,8 +1104,9 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu @Override public List findByLinkNum(String code) { List list = new ArrayList<>(); - for (int i = 0; i < this.instructions.size(); i++) { - Instruction inst = instructions.get(i); + Iterator it = instructions.iterator(); + while (it.hasNext()){ + Instruction inst = it.next(); if (StrUtil.equals(code, inst.getLink_num()) && StrUtil.equals(inst.getIs_send(), "0")) { list.add(inst); } @@ -1113,19 +1116,22 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu @Override public Instruction findByLinkNumNoSend(String code) { - for (int i = 0; i < this.instructions.size(); i++) { - Instruction inst = instructions.get(i); + Iterator it = instructions.iterator(); + while (it.hasNext()){ + Instruction inst = it.next(); if (StrUtil.equals(code, inst.getLink_num()) && StrUtil.equals(inst.getIs_send(), "0")) { return inst; } } + return null; } @Override public Instruction findByCodeFromCache(String code) { - for (int i = 0; i < this.instructions.size(); i++) { - Instruction inst = instructions.get(i); + Iterator it = instructions.iterator(); + while (it.hasNext()){ + Instruction inst = it.next(); if (StrUtil.equals(code, inst.getInstruction_code())) { return inst; } @@ -1136,8 +1142,9 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu @Override public Instruction findByBarcodeFromCache(String barcode) { - for (int i = 0; i < this.instructions.size(); i++) { - Instruction inst = instructions.get(i); + Iterator it = instructions.iterator(); + while (it.hasNext()){ + Instruction inst = it.next(); if (StrUtil.equals(barcode, inst.getVehicle_code())) { return inst; } @@ -1147,9 +1154,9 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu @Override public Instruction findByIdFromCache(String id) { - - for (int i = 0; i < this.instructions.size(); i++) { - Instruction inst = instructions.get(i); + Iterator it = instructions.iterator(); + while (it.hasNext()){ + Instruction inst = it.next(); if (StrUtil.equals(id, inst.getInstruction_id())) { return inst; } @@ -1244,8 +1251,9 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu @Override public Integer querySameDestinationInst(String devicecode) { int num = 0; - for (int i = 0; i < this.instructions.size(); i++) { - Instruction inst = instructions.get(i); + Iterator it = instructions.iterator(); + while (it.hasNext()){ + Instruction inst = it.next(); //处理空盘位站点 String next_code = inst.getNext_point_code(); if (next_code.indexOf(".") != -1) { @@ -1255,14 +1263,16 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu num = num + 1; } } + return num; } @Override public Integer querySameInstType(String inst_type) { int num = 0; - for (int i = 0; i < this.instructions.size(); i++) { - Instruction inst = instructions.get(i); + Iterator it = instructions.iterator(); + while (it.hasNext()){ + Instruction inst = it.next(); if (StrUtil.equals(inst.getInstruction_type(), inst_type)) { num = num + 1; } @@ -1273,8 +1283,9 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu @Override public Integer querySameOriginInst(String devicecode) { int num = 0; - for (int i = 0; i < this.instructions.size(); i++) { - Instruction inst = instructions.get(i); + Iterator it = instructions.iterator(); + while (it.hasNext()){ + Instruction inst = it.next(); //处理空盘位站点 String start_code = inst.getStart_point_code(); if (start_code.indexOf(".") != -1) { diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/opc/DeviceOpcProtocolRunable.java b/acs/nladmin-system/src/main/java/org/nl/acs/opc/DeviceOpcProtocolRunable.java index 2c06c54c7..49269e427 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/opc/DeviceOpcProtocolRunable.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/opc/DeviceOpcProtocolRunable.java @@ -21,6 +21,8 @@ public class DeviceOpcProtocolRunable implements Runnable { String message; private Server server; + Group group; + public DeviceOpcProtocolRunable() { this.error_num = 0; this.message = null; @@ -62,13 +64,15 @@ public class DeviceOpcProtocolRunable implements Runnable { public void run() { while (true) { try { - server = OpcServerUtl.getServerWithOutException( + server = + OpcServerUtl.getServerWithOutException( this.OpcServer.getOpc_host(), this.OpcServer.getCls_id(), this.OpcServer.getUser(), this.OpcServer.getPassword(), this.OpcServer.getDomain()); - Group group = server.addGroup(); + group = server.addGroup(); + List itemsString = new ArrayList(); Iterator it = this.protocols.iterator(); @@ -117,10 +121,12 @@ public class DeviceOpcProtocolRunable implements Runnable { label97: while (true) { -// System.out.println("label97"); + // System.out.println("label97"); long begin = System.currentTimeMillis(); Map itemStatus = group.read(true, (Item[]) itemsMap.values().toArray(new Item[0])); + //TODO 读完释放server可行否? + long end = System.currentTimeMillis(); log.trace("{} 开始记时{}", tag, DateUtil.now()); long duration = end - begin; @@ -135,12 +141,13 @@ public class DeviceOpcProtocolRunable implements Runnable { time_out = false; } + // A1_HK_04.A1_HK_04.A1_HK_04_3.door 列表 Set items = itemStatus.keySet(); Iterator var18 = items.iterator(); while (true) { -// System.out.println("label98"); Item item; + // A1_HK_04.A1_HK_04.A1_HK_04_3.door // 当前值 Object value; // 旧的值 @@ -155,6 +162,7 @@ public class DeviceOpcProtocolRunable implements Runnable { this.error_num = 0; this.message = null; } + // 所有信号读完并且没有变化的值 continue label97; } @@ -183,7 +191,6 @@ public class DeviceOpcProtocolRunable implements Runnable { log.info("信号{}变更从{}->{};信号快照:{}", new Object[] {item.getId(), his, value, sb}); } - System.out.println("设置值:【"+item.getId()+"】-->"+value); // 设置值 accessor_value.setValue(item.getId(), value); } @@ -197,6 +204,15 @@ public class DeviceOpcProtocolRunable implements Runnable { this.server = null; } + if (group != null) { + try { + group.clear(); + group.remove(); + } catch (Exception var6) { + } + this.group = null; + } + String error_message = "设备信息同步异常"; if (!StrUtil.equals(this.message, error_message)) { log.warn("", var30); @@ -215,5 +231,4 @@ public class DeviceOpcProtocolRunable implements Runnable { } } } - } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/opc/OpcUtl.java b/acs/nladmin-system/src/main/java/org/nl/acs/opc/OpcUtl.java index e03649e7f..3ed420b6d 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/opc/OpcUtl.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/opc/OpcUtl.java @@ -268,31 +268,6 @@ public class OpcUtl { return value; } - public static String read(String item) throws Exception { - System.out.println(item); - Server server = getServer("192.168.81.251", "7bc0cc8e-482c-47ca-abdc-0fe7f9c6e729", "administrator", "Huawei@123", ""); -// String byteItemString = "RD1.RD1.1001.mode"; - Group group = server.addGroup(); - Item byteItem = group.addItem(item); - ItemState itemState = null; - JIVariant value = null; - itemState = byteItem.read(true); - value = itemState.getValue(); - String data = OpcUtl.getValue(byteItem, itemState) + ""; - return data; - } - public static void main(String[] args) throws Exception { - Server server = getServer("192.168.81.251", "7bc0cc8e-482c-47ca-abdc-0fe7f9c6e729", "administrator", "Huawei@123", ""); - String byteItemString = "RD1.RD1.1001.mode"; - Group group = server.addGroup(); - Item byteItem = group.addItem(byteItemString); - ItemState itemState = null; - JIVariant value = null; - System.out.println(byteItem.getId()); - itemState = byteItem.read(true); - System.out.println(itemState.getQuality()); - System.out.println(getValue(byteItem, itemState)); - } } 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 a1fcaa4f7..7b43f2516 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 @@ -1,7 +1,5 @@ - package org.nl.acs.task.service.impl; - import cn.hutool.core.date.DateUtil; import cn.hutool.core.map.MapUtil; import cn.hutool.core.util.IdUtil; @@ -61,1482 +59,1510 @@ import java.util.stream.Collectors; * @author ldjun * @description 服务实现 * @date 2021-03-18 - **/ + */ @Service @RequiredArgsConstructor @Slf4j public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { - List tasks = new ArrayList(); + List tasks = new ArrayList(); - @Autowired - DeviceAppService deviceAppService; - @Autowired - RouteLineService routelineserver; - @Autowired - AcsToWmsService acstowmsService; - @Autowired - TaskFeedbackService taskFeedbackService; - @Autowired - ParamService paramService; - @Autowired - XianGongAgvService agvService; - @Autowired - RouteLineService routeLineService; - @Autowired - DeviceAssignedService deviceAssignedService; - @Autowired - InstructionService instructionService; - @Autowired - StorageCellService storageCellService; + @Autowired DeviceAppService deviceAppService; + @Autowired RouteLineService routelineserver; + @Autowired AcsToWmsService acstowmsService; + @Autowired TaskFeedbackService taskFeedbackService; + @Autowired ParamService paramService; + @Autowired XianGongAgvService agvService; + @Autowired RouteLineService routeLineService; + @Autowired DeviceAssignedService deviceAssignedService; + @Autowired InstructionService instructionService; + @Autowired StorageCellService storageCellService; - @Override - public void autoInitial() throws Exception { - this.reload(); + @Override + public void autoInitial() throws Exception { + this.reload(); + } + + public synchronized void reload() { + this.tasks = this.queryAll("task_status <2 and is_delete =0 order by create_time"); + } + + @Override + public List queryAll(String whereJson) { + WQLObject wo = WQLObject.getWQLObject("acs_task"); + JSONArray arr = wo.query(whereJson).getResultJSONArray(0); + List list = arr.toJavaList(TaskDto.class); + return list; + } + + @Override + public Map queryAll(Map whereJson, Pageable page) { + + // WQLObject wo = WQLObject.getWQLObject("acs_task"); + // ResultBean rb = wo.pagequery(WqlUtil.getHttpContext(page), "task_status < 2 ", "update_time + // desc"); + HashMap map = new HashMap<>(); + map.put("flag", "1"); + String task_code = (String) whereJson.get("task_code"); + String vehicle_code = (String) whereJson.get("vehicle_code"); + String material_type = (String) whereJson.get("material_type"); + String status = (String) whereJson.get("status"); + String point_code = (String) whereJson.get("point_code"); + String is_over = (String) whereJson.get("is_over"); + if (!StrUtil.isEmpty(task_code)) { + map.put("task_code", task_code); + } + if (!StrUtil.isEmpty(vehicle_code)) { + map.put("vehicle_code", vehicle_code); + } + if (!StrUtil.isEmpty(material_type)) { + map.put("material_type", material_type); + } + if (!StrUtil.isEmpty(status)) { + map.put("status", status); + } + if (!StrUtil.isEmpty(point_code)) { + map.put("point_code", point_code); + } + if (!StrUtil.isEmpty(is_over)) { + map.put("is_over", is_over); + } + final JSONObject jo = + WQL.getWO("QTASK_QUERY").addParamMap(map).pageQuery(WqlUtil.getHttpContext(page), ""); + return jo; + } + + @Override + public Map queryAllByCache(Map whereJson, Pageable page) { + this.reload(); + String task_code = (String) whereJson.get("task_code"); + String vehicle_code = (String) whereJson.get("vehicle_code"); + String material_type = (String) whereJson.get("material_type"); + String status = (String) whereJson.get("status"); + String point_code = (String) whereJson.get("point_code"); + String is_over = (String) whereJson.get("is_over"); + String task_type = (String) whereJson.get("task_type"); + List taskList = new ArrayList(); + + Iterator it = tasks.iterator(); + while (it.hasNext()) { + TaskDto task = it.next(); + if ("1".equals(is_over) && Integer.valueOf(task.getTask_status()) < 2) { + continue; + } + if (!"1".equals(is_over) && Integer.valueOf(task.getTask_status()) >= 2) { + continue; + } + if (!ObjectUtil.isEmpty(task_code) && !task.getTask_code().contains(task_code)) { + continue; + } + if (!ObjectUtil.isEmpty(status) && !task.getTask_status().equals(status)) { + continue; + } + if (!ObjectUtil.isEmpty(vehicle_code) && !task.getVehicle_code().contains(vehicle_code)) { + continue; + } + if (!ObjectUtil.isEmpty(material_type) && !task.getMaterial().equals(material_type)) { + continue; + } + if (!ObjectUtil.isEmpty(point_code) + && !(task.getStart_point_code().contains(point_code) + || task.getNext_point_code().contains(point_code))) { + continue; + } + if (!ObjectUtil.isEmpty(task_type) && !task.getTask_type().equals(task_type)) { + continue; + } + taskList.add(task); } - public synchronized void reload() { - this.tasks = this.queryAll("task_status <2 and is_delete =0 order by create_time"); + // 按照创建时间排序 + taskList = + taskList.stream() + .sorted( + (task1, task2) -> + DateUtil.compare( + DateUtil.parseDate(task1.getCreate_time()), + DateUtil.parse(task2.getCreate_time()))) + .collect(Collectors.toList()); + + Integer currentPageNumber = page.getPageNumber() + 1; + Integer pageMaxSize = page.getPageSize(); + List taskDtoList = + taskList.stream() + .skip((currentPageNumber - 1) * pageMaxSize) + .limit(pageMaxSize) + .collect(Collectors.toList()); + JSONObject jo = new JSONObject(); + jo.put("content", taskDtoList); + jo.put("totalElements", taskList.size()); + return jo; + } + + @Override + public Map getAll(Map whereJson, Pageable page) { + // WQLObject wo = WQLObject.getWQLObject("acs_task"); + // ResultBean rb = wo.pagequery(WqlUtil.getHttpContext(page), "task_status < 2 ", "update_time + // desc"); + HashMap map = new HashMap<>(); + map.put("flag", "2"); + String task_code = (String) whereJson.get("task_code"); + String vehicle_code = (String) whereJson.get("vehicle_code"); + String material_type = (String) whereJson.get("material_type"); + String status = (String) whereJson.get("status"); + String point_code = (String) whereJson.get("point_code"); + String create_time = (String) whereJson.get("createTime"); + String end_time = (String) whereJson.get("end_time"); + if (!StrUtil.isEmpty(task_code)) { + map.put("task_code", task_code); } - - @Override - public List queryAll(String whereJson) { - WQLObject wo = WQLObject.getWQLObject("acs_task"); - JSONArray arr = wo.query(whereJson).getResultJSONArray(0); - List list = arr.toJavaList(TaskDto.class); - return list; + if (!StrUtil.isEmpty(vehicle_code)) { + map.put("vehicle_code", vehicle_code); } - - @Override - public Map queryAll(Map whereJson, Pageable page) { - - //WQLObject wo = WQLObject.getWQLObject("acs_task"); - //ResultBean rb = wo.pagequery(WqlUtil.getHttpContext(page), "task_status < 2 ", "update_time desc"); - HashMap map = new HashMap<>(); - map.put("flag", "1"); - String task_code = (String) whereJson.get("task_code"); - String vehicle_code = (String) whereJson.get("vehicle_code"); - String material_type = (String) whereJson.get("material_type"); - String status = (String) whereJson.get("status"); - String point_code = (String) whereJson.get("point_code"); - String is_over = (String) whereJson.get("is_over"); - if (!StrUtil.isEmpty(task_code)) { - map.put("task_code", task_code); - } - if (!StrUtil.isEmpty(vehicle_code)) { - map.put("vehicle_code", vehicle_code); - } - if (!StrUtil.isEmpty(material_type)) { - map.put("material_type", material_type); - } - if (!StrUtil.isEmpty(status)) { - map.put("status", status); - } - if (!StrUtil.isEmpty(point_code)) { - map.put("point_code", point_code); - } - if (!StrUtil.isEmpty(is_over)) { - map.put("is_over", is_over); - } - final JSONObject jo = WQL.getWO("QTASK_QUERY").addParamMap(map).pageQuery(WqlUtil.getHttpContext(page), ""); - return jo; + if (!StrUtil.isEmpty(material_type)) { + map.put("material_type", material_type); } + if (!StrUtil.isEmpty(status)) { + map.put("status", status); + } + if (!StrUtil.isEmpty(point_code)) { + map.put("point_code", point_code); + } + if (!StrUtil.isEmpty(create_time) && !StrUtil.isEmpty(end_time)) { + map.put("create_time", create_time); + map.put("end_time", end_time); + } + JSONObject jsonObject1 = + WQL.getWO("QTASK_QUERY") + .addParamMap(map) + .pageQuery(WqlUtil.getHttpContext(page), "create_time desc"); + JSONArray array = jsonObject1.getJSONArray("content"); + int totalElements = (Integer) jsonObject1.get("totalElements"); + JSONArray arr = new JSONArray(); + for (int i = 0; i < array.size(); i++) { + JSONObject jsonObject = (JSONObject) array.get(i); + jsonObject.put("hasChildren", true); + arr.add(jsonObject); + } + JSONObject jo = new JSONObject(); + jo.put("content", arr); + jo.put("totalElements", totalElements); + return jo; + } - @Override - public Map queryAllByCache(Map whereJson, Pageable page) { - this.reload(); - String task_code = (String) whereJson.get("task_code"); - String vehicle_code = (String) whereJson.get("vehicle_code"); - String material_type = (String) whereJson.get("material_type"); - String status = (String) whereJson.get("status"); - String point_code = (String) whereJson.get("point_code"); - String is_over = (String) whereJson.get("is_over"); - String task_type = (String) whereJson.get("task_type"); - List taskList = new ArrayList(); - for (int i = 0; i < tasks.size(); i++) { - TaskDto task = tasks.get(i); - if ("1".equals(is_over) && Integer.valueOf(task.getTask_status()) < 2) { - continue; - } - if (!"1".equals(is_over) && Integer.valueOf(task.getTask_status()) >= 2) { - continue; - } - if (!ObjectUtil.isEmpty(task_code) && !task.getTask_code().contains(task_code)) { - continue; - } - if (!ObjectUtil.isEmpty(status) && !task.getTask_status().equals(status)) { - continue; - } - if (!ObjectUtil.isEmpty(vehicle_code) && !task.getVehicle_code().contains(vehicle_code)) { - continue; - } - if (!ObjectUtil.isEmpty(material_type) && !task.getMaterial().equals(material_type)) { - continue; - } - if (!ObjectUtil.isEmpty(point_code) && !(task.getStart_point_code().contains(point_code) || task.getNext_point_code().contains(point_code))) { - continue; - } - if (!ObjectUtil.isEmpty(task_type) && !task.getTask_type().equals(task_type)) { - continue; - } - taskList.add(task); + @Override + public List queryAll(Map whereJson) { + WQLObject wo = WQLObject.getWQLObject("acs_task"); + JSONArray arr = wo.query().getResultJSONArray(0); + List list = arr.toJavaList(TaskDto.class); + return list; + } + + @Override + public TaskDto findById(String task_id) { + WQLObject wo = WQLObject.getWQLObject("acs_task"); + JSONObject json = wo.query("task_id ='" + task_id + "'").uniqueResult(0); + final TaskDto obj = json.toJavaObject(TaskDto.class); + return obj; + } + + @Override + public List queryAllUnfinished(Map whereJson) { + WQLObject wo = WQLObject.getWQLObject("acs_task"); + JSONArray arr = wo.query("task_status < 2 ").getResultJSONArray(0); + List list = arr.toJavaList(TaskDto.class); + return list; + } + + @Override + public TaskDto findByCode(String code) { + WQLObject wo = WQLObject.getWQLObject("acs_task"); + JSONObject json = wo.query("task_code ='" + code + "'").uniqueResult(0); + final TaskDto obj = json.toJavaObject(TaskDto.class); + return obj; + } + + @Override + public List queryTaskByDeviceCode(String device_code) { + List list = new ArrayList<>(); + Iterator iterator = tasks.iterator(); + while (iterator.hasNext()) { + TaskDto task = iterator.next(); + if (task.getStart_device_code().equals(device_code) + && StrUtil.equals(task.getTask_status(), "0")) { + list.add(task); + } + } + return list; + } + + @Override + public List queryTaskByStartDeviceCode(String start_device_code) { + List list = new ArrayList<>(); + Iterator iterator = tasks.iterator(); + while (iterator.hasNext()) { + TaskDto task = iterator.next(); + if (!StrUtil.equals(task.getTask_type(), "6")) { + continue; + } + if ((task.getStart_device_code().equals(start_device_code) + || task.getStart_device_code2().equals(start_device_code)) + && StrUtil.equals(task.getTask_status(), "0")) { + list.add(task); + } + } + return list; + } + + @Override + public List queryTaskByBackDeviceCode(String back_start_device_code) { + List list = new ArrayList<>(); + Iterator iterator = tasks.iterator(); + while (iterator.hasNext()) { + TaskDto task = iterator.next(); + if (!StrUtil.equals(task.getTask_type(), "6")) { + continue; + } + if (task.getStart_device_code().equals(back_start_device_code) + && StrUtil.equals(task.getTask_status(), "0")) { + list.add(task); + } + } + return list; + } + + @Override + public List queryTaskByDeviceCodeAndStatus(String device_code) { + List list = new ArrayList<>(); + Iterator iterator = tasks.iterator(); + while (iterator.hasNext()) { + TaskDto task = iterator.next(); + if (task.getStart_device_code().equals(device_code) + && StrUtil.equals(task.getTask_status(), "1")) { + Instruction instruction = instructionService.findByTaskcodeAndStatus(task.getTask_code()); + if (ObjectUtil.isNotEmpty(instruction)) { + list.add(task); } + } + } + return list; + } - // 按照创建时间排序 - taskList = taskList - .stream() - .sorted((task1, task2) -> DateUtil.compare(DateUtil.parseDate(task1.getCreate_time()), DateUtil.parse(task2.getCreate_time()))) - .collect(Collectors.toList()); + public List queryTaskByStartAndIntStatus(String head_start_device_code) { + List list = new ArrayList<>(); + Iterator iterator = tasks.iterator(); + while (iterator.hasNext()) { + TaskDto task = iterator.next(); + if (!StrUtil.equals(task.getTask_type(), "6")) { + continue; + } + if ((task.getStart_device_code().equals(head_start_device_code) + || task.getStart_device_code2().equals(head_start_device_code)) + && StrUtil.equals(task.getTask_status(), "1")) { + Instruction instruction = instructionService.findByTaskcodeAndStatus(task.getTask_code()); + if (ObjectUtil.isNotEmpty(instruction)) { + list.add(task); + } + } + } + return list; + } + + public List queryTaskByNextAndIntStatus(String back_start_device_code) { + List list = new ArrayList<>(); + Iterator iterator = tasks.iterator(); + while (iterator.hasNext()) { + TaskDto task = iterator.next(); + if (!StrUtil.equals(task.getTask_type(), "6")) { + continue; + } + if ((task.getStart_device_code().equals(back_start_device_code)) + && StrUtil.equals(task.getTask_status(), "1")) { + Instruction instruction = instructionService.findByTaskcodeAndStatus(task.getTask_code()); + if (ObjectUtil.isNotEmpty(instruction)) { + list.add(task); + } + } + } + return list; + } + + @Override + public TaskDto queryTaskByLinkNum(String link_num) { + return null; + } + + @Override + public List queryByStauts(String status) { + WQLObject wo = WQLObject.getWQLObject("acs_task"); + JSONArray arr = wo.query("task_status = '" + status + "'").getResultJSONArray(0); + List list = arr.toJavaList(TaskDto.class); + return list; + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void create(TaskDto dto) throws Exception { + dto = foramte(dto); + if (!StrUtil.isEmpty(dto.getVehicle_code())) { + TaskDto vehicle_dto = this.findByContainer(dto.getVehicle_code()); + if (vehicle_dto != null) { + throw new WDKException("已存在该载具号的任务!"); + } + } + String currentUsername = SecurityUtils.getCurrentUsername(); + String now = DateUtil.now(); + String task_uuid = dto.getTask_id(); + if (StrUtil.isEmpty(task_uuid)) { + dto.setTask_id(IdUtil.simpleUUID()); + } + String task_code = dto.getTask_code(); + if (StrUtil.isEmpty(task_code)) { + task_code = CodeUtil.getNewCode("TASK_NO"); + task_code = "-" + task_code; + } + String start_point_code = dto.getStart_point_code(); + String next_point_code = dto.getNext_point_code(); + String start_device_code = dto.getStart_device_code(); + String next_device_code = dto.getNext_device_code(); + String route_plan_code = dto.getRoute_plan_code(); + dto.setCreate_by(currentUsername); + dto.setUpdate_by(currentUsername); + dto.setUpdate_time(now); + dto.setCreate_time(now); + dto.setTask_code(task_code); + dto.setRoute_plan_code(route_plan_code); + dto.setTask_status("0"); + dto.setStart_device_code2(dto.getStart_point_code2()); + dto.setNext_device_code2(dto.getNext_point_code2()); + + if (StrUtil.isEmpty(dto.getPriority())) { + dto.setPriority("1"); + } + String plan_code = dto.getRoute_plan_code(); + // 判断起点终点设备类型 + String startDeviceType = deviceAppService.findDeviceTypeByCode(dto.getStart_device_code()); + String nextDeviceType = deviceAppService.findDeviceTypeByCode(dto.getNext_device_code()); + if (routelineserver + .getShortPathLines(dto.getStart_device_code(), dto.getNext_device_code(), plan_code) + .size() + == 0) { + throw new Exception(dto.getStart_point_code() + "->" + dto.getNext_point_code() + "路由不通!"); + } + String createTaskCheck = paramService.findByCode(AcsConfig.CREATETASKCHECK).getValue(); + DeviceService deviceService = SpringContextHolder.getBean(DeviceServiceImpl.class); + DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); + Device nextdevice = appService.findDeviceByCode(next_device_code); + Device startdevice = appService.findDeviceByCode(start_device_code); + dto.setMaterial(startdevice.getMaterial_type()); + if (StrUtil.equals(createTaskCheck, "1")) { + // 判断起点为输送设备 + if (StrUtil.equals(DeviceType.conveyor.toString(), startDeviceType)) {} + + if (StrUtil.equals(DeviceType.conveyor.toString(), nextDeviceType)) {} + } else { + // 判断起点为输送设备 + if (StrUtil.equals(DeviceType.conveyor.toString(), startDeviceType)) {} + + if (StrUtil.equals(DeviceType.conveyor.toString(), nextDeviceType)) { + // if (nextdevice.getDeviceDriver() instanceof + // StandardOrdinarySiteDeviceDriver) { + // standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) + // nextdevice.getDeviceDriver(); + // if (nextdevice.getHas_goods() != 0) { + // throw new Exception("任务终点需满足无货!"); + // } + // } - Integer currentPageNumber = page.getPageNumber() + 1; - Integer pageMaxSize = page.getPageSize(); - List taskDtoList = taskList.stream().skip((currentPageNumber - 1) * pageMaxSize).limit(pageMaxSize).collect(Collectors.toList()); JSONObject jo = new JSONObject(); - jo.put("content", taskDtoList); - jo.put("totalElements", taskList.size()); - return jo; - } - - @Override - public Map getAll(Map whereJson, Pageable page) { - //WQLObject wo = WQLObject.getWQLObject("acs_task"); - //ResultBean rb = wo.pagequery(WqlUtil.getHttpContext(page), "task_status < 2 ", "update_time desc"); - HashMap map = new HashMap<>(); - map.put("flag", "2"); - String task_code = (String) whereJson.get("task_code"); - String vehicle_code = (String) whereJson.get("vehicle_code"); - String material_type = (String) whereJson.get("material_type"); - String status = (String) whereJson.get("status"); - String point_code = (String) whereJson.get("point_code"); - String create_time = (String) whereJson.get("createTime"); - String end_time = (String) whereJson.get("end_time"); - if (!StrUtil.isEmpty(task_code)) { - map.put("task_code", task_code); - } - if (!StrUtil.isEmpty(vehicle_code)) { - map.put("vehicle_code", vehicle_code); - } - if (!StrUtil.isEmpty(material_type)) { - map.put("material_type", material_type); - } - if (!StrUtil.isEmpty(status)) { - map.put("status", status); - } - if (!StrUtil.isEmpty(point_code)) { - map.put("point_code", point_code); - } - if (!StrUtil.isEmpty(create_time) && !StrUtil.isEmpty(end_time)) { - map.put("create_time", create_time); - map.put("end_time", end_time); - } - JSONObject jsonObject1 = WQL.getWO("QTASK_QUERY").addParamMap(map).pageQuery(WqlUtil.getHttpContext(page), "create_time desc"); - JSONArray array = jsonObject1.getJSONArray("content"); - int totalElements = (Integer) jsonObject1.get("totalElements"); - JSONArray arr = new JSONArray(); - for (int i = 0; i < array.size(); i++) { - JSONObject jsonObject = (JSONObject) array.get(i); - jsonObject.put("hasChildren", true); - arr.add(jsonObject); - } - JSONObject jo = new JSONObject(); - jo.put("content", arr); - jo.put("totalElements", totalElements); - return jo; - } - - @Override - public List queryAll(Map whereJson) { - WQLObject wo = WQLObject.getWQLObject("acs_task"); - JSONArray arr = wo.query().getResultJSONArray(0); - List list = arr.toJavaList(TaskDto.class); - return list; - } - - @Override - public TaskDto findById(String task_id) { - WQLObject wo = WQLObject.getWQLObject("acs_task"); - JSONObject json = wo.query("task_id ='" + task_id + "'").uniqueResult(0); - final TaskDto obj = json.toJavaObject(TaskDto.class); - return obj; - } - - @Override - public List queryAllUnfinished(Map whereJson) { - WQLObject wo = WQLObject.getWQLObject("acs_task"); - JSONArray arr = wo.query("task_status < 2 ").getResultJSONArray(0); - List list = arr.toJavaList(TaskDto.class); - return list; - } - - @Override - public TaskDto findByCode(String code) { - WQLObject wo = WQLObject.getWQLObject("acs_task"); - JSONObject json = wo.query("task_code ='" + code + "'").uniqueResult(0); - final TaskDto obj = json.toJavaObject(TaskDto.class); - return obj; - } - - @Override - public List queryTaskByDeviceCode(String device_code) { - List list = new ArrayList<>(); - Iterator iterator = tasks.iterator(); - while (iterator.hasNext()) { - TaskDto task = iterator.next(); - if (task.getStart_device_code().equals(device_code) && StrUtil.equals(task.getTask_status(), "0")) { - list.add(task); - } - } - return list; - } - - @Override - public List queryTaskByStartDeviceCode(String start_device_code) { - List list = new ArrayList<>(); - Iterator iterator = tasks.iterator(); - while (iterator.hasNext()) { - TaskDto task = iterator.next(); - if (!StrUtil.equals(task.getTask_type(), "6")) { - continue; - } - if ((task.getStart_device_code().equals(start_device_code) || task.getStart_device_code2().equals(start_device_code)) && StrUtil.equals(task.getTask_status(), "0")) { - list.add(task); - } - } - return list; - } - - @Override - public List queryTaskByBackDeviceCode(String back_start_device_code) { - List list = new ArrayList<>(); - Iterator iterator = tasks.iterator(); - while (iterator.hasNext()) { - TaskDto task = iterator.next(); - if (!StrUtil.equals(task.getTask_type(), "6")) { - continue; - } - if (task.getStart_device_code().equals(back_start_device_code) && StrUtil.equals(task.getTask_status(), "0")) { - list.add(task); - } - } - return list; - } - - @Override - public List queryTaskByDeviceCodeAndStatus(String device_code) { - List list = new ArrayList<>(); - Iterator iterator = tasks.iterator(); - while (iterator.hasNext()) { - TaskDto task = iterator.next(); - if (task.getStart_device_code().equals(device_code) && StrUtil.equals(task.getTask_status(), "1")) { - Instruction instruction = instructionService.findByTaskcodeAndStatus(task.getTask_code()); - if (ObjectUtil.isNotEmpty(instruction)) { - list.add(task); - } - } - } - return list; - } - - - public List queryTaskByStartAndIntStatus(String head_start_device_code) { - List list = new ArrayList<>(); - Iterator iterator = tasks.iterator(); - while (iterator.hasNext()) { - TaskDto task = iterator.next(); - if (!StrUtil.equals(task.getTask_type(), "6")) { - continue; - } - if ((task.getStart_device_code().equals(head_start_device_code) || task.getStart_device_code2().equals(head_start_device_code)) && StrUtil.equals(task.getTask_status(), "1")) { - Instruction instruction = instructionService.findByTaskcodeAndStatus(task.getTask_code()); - if (ObjectUtil.isNotEmpty(instruction)) { - list.add(task); - } - } - } - return list; - } - - public List queryTaskByNextAndIntStatus(String back_start_device_code) { - List list = new ArrayList<>(); - Iterator iterator = tasks.iterator(); - while (iterator.hasNext()) { - TaskDto task = iterator.next(); - if (!StrUtil.equals(task.getTask_type(), "6")) { - continue; - } - if ((task.getStart_device_code().equals(back_start_device_code)) && StrUtil.equals(task.getTask_status(), "1")) { - Instruction instruction = instructionService.findByTaskcodeAndStatus(task.getTask_code()); - if (ObjectUtil.isNotEmpty(instruction)) { - list.add(task); - } - } - } - return list; - } - - @Override - public TaskDto queryTaskByLinkNum(String link_num) { - return null; - } - - @Override - public List queryByStauts(String status) { - WQLObject wo = WQLObject.getWQLObject("acs_task"); - JSONArray arr = wo.query("task_status = '" + status + "'").getResultJSONArray(0); - List list = arr.toJavaList(TaskDto.class); - return list; - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void create(TaskDto dto) throws Exception { - dto = foramte(dto); - if (!StrUtil.isEmpty(dto.getVehicle_code())) { - TaskDto vehicle_dto = this.findByContainer(dto.getVehicle_code()); - if (vehicle_dto != null) { - throw new WDKException("已存在该载具号的任务!"); - } - } - String currentUsername = SecurityUtils.getCurrentUsername(); - String now = DateUtil.now(); - String task_uuid = dto.getTask_id(); - if (StrUtil.isEmpty(task_uuid)) { - dto.setTask_id(IdUtil.simpleUUID()); - } - String task_code = dto.getTask_code(); - if (StrUtil.isEmpty(task_code)) { - task_code = CodeUtil.getNewCode("TASK_NO"); - task_code = "-" + task_code; - } - String start_point_code = dto.getStart_point_code(); - String next_point_code = dto.getNext_point_code(); - String start_device_code = dto.getStart_device_code(); - String next_device_code = dto.getNext_device_code(); - String route_plan_code = dto.getRoute_plan_code(); - dto.setCreate_by(currentUsername); - dto.setUpdate_by(currentUsername); - dto.setUpdate_time(now); - dto.setCreate_time(now); - dto.setTask_code(task_code); - dto.setRoute_plan_code(route_plan_code); - dto.setTask_status("0"); - dto.setStart_device_code2(dto.getStart_point_code2()); - dto.setNext_device_code2(dto.getNext_point_code2()); - - if (StrUtil.isEmpty(dto.getPriority())) { - dto.setPriority("1"); - } - String plan_code = dto.getRoute_plan_code(); - //判断起点终点设备类型 - String startDeviceType = deviceAppService.findDeviceTypeByCode(dto.getStart_device_code()); - String nextDeviceType = deviceAppService.findDeviceTypeByCode(dto.getNext_device_code()); - if (routelineserver.getShortPathLines(dto.getStart_device_code(), dto.getNext_device_code(), plan_code).size() == 0) { - throw new Exception(dto.getStart_point_code() + "->" + dto.getNext_point_code() + "路由不通!"); - } - String createTaskCheck = paramService.findByCode(AcsConfig.CREATETASKCHECK).getValue(); - DeviceService deviceService = SpringContextHolder.getBean(DeviceServiceImpl.class); - DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); - Device nextdevice = appService.findDeviceByCode(next_device_code); - Device startdevice = appService.findDeviceByCode(start_device_code); - dto.setMaterial(startdevice.getMaterial_type()); - if (StrUtil.equals(createTaskCheck, "1")) { - //判断起点为输送设备 - if (StrUtil.equals(DeviceType.conveyor.toString(), startDeviceType)) { - - } - if (StrUtil.equals(DeviceType.conveyor.toString(), nextDeviceType)) { - } - } else { - //判断起点为输送设备 - if (StrUtil.equals(DeviceType.conveyor.toString(), startDeviceType)) { - - } - - if (StrUtil.equals(DeviceType.conveyor.toString(), nextDeviceType)) { -// if (nextdevice.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { -// standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) nextdevice.getDeviceDriver(); -// if (nextdevice.getHas_goods() != 0) { -// throw new Exception("任务终点需满足无货!"); -// } -// } - - JSONObject jo = new JSONObject(); - JSONObject jo2 = new JSONObject(); - if (!StrUtil.isEmpty(dto.getMaterial())) { - if (!StrUtil.equals(dto.getMaterial(), "1")) { - jo.put("hasGoodStatus", "2"); - jo.put("material_type", dto.getMaterial()); - } else { - jo.put("hasGoodStatus", "1"); - jo.put("material_type", "1"); - } - - } else { - jo.put("hasGoodStatus", "1"); - jo.put("material_type", "1"); - } - jo.put("device_code", dto.getStart_device_code()); - jo.put("quantity", dto.getQuantity()); - jo.put("remark", dto.getRemark()); - jo.put("batch", startdevice.getBatch()); - jo.put("islock", "true"); - deviceService.changeDeviceStatus(jo); - Device deviceByCode = deviceAppService.findDeviceByCode(dto.getNext_device_code()); - jo2.put("device_code", dto.getNext_device_code()); - jo2.put("hasGoodStatus", deviceByCode.getHas_goods()); - jo2.put("quantity", deviceByCode.getQuantity()); - jo2.put("remark", deviceByCode.getRemark()); - jo2.put("material_type", deviceByCode.getMaterial_type()); - jo2.put("batch", deviceByCode.getBatch()); - jo2.put("islock", "true"); - deviceService.changeDeviceStatus(jo2); - } - } - WQLObject wo = WQLObject.getWQLObject("acs_task"); - JSONObject json = (JSONObject) JSONObject.toJSON(dto); - - wo.insert(json); - tasks.add(dto); - } - - /** - * 常规任务保存 - * - * @param / - * @throws Exception - */ - @Override - public void ordinaryTaskCreate(JSONObject json) throws Exception { - JSONArray array = json.getJSONArray("data"); - - if (array.size() == 0) { - throw new RuntimeException("请选择起点"); - } - for (int i = 0; i < array.size(); i++) { - JSONObject arrjo = array.getJSONObject(i); - String material_type = arrjo.getString("material_type"); - String quantity = arrjo.getString("quantity"); - String remark = arrjo.getString("remark"); - TaskDto dto = new TaskDto(); - Map whereJson = (Map) array.get(i); - - //String device_code = (String) whereJson.get("device_code"); - String device_code = MapUtil.getStr(whereJson, "device_code"); - dto.setRoute_plan_code("one"); - String next_device_code = ""; - String plan_uuid = WQLObject.getWQLObject("acs_route_plan").query("plan_code= '" + dto.getRoute_plan_code() + "'").uniqueResult(0).getString("plan_uuid"); - JSONArray ja = routelineserver.queryNextLine(device_code, plan_uuid); - for (int j = 0; j < ja.size(); j++) { - JSONObject jo = (JSONObject) ja.get(j); - next_device_code = jo.get("next_device_code").toString(); - } - if (ObjectUtil.isNotEmpty(this.findByStartCode(device_code))) { - throw new WDKException("已存在该起点的任务!"); - } - if (StrUtil.equals(material_type, "") || StrUtil.equals(quantity, "")) { - throw new RuntimeException("请填写物料信息!"); - } - dto.setStart_device_code(device_code); - dto.setStart_point_code(device_code); - dto.setNext_device_code(next_device_code); - dto.setNext_point_code(next_device_code); - dto.setRemark(remark); - dto.setMaterial(material_type); - create(dto); - } - } - - /** - * 特殊任务保存 - * - * @param / - * @throws Exception - */ - @Override - public void specialTaskCreate(JSONObject json) throws Exception { - - JSONArray array = json.getJSONArray("data1"); - JSONArray array2 = json.getJSONArray("data2"); - JSONArray array3 = json.getJSONArray("data3"); - if (array.size() != 0 && array3.size() != 0) { - throw new RuntimeException("只能选择一个终点"); - } - - for (int i = 0; i < array2.size(); i++) { - JSONObject arrjo = array2.getJSONObject(i); - String material_type = arrjo.getString("material_type"); - String quantity = arrjo.getString("quantity"); - String remark = arrjo.getString("remark"); - TaskDto dto = new TaskDto(); - Map whereJson; - Map whereJson2; - Map whereJson3; - if (array.size() != 0) { - whereJson = (Map) array.get(i); - } else { - whereJson = null; - } - if (array2.size() != 0) { - whereJson2 = (Map) array2.get(i); - } else { - whereJson2 = null; - } - if (array3.size() != 0) { - whereJson3 = (Map) array3.get(i); - } else { - whereJson3 = null; - } - String start_device_code = MapUtil.getStr(whereJson2, "device_code"); - String next_device_code = ""; - if (ObjectUtil.isEmpty(whereJson)) { - next_device_code = MapUtil.getStr(whereJson3, "device_code"); - } else { - next_device_code = MapUtil.getStr(whereJson, "device_code"); - } - - if (ObjectUtil.isNotEmpty(this.findByStartCode(start_device_code)) - || ObjectUtil.isNotEmpty(this.findByNextCode(next_device_code))) { - throw new WDKException("已存在该起点或终点的任务!"); - } - if (StrUtil.equals(material_type, "") || StrUtil.equals(quantity, "")) { - throw new RuntimeException("请填写物料信息!"); - } - dto.setRoute_plan_code("two"); - dto.setStart_device_code(start_device_code); - dto.setStart_point_code(start_device_code); - dto.setNext_device_code(next_device_code); - dto.setNext_point_code(next_device_code); - dto.setRemark(remark); - dto.setMaterial(material_type); - create(dto); - } - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void update(TaskDto dto) { - TaskDto entity = this.findById(dto.getTask_id()); - if (entity == null) { - throw new BadRequestException("被删除或无权限,操作失败!"); - } - - String currentUsername = SecurityUtils.getCurrentUsername(); - String now = DateUtil.now(); - dto.setUpdate_time(now); - dto.setUpdate_by(currentUsername); - - WQLObject wo = WQLObject.getWQLObject("acs_task"); - JSONObject json = (JSONObject) JSONObject.toJSON(dto); - - wo.update(json); - - Iterator iterator = tasks.iterator(); - while (iterator.hasNext()) { - TaskDto task = iterator.next(); - if (task.getTask_code().equals(dto.getTask_code())) { - iterator.remove(); - } - } - if (StrUtil.equals(dto.getTask_status(), "0") || StrUtil.equals(dto.getTask_status(), "1")) { - tasks.add(dto); - } - //判断是否为WMS下发的任务,如果是反馈任务状态给WMS - String hasWms = paramService.findByCode(AcsConfig.HASWMS).getValue(); - if (!StrUtil.startWith(dto.getTask_code(), "-") && StrUtil.equals(hasWms, "1")) { - TaskFeedbackDto feefbackdto = taskFeedbackService.findByCode(entity.getTask_code()); - JSONObject feed_jo = new JSONObject(); - feed_jo.put("task_id", entity.getExt_task_id()); - feed_jo.put("task_code", dto.getTask_code()); - feed_jo.put("task_status", dto.getTask_status()); - JSONArray ja = new JSONArray(); - ja.add(feed_jo); - String message = null; - HttpResponse body = null; - boolean flag = false; - try { - body = acstowmsService.feedbackTaskStatusToWms(ja); - } catch (Exception e) { - flag = true; - message = e.getMessage(); - e.printStackTrace(); - } finally { - - } - if (flag) { - if (ObjectUtil.isEmpty(feefbackdto)) { - feefbackdto = new TaskFeedbackDto(); - feefbackdto.setTask_id(entity.getTask_id()); - feefbackdto.setTask_code(entity.getTask_code()); - feefbackdto.setTask_status(entity.getTask_status()); - feefbackdto.setVehicle_type(entity.getVehicle_type()); - feefbackdto.setVehicle_code(entity.getVehicle_code()); - feefbackdto.setStart_device_code(entity.getStart_device_code()); - feefbackdto.setStart_point_code(entity.getStart_point_code()); - feefbackdto.setNext_device_code(entity.getNext_device_code()); - feefbackdto.setNext_point_code(entity.getNext_point_code()); - feefbackdto.setError_code("400"); - feefbackdto.setIs_finished("0"); - feefbackdto.setRemark(message); - taskFeedbackService.create(feefbackdto); - } else { - feefbackdto.setTask_status(entity.getTask_status()); - feefbackdto.setStart_device_code(entity.getStart_device_code()); - feefbackdto.setStart_point_code(entity.getStart_point_code()); - feefbackdto.setNext_device_code(entity.getNext_device_code()); - feefbackdto.setNext_point_code(entity.getNext_point_code()); - feefbackdto.setError_code("400"); - feefbackdto.setRemark(message); - taskFeedbackService.update(feefbackdto); - } - } else { - int status = body.getStatus(); - JSONObject jo = JSONObject.parseObject(body.body()); - if (ObjectUtil.isEmpty(feefbackdto)) { - feefbackdto = new TaskFeedbackDto(); - feefbackdto.setTask_id(entity.getTask_id()); - feefbackdto.setTask_code(entity.getTask_code()); - feefbackdto.setTask_status(entity.getTask_status()); - feefbackdto.setVehicle_type(entity.getVehicle_type()); - feefbackdto.setVehicle_code(entity.getVehicle_code()); - feefbackdto.setError_code(String.valueOf(body.getStatus())); - feefbackdto.setStart_device_code(entity.getStart_device_code()); - feefbackdto.setStart_point_code(entity.getNext_point_code()); - feefbackdto.setNext_device_code(entity.getNext_device_code()); - feefbackdto.setNext_point_code(entity.getNext_point_code()); - if (status == 200) { - if (StrUtil.equals(entity.getTask_status(), "2")) { - feefbackdto.setIs_finished("1"); - } else { - feefbackdto.setIs_finished("0"); - } - } else { - feefbackdto.setIs_finished("0"); - feefbackdto.setRemark(jo.getString("message")); - } - taskFeedbackService.create(feefbackdto); - } else { - feefbackdto.setTask_status(entity.getTask_status()); - if (status == 200) { - } else { - if (StrUtil.equals(entity.getTask_status(), "2")) { - feefbackdto.setIs_finished("1"); - } else { - feefbackdto.setIs_finished("0"); - } - } - taskFeedbackService.update(feefbackdto); - } - } - - } - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void deleteAll(String[] ids) throws Exception { - for (String task_id : ids) { - this.cancel(task_id); - } - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void finish(String id) { - TaskDto entity = this.findById(id); - if (entity == null) throw new BadRequestException("被删除或无权限,操作失败!"); - InstructionService instructionservice = SpringContextHolder.getBean("instructionServiceImpl"); - InstructionDto instdto = instructionservice.findByTaskid(id, "instruction_status <2 "); - if (instdto != null) throw new BadRequestException("有指令未完成!"); - String currentUsername = SecurityUtils.getCurrentUsername(); - String now = DateUtil.now(); - entity.setUpdate_time(now); - entity.setUpdate_by(currentUsername); - entity.setTask_status("2"); - WQLObject wo = WQLObject.getWQLObject("acs_task"); - JSONObject json = (JSONObject) JSONObject.toJSON(entity); - wo.update(json); - removeByCodeFromCache(entity.getTask_code()); - //判断是否为WMS下发的任务,如果是反馈任务状态给WMS - String hasWms = paramService.findByCode(AcsConfig.HASWMS).getValue(); - if (!StrUtil.startWith(entity.getTask_code(), "-") && StrUtil.equals(hasWms, "1")) { - TaskFeedbackDto feefbackdto = taskFeedbackService.findByCode(entity.getTask_code()); - JSONObject feed_jo = new JSONObject(); - feed_jo.put("task_id", entity.getTask_id()); - feed_jo.put("task_code", entity.getTask_code()); - feed_jo.put("task_status", entity.getTask_status()); - JSONArray ja = new JSONArray(); - ja.add(feed_jo); - String message = null; - HttpResponse body = null; - boolean flag = false; - try { - body = acstowmsService.feedbackTaskStatusToWms(ja); - } catch (Exception e) { - flag = true; - message = e.getMessage(); - e.printStackTrace(); - } finally { - - } - if (flag) { - if (ObjectUtil.isEmpty(feefbackdto)) { - feefbackdto = new TaskFeedbackDto(); - feefbackdto.setTask_id(entity.getTask_id()); - feefbackdto.setTask_code(entity.getTask_code()); - feefbackdto.setTask_status(entity.getTask_status()); - feefbackdto.setVehicle_type(entity.getVehicle_type()); - feefbackdto.setVehicle_code(entity.getVehicle_code()); - feefbackdto.setStart_device_code(entity.getStart_device_code()); - feefbackdto.setStart_point_code(entity.getStart_point_code()); - feefbackdto.setNext_device_code(entity.getNext_device_code()); - feefbackdto.setNext_point_code(entity.getNext_point_code()); - feefbackdto.setError_code("400"); - feefbackdto.setIs_finished("0"); - feefbackdto.setRemark(message); - taskFeedbackService.create(feefbackdto); - } else { - feefbackdto.setTask_status(entity.getTask_status()); - feefbackdto.setStart_device_code(entity.getStart_device_code()); - feefbackdto.setStart_point_code(entity.getStart_point_code()); - feefbackdto.setNext_device_code(entity.getNext_device_code()); - feefbackdto.setNext_point_code(entity.getNext_point_code()); - feefbackdto.setError_code("400"); - feefbackdto.setRemark(message); - taskFeedbackService.update(feefbackdto); - } - } else { - int status = body.getStatus(); - JSONObject jo = JSONObject.parseObject(body.body()); - if (ObjectUtil.isEmpty(feefbackdto)) { - feefbackdto = new TaskFeedbackDto(); - feefbackdto.setTask_id(entity.getTask_id()); - feefbackdto.setTask_code(entity.getTask_code()); - feefbackdto.setTask_status(entity.getTask_status()); - feefbackdto.setVehicle_type(entity.getVehicle_type()); - feefbackdto.setVehicle_code(entity.getVehicle_code()); - feefbackdto.setError_code(String.valueOf(body.getStatus())); - feefbackdto.setStart_device_code(entity.getStart_device_code()); - feefbackdto.setStart_point_code(entity.getNext_point_code()); - feefbackdto.setNext_device_code(entity.getNext_device_code()); - feefbackdto.setNext_point_code(entity.getNext_point_code()); - if (status == 200) { - if (StrUtil.equals(entity.getTask_status(), "2")) { - feefbackdto.setIs_finished("1"); - } else { - feefbackdto.setIs_finished("0"); - } - } else { - feefbackdto.setIs_finished("0"); - feefbackdto.setRemark(jo.getString("message")); - } - taskFeedbackService.create(feefbackdto); - } else { - feefbackdto.setTask_status(entity.getTask_status()); - if (status == 200) { - if (StrUtil.equals(entity.getTask_status(), "2")) { - feefbackdto.setIs_finished("1"); - } else { - feefbackdto.setIs_finished("0"); - } - } else { - feefbackdto.setIs_finished("0"); - feefbackdto.setRemark(jo.getString("message")); - } - taskFeedbackService.update(feefbackdto); - } - } - - } - //如果属于先知AGV,关闭运单序列 - if (StrUtil.equals(paramService.findByCode(AcsConfig.AGVTYPE).getValue(), "3")) { - try { - agvService.markComplete(entity.getTask_code()); - } catch (Exception e) { - e.printStackTrace(); - } - } - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void cancel(String id) throws Exception { - TaskDto entity = this.findById(id); - if (entity == null) { - throw new BadRequestException("被删除或无权限,操作失败!"); - } - InstructionService instructionservice = SpringContextHolder.getBean("instructionServiceImpl"); - InstructionDto instdto = instructionservice.findByTaskid(id, "instruction_status <2 "); - if (instdto != null) { - throw new BadRequestException("有指令未完成!"); - } - String currentUsername = SecurityUtils.getCurrentUsername(); - String now = DateUtil.now(); - entity.setUpdate_time(now); - entity.setUpdate_by(currentUsername); - entity.setTask_status("3"); - WQLObject wo = WQLObject.getWQLObject("acs_task"); - JSONObject json = (JSONObject) JSONObject.toJSON(entity); - wo.update(json); - //清理缓存 - for (int i = 0; i < tasks.size(); i++) { - TaskDto taskDto = tasks.get(i); - if (taskDto.getTask_id().equals(id)) { - tasks.remove(i); - } - } - //判断是否为WMS下发的任务,如果是反馈任务状态给WMS - String hasWms = paramService.findByCode(AcsConfig.HASWMS).getValue(); - if (!StrUtil.startWith(entity.getTask_code(), "-") && StrUtil.equals(hasWms, "1")) { - JSONObject feed_jo = new JSONObject(); - feed_jo.put("task_id", entity.getTask_id()); - feed_jo.put("task_code", entity.getTask_code()); - feed_jo.put("task_status", entity.getTask_status()); - JSONArray ja = new JSONArray(); - ja.add(feed_jo); - acstowmsService.feedbackTaskStatusToWms(ja); - } - List shortPathsList = routeLineService.getShortPathLines(entity.getStart_device_code(), entity.getNext_device_code(), entity.getRoute_plan_code()); - String type = shortPathsList.get(0).getType(); - // != 0 为agv任务 - if (!StrUtil.equals(type, "0")) { - if (StrUtil.equals(paramService.findByCode(AcsConfig.AGVTYPE).getValue(), "3")) { - agvService.markComplete(entity.getTask_code()); - } - } - } - - @Override - public Instruction createTemporaryInst(TaskDto acsTask){ - if (acsTask == null) { - throw new BadRequestException("被删除或无权限,操作失败!"); - } - acsTask = foramte(acsTask); - ParamService paramService = SpringContextHolder.getBean(ParamService.class); - DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); - InstructionService instructionservice = SpringContextHolder.getBean("instructionServiceImpl"); -// InstructionDto inst = instructionservice.findByTaskid(acsTask, "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 from_x = acsTask.getFrom_x(); - String from_y = acsTask.getFrom_y(); - String from_z = acsTask.getFrom_z(); - String to_x = acsTask.getTo_x(); - String to_y = acsTask.getTo_y(); - String to_z = acsTask.getTo_z(); - - - /** - * 开始平均分解校验 - */ - String this_device_code = this.queryAssignedByDevice(acsTask.getStart_device_code(), acsTask.getNext_device_code()); - if (StrUtil.isEmpty(this_device_code)) { - List 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 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(); - if (StrUtil.isEmpty(instdto.getInstruction_code())) { - instdto.setInstruction_code(CodeUtil.getNewCode("INSTRUCT_NO")); - } - 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.setFrom_x(from_x); - instdto.setFrom_y(from_y); - instdto.setFrom_z(from_z); - instdto.setTo_x(to_x); - instdto.setTo_y(to_y); - instdto.setTo_z(to_z); - - //判断agv系统 - //1、1楼叉车系统 - //2、2楼1区域AGV系统 - //3、2楼2区域AGV系统 - if (!StrUtil.equals(agv_system_type, "1")) { - // task_type - //1、生箔; Itype=1:取空,取满,放空,放满; - //2、分切 Itype=3取满、取空、放满、放空; - //3、普通任务 Itype=2:取货、放货; - //4、叉车任务 - //5、输送任务 - //6、行架 - //7、立库 - if (StrUtil.equals(task_type, "1")) { - instdto.setAgv_inst_type("1"); - } else if (StrUtil.equals(task_type, "3")) { - instdto.setAgv_inst_type("2"); - } else if (StrUtil.equals(task_type, "2")) { - instdto.setAgv_inst_type("3"); - } - } else { - instdto.setAgv_inst_type("4"); - } - return instdto; - } - - - - @Override - public Instruction createInst(String ids) throws Exception { - TaskDto acsTask = this.findById(ids); - if (acsTask == null) { - throw new BadRequestException("被删除或无权限,操作失败!"); - } - ParamService paramService = SpringContextHolder.getBean(ParamService.class); - 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 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 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); - //判断agv系统 - //1、1楼叉车系统 - //2、2楼1区域AGV系统 - //3、2楼2区域AGV系统 - if (!StrUtil.equals(agv_system_type, "1")) { - // task_type - //1、生箔; Itype=1:取空,取满,放空,放满; - //2、分切 Itype=3取满、取空、放满、放空; - //3、普通任务 Itype=2:取货、放货; - //4、叉车任务 - //5、输送任务 - //6、行架 - //7、立库 - if (StrUtil.equals(task_type, "1")) { - instdto.setAgv_inst_type("1"); - } else if (StrUtil.equals(task_type, "3")) { - instdto.setAgv_inst_type("2"); - } else if (StrUtil.equals(task_type, "2")) { - instdto.setAgv_inst_type("3"); - } - } else { - instdto.setAgv_inst_type("4"); - } - instructionservice.create2(instdto); - -// acsTask.setTask_status("1"); -// this.update(acsTask); - return instdto; - } - - @Override - public Instruction createInst(Instruction inst) throws Exception { - - DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); - InstructionService instructionservice = SpringContextHolder.getBean("instructionServiceImpl"); - - instructionservice.create2(inst); - return inst; - } - - - @Override - public void download(List all, HttpServletResponse response) throws IOException { - List> list = new ArrayList<>(); - for (TaskDto acsTask : all) { - Map map = new LinkedHashMap<>(); - map.put("任务号", acsTask.getTask_code()); - map.put("载具号", acsTask.getVehicle_code()); - map.put("载具类型", acsTask.getVehicle_type()); - map.put("任务类型", acsTask.getTask_type()); - map.put("任务状态", acsTask.getTask_status()); - map.put("任务优先级", acsTask.getPriority()); - map.put("创建类型", acsTask.getCreate_type()); - map.put("完成类型", acsTask.getFinish_type()); - map.put("执行描述编码", acsTask.getExecute_code()); - map.put("执行描述信息", acsTask.getExecute_message()); - map.put("起始点位编码", acsTask.getStart_point_code()); - map.put("起始设备编码", acsTask.getStart_device_code()); - map.put("目标点位编码", acsTask.getNext_point_code()); - map.put("目标设备编码", acsTask.getNext_device_code()); - map.put("排", acsTask.getFrom_x()); - map.put("列", acsTask.getFrom_y()); - map.put("层", acsTask.getFrom_z()); - map.put("排", acsTask.getTo_x()); - map.put("列", acsTask.getTo_y()); - map.put("层", acsTask.getTo_z()); - map.put("路由方案名称", acsTask.getRoute_plan_name()); - map.put("路由方案编码", acsTask.getRoute_plan_code()); - map.put("是否需要反馈上位系统", acsTask.getIs_needfeedback()); - map.put("备注", acsTask.getRemark()); - map.put("是否启用", acsTask.getIs_active()); - map.put("是否删除", acsTask.getIs_delete()); - map.put("创建者", acsTask.getCreate_by()); - map.put("创建时间", acsTask.getCreate_time()); - map.put("修改者", acsTask.getUpdate_by()); - map.put("修改时间", acsTask.getUpdate_time()); - list.add(map); - } - FileUtil.downloadExcel(list, response); - } - - @Override - public void createTaskByClick(JSONObject json) { - - } - - @Override - public int checkAllowCreate(String devicecode) { - Map map = new HashMap(); - List taskList = this.queryAllUnfinished(map); - int num = 0; - for (int i = 0; i < taskList.size(); i++) { - TaskDto onetask = taskList.get(i); - String next_code = onetask.getNext_point_code(); - if (StrUtil.equals(devicecode, next_code)) { - num = num + 1; - } - } - return num; - } - - @Override - public boolean removeByCodeFromCache(String code) { - Iterator iterator = tasks.iterator(); - while (iterator.hasNext()) { - TaskDto task = iterator.next(); - if (task.getTask_code().equals(code)) { - iterator.remove(); - return true; - } - } - return false; - } - - @Override - public List findAllTaskFromCache() { - return tasks; - } - - - public TaskDto findByContainer(String container_code) { - Iterator var3 = tasks.iterator(); - - while (var3.hasNext()) { - TaskDto task = (TaskDto) var3.next(); - if (StrUtil.equals(task.getVehicle_code(), container_code)) { - return task; - } - } - - return null; - } - - public TaskDto findByCodeFromCache(String task_code) { - Iterator var3 = tasks.iterator(); - - while (var3.hasNext()) { - TaskDto task = (TaskDto) var3.next(); - if (StrUtil.equals(task.getTask_code(), task_code)) { - return task; - } - } - return null; - } - - @Override - public TaskDto findByNextCode(String device_code) { - Iterator var3 = tasks.iterator(); - - while (var3.hasNext()) { - TaskDto task = (TaskDto) var3.next(); - if (StrUtil.equals(task.getNext_device_code(), device_code)) { - return task; - } - } - return null; - } - - @Override - public List findAllByNextCode(String device_code) { - return null; - } - - @Override - public Integer queryAllTaskMaterialQty(String device_code) { - return null; - } - - - @Override - public TaskDto findByStartCodeAndReady(String device_code) { - Iterator var3 = tasks.iterator(); - - while (var3.hasNext()) { - TaskDto task = (TaskDto) var3.next(); -// if (!StrUtil.equals(task.getTask_type(), "5")) { -// continue; -// } - if (StrUtil.equals(task.getStart_device_code(), device_code) && StrUtil.equals(task.getTask_status(), "0")) { - return task; - } - } - return null; - } - - @Override - public TaskDto findByStartCode(String device_code) { - Iterator var3 = tasks.iterator(); - - while (var3.hasNext()) { - TaskDto task = (TaskDto) var3.next(); - if (StrUtil.equals(task.getStart_device_code(), device_code)) { - return task; - } - } - return null; - } - - @Override - public TaskDto foramte(TaskDto task) { - String start_point_code = task.getStart_point_code(); - String next_point_code = task.getNext_point_code(); - String from_y = null; - String from_z = null; - String to_y = null; - String to_z = null; - if (StrUtil.contains(start_point_code, "-") && StrUtil.count(start_point_code, "-") == 2) { - String[] start_point = start_point_code.split("-"); - task.setFrom_x(start_point[0]); - task.setStart_device_code(start_point[0]); - if (Integer.parseInt(start_point[1]) < 10 && start_point[1].length() == 1) { - from_y = "0" + start_point[1]; - task.setFrom_y(from_y); - } else { - from_y = start_point[1]; - task.setFrom_y(from_y); - } - if (Integer.parseInt(start_point[2]) < 10 && start_point[2].length() == 1) { - from_z = "0" + start_point[2]; - task.setFrom_z(from_z); - } else if (start_point[2].length() == 2 ){ - from_z = start_point[2]; - task.setFrom_z(start_point[2]); - } else { - from_z = start_point[2]; - } - task.setStart_point_code(task.getStart_device_code() + "-" + from_y + "-" + from_z); - task.setStart_device_code(task.getStart_device_code()); + JSONObject jo2 = new JSONObject(); + if (!StrUtil.isEmpty(dto.getMaterial())) { + if (!StrUtil.equals(dto.getMaterial(), "1")) { + jo.put("hasGoodStatus", "2"); + jo.put("material_type", dto.getMaterial()); + } else { + jo.put("hasGoodStatus", "1"); + jo.put("material_type", "1"); + } } else { - String start_device = deviceAppService.findDeviceByCode(start_point_code).getDeviceDriverDefination().getFitDeviceTypes().get(0).name(); - //如果point_device为货架,则不包含列层信息,需要重新拼接 - if (StrUtil.equals("storage", start_device)) { - if (StrUtil.isEmpty(task.getFrom_x())) { - throw new BadRequestException("货位信息起点需要包含列信息"); - } - if (StrUtil.isEmpty(task.getFrom_y())) { - throw new BadRequestException("货位信息起点需要包含层信息"); - } - if (Integer.parseInt(task.getFrom_y()) < 10 && task.getFrom_y().length() == 1) { - from_y = "0" + task.getFrom_y(); - task.setFrom_y(from_y); - } else { - from_y = task.getFrom_y(); - } - if (Integer.parseInt(task.getFrom_z()) < 10 && task.getFrom_z().length() == 1) { - from_z = "0" + task.getFrom_z(); - task.setFrom_z(from_z); - } else if (task.getFrom_z().length() == 2 ) { - from_z = task.getFrom_z(); - task.setFrom_z(from_z); - } else { - from_z = task.getFrom_z(); - } - task.setFrom_x(start_point_code); - task.setStart_point_code(start_point_code + "-" + from_y + "-" + from_z); - task.setStart_device_code(start_point_code); - } else { - task.setStart_device_code(start_point_code); - task.setStart_device_code(start_point_code); - } + jo.put("hasGoodStatus", "1"); + jo.put("material_type", "1"); } + jo.put("device_code", dto.getStart_device_code()); + jo.put("quantity", dto.getQuantity()); + jo.put("remark", dto.getRemark()); + jo.put("batch", startdevice.getBatch()); + jo.put("islock", "true"); + deviceService.changeDeviceStatus(jo); + Device deviceByCode = deviceAppService.findDeviceByCode(dto.getNext_device_code()); + jo2.put("device_code", dto.getNext_device_code()); + jo2.put("hasGoodStatus", deviceByCode.getHas_goods()); + jo2.put("quantity", deviceByCode.getQuantity()); + jo2.put("remark", deviceByCode.getRemark()); + jo2.put("material_type", deviceByCode.getMaterial_type()); + jo2.put("batch", deviceByCode.getBatch()); + jo2.put("islock", "true"); + deviceService.changeDeviceStatus(jo2); + } + } + WQLObject wo = WQLObject.getWQLObject("acs_task"); + JSONObject json = (JSONObject) JSONObject.toJSON(dto); - if (StrUtil.contains(next_point_code, "-") && StrUtil.count(next_point_code, "-") == 2) { - String[] next_point = next_point_code.split("-"); - task.setNext_device_code(next_point[0]); - task.setTo_x(next_point[0]); - if (Integer.parseInt(next_point[1]) < 10 && next_point[1].length() == 1) { - to_y = "0" + next_point[1]; - task.setTo_y(to_y); - } else { - to_y = next_point[1]; - task.setTo_y(to_y); - } - if (Integer.parseInt(next_point[2]) < 10 && next_point[2].length() == 1) { - to_z = "0" + next_point[2]; - task.setTo_z(to_z); - } else if ( next_point[2].length() == 2){ - to_z = next_point[2]; - task.setTo_z(to_z); - } else { - to_z = next_point[2]; - task.setTo_z(to_z); - } - task.setNext_point_code(task.getNext_device_code() + "-" + to_y + "-" + to_z); - task.setNext_device_code(task.getNext_device_code()); + wo.insert(json); + tasks.add(dto); + } + /** + * 常规任务保存 + * + * @param / + * @throws Exception + */ + @Override + public void ordinaryTaskCreate(JSONObject json) throws Exception { + JSONArray array = json.getJSONArray("data"); + + if (array.size() == 0) { + throw new RuntimeException("请选择起点"); + } + for (int i = 0; i < array.size(); i++) { + JSONObject arrjo = array.getJSONObject(i); + String material_type = arrjo.getString("material_type"); + String quantity = arrjo.getString("quantity"); + String remark = arrjo.getString("remark"); + TaskDto dto = new TaskDto(); + Map whereJson = (Map) array.get(i); + + // String device_code = (String) whereJson.get("device_code"); + String device_code = MapUtil.getStr(whereJson, "device_code"); + dto.setRoute_plan_code("one"); + String next_device_code = ""; + String plan_uuid = + WQLObject.getWQLObject("acs_route_plan") + .query("plan_code= '" + dto.getRoute_plan_code() + "'") + .uniqueResult(0) + .getString("plan_uuid"); + JSONArray ja = routelineserver.queryNextLine(device_code, plan_uuid); + for (int j = 0; j < ja.size(); j++) { + JSONObject jo = (JSONObject) ja.get(j); + next_device_code = jo.get("next_device_code").toString(); + } + if (ObjectUtil.isNotEmpty(this.findByStartCode(device_code))) { + throw new WDKException("已存在该起点的任务!"); + } + if (StrUtil.equals(material_type, "") || StrUtil.equals(quantity, "")) { + throw new RuntimeException("请填写物料信息!"); + } + dto.setStart_device_code(device_code); + dto.setStart_point_code(device_code); + dto.setNext_device_code(next_device_code); + dto.setNext_point_code(next_device_code); + dto.setRemark(remark); + dto.setMaterial(material_type); + create(dto); + } + } + + /** + * 特殊任务保存 + * + * @param / + * @throws Exception + */ + @Override + public void specialTaskCreate(JSONObject json) throws Exception { + + JSONArray array = json.getJSONArray("data1"); + JSONArray array2 = json.getJSONArray("data2"); + JSONArray array3 = json.getJSONArray("data3"); + if (array.size() != 0 && array3.size() != 0) { + throw new RuntimeException("只能选择一个终点"); + } + + for (int i = 0; i < array2.size(); i++) { + JSONObject arrjo = array2.getJSONObject(i); + String material_type = arrjo.getString("material_type"); + String quantity = arrjo.getString("quantity"); + String remark = arrjo.getString("remark"); + TaskDto dto = new TaskDto(); + Map whereJson; + Map whereJson2; + Map whereJson3; + if (array.size() != 0) { + whereJson = (Map) array.get(i); + } else { + whereJson = null; + } + if (array2.size() != 0) { + whereJson2 = (Map) array2.get(i); + } else { + whereJson2 = null; + } + if (array3.size() != 0) { + whereJson3 = (Map) array3.get(i); + } else { + whereJson3 = null; + } + String start_device_code = MapUtil.getStr(whereJson2, "device_code"); + String next_device_code = ""; + if (ObjectUtil.isEmpty(whereJson)) { + next_device_code = MapUtil.getStr(whereJson3, "device_code"); + } else { + next_device_code = MapUtil.getStr(whereJson, "device_code"); + } + + if (ObjectUtil.isNotEmpty(this.findByStartCode(start_device_code)) + || ObjectUtil.isNotEmpty(this.findByNextCode(next_device_code))) { + throw new WDKException("已存在该起点或终点的任务!"); + } + if (StrUtil.equals(material_type, "") || StrUtil.equals(quantity, "")) { + throw new RuntimeException("请填写物料信息!"); + } + dto.setRoute_plan_code("two"); + dto.setStart_device_code(start_device_code); + dto.setStart_point_code(start_device_code); + dto.setNext_device_code(next_device_code); + dto.setNext_point_code(next_device_code); + dto.setRemark(remark); + dto.setMaterial(material_type); + create(dto); + } + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void update(TaskDto dto) { + TaskDto entity = this.findById(dto.getTask_id()); + if (entity == null) { + throw new BadRequestException("被删除或无权限,操作失败!"); + } + + String currentUsername = SecurityUtils.getCurrentUsername(); + String now = DateUtil.now(); + dto.setUpdate_time(now); + dto.setUpdate_by(currentUsername); + + WQLObject wo = WQLObject.getWQLObject("acs_task"); + JSONObject json = (JSONObject) JSONObject.toJSON(dto); + + wo.update(json); + + Iterator iterator = tasks.iterator(); + while (iterator.hasNext()) { + TaskDto task = iterator.next(); + if (task.getTask_code().equals(dto.getTask_code())) { + iterator.remove(); + } + } + if (StrUtil.equals(dto.getTask_status(), "0") || StrUtil.equals(dto.getTask_status(), "1")) { + tasks.add(dto); + } + // 判断是否为WMS下发的任务,如果是反馈任务状态给WMS + String hasWms = paramService.findByCode(AcsConfig.HASWMS).getValue(); + if (!StrUtil.startWith(dto.getTask_code(), "-") && StrUtil.equals(hasWms, "1")) { + TaskFeedbackDto feefbackdto = taskFeedbackService.findByCode(entity.getTask_code()); + JSONObject feed_jo = new JSONObject(); + feed_jo.put("task_id", entity.getExt_task_id()); + feed_jo.put("task_code", dto.getTask_code()); + feed_jo.put("task_status", dto.getTask_status()); + JSONArray ja = new JSONArray(); + ja.add(feed_jo); + String message = null; + HttpResponse body = null; + boolean flag = false; + try { + body = acstowmsService.feedbackTaskStatusToWms(ja); + } catch (Exception e) { + flag = true; + message = e.getMessage(); + e.printStackTrace(); + } finally { + + } + if (flag) { + if (ObjectUtil.isEmpty(feefbackdto)) { + feefbackdto = new TaskFeedbackDto(); + feefbackdto.setTask_id(entity.getTask_id()); + feefbackdto.setTask_code(entity.getTask_code()); + feefbackdto.setTask_status(entity.getTask_status()); + feefbackdto.setVehicle_type(entity.getVehicle_type()); + feefbackdto.setVehicle_code(entity.getVehicle_code()); + feefbackdto.setStart_device_code(entity.getStart_device_code()); + feefbackdto.setStart_point_code(entity.getStart_point_code()); + feefbackdto.setNext_device_code(entity.getNext_device_code()); + feefbackdto.setNext_point_code(entity.getNext_point_code()); + feefbackdto.setError_code("400"); + feefbackdto.setIs_finished("0"); + feefbackdto.setRemark(message); + taskFeedbackService.create(feefbackdto); } else { - String next_device = deviceAppService.findDeviceByCode(next_point_code).getDeviceDriverDefination().getFitDeviceTypes().get(0).name(); - if (StrUtil.equals("storage", next_device)) { - if (StrUtil.isEmpty(task.getTo_x())) { - throw new BadRequestException("货位信息终点需要包含列信息"); - } - if (StrUtil.isEmpty(task.getTo_y())) { - throw new BadRequestException("货位信息终点需要包含层信息"); - } - if (Integer.parseInt(task.getTo_y()) < 10 && task.getTo_y().length() == 1) { - to_y = "0" + task.getTo_y(); - task.setTo_y(to_y); - } else { - to_y = task.getTo_y(); - } - if (Integer.parseInt(task.getTo_z()) < 10 && task.getTo_z().length() == 1) { - to_z = "0" + task.getTo_z(); - task.setTo_z(to_z); - } else if (task.getTo_z().length() == 2){ - to_z = task.getTo_z(); - task.setTo_z(to_z); - } else { - to_z = task.getTo_z(); - } - task.setTo_x(next_point_code); - task.setNext_point_code(next_point_code + "-" + to_y + "-" + to_z); - task.setNext_device_code(next_point_code); - - } else { - task.setNext_device_code(next_point_code); - task.setNext_device_code(next_point_code); - - } + feefbackdto.setTask_status(entity.getTask_status()); + feefbackdto.setStart_device_code(entity.getStart_device_code()); + feefbackdto.setStart_point_code(entity.getStart_point_code()); + feefbackdto.setNext_device_code(entity.getNext_device_code()); + feefbackdto.setNext_point_code(entity.getNext_point_code()); + feefbackdto.setError_code("400"); + feefbackdto.setRemark(message); + taskFeedbackService.update(feefbackdto); } + } else { + int status = body.getStatus(); + JSONObject jo = JSONObject.parseObject(body.body()); + if (ObjectUtil.isEmpty(feefbackdto)) { + feefbackdto = new TaskFeedbackDto(); + feefbackdto.setTask_id(entity.getTask_id()); + feefbackdto.setTask_code(entity.getTask_code()); + feefbackdto.setTask_status(entity.getTask_status()); + feefbackdto.setVehicle_type(entity.getVehicle_type()); + feefbackdto.setVehicle_code(entity.getVehicle_code()); + feefbackdto.setError_code(String.valueOf(body.getStatus())); + feefbackdto.setStart_device_code(entity.getStart_device_code()); + feefbackdto.setStart_point_code(entity.getNext_point_code()); + feefbackdto.setNext_device_code(entity.getNext_device_code()); + feefbackdto.setNext_point_code(entity.getNext_point_code()); + if (status == 200) { + if (StrUtil.equals(entity.getTask_status(), "2")) { + feefbackdto.setIs_finished("1"); + } else { + feefbackdto.setIs_finished("0"); + } + } else { + feefbackdto.setIs_finished("0"); + feefbackdto.setRemark(jo.getString("message")); + } + taskFeedbackService.create(feefbackdto); + } else { + feefbackdto.setTask_status(entity.getTask_status()); + if (status == 200) { + } else { + if (StrUtil.equals(entity.getTask_status(), "2")) { + feefbackdto.setIs_finished("1"); + } else { + feefbackdto.setIs_finished("0"); + } + } + taskFeedbackService.update(feefbackdto); + } + } + } + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void deleteAll(String[] ids) throws Exception { + for (String task_id : ids) { + this.cancel(task_id); + } + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void finish(String id) { + TaskDto entity = this.findById(id); + if (entity == null) throw new BadRequestException("被删除或无权限,操作失败!"); + InstructionService instructionservice = SpringContextHolder.getBean("instructionServiceImpl"); + InstructionDto instdto = instructionservice.findByTaskid(id, "instruction_status <2 "); + if (instdto != null) throw new BadRequestException("有指令未完成!"); + String currentUsername = SecurityUtils.getCurrentUsername(); + String now = DateUtil.now(); + entity.setUpdate_time(now); + entity.setUpdate_by(currentUsername); + entity.setTask_status("2"); + WQLObject wo = WQLObject.getWQLObject("acs_task"); + JSONObject json = (JSONObject) JSONObject.toJSON(entity); + wo.update(json); + removeByCodeFromCache(entity.getTask_code()); + // 判断是否为WMS下发的任务,如果是反馈任务状态给WMS + String hasWms = paramService.findByCode(AcsConfig.HASWMS).getValue(); + if (!StrUtil.startWith(entity.getTask_code(), "-") && StrUtil.equals(hasWms, "1")) { + TaskFeedbackDto feefbackdto = taskFeedbackService.findByCode(entity.getTask_code()); + JSONObject feed_jo = new JSONObject(); + feed_jo.put("task_id", entity.getTask_id()); + feed_jo.put("task_code", entity.getTask_code()); + feed_jo.put("task_status", entity.getTask_status()); + JSONArray ja = new JSONArray(); + ja.add(feed_jo); + String message = null; + HttpResponse body = null; + boolean flag = false; + try { + body = acstowmsService.feedbackTaskStatusToWms(ja); + } catch (Exception e) { + flag = true; + message = e.getMessage(); + e.printStackTrace(); + } finally { + + } + if (flag) { + if (ObjectUtil.isEmpty(feefbackdto)) { + feefbackdto = new TaskFeedbackDto(); + feefbackdto.setTask_id(entity.getTask_id()); + feefbackdto.setTask_code(entity.getTask_code()); + feefbackdto.setTask_status(entity.getTask_status()); + feefbackdto.setVehicle_type(entity.getVehicle_type()); + feefbackdto.setVehicle_code(entity.getVehicle_code()); + feefbackdto.setStart_device_code(entity.getStart_device_code()); + feefbackdto.setStart_point_code(entity.getStart_point_code()); + feefbackdto.setNext_device_code(entity.getNext_device_code()); + feefbackdto.setNext_point_code(entity.getNext_point_code()); + feefbackdto.setError_code("400"); + feefbackdto.setIs_finished("0"); + feefbackdto.setRemark(message); + taskFeedbackService.create(feefbackdto); + } else { + feefbackdto.setTask_status(entity.getTask_status()); + feefbackdto.setStart_device_code(entity.getStart_device_code()); + feefbackdto.setStart_point_code(entity.getStart_point_code()); + feefbackdto.setNext_device_code(entity.getNext_device_code()); + feefbackdto.setNext_point_code(entity.getNext_point_code()); + feefbackdto.setError_code("400"); + feefbackdto.setRemark(message); + taskFeedbackService.update(feefbackdto); + } + } else { + int status = body.getStatus(); + JSONObject jo = JSONObject.parseObject(body.body()); + if (ObjectUtil.isEmpty(feefbackdto)) { + feefbackdto = new TaskFeedbackDto(); + feefbackdto.setTask_id(entity.getTask_id()); + feefbackdto.setTask_code(entity.getTask_code()); + feefbackdto.setTask_status(entity.getTask_status()); + feefbackdto.setVehicle_type(entity.getVehicle_type()); + feefbackdto.setVehicle_code(entity.getVehicle_code()); + feefbackdto.setError_code(String.valueOf(body.getStatus())); + feefbackdto.setStart_device_code(entity.getStart_device_code()); + feefbackdto.setStart_point_code(entity.getNext_point_code()); + feefbackdto.setNext_device_code(entity.getNext_device_code()); + feefbackdto.setNext_point_code(entity.getNext_point_code()); + if (status == 200) { + if (StrUtil.equals(entity.getTask_status(), "2")) { + feefbackdto.setIs_finished("1"); + } else { + feefbackdto.setIs_finished("0"); + } + } else { + feefbackdto.setIs_finished("0"); + feefbackdto.setRemark(jo.getString("message")); + } + taskFeedbackService.create(feefbackdto); + } else { + feefbackdto.setTask_status(entity.getTask_status()); + if (status == 200) { + if (StrUtil.equals(entity.getTask_status(), "2")) { + feefbackdto.setIs_finished("1"); + } else { + feefbackdto.setIs_finished("0"); + } + } else { + feefbackdto.setIs_finished("0"); + feefbackdto.setRemark(jo.getString("message")); + } + taskFeedbackService.update(feefbackdto); + } + } + } + // 如果属于先知AGV,关闭运单序列 + if (StrUtil.equals(paramService.findByCode(AcsConfig.AGVTYPE).getValue(), "3")) { + try { + agvService.markComplete(entity.getTask_code()); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void cancel(String id) throws Exception { + TaskDto entity = this.findById(id); + if (entity == null) { + throw new BadRequestException("被删除或无权限,操作失败!"); + } + InstructionService instructionservice = SpringContextHolder.getBean("instructionServiceImpl"); + InstructionDto instdto = instructionservice.findByTaskid(id, "instruction_status <2 "); + if (instdto != null) { + throw new BadRequestException("有指令未完成!"); + } + String currentUsername = SecurityUtils.getCurrentUsername(); + String now = DateUtil.now(); + entity.setUpdate_time(now); + entity.setUpdate_by(currentUsername); + entity.setTask_status("3"); + WQLObject wo = WQLObject.getWQLObject("acs_task"); + JSONObject json = (JSONObject) JSONObject.toJSON(entity); + wo.update(json); + + Iterator it = tasks.iterator(); + // 清理缓存 + while (it.hasNext()){ + TaskDto taskDto = it.next(); + if (taskDto.getTask_id().equals(id)) { + tasks.remove(taskDto); + } + } + // 判断是否为WMS下发的任务,如果是反馈任务状态给WMS + String hasWms = paramService.findByCode(AcsConfig.HASWMS).getValue(); + if (!StrUtil.startWith(entity.getTask_code(), "-") && StrUtil.equals(hasWms, "1")) { + JSONObject feed_jo = new JSONObject(); + feed_jo.put("task_id", entity.getTask_id()); + feed_jo.put("task_code", entity.getTask_code()); + feed_jo.put("task_status", entity.getTask_status()); + JSONArray ja = new JSONArray(); + ja.add(feed_jo); + acstowmsService.feedbackTaskStatusToWms(ja); + } + List shortPathsList = + routeLineService.getShortPathLines( + entity.getStart_device_code(), + entity.getNext_device_code(), + entity.getRoute_plan_code()); + String type = shortPathsList.get(0).getType(); + // != 0 为agv任务 + if (!StrUtil.equals(type, "0")) { + if (StrUtil.equals(paramService.findByCode(AcsConfig.AGVTYPE).getValue(), "3")) { + agvService.markComplete(entity.getTask_code()); + } + } + } + + @Override + public Instruction createTemporaryInst(TaskDto acsTask) { + if (acsTask == null) { + throw new BadRequestException("被删除或无权限,操作失败!"); + } + acsTask = foramte(acsTask); + ParamService paramService = SpringContextHolder.getBean(ParamService.class); + DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); + InstructionService instructionservice = SpringContextHolder.getBean("instructionServiceImpl"); + // InstructionDto inst = instructionservice.findByTaskid(acsTask, "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 from_x = acsTask.getFrom_x(); + String from_y = acsTask.getFrom_y(); + String from_z = acsTask.getFrom_z(); + String to_x = acsTask.getTo_x(); + String to_y = acsTask.getTo_y(); + String to_z = acsTask.getTo_z(); + + /** 开始平均分解校验 */ + String this_device_code = + this.queryAssignedByDevice(acsTask.getStart_device_code(), acsTask.getNext_device_code()); + if (StrUtil.isEmpty(this_device_code)) { + List 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 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(); + if (StrUtil.isEmpty(instdto.getInstruction_code())) { + instdto.setInstruction_code(CodeUtil.getNewCode("INSTRUCT_NO")); + } + 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.setFrom_x(from_x); + instdto.setFrom_y(from_y); + instdto.setFrom_z(from_z); + instdto.setTo_x(to_x); + instdto.setTo_y(to_y); + instdto.setTo_z(to_z); + + // 判断agv系统 + // 1、1楼叉车系统 + // 2、2楼1区域AGV系统 + // 3、2楼2区域AGV系统 + if (!StrUtil.equals(agv_system_type, "1")) { + // task_type + // 1、生箔; Itype=1:取空,取满,放空,放满; + // 2、分切 Itype=3取满、取空、放满、放空; + // 3、普通任务 Itype=2:取货、放货; + // 4、叉车任务 + // 5、输送任务 + // 6、行架 + // 7、立库 + if (StrUtil.equals(task_type, "1")) { + instdto.setAgv_inst_type("1"); + } else if (StrUtil.equals(task_type, "3")) { + instdto.setAgv_inst_type("2"); + } else if (StrUtil.equals(task_type, "2")) { + instdto.setAgv_inst_type("3"); + } + } else { + instdto.setAgv_inst_type("4"); + } + return instdto; + } + + @Override + public Instruction createInst(String ids) throws Exception { + TaskDto acsTask = this.findById(ids); + if (acsTask == null) { + throw new BadRequestException("被删除或无权限,操作失败!"); + } + ParamService paramService = SpringContextHolder.getBean(ParamService.class); + 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 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 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); + // 判断agv系统 + // 1、1楼叉车系统 + // 2、2楼1区域AGV系统 + // 3、2楼2区域AGV系统 + if (!StrUtil.equals(agv_system_type, "1")) { + // task_type + // 1、生箔; Itype=1:取空,取满,放空,放满; + // 2、分切 Itype=3取满、取空、放满、放空; + // 3、普通任务 Itype=2:取货、放货; + // 4、叉车任务 + // 5、输送任务 + // 6、行架 + // 7、立库 + if (StrUtil.equals(task_type, "1")) { + instdto.setAgv_inst_type("1"); + } else if (StrUtil.equals(task_type, "3")) { + instdto.setAgv_inst_type("2"); + } else if (StrUtil.equals(task_type, "2")) { + instdto.setAgv_inst_type("3"); + } + } else { + instdto.setAgv_inst_type("4"); + } + instructionservice.create2(instdto); + + // acsTask.setTask_status("1"); + // this.update(acsTask); + return instdto; + } + + @Override + public Instruction createInst(Instruction inst) throws Exception { + + DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); + InstructionService instructionservice = SpringContextHolder.getBean("instructionServiceImpl"); + + instructionservice.create2(inst); + return inst; + } + + @Override + public void download(List all, HttpServletResponse response) throws IOException { + List> list = new ArrayList<>(); + for (TaskDto acsTask : all) { + Map map = new LinkedHashMap<>(); + map.put("任务号", acsTask.getTask_code()); + map.put("载具号", acsTask.getVehicle_code()); + map.put("载具类型", acsTask.getVehicle_type()); + map.put("任务类型", acsTask.getTask_type()); + map.put("任务状态", acsTask.getTask_status()); + map.put("任务优先级", acsTask.getPriority()); + map.put("创建类型", acsTask.getCreate_type()); + map.put("完成类型", acsTask.getFinish_type()); + map.put("执行描述编码", acsTask.getExecute_code()); + map.put("执行描述信息", acsTask.getExecute_message()); + map.put("起始点位编码", acsTask.getStart_point_code()); + map.put("起始设备编码", acsTask.getStart_device_code()); + map.put("目标点位编码", acsTask.getNext_point_code()); + map.put("目标设备编码", acsTask.getNext_device_code()); + map.put("排", acsTask.getFrom_x()); + map.put("列", acsTask.getFrom_y()); + map.put("层", acsTask.getFrom_z()); + map.put("排", acsTask.getTo_x()); + map.put("列", acsTask.getTo_y()); + map.put("层", acsTask.getTo_z()); + map.put("路由方案名称", acsTask.getRoute_plan_name()); + map.put("路由方案编码", acsTask.getRoute_plan_code()); + map.put("是否需要反馈上位系统", acsTask.getIs_needfeedback()); + map.put("备注", acsTask.getRemark()); + map.put("是否启用", acsTask.getIs_active()); + map.put("是否删除", acsTask.getIs_delete()); + map.put("创建者", acsTask.getCreate_by()); + map.put("创建时间", acsTask.getCreate_time()); + map.put("修改者", acsTask.getUpdate_by()); + map.put("修改时间", acsTask.getUpdate_time()); + list.add(map); + } + FileUtil.downloadExcel(list, response); + } + + @Override + public void createTaskByClick(JSONObject json) {} + + @Override + public int checkAllowCreate(String devicecode) { + Map map = new HashMap(); + List taskList = this.queryAllUnfinished(map); + int num = 0; + for (int i = 0; i < taskList.size(); i++) { + TaskDto onetask = taskList.get(i); + String next_code = onetask.getNext_point_code(); + if (StrUtil.equals(devicecode, next_code)) { + num = num + 1; + } + } + return num; + } + + @Override + public boolean removeByCodeFromCache(String code) { + Iterator iterator = tasks.iterator(); + while (iterator.hasNext()) { + TaskDto task = iterator.next(); + if (task.getTask_code().equals(code)) { + iterator.remove(); + return true; + } + } + return false; + } + + @Override + public List findAllTaskFromCache() { + return tasks; + } + + public TaskDto findByContainer(String container_code) { + Iterator var3 = tasks.iterator(); + + while (var3.hasNext()) { + TaskDto task = (TaskDto) var3.next(); + if (StrUtil.equals(task.getVehicle_code(), container_code)) { return task; + } } - @Override - public void updateByCodeFromCache(TaskDto dto) { - Iterator iterator = tasks.iterator(); - while (iterator.hasNext()) { - TaskDto task = iterator.next(); - if (task.getTask_code().equals(dto.getTask_code())) { - iterator.remove(); - } + return null; + } + + public TaskDto findByCodeFromCache(String task_code) { + Iterator var3 = tasks.iterator(); + + while (var3.hasNext()) { + TaskDto task = (TaskDto) var3.next(); + if (StrUtil.equals(task.getTask_code(), task_code)) { + return task; + } + } + return null; + } + + @Override + public TaskDto findByNextCode(String device_code) { + Iterator var3 = tasks.iterator(); + + while (var3.hasNext()) { + TaskDto task = (TaskDto) var3.next(); + if (StrUtil.equals(task.getNext_device_code(), device_code)) { + return task; + } + } + return null; + } + + @Override + public List findAllByNextCode(String device_code) { + return null; + } + + @Override + public Integer queryAllTaskMaterialQty(String device_code) { + return null; + } + + @Override + public TaskDto findByStartCodeAndReady(String device_code) { + Iterator var3 = tasks.iterator(); + + while (var3.hasNext()) { + TaskDto task = (TaskDto) var3.next(); + // if (!StrUtil.equals(task.getTask_type(), "5")) { + // continue; + // } + if (StrUtil.equals(task.getStart_device_code(), device_code) + && StrUtil.equals(task.getTask_status(), "0")) { + return task; + } + } + return null; + } + + @Override + public TaskDto findByStartCode(String device_code) { + Iterator var3 = tasks.iterator(); + + while (var3.hasNext()) { + TaskDto task = (TaskDto) var3.next(); + if (StrUtil.equals(task.getStart_device_code(), device_code)) { + return task; + } + } + return null; + } + + @Override + public TaskDto foramte(TaskDto task) { + String start_point_code = task.getStart_point_code(); + String next_point_code = task.getNext_point_code(); + String from_y = null; + String from_z = null; + String to_y = null; + String to_z = null; + if (StrUtil.contains(start_point_code, "-") && StrUtil.count(start_point_code, "-") == 2) { + String[] start_point = start_point_code.split("-"); + task.setFrom_x(start_point[0]); + task.setStart_device_code(start_point[0]); + if (Integer.parseInt(start_point[1]) < 10 && start_point[1].length() == 1) { + from_y = "0" + start_point[1]; + task.setFrom_y(from_y); + } else { + from_y = start_point[1]; + task.setFrom_y(from_y); + } + if (Integer.parseInt(start_point[2]) < 10 && start_point[2].length() == 1) { + from_z = "0" + start_point[2]; + task.setFrom_z(from_z); + } else if (start_point[2].length() == 2) { + from_z = start_point[2]; + task.setFrom_z(start_point[2]); + } else { + from_z = start_point[2]; + } + task.setStart_point_code(task.getStart_device_code() + "-" + from_y + "-" + from_z); + task.setStart_device_code(task.getStart_device_code()); + + } else { + String start_device = + deviceAppService + .findDeviceByCode(start_point_code) + .getDeviceDriverDefination() + .getFitDeviceTypes() + .get(0) + .name(); + // 如果point_device为货架,则不包含列层信息,需要重新拼接 + if (StrUtil.equals("storage", start_device)) { + if (StrUtil.isEmpty(task.getFrom_x())) { + throw new BadRequestException("货位信息起点需要包含列信息"); } - tasks.add(dto); - } - - @Override - public String queryAssignedByDevice(String device_code, String task_nextdeice_code) { - List list = deviceAssignedService.queryAssignedBydevice(device_code, task_nextdeice_code); - int flag1 = 0; - String flag2 = null; - for (int i = 0; i < list.size(); i++) { - DeviceAssignedDto dto = list.get(i); - String inst_nextDevice_code = dto.getInst_nextdevice_code(); - String task_nextDevice_code = dto.getTask_nextdevice_code(); - String param = dto.getParam(); - JSONObject jo = JSON.parseObject(param); - String regEx = "[`~!@#$%^&*()+=|{}':;'\\[\\].<>/?~!@#¥%……&*()——+|{}【】':”“’。、?]"; - Pattern p = Pattern.compile(regEx); - Matcher m = p.matcher(inst_nextDevice_code); - String toSpeechText = m.replaceAll("").trim(); - - String[] str = toSpeechText.split(","); - List pathlist = Arrays.asList(str); - for (int j = 0; j < pathlist.size(); j++) { - String this_device_code = pathlist.get(j).toString(); - JSONObject data = JSON.parseObject(jo.getString(this_device_code)); - String limit = data.getString("limit"); - int num = instructionService.querySameDestinationInst(this_device_code); - if (num >= Integer.parseInt(limit)) { - continue; - } - if (j == 0) { - flag1 = num; - } - if (num <= flag1) { - flag2 = this_device_code; - } - } - + if (StrUtil.isEmpty(task.getFrom_y())) { + throw new BadRequestException("货位信息起点需要包含层信息"); } - if (!StrUtil.isEmpty(flag2)) { - return flag2; + if (Integer.parseInt(task.getFrom_y()) < 10 && task.getFrom_y().length() == 1) { + from_y = "0" + task.getFrom_y(); + task.setFrom_y(from_y); + } else { + from_y = task.getFrom_y(); } - return null; - } - - - @Override - public Integer querySameDeviceReadyTask(String start_device,String next_device,String status ) { - int num = 0; - Iterator iterator = tasks.iterator(); - while (iterator.hasNext()) { - TaskDto task = iterator.next(); - if (StrUtil.equals(task.getStart_device_code(),start_device) && StrUtil.equals(task.getNext_device_code(),next_device) - && StrUtil.equals(task.getTask_status(),status)) { - num++; - } + if (Integer.parseInt(task.getFrom_z()) < 10 && task.getFrom_z().length() == 1) { + from_z = "0" + task.getFrom_z(); + task.setFrom_z(from_z); + } else if (task.getFrom_z().length() == 2) { + from_z = task.getFrom_z(); + task.setFrom_z(from_z); + } else { + from_z = task.getFrom_z(); } - - return num; + task.setFrom_x(start_point_code); + task.setStart_point_code(start_point_code + "-" + from_y + "-" + from_z); + task.setStart_device_code(start_point_code); + } else { + task.setStart_device_code(start_point_code); + task.setStart_device_code(start_point_code); + } } + if (StrUtil.contains(next_point_code, "-") && StrUtil.count(next_point_code, "-") == 2) { + String[] next_point = next_point_code.split("-"); + task.setNext_device_code(next_point[0]); + task.setTo_x(next_point[0]); + if (Integer.parseInt(next_point[1]) < 10 && next_point[1].length() == 1) { + to_y = "0" + next_point[1]; + task.setTo_y(to_y); + } else { + to_y = next_point[1]; + task.setTo_y(to_y); + } + if (Integer.parseInt(next_point[2]) < 10 && next_point[2].length() == 1) { + to_z = "0" + next_point[2]; + task.setTo_z(to_z); + } else if (next_point[2].length() == 2) { + to_z = next_point[2]; + task.setTo_z(to_z); + } else { + to_z = next_point[2]; + task.setTo_z(to_z); + } + task.setNext_point_code(task.getNext_device_code() + "-" + to_y + "-" + to_z); + task.setNext_device_code(task.getNext_device_code()); - @Override - public Integer querySameTaskByType(String taskType) { - int num = 0; - Iterator iterator = tasks.iterator(); - while (iterator.hasNext()) { - TaskDto task = iterator.next(); - if (task.getTask_type().equals(taskType) && task.getTask_status().equals("1")) { - num++; - } + } else { + String next_device = + deviceAppService + .findDeviceByCode(next_point_code) + .getDeviceDriverDefination() + .getFitDeviceTypes() + .get(0) + .name(); + if (StrUtil.equals("storage", next_device)) { + if (StrUtil.isEmpty(task.getTo_x())) { + throw new BadRequestException("货位信息终点需要包含列信息"); } + if (StrUtil.isEmpty(task.getTo_y())) { + throw new BadRequestException("货位信息终点需要包含层信息"); + } + if (Integer.parseInt(task.getTo_y()) < 10 && task.getTo_y().length() == 1) { + to_y = "0" + task.getTo_y(); + task.setTo_y(to_y); + } else { + to_y = task.getTo_y(); + } + if (Integer.parseInt(task.getTo_z()) < 10 && task.getTo_z().length() == 1) { + to_z = "0" + task.getTo_z(); + task.setTo_z(to_z); + } else if (task.getTo_z().length() == 2) { + to_z = task.getTo_z(); + task.setTo_z(to_z); + } else { + to_z = task.getTo_z(); + } + task.setTo_x(next_point_code); + task.setNext_point_code(next_point_code + "-" + to_y + "-" + to_z); + task.setNext_device_code(next_point_code); - return num; + } else { + task.setNext_device_code(next_point_code); + task.setNext_device_code(next_point_code); + } + } + return task; + } + + @Override + public void updateByCodeFromCache(TaskDto dto) { + Iterator iterator = tasks.iterator(); + while (iterator.hasNext()) { + TaskDto task = iterator.next(); + if (task.getTask_code().equals(dto.getTask_code())) { + iterator.remove(); + } + } + tasks.add(dto); + } + + @Override + public String queryAssignedByDevice(String device_code, String task_nextdeice_code) { + List list = + deviceAssignedService.queryAssignedBydevice(device_code, task_nextdeice_code); + int flag1 = 0; + String flag2 = null; + for (int i = 0; i < list.size(); i++) { + DeviceAssignedDto dto = list.get(i); + String inst_nextDevice_code = dto.getInst_nextdevice_code(); + String task_nextDevice_code = dto.getTask_nextdevice_code(); + String param = dto.getParam(); + JSONObject jo = JSON.parseObject(param); + String regEx = "[`~!@#$%^&*()+=|{}':;'\\[\\].<>/?~!@#¥%……&*()——+|{}【】':”“’。、?]"; + Pattern p = Pattern.compile(regEx); + Matcher m = p.matcher(inst_nextDevice_code); + String toSpeechText = m.replaceAll("").trim(); + + String[] str = toSpeechText.split(","); + List pathlist = Arrays.asList(str); + for (int j = 0; j < pathlist.size(); j++) { + String this_device_code = pathlist.get(j).toString(); + JSONObject data = JSON.parseObject(jo.getString(this_device_code)); + String limit = data.getString("limit"); + int num = instructionService.querySameDestinationInst(this_device_code); + if (num >= Integer.parseInt(limit)) { + continue; + } + if (j == 0) { + flag1 = num; + } + if (num <= flag1) { + flag2 = this_device_code; + } + } + } + if (!StrUtil.isEmpty(flag2)) { + return flag2; + } + return null; + } + + @Override + public Integer querySameDeviceReadyTask(String start_device, String next_device, String status) { + int num = 0; + Iterator iterator = tasks.iterator(); + while (iterator.hasNext()) { + TaskDto task = iterator.next(); + if (StrUtil.equals(task.getStart_device_code(), start_device) + && StrUtil.equals(task.getNext_device_code(), next_device) + && StrUtil.equals(task.getTask_status(), status)) { + num++; + } } - @Override - public Integer querySameOriginTask(String code) { - return null; + return num; + } + + @Override + public Integer querySameTaskByType(String taskType) { + int num = 0; + Iterator iterator = tasks.iterator(); + while (iterator.hasNext()) { + TaskDto task = iterator.next(); + if (task.getTask_type().equals(taskType) && task.getTask_status().equals("1")) { + num++; + } } - @Override - public Integer querySameDestinationTask(String code) { - return null; - } + return num; + } + @Override + public Integer querySameOriginTask(String code) { + return null; + } + @Override + public Integer querySameDestinationTask(String code) { + return null; + } }