diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/agv/server/impl/NDCAgvServiceImpl.java b/acs/nladmin-system/src/main/java/org/nl/acs/agv/server/impl/NDCAgvServiceImpl.java index 566b9d9..d225613 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/agv/server/impl/NDCAgvServiceImpl.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/agv/server/impl/NDCAgvServiceImpl.java @@ -83,170 +83,53 @@ public class NDCAgvServiceImpl implements NDCAgvService { @Override public void sendAgvInstToNDC(String agv_system_type, Instruction inst) { if (StrUtil.equals(paramService.findByCode(AcsConfig.FORKAGV).getValue(), "1")) { - if (!StrUtil.equals(agv_system_type, "1")) { - String instcode = inst.getInstruction_code(); - int type = Integer.parseInt(inst.getAgv_inst_type()); - int priority = Integer.parseInt(inst.getPriority()) + 128; - DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); - DeviceService deviceService = SpringContextHolder.getBean(DeviceServiceImpl.class); - int startAddress = deviceService.queryAddressBydeviceCode(inst.getStart_point_code()); - int nextAddress = deviceService.queryAddressBydeviceCode(inst.getNext_point_code()); - int startAddress2 = deviceService.queryAddressBydeviceCode(inst.getStart_point_code2()); - int nextAddress2 = deviceService.queryAddressBydeviceCode(inst.getNext_point_code2()); - byte ikeyhigh = (byte) IntToHexHigh(Integer.parseInt(instcode)); - byte ikeylow = (byte) IntToHexLow(Integer.parseInt(instcode)); - byte typehigh = (byte) IntToHexHigh(type); - byte typelow = (byte) IntToHexLow(type); - byte qhdhigh = (byte) IntToHexHigh(startAddress); - byte qhdlow = (byte) IntToHexLow(startAddress); - byte qhdhigh2 = (byte) IntToHexHigh(startAddress2); - byte qhdlow2 = (byte) IntToHexLow(startAddress2); - byte fhdhigh = (byte) IntToHexHigh(nextAddress); - byte fhdlow = (byte) IntToHexLow(nextAddress); - byte fhdhigh2 = (byte) IntToHexHigh(nextAddress2); - byte fhdlow2 = (byte) IntToHexLow(nextAddress2); - byte prioritylow = (byte) IntToHexLow(priority); - - String str = "十进制下发:"; - String str1 = "十六进制下发:"; - str += "ikey:" + (Integer.parseInt(instcode)); - str1 += "ikey:" + hexToString(ikeyhigh & 0xFF) + hexToString(ikeylow & 0xFF); - - str += "/type:" + (type); - str1 += "/type:" + hexToString(typehigh & 0xFF) + hexToString(typelow & 0xFF); - - str += "/qhd:" + (startAddress); - str1 += "/qhd:" + hexToString(qhdhigh & 0xFF) + hexToString(qhdlow & 0xFF); - str += "/fhd:" + (nextAddress); - str1 += "/fhd:" + hexToString(fhdhigh & 0xFF) + hexToString(fhdlow & 0xFF); - - str += "/qhd2:" + (startAddress2); - str1 += "/qhd2:" + hexToString(qhdhigh2 & 0xFF) + hexToString(qhdlow2 & 0xFF); - str += "/fhd2:" + (nextAddress2); - str1 += "/fhd2:" + hexToString(fhdhigh2 & 0xFF) + hexToString(fhdlow2 & 0xFF); - - str += "/priority:" + (priority); - str1 += "/priority:" + hexToString(prioritylow & 0xFF); - - System.out.println(str); - System.out.println(str1); - byte[] b = new byte[]{}; - if (type == 1) { - b = new byte[]{(byte) 0X87, (byte) 0XCD, - (byte) 0X00, (byte) 0X08, - (byte) 0X00, (byte) 0X16, - (byte) 0X00, (byte) 0X01, - (byte) 0X00, (byte) 0X71, - (byte) 0X00, (byte) 0X12, - (byte) 0X01, prioritylow, - (byte) 0X00, (byte) 0X01, - (byte) ikeyhigh, (byte) ikeylow, - (byte) ikeyhigh, (byte) ikeylow, - (byte) typehigh, (byte) typelow, - (byte) qhdhigh, (byte) qhdlow, - (byte) qhdhigh2, (byte) qhdlow2, - (byte) fhdhigh, (byte) fhdlow, - (byte) fhdhigh2, (byte) fhdlow2 - }; - } else if (type == 2) { - b = new byte[]{(byte) 0X87, (byte) 0XCD, - (byte) 0X00, (byte) 0X08, - (byte) 0X00, (byte) 0X16, - (byte) 0X00, (byte) 0X01, - (byte) 0X00, (byte) 0X71, - (byte) 0X00, (byte) 0X12, - (byte) 0X01, prioritylow, - (byte) 0X00, (byte) 0X01, - (byte) ikeyhigh, (byte) ikeylow, - (byte) ikeyhigh, (byte) ikeylow, - (byte) typehigh, (byte) typelow, - (byte) qhdhigh, (byte) qhdlow, - (byte) 0X00, (byte) 0X00, - (byte) fhdhigh, (byte) fhdlow, - (byte) 0X00, (byte) 0X00 - }; - } else if (type == 3) { - b = new byte[]{(byte) 0X87, (byte) 0XCD, - (byte) 0X00, (byte) 0X08, - (byte) 0X00, (byte) 0X16, - (byte) 0X00, (byte) 0X01, - (byte) 0X00, (byte) 0X71, - (byte) 0X00, (byte) 0X12, - (byte) 0X01, prioritylow, - (byte) 0X00, (byte) 0X01, - (byte) ikeyhigh, (byte) ikeylow, - (byte) ikeyhigh, (byte) ikeylow, - (byte) typehigh, (byte) typelow, - (byte) qhdhigh, (byte) qhdlow, - (byte) qhdhigh2, (byte) qhdlow2, - (byte) fhdhigh, (byte) fhdlow, - (byte) fhdhigh2, (byte) fhdlow2 - }; - } - log.info("下发AGV作业指令--{}", str1); - if (StrUtil.equals(agv_system_type,"2")){ - TwoNDCSocketConnectionAutoRun.write(b); - } else if (StrUtil.equals(agv_system_type,"3")){ - TwoNDC2SocketConnectionAutoRun.write(b); - } - System.out.println("下发agv指令数据:" + Bytes2HexString(b)); - } else { - - String instcode = inst.getInstruction_code(); - int type = Integer.parseInt(inst.getInstruction_type()); - int priority = Integer.parseInt(inst.getPriority()) + 128; - DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); - DeviceService deviceService = SpringContextHolder.getBean(DeviceServiceImpl.class); - int startAddress = deviceService.queryAddressBydeviceCode(inst.getStart_point_code()); - int nextAddress = deviceService.queryAddressBydeviceCode(inst.getNext_point_code()); - - byte ikeyhigh = (byte) IntToHexHigh(Integer.parseInt(instcode)); - byte ikeylow = (byte) IntToHexLow(Integer.parseInt(instcode)); - byte typehigh = (byte) IntToHexHigh(type); - byte typelow = (byte) IntToHexLow(type); - byte qhdhigh = (byte) IntToHexHigh(startAddress); - byte qhdlow = (byte) IntToHexLow(startAddress); - byte fhdhigh = (byte) IntToHexHigh(nextAddress); - byte fhdlow = (byte) IntToHexLow(nextAddress); - byte prioritylow = (byte) IntToHexLow(priority); - - String str = "十进制下发:"; - String str1 = "十六进制下发:"; - str += "ikey:" + (Integer.parseInt(instcode)); - str1 += "ikey:" + hexToString(ikeyhigh & 0xFF) + hexToString(ikeylow & 0xFF); - - str += "/type:" + (type); - str1 += "/type:" + hexToString(typehigh & 0xFF) + hexToString(typelow & 0xFF); - - str += "/qhd:" + (startAddress); - str1 += "/qhd:" + hexToString(qhdhigh & 0xFF) + hexToString(qhdlow & 0xFF); - str += "/fhd:" + (nextAddress); - str1 += "/fhd:" + hexToString(fhdhigh & 0xFF) + hexToString(fhdlow & 0xFF); - - str += "/priority:" + (priority); - str1 += "/priority:" + hexToString(prioritylow & 0xFF); - - System.out.println(str); - System.out.println(str1); - - byte[] b = new byte[]{(byte) 0X87, (byte) 0XCD, - (byte) 0X00, (byte) 0X08, - (byte) 0X00, (byte) 0X12, - (byte) 0X00, (byte) 0X01, - (byte) 0X00, (byte) 0X71, - (byte) 0X00, (byte) 0X0E, - (byte) 0X01, prioritylow, - (byte) 0X00, (byte) 0X01, - (byte) ikeyhigh, (byte) ikeylow, - (byte) ikeyhigh, (byte) ikeylow, - (byte) typehigh, (byte) typelow, - (byte) qhdhigh, (byte) qhdlow, - (byte) fhdhigh, (byte) fhdlow - }; - log.info("下发AGV作业指令--{}", str1); - OneNDCSocketConnectionAutoRun.write(b); - System.out.println("下发agv指令数据:" + Bytes2HexString(b)); - } + String instcode = inst.getInstruction_code(); + int type = Integer.parseInt(inst.getAgv_inst_type()); + int priority = Integer.parseInt(inst.getPriority()) + 128; + DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); + DeviceService deviceService = SpringContextHolder.getBean(DeviceServiceImpl.class); + int startAddress = deviceService.queryAddressBydeviceCode(inst.getStart_point_code()); + int nextAddress = deviceService.queryAddressBydeviceCode(inst.getNext_point_code()); + byte ikeyhigh = (byte) IntToHexHigh(Integer.parseInt(instcode)); + byte ikeylow = (byte) IntToHexLow(Integer.parseInt(instcode)); + byte typehigh = (byte) IntToHexHigh(type); + byte typelow = (byte) IntToHexLow(type); + byte qhdhigh = (byte) IntToHexHigh(startAddress); + byte qhdlow = (byte) IntToHexLow(startAddress); + byte fhdhigh = (byte) IntToHexHigh(nextAddress); + byte fhdlow = (byte) IntToHexLow(nextAddress); + byte prioritylow = (byte) IntToHexLow(priority); + String str = "十进制下发:"; + String str1 = "十六进制下发:"; + str += "ikey:" + (Integer.parseInt(instcode)); + str1 += "ikey:" + hexToString(ikeyhigh & 0xFF) + hexToString(ikeylow & 0xFF); + str += "/type:" + (type); + str1 += "/type:" + hexToString(typehigh & 0xFF) + hexToString(typelow & 0xFF); + str += "/qhd:" + (startAddress); + str1 += "/qhd:" + hexToString(qhdhigh & 0xFF) + hexToString(qhdlow & 0xFF); + str += "/fhd:" + (nextAddress); + str1 += "/fhd:" + hexToString(fhdhigh & 0xFF) + hexToString(fhdlow & 0xFF); + str += "/priority:" + (priority); + str1 += "/priority:" + hexToString(prioritylow & 0xFF); + System.out.println(str); + System.out.println(str1); + byte[] b = new byte[]{(byte) 0X87, (byte) 0XCD, + (byte) 0X00, (byte) 0X08, + (byte) 0X00, (byte) 0X12, + (byte) 0X00, (byte) 0X01, + (byte) 0X00, (byte) 0X71, + (byte) 0X00, (byte) 0X0E, + (byte) 0X01, prioritylow, + (byte) 0X00, (byte) 0X01, + (byte) ikeyhigh, (byte) ikeylow, + (byte) ikeyhigh, (byte) ikeylow, + (byte) typehigh, (byte) typelow, + (byte) qhdhigh, (byte) qhdlow, + (byte) fhdhigh, (byte) fhdlow + }; + log.info("下发AGV作业指令--{}", str1); + OneNDCSocketConnectionAutoRun.write(b); + System.out.println("下发agv指令数据:" + Bytes2HexString(b)); } } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/auto/run/OneNDCSocketConnectionAutoRun.java b/acs/nladmin-system/src/main/java/org/nl/acs/auto/run/OneNDCSocketConnectionAutoRun.java index 6eb984a..e2feb5e 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/auto/run/OneNDCSocketConnectionAutoRun.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/auto/run/OneNDCSocketConnectionAutoRun.java @@ -126,12 +126,12 @@ public class OneNDCSocketConnectionAutoRun extends AbstractAutoRunnable { List insts = null; boolean link_flag = false; Device agv_device = null; - if(carno != 0){ + if (carno != 0) { agv_device = deviceAppService.findDeviceByCode(String.valueOf(carno)); } if (ikey != 0) { inst = instructionService.findByCodeFromCache(String.valueOf(ikey)); - if (ObjectUtil.isEmpty(inst)){ + if (ObjectUtil.isEmpty(inst)) { inst = instructionService.findByCode(String.valueOf(ikey)); } } @@ -160,24 +160,22 @@ public class OneNDCSocketConnectionAutoRun extends AbstractAutoRunnable { //任务完毕 //(无车id及状态) else if (phase == 0x0A) { - if (!ObjectUtil.isEmpty(inst)) { - if (!ObjectUtil.isEmpty(inst)) { - instructionService.finish(inst.getInstruction_id()); - } + instructionService.finish(inst.getInstruction_id()); + } else { + log.warn("指令号:{},未反馈wms任务完成,因为agv上报指令号查询指令为空!"); } data = NDCAgvService.sendAgvOneModeInst(phase, index, 0); - + log.info("指令号:{},已反馈agv任务完成!"); } //请求删除任务 //(需要WCS反馈) - else if(phase == 0x30){ + else if (phase == 0x30) { data = NDCAgvService.sendAgvOneModeInst(0x8F, index, 0); - } //任务删除确认 //(需要WCS反馈) - else if(phase == 0xFF) { + else if (phase == 0xFF) { if (!ObjectUtil.isEmpty(inst)) { if (!ObjectUtil.isEmpty(inst)) { @@ -189,12 +187,12 @@ public class OneNDCSocketConnectionAutoRun extends AbstractAutoRunnable { } else { //上报异常信息 //(不需要WCS反馈) - if(phase == 0x67){ + if (phase == 0x67) { device = deviceAppService.findDeviceByCode(Integer.toString(arr[27])); } else { device = deviceAppService.findDeviceByCode(Integer.toString(arr[20])); } - if(ObjectUtil.isNotEmpty(device)){ + if (ObjectUtil.isNotEmpty(device)) { if (device.getDeviceDriver() instanceof AgvNdcOneDeviceDriver) { agvNdcOneDeviceDriver = (AgvNdcOneDeviceDriver) device.getDeviceDriver(); agvNdcOneDeviceDriver.processSocket(arr); @@ -215,9 +213,9 @@ public class OneNDCSocketConnectionAutoRun extends AbstractAutoRunnable { System.out.println("OneAgv链接异常"); log.info("OneAgv链接异常"); log.error("agv连接出现异常:{}", e); - logServer.deviceExecuteLog("1","","","agv异常"+e.getMessage()); - logServer.deviceExecuteLog("1","","","agv异常" + e); - if(ObjectUtil.isNotEmpty(s)){ + logServer.deviceExecuteLog("1", "", "", "agv异常" + e.getMessage()); + logServer.deviceExecuteLog("1", "", "", "agv异常" + e); + if (ObjectUtil.isNotEmpty(s)) { s.close(); } System.out.println(e.getMessage()); diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/agv/ndcone/AgvNdcOneDeviceDriver.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/agv/ndcone/AgvNdcOneDeviceDriver.java index eaac648..c7b8aa7 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/agv/ndcone/AgvNdcOneDeviceDriver.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/agv/ndcone/AgvNdcOneDeviceDriver.java @@ -2,6 +2,9 @@ package org.nl.acs.device_driver.basedriver.agv.ndcone; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; +import cn.hutool.http.HttpResponse; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; import lombok.Data; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -23,6 +26,8 @@ import org.nl.acs.log.LokiLogType; import org.nl.acs.log.service.DeviceExecuteLogService; import org.nl.acs.opc.Device; import org.nl.acs.opc.DeviceAppService; +import org.nl.acs.task.service.TaskService; +import org.nl.acs.task.service.impl.TaskServiceImpl; import org.nl.modules.system.service.ParamService; import org.nl.modules.system.service.impl.ParamServiceImpl; import org.nl.modules.wql.util.SpringContextHolder; @@ -43,6 +48,7 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic ParamService paramService = SpringContextHolder.getBean(ParamServiceImpl.class); InstructionService instructionService = SpringContextHolder.getBean(InstructionServiceImpl.class); AcsToWmsService acsToWmsService = SpringContextHolder.getBean(AcsToWmsServiceImpl.class); + TaskService taskService = SpringContextHolder.getBean(TaskServiceImpl.class); NDCAgvService NDCAgvService = SpringContextHolder.getBean(NDCAgvService.class); DeviceExecuteLogService logServer = SpringContextHolder.getBean(DeviceExecuteLogService.class); DeviceAppService deviceAppService = SpringContextHolder.getBean(DeviceAppService.class); @@ -90,7 +96,7 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic } if (ikey != 0) { inst = instructionService.findByCodeFromCache(String.valueOf(ikey)); - if (ObjectUtil.isEmpty(inst)){ + if (ObjectUtil.isEmpty(inst)) { inst = instructionService.findByCode(String.valueOf(ikey)); } } @@ -163,27 +169,43 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic return; } - if (device.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { - standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) device.getDeviceDriver(); - standardOrdinarySiteDeviceDriver.setAgvphase(phase); - standardOrdinarySiteDeviceDriver.setIndex(index); - standardOrdinarySiteDeviceDriver.setInst(inst); - } - - if (device.getDeviceDriver() instanceof SiemensConveyorDeviceDriver) { - siemensConveyorDeviceDriver = (SiemensConveyorDeviceDriver) device.getDeviceDriver(); - if (siemensConveyorDeviceDriver.getMove() == 1) { - data = NDCAgvService.sendAgvOneModeInst(phase, index, 0); +// if (device.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { +// standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) device.getDeviceDriver(); +// standardOrdinarySiteDeviceDriver.setAgvphase(phase); +// standardOrdinarySiteDeviceDriver.setIndex(index); +// standardOrdinarySiteDeviceDriver.setInst(inst); +// } + if (StrUtil.equals(inst.getStart_device_code(), device_code)) { + String instruction_type = inst.getInstruction_type(); + if (StrUtil.equals(instruction_type, "3") + || StrUtil.equals(instruction_type, "5") + || StrUtil.equals(instruction_type, "9") + || StrUtil.equals(instruction_type, "11") + || StrUtil.equals(instruction_type, "13")) { + JSONArray req = new JSONArray(); + JSONObject map = new JSONObject(); + map.put("vehicle_code", inst.getVehicle_code()); + map.put("status", "1"); + map.put("device_code", inst.getStart_point_code()); + map.put("task_code", inst.getTask_code()); + req.add(map); + HttpResponse httpResponse = acsToWmsService.feedAgvTaskStatus(req); + if (ObjectUtil.isNotEmpty(httpResponse) && httpResponse.getStatus() == 200) { + JSONObject resp = JSONObject.parseObject(httpResponse.body()); + if (resp.getInteger("status") == 200) { + data = NDCAgvService.sendAgvOneModeInst(phase, index, 0); + log.info("指令号:{},acs请求wms取货申请成功,wms允许agv申请取货,已反馈agv允许取货", inst.getInstruction_code()); + } else { + log.warn("指令号:{},acs请求wms取货申请成功,wms不允许agv申请取货,未反馈agv允许取货", inst.getInstruction_code()); + } + } else { + log.warn("指令号:{},acs请求wms取货申请失败,连接被拒绝,未反馈agv允许取货", inst.getInstruction_code()); + } } else { - log.info("请求取货条件不满足待机有货"); + data = NDCAgvService.sendAgvOneModeInst(phase, index, 0); + log.info("指令号:{},acs不需要请求wms取货申请,已反馈agv允许取货", inst.getInstruction_code()); } } - - if (device.getDeviceDriver() instanceof StandardStorageDeviceDriver) { - data = NDCAgvService.sendAgvOneModeInst(phase, index, 0); - } - logServer.deviceExecuteLog(this.device_code, "", "", "agvphase:" + phase + "反馈:" + data); - //取货完毕 //(需要WCS反馈) } else if (phase == 0x05) { @@ -223,38 +245,41 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic if (StrUtil.equals(inst.getStart_device_code(), device_code)) { - if (device.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { - standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) device.getDeviceDriver(); - standardOrdinarySiteDeviceDriver.setAgvphase(phase); - standardOrdinarySiteDeviceDriver.setIndex(index); - standardOrdinarySiteDeviceDriver.setInst(inst); - } - - if (device.getDeviceDriver() instanceof SiemensConveyorDeviceDriver) { - siemensConveyorDeviceDriver = (SiemensConveyorDeviceDriver) device.getDeviceDriver(); - if(siemensConveyorDeviceDriver.getTo_command() == 2){ - log.info("取货完成请求离开,当前输送to_command:"+siemensConveyorDeviceDriver.getTo_command()); - data = NDCAgvService.sendAgvOneModeInst(phase, index, 0); + String instruction_type = inst.getInstruction_type(); + if (StrUtil.equals(instruction_type, "2") + || StrUtil.equals(instruction_type, "3") + || StrUtil.equals(instruction_type, "4") + || StrUtil.equals(instruction_type, "5") + || StrUtil.equals(instruction_type, "6") + || StrUtil.equals(instruction_type, "8") + || StrUtil.equals(instruction_type, "9") + || StrUtil.equals(instruction_type, "10") + || StrUtil.equals(instruction_type, "11") + || StrUtil.equals(instruction_type, "13")) { + JSONArray req = new JSONArray(); + JSONObject map = new JSONObject(); + map.put("vehicle_code", inst.getVehicle_code()); + map.put("status", "2"); + map.put("device_code", inst.getStart_point_code()); + map.put("task_code", inst.getTask_code()); + req.add(map); + HttpResponse httpResponse = acsToWmsService.feedAgvTaskStatus(req); + if (ObjectUtil.isNotEmpty(httpResponse) && httpResponse.getStatus() == 200) { + JSONObject resp = JSONObject.parseObject(httpResponse.body()); + if (resp.getInteger("status") == 200) { + data = NDCAgvService.sendAgvOneModeInst(phase, index, 0); + log.info("指令号:{},acs反馈wms取货完成成功,wms允许agv取货完成,已反馈agv取货完成", inst.getInstruction_code()); + } else { + log.warn("指令号:{},acs反馈wms取货完成成功,wms不允许agv取货完成,未反馈agv取货完成", inst.getInstruction_code()); + } } else { - log.info("取货完成请求离开下发输送信号,当前输送to_command:"+siemensConveyorDeviceDriver.getTo_command()); - List list = new ArrayList(); - Map map = new HashMap(); - map.put("code", "to_command"); - map.put("value", "2"); - list.add(map); - siemensConveyorDeviceDriver.writing(list); - siemensConveyorDeviceDriver.writing(list); + log.warn("指令号:{},acs反馈wms取货完成失败,连接被拒绝,未反馈agv取货完成", inst.getInstruction_code()); } - } - - if (device.getDeviceDriver() instanceof StandardStorageDeviceDriver) { - standardStorageDeviceDriver = (StandardStorageDeviceDriver) device.getDeviceDriver(); + } else { data = NDCAgvService.sendAgvOneModeInst(phase, index, 0); + log.info("指令号:{},acs不需要反馈wms取货完成,已反馈agv取货完成", inst.getInstruction_code()); } - } - logServer.deviceExecuteLog(this.device_code, "", "", "agvphase:" + phase + "反馈:" + data); - //到达放货点 //(需要WCS反馈) } else if (phase == 0x07) { @@ -289,22 +314,34 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic return; } if (StrUtil.equals(inst.getNext_device_code(), device_code)) { - - if (device.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { - standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) device.getDeviceDriver(); -// standardOrdinarySiteDeviceDriver.setAgvphase(phase); -// standardOrdinarySiteDeviceDriver.setIndex(index); -// standardOrdinarySiteDeviceDriver.setInst(inst); - data = NDCAgvService.sendAgvOneModeInst(phase, index, 0); - } - - if (device.getDeviceDriver() instanceof StandardStorageDeviceDriver) { - standardStorageDeviceDriver = (StandardStorageDeviceDriver) device.getDeviceDriver(); + String instruction_type = inst.getInstruction_type(); + if (StrUtil.equals(instruction_type, "2") + || StrUtil.equals(instruction_type, "4") + || StrUtil.equals(instruction_type, "8")) { + JSONArray req = new JSONArray(); + JSONObject map = new JSONObject(); + map.put("vehicle_code", inst.getVehicle_code()); + map.put("status", "3"); + map.put("device_code", inst.getStart_point_code()); + map.put("task_code", inst.getTask_code()); + req.add(map); + HttpResponse httpResponse = acsToWmsService.feedAgvTaskStatus(req); + if (ObjectUtil.isNotEmpty(httpResponse) && httpResponse.getStatus() == 200) { + JSONObject resp = JSONObject.parseObject(httpResponse.body()); + if (resp.getInteger("status") == 200) { + data = NDCAgvService.sendAgvOneModeInst(phase, index, 0); + log.info("指令号:{},acs请求wms放货申请成功,wms允许agv申请放货,已反馈agv允许放货", inst.getInstruction_code()); + } else { + log.warn("指令号:{},acs请求wms放货申请成功,wms不允许agv申请放货,未反馈agv允许放货", inst.getInstruction_code()); + } + } else { + log.warn("指令号:{},acs请求wms放货申请失败,连接被拒绝,未反馈agv允许放货", inst.getInstruction_code()); + } + } else { data = NDCAgvService.sendAgvOneModeInst(phase, index, 0); + log.info("指令号:{},acs不需要请求wms放货申请,已反馈agv允许放货", inst.getInstruction_code()); } - } - logServer.deviceExecuteLog(this.device_code, "", "", "agvphase:" + phase + "反馈:" + data); //放货完毕 //(需要WCS反馈) @@ -341,23 +378,8 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic return; } if (StrUtil.equals(inst.getNext_device_code(), device_code)) { - - if (device.getDeviceDriver() instanceof StandardStorageDeviceDriver) { - standardStorageDeviceDriver = (StandardStorageDeviceDriver) device.getDeviceDriver(); - data = NDCAgvService.sendAgvOneModeInst(phase, index, 0); - } - - if (device.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { - standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) device.getDeviceDriver(); -// standardOrdinarySiteDeviceDriver.setAgvphase(phase); -// standardOrdinarySiteDeviceDriver.setIndex(index); -// standardOrdinarySiteDeviceDriver.setInst(inst); - data = NDCAgvService.sendAgvOneModeInst(phase, index, 0); - } - + data = NDCAgvService.sendAgvOneModeInst(phase, index, 0); } - logServer.deviceExecuteLog(this.device_code, "", "", "agvphase:" + phase + "反馈:" + data); - } //到达位置点 //(需要WCS反馈) diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/rest/AcsToWmsController.java b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/rest/AcsToWmsController.java index 35965e4..b42504a 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/rest/AcsToWmsController.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/rest/AcsToWmsController.java @@ -105,4 +105,11 @@ public class AcsToWmsController { public ResponseEntity liKuApplyTaskRequest(@RequestBody LiKuApplyTaskRequest param) { return new ResponseEntity<>(acstowmsService.liKuApplyTaskRequest(param), HttpStatus.OK); } + + @PostMapping("/feedAgvTaskStatus") + @Log(value = "反馈AGV取放货状态",isInterfaceLog = true,interfaceLogType= InterfaceLogType.ACS_TO_LMS) + @ApiOperation("反馈AGV取放货状态") + public ResponseEntity feedAgvTaskStatus(@RequestBody JSONArray from) { + return new ResponseEntity<>(acstowmsService.feedAgvTaskStatus(from), HttpStatus.OK); + } } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/AcsToWmsService.java b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/AcsToWmsService.java index b301900..57875fb 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/AcsToWmsService.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/AcsToWmsService.java @@ -104,4 +104,12 @@ public interface AcsToWmsService { // 输送线有货变成无货时向lms请求 HttpResponse shipDeviceUpdate(JSONObject param); + + /** + * 反馈AGV取放货状态 + * + * @param from + * @return + */ + HttpResponse feedAgvTaskStatus(JSONArray from); } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/AcsToWmsServiceImpl.java b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/AcsToWmsServiceImpl.java index 71e9640..bf5729e 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/AcsToWmsServiceImpl.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/AcsToWmsServiceImpl.java @@ -529,4 +529,28 @@ public class AcsToWmsServiceImpl implements AcsToWmsService { } return null; } + + @Override + public HttpResponse feedAgvTaskStatus(JSONArray from) { + String wmsUrl = paramService.findByCode(AcsConfig.WMSURL).getValue(); + + AddressDto addressDto = addressService.findByCode("feedAgvTaskStatus"); + String methods_url = addressDto.getMethods_url(); + String url = wmsUrl + methods_url; + HttpResponse result = null; + log.info("feedAgvTaskStatus----请求参数{}", from); + + try { + result = HttpRequest.post(url) + .body(String.valueOf(from)) + .execute(); + System.out.println(result); + log.info("feedAgvTaskStatus----返回参数{}", result); + } catch (Exception e) { + String msg = e.getMessage(); + //网络不通 + //System.out.println(msg); + } + return result; + } } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/WmsToAcsServiceImpl.java b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/WmsToAcsServiceImpl.java index 15564de..20d6515 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/WmsToAcsServiceImpl.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/WmsToAcsServiceImpl.java @@ -58,8 +58,8 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { private final AcsToLiKuService acsToLiKuService; - private String log_file_type="log_file_type"; - private String log_type="LMS请求ACS"; + private String log_file_type = "log_file_type"; + private String log_type = "LMS请求ACS"; @Override public CancelTaskResponse cancelFromWms(String param) throws Exception { @@ -172,7 +172,6 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { } - } response.setStatus(200); response.setMessage("success"); @@ -232,7 +231,7 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { jo.put("countdown_min", hongXiangConveyorDeviceDriver.getCountdown_min()); jo.put("countdown_sec", hongXiangConveyorDeviceDriver.getCountdown_sec()); //温度需要除以10 - jo.put("temperature", hongXiangConveyorDeviceDriver.getTemperature()/10); + jo.put("temperature", hongXiangConveyorDeviceDriver.getTemperature() / 10); jo.put("door", hongXiangConveyorDeviceDriver.getDoor()); jo.put("finish", hongXiangConveyorDeviceDriver.getFinish()); jo.put("task", hongXiangConveyorDeviceDriver.getTask()); @@ -305,7 +304,6 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { } - @Override public Map putPlusPullAction(String param) { try { @@ -319,61 +317,61 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { if (ObjectUtil.isEmpty(device)) { JSONObject resultJson = new JSONObject(); resultJson.put("status", HttpStatus.BAD_REQUEST.value()); - resultJson.put("message", "未找到对应的设备:"+device_code); + resultJson.put("message", "未找到对应的设备:" + device_code); return resultJson; } PlugPullDeviceSiteDeviceDriver plugPullDeviceSiteDeviceDriver; if (device.getDeviceDriver() instanceof PlugPullDeviceSiteDeviceDriver) { plugPullDeviceSiteDeviceDriver = (PlugPullDeviceSiteDeviceDriver) device.getDeviceDriver(); // 0 穿轴 1拔轴 - if(StrUtil.equals(type,"1")){ + if (StrUtil.equals(type, "1")) { - if(plugPullDeviceSiteDeviceDriver.getMode() == 1){ + if (plugPullDeviceSiteDeviceDriver.getMode() == 1) { JSONObject resultJson = new JSONObject(); resultJson.put("status", HttpStatus.BAD_REQUEST.value()); resultJson.put("message", "请求拔轴,当前设备工作模式未自动"); return resultJson; } - if(plugPullDeviceSiteDeviceDriver.getAction() == 0){ + if (plugPullDeviceSiteDeviceDriver.getAction() == 0) { JSONObject resultJson = new JSONObject(); resultJson.put("status", HttpStatus.BAD_REQUEST.value()); resultJson.put("message", "请求拔轴,当前设备未全自动"); return resultJson; } - if(plugPullDeviceSiteDeviceDriver.getStatus() != 0){ + if (plugPullDeviceSiteDeviceDriver.getStatus() != 0) { JSONObject resultJson = new JSONObject(); resultJson.put("status", HttpStatus.BAD_REQUEST.value()); resultJson.put("message", "请求拔轴,当前设备未待机"); return resultJson; } - if(plugPullDeviceSiteDeviceDriver.getControl() != 0){ + if (plugPullDeviceSiteDeviceDriver.getControl() != 0) { JSONObject resultJson = new JSONObject(); resultJson.put("status", HttpStatus.BAD_REQUEST.value()); resultJson.put("message", "请求拔轴,当前设备未远程控制"); return resultJson; } - if(plugPullDeviceSiteDeviceDriver.getMove() != 0){ + if (plugPullDeviceSiteDeviceDriver.getMove() != 0) { JSONObject resultJson = new JSONObject(); resultJson.put("status", HttpStatus.BAD_REQUEST.value()); resultJson.put("message", "请求拔轴,当前设备有轴"); return resultJson; } - if(plugPullDeviceSiteDeviceDriver.getMode() == 0 && plugPullDeviceSiteDeviceDriver.getAction() ==1 - && plugPullDeviceSiteDeviceDriver.getStatus() ==0 && plugPullDeviceSiteDeviceDriver.getMove() ==0 - && plugPullDeviceSiteDeviceDriver.getControl() ==0 ){ + if (plugPullDeviceSiteDeviceDriver.getMode() == 0 && plugPullDeviceSiteDeviceDriver.getAction() == 1 + && plugPullDeviceSiteDeviceDriver.getStatus() == 0 && plugPullDeviceSiteDeviceDriver.getMove() == 0 + && plugPullDeviceSiteDeviceDriver.getControl() == 0) { List list = new ArrayList(); Map map = new HashMap(); - map.put("code","to_size"); - map.put("value",size); + map.put("code", "to_size"); + map.put("value", size); list.add(map); Map map2 = new HashMap(); - map2.put("code","to_type"); - map2.put("value",type); + map2.put("code", "to_type"); + map2.put("value", type); list.add(map2); Map map3 = new HashMap(); - map3.put("code","to_command"); - map3.put("value","1"); + map3.put("code", "to_command"); + map3.put("value", "1"); list.add(map3); plugPullDeviceSiteDeviceDriver.writing(list); @@ -384,55 +382,55 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { return resultJson; } - } else if (StrUtil.equals(type,"0")){ + } else if (StrUtil.equals(type, "0")) { - if(plugPullDeviceSiteDeviceDriver.getMode() == 1){ + if (plugPullDeviceSiteDeviceDriver.getMode() == 1) { JSONObject resultJson = new JSONObject(); resultJson.put("status", HttpStatus.BAD_REQUEST.value()); resultJson.put("message", "请求插轴,当前设备工作模式未自动"); return resultJson; } - if(plugPullDeviceSiteDeviceDriver.getAction() == 0){ + if (plugPullDeviceSiteDeviceDriver.getAction() == 0) { JSONObject resultJson = new JSONObject(); resultJson.put("status", HttpStatus.BAD_REQUEST.value()); resultJson.put("message", "请求插轴,当前设备未全自动"); return resultJson; } - if(plugPullDeviceSiteDeviceDriver.getStatus() != 0){ + if (plugPullDeviceSiteDeviceDriver.getStatus() != 0) { JSONObject resultJson = new JSONObject(); resultJson.put("status", HttpStatus.BAD_REQUEST.value()); resultJson.put("message", "请求插轴,当前设备未待机"); return resultJson; } - if(plugPullDeviceSiteDeviceDriver.getControl() != 0){ + if (plugPullDeviceSiteDeviceDriver.getControl() != 0) { JSONObject resultJson = new JSONObject(); resultJson.put("status", HttpStatus.BAD_REQUEST.value()); resultJson.put("message", "请求插轴,当前设备未远程控制"); return resultJson; } - if(plugPullDeviceSiteDeviceDriver.getMove() != 1){ + if (plugPullDeviceSiteDeviceDriver.getMove() != 1) { JSONObject resultJson = new JSONObject(); resultJson.put("status", HttpStatus.BAD_REQUEST.value()); resultJson.put("message", "请求插轴,当前设备没有轴"); return resultJson; } - if(plugPullDeviceSiteDeviceDriver.getMode() == 0 && plugPullDeviceSiteDeviceDriver.getAction() ==1 - && plugPullDeviceSiteDeviceDriver.getStatus() ==0 && plugPullDeviceSiteDeviceDriver.getMove() ==1 - && plugPullDeviceSiteDeviceDriver.getControl() ==0 ){ + if (plugPullDeviceSiteDeviceDriver.getMode() == 0 && plugPullDeviceSiteDeviceDriver.getAction() == 1 + && plugPullDeviceSiteDeviceDriver.getStatus() == 0 && plugPullDeviceSiteDeviceDriver.getMove() == 1 + && plugPullDeviceSiteDeviceDriver.getControl() == 0) { List list = new ArrayList(); Map map = new HashMap(); - map.put("code","to_size"); - map.put("value",size); + map.put("code", "to_size"); + map.put("value", size); list.add(map); Map map2 = new HashMap(); - map2.put("code","to_type"); - map2.put("value",type); + map2.put("code", "to_type"); + map2.put("value", type); list.add(map2); Map map3 = new HashMap(); - map3.put("code","to_command"); - map3.put("value","1"); + map3.put("code", "to_command"); + map3.put("value", "1"); list.add(map3); plugPullDeviceSiteDeviceDriver.writing(list); @@ -457,7 +455,6 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { } - @Override public CreateTaskResponse crateTask(String param) { try { @@ -581,14 +578,14 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { route_plan_code = "normal"; } - if( StrUtil.equals(task_type,"5") && taskService.querySameDeviceReadyTask(start_device_code,next_device_code,"0") > 1){ - JSONObject json = new JSONObject(); - json.put("task_code", task_code); - json.put("ext_task_id", ext_task_id); - json.put("message", "已存在相同的起点终点未执行的输送任务"); - errArr.add(json); - continue; - } +// if( StrUtil.equals(task_type,"5") && taskService.querySameDeviceReadyTask(start_device_code,next_device_code,"0") > 1){ +// JSONObject json = new JSONObject(); +// json.put("task_code", task_code); +// json.put("ext_task_id", ext_task_id); +// json.put("message", "已存在相同的起点终点未执行的输送任务"); +// errArr.add(json); +// continue; +// } TaskDto taskDto = taskService.findByCodeFromCache(task_code); if (taskDto != null) { JSONObject json = new JSONObject(); @@ -646,6 +643,9 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { jo.put("vehicle_code", vehicle_code); jo.put("vehicle_type", vehicle_type); jo.put("storage_task_type", storage_task_type); + if (StrUtil.isEmpty(agv_system_type)) { + agv_system_type = "1"; + } jo.put("agv_system_type", agv_system_type); jo.put("oven_time", (int) Math.ceil(oven_time)); jo.put("remark", remark); @@ -658,45 +658,7 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { TaskDto task_dto = jo.toJavaObject(TaskDto.class); try { - // task_type=7 则是立库任务需要下刻下发 - if (StrUtil.equals(task_dto.getTask_type(), "7")) { -// taskService.create(task_dto); -// try{ -// taskService.createInst(task_dto.getTask_id()); -// } catch (Exception e) { -// e.printStackTrace(); -// JSONObject json = new JSONObject(); -// json.put("task_code", task_code); -// json.put("ext_task_id", ext_task_id); -// json.put("message", "创建指令失败:"+e.getMessage()); -// errArr.add(json); -// } - - //创建临时指令 不创建、不生成 - //等立库反馈成功才能创建任务和指令 - Instruction inst = taskService.createTemporaryInst(task_dto); - Resp resp = acsToLiKuService.sendInst(task_dto.getStorage_task_type(),inst); - - if(StrUtil.equals(resp.result,"true")){ - //创建任务和指令 - taskService.create(task_dto); - inst.setSend_status("1"); - taskService.createInst(inst); - - } else { - JSONObject json = new JSONObject(); - json.put("task_code", task_code); - json.put("ext_task_id", ext_task_id); - json.put("message", resp.getComment()); - json.put("code", resp.code); - json.put("data", data); - errArr.add(json); - continue; - } - - } else { - taskService.create(task_dto); - } + taskService.create(task_dto); } catch (Exception e) { // e.printStackTrace(); JSONObject json = new JSONObject(); @@ -712,7 +674,7 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { response.setMessage("success"); } else { response.setStatus(400); - if(ObjectUtil.isNotEmpty(errArr)){ + if (ObjectUtil.isNotEmpty(errArr)) { response.setMessage(errArr.getJSONObject(0).getString("message")); } else { response.setMessage("false"); @@ -727,7 +689,6 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { } - } 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 3081615..820a901 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 @@ -250,15 +250,15 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu @Override public Instruction findByTaskcodeAndStatus(String code) { - Iterator var3 = instructions.iterator(); - while (var3.hasNext()) { - Instruction instruction = (Instruction) var3.next(); - if (StrUtil.equals(instruction.getTask_code(), code) - && StrUtil.equals(instruction.getInstruction_status(), "0")) { - return instruction; - } + Iterator var3 = instructions.iterator(); + while (var3.hasNext()) { + Instruction instruction = (Instruction) var3.next(); + if (StrUtil.equals(instruction.getTask_code(), code) + && StrUtil.equals(instruction.getInstruction_status(), "0")) { + return instruction; } - return null; + } + return null; } @Override @@ -342,11 +342,6 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu HongXiangConveyorDeviceDriver hongXiangConveyorDeviceDriver; StandardCoveyorControlWithScannerDeviceDriver standardCoveyorControlWithScannerDeviceDriver; - if (startdevice.getDeviceDriver() instanceof HongXiangConveyorDeviceDriver) { - hongXiangConveyorDeviceDriver = (HongXiangConveyorDeviceDriver) startdevice.getDeviceDriver(); - hongXiangConveyorDeviceDriver.writing(3, Integer.valueOf(dto.getInstruction_code())); - } - try { String start_device_code = dto.getStart_device_code(); String next_device_code = dto.getNext_device_code(); @@ -1097,77 +1092,77 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu @Override public Instruction findByLinkNumSend(String code) { - 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; - } + 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; } @Override public List findByLinkNum(String code) { - List list = new ArrayList<>(); - 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); - } + List list = new ArrayList<>(); + 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); } - return list; + } + return list; } @Override public Instruction findByLinkNumNoSend(String code) { - 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; - } + 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; + return null; } @Override public Instruction findByCodeFromCache(String code) { - Iterator it = instructions.iterator(); - while (it.hasNext()) { - Instruction inst = it.next(); - if (StrUtil.equals(code, inst.getInstruction_code())) { - return inst; - } + Iterator it = instructions.iterator(); + while (it.hasNext()) { + Instruction inst = it.next(); + if (StrUtil.equals(code, inst.getInstruction_code())) { + return inst; } - return null; + } + return null; } @Override public Instruction findByBarcodeFromCache(String barcode) { - Iterator it = instructions.iterator(); - while (it.hasNext()) { - Instruction inst = it.next(); - if (StrUtil.equals(barcode, inst.getVehicle_code())) { - return inst; - } + Iterator it = instructions.iterator(); + while (it.hasNext()) { + Instruction inst = it.next(); + if (StrUtil.equals(barcode, inst.getVehicle_code())) { + return inst; } - return null; + } + return null; } @Override public Instruction findByIdFromCache(String id) { - Iterator it = instructions.iterator(); - while (it.hasNext()) { - Instruction inst = it.next(); - if (StrUtil.equals(id, inst.getInstruction_id())) { - return inst; - } + Iterator it = instructions.iterator(); + while (it.hasNext()) { + Instruction inst = it.next(); + if (StrUtil.equals(id, inst.getInstruction_id())) { + return inst; } - return null; + } + return null; } @Override @@ -1243,23 +1238,23 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu @Override public Instruction findByDeviceCodeFromCache(String devicecode) { - List instructionList = instructions; - ListUtil.sort( - instructionList, - new Comparator() { - @Override - public int compare(Instruction o1, Instruction o2) { - return o1.getCreate_time().compareTo(o2.getCreate_time()); - } - }); - Iterator it = instructions.iterator(); - while (it.hasNext()) { - Instruction inst = it.next(); - if (StrUtil.equals(devicecode, inst.getStart_device_code()) - && inst.getInstruction_status().equals("0")) { - return inst; - } + List instructionList = instructions; + ListUtil.sort( + instructionList, + new Comparator() { + @Override + public int compare(Instruction o1, Instruction o2) { + return o1.getCreate_time().compareTo(o2.getCreate_time()); + } + }); + Iterator it = instructions.iterator(); + while (it.hasNext()) { + Instruction inst = it.next(); + if (StrUtil.equals(devicecode, inst.getStart_device_code()) + && inst.getInstruction_status().equals("0")) { + return inst; } + } return null; } @@ -1271,52 +1266,52 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu @Override public Integer querySameDestinationInst(String devicecode) { - int num = 0; - Iterator it = instructions.iterator(); - while (it.hasNext()) { - Instruction inst = it.next(); - // 处理空盘位站点 - String next_code = inst.getNext_point_code(); - if (next_code.indexOf(".") != -1) { - next_code = next_code.substring(0, next_code.indexOf(".")); - } - if (StrUtil.equals(devicecode, next_code)) { - num = num + 1; - } + int num = 0; + Iterator it = instructions.iterator(); + while (it.hasNext()) { + Instruction inst = it.next(); + // 处理空盘位站点 + String next_code = inst.getNext_point_code(); + if (next_code.indexOf(".") != -1) { + next_code = next_code.substring(0, next_code.indexOf(".")); + } + if (StrUtil.equals(devicecode, next_code)) { + num = num + 1; } + } - return num; + return num; } @Override public Integer querySameInstType(String inst_type) { - int num = 0; - Iterator it = instructions.iterator(); - while (it.hasNext()) { - Instruction inst = it.next(); - if (StrUtil.equals(inst.getInstruction_type(), inst_type)) { - num = num + 1; - } + int num = 0; + Iterator it = instructions.iterator(); + while (it.hasNext()) { + Instruction inst = it.next(); + if (StrUtil.equals(inst.getInstruction_type(), inst_type)) { + num = num + 1; } - return num; } + return num; + } @Override public Integer querySameOriginInst(String devicecode) { - int num = 0; - Iterator it = instructions.iterator(); - while (it.hasNext()) { - Instruction inst = it.next(); - // 处理空盘位站点 - String start_code = inst.getStart_point_code(); - if (start_code.indexOf(".") != -1) { - start_code = start_code.substring(0, start_code.indexOf(".")); - } - if (StrUtil.equals(devicecode, start_code)) { - num = num + 1; - } + int num = 0; + Iterator it = instructions.iterator(); + while (it.hasNext()) { + Instruction inst = it.next(); + // 处理空盘位站点 + String start_code = inst.getStart_point_code(); + if (start_code.indexOf(".") != -1) { + start_code = start_code.substring(0, start_code.indexOf(".")); } - return num; + if (StrUtil.equals(devicecode, start_code)) { + num = num + 1; + } + } + return num; } @Override 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 7efd12e..1077f64 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 @@ -68,610 +68,622 @@ import java.util.stream.Collectors; @RequiredArgsConstructor @Slf4j public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { - List tasks = new CopyOnWriteArrayList<>(); - - @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 { - Class var1 = TaskInstructionLock.class; - synchronized (TaskInstructionLock.class) { - this.reload(); - } - } - - public synchronized void reload() { - List list = this.queryAll("task_status <2 and is_delete =0 order by create_time"); - - tasks = new CopyOnWriteArrayList<>(list); - } - - @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); + List tasks = new CopyOnWriteArrayList<>(); + + @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 { + Class var1 = TaskInstructionLock.class; + synchronized (TaskInstructionLock.class) { + this.reload(); + } } - if (!StrUtil.isEmpty(point_code)) { - map.put("point_code", point_code); + + public synchronized void reload() { + List list = this.queryAll("task_status <2 and is_delete =0 order by create_time"); + + tasks = new CopyOnWriteArrayList<>(list); } - if (!StrUtil.isEmpty(is_over)) { - map.put("is_over", is_over); + + @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; } - 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(); - - synchronized (TaskServiceImpl.class){ - 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); + + @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; } - // 按照创建时间排序 - taskList = - taskList.stream() - .sorted( - (task1, task2) -> - DateUtil.compare( - DateUtil.parseDate(task1.getCreate_time()), - DateUtil.parse(task2.getCreate_time()))) - .collect(Collectors.toList()); + @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(); + + synchronized (TaskServiceImpl.class) { + 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); + } + + // 按照创建时间排序 + 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; } - 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 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; } - if (!StrUtil.isEmpty(vehicle_code)) { - map.put("vehicle_code", vehicle_code); + + @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; } - if (!StrUtil.isEmpty(material_type)) { - map.put("material_type", material_type); + + @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; } - if (!StrUtil.isEmpty(status)) { - map.put("status", status); + + @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; } - if (!StrUtil.isEmpty(point_code)) { - map.put("point_code", point_code); + + @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; } - if (!StrUtil.isEmpty(create_time) && !StrUtil.isEmpty(end_time)) { - map.put("create_time", create_time); - map.put("end_time", end_time); + + @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; } - 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); + + @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; } - 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("已存在该载具号的任务!"); - } + + @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; } - String currentUsername = SecurityUtils.getCurrentUsername(); - String now = DateUtil.now(); - String task_uuid = dto.getTask_id(); - if (StrUtil.isEmpty(task_uuid)) { - dto.setTask_id(IdUtil.simpleUUID()); + + @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; } - String task_code = dto.getTask_code(); - if (StrUtil.isEmpty(task_code)) { - task_code = CodeUtil.getNewCode("TASK_NO"); - task_code = "-" + task_code; + + 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; } - 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"); + + @Override + public TaskDto queryTaskByLinkNum(String link_num) { + return null; } - 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() + "路由不通!"); + + @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; } - 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"); - } + @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 { - 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.equals(DeviceType.conveyor.toString(), startDeviceType)) { + } - wo.insert(json); - synchronized(TaskServiceImpl.class){ - System.out.println("-------------------"+dto.getTask_code()); - System.out.println("-------------1"+tasks.size()); + 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); - tasks.add(dto); - System.out.println("-------------2"+tasks.size()); + wo.insert(json); + synchronized (TaskServiceImpl.class) { + System.out.println("-------------------" + dto.getTask_code()); + System.out.println("-------------1" + tasks.size()); + tasks.add(dto); + System.out.println("-------------2" + tasks.size()); + + } } - } - - /** - * 常规任务保存 - * - * @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("只能选择一个终点"); + + /** + * 常规任务保存 + * + * @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); + } } - 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); + /** + * 特殊任务保存 + * + * @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) { + @Override + @Transactional(rollbackFor = Exception.class) + public void update(TaskDto dto) { - TaskDto entity = this.findById(dto.getTask_id()); - if (entity == null) { - throw new BadRequestException("被删除或无权限,操作失败!"); - } + 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); + 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); + WQLObject wo = WQLObject.getWQLObject("acs_task"); + JSONObject json = (JSONObject) JSONObject.toJSON(dto); - wo.update(json); + wo.update(json); - Iterator iterator = tasks.iterator(); + Iterator iterator = tasks.iterator(); // while (iterator.hasNext()) { // TaskDto task = iterator.next(); // if (task.getTask_code().equals(dto.getTask_code())) { @@ -680,248 +692,250 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { // } - removeByCodeFromCache(entity.getTask_code()); + removeByCodeFromCache(entity.getTask_code()); + + 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 (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) { + 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 { - if (StrUtil.equals(entity.getTask_status(), "2")) { - feefbackdto.setIs_finished("1"); - } else { - feefbackdto.setIs_finished("0"); - } + 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); + } } - 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 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()); - System.out.println(feefbackdto == null); - 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"); + + @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()); + System.out.println(feefbackdto == null); + 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); + log.info("任务号:{},反馈wms任务状态完成成功,响应信息:{}!", entity.getTask_code(), body.body()); + } catch (Exception e) { + log.error("任务号:{},反馈wms任务状态失败,原因:{}!", entity.getTask_code(), e.getMessage()); + flag = true; + message = e.getMessage(); + e.printStackTrace(); + } finally { + } - } 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"); + 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 { - feefbackdto.setIs_finished("0"); + 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(); } - } 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); + + @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); // synchronized (TaskServiceImpl.class){ // Iterator it = tasks.iterator(); @@ -933,678 +947,679 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { // } // }} - removeByCodeFromCache(entity.getTask_code()); - - // 判断是否为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); + removeByCodeFromCache(entity.getTask_code()); + + // 判断是否为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()); + } + } } - 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 createTemporaryInst(TaskDto acsTask) { - if (acsTask == null) { - throw new BadRequestException("被删除或无权限,操作失败!"); + @Override + public Instruction createInst(String ids) throws Exception { + TaskDto acsTask = this.findById(ids); + if (acsTask == null) { + throw new BadRequestException("被删除或无权限,操作失败!"); + } + DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); + InstructionService instructionservice = SpringContextHolder.getBean("instructionServiceImpl"); + InstructionDto inst = instructionservice.findByTaskid(ids, "instruction_status < 2 "); + if (inst != null) { + throw new BadRequestException("有指令未完成!"); + } + + String taskid = acsTask.getTask_id(); + String taskcode = acsTask.getTask_code(); + String vehiclecode = acsTask.getVehicle_code(); + String priority = acsTask.getPriority(); + String start_point_code = acsTask.getStart_point_code(); + String start_device_code = acsTask.getStart_device_code(); + String route_plan_code = acsTask.getRoute_plan_code(); + String vehicleType = acsTask.getVehicle_type(); + // 是否复合任务 =0非复合任务 + String compound_task = acsTask.getCompound_task(); + String next_point_code = acsTask.getNext_point_code(); + String next_device_code = acsTask.getNext_device_code(); + String start_point_code2 = acsTask.getStart_point_code2(); + String next_point_code2 = acsTask.getNext_point_code2(); + String agv_system_type = acsTask.getAgv_system_type(); + String task_type = acsTask.getTask_type(); + /** 开始平均分解校验 */ + String this_device_code = + this.queryAssignedByDevice(acsTask.getStart_device_code(), acsTask.getNext_device_code()); + if (StrUtil.isEmpty(this_device_code)) { + List 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; } - 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; + + @Override + public Instruction createInst(Instruction inst) throws Exception { + + DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); + InstructionService instructionservice = SpringContextHolder.getBean("instructionServiceImpl"); + + instructionservice.create2(inst); + return inst; } - 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; + @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); } - Instruction instdto = new Instruction(); - if (StrUtil.isEmpty(instdto.getInstruction_code())) { - instdto.setInstruction_code(CodeUtil.getNewCode("INSTRUCT_NO")); + @Override + public void createTaskByClick(JSONObject json) { } - 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"); + + @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; } - return instdto; - } - - @Override - public Instruction createInst(String ids) throws Exception { - TaskDto acsTask = this.findById(ids); - if (acsTask == null) { - throw new BadRequestException("被删除或无权限,操作失败!"); + + @Override + public boolean removeByCodeFromCache(String code) { + CopyOnWriteArrayList taskDtos = (CopyOnWriteArrayList) this.tasks; + taskDtos.removeIf((task) -> { + return task.getTask_code().equals(code); + }); + return true; } - 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("有指令未完成!"); + + @Override + public List findAllTaskFromCache() { + return tasks; } - 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; + 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; } - 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; + 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; } - 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"); + @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; } - 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); + + @Override + public List findAllByNextCode(String device_code) { + return null; } - 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; - } + + @Override + public Integer queryAllTaskMaterialQty(String device_code) { + return null; } - return num; - } - - @Override - public boolean removeByCodeFromCache(String code) { - CopyOnWriteArrayList taskDtos = (CopyOnWriteArrayList) this.tasks; - taskDtos.removeIf((task) -> { - return task.getTask_code().equals(code); - }); - return true; - } - - @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()); - - } 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); - } + + @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; } - 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()); - - } 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); + @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 { - 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); + 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); + } + } + + 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()); + } else { - to_z = task.getTo_z(); + 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); + } } - 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 task; + } - } else { - task.setNext_device_code(next_point_code); - task.setNext_device_code(next_point_code); - } + @Override + public void updateByCodeFromCache(TaskDto dto) { + removeByCodeFromCache(dto.getTask_code()); + tasks.add(dto); } - return task; - } - - @Override - public void updateByCodeFromCache(TaskDto dto) { - removeByCodeFromCache(dto.getTask_code()); - 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; - } - } + + @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; } - if (!StrUtil.isEmpty(flag2)) { - return flag2; + + @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++; + } + } + + return num; } - 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++; - } - } - - 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++; - } - } - - return num; - } - - @Override - public Integer querySameOriginTask(String code) { - int num = 0; - Iterator iterator = tasks.iterator(); - while (iterator.hasNext()) { - TaskDto task = iterator.next(); - if (StrUtil.equals(task.getStart_device_code(), code)) { - num++; - } - } - - return num; - } - - @Override - public Integer querySameDestinationTask(String code) { - int num = 0; - Iterator iterator = tasks.iterator(); - while (iterator.hasNext()) { - TaskDto task = iterator.next(); - if (StrUtil.equals(task.getNext_device_code(), code)) { - num++; - } - } - - 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++; + } + } + + return num; + } + + @Override + public Integer querySameOriginTask(String code) { + int num = 0; + Iterator iterator = tasks.iterator(); + while (iterator.hasNext()) { + TaskDto task = iterator.next(); + if (StrUtil.equals(task.getStart_device_code(), code)) { + num++; + } + } + + return num; + } + + @Override + public Integer querySameDestinationTask(String code) { + int num = 0; + Iterator iterator = tasks.iterator(); + while (iterator.hasNext()) { + TaskDto task = iterator.next(); + if (StrUtil.equals(task.getNext_device_code(), code)) { + num++; + } + } + + return num; } } diff --git a/acs/nladmin-system/src/main/java/org/nl/modules/quartz/task/AutoCreateInst.java b/acs/nladmin-system/src/main/java/org/nl/modules/quartz/task/AutoCreateInst.java index f68170c..e575119 100644 --- a/acs/nladmin-system/src/main/java/org/nl/modules/quartz/task/AutoCreateInst.java +++ b/acs/nladmin-system/src/main/java/org/nl/modules/quartz/task/AutoCreateInst.java @@ -139,29 +139,8 @@ public class AutoCreateInst { instdto.setExecute_device_code(start_point_code); instdto.setVehicle_type(vehicleType); 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"); - } + instdto.setAgv_inst_type("1"); + try { instructionService.create(instdto);