diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor/SiemensConveyorDeviceDriver.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor/SiemensConveyorDeviceDriver.java index 1e8bae273..c5ac3a170 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor/SiemensConveyorDeviceDriver.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor/SiemensConveyorDeviceDriver.java @@ -188,7 +188,7 @@ public class SiemensConveyorDeviceDriver extends AbstractOpcDeviceDriver impleme logServer.deviceExecuteLog(this.device_code, "", "", "信号task:" + last_task + "->" + task); } - if (move != 0 && task > 0) { + if (move != 0 && task > 0 ) { // logServer.deviceExecuteLog(device_code, "", "", "输送线任务开始反馈任务状态,指令号:" + task); //inst_message inst = instructionService.findByCodeFromCache(String.valueOf(task)); @@ -781,18 +781,21 @@ public class SiemensConveyorDeviceDriver extends AbstractOpcDeviceDriver impleme Instruction instruction = instructionService.findByCodeFromCache(String.valueOf(task)); if(ObjectUtil.isEmpty(instruction)){ message = "申请捆扎电气设备任务号:" + task + "未找到对应指令"; - throw new RuntimeException("该电气任务号未找到对应指令!"); + return ; +// throw new RuntimeException("该电气任务号未找到对应指令!"); } vehicle_code = instruction.getVehicle_code(); } else { logServer.deviceExecuteLog(device_code, "", "", "申请捆扎电气设备任务号:" + task + "异常"); message = "申请捆扎电气设备任务号:" + task + "异常"; - throw new RuntimeException("任务号为空!"); + return ; +// throw new RuntimeException("任务号为空!"); } if (StrUtil.isEmpty(vehicle_code)) { logServer.deviceExecuteLog(device_code, "", "", "申请捆扎电气设备任务号:" + task + "未找到载具号"); message = "申请捆扎电气设备任务号:" + task + "未找到载具号"; - throw new RuntimeException("载具号为空!"); + return ; +// throw new RuntimeException("载具号为空!"); } ApplyLabelingAndBindingRequest applyLabelingAndBindingRequest = new ApplyLabelingAndBindingRequest(); @@ -901,6 +904,10 @@ public class SiemensConveyorDeviceDriver extends AbstractOpcDeviceDriver impleme message = "指令号"+task+"未找到对应指令"; return; } + if(StrUtil.isEmpty(instruction.getVehicle_code())){ + message = "指令号"+task+"未找到对应木箱号"; + return; + } message = "申请AGV搬运任务中..."; JSONObject apply = new JSONObject(); apply.put("device_code", device_code); diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/rest/AcsToLiKuController.java b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/rest/AcsToLiKuController.java index 012674495..494393c02 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/rest/AcsToLiKuController.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/rest/AcsToLiKuController.java @@ -11,6 +11,7 @@ import lombok.extern.slf4j.Slf4j; import org.nl.acs.ext.wms.liKuData.*; import org.nl.acs.ext.wms.service.AcsToLiKuService; import org.nl.acs.ext.wms.service.AcsToWmsService; +import org.nl.modules.logging.InterfaceLogType; import org.nl.modules.logging.annotation.Log; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -34,77 +35,77 @@ public class AcsToLiKuController { private final AcsToLiKuService acsToLiKuService; @PostMapping("/inStore") - @Log("向立库wcs下发入库任务") - @ApiOperation("向立库wcs下发入库任务") + @Log(value = "下发立库入库任务",isInterfaceLog = true,interfaceLogType= InterfaceLogType.ACS_TO_LK) + @ApiOperation("下发立库物料入库任务") public ResponseEntity inStore(@RequestBody InStoreRequest requestParam) { return new ResponseEntity<>(acsToLiKuService.inStore(requestParam), HttpStatus.OK); } @PostMapping("/outStore") - @Log("向立库wcs下发出库任务") - @ApiOperation("向立库wcs下发出库任务") + @Log(value = "下发立库出库任务",isInterfaceLog = true,interfaceLogType= InterfaceLogType.ACS_TO_LK) + @ApiOperation("下发立库出库任务") public ResponseEntity outStore(@RequestBody OutStoreRequest requestParam) { return new ResponseEntity<>(acsToLiKuService.outStore(requestParam), HttpStatus.OK); } @PostMapping("/emptyVehicleOutStore") - @Log("向立库wcs下发空托盘出库任务") - @ApiOperation("向立库wcs下发空托盘出库任务") + @Log(value = "下发立库空盘出库任务",isInterfaceLog = true,interfaceLogType= InterfaceLogType.ACS_TO_LK) + @ApiOperation("下发立库空盘出库任务") public ResponseEntity emptyVehicleOutStore(@RequestBody EmptyVehicleOutStoreRequest requestParam) { return new ResponseEntity<>(acsToLiKuService.emptyVehicleOutStore(requestParam), HttpStatus.OK); } @PostMapping("/moveStore") - @Log("向立库wcs下发移库任务") - @ApiOperation("向立库wcs下发移库任务") + @Log(value = "下发立库移库任务",isInterfaceLog = true,interfaceLogType= InterfaceLogType.ACS_TO_LK) + @ApiOperation("下发立库移库任务") public ResponseEntity moveStore(@RequestBody MoveStoreRequest requestParam) { return new ResponseEntity<>(acsToLiKuService.moveStore(requestParam), HttpStatus.OK); } @PostMapping("/inStoreReset") - @Log("向立库wcs下发入库任务调整") - @ApiOperation("向立库wcs下发入库任务调整") + @Log(value = "下发立库入库任务调整",isInterfaceLog = true,interfaceLogType= InterfaceLogType.ACS_TO_LK) + @ApiOperation("下发立库入库任务调整") public ResponseEntity inStoreReset(@RequestBody InStoreResetRequest requestParam) { return new ResponseEntity<>(acsToLiKuService.inStoreReset(requestParam), HttpStatus.OK); } @PostMapping("/moveStoreReset") - @Log("向立库wcs下发移库任务调整") - @ApiOperation("向立库wcs下发移库任务调整") + @Log(value = "下发立库移库任务调整",isInterfaceLog = true,interfaceLogType= InterfaceLogType.ACS_TO_LK) + @ApiOperation("下发立库移库任务调整") public ResponseEntity moveStoreReset(@RequestBody MoveStoreResetRequest requestParam) { return new ResponseEntity<>(acsToLiKuService.moveStoreReset(requestParam), HttpStatus.OK); } @PostMapping("/roadWayIsLock") - @Log("向立库下发巷道锁定或解锁") + @Log(value = "下发立库巷道锁定或解锁",isInterfaceLog = true,interfaceLogType= InterfaceLogType.ACS_TO_LK) @ApiOperation("向立库下发巷道锁定或解锁") public ResponseEntity roadWayIsLock(@RequestBody RoadWayIsLockRequest requestParam) { return new ResponseEntity<>(acsToLiKuService.roadWayIsLock(requestParam), HttpStatus.OK); } @PostMapping("/cancelTask") - @Log("向立库下发任务取消") - @ApiOperation("向立库下发任务取消") + @Log(value = "取消立库任务",isInterfaceLog = true,interfaceLogType= InterfaceLogType.ACS_TO_LK) + @ApiOperation("取消立库任务") public ResponseEntity cancelTask(@RequestBody CancelTaskRequest requestParam) { return new ResponseEntity<>(acsToLiKuService.cancelTask(requestParam), HttpStatus.OK); } @PostMapping("/queryCarStatus") - @Log("查询四向车状态") + @Log(value = "查询四向车状态",isInterfaceLog = true,interfaceLogType= InterfaceLogType.ACS_TO_LK) @ApiOperation("查询四向车状态") public ResponseEntity queryCarStatus(@RequestBody DeviceStatusRequest requestParam) { return new ResponseEntity<>(acsToLiKuService.queryCarDeviceStatus(requestParam), HttpStatus.OK); } @PostMapping("/queryTsjStatus") - @Log("查询提升机状态") + @Log(value = "查询提升机状态",isInterfaceLog = true,interfaceLogType= InterfaceLogType.ACS_TO_LK) @ApiOperation("查询提升机状态") public ResponseEntity queryTsjStatus(@RequestBody DeviceStatusRequest requestParam) { return new ResponseEntity<>(acsToLiKuService.queryTsjDeviceStatus(requestParam), HttpStatus.OK); } @PostMapping("/querySsxStatus") - @Log("查询输送线状态") + @Log(value = "查询提升机状态",isInterfaceLog = true,interfaceLogType= InterfaceLogType.ACS_TO_LK) @ApiOperation("查询提升机状态") public ResponseEntity querySsxStatus(@RequestBody DeviceStatusRequest requestParam) { return new ResponseEntity<>(acsToLiKuService.queryTsjDeviceStatus(requestParam), HttpStatus.OK); 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 9d5d6c5ea..35965e4a6 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 @@ -11,6 +11,7 @@ import lombok.extern.slf4j.Slf4j; import org.nl.acs.ext.wms.data.ApplyLabelingAndBindingRequest; import org.nl.acs.ext.wms.data.LiKuApplyTaskRequest; import org.nl.acs.ext.wms.service.AcsToWmsService; +import org.nl.modules.logging.InterfaceLogType; import org.nl.modules.logging.annotation.Log; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -34,43 +35,43 @@ public class AcsToWmsController { private final AcsToWmsService acstowmsService; @PostMapping("/applyTask") - @Log("向WMS申请任务") - @ApiOperation("向WMS申请任务") + @Log(value = "ACS向WMS申请任务",isInterfaceLog = true,interfaceLogType= InterfaceLogType.ACS_TO_LMS) + @ApiOperation("ACS向WMS申请任务") public ResponseEntity applyTaskToWms(@RequestBody JSONObject jo) { return new ResponseEntity<>(acstowmsService.applyTaskToWms(jo), HttpStatus.OK); } @PostMapping("/taskStatusFeedback") - @Log("向WMS反馈任务状态") - @ApiOperation("向WMS反馈任务状态") + @Log(value = "ACS向WMS反馈任务状态",isInterfaceLog = true,interfaceLogType= InterfaceLogType.ACS_TO_LMS) + @ApiOperation("ACS向WMS反馈任务状态") public ResponseEntity feedbackTaskStatusToWms(@RequestBody Map whereJson) { JSONArray data = JSONArray.parseArray(String.valueOf(whereJson)); return new ResponseEntity<>(acstowmsService.feedbackTaskStatusToWms(data), HttpStatus.OK); } @PostMapping("/feedbackAgvStatus") - @Log("反馈AGV设备状态") + @Log(value = "反馈AGV设备状态",isInterfaceLog = true,interfaceLogType= InterfaceLogType.ACS_TO_LMS) @ApiOperation("反馈AGV设备状态") public ResponseEntity feedbackAgvStatus(@RequestBody String device_code, String error, String error_message) { return new ResponseEntity<>(acstowmsService.feedbackAgvStatus(device_code, error, error_message), HttpStatus.OK); } @PostMapping("/feedbackAgv") - @Log("反馈AGV设备信息") + @Log(value = "反馈AGV设备信息",isInterfaceLog = true,interfaceLogType= InterfaceLogType.ACS_TO_LMS) @ApiOperation("反馈AGV设备信息") public ResponseEntity feedbackAgv(@RequestBody JSONArray from) { return new ResponseEntity<>(acstowmsService.feedbackAgv(from), HttpStatus.OK); } @PostMapping("/feedbackDeviceStatus") - @Log("反馈设备状态") + @Log(value = "反馈设备状态",isInterfaceLog = true,interfaceLogType= InterfaceLogType.ACS_TO_LMS) @ApiOperation("反馈设备状态") public ResponseEntity feedbackDeviceStatus(@RequestBody String device_code, String code, String value) { return new ResponseEntity<>(acstowmsService.feedbackDeviceStatus(device_code, code, value), HttpStatus.OK); } @PostMapping("/feedbackOrderStatus") - @Log("acs强制完成向wms反馈") + @Log(value = "ACS强制完成向WMS反馈",isInterfaceLog = true,interfaceLogType= InterfaceLogType.ACS_TO_LMS) @ApiOperation("acs强制完成向wms反馈") public ResponseEntity feedbackOrderStatus(@RequestBody JSONObject param) { return new ResponseEntity<>(acstowmsService.feedbackOrderStatus(param), HttpStatus.OK); @@ -78,28 +79,28 @@ public class AcsToWmsController { @PostMapping("/applyInCacheLineTask") - @Log("ACS申请缓存线入库任务") + @Log(value = "ACS申请缓存线入库任务",isInterfaceLog = true,interfaceLogType= InterfaceLogType.ACS_TO_LMS) @ApiOperation("ACS申请缓存线入库任务") public ResponseEntity applyInCacheLineTask(@RequestBody JSONObject param) { return new ResponseEntity<>(acstowmsService.applyInCacheLineTask(param), HttpStatus.OK); } @PostMapping("/applyOutCacheLineTask") - @Log("ACS系统申请出库任务") + @Log(value = "ACS系统申请出库任务",isInterfaceLog = true,interfaceLogType= InterfaceLogType.ACS_TO_LMS) @ApiOperation("ACS系统申请出库任务") public ResponseEntity applyOutCacheLineTask(@RequestBody JSONObject param) { return new ResponseEntity<>(acstowmsService.applyOutCacheLineTask(param), HttpStatus.OK); } @PostMapping("/applyLabelingAndBindingRequest") - @Log("ACS系统申请贴标、捆扎") + @Log(value = "ACS系统申请贴标、捆扎",isInterfaceLog = true,interfaceLogType= InterfaceLogType.ACS_TO_LMS) @ApiOperation("ACS系统申请贴标、捆扎") public ResponseEntity applyLabelingAndBindingRequest(@RequestBody ApplyLabelingAndBindingRequest param) { return new ResponseEntity<>(acstowmsService.applyLabelingAndBindingRequest(param), HttpStatus.OK); } @PostMapping("/liKuApplyTaskRequest") - @Log("立库申请任务") + @Log(value = "立库申请任务",isInterfaceLog = true,interfaceLogType= InterfaceLogType.ACS_TO_LMS) @ApiOperation("立库申请任务") public ResponseEntity liKuApplyTaskRequest(@RequestBody LiKuApplyTaskRequest param) { return new ResponseEntity<>(acstowmsService.liKuApplyTaskRequest(param), HttpStatus.OK); diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/rest/LiKuToACSController.java b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/rest/LiKuToACSController.java index acf3a41b0..e140f01ba 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/rest/LiKuToACSController.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/rest/LiKuToACSController.java @@ -11,6 +11,7 @@ import lombok.extern.slf4j.Slf4j; import org.nl.acs.ext.wms.liKuData.*; import org.nl.acs.ext.wms.service.AcsToLiKuService; import org.nl.acs.ext.wms.service.LiKuToAcsService; +import org.nl.modules.logging.InterfaceLogType; import org.nl.modules.logging.annotation.Log; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -33,32 +34,32 @@ public class LiKuToACSController { @SaIgnore @PostMapping("/inStoreReport") - @Log("入库任务上报") - @ApiOperation("向立库下发入库任务上报") + @Log(value = "立库反馈入库任务状态",isInterfaceLog = true,interfaceLogType= InterfaceLogType.LK_TO_ACS) + @ApiOperation("立库反馈入库任务状态") public ResponseEntity inStoreReport(@RequestBody InStoreReportRequest requestParam) throws Exception { return new ResponseEntity<>(liKuToAcsService.inStoreReport(requestParam), HttpStatus.OK); } @SaIgnore @PostMapping("/outStoreReport") - @Log("出库任务上报") - @ApiOperation("向立库下发出库任务上报") + @Log(value = "立库反馈出库任务状态",isInterfaceLog = true,interfaceLogType= InterfaceLogType.LK_TO_ACS) + @ApiOperation("立库反馈出库任务状态") public ResponseEntity outStoreReport(@RequestBody OutStoreReportRequest requestParam) throws Exception { return new ResponseEntity<>(liKuToAcsService.outStoreReport(requestParam), HttpStatus.OK); } @SaIgnore @PostMapping("/moveStoreReport") - @Log("移库任务上报") - @ApiOperation("向立库下发移库任务上报") + @Log(value = "立库反馈移库任务状态",isInterfaceLog = true,interfaceLogType= InterfaceLogType.LK_TO_ACS) + @ApiOperation("立库反馈移库任务状态") public ResponseEntity moveStoreReport(@RequestBody MoveStoreReportRequest requestParam) throws Exception { return new ResponseEntity<>(liKuToAcsService.moveStoreReport(requestParam), HttpStatus.OK); } @SaIgnore @PostMapping("/putEmptyPallet") - @Log("请求放空盘") - @ApiOperation("请求放空盘") + @Log(value = "立库请求放空盘",isInterfaceLog = true,interfaceLogType= InterfaceLogType.LK_TO_ACS) + @ApiOperation("立库请求放空盘") public ResponseEntity putEmptyPallet(@RequestBody putEmptyPalletRequest requestParam) throws Exception { return new ResponseEntity<>(liKuToAcsService.putEmptyPallet(requestParam), HttpStatus.OK); } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/rest/WmsToAcsController.java b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/rest/WmsToAcsController.java index 4ae5fec1a..47c5a8807 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/rest/WmsToAcsController.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/rest/WmsToAcsController.java @@ -10,6 +10,7 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.nl.acs.ext.wms.data.CreateTaskResponse; import org.nl.acs.ext.wms.service.WmsToAcsService; +import org.nl.modules.logging.InterfaceLogType; import org.nl.modules.logging.annotation.Log; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -31,7 +32,7 @@ public class WmsToAcsController { private final WmsToAcsService wmstoacsService; @PostMapping("/task") - @Log("接收WMS任务") + @Log(value = "ACS接收WMS任务",isInterfaceLog = true,interfaceLogType= InterfaceLogType.LMS_TO_ACS) @ApiOperation("接收WMS任务") @SaIgnore public ResponseEntity createFromWms(@RequestBody String whereJson) { @@ -39,7 +40,7 @@ public class WmsToAcsController { } @PostMapping("/cancelTask") - @Log("WMS取消任务") + @Log(value = "WMS取消任务",isInterfaceLog = true,interfaceLogType= InterfaceLogType.LMS_TO_ACS) @ApiOperation("WMS取消任务") @SaIgnore public ResponseEntity cancelFromWms(@RequestBody String whereJson) throws Exception { @@ -47,38 +48,38 @@ public class WmsToAcsController { } @PostMapping("/updateDeviceGoodsFromWms") - @Log("WMS修改点位状态") + @Log(value = "WMS修改点位状态",isInterfaceLog = true,interfaceLogType= InterfaceLogType.LMS_TO_ACS) @ApiOperation("WMS修改点位状态") public ResponseEntity updateDeviceGoodsFromWms(@RequestBody String whereJson) { return new ResponseEntity<>(wmstoacsService.updateDeviceGoodsFromWms(whereJson), HttpStatus.OK); } @PostMapping("/areaControl") - @Log("区域控制") + @Log(value = "区域控制",isInterfaceLog = true,interfaceLogType= InterfaceLogType.LMS_TO_ACS) @ApiOperation("区域控制") public ResponseEntity areaControl(@RequestBody JSONObject whereJson) { return new ResponseEntity<>(wmstoacsService.areaControl(whereJson), HttpStatus.OK); } @PostMapping("/action") - @Log("下发动作") - @ApiOperation("WMS修改点位状态") + @Log(value = "WMS下发点位信号",isInterfaceLog = true,interfaceLogType= InterfaceLogType.LMS_TO_ACS) + @ApiOperation("WMS下发点位信号") @SaIgnore public ResponseEntity putAction(@RequestBody String whereJson) throws Exception { return new ResponseEntity<>(wmstoacsService.putAction(whereJson), HttpStatus.OK); } @PostMapping("/querydevice") - @Log("查询设备状态") - @ApiOperation("查询设备状态") + @Log(value = "WMS查询设备状态",isInterfaceLog = true,interfaceLogType= InterfaceLogType.LMS_TO_ACS) + @ApiOperation("WMS查询设备状态") @SaIgnore public ResponseEntity queryDevice(@RequestBody String whereJson) throws Exception { return new ResponseEntity<>(wmstoacsService.queryDevice(whereJson), HttpStatus.OK); } @PostMapping("/queryDeviceDBValue") - @Log("查询设备DB值") - @ApiOperation("查询设备DB值") + @Log(value = "WMS查询设备DB值",isInterfaceLog = true,interfaceLogType= InterfaceLogType.LMS_TO_ACS) + @ApiOperation("WMS查询设备DB值") @SaIgnore public ResponseEntity queryDeviceDBValue(@RequestBody String whereJson){ return new ResponseEntity<>(wmstoacsService.queryDeviceDBValue(whereJson), HttpStatus.OK); @@ -86,8 +87,8 @@ public class WmsToAcsController { @PostMapping("/putPlusPullAction") - @Log("下发插拔轴动作") - @ApiOperation("下发插拔轴动作") + @Log(value = "WMS下发插拔轴动作",isInterfaceLog = true,interfaceLogType= InterfaceLogType.LMS_TO_ACS) + @ApiOperation("WMS下发插拔轴动作") @SaIgnore public ResponseEntity putPlusPullAction(@RequestBody String whereJson){ return new ResponseEntity<>(wmstoacsService.putPlusPullAction(whereJson), HttpStatus.OK); diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/LiKuToAcsServiceImpl.java b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/LiKuToAcsServiceImpl.java index 942392c4d..1bcc665ef 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/LiKuToAcsServiceImpl.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/LiKuToAcsServiceImpl.java @@ -56,45 +56,40 @@ public class LiKuToAcsServiceImpl implements LiKuToAcsService { //入库任务状态反馈 @Override public Resp inStoreReport(InStoreReportRequest requestParam) throws Exception { - try { - MDC.put(log_file_type, log_type); - log.info("入库任务状态反馈-----输入参数{}", JSON.toJSONString(requestParam)); - String inst_code = requestParam.getOrderId(); - String status = requestParam.getState(); - String carNo = requestParam.getRobotId(); - Instruction inst = instructionService.findByCodeFromCache(inst_code); - TaskDto task = taskService.findByCodeFromCache(inst.getTask_code()); - // 1 已接收 2 开始执行 3执行完成 4 5 取消 - if(StrUtil.equals(status,"1") || StrUtil.equals(status,"2") ){ - task.setTask_status("1"); - taskService.update(task); - inst.setInstruction_status("1"); - inst.setExecute_device_code(carNo); - inst.setCarno(carNo); - instructionService.update(inst); - } else if(StrUtil.equals(status,"3")){ - inst.setInstruction_status("2"); - instructionService.finish(inst.getInstruction_id()); - } else if(StrUtil.equals(status,"4")) { - // 5 取消指令 - } else if(StrUtil.equals(status,"5")) { + log.info("入库任务状态反馈-----输入参数{}", JSON.toJSONString(requestParam)); + String inst_code = requestParam.getOrderId(); + String status = requestParam.getState(); + String carNo = requestParam.getRobotId(); + Instruction inst = instructionService.findByCodeFromCache(inst_code); + TaskDto task = taskService.findByCodeFromCache(inst.getTask_code()); + // 1 已接收 2 开始执行 3执行完成 4 5 取消 + if(StrUtil.equals(status,"1") || StrUtil.equals(status,"2") ){ + task.setTask_status("1"); + taskService.update(task); + inst.setInstruction_status("1"); + inst.setExecute_device_code(carNo); + inst.setCarno(carNo); + instructionService.update(inst); + } else if(StrUtil.equals(status,"3")){ + inst.setInstruction_status("2"); + instructionService.finish(inst.getInstruction_id()); + } else if(StrUtil.equals(status,"4")) { - instructionService.cancel(inst.getInstruction_id()); - } - InStoreReportResponse inStoreReportResponse = new InStoreReportResponse(); - inStoreReportResponse.setOrderId(inst_code); - JSONObject result = new JSONObject(); - result.put("result", "true"); - result.put("code", "0"); - result.put("comment", ""); - result.put("data", inStoreReportResponse ); - log.info("入库任务状态反馈-----输出参数{}", result); - return RespUtil.getResp(result.toString(), new InStoreReportResponse()); - } finally { - MDC.remove(log_file_type); + // 5 取消指令 + } else if(StrUtil.equals(status,"5")) { + + instructionService.cancel(inst.getInstruction_id()); } - + InStoreReportResponse inStoreReportResponse = new InStoreReportResponse(); + inStoreReportResponse.setOrderId(inst_code); + JSONObject result = new JSONObject(); + result.put("result", "true"); + result.put("code", "0"); + result.put("comment", ""); + result.put("data", inStoreReportResponse ); + log.info("入库任务状态反馈-----输出参数{}", result); + return RespUtil.getResp(result.toString(), new InStoreReportResponse()); } 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 2ab2c8efe..15564de89 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 @@ -691,6 +691,7 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { json.put("code", resp.code); json.put("data", data); errArr.add(json); + continue; } } else { @@ -703,6 +704,7 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { json.put("ext_task_id", ext_task_id); json.put("message", e.getMessage()); errArr.add(json); + continue; } } if (ObjectUtil.isEmpty(errArr)) { 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 ebb514a99..a0e155f4c 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 @@ -53,6 +53,7 @@ import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.*; import java.util.concurrent.CopyOnWriteArrayList; +import java.util.function.Predicate; import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -66,1410 +67,1395 @@ import java.util.stream.Collectors; @Slf4j public class InstructionServiceImpl implements InstructionService, ApplicationAutoInitial { - List instructions = new CopyOnWriteArrayList(); + List instructions = new CopyOnWriteArrayList(); - @Autowired DeviceAppService deviceAppService; - @Autowired NDCAgvService ndcAgvService; - @Autowired ParamService paramService; - @Autowired RouteLineService routeLineService; - @Autowired TaskService taskService; - @Autowired AcsToLiKuService acsToLiKuService; + @Autowired + DeviceAppService deviceAppService; + @Autowired + NDCAgvService ndcAgvService; + @Autowired + ParamService paramService; + @Autowired + RouteLineService routeLineService; + @Autowired + TaskService taskService; + @Autowired + AcsToLiKuService acsToLiKuService; - @Override - public void autoInitial() { - this.reload(); - } - - @Override - public synchronized void reload() { - synchronized (TaskInstructionLock.class) { - this.instructions = this.queryAll("instruction_status <2 and is_delete =0"); - } - } - - @Override - public Map queryAll(Map whereJson, Pageable page) { - HashMap map = new HashMap<>(); - map.put("flag", "1"); - String code = (String) whereJson.get("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 instruction_type = (String) whereJson.get("instruction_type"); - if (!StrUtil.isEmpty(code)) { - map.put("code", 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); - } - map.put("instruction_type", instruction_type); - - Integer currentPageNumber = page.getPageNumber() + 1; - Integer pageMaxSize = page.getPageSize(); - final JSONObject jo = - WQL.getWO("QINST_QUERY").addParamMap(map).pageQuery(WqlUtil.getHttpContext(page), ""); - JSONArray jsonArray = jo.getJSONArray("content"); - List instructions = jsonArray.toJavaList(Instruction.class); - List instDtoList = - instructions.stream() - .skip((currentPageNumber - 1) * pageMaxSize) - .limit(pageMaxSize) - .collect(Collectors.toList()); - jo.put("content", instDtoList); - jo.put("totalElements", jsonArray.size()); - return jo; - } - - @Override - public Map getAll(Map whereJson, Pageable page) { - HashMap map = new HashMap<>(); - map.put("flag", "2"); - String code = (String) whereJson.get("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(code)) { - map.put("code", 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); + @Override + public void autoInitial() { + this.reload(); } - final JSONObject jo = - WQL.getWO("QINST_QUERY") - .addParamMap(map) - .pageQuery(WqlUtil.getHttpContext(page), "create_time desc"); - return jo; - } - - @Override - public Map getByTaskId(String id) { - WQLObject wo = WQLObject.getWQLObject("acs_instruction"); - JSONObject jsonObject = wo.query("task_id='" + id + "'").pageResult(); - JSONArray content = jsonObject.getJSONArray("content"); - JSONArray array = new JSONArray(); - for (int i = 0; i < content.size(); i++) { - JSONObject jo = (JSONObject) content.get(i); - JSONObject ins = new JSONObject(); - ins.put("task_id", jo.get("instruction_id")); - ins.put("task_code", jo.get("instruction_code")); - ins.put("task_status", jo.get("instruction_status")); - ins.put("start_point_code", jo.get("start_point_code")); - ins.put("next_point_code", jo.get("next_point_code")); - ins.put("matarial", jo.get("matarial")); - ins.put("remark", jo.get("remark")); - ins.put("create_by", jo.get("create_by")); - ins.put("create_time", jo.get("create_time")); - array.add(ins); + @Override + public synchronized void reload() { + List list = this.queryAll("instruction_status <2 and is_delete =0"); + this.instructions = new CopyOnWriteArrayList<>(list); } - jsonObject.put("content", array); - return jsonObject; - } - @Override - public List queryAll(Map whereJson) { - WQLObject wo = WQLObject.getWQLObject("acs_instruction"); - JSONArray arr = wo.query().getResultJSONArray(0); - List list = arr.toJavaList(Instruction.class); - return list; - } - - @Override - public List queryAll(String whereJson) { - WQLObject wo = WQLObject.getWQLObject("acs_instruction"); - JSONArray arr = wo.query(whereJson, "create_time").getResultJSONArray(0); - List list = arr.toJavaList(Instruction.class); - return list; - } - - @Override - public Instruction findById(String instruction_id) { - WQLObject wo = WQLObject.getWQLObject("acs_instruction"); - JSONObject json = wo.query("instruction_id ='" + instruction_id + "'").uniqueResult(0); - if (ObjectUtil.isNotEmpty(json)) { - final Instruction obj = json.toJavaObject(Instruction.class); - return obj; - } - return null; - } - - @Override - public Instruction findByCode(String code) { - WQLObject wo = WQLObject.getWQLObject("acs_instruction"); - JSONObject json = wo.query("instruction_code ='" + code + "'").uniqueResult(0); - if (ObjectUtil.isEmpty(json)) { - return null; - } - final Instruction obj = json.toJavaObject(Instruction.class); - return obj; - } - - @Override - public Instruction findByTaskcode(String code) { - WQLObject wo = WQLObject.getWQLObject("acs_instruction"); - JSONObject json = wo.query("task_code ='" + code + "'").uniqueResult(0); - final Instruction obj = json.toJavaObject(Instruction.class); - return obj; - } - - @Override - public Instruction findByTaskcodeAndStatus(String code) { - synchronized (InstructionServiceImpl.class) { - 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; + @Override + public Map queryAll(Map whereJson, Pageable page) { + HashMap map = new HashMap<>(); + map.put("flag", "1"); + String code = (String) whereJson.get("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 instruction_type = (String) whereJson.get("instruction_type"); + if (!StrUtil.isEmpty(code)) { + map.put("code", code); } - } - return null; - } - } - - @Override - public Instruction findByTaskid(String id, String wherecaluse) { - if (!StrUtil.isEmpty(wherecaluse)) { - wherecaluse = " and " + wherecaluse; - } - WQLObject wo = WQLObject.getWQLObject("acs_instruction"); - JSONObject json = wo.query("task_id ='" + id + "'" + wherecaluse).uniqueResult(0); - if (ObjectUtil.isNotEmpty(json)) { - return json.toJavaObject(Instruction.class); - } - return null; - } - - @Override - public void create(Instruction dto) { - dto = foramte(dto); - String task_code = dto.getTask_code(); - TaskDto task = taskService.findByCodeFromCache(task_code); - - String currentUsername = SecurityUtils.getCurrentUsername(); - String now = DateUtil.now(); - if (StrUtil.isEmpty(dto.getRoute_plan_code())) { - dto.setRoute_plan_code(task.getRoute_plan_code()); - } - if (StrUtil.isEmpty(dto.getPriority())) { - dto.setPriority(task.getPriority()); - } - if (StrUtil.isEmpty(dto.getInstruction_code())) { - dto.setInstruction_code(CodeUtil.getNewCode("INSTRUCT_NO")); - } - if (StrUtil.isEmpty(dto.getInstruction_id())) { - dto.setInstruction_id(IdUtil.simpleUUID()); - } - if (StrUtil.isEmpty(dto.getIs_send())) { - dto.setIs_send(task.getIs_send()); - } - if (StrUtil.isEmpty(dto.getLink_num())) { - dto.setIs_send(task.getLink_num()); - } - if (task.getTask_type().equals("1") || task.getTask_type().equals("2")) { - dto.setInstruction_type(task.getTask_type()); - } else if (false) { - - } else { - dto.setInstruction_type("3"); - } - - // 查询是否存在相同指令号 - // if (!StrUtil.isEmpty(dto.getVehicle_code() )) { - // Instruction inst_dto = findByContainer(dto.getVehicle_code()); - // if (inst_dto != null) { - // log.error("存在相同载具号任务,载具号"+dto.getVehicle_code()); - // throw new BadRequestException("存在相同载具号任务!"); - // } - // } - // 起点设备与终点设备相同则为初始指令 - if (StrUtil.equals(task.getStart_device_code(), dto.getStart_device_code())) { - if (!StrUtil.equals(dto.getCompound_inst(), "0") - && StrUtil.equals(task.getCompound_task(), "1")) { - dto.setCompound_inst("1"); - dto.setCompound_inst_data(task.getCompound_task_data()); - } - } - - dto.setCreate_by(currentUsername); - dto.setUpdate_by(currentUsername); - dto.setUpdate_time(now); - dto.setCreate_time(now); - dto.setStart_parent_code(task.getStart_parent_code()); - dto.setNext_parent_code(task.getNext_parent_code()); - - if (ObjectUtil.isNotEmpty(task.getTask_type())) { - dto.setInstruction_type(task.getTask_type()); - } - - DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); - Device startdevice = appService.findDeviceByCode(dto.getStart_device_code()); - - 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(); - String route_plan_code = task.getRoute_plan_code(); - List shortPathsList = - routeLineService.getShortPathLines(start_device_code, next_device_code, route_plan_code); - RouteLineDto route = null; - for (int i = 0; i < shortPathsList.size(); i++) { - RouteLineDto routeLineDto = shortPathsList.get(i); - String route_device = routeLineDto.getDevice_code(); - String route_next_device = routeLineDto.getNext_device_code(); - if (route_device.equals(dto.getStart_device_code()) - && route_next_device.equals(dto.getNext_device_code())) { - route = routeLineDto; - break; + if (!StrUtil.isEmpty(vehicle_code)) { + map.put("vehicle_code", vehicle_code); } - } - if (ObjectUtil.isEmpty(route)) { - throw new BadRequestException("未查询到相关路由!"); - } - if (StrUtil.equals(shortPathsList.get(0).getType(), "1")) { - // 0为输送、立库任务 1 1楼叉车系统 2 2楼1区域AGV系统 3 2楼2区域AGV系统 - if (!StrUtil.equals(task.getAgv_system_type(), "0") - && ObjectUtil.isNotEmpty(task.getAgv_system_type())) { - NDCAgvService ndcAgvService = SpringContextHolder.getBean(NDCAgvService.class); - ndcAgvService.sendAgvInstToNDC(task.getAgv_system_type(), dto); - } else { - // Boolean result = createLkInst(task.getStorage_task_type(),dto); - Resp resp = acsToLiKuService.sendInst(task.getStorage_task_type(), dto); - if (StrUtil.equals(resp.result, "true")) { - dto.setSend_status("1"); - } else { - dto.setSend_status("2"); - } + if (!StrUtil.isEmpty(material_type)) { + map.put("material_type", material_type); } - } - } catch (Exception e) { - dto.setSend_status("2"); - e.printStackTrace(); - log.error(""); - } - - WQLObject wo = WQLObject.getWQLObject("acs_instruction"); - JSONObject json = (JSONObject) JSONObject.toJSON(dto); - - wo.insert(json); - instructions.add(dto); - } - - @Override - public void create2(Instruction dto) throws Exception { - dto = foramte(dto); - String task_code = dto.getTask_code(); - TaskDto task = taskService.findByCodeFromCache(task_code); - - WQLObject instwo = WQLObject.getWQLObject("acs_instruction"); - String currentUsername = SecurityUtils.getCurrentUsername(); - String now = DateUtil.now(); - if (StrUtil.isEmpty(dto.getRoute_plan_code())) { - dto.setRoute_plan_code(task.getRoute_plan_code()); - } - if (StrUtil.isEmpty(dto.getPriority())) { - dto.setPriority(task.getPriority()); - } - if (StrUtil.isEmpty(dto.getInstruction_code())) { - dto.setInstruction_code(CodeUtil.getNewCode("INSTRUCT_NO")); - } - if (StrUtil.isEmpty(dto.getInstruction_id())) { - dto.setInstruction_id(IdUtil.simpleUUID()); - } - if (StrUtil.isEmpty(dto.getIs_send())) { - dto.setIs_send(task.getIs_send()); - } - if (StrUtil.isEmpty(dto.getLink_num())) { - dto.setIs_send(task.getLink_num()); - } - if (task.getTask_type().equals("1") || task.getTask_type().equals("2")) { - dto.setInstruction_type(task.getTask_type()); - } else if (false) { - - } else { - dto.setInstruction_type("3"); - } - - // 起点设备与终点设备相同则为初始指令 - if (StrUtil.equals(task.getStart_device_code(), dto.getStart_device_code())) { - if (!StrUtil.equals(dto.getCompound_inst(), "0") - && StrUtil.equals(task.getCompound_task(), "1")) { - dto.setCompound_inst("1"); - dto.setCompound_inst_data(task.getCompound_task_data()); - } - } - - dto.setCreate_by(currentUsername); - dto.setUpdate_by(currentUsername); - dto.setUpdate_time(now); - dto.setCreate_time(now); - dto.setStart_parent_code(task.getStart_parent_code()); - dto.setNext_parent_code(task.getNext_parent_code()); - - if (ObjectUtil.isNotEmpty(task.getTask_type())) { - dto.setInstruction_type(task.getTask_type()); - } - - DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); - Device startdevice = appService.findDeviceByCode(dto.getStart_device_code()); - Device nextdevice = appService.findDeviceByCode(dto.getNext_device_code()); - - 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(); - String route_plan_code = task.getRoute_plan_code(); - List shortPathsList = - routeLineService.getShortPathLines(start_device_code, next_device_code, route_plan_code); - RouteLineDto route = null; - for (int i = 0; i < shortPathsList.size(); i++) { - RouteLineDto routeLineDto = shortPathsList.get(i); - String route_device = routeLineDto.getDevice_code(); - String route_next_device = routeLineDto.getNext_device_code(); - if (route_device.equals(dto.getStart_device_code()) - && route_next_device.equals(dto.getNext_device_code())) { - route = routeLineDto; - break; + if (!StrUtil.isEmpty(status)) { + map.put("status", status); } - } - if (ObjectUtil.isEmpty(route)) { - throw new BadRequestException("未查询到相关路由!"); - } - if (StrUtil.equals(shortPathsList.get(0).getType(), "1")) { - // 0为输送、立库任务 1 1楼叉车系统 2 2楼1区域AGV系统 3 2楼2区域AGV系统 - if (!StrUtil.equals(task.getAgv_system_type(), "0") - && ObjectUtil.isNotEmpty(task.getAgv_system_type())) { - NDCAgvService ndcAgvService = SpringContextHolder.getBean(NDCAgvService.class); - ndcAgvService.sendAgvInstToNDC(task.getAgv_system_type(), dto); - } else { - // Boolean result = createLkInst(task.getStorage_task_type(),dto); + if (!StrUtil.isEmpty(point_code)) { + map.put("point_code", point_code); } - } - } catch (Exception e) { - dto.setSend_status("2"); - e.printStackTrace(); - } - - WQLObject wo = WQLObject.getWQLObject("acs_instruction"); - JSONObject json = (JSONObject) JSONObject.toJSON(dto); - - wo.insert(json); - instructions.add(dto); - } - - @Override - public void createAgain(Instruction dto) throws Exception { - String task_code = dto.getTask_code(); - TaskDto task = taskService.findByCodeFromCache(task_code); - WQLObject instwo = WQLObject.getWQLObject("acs_instruction"); - String currentUsername = SecurityUtils.getCurrentUsername(); - String now = DateUtil.now(); - if (StrUtil.isEmpty(dto.getRoute_plan_code())) { - dto.setRoute_plan_code(task.getRoute_plan_code()); - } - if (StrUtil.isEmpty(dto.getInstruction_code())) { - dto.setInstruction_code(CodeUtil.getNewCode("INSTRUCT_NO")); - } - if (StrUtil.isEmpty(dto.getInstruction_id())) { - dto.setInstruction_id(IdUtil.simpleUUID()); - } - List shortPathsList = - routeLineService.getShortPathLines( - dto.getStart_device_code(), dto.getNext_device_code(), dto.getRoute_plan_code()); - if (ObjectUtils.isEmpty(shortPathsList)) { - throw new Exception(dto.getStart_device_code() + "->" + dto.getNext_device_code() + "路由不通"); - } - String type = shortPathsList.get(0).getType(); - if (!StrUtil.equals(type, "0")) { - JSONObject instcheckjson = - instwo - .query( - " instruction_status <3 and next_point_code= '" - + dto.getNext_point_code() - + "'" - + " and start_point_code = '" - + dto.getStart_point_code() - + "'" - + " and task_id = '" - + dto.getTask_id() - + "'") - .uniqueResult(0); - if (instcheckjson != null) { - throw new Exception(dto.getTask_code() + ":该任务已存在待完成指令!"); - } - } - - if (!StrUtil.equals(dto.getCompound_inst(), "0") - && StrUtil.equals(task.getCompound_task(), "1")) { - dto.setCompound_inst("1"); - dto.setCompound_inst_data(task.getCompound_task_data()); - } - - dto.setCreate_by(currentUsername); - dto.setUpdate_by(currentUsername); - dto.setUpdate_time(now); - dto.setCreate_time(now); - - WQLObject wo = WQLObject.getWQLObject("acs_instruction"); - JSONObject json = (JSONObject) JSONObject.toJSON(dto); - - wo.insert(json); - - DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); - Device startdevice = appService.findDeviceByCode(dto.getStart_device_code()); - Device nextdevice = appService.findDeviceByCode(dto.getNext_device_code()); - - StandardInspectSiteDeviceDriver standardInspectSiteDeviceDriver; - StandardCoveyorControlWithScannerDeviceDriver standardCoveyorControlWithScannerDeviceDriver; - - if (!ObjectUtils.isEmpty(nextdevice.getExtraValue().get("link_three_lamp"))) { - String lamd_device = nextdevice.getExtraValue().get("link_three_lamp").toString(); - Device lamddevice = appService.findDeviceByCode(lamd_device); - } - - // != 0 为agv任务 - // if(!StrUtil.equals(type,"0")){ - // if (StrUtil.equals(paramService.findByCode(AcsConfig.AGVTYPE).getValue(), "1")) - // { - // agvService.sendAgvInstToMagic(dto); - // } else if (StrUtil.equals(paramService.findByCode(AcsConfig.AGVTYPE).getValue(), - // "2")) { - // agvService.sendAgvInstToNDC(dto); - // } else if (StrUtil.equals(paramService.findByCode(AcsConfig.AGVTYPE).getValue(), - // "3")) { - // agvService.addOrderSequences(dto); - // } - // } - instructions.add(dto); - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void update(Instruction dto) { - String currentUsername = SecurityUtils.getCurrentUsername(); - String now = DateUtil.now(); - dto.setUpdate_time(now); - dto.setUpdate_by(currentUsername); - WQLObject wo = WQLObject.getWQLObject("acs_instruction"); - JSONObject json = (JSONObject) JSONObject.toJSON(dto); - - wo.update(json); - - this.reload(); - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void deleteAll(String[] ids) throws Exception { - for (String instruction_id : ids) { - this.cancel(instruction_id); - } - } - - @Override - public void download(List all, HttpServletResponse response) throws IOException { - List> list = new ArrayList<>(); - for (Instruction instruction : all) { - Map map = new LinkedHashMap<>(); - map.put("任务标识", instruction.getTask_id()); - map.put("指令编码", instruction.getInstruction_code()); - map.put("指令由哪台设备做", instruction.getExecute_device_code()); - map.put("执行状态", instruction.getExecute_status()); - map.put("执行状态描述", instruction.getExecute_status_description()); - map.put("下一条指令由哪台设备做", instruction.getFollow_device_code()); - map.put("指令类型", instruction.getInstruction_type()); - map.put("指令状态", instruction.getInstruction_status()); - map.put("创建类型", instruction.getCreate_type()); - map.put("完成类型", instruction.getFinish_type()); - map.put("优先级", instruction.getPriority()); - map.put("执行编码", instruction.getExecute_code()); - map.put("执行信息", instruction.getExecute_message()); - map.put("起始点位编码", instruction.getStart_point_code()); - map.put("起始设备编码", instruction.getStart_device_code()); - map.put("目标点位编码", instruction.getNext_point_code()); - map.put("目标设备编码", instruction.getNext_device_code()); - map.put("排", instruction.getFrom_x()); - map.put("列", instruction.getFrom_y()); - map.put("层", instruction.getFrom_z()); - map.put("排", instruction.getTo_x()); - map.put("列", instruction.getTo_y()); - map.put("层", instruction.getTo_z()); - map.put("最后一条指令标识", instruction.getLast_instruction_id()); - map.put("是否允许修改", instruction.getCan_modify()); - map.put("备注", instruction.getRemark()); - map.put("是否启用", instruction.getIs_active()); - map.put("是否删除", instruction.getIs_delete()); - map.put("创建者", instruction.getCreate_by()); - map.put("创建时间", instruction.getCreate_time()); - map.put("修改者", instruction.getUpdate_by()); - map.put("修改时间", instruction.getUpdate_time()); - list.add(map); - } - FileUtil.downloadExcel(list, response); - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void finish(String id) { - Instruction entity = this.findById(id); - // if (entity == null) throw new BadRequestException("被删除或无权限,操作失败!"); - String currentUsername = SecurityUtils.getCurrentUsername(); - String now = DateUtil.now(); - entity.setUpdate_time(now); - entity.setUpdate_by(currentUsername); - entity.setInstruction_status("2"); - WQLObject wo = WQLObject.getWQLObject("acs_instruction"); - String instnextdevice = entity.getNext_device_code(); - String insttaskid = entity.getTask_id(); - WQLObject taskwo = WQLObject.getWQLObject("acs_task"); - DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); - Device startdevice = appService.findDeviceByCode(entity.getStart_device_code()); - if (ObjectUtils.isEmpty(startdevice)) { - log.debug("地址对应设备未找到"); - throw new BadRequestException("地址对应设备未找到"); - } - if (instnextdevice.indexOf(".") != -1) { - instnextdevice = instnextdevice.substring(0, instnextdevice.indexOf(".")); - } - Device device = appService.findDeviceByCode(instnextdevice); - if (device == null) { - log.debug("地址对应设备未找到"); - throw new BadRequestException("地址对应设备未找到"); - } - DeviceService deviceService = SpringContextHolder.getBean(DeviceServiceImpl.class); - - JSONObject jo1 = new JSONObject(); - jo1.put("device_code", instnextdevice); - - String start_device_code = entity.getStart_device_code(); - - Device deviceByCode = deviceAppService.findDeviceByCode(start_device_code); - if (deviceByCode == null) { - log.debug("地址对应设备未找到"); - throw new BadRequestException("地址对应设备未找到"); - } - - jo1.put("hasGoodStatus", "1"); - jo1.put("material_type", startdevice.getMaterial_type()); - - jo1.put("quantity", startdevice.getQuantity()); - jo1.put("remark", startdevice.getRemark()); - jo1.put("batch", startdevice.getBatch()); - jo1.put("vehicle_code", entity.getVehicle_code()); - jo1.put("islock", "0"); - jo1.put("barrels_code", startdevice.getBarrels_code()); - jo1.put("cooperate_code", startdevice.getCooperate_code()); - jo1.put("powder_name", startdevice.getPowder_name()); - jo1.put("barrels_status", startdevice.getBarrels_status()); - deviceService.changeDeviceStatus(jo1); - // 如果是无光电的设备 指令完成变更起点、终点状态 - JSONObject jo = new JSONObject(); - jo.put("device_code", entity.getStart_device_code()); - jo.put("hasGoodStatus", "0"); - jo.put("material_type", ""); - jo.put("quantity", ""); - jo.put("remark", ""); - jo.put("batch", ""); - jo.put("islock", "0"); - deviceService.changeDeviceStatus(jo); - - JSONObject json = (JSONObject) JSONObject.toJSON(entity); - wo.update(json); - JSONObject taskjson = taskwo.query("task_id ='" + insttaskid + "'").uniqueResult(0); - TaskDto obj = taskjson.toJavaObject(TaskDto.class); - // =0 则不用再次请求 - if (StrUtil.equals(obj.getRequest_again(), "0")) { - if (StrUtil.equals(obj.getNext_device_code(), instnextdevice)) { - taskService.finish(obj.getTask_id()); - } else { - finishAndCreateNextInst(entity); - } - } - - removeByCodeFromCache(entity.getInstruction_code()); - this.reload(); - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void finish(Instruction dto) { - String now = DateUtil.now(); - dto.setInstruction_status("2"); - WQLObject wo = WQLObject.getWQLObject("acs_instruction"); - JSONObject json = (JSONObject) JSONObject.toJSON(dto); - - wo.update(json); - String instnextdevice = dto.getNext_device_code(); - String insttaskid = dto.getTask_id(); - WQLObject taskwo = WQLObject.getWQLObject("acs_task"); - JSONObject taskjson = taskwo.query("task_id ='" + insttaskid + "'").uniqueResult(0); - TaskDto obj = taskjson.toJavaObject(TaskDto.class); - // =0 则不用再次请求 - if (StrUtil.equals(obj.getRequest_again(), "0")) { - if (StrUtil.equals(obj.getNext_device_code(), instnextdevice)) { - taskService.finish(obj.getTask_id()); - } else { - finishAndCreateNextInst(dto); - } - } - - DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); - DeviceService deviceService = SpringContextHolder.getBean(DeviceServiceImpl.class); - Device device = appService.findDeviceByCode(instnextdevice); - if (device == null) { - log.debug("地址对应设备未找到"); - return; - } - // 如果是无光电的设备 放货任务完成需要变更有货状态 - // StandardOrdinarySiteDeviceDriver standardOrdinarySiteDeviceDriver; - // if(device.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { - // standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) - // device.getDeviceDriver(); - // standardOrdinarySiteDeviceDriver.setMove(2); - // } - - // 如果是无光电的设备 指令完成变更起点、终点状态 - JSONObject jo = new JSONObject(); - jo.put("device_code", dto.getStart_point_code()); - jo.put("hasGoodStatus", "0"); - jo.put("material_type", ""); - jo.put("batch", ""); - deviceService.changeDeviceStatus(jo); - - JSONObject jo1 = new JSONObject(); - jo1.put("device_code", dto.getNext_point_code()); - jo1.put("hasGoodStatus", "1"); - jo1.put("material_type", dto.getMaterial()); - jo1.put("batch", dto.getBatch()); - deviceService.changeDeviceStatus(jo1); - - removeByCodeFromCache(dto.getInstruction_code()); - // this.reload(); - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void finishAndCreateNextInst(Instruction dto) { - dto = foramte(dto); - String device_code = dto.getNext_device_code(); - WQLObject taskwo = WQLObject.getWQLObject("acs_task"); - JSONObject taskjson = taskwo.query("task_id ='" + dto.getTask_id() + "'").uniqueResult(0); - TaskDto acsTask = taskjson.toJavaObject(TaskDto.class); - RouteLineService routeLineService = SpringContextHolder.getBean(RouteLineServiceImpl.class); - List list = - routeLineService.getShortPathLines( - dto.getNext_device_code(), acsTask.getNext_device_code(), acsTask.getRoute_plan_code()); - if (ObjectUtils.isEmpty(list)) { - throw new BadRequestException("路由不通"); - } - RouteLineDto routeLineDto = (RouteLineDto) list.get(0); - String[] path = routeLineDto.getPath().split("->"); - List pathlist = Arrays.asList(path); - int index = 0; - for (int m = 0; m < pathlist.size(); m++) { - if (pathlist.get(m).equals(dto.getNext_device_code())) { - index = m + 1; - break; - } - } - String next_device_code = pathlist.get(index); - String start_device_code = dto.getNext_device_code(); - String start_point_code = null; - String next_point_code = null; - String start_device = - deviceAppService - .findDeviceByCode(start_device_code) - .getDeviceDriverDefination() - .getFitDeviceTypes() - .get(0) - .name(); - String next_device = - deviceAppService - .findDeviceByCode(next_device_code) - .getDeviceDriverDefination() - .getFitDeviceTypes() - .get(0) - .name(); - if (StrUtil.equals("storage", start_device)) { - start_point_code = start_device_code + "-" + acsTask.getFrom_y() + "-" + acsTask.getFrom_z(); - } else { - start_point_code = start_device_code; - } - if (StrUtil.equals("storage", next_device)) { - 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_id(IdUtil.simpleUUID()); - instdto.setRoute_plan_code(acsTask.getRoute_plan_code()); - instdto.setRemark(acsTask.getRemark()); - instdto.setMaterial(acsTask.getMaterial()); - instdto.setQuantity(acsTask.getQuantity()); - instdto.setTask_id(acsTask.getTask_id()); - instdto.setTask_code(acsTask.getTask_code()); - instdto.setVehicle_code(acsTask.getVehicle_code()); - 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(acsTask.getPriority()); - instdto.setInstruction_status("0"); - instdto.setExecute_device_code(dto.getNext_device_code()); - try { - this.create(instdto); - } catch (Exception e) { - e.printStackTrace(); - log.error("完成并创建下一条指令", e.getMessage()); - } - } - - @Override - public void cancel(String id) throws Exception { - // flag= true时取消指令 - boolean flag = false; - Instruction entity = this.findById(id); - if (entity == null) { - throw new BadRequestException("被删除或无权限,操作失败!"); - } - TaskDto task = taskService.findByCodeFromCache(entity.getTask_code()); - if (StrUtil.isEmpty(entity.getRoute_plan_code())) { - entity.setRoute_plan_code(task.getRoute_plan_code()); - } - - // != 0 为agv任务 1=magic 2=NDC 3=XZ,4=ZHEDA - if (StrUtil.equals(paramService.findByCode(AcsConfig.AGVTYPE).getValue(), "1") - && !StrUtil.equals(entity.getSend_status(), "2")) { - MagicAgvService magicAgvService = SpringContextHolder.getBean(MagicAgvService.class); - magicAgvService.deleteAgvInst(entity.getInstruction_code()); - flag = true; - - } else if (StrUtil.equals(paramService.findByCode(AcsConfig.AGVTYPE).getValue(), "2")) { - // NDC agv指令不当场取消指令,需要等agv上报 - if (!StrUtil.isEmpty(entity.getAgv_jobno())) { - ndcAgvService.deleteAgvInstToNDC(entity); - } else { - flag = true; - } - } else if (StrUtil.equals(paramService.findByCode(AcsConfig.AGVTYPE).getValue(), "3") - && !StrUtil.equals(entity.getSend_status(), "2")) { - XianGongAgvService xianGongAgvService = SpringContextHolder.getBean(XianGongAgvService.class); - xianGongAgvService.deleteXZAgvInst(entity.getInstruction_code()); - flag = true; - } else { - flag = true; - } - - if (flag) { - - if (StrUtil.equals(entity.getInstruction_type(), "7")) { - CancelTaskRequest cancelTaskRequest = new CancelTaskRequest(); - cancelTaskRequest.setOrderId(entity.getInstruction_code()); - cancelTaskRequest.setPalletCode(entity.getVehicle_code()); - cancelTaskRequest.setSrcLocation(entity.getStart_point_code()); - cancelTaskRequest.setDestLocation(entity.getNext_point_code()); - // 1 入库,2 出库,3 移库,4 空托盘入库,5 空托盘出库 - int type = 0; - if (StrUtil.equals(task.getStorage_task_type(), "1")) { - type = 1; - } else if (StrUtil.equals(task.getStorage_task_type(), "2")) { - type = 4; - } else if (StrUtil.equals(task.getStorage_task_type(), "3")) { - type = 2; - } else if (StrUtil.equals(task.getStorage_task_type(), "4")) { - type = 5; - } else if (StrUtil.equals(task.getStorage_task_type(), "5")) { - type = 3; + if (!StrUtil.isEmpty(is_over)) { + map.put("is_over", is_over); } - cancelTaskRequest.setTaskType(type); - acsToLiKuService.cancelTask(cancelTaskRequest); - } + map.put("instruction_type", instruction_type); - String currentUsername = SecurityUtils.getCurrentUsername(); - String now = DateUtil.now(); - entity.setUpdate_time(now); - entity.setUpdate_by(currentUsername); - entity.setInstruction_status("3"); - WQLObject wo = WQLObject.getWQLObject("acs_instruction"); - JSONObject json = (JSONObject) JSONObject.toJSON(entity); - wo.update(json); - DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); - DeviceService deviceService = SpringContextHolder.getBean(DeviceServiceImpl.class); - - // 如果是无光电的设备 指令完成变更起点、终点状态 - JSONObject jo = new JSONObject(); - jo.put("device_code", entity.getStart_device_code()); - if (StrUtil.equals(entity.getMaterial(), "1")) { - jo.put("hasGoodStatus", "1"); - } else if (!StrUtil.equals(entity.getMaterial(), "1") - && !StrUtil.isEmpty(entity.getMaterial())) { - jo.put("hasGoodStatus", "2"); - } else { - jo.put("hasGoodStatus", "0"); - } - jo.put("material_type", entity.getMaterial()); - jo.put("batch", entity.getBatch()); - jo.put("islock", "false"); - deviceService.changeDeviceStatus(jo); - - JSONObject jo1 = new JSONObject(); - jo1.put("device_code", entity.getNext_device_code()); - jo.put("hasGoodStatus", "0"); - jo.put("material_type", ""); - jo.put("batch", ""); - jo1.put("islock", "false"); - deviceService.changeDeviceStatus(jo1); - - String instnextdevice = entity.getNext_device_code(); - Device device = appService.findDeviceByCode(instnextdevice); - if (device == null) { - log.debug("地址对应设备未找到"); - return; - } - removeByCodeFromCache(entity.getInstruction_code()); - } - this.reload(); - } - - @Override - public void forceCancel(String id) throws Exception { - // flag= true时取消指令 - boolean flag = false; - Instruction entity = this.findById(id); - if (entity == null) { - throw new BadRequestException("被删除或无权限,操作失败!"); - } - TaskDto task = taskService.findByCodeFromCache(entity.getTask_code()); - if (StrUtil.isEmpty(entity.getRoute_plan_code())) { - entity.setRoute_plan_code(task.getRoute_plan_code()); - } - String currentUsername = SecurityUtils.getCurrentUsername(); - String now = DateUtil.now(); - entity.setUpdate_time(now); - entity.setUpdate_by(currentUsername); - entity.setInstruction_status("3"); - WQLObject wo = WQLObject.getWQLObject("acs_instruction"); - JSONObject json = (JSONObject) JSONObject.toJSON(entity); - wo.update(json); - DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); - DeviceService deviceService = SpringContextHolder.getBean(DeviceServiceImpl.class); - // 如果是无光电的设备 指令完成变更起点、终点状态 - JSONObject jo = new JSONObject(); - jo.put("device_code", entity.getStart_device_code()); - if (StrUtil.equals(entity.getMaterial(), "1")) { - jo.put("hasGoodStatus", "1"); - } else if (!StrUtil.equals(entity.getMaterial(), "1") - && !StrUtil.isEmpty(entity.getMaterial())) { - jo.put("hasGoodStatus", "2"); - } else { - jo.put("hasGoodStatus", "0"); - } - jo.put("material_type", entity.getMaterial()); - jo.put("batch", entity.getBatch()); - jo.put("islock", "false"); - deviceService.changeDeviceStatus(jo); - - JSONObject jo1 = new JSONObject(); - jo1.put("device_code", entity.getNext_device_code()); - jo.put("hasGoodStatus", "0"); - jo.put("material_type", ""); - jo.put("batch", ""); - jo1.put("islock", "false"); - deviceService.changeDeviceStatus(jo1); - - String instnextdevice = entity.getNext_device_code(); - Device device = appService.findDeviceByCode(instnextdevice); - if (device == null) { - log.debug("地址对应设备未找到"); - return; - } - removeByCodeFromCache(entity.getInstruction_code()); - } - - @Override - public void cancelNOSendAgv(String id) throws Exception { - // flag= true时取消指令 - Instruction entity = this.findById(id); - if (entity == null) { - throw new BadRequestException("被删除或无权限,操作失败!"); - } - TaskDto task = taskService.findByCodeFromCache(entity.getTask_code()); - if (StrUtil.isEmpty(entity.getRoute_plan_code())) { - entity.setRoute_plan_code(task.getRoute_plan_code()); + Integer currentPageNumber = page.getPageNumber() + 1; + Integer pageMaxSize = page.getPageSize(); + final JSONObject jo = + WQL.getWO("QINST_QUERY").addParamMap(map).pageQuery(WqlUtil.getHttpContext(page), ""); + JSONArray jsonArray = jo.getJSONArray("content"); + List instructions = jsonArray.toJavaList(Instruction.class); + List instDtoList = + instructions.stream() + .skip((currentPageNumber - 1) * pageMaxSize) + .limit(pageMaxSize) + .collect(Collectors.toList()); + jo.put("content", instDtoList); + jo.put("totalElements", jsonArray.size()); + return jo; } - String currentUsername = SecurityUtils.getCurrentUsername(); - String now = DateUtil.now(); - entity.setUpdate_time(now); - entity.setUpdate_by(currentUsername); - entity.setInstruction_status("3"); - WQLObject wo = WQLObject.getWQLObject("acs_instruction"); - JSONObject json = (JSONObject) JSONObject.toJSON(entity); - wo.update(json); - DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); - DeviceService deviceService = SpringContextHolder.getBean(DeviceServiceImpl.class); - - // 如果是无光电的设备 指令完成变更起点、终点状态 - JSONObject jo = new JSONObject(); - jo.put("device_code", entity.getStart_device_code()); - if (StrUtil.equals(entity.getMaterial(), "1")) { - jo.put("hasGoodStatus", "1"); - } else if (!StrUtil.equals(entity.getMaterial(), "1") - && !StrUtil.isEmpty(entity.getMaterial())) { - jo.put("hasGoodStatus", "2"); - } else { - jo.put("hasGoodStatus", "0"); - } - jo.put("material_type", entity.getMaterial()); - jo.put("batch", entity.getBatch()); - jo.put("islock", "false"); - deviceService.changeDeviceStatus(jo); - - JSONObject jo1 = new JSONObject(); - jo1.put("device_code", entity.getNext_device_code()); - jo.put("hasGoodStatus", "0"); - jo.put("material_type", ""); - jo.put("batch", ""); - jo1.put("islock", "false"); - deviceService.changeDeviceStatus(jo1); - - String instnextdevice = entity.getNext_device_code(); - Device device = appService.findDeviceByCode(instnextdevice); - if (device == null) { - log.debug("地址对应设备未找到"); - return; - } - - removeByCodeFromCache(entity.getInstruction_code()); - } - - @Override - public Instruction findByLinkNumSend(String code) { - synchronized (InstructionServiceImpl.class) { - 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; + @Override + public Map getAll(Map whereJson, Pageable page) { + HashMap map = new HashMap<>(); + map.put("flag", "2"); + String code = (String) whereJson.get("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(code)) { + map.put("code", code); } - } - } - - return null; - } - - @Override - public List findByLinkNum(String code) { - synchronized (InstructionServiceImpl.class) { - 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); + if (!StrUtil.isEmpty(vehicle_code)) { + map.put("vehicle_code", vehicle_code); } - } - return list; - } - } - - @Override - public Instruction findByLinkNumNoSend(String code) { - synchronized (InstructionServiceImpl.class) { - 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; + if (!StrUtil.isEmpty(material_type)) { + map.put("material_type", material_type); } - } - - return null; - } - } - - @Override - public Instruction findByCodeFromCache(String code) { - synchronized (InstructionServiceImpl.class) { - Iterator it = instructions.iterator(); - while (it.hasNext()) { - Instruction inst = it.next(); - if (StrUtil.equals(code, inst.getInstruction_code())) { - return inst; + if (!StrUtil.isEmpty(status)) { + map.put("status", status); } - } - return null; - } - } - - @Override - public Instruction findByBarcodeFromCache(String barcode) { - synchronized (InstructionServiceImpl.class) { - Iterator it = instructions.iterator(); - while (it.hasNext()) { - Instruction inst = it.next(); - if (StrUtil.equals(barcode, inst.getVehicle_code())) { - return inst; + if (!StrUtil.isEmpty(point_code)) { + map.put("point_code", point_code); } - } - return null; - } - } - - @Override - public Instruction findByIdFromCache(String id) { - synchronized (InstructionServiceImpl.class) { - Iterator it = instructions.iterator(); - while (it.hasNext()) { - Instruction inst = it.next(); - if (StrUtil.equals(id, inst.getInstruction_id())) { - return inst; + if (!StrUtil.isEmpty(create_time) && !StrUtil.isEmpty(end_time)) { + map.put("create_time", create_time); + map.put("end_time", end_time); } - } - return null; - } - } - @Override - public Instruction foramte(Instruction inst) { - String start_point_code = inst.getStart_point_code(); - String next_point_code = inst.getNext_point_code(); - String start_device_code = ""; - String next_device_code = ""; - if (StrUtil.contains(start_point_code, ".")) { - String[] point = start_point_code.split("\\."); - start_device_code = point[0]; - } else { - start_device_code = start_point_code; - } - if (StrUtil.contains(next_point_code, ".")) { - String[] point = next_point_code.split("\\."); - next_device_code = point[0]; - } else { - next_device_code = next_point_code; - } - if (StrUtil.contains(start_point_code, "-") && StrUtil.count(start_point_code, "-") == 2) { - String[] start_point = start_point_code.split("-"); - inst.setFrom_x(start_point[0]); - inst.setStart_device_code(start_point[0]); - inst.setFrom_y(start_point[1]); - inst.setFrom_z(start_point[2]); - } else { - String start_device = - deviceAppService - .findDeviceByCode(start_device_code) - .getDeviceDriverDefination() - .getFitDeviceTypes() - .get(0) - .name(); - if (StrUtil.equals("storage", start_device)) { - String[] start_point = start_point_code.split("-"); - inst.setFrom_x(start_point[0]); - inst.setStart_device_code(start_point[0]); - inst.setFrom_y(start_point[1]); - inst.setFrom_z(start_point[2]); - } else { - inst.setStart_device_code(start_device_code); - } + final JSONObject jo = + WQL.getWO("QINST_QUERY") + .addParamMap(map) + .pageQuery(WqlUtil.getHttpContext(page), "create_time desc"); + return jo; } - if (StrUtil.contains(next_point_code, "-") && StrUtil.count(next_point_code, "-") == 2) { - String[] next_point = next_point_code.split("-"); - inst.setTo_x(next_point[0]); - inst.setNext_device_code(next_point[0]); - inst.setTo_y(next_point[1]); - inst.setTo_z(next_point[2]); - } else { - - String next_device = - deviceAppService - .findDeviceByCode(next_device_code) - .getDeviceDriverDefination() - .getFitDeviceTypes() - .get(0) - .name(); - if (StrUtil.equals("storage", next_device)) { - String[] next_point = start_point_code.split("-"); - inst.setTo_x(next_point[0]); - inst.setNext_device_code(next_point[0]); - inst.setTo_y(next_point[1]); - inst.setTo_z(next_point[2]); - } else { - inst.setNext_device_code(next_device_code); - } + @Override + public Map getByTaskId(String id) { + WQLObject wo = WQLObject.getWQLObject("acs_instruction"); + JSONObject jsonObject = wo.query("task_id='" + id + "'").pageResult(); + JSONArray content = jsonObject.getJSONArray("content"); + JSONArray array = new JSONArray(); + for (int i = 0; i < content.size(); i++) { + JSONObject jo = (JSONObject) content.get(i); + JSONObject ins = new JSONObject(); + ins.put("task_id", jo.get("instruction_id")); + ins.put("task_code", jo.get("instruction_code")); + ins.put("task_status", jo.get("instruction_status")); + ins.put("start_point_code", jo.get("start_point_code")); + ins.put("next_point_code", jo.get("next_point_code")); + ins.put("matarial", jo.get("matarial")); + ins.put("remark", jo.get("remark")); + ins.put("create_by", jo.get("create_by")); + ins.put("create_time", jo.get("create_time")); + array.add(ins); + } + jsonObject.put("content", array); + return jsonObject; } - return inst; - } - @Override - public Instruction findByDeviceCodeFromCache(String devicecode) { - synchronized (InstructionServiceImpl.class) { - List instructionList = instructions; - ListUtil.sort( - instructionList, - new Comparator() { - @Override - public int compare(Instruction o1, Instruction o2) { - return o1.getCreate_time().compareTo(o2.getCreate_time()); + @Override + public List queryAll(Map whereJson) { + WQLObject wo = WQLObject.getWQLObject("acs_instruction"); + JSONArray arr = wo.query().getResultJSONArray(0); + List list = arr.toJavaList(Instruction.class); + return list; + } + + @Override + public List queryAll(String whereJson) { + WQLObject wo = WQLObject.getWQLObject("acs_instruction"); + JSONArray arr = wo.query(whereJson, "create_time").getResultJSONArray(0); + List list = arr.toJavaList(Instruction.class); + return list; + } + + @Override + public Instruction findById(String instruction_id) { + WQLObject wo = WQLObject.getWQLObject("acs_instruction"); + JSONObject json = wo.query("instruction_id ='" + instruction_id + "'").uniqueResult(0); + if (ObjectUtil.isNotEmpty(json)) { + final Instruction obj = json.toJavaObject(Instruction.class); + return obj; + } + return null; + } + + @Override + public Instruction findByCode(String code) { + WQLObject wo = WQLObject.getWQLObject("acs_instruction"); + JSONObject json = wo.query("instruction_code ='" + code + "'").uniqueResult(0); + if (ObjectUtil.isEmpty(json)) { + return null; + } + final Instruction obj = json.toJavaObject(Instruction.class); + return obj; + } + + @Override + public Instruction findByTaskcode(String code) { + WQLObject wo = WQLObject.getWQLObject("acs_instruction"); + JSONObject json = wo.query("task_code ='" + code + "'").uniqueResult(0); + final Instruction obj = json.toJavaObject(Instruction.class); + return obj; + } + + @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 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; } - return null; - } - - @Override - public List findAllInstFromCache() { - return instructions; - } - - @Override - public Integer querySameDestinationInst(String devicecode) { - synchronized (InstructionServiceImpl.class) { - 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(".")); + @Override + public Instruction findByTaskid(String id, String wherecaluse) { + if (!StrUtil.isEmpty(wherecaluse)) { + wherecaluse = " and " + wherecaluse; } - if (StrUtil.equals(devicecode, next_code)) { - num = num + 1; + WQLObject wo = WQLObject.getWQLObject("acs_instruction"); + JSONObject json = wo.query("task_id ='" + id + "'" + wherecaluse).uniqueResult(0); + if (ObjectUtil.isNotEmpty(json)) { + return json.toJavaObject(Instruction.class); } - } - - return num; + return null; } - } - @Override - public Integer querySameInstType(String inst_type) { - synchronized (InstructionServiceImpl.class) { - 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; + @Override + public void create(Instruction dto) { + dto = foramte(dto); + String task_code = dto.getTask_code(); + TaskDto task = taskService.findByCodeFromCache(task_code); + + String currentUsername = SecurityUtils.getCurrentUsername(); + String now = DateUtil.now(); + if (StrUtil.isEmpty(dto.getRoute_plan_code())) { + dto.setRoute_plan_code(task.getRoute_plan_code()); } - } - return num; - } - } - - @Override - public Integer querySameOriginInst(String devicecode) { - synchronized (InstructionServiceImpl.class) { - 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.isEmpty(dto.getPriority())) { + dto.setPriority(task.getPriority()); } - if (StrUtil.equals(devicecode, start_code)) { - num = num + 1; + if (StrUtil.isEmpty(dto.getInstruction_code())) { + dto.setInstruction_code(CodeUtil.getNewCode("INSTRUCT_NO")); } - } - return num; - } - } - - @Override - public boolean removeByCodeFromCache(String code) { - synchronized (InstructionServiceImpl.class) { - Iterator iterator = instructions.iterator(); - while (iterator.hasNext()) { - Instruction instruction = iterator.next(); - if (instruction.getInstruction_code().equals(code)) { - iterator.remove(); - return true; + if (StrUtil.isEmpty(dto.getInstruction_id())) { + dto.setInstruction_id(IdUtil.simpleUUID()); } - } - return false; - } - } + if (StrUtil.isEmpty(dto.getIs_send())) { + dto.setIs_send(task.getIs_send()); + } + if (StrUtil.isEmpty(dto.getLink_num())) { + dto.setIs_send(task.getLink_num()); + } + if (task.getTask_type().equals("1") || task.getTask_type().equals("2")) { + dto.setInstruction_type(task.getTask_type()); + } else if (false) { - @Override - public boolean createLkInst(String type, Instruction dto) { - Class var3 = TaskInstructionLock.class; - synchronized (TaskInstructionLock.class) { - // 入库 - AcsToLiKuService acsToLiKuService = SpringContextHolder.getBean(AcsToLiKuService.class); - Resp resp = null; - if (StrUtil.equals(type, "1")) { - InStoreRequest request = new InStoreRequest(); - request.setFloorNo(Integer.parseInt(dto.getTo_z())); - request.setType(1); - request.setPalletCode(dto.getVehicle_code()); - request.setOrderId(dto.getInstruction_code()); - request.setSrcLocation(dto.getStart_point_code()); - request.setDestLocation(dto.getNext_point_code()); - resp = acsToLiKuService.inStore(request); - // 空托入库 - } else if (StrUtil.equals(type, "2")) { - InStoreRequest request = new InStoreRequest(); - request.setFloorNo(Integer.parseInt(dto.getTo_z())); - request.setType(2); - request.setPalletCode(dto.getVehicle_code()); - request.setOrderId(dto.getInstruction_code()); - request.setSrcLocation(dto.getStart_point_code()); - request.setDestLocation(dto.getNext_point_code()); - resp = acsToLiKuService.inStore(request); - // 出库 - } else if (StrUtil.equals(type, "3")) { - OutStoreRequest outStore = new OutStoreRequest(); - BaseStoreRequest baseReq = new BaseStoreRequest(); - List list = new ArrayList(); - baseReq.setOrderId(dto.getInstruction_code()); - baseReq.setSrcLocation(dto.getStart_point_code()); - baseReq.setDestLocation(dto.getNext_point_code()); - baseReq.setFloorNo(Integer.parseInt(dto.getFrom_z())); - baseReq.setPalletCode(dto.getVehicle_code()); - list.add(baseReq); - outStore.setOrderInfos(list); - outStore.setGroupId(dto.getInstruction_code()); - resp = acsToLiKuService.outStore(outStore); - // 空托出库 - } else if (StrUtil.equals(type, "4")) { - EmptyVehicleOutStoreRequest emptyVehicleOutStoreRequest = new EmptyVehicleOutStoreRequest(); - emptyVehicleOutStoreRequest.setOrderId(dto.getInstruction_code()); - emptyVehicleOutStoreRequest.setFloorNo(Integer.parseInt(dto.getFrom_z())); - emptyVehicleOutStoreRequest.setSrcLocation(dto.getStart_point_code()); - emptyVehicleOutStoreRequest.setDestLocation(dto.getNext_point_code()); - emptyVehicleOutStoreRequest.setPalletCode(dto.getVehicle_code()); - resp = acsToLiKuService.emptyVehicleOutStore(emptyVehicleOutStoreRequest); - // 转库 - } else if (StrUtil.equals(type, "5")) { - MoveStoreRequest moveStoreRequest = new MoveStoreRequest(); - BaseStoreRequest baseReq = new BaseStoreRequest(); - List list = new ArrayList(); - baseReq.setFloorNo(Integer.parseInt(dto.getFrom_z())); - baseReq.setPalletCode(dto.getVehicle_code()); - baseReq.setOrderId(dto.getInstruction_code()); - baseReq.setSrcLocation(dto.getStart_point_code()); - baseReq.setDestLocation(dto.getNext_point_code()); - list.add(baseReq); - moveStoreRequest.setGroupId(dto.getInstruction_code()); - moveStoreRequest.setOrderInfos(list); - resp = acsToLiKuService.moveStore(moveStoreRequest); - } - - if (ObjectUtil.isNotEmpty(resp)) { - if (StrUtil.equals(resp.getResult(), "true")) { - dto.setSend_status("1"); } else { - dto.setSend_status("2"); - dto.setRemark(resp.getData().toString()); - return false; + dto.setInstruction_type("3"); } - } else { - dto.setSend_status("2"); - dto.setRemark("ERROR"); - return false; - } - return true; - } - } - /* - * 判断是否为整数 - * @param str 传入的字符串 - * @return 是整数返回true,否则返回false - */ - public static boolean isInteger(String str) { - Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$"); - return pattern.matcher(str).matches(); - } + // 查询是否存在相同指令号 + // if (!StrUtil.isEmpty(dto.getVehicle_code() )) { + // Instruction inst_dto = findByContainer(dto.getVehicle_code()); + // if (inst_dto != null) { + // log.error("存在相同载具号任务,载具号"+dto.getVehicle_code()); + // throw new BadRequestException("存在相同载具号任务!"); + // } + // } + // 起点设备与终点设备相同则为初始指令 + if (StrUtil.equals(task.getStart_device_code(), dto.getStart_device_code())) { + if (!StrUtil.equals(dto.getCompound_inst(), "0") + && StrUtil.equals(task.getCompound_task(), "1")) { + dto.setCompound_inst("1"); + dto.setCompound_inst_data(task.getCompound_task_data()); + } + } - @Override - public void init(String id) { - Instruction inst = this.findById(id); - if (inst == null) { - throw new BadRequestException("指令不存在或已删除"); - } - if ("2".equals(inst.getInstruction_status())) { - throw new BadRequestException("指令已经完成"); + dto.setCreate_by(currentUsername); + dto.setUpdate_by(currentUsername); + dto.setUpdate_time(now); + dto.setCreate_time(now); + dto.setStart_parent_code(task.getStart_parent_code()); + dto.setNext_parent_code(task.getNext_parent_code()); + + if (ObjectUtil.isNotEmpty(task.getTask_type())) { + dto.setInstruction_type(task.getTask_type()); + } + + DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); + Device startdevice = appService.findDeviceByCode(dto.getStart_device_code()); + + 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(); + String route_plan_code = task.getRoute_plan_code(); + List shortPathsList = + routeLineService.getShortPathLines(start_device_code, next_device_code, route_plan_code); + RouteLineDto route = null; + for (int i = 0; i < shortPathsList.size(); i++) { + RouteLineDto routeLineDto = shortPathsList.get(i); + String route_device = routeLineDto.getDevice_code(); + String route_next_device = routeLineDto.getNext_device_code(); + if (route_device.equals(dto.getStart_device_code()) + && route_next_device.equals(dto.getNext_device_code())) { + route = routeLineDto; + break; + } + } + if (ObjectUtil.isEmpty(route)) { + throw new BadRequestException("未查询到相关路由!"); + } + if (StrUtil.equals(shortPathsList.get(0).getType(), "1")) { + // 0为输送、立库任务 1 1楼叉车系统 2 2楼1区域AGV系统 3 2楼2区域AGV系统 + if (!StrUtil.equals(task.getAgv_system_type(), "0") + && ObjectUtil.isNotEmpty(task.getAgv_system_type())) { + NDCAgvService ndcAgvService = SpringContextHolder.getBean(NDCAgvService.class); + ndcAgvService.sendAgvInstToNDC(task.getAgv_system_type(), dto); + } else { + // Boolean result = createLkInst(task.getStorage_task_type(),dto); + Resp resp = acsToLiKuService.sendInst(task.getStorage_task_type(), dto); + if (StrUtil.equals(resp.result, "true")) { + dto.setSend_status("1"); + } else { + dto.setSend_status("2"); + } + } + } + } catch (Exception e) { + dto.setSend_status("2"); + e.printStackTrace(); + log.error(""); + } + + WQLObject wo = WQLObject.getWQLObject("acs_instruction"); + JSONObject json = (JSONObject) JSONObject.toJSON(dto); + + wo.insert(json); + instructions.add(dto); } - Device startDevice = deviceAppService.findDeviceByCode(inst.getStart_device_code()); - DeviceDriver startDeviceDriver = startDevice.getDeviceDriver(); - if (startDeviceDriver instanceof SiemensConveyorDeviceDriver) { - Device nextDevice = deviceAppService.findDeviceByCode(inst.getNext_device_code()); + @Override + public void create2(Instruction dto) throws Exception { + dto = foramte(dto); + String task_code = dto.getTask_code(); + TaskDto task = taskService.findByCodeFromCache(task_code); - List> list = new ArrayList<>(); - Map map = new HashMap<>(); - map.put("code", "to_target"); - map.put("value", nextDevice.getExtraValue().get("address").toString()); - list.add(map); - Map map2 = new HashMap<>(); - map2.put("code", "to_task"); - map2.put("value", inst.getInstruction_code()); - list.add(map2); - Map map3 = new HashMap<>(); - map3.put("code", "to_command"); - map3.put("value", "1"); - list.add(map3); - ((SiemensConveyorDeviceDriver) startDeviceDriver).writing(list); + WQLObject instwo = WQLObject.getWQLObject("acs_instruction"); + String currentUsername = SecurityUtils.getCurrentUsername(); + String now = DateUtil.now(); + if (StrUtil.isEmpty(dto.getRoute_plan_code())) { + dto.setRoute_plan_code(task.getRoute_plan_code()); + } + if (StrUtil.isEmpty(dto.getPriority())) { + dto.setPriority(task.getPriority()); + } + if (StrUtil.isEmpty(dto.getInstruction_code())) { + dto.setInstruction_code(CodeUtil.getNewCode("INSTRUCT_NO")); + } + if (StrUtil.isEmpty(dto.getInstruction_id())) { + dto.setInstruction_id(IdUtil.simpleUUID()); + } + if (StrUtil.isEmpty(dto.getIs_send())) { + dto.setIs_send(task.getIs_send()); + } + if (StrUtil.isEmpty(dto.getLink_num())) { + dto.setIs_send(task.getLink_num()); + } + if (task.getTask_type().equals("1") || task.getTask_type().equals("2")) { + dto.setInstruction_type(task.getTask_type()); + } else if (false) { + + } else { + dto.setInstruction_type("3"); + } + + // 起点设备与终点设备相同则为初始指令 + if (StrUtil.equals(task.getStart_device_code(), dto.getStart_device_code())) { + if (!StrUtil.equals(dto.getCompound_inst(), "0") + && StrUtil.equals(task.getCompound_task(), "1")) { + dto.setCompound_inst("1"); + dto.setCompound_inst_data(task.getCompound_task_data()); + } + } + + dto.setCreate_by(currentUsername); + dto.setUpdate_by(currentUsername); + dto.setUpdate_time(now); + dto.setCreate_time(now); + dto.setStart_parent_code(task.getStart_parent_code()); + dto.setNext_parent_code(task.getNext_parent_code()); + + if (ObjectUtil.isNotEmpty(task.getTask_type())) { + dto.setInstruction_type(task.getTask_type()); + } + + DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); + Device startdevice = appService.findDeviceByCode(dto.getStart_device_code()); + Device nextdevice = appService.findDeviceByCode(dto.getNext_device_code()); + + 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(); + String route_plan_code = task.getRoute_plan_code(); + List shortPathsList = + routeLineService.getShortPathLines(start_device_code, next_device_code, route_plan_code); + RouteLineDto route = null; + for (int i = 0; i < shortPathsList.size(); i++) { + RouteLineDto routeLineDto = shortPathsList.get(i); + String route_device = routeLineDto.getDevice_code(); + String route_next_device = routeLineDto.getNext_device_code(); + if (route_device.equals(dto.getStart_device_code()) + && route_next_device.equals(dto.getNext_device_code())) { + route = routeLineDto; + break; + } + } + if (ObjectUtil.isEmpty(route)) { + throw new BadRequestException("未查询到相关路由!"); + } + if (StrUtil.equals(shortPathsList.get(0).getType(), "1")) { + // 0为输送、立库任务 1 1楼叉车系统 2 2楼1区域AGV系统 3 2楼2区域AGV系统 + if (!StrUtil.equals(task.getAgv_system_type(), "0") + && ObjectUtil.isNotEmpty(task.getAgv_system_type())) { + NDCAgvService ndcAgvService = SpringContextHolder.getBean(NDCAgvService.class); + ndcAgvService.sendAgvInstToNDC(task.getAgv_system_type(), dto); + } else { + // Boolean result = createLkInst(task.getStorage_task_type(),dto); + } + } + } catch (Exception e) { + dto.setSend_status("2"); + e.printStackTrace(); + } + + WQLObject wo = WQLObject.getWQLObject("acs_instruction"); + JSONObject json = (JSONObject) JSONObject.toJSON(dto); + + wo.insert(json); + instructions.add(dto); + } + + @Override + public void createAgain(Instruction dto) throws Exception { + String task_code = dto.getTask_code(); + TaskDto task = taskService.findByCodeFromCache(task_code); + WQLObject instwo = WQLObject.getWQLObject("acs_instruction"); + String currentUsername = SecurityUtils.getCurrentUsername(); + String now = DateUtil.now(); + if (StrUtil.isEmpty(dto.getRoute_plan_code())) { + dto.setRoute_plan_code(task.getRoute_plan_code()); + } + if (StrUtil.isEmpty(dto.getInstruction_code())) { + dto.setInstruction_code(CodeUtil.getNewCode("INSTRUCT_NO")); + } + if (StrUtil.isEmpty(dto.getInstruction_id())) { + dto.setInstruction_id(IdUtil.simpleUUID()); + } + List shortPathsList = + routeLineService.getShortPathLines( + dto.getStart_device_code(), dto.getNext_device_code(), dto.getRoute_plan_code()); + if (ObjectUtils.isEmpty(shortPathsList)) { + throw new Exception(dto.getStart_device_code() + "->" + dto.getNext_device_code() + "路由不通"); + } + String type = shortPathsList.get(0).getType(); + if (!StrUtil.equals(type, "0")) { + JSONObject instcheckjson = + instwo + .query( + " instruction_status <3 and next_point_code= '" + + dto.getNext_point_code() + + "'" + + " and start_point_code = '" + + dto.getStart_point_code() + + "'" + + " and task_id = '" + + dto.getTask_id() + + "'") + .uniqueResult(0); + if (instcheckjson != null) { + throw new Exception(dto.getTask_code() + ":该任务已存在待完成指令!"); + } + } + + if (!StrUtil.equals(dto.getCompound_inst(), "0") + && StrUtil.equals(task.getCompound_task(), "1")) { + dto.setCompound_inst("1"); + dto.setCompound_inst_data(task.getCompound_task_data()); + } + + dto.setCreate_by(currentUsername); + dto.setUpdate_by(currentUsername); + dto.setUpdate_time(now); + dto.setCreate_time(now); + + WQLObject wo = WQLObject.getWQLObject("acs_instruction"); + JSONObject json = (JSONObject) JSONObject.toJSON(dto); + + wo.insert(json); + + DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); + Device startdevice = appService.findDeviceByCode(dto.getStart_device_code()); + Device nextdevice = appService.findDeviceByCode(dto.getNext_device_code()); + + StandardInspectSiteDeviceDriver standardInspectSiteDeviceDriver; + StandardCoveyorControlWithScannerDeviceDriver standardCoveyorControlWithScannerDeviceDriver; + + if (!ObjectUtils.isEmpty(nextdevice.getExtraValue().get("link_three_lamp"))) { + String lamd_device = nextdevice.getExtraValue().get("link_three_lamp").toString(); + Device lamddevice = appService.findDeviceByCode(lamd_device); + } + + // != 0 为agv任务 + // if(!StrUtil.equals(type,"0")){ + // if (StrUtil.equals(paramService.findByCode(AcsConfig.AGVTYPE).getValue(), "1")) + // { + // agvService.sendAgvInstToMagic(dto); + // } else if (StrUtil.equals(paramService.findByCode(AcsConfig.AGVTYPE).getValue(), + // "2")) { + // agvService.sendAgvInstToNDC(dto); + // } else if (StrUtil.equals(paramService.findByCode(AcsConfig.AGVTYPE).getValue(), + // "3")) { + // agvService.addOrderSequences(dto); + // } + // } + instructions.add(dto); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void update(Instruction dto) { + String currentUsername = SecurityUtils.getCurrentUsername(); + String now = DateUtil.now(); + dto.setUpdate_time(now); + dto.setUpdate_by(currentUsername); + WQLObject wo = WQLObject.getWQLObject("acs_instruction"); + JSONObject json = (JSONObject) JSONObject.toJSON(dto); + + wo.update(json); + + this.reload(); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void deleteAll(String[] ids) throws Exception { + for (String instruction_id : ids) { + this.cancel(instruction_id); + } + } + + @Override + public void download(List all, HttpServletResponse response) throws IOException { + List> list = new ArrayList<>(); + for (Instruction instruction : all) { + Map map = new LinkedHashMap<>(); + map.put("任务标识", instruction.getTask_id()); + map.put("指令编码", instruction.getInstruction_code()); + map.put("指令由哪台设备做", instruction.getExecute_device_code()); + map.put("执行状态", instruction.getExecute_status()); + map.put("执行状态描述", instruction.getExecute_status_description()); + map.put("下一条指令由哪台设备做", instruction.getFollow_device_code()); + map.put("指令类型", instruction.getInstruction_type()); + map.put("指令状态", instruction.getInstruction_status()); + map.put("创建类型", instruction.getCreate_type()); + map.put("完成类型", instruction.getFinish_type()); + map.put("优先级", instruction.getPriority()); + map.put("执行编码", instruction.getExecute_code()); + map.put("执行信息", instruction.getExecute_message()); + map.put("起始点位编码", instruction.getStart_point_code()); + map.put("起始设备编码", instruction.getStart_device_code()); + map.put("目标点位编码", instruction.getNext_point_code()); + map.put("目标设备编码", instruction.getNext_device_code()); + map.put("排", instruction.getFrom_x()); + map.put("列", instruction.getFrom_y()); + map.put("层", instruction.getFrom_z()); + map.put("排", instruction.getTo_x()); + map.put("列", instruction.getTo_y()); + map.put("层", instruction.getTo_z()); + map.put("最后一条指令标识", instruction.getLast_instruction_id()); + map.put("是否允许修改", instruction.getCan_modify()); + map.put("备注", instruction.getRemark()); + map.put("是否启用", instruction.getIs_active()); + map.put("是否删除", instruction.getIs_delete()); + map.put("创建者", instruction.getCreate_by()); + map.put("创建时间", instruction.getCreate_time()); + map.put("修改者", instruction.getUpdate_by()); + map.put("修改时间", instruction.getUpdate_time()); + list.add(map); + } + FileUtil.downloadExcel(list, response); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void finish(String id) { + Instruction entity = this.findById(id); + // if (entity == null) throw new BadRequestException("被删除或无权限,操作失败!"); + String currentUsername = SecurityUtils.getCurrentUsername(); + String now = DateUtil.now(); + entity.setUpdate_time(now); + entity.setUpdate_by(currentUsername); + entity.setInstruction_status("2"); + WQLObject wo = WQLObject.getWQLObject("acs_instruction"); + String instnextdevice = entity.getNext_device_code(); + String insttaskid = entity.getTask_id(); + WQLObject taskwo = WQLObject.getWQLObject("acs_task"); + DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); + Device startdevice = appService.findDeviceByCode(entity.getStart_device_code()); + if (ObjectUtils.isEmpty(startdevice)) { + log.debug("地址对应设备未找到"); + throw new BadRequestException("地址对应设备未找到"); + } + if (instnextdevice.indexOf(".") != -1) { + instnextdevice = instnextdevice.substring(0, instnextdevice.indexOf(".")); + } + Device device = appService.findDeviceByCode(instnextdevice); + if (device == null) { + log.debug("地址对应设备未找到"); + throw new BadRequestException("地址对应设备未找到"); + } + DeviceService deviceService = SpringContextHolder.getBean(DeviceServiceImpl.class); + + JSONObject jo1 = new JSONObject(); + jo1.put("device_code", instnextdevice); + + String start_device_code = entity.getStart_device_code(); + + Device deviceByCode = deviceAppService.findDeviceByCode(start_device_code); + if (deviceByCode == null) { + log.debug("地址对应设备未找到"); + throw new BadRequestException("地址对应设备未找到"); + } + + jo1.put("hasGoodStatus", "1"); + jo1.put("material_type", startdevice.getMaterial_type()); + + jo1.put("quantity", startdevice.getQuantity()); + jo1.put("remark", startdevice.getRemark()); + jo1.put("batch", startdevice.getBatch()); + jo1.put("vehicle_code", entity.getVehicle_code()); + jo1.put("islock", "0"); + jo1.put("barrels_code", startdevice.getBarrels_code()); + jo1.put("cooperate_code", startdevice.getCooperate_code()); + jo1.put("powder_name", startdevice.getPowder_name()); + jo1.put("barrels_status", startdevice.getBarrels_status()); + deviceService.changeDeviceStatus(jo1); + // 如果是无光电的设备 指令完成变更起点、终点状态 + JSONObject jo = new JSONObject(); + jo.put("device_code", entity.getStart_device_code()); + jo.put("hasGoodStatus", "0"); + jo.put("material_type", ""); + jo.put("quantity", ""); + jo.put("remark", ""); + jo.put("batch", ""); + jo.put("islock", "0"); + deviceService.changeDeviceStatus(jo); + + JSONObject json = (JSONObject) JSONObject.toJSON(entity); + wo.update(json); + JSONObject taskjson = taskwo.query("task_id ='" + insttaskid + "'").uniqueResult(0); + TaskDto obj = taskjson.toJavaObject(TaskDto.class); + // =0 则不用再次请求 + if (StrUtil.equals(obj.getRequest_again(), "0")) { + if (StrUtil.equals(obj.getNext_device_code(), instnextdevice)) { + taskService.finish(obj.getTask_id()); + } else { + finishAndCreateNextInst(entity); + } + } + + removeByCodeFromCache(entity.getInstruction_code()); + this.reload(); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void finish(Instruction dto) { + String now = DateUtil.now(); + dto.setInstruction_status("2"); + WQLObject wo = WQLObject.getWQLObject("acs_instruction"); + JSONObject json = (JSONObject) JSONObject.toJSON(dto); + + wo.update(json); + String instnextdevice = dto.getNext_device_code(); + String insttaskid = dto.getTask_id(); + WQLObject taskwo = WQLObject.getWQLObject("acs_task"); + JSONObject taskjson = taskwo.query("task_id ='" + insttaskid + "'").uniqueResult(0); + TaskDto obj = taskjson.toJavaObject(TaskDto.class); + // =0 则不用再次请求 + if (StrUtil.equals(obj.getRequest_again(), "0")) { + if (StrUtil.equals(obj.getNext_device_code(), instnextdevice)) { + taskService.finish(obj.getTask_id()); + } else { + finishAndCreateNextInst(dto); + } + } + + DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); + DeviceService deviceService = SpringContextHolder.getBean(DeviceServiceImpl.class); + Device device = appService.findDeviceByCode(instnextdevice); + if (device == null) { + log.debug("地址对应设备未找到"); + return; + } + // 如果是无光电的设备 放货任务完成需要变更有货状态 + // StandardOrdinarySiteDeviceDriver standardOrdinarySiteDeviceDriver; + // if(device.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { + // standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) + // device.getDeviceDriver(); + // standardOrdinarySiteDeviceDriver.setMove(2); + // } + + // 如果是无光电的设备 指令完成变更起点、终点状态 + JSONObject jo = new JSONObject(); + jo.put("device_code", dto.getStart_point_code()); + jo.put("hasGoodStatus", "0"); + jo.put("material_type", ""); + jo.put("batch", ""); + deviceService.changeDeviceStatus(jo); + + JSONObject jo1 = new JSONObject(); + jo1.put("device_code", dto.getNext_point_code()); + jo1.put("hasGoodStatus", "1"); + jo1.put("material_type", dto.getMaterial()); + jo1.put("batch", dto.getBatch()); + deviceService.changeDeviceStatus(jo1); + + removeByCodeFromCache(dto.getInstruction_code()); + // this.reload(); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void finishAndCreateNextInst(Instruction dto) { + dto = foramte(dto); + String device_code = dto.getNext_device_code(); + WQLObject taskwo = WQLObject.getWQLObject("acs_task"); + JSONObject taskjson = taskwo.query("task_id ='" + dto.getTask_id() + "'").uniqueResult(0); + TaskDto acsTask = taskjson.toJavaObject(TaskDto.class); + RouteLineService routeLineService = SpringContextHolder.getBean(RouteLineServiceImpl.class); + List list = + routeLineService.getShortPathLines( + dto.getNext_device_code(), acsTask.getNext_device_code(), acsTask.getRoute_plan_code()); + if (ObjectUtils.isEmpty(list)) { + throw new BadRequestException("路由不通"); + } + RouteLineDto routeLineDto = (RouteLineDto) list.get(0); + String[] path = routeLineDto.getPath().split("->"); + List pathlist = Arrays.asList(path); + int index = 0; + for (int m = 0; m < pathlist.size(); m++) { + if (pathlist.get(m).equals(dto.getNext_device_code())) { + index = m + 1; + break; + } + } + String next_device_code = pathlist.get(index); + String start_device_code = dto.getNext_device_code(); + String start_point_code = null; + String next_point_code = null; + String start_device = + deviceAppService + .findDeviceByCode(start_device_code) + .getDeviceDriverDefination() + .getFitDeviceTypes() + .get(0) + .name(); + String next_device = + deviceAppService + .findDeviceByCode(next_device_code) + .getDeviceDriverDefination() + .getFitDeviceTypes() + .get(0) + .name(); + if (StrUtil.equals("storage", start_device)) { + start_point_code = start_device_code + "-" + acsTask.getFrom_y() + "-" + acsTask.getFrom_z(); + } else { + start_point_code = start_device_code; + } + if (StrUtil.equals("storage", next_device)) { + 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_id(IdUtil.simpleUUID()); + instdto.setRoute_plan_code(acsTask.getRoute_plan_code()); + instdto.setRemark(acsTask.getRemark()); + instdto.setMaterial(acsTask.getMaterial()); + instdto.setQuantity(acsTask.getQuantity()); + instdto.setTask_id(acsTask.getTask_id()); + instdto.setTask_code(acsTask.getTask_code()); + instdto.setVehicle_code(acsTask.getVehicle_code()); + 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(acsTask.getPriority()); + instdto.setInstruction_status("0"); + instdto.setExecute_device_code(dto.getNext_device_code()); + try { + this.create(instdto); + } catch (Exception e) { + e.printStackTrace(); + log.error("完成并创建下一条指令", e.getMessage()); + } + } + + @Override + public void cancel(String id) throws Exception { + // flag= true时取消指令 + boolean flag = false; + Instruction entity = this.findById(id); + if (entity == null) { + throw new BadRequestException("被删除或无权限,操作失败!"); + } + TaskDto task = taskService.findByCodeFromCache(entity.getTask_code()); + if (StrUtil.isEmpty(entity.getRoute_plan_code())) { + entity.setRoute_plan_code(task.getRoute_plan_code()); + } + + // != 0 为agv任务 1=magic 2=NDC 3=XZ,4=ZHEDA + if (StrUtil.equals(paramService.findByCode(AcsConfig.AGVTYPE).getValue(), "1") + && !StrUtil.equals(entity.getSend_status(), "2")) { + MagicAgvService magicAgvService = SpringContextHolder.getBean(MagicAgvService.class); + magicAgvService.deleteAgvInst(entity.getInstruction_code()); + flag = true; + + } else if (StrUtil.equals(paramService.findByCode(AcsConfig.AGVTYPE).getValue(), "2")) { + // NDC agv指令不当场取消指令,需要等agv上报 + if (!StrUtil.isEmpty(entity.getAgv_jobno())) { + ndcAgvService.deleteAgvInstToNDC(entity); + } else { + flag = true; + } + } else if (StrUtil.equals(paramService.findByCode(AcsConfig.AGVTYPE).getValue(), "3") + && !StrUtil.equals(entity.getSend_status(), "2")) { + XianGongAgvService xianGongAgvService = SpringContextHolder.getBean(XianGongAgvService.class); + xianGongAgvService.deleteXZAgvInst(entity.getInstruction_code()); + flag = true; + } else { + flag = true; + } + + if (flag) { + + if (StrUtil.equals(entity.getInstruction_type(), "7")) { + CancelTaskRequest cancelTaskRequest = new CancelTaskRequest(); + cancelTaskRequest.setOrderId(entity.getInstruction_code()); + cancelTaskRequest.setPalletCode(entity.getVehicle_code()); + cancelTaskRequest.setSrcLocation(entity.getStart_point_code()); + cancelTaskRequest.setDestLocation(entity.getNext_point_code()); + // 1 入库,2 出库,3 移库,4 空托盘入库,5 空托盘出库 + int type = 0; + if (StrUtil.equals(task.getStorage_task_type(), "1")) { + type = 1; + } else if (StrUtil.equals(task.getStorage_task_type(), "2")) { + type = 4; + } else if (StrUtil.equals(task.getStorage_task_type(), "3")) { + type = 2; + } else if (StrUtil.equals(task.getStorage_task_type(), "4")) { + type = 5; + } else if (StrUtil.equals(task.getStorage_task_type(), "5")) { + type = 3; + } + cancelTaskRequest.setTaskType(type); + acsToLiKuService.cancelTask(cancelTaskRequest); + } + + String currentUsername = SecurityUtils.getCurrentUsername(); + String now = DateUtil.now(); + entity.setUpdate_time(now); + entity.setUpdate_by(currentUsername); + entity.setInstruction_status("3"); + WQLObject wo = WQLObject.getWQLObject("acs_instruction"); + JSONObject json = (JSONObject) JSONObject.toJSON(entity); + wo.update(json); + DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); + DeviceService deviceService = SpringContextHolder.getBean(DeviceServiceImpl.class); + + // 如果是无光电的设备 指令完成变更起点、终点状态 + JSONObject jo = new JSONObject(); + jo.put("device_code", entity.getStart_device_code()); + if (StrUtil.equals(entity.getMaterial(), "1")) { + jo.put("hasGoodStatus", "1"); + } else if (!StrUtil.equals(entity.getMaterial(), "1") + && !StrUtil.isEmpty(entity.getMaterial())) { + jo.put("hasGoodStatus", "2"); + } else { + jo.put("hasGoodStatus", "0"); + } + jo.put("material_type", entity.getMaterial()); + jo.put("batch", entity.getBatch()); + jo.put("islock", "false"); + deviceService.changeDeviceStatus(jo); + + JSONObject jo1 = new JSONObject(); + jo1.put("device_code", entity.getNext_device_code()); + jo.put("hasGoodStatus", "0"); + jo.put("material_type", ""); + jo.put("batch", ""); + jo1.put("islock", "false"); + deviceService.changeDeviceStatus(jo1); + + String instnextdevice = entity.getNext_device_code(); + Device device = appService.findDeviceByCode(instnextdevice); + if (device == null) { + log.debug("地址对应设备未找到"); + return; + } + removeByCodeFromCache(entity.getInstruction_code()); + } + this.reload(); + } + + @Override + public void forceCancel(String id) throws Exception { + // flag= true时取消指令 + boolean flag = false; + Instruction entity = this.findById(id); + if (entity == null) { + throw new BadRequestException("被删除或无权限,操作失败!"); + } + TaskDto task = taskService.findByCodeFromCache(entity.getTask_code()); + if (StrUtil.isEmpty(entity.getRoute_plan_code())) { + entity.setRoute_plan_code(task.getRoute_plan_code()); + } + String currentUsername = SecurityUtils.getCurrentUsername(); + String now = DateUtil.now(); + entity.setUpdate_time(now); + entity.setUpdate_by(currentUsername); + entity.setInstruction_status("3"); + WQLObject wo = WQLObject.getWQLObject("acs_instruction"); + JSONObject json = (JSONObject) JSONObject.toJSON(entity); + wo.update(json); + DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); + DeviceService deviceService = SpringContextHolder.getBean(DeviceServiceImpl.class); + // 如果是无光电的设备 指令完成变更起点、终点状态 + JSONObject jo = new JSONObject(); + jo.put("device_code", entity.getStart_device_code()); + if (StrUtil.equals(entity.getMaterial(), "1")) { + jo.put("hasGoodStatus", "1"); + } else if (!StrUtil.equals(entity.getMaterial(), "1") + && !StrUtil.isEmpty(entity.getMaterial())) { + jo.put("hasGoodStatus", "2"); + } else { + jo.put("hasGoodStatus", "0"); + } + jo.put("material_type", entity.getMaterial()); + jo.put("batch", entity.getBatch()); + jo.put("islock", "false"); + deviceService.changeDeviceStatus(jo); + + JSONObject jo1 = new JSONObject(); + jo1.put("device_code", entity.getNext_device_code()); + jo.put("hasGoodStatus", "0"); + jo.put("material_type", ""); + jo.put("batch", ""); + jo1.put("islock", "false"); + deviceService.changeDeviceStatus(jo1); + + String instnextdevice = entity.getNext_device_code(); + Device device = appService.findDeviceByCode(instnextdevice); + if (device == null) { + log.debug("地址对应设备未找到"); + return; + } + removeByCodeFromCache(entity.getInstruction_code()); + } + + @Override + public void cancelNOSendAgv(String id) throws Exception { + // flag= true时取消指令 + Instruction entity = this.findById(id); + if (entity == null) { + throw new BadRequestException("被删除或无权限,操作失败!"); + } + TaskDto task = taskService.findByCodeFromCache(entity.getTask_code()); + if (StrUtil.isEmpty(entity.getRoute_plan_code())) { + entity.setRoute_plan_code(task.getRoute_plan_code()); + } + + String currentUsername = SecurityUtils.getCurrentUsername(); + String now = DateUtil.now(); + entity.setUpdate_time(now); + entity.setUpdate_by(currentUsername); + entity.setInstruction_status("3"); + WQLObject wo = WQLObject.getWQLObject("acs_instruction"); + JSONObject json = (JSONObject) JSONObject.toJSON(entity); + wo.update(json); + DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); + DeviceService deviceService = SpringContextHolder.getBean(DeviceServiceImpl.class); + + // 如果是无光电的设备 指令完成变更起点、终点状态 + JSONObject jo = new JSONObject(); + jo.put("device_code", entity.getStart_device_code()); + if (StrUtil.equals(entity.getMaterial(), "1")) { + jo.put("hasGoodStatus", "1"); + } else if (!StrUtil.equals(entity.getMaterial(), "1") + && !StrUtil.isEmpty(entity.getMaterial())) { + jo.put("hasGoodStatus", "2"); + } else { + jo.put("hasGoodStatus", "0"); + } + jo.put("material_type", entity.getMaterial()); + jo.put("batch", entity.getBatch()); + jo.put("islock", "false"); + deviceService.changeDeviceStatus(jo); + + JSONObject jo1 = new JSONObject(); + jo1.put("device_code", entity.getNext_device_code()); + jo.put("hasGoodStatus", "0"); + jo.put("material_type", ""); + jo.put("batch", ""); + jo1.put("islock", "false"); + deviceService.changeDeviceStatus(jo1); + + String instnextdevice = entity.getNext_device_code(); + Device device = appService.findDeviceByCode(instnextdevice); + if (device == null) { + log.debug("地址对应设备未找到"); + return; + } + + removeByCodeFromCache(entity.getInstruction_code()); + } + + @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; + } + } + + 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); + } + } + 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; + } + } + + 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; + } + } + 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; + } + } + 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; + } + } + return null; + } + + @Override + public Instruction foramte(Instruction inst) { + String start_point_code = inst.getStart_point_code(); + String next_point_code = inst.getNext_point_code(); + String start_device_code = ""; + String next_device_code = ""; + if (StrUtil.contains(start_point_code, ".")) { + String[] point = start_point_code.split("\\."); + start_device_code = point[0]; + } else { + start_device_code = start_point_code; + } + if (StrUtil.contains(next_point_code, ".")) { + String[] point = next_point_code.split("\\."); + next_device_code = point[0]; + } else { + next_device_code = next_point_code; + } + if (StrUtil.contains(start_point_code, "-") && StrUtil.count(start_point_code, "-") == 2) { + String[] start_point = start_point_code.split("-"); + inst.setFrom_x(start_point[0]); + inst.setStart_device_code(start_point[0]); + inst.setFrom_y(start_point[1]); + inst.setFrom_z(start_point[2]); + } else { + String start_device = + deviceAppService + .findDeviceByCode(start_device_code) + .getDeviceDriverDefination() + .getFitDeviceTypes() + .get(0) + .name(); + if (StrUtil.equals("storage", start_device)) { + String[] start_point = start_point_code.split("-"); + inst.setFrom_x(start_point[0]); + inst.setStart_device_code(start_point[0]); + inst.setFrom_y(start_point[1]); + inst.setFrom_z(start_point[2]); + } else { + inst.setStart_device_code(start_device_code); + } + } + + if (StrUtil.contains(next_point_code, "-") && StrUtil.count(next_point_code, "-") == 2) { + String[] next_point = next_point_code.split("-"); + inst.setTo_x(next_point[0]); + inst.setNext_device_code(next_point[0]); + inst.setTo_y(next_point[1]); + inst.setTo_z(next_point[2]); + } else { + + String next_device = + deviceAppService + .findDeviceByCode(next_device_code) + .getDeviceDriverDefination() + .getFitDeviceTypes() + .get(0) + .name(); + if (StrUtil.equals("storage", next_device)) { + String[] next_point = start_point_code.split("-"); + inst.setTo_x(next_point[0]); + inst.setNext_device_code(next_point[0]); + inst.setTo_y(next_point[1]); + inst.setTo_z(next_point[2]); + } else { + inst.setNext_device_code(next_device_code); + } + } + return inst; + } + + @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; + } + } + + return null; + } + + @Override + public List findAllInstFromCache() { + return instructions; + } + + @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; + } + } + + 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; + } + } + 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; + } + } + return num; + } + + @Override + public boolean removeByCodeFromCache(String code) { + CopyOnWriteArrayList instructions = (CopyOnWriteArrayList) this.instructions; + instructions.removeIf((instruction) -> { + instruction.getInstruction_code().equals(code); + return true; + }); +// while (iterator.hasNext()) { +// Instruction instruction = iterator.next(); +// if (instruction.getInstruction_code().equals(code)) { +// iterator.remove(); +// return true; +// } +// } + return true; + } + + @Override + public boolean createLkInst(String type, Instruction dto) { + Class var3 = TaskInstructionLock.class; + synchronized (TaskInstructionLock.class) { + // 入库 + AcsToLiKuService acsToLiKuService = SpringContextHolder.getBean(AcsToLiKuService.class); + Resp resp = null; + if (StrUtil.equals(type, "1")) { + InStoreRequest request = new InStoreRequest(); + request.setFloorNo(Integer.parseInt(dto.getTo_z())); + request.setType(1); + request.setPalletCode(dto.getVehicle_code()); + request.setOrderId(dto.getInstruction_code()); + request.setSrcLocation(dto.getStart_point_code()); + request.setDestLocation(dto.getNext_point_code()); + resp = acsToLiKuService.inStore(request); + // 空托入库 + } else if (StrUtil.equals(type, "2")) { + InStoreRequest request = new InStoreRequest(); + request.setFloorNo(Integer.parseInt(dto.getTo_z())); + request.setType(2); + request.setPalletCode(dto.getVehicle_code()); + request.setOrderId(dto.getInstruction_code()); + request.setSrcLocation(dto.getStart_point_code()); + request.setDestLocation(dto.getNext_point_code()); + resp = acsToLiKuService.inStore(request); + // 出库 + } else if (StrUtil.equals(type, "3")) { + OutStoreRequest outStore = new OutStoreRequest(); + BaseStoreRequest baseReq = new BaseStoreRequest(); + List list = new ArrayList(); + baseReq.setOrderId(dto.getInstruction_code()); + baseReq.setSrcLocation(dto.getStart_point_code()); + baseReq.setDestLocation(dto.getNext_point_code()); + baseReq.setFloorNo(Integer.parseInt(dto.getFrom_z())); + baseReq.setPalletCode(dto.getVehicle_code()); + list.add(baseReq); + outStore.setOrderInfos(list); + outStore.setGroupId(dto.getInstruction_code()); + resp = acsToLiKuService.outStore(outStore); + // 空托出库 + } else if (StrUtil.equals(type, "4")) { + EmptyVehicleOutStoreRequest emptyVehicleOutStoreRequest = new EmptyVehicleOutStoreRequest(); + emptyVehicleOutStoreRequest.setOrderId(dto.getInstruction_code()); + emptyVehicleOutStoreRequest.setFloorNo(Integer.parseInt(dto.getFrom_z())); + emptyVehicleOutStoreRequest.setSrcLocation(dto.getStart_point_code()); + emptyVehicleOutStoreRequest.setDestLocation(dto.getNext_point_code()); + emptyVehicleOutStoreRequest.setPalletCode(dto.getVehicle_code()); + resp = acsToLiKuService.emptyVehicleOutStore(emptyVehicleOutStoreRequest); + // 转库 + } else if (StrUtil.equals(type, "5")) { + MoveStoreRequest moveStoreRequest = new MoveStoreRequest(); + BaseStoreRequest baseReq = new BaseStoreRequest(); + List list = new ArrayList(); + baseReq.setFloorNo(Integer.parseInt(dto.getFrom_z())); + baseReq.setPalletCode(dto.getVehicle_code()); + baseReq.setOrderId(dto.getInstruction_code()); + baseReq.setSrcLocation(dto.getStart_point_code()); + baseReq.setDestLocation(dto.getNext_point_code()); + list.add(baseReq); + moveStoreRequest.setGroupId(dto.getInstruction_code()); + moveStoreRequest.setOrderInfos(list); + resp = acsToLiKuService.moveStore(moveStoreRequest); + } + + if (ObjectUtil.isNotEmpty(resp)) { + if (StrUtil.equals(resp.getResult(), "true")) { + dto.setSend_status("1"); + } else { + dto.setSend_status("2"); + dto.setRemark(resp.getData().toString()); + return false; + } + } else { + dto.setSend_status("2"); + dto.setRemark("ERROR"); + return false; + } + return true; + } + } + + /* + * 判断是否为整数 + * @param str 传入的字符串 + * @return 是整数返回true,否则返回false + */ + public static boolean isInteger(String str) { + Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$"); + return pattern.matcher(str).matches(); + } + + @Override + public void init(String id) { + Instruction inst = this.findById(id); + if (inst == null) { + throw new BadRequestException("指令不存在或已删除"); + } + if ("2".equals(inst.getInstruction_status())) { + throw new BadRequestException("指令已经完成"); + } + + Device startDevice = deviceAppService.findDeviceByCode(inst.getStart_device_code()); + DeviceDriver startDeviceDriver = startDevice.getDeviceDriver(); + if (startDeviceDriver instanceof SiemensConveyorDeviceDriver) { + Device nextDevice = deviceAppService.findDeviceByCode(inst.getNext_device_code()); + + List> list = new ArrayList<>(); + Map map = new HashMap<>(); + map.put("code", "to_target"); + map.put("value", nextDevice.getExtraValue().get("address").toString()); + list.add(map); + Map map2 = new HashMap<>(); + map2.put("code", "to_task"); + map2.put("value", inst.getInstruction_code()); + list.add(map2); + Map map3 = new HashMap<>(); + map3.put("code", "to_command"); + map3.put("value", "1"); + list.add(map3); + ((SiemensConveyorDeviceDriver) startDeviceDriver).writing(list); + } } - } } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/log/LokiLogAspect.java b/acs/nladmin-system/src/main/java/org/nl/acs/log/LokiLogAspect.java index d41679d25..7caa9b538 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/log/LokiLogAspect.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/log/LokiLogAspect.java @@ -37,7 +37,7 @@ public class LokiLogAspect { * @return */ @Around("operatorLog()") - public synchronized Object around(ProceedingJoinPoint pjp) throws Throwable { + public Object around(ProceedingJoinPoint pjp) throws Throwable { // ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); // HttpServletRequest request = attributes.getRequest(); // HttpServletResponse response = attributes.getResponse(); diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/task/rest/TaskController.java b/acs/nladmin-system/src/main/java/org/nl/acs/task/rest/TaskController.java index e2089997c..9b37cfca3 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/task/rest/TaskController.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/task/rest/TaskController.java @@ -2,6 +2,7 @@ package org.nl.acs.task.rest; +import cn.dev33.satoken.annotation.SaIgnore; import com.alibaba.fastjson.JSONObject; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -46,6 +47,7 @@ public class TaskController { @GetMapping("/reload") @Log("数据同步") @ApiOperation("数据同步") + @SaIgnore //@PreAuthorize("@el.check('task:list')") public ResponseEntity reload() { taskService.reload(); @@ -146,4 +148,13 @@ public class TaskController { return new ResponseEntity<>(HttpStatus.CREATED); } + @SaIgnore + @Log("查询缓存所有任务") + @ApiOperation("查询缓存任务") + @PostMapping(value = "/findAllTaskFromCache") + public ResponseEntity findAllTaskFromCache() { + return new ResponseEntity<>(taskService.findAllTaskFromCache(), HttpStatus.OK); + } + + } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/task/service/TaskService.java b/acs/nladmin-system/src/main/java/org/nl/acs/task/service/TaskService.java index ee6ab66cd..2acbb63fb 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/task/service/TaskService.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/task/service/TaskService.java @@ -313,4 +313,6 @@ public interface TaskService { * @return */ Integer querySameDeviceReadyTask(String start_device,String next_device,String status); + + } 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 4960b2c97..877d6e05e 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 @@ -10,6 +10,7 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import lombok.RequiredArgsConstructor; +import lombok.Synchronized; import lombok.extern.slf4j.Slf4j; import org.nl.acs.AcsConfig; import org.nl.acs.agv.server.XianGongAgvService; @@ -88,7 +89,9 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { } public synchronized void reload() { - this.tasks = this.queryAll("task_status <2 and is_delete =0 order by create_time"); + List list = this.queryAll("task_status <2 and is_delete =0 order by create_time"); + + tasks = new CopyOnWriteArrayList<>(list); } @Override @@ -295,7 +298,6 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { @Override public List queryTaskByDeviceCode(String device_code) { - synchronized (TaskServiceImpl.class) { List list = new ArrayList<>(); Iterator iterator = tasks.iterator(); while (iterator.hasNext()) { @@ -306,12 +308,10 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { } } return list; - } } @Override public List queryTaskByStartDeviceCode(String start_device_code) { - synchronized (TaskServiceImpl.class) { List list = new ArrayList<>(); Iterator iterator = tasks.iterator(); while (iterator.hasNext()) { @@ -326,12 +326,10 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { } } return list; - } } @Override public List queryTaskByBackDeviceCode(String back_start_device_code) { - synchronized (TaskServiceImpl.class) { List list = new ArrayList<>(); Iterator iterator = tasks.iterator(); while (iterator.hasNext()) { @@ -345,12 +343,10 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { } } return list; - } } @Override public List queryTaskByDeviceCodeAndStatus(String device_code) { - synchronized (TaskServiceImpl.class) { List list = new ArrayList<>(); Iterator iterator = tasks.iterator(); while (iterator.hasNext()) { @@ -364,11 +360,9 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { } } return list; - } } public List queryTaskByStartAndIntStatus(String head_start_device_code) { - synchronized (TaskServiceImpl.class) { List list = new ArrayList<>(); Iterator iterator = tasks.iterator(); while (iterator.hasNext()) { @@ -386,11 +380,9 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { } } return list; - } } public List queryTaskByNextAndIntStatus(String back_start_device_code) { - synchronized (TaskServiceImpl.class) { List list = new ArrayList<>(); Iterator iterator = tasks.iterator(); while (iterator.hasNext()) { @@ -407,7 +399,6 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { } } return list; - } } @Override @@ -533,7 +524,9 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { JSONObject json = (JSONObject) JSONObject.toJSON(dto); wo.insert(json); - tasks.add(dto); + synchronized(TaskServiceImpl.class){ + tasks.add(dto); + } } /** @@ -672,18 +665,20 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { wo.update(json); - synchronized (TaskServiceImpl.class) { Iterator iterator = tasks.iterator(); - while (iterator.hasNext()) { - TaskDto task = iterator.next(); - if (task.getTask_code().equals(dto.getTask_code())) { - iterator.remove(); - } - } +// while (iterator.hasNext()) { +// TaskDto task = iterator.next(); +// if (task.getTask_code().equals(dto.getTask_code())) { +// iterator.remove(); +// } +// } + + + 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")) { @@ -804,6 +799,7 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { 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()); @@ -921,15 +917,17 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { JSONObject json = (JSONObject) JSONObject.toJSON(entity); wo.update(json); - synchronized (TaskServiceImpl.class){ - Iterator it = tasks.iterator(); - // 清理缓存 - while (it.hasNext()) { - TaskDto taskDto = it.next(); - if (taskDto.getTask_id().equals(id)) { - tasks.remove(taskDto); - } - }} +// synchronized (TaskServiceImpl.class){ +// Iterator it = tasks.iterator(); +// // 清理缓存 +// while (it.hasNext()) { +// TaskDto taskDto = it.next(); +// if (taskDto.getTask_id().equals(id)) { +// tasks.remove(taskDto); +// } +// }} + + removeByCodeFromCache(entity.getTask_code()); // 判断是否为WMS下发的任务,如果是反馈任务状态给WMS String hasWms = paramService.findByCode(AcsConfig.HASWMS).getValue(); @@ -1271,17 +1269,12 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { @Override public boolean removeByCodeFromCache(String code) { - synchronized (TaskServiceImpl.class) { - Iterator iterator = tasks.iterator(); - while (iterator.hasNext()) { - TaskDto task = iterator.next(); - if (task.getTask_code().equals(code)) { - iterator.remove(); - return true; - } - } + CopyOnWriteArrayList taskDtos = (CopyOnWriteArrayList) this.tasks; + taskDtos.removeIf((task) -> { + task.getTask_code().equals(code); + return true; + }); return false; - } } @Override @@ -1290,7 +1283,6 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { } public TaskDto findByContainer(String container_code) { - synchronized (TaskServiceImpl.class) { Iterator var3 = tasks.iterator(); while (var3.hasNext()) { @@ -1301,11 +1293,9 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { } return null; - } } public TaskDto findByCodeFromCache(String task_code) { - synchronized (TaskServiceImpl.class) { Iterator var3 = tasks.iterator(); while (var3.hasNext()) { @@ -1315,12 +1305,10 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { } } return null; - } } @Override public TaskDto findByNextCode(String device_code) { - synchronized (TaskServiceImpl.class) { Iterator var3 = tasks.iterator(); while (var3.hasNext()) { @@ -1330,7 +1318,6 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { } } return null; - } } @Override @@ -1345,7 +1332,6 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { @Override public TaskDto findByStartCodeAndReady(String device_code) { - synchronized (TaskServiceImpl.class) { Iterator var3 = tasks.iterator(); while (var3.hasNext()) { @@ -1359,12 +1345,10 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { } } return null; - } } @Override public TaskDto findByStartCode(String device_code) { - synchronized (TaskServiceImpl.class) { Iterator var3 = tasks.iterator(); while (var3.hasNext()) { @@ -1374,7 +1358,6 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { } } return null; - } } @Override @@ -1516,16 +1499,8 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { @Override public void updateByCodeFromCache(TaskDto dto) { - synchronized (TaskServiceImpl.class) { - Iterator iterator = tasks.iterator(); - while (iterator.hasNext()) { - TaskDto task = iterator.next(); - if (task.getTask_code().equals(dto.getTask_code())) { - iterator.remove(); - } - } - tasks.add(dto); - } + removeByCodeFromCache(dto.getTask_code()); + tasks.add(dto); } @Override @@ -1571,7 +1546,6 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { @Override public Integer querySameDeviceReadyTask(String start_device, String next_device, String status) { - synchronized (TaskServiceImpl.class) { int num = 0; Iterator iterator = tasks.iterator(); while (iterator.hasNext()) { @@ -1584,12 +1558,11 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { } return num; - } } + @Override public Integer querySameTaskByType(String taskType) { - synchronized (TaskServiceImpl.class) { int num = 0; Iterator iterator = tasks.iterator(); while (iterator.hasNext()) { @@ -1600,12 +1573,10 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { } return num; - } } @Override public Integer querySameOriginTask(String code) { - synchronized (TaskServiceImpl.class) { int num = 0; Iterator iterator = tasks.iterator(); while (iterator.hasNext()) { @@ -1616,12 +1587,10 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { } return num; - } } @Override public Integer querySameDestinationTask(String code) { - synchronized (TaskServiceImpl.class) { int num = 0; Iterator iterator = tasks.iterator(); while (iterator.hasNext()) { @@ -1633,5 +1602,4 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { return num; } - } } diff --git a/acs/nladmin-system/src/main/java/org/nl/common/utils/IdUtil.java b/acs/nladmin-system/src/main/java/org/nl/common/utils/IdUtil.java new file mode 100644 index 000000000..41f47c0b4 --- /dev/null +++ b/acs/nladmin-system/src/main/java/org/nl/common/utils/IdUtil.java @@ -0,0 +1,11 @@ +package org.nl.common.utils; + +public class IdUtil { + public static Long getLongId() { + return cn.hutool.core.util.IdUtil.getSnowflake(1, 1).nextId(); + } + + public static String getStringId() { + return String.valueOf(IdUtil.getLongId()); + } +} diff --git a/acs/nladmin-system/src/main/java/org/nl/modules/logging/InterfaceLogType.java b/acs/nladmin-system/src/main/java/org/nl/modules/logging/InterfaceLogType.java new file mode 100644 index 000000000..41c489623 --- /dev/null +++ b/acs/nladmin-system/src/main/java/org/nl/modules/logging/InterfaceLogType.java @@ -0,0 +1,24 @@ +package org.nl.modules.logging; + +/** + * @author: lyd + * @description: + * @Date: 2022/10/11 + */ +public enum InterfaceLogType { + DEFAULT("默认"), + LMS_TO_ACS("LMS请求ACS"), + ACS_TO_LMS("ACS请求LMS"), + ACS_TO_LK("ACS请求立库"), + LK_TO_ACS("立库请求ACS"); + + private String desc; + + InterfaceLogType(String desc) { + this.desc=desc; + } + + public String getDesc() { + return desc; + } +} diff --git a/acs/nladmin-system/src/main/java/org/nl/modules/logging/annotation/Log.java b/acs/nladmin-system/src/main/java/org/nl/modules/logging/annotation/Log.java index e14ae508e..98984194a 100644 --- a/acs/nladmin-system/src/main/java/org/nl/modules/logging/annotation/Log.java +++ b/acs/nladmin-system/src/main/java/org/nl/modules/logging/annotation/Log.java @@ -15,6 +15,8 @@ */ package org.nl.modules.logging.annotation; +import org.nl.modules.logging.InterfaceLogType; + import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -28,4 +30,33 @@ import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) public @interface Log { String value() default ""; + + /** + * 是否打印到日志文件 + * + * @return + */ + boolean isPrintToLogFile() default false; + + + /** + * 是否插入操作日志表 + * + * @return + */ + boolean isAddLogTable() default true; + + /** + * 是否接口日志 + * + * @return + */ + boolean isInterfaceLog() default false; + + /** + * 接口日志类型 + * + * @return + */ + InterfaceLogType interfaceLogType() default InterfaceLogType.DEFAULT; } diff --git a/acs/nladmin-system/src/main/java/org/nl/modules/logging/aspect/LogAspect.java b/acs/nladmin-system/src/main/java/org/nl/modules/logging/aspect/LogAspect.java index 24e8e05f4..78b69b45d 100644 --- a/acs/nladmin-system/src/main/java/org/nl/modules/logging/aspect/LogAspect.java +++ b/acs/nladmin-system/src/main/java/org/nl/modules/logging/aspect/LogAspect.java @@ -15,22 +15,23 @@ */ package org.nl.modules.logging.aspect; +import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.json.JSONUtil; +import com.alibaba.fastjson.JSONObject; import lombok.extern.slf4j.Slf4j; -import org.aspectj.lang.JoinPoint; import org.aspectj.lang.ProceedingJoinPoint; -import org.aspectj.lang.annotation.AfterThrowing; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Pointcut; import org.aspectj.lang.reflect.MethodSignature; +import org.nl.common.utils.IdUtil; import org.nl.modules.common.utils.RequestHolder; -import org.nl.modules.common.utils.SecurityUtils; import org.nl.modules.common.utils.StringUtils; import org.nl.modules.common.utils.ThrowableUtil; import org.nl.modules.logging.domain.Log; import org.nl.modules.logging.service.LogService; +import org.nl.modules.wql.core.bean.WQLObject; import org.springframework.stereotype.Component; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestParam; @@ -38,10 +39,7 @@ import org.springframework.web.bind.annotation.RequestParam; import javax.servlet.http.HttpServletRequest; import java.lang.reflect.Method; import java.lang.reflect.Parameter; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; /** * @author Zheng Jie @@ -54,8 +52,6 @@ public class LogAspect { private final LogService logService; - ThreadLocal currentTime = new ThreadLocal<>(); - public LogAspect(LogService logService) { this.logService = logService; } @@ -75,21 +71,60 @@ public class LogAspect { */ @Around("logPointcut()") public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable { + String trackId = UUID.randomUUID().toString(); MethodSignature signature = (MethodSignature) joinPoint.getSignature(); Method method = signature.getMethod(); // 方法路径 String methodName = joinPoint.getTarget().getClass().getName() + "." + signature.getName() + "()"; - String params=getParameter(method, joinPoint.getArgs()); - log.info("请求方法:{}",methodName); - log.info("请求方法参数:{}",params); + String params = getParameter(method, joinPoint.getArgs()); - Object result; - currentTime.set(System.currentTimeMillis()); - result = joinPoint.proceed(); - Log log = new Log("INFO",System.currentTimeMillis() - currentTime.get()); - currentTime.remove(); + org.nl.modules.logging.annotation.Log logInfo = method.getAnnotation(org.nl.modules.logging.annotation.Log.class); + + //是否输出到日志文件 + if (logInfo.isPrintToLogFile()) { + log.info("track_id:{},请求方法:{},请求方法参数:{}", trackId, methodName, params); + } HttpServletRequest request = RequestHolder.getHttpServletRequest(); - logService.save(getUsername(), StringUtils.getBrowser(request), StringUtils.getIp(request),joinPoint, log); + String requestIp = StringUtils.getIp(request); + Object result; + long startTime = System.currentTimeMillis(); + try { + result = joinPoint.proceed(); + //是否把日志存到日志表 + if (logInfo.isAddLogTable()) { + Log log = new Log("INFO", System.currentTimeMillis() - startTime); + logService.save("", StringUtils.getBrowser(request), requestIp, joinPoint, log); + } + if (logInfo.isInterfaceLog()) { + try { + WQLObject interfaceLog = WQLObject.getWQLObject("sys_interface_log"); + JSONObject json = new JSONObject(); + json.put("log_id", IdUtil.getStringId()); + json.put("description", logInfo.value()); + json.put("log_type", logInfo.interfaceLogType().getDesc()); + json.put("log_level", "1"); + json.put("method", methodName); + json.put("params", getParameter(method, joinPoint.getArgs())); + json.put("request_ip", StringUtils.getIp(request)); + json.put("time", System.currentTimeMillis() - startTime); + json.put("username", ""); + json.put("address", StringUtils.getCityInfo(requestIp)); + json.put("browser", StringUtils.getBrowser(request)); + json.put("exception_detail", IdUtil.getStringId()); + json.put("create_time", DateUtil.now()); + json.put("return_result", JSONObject.parse(result.toString())); + interfaceLog.insert(json); + } catch (Exception e) { + + } + } + } catch (Exception ex) { + log.error("track_id:{},error:{}", trackId, ex.getMessage()); + Log log = new Log("ERROR", System.currentTimeMillis() - startTime); + log.setExceptionDetail(ThrowableUtil.getStackTrace(ex).getBytes()); + logService.save("", StringUtils.getBrowser(request), StringUtils.getIp(request), (ProceedingJoinPoint) joinPoint, log); + throw ex; + } return result; } @@ -123,26 +158,11 @@ public class LogAspect { return argList.size() == 1 ? JSONUtil.toJsonStr(argList.get(0)) : JSONUtil.toJsonStr(argList); } - /** - * 配置异常通知 - * - * @param joinPoint join point for advice - * @param e exception - */ - @AfterThrowing(pointcut = "logPointcut()", throwing = "e") - public void logAfterThrowing(JoinPoint joinPoint, Throwable e) { - Log log = new Log("ERROR",System.currentTimeMillis() - currentTime.get()); - currentTime.remove(); - log.setExceptionDetail(ThrowableUtil.getStackTrace(e).getBytes()); - HttpServletRequest request = RequestHolder.getHttpServletRequest(); - logService.save(getUsername(), StringUtils.getBrowser(request), StringUtils.getIp(request), (ProceedingJoinPoint)joinPoint, log); - } - - public String getUsername() { - try { - return SecurityUtils.getCurrentUsername(); - }catch (Exception e){ - return ""; - } - } +// public String getUsername() { +// try { +// return SecurityUtils.getCurrentUsername(); +// } catch (Exception e) { +// return ""; +// } +// } } diff --git a/acs/nladmin-system/src/main/java/org/nl/modules/logging/rest/InterfaceLogController.java b/acs/nladmin-system/src/main/java/org/nl/modules/logging/rest/InterfaceLogController.java new file mode 100644 index 000000000..847d8f5f5 --- /dev/null +++ b/acs/nladmin-system/src/main/java/org/nl/modules/logging/rest/InterfaceLogController.java @@ -0,0 +1,51 @@ +package org.nl.modules.logging.rest; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import org.nl.modules.logging.annotation.Log; +import org.nl.modules.logging.service.InterfaceLogService; +import org.springframework.data.domain.Pageable; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import java.util.Map; + +/** + * @author ldjun + * @version 1.0 + * @date 2023年01月29日 18:55 + * @desc desc + */ + +@RestController +@RequiredArgsConstructor +@RequestMapping("/api/interfaceLog") +@Api(tags = "系统:接口日志管理") +public class InterfaceLogController { + private final InterfaceLogService interfaceLogService; + + @GetMapping + @Log("查询接口日志") + @ApiOperation("查询接口日志") + //@SaCheckPermission("point:list") + public ResponseEntity query(@RequestParam Map whereJson, Pageable page) { + return new ResponseEntity<>(interfaceLogService.queryAll(whereJson, page), HttpStatus.OK); + } + + @DeleteMapping(value = "/delLogs") + @Log("删除所有接口日志") + @ApiOperation("删除所有接口日志") + public ResponseEntity delLogs(){ + interfaceLogService.delLogs(); + return new ResponseEntity<>(HttpStatus.OK); + } + + @GetMapping("/logTypeList") + @Log("查询接口日志类型下拉框") + @ApiOperation("查询接口日志类型下拉框") + public ResponseEntity logTypeList() { + return new ResponseEntity<>(interfaceLogService.logTypeList(), HttpStatus.OK); + } +} diff --git a/acs/nladmin-system/src/main/java/org/nl/modules/logging/service/InterfaceLogService.java b/acs/nladmin-system/src/main/java/org/nl/modules/logging/service/InterfaceLogService.java new file mode 100644 index 000000000..b40b2d6b6 --- /dev/null +++ b/acs/nladmin-system/src/main/java/org/nl/modules/logging/service/InterfaceLogService.java @@ -0,0 +1,44 @@ +/* + * Copyright 2019-2020 Zheng Jie + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.nl.modules.logging.service; + +import com.alibaba.fastjson.JSONArray; +import org.springframework.data.domain.Pageable; + +import java.util.Map; + +/** + * @author Zheng Jie + * @date 2018-11-24 + */ +public interface InterfaceLogService { + + /** + * 查询数据分页 + * @param whereJson 条件 + * @param page 分页参数 + * @return Map + */ + Map queryAll(Map whereJson, Pageable page); + + + /** + * 删除所有日志 + */ + void delLogs(); + + JSONArray logTypeList(); +} diff --git a/acs/nladmin-system/src/main/java/org/nl/modules/logging/service/impl/InterfaceLogServiceImpl.java b/acs/nladmin-system/src/main/java/org/nl/modules/logging/service/impl/InterfaceLogServiceImpl.java new file mode 100644 index 000000000..6b9d5a5d1 --- /dev/null +++ b/acs/nladmin-system/src/main/java/org/nl/modules/logging/service/impl/InterfaceLogServiceImpl.java @@ -0,0 +1,70 @@ +/* + * Copyright 2019-2020 Zheng Jie + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.nl.modules.logging.service.impl; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.nl.modules.logging.InterfaceLogType; +import org.nl.modules.logging.service.InterfaceLogService; +import org.nl.modules.wql.WQL; +import org.nl.modules.wql.core.bean.WQLObject; +import org.nl.modules.wql.util.WqlUtil; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Service; + +import java.util.HashMap; +import java.util.Map; + +/** + * @author Zheng Jie + * @date 2018-11-24 + */ +@Service +@RequiredArgsConstructor +@Slf4j +public class InterfaceLogServiceImpl implements InterfaceLogService { + + + @Override + public Map queryAll(Map whereJson, Pageable pageable) { + HashMap map = new HashMap(); + map.put("flag", "1"); + map.put("blurry", whereJson.get("blurry")); + map.put("logType", whereJson.get("logType")); + map.put("begin_time", whereJson.get("begin_time")); + map.put("end_time", whereJson.get("end_time")); + JSONObject json = WQL.getWO("QSCH_INTERFACE_LOGS").addParamMap(map).pageQuery(WqlUtil.getHttpContext(pageable), "create_time desc"); + return json; + } + + @Override + public void delLogs() { + WQLObject logTab = WQLObject.getWQLObject("sys_interface_log"); + logTab.delete("log_id is not null"); + } + + @Override + public JSONArray logTypeList() { + JSONArray jsonArray = new JSONArray(); + InterfaceLogType[] values = InterfaceLogType.values(); + for (InterfaceLogType value : values) { + jsonArray.add(value.getDesc()); + } + return jsonArray; + } +} diff --git a/acs/nladmin-system/src/main/java/org/nl/modules/logging/service/wql/QSCH_INTERFACE_LOGS.wql b/acs/nladmin-system/src/main/java/org/nl/modules/logging/service/wql/QSCH_INTERFACE_LOGS.wql new file mode 100644 index 000000000..afd14ee44 --- /dev/null +++ b/acs/nladmin-system/src/main/java/org/nl/modules/logging/service/wql/QSCH_INTERFACE_LOGS.wql @@ -0,0 +1,68 @@ +[交易说明] + 交易名: 接口日志分页查询 + 所属模块: + 功能简述: + 版权所有: + 表引用: + 版本经历: + +[数据库] + --指定数据库,为空采用默认值,默认为db.properties中列出的第一个库 + +[IO定义] + ################################################# + ## 表字段对应输入参数 + ################################################# + 输入.flag TYPEAS s_string + 输入.blurry TYPEAS s_string + 输入.logType TYPEAS s_string + 输入.begin_time TYPEAS s_string + 输入.end_time TYPEAS s_string + + +[临时表] + --这边列出来的临时表就会在运行期动态创建 + +[临时变量] + --所有中间过程变量均可在此处定义 + +[业务过程] + + ########################################## + # 1、输入输出检查 # + ########################################## + + + ########################################## + # 2、主过程前处理 # + ########################################## + + + ########################################## + # 3、业务主过程 # + ########################################## + + IF 输入.flag = "1" + PAGEQUERY + SELECT + * + FROM + sys_interface_log + WHERE + 1=1 + OPTION 输入.blurry <> "" + description like "%" 输入.blurry "%" + ENDOPTION + OPTION 输入.logType <> "" + log_type = 输入.logType + ENDOPTION + OPTION 输入.begin_time <> "" + create_time >= 输入.begin_time + ENDOPTION + OPTION 输入.end_time <> "" + create_time <= 输入.end_time + ENDOPTION + ENDSELECT + ENDPAGEQUERY + ENDIF + diff --git a/acs/nladmin-system/src/main/java/org/nl/modules/mnt/websocket/WebSocketServer.java b/acs/nladmin-system/src/main/java/org/nl/modules/mnt/websocket/WebSocketServer.java index f6e9d0c27..74a00f35a 100644 --- a/acs/nladmin-system/src/main/java/org/nl/modules/mnt/websocket/WebSocketServer.java +++ b/acs/nladmin-system/src/main/java/org/nl/modules/mnt/websocket/WebSocketServer.java @@ -77,7 +77,6 @@ public class WebSocketServer { * @param message 客户端发送过来的消息*/ @OnMessage public void onMessage(String message, Session session) { - log.info("收到来"+sid+"的信息:"+message); //群发消息 for (WebSocketServer item : webSocketSet) { try { @@ -106,7 +105,6 @@ public class WebSocketServer { * */ public static void sendInfo(SocketMsg socketMsg,@PathParam("sid") String sid) throws IOException { String message = JSONObject.toJSONString(socketMsg); - log.info("推送消息到"+sid+",推送内容:"+message); for (WebSocketServer item : webSocketSet) { try { //这里可以设定只推送给这个sid的,为null则全部推送 diff --git a/acs/nladmin-system/src/main/java/org/nl/modules/system/wql/sys.xls b/acs/nladmin-system/src/main/java/org/nl/modules/system/wql/sys.xls index a73514e74..82566ab64 100644 Binary files a/acs/nladmin-system/src/main/java/org/nl/modules/system/wql/sys.xls and b/acs/nladmin-system/src/main/java/org/nl/modules/system/wql/sys.xls differ diff --git a/acs/nladmin-system/src/main/resources/config/application-dev.yml b/acs/nladmin-system/src/main/resources/config/application-dev.yml index da186d068..d4bbec25a 100644 --- a/acs/nladmin-system/src/main/resources/config/application-dev.yml +++ b/acs/nladmin-system/src/main/resources/config/application-dev.yml @@ -1,18 +1,23 @@ server: port: 8010 + tomcat: + accept-count: 1000 + max-connections: 10000 + max-threads: 800 + min-spare-threads: 100 #配置数据源 spring: datasource: druid: db-type: com.alibaba.druid.pool.DruidDataSource driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy -# url: jdbc:log4jdbc:mysql://${DB_HOST:10.1.3.91}:${DB_PORT:3306}/${DB_NAME:acs}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true -# url: jdbc:log4jdbc:mysql://${DB_HOST:192.168.81.252}:${DB_PORT:3306}/${DB_NAME:lzhl_one_acs}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true - url: jdbc:log4jdbc:mysql://${DB_HOST:127.0.0.1}:${DB_PORT:3306}/${DB_NAME:lzhl_one_wcs}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true + # url: jdbc:log4jdbc:mysql://${DB_HOST:10.1.3.91}:${DB_PORT:3306}/${DB_NAME:acs}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true + # url: jdbc:log4jdbc:mysql://${DB_HOST:192.168.81.252}:${DB_PORT:3306}/${DB_NAME:lzhl_one_acs}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true + url: jdbc:log4jdbc:mysql://${DB_HOST:127.0.0.1}:${DB_PORT:3306}/${DB_NAME:lzhl_one_acs}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true username: ${DB_USER:root} # password: ${DB_PWD:P@ssw0rd} # password: ${DB_PWD:Root.123456} - password: ${DB_PWD:password} + password: ${DB_PWD:123456} # 初始连接数 initial-size: 5 diff --git a/acs/nladmin-system/src/main/resources/config/application-prod.yml b/acs/nladmin-system/src/main/resources/config/application-prod.yml index e95a76390..e6113d90b 100644 --- a/acs/nladmin-system/src/main/resources/config/application-prod.yml +++ b/acs/nladmin-system/src/main/resources/config/application-prod.yml @@ -1,5 +1,10 @@ server: port: 8011 + tomcat: + accept-count: 1000 + max-connections: 10000 + max-threads: 800 + min-spare-threads: 100 #配置数据源 spring: datasource: diff --git a/acs/nladmin-system/src/main/resources/logback-spring.xml b/acs/nladmin-system/src/main/resources/logback-spring.xml index 86bdaa02c..34e8af111 100644 --- a/acs/nladmin-system/src/main/resources/logback-spring.xml +++ b/acs/nladmin-system/src/main/resources/logback-spring.xml @@ -92,26 +92,46 @@ https://juejin.cn/post/6844903775631572999 + + + error + + + + ${LOG_HOME}/ERROR/%d{yyyy-MM-dd}.%i.log + + 15 + + 200MB + + 20GB + + + ${log.pattern} + ${log.charset} + + + - + - + - + - + @@ -143,27 +163,27 @@ https://juejin.cn/post/6844903775631572999 - + - + - + - + - + diff --git a/acs/nladmin-ui/src/views/acs/device/driver/hongxiang_conveyor.vue b/acs/nladmin-ui/src/views/acs/device/driver/hongxiang_conveyor.vue index 8f23c7a15..e0d20f8f3 100644 --- a/acs/nladmin-ui/src/views/acs/device/driver/hongxiang_conveyor.vue +++ b/acs/nladmin-ui/src/views/acs/device/driver/hongxiang_conveyor.vue @@ -222,6 +222,14 @@ /> + + + + + + + + + + + +