From 3101c2c8f98061f13a72f194d064b44ac021f1b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=B1=9F=E7=8E=AE?= Date: Thu, 16 Nov 2023 14:23:01 +0800 Subject: [PATCH] fix --- .../org/nl/acs/agv/server/AgvWaitUtil.java | 32 +- .../acs/agv/server/impl/AgvServiceImpl.java | 53 +- .../acs/ext/wms/rest/WmsToAcsController.java | 6 + .../acs/ext/wms/service/WmsToAcsService.java | 2 + .../wms/service/impl/WmsToAcsServiceImpl.java | 71 +- .../service/dto/InstructionDto.java | 2 +- .../modules/quartz/task/AutoCreateInst.java | 619 +++++++++--------- .../quartz/task/QueryXZAgvTaskStatus.java | 40 +- 8 files changed, 445 insertions(+), 380 deletions(-) diff --git a/hd/nladmin-system/src/main/java/org/nl/acs/agv/server/AgvWaitUtil.java b/hd/nladmin-system/src/main/java/org/nl/acs/agv/server/AgvWaitUtil.java index b6fe091..2522e96 100644 --- a/hd/nladmin-system/src/main/java/org/nl/acs/agv/server/AgvWaitUtil.java +++ b/hd/nladmin-system/src/main/java/org/nl/acs/agv/server/AgvWaitUtil.java @@ -6,18 +6,15 @@ import lombok.extern.slf4j.Slf4j; import net.sf.json.JSONArray; import net.sf.json.JSONObject; import org.nl.acs.ext.wms.service.AcsToWmsService; -import org.nl.acs.ext.wms.service.impl.AcsToWmsZDServiceImpl; import org.nl.acs.instruction.service.InstructionService; import org.nl.acs.instruction.service.dto.Instruction; import org.nl.acs.log.service.LogServer; -import org.nl.acs.opc.DeviceAppService; import org.nl.exception.BadRequestException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; /** - * @author: geng by - * @createDate: 2022/12/5 + * @author zhangjiangwei */ @Service @RequiredArgsConstructor @@ -27,6 +24,9 @@ public class AgvWaitUtil { @Autowired LogServer logServer; + @Autowired + InstructionService instructionService; + //取货前等待 public JSONObject waitInGet(String startDeviceCode, Instruction inst) { log.info("仙工AGV请求取货,设备号 - {}", startDeviceCode); @@ -55,24 +55,14 @@ public class AgvWaitUtil { public JSONObject waitOutGet(String startDeviceCode, Instruction inst) { log.info("仙工AGV取货完成后请求离开,设备号 - {}", startDeviceCode); - JSONObject responseBody = acsToWmsService.gccQueryStationState(inst); + inst.setExecute_status("2"); + instructionService.update(inst); - if (ObjectUtil.isNotEmpty(responseBody) && 200 == responseBody.optInt("status")) { - JSONArray data = responseBody.optJSONArray("data"); - for (int i = 0; i < data.size(); i++) { - JSONObject datum = data.getJSONObject(i); - if (startDeviceCode.equals(datum.optString("Station_Code")) - && !datum.optBoolean("IsHasGoods", true)) { - JSONObject map = new JSONObject(); - map.put("status", 200); - map.put("message", "允许离开!"); - log.info("允许仙工AGV取货完成后请求离开,设备号 - {}", startDeviceCode); - return map; - } - } - } - - throw new BadRequestException("请求失败!"); + JSONObject map = new JSONObject(); + map.put("status", 200); + map.put("message", "允许离开!"); + log.info("允许仙工AGV取货完成后请求离开,设备号 - {}", startDeviceCode); + return map; } //放货前等待 diff --git a/hd/nladmin-system/src/main/java/org/nl/acs/agv/server/impl/AgvServiceImpl.java b/hd/nladmin-system/src/main/java/org/nl/acs/agv/server/impl/AgvServiceImpl.java index 4ba7d66..f81bb09 100644 --- a/hd/nladmin-system/src/main/java/org/nl/acs/agv/server/impl/AgvServiceImpl.java +++ b/hd/nladmin-system/src/main/java/org/nl/acs/agv/server/impl/AgvServiceImpl.java @@ -663,6 +663,21 @@ public class AgvServiceImpl implements AgvService { String agvport = acsConfigService.findConfigFromCache().get(AcsConfig.AGVPORT); agvurl = agvurl + ":" + agvport + "/orders?page=1&size=9999"; + List insts = instructionService.findAllInstFromCache(); + if (!insts.isEmpty()) { + JSONObject where = new JSONObject(); + where.put("relation", "OR"); + JSONArray predicates = new JSONArray(); + where.put("predicates", predicates); + for (Instruction instruction : insts) { + JSONArray row = new JSONArray(); + row.add("id"); + row.add("EQ"); + row.add(instruction.getInstruction_code()); + predicates.add(row); + } + agvurl = agvurl+ "&where=" + where; + } HttpResponse result = HttpRequest.get(agvurl) .timeout(20000)//超时,毫秒 @@ -2132,26 +2147,24 @@ public class AgvServiceImpl implements AgvService { jo1.put("operation", "JackLoad"); ja.add(jo1); -// if ("true".equals(startDevice.getExtraValue().get("ignore_pickup_check"))) { -// //取货完成等待 -// com.alibaba.fastjson.JSONObject jo2 = new com.alibaba.fastjson.JSONObject(); -// jo2.put("blockId", IdUtil.simpleUUID()); -// jo2.put("location", inst.getStart_point_code() + "OUTGET"); -// jo2.put("operation", "script"); -// jo2.put("id", inst.getStart_point_code() + "OUTGET"); -// jo2.put("script_name", "userpy/interact.py"); -// com.alibaba.fastjson.JSONObject script_args2 = new com.alibaba.fastjson.JSONObject(); -// script_args2.put("addr", addr); -// com.alibaba.fastjson.JSONObject data2 = new com.alibaba.fastjson.JSONObject(); -// com.alibaba.fastjson.JSONObject reach2 = new com.alibaba.fastjson.JSONObject(); -// reach2.put("task_code", inst.getInstruction_code()); -// reach2.put("address", inst.getStart_point_code() + "OUTGET"); -// data2.put("reach", reach2); -// script_args2.put("data", data2); -// script_args2.put("protocol", "HTTP"); -// jo2.put("script_args", script_args2); -// ja.add(jo2); -// } + //取货完成等待 + com.alibaba.fastjson.JSONObject jo2 = new com.alibaba.fastjson.JSONObject(); + jo2.put("blockId", IdUtil.simpleUUID()); + jo2.put("location", inst.getStart_point_code() + "OUTGET"); + jo2.put("operation", "script"); + jo2.put("id", inst.getStart_point_code() + "OUTGET"); + jo2.put("script_name", "userpy/interact.py"); + com.alibaba.fastjson.JSONObject script_args2 = new com.alibaba.fastjson.JSONObject(); + script_args2.put("addr", addr); + com.alibaba.fastjson.JSONObject data2 = new com.alibaba.fastjson.JSONObject(); + com.alibaba.fastjson.JSONObject reach2 = new com.alibaba.fastjson.JSONObject(); + reach2.put("task_code", inst.getInstruction_code()); + reach2.put("address", inst.getStart_point_code() + "OUTGET"); + data2.put("reach", reach2); + script_args2.put("data", data2); + script_args2.put("protocol", "HTTP"); + jo2.put("script_args", script_args2); + ja.add(jo2); Device nextDevice = deviceAppService.findDeviceByCode(inst.getNext_device_code()); if ("true".equals(nextDevice.getExtraValue().get("ignore_release_check"))) { diff --git a/hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/rest/WmsToAcsController.java b/hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/rest/WmsToAcsController.java index 110e3cf..a479bab 100644 --- a/hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/rest/WmsToAcsController.java +++ b/hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/rest/WmsToAcsController.java @@ -70,4 +70,10 @@ public class WmsToAcsController { return new ResponseEntity<>(wmstoacsService.queryDevice(whereJson), HttpStatus.OK); } + @PostMapping("/gccCancelTask") + @Log("广钞厂取消任务") + @ApiOperation("广钞厂取消任务") + public ResponseEntity gccCancelTask(@RequestBody String whereJson) { + return new ResponseEntity<>(wmstoacsService.gccCancelTask(whereJson), HttpStatus.OK); + } } diff --git a/hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/WmsToAcsService.java b/hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/WmsToAcsService.java index 40c1ea5..ede3947 100644 --- a/hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/WmsToAcsService.java +++ b/hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/WmsToAcsService.java @@ -52,4 +52,6 @@ public interface WmsToAcsService { * @return Map */ Map queryDevice(String jsonObject) throws Exception; + + Map gccCancelTask(String whereJson); } diff --git a/hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/WmsToAcsServiceImpl.java b/hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/WmsToAcsServiceImpl.java index 2f0fc58..bd39488 100644 --- a/hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/WmsToAcsServiceImpl.java +++ b/hd/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/WmsToAcsServiceImpl.java @@ -1,5 +1,6 @@ package org.nl.acs.ext.wms.service.impl; +import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import lombok.RequiredArgsConstructor; @@ -41,6 +42,8 @@ import org.nl.acs.route.service.RouteLineService; import org.nl.acs.route.service.dto.RouteLineDto; import org.nl.acs.task.service.TaskService; import org.nl.acs.task.service.dto.TaskDto; +import org.nl.exception.BadRequestException; +import org.nl.utils.SecurityUtils; import org.nl.utils.SpringContextHolder; import org.nl.wql.core.bean.WQLObject; import org.springframework.beans.factory.annotation.Autowired; @@ -69,7 +72,7 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { JSONObject resultJson = new JSONObject(); log.info("createFromWms--------------:输入参数:" + tasks.toString()); logServer.log("", "createFromWms", "info", tasks.toString(), "", "", "", ""); - try{ + try { JSONArray errArr = new JSONArray(); for (int i = 0; i < tasks.size(); i++) { JSONObject task = tasks.getJSONObject(i); @@ -153,7 +156,7 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { continue; } - if(TaskService.checkSameTaskByCode(task_code)){ + if (TaskService.checkSameTaskByCode(task_code)) { JSONObject json = new JSONObject(); json.put("task_code", task_code); json.put("message", "不能存在相同的任务号!"); @@ -227,7 +230,7 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { resultJson.put("message", "操作成功"); resultJson.put("data", new JSONObject()); log.info("createFromWms--------------:输出参数:" + resultJson.toString()); - logServer.log("", "createFromWms", "info",tasks.toString(), resultJson.toString(), "200", "", ""); + logServer.log("", "createFromWms", "info", tasks.toString(), resultJson.toString(), "200", "", ""); } catch (Exception e) { @@ -236,7 +239,7 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { resultJson.put("message", e.getMessage()); resultJson.put("data", new JSONObject()); log.info("createFromWms--------------:输出参数:" + resultJson.toString()); - logServer.log("", "createFromWms", "error",tasks.toString(), resultJson.toString(), "400", "", ""); + logServer.log("", "createFromWms", "error", tasks.toString(), resultJson.toString(), "400", "", ""); } @@ -330,9 +333,9 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { electricFenceDeviceDriver = (ElectricFenceDeviceDriver) device.getDeviceDriver(); if (electricFenceDeviceDriver.getSuspended()) { throw new RuntimeException("交通管制无法进入"); - } else if (StrUtil.equals(type,"1")) { + } else if (StrUtil.equals(type, "1")) { electricFenceDeviceDriver.setSuspended(true); - } else if (StrUtil.equals(type,"2")) { + } else if (StrUtil.equals(type, "2")) { electricFenceDeviceDriver.setSuspended(false); } } @@ -938,4 +941,60 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { return resultJson; } + @Override + public Map gccCancelTask(String whereJson) { + try { + log.info("gccCancelTask 请求参数:{}", whereJson); + JSONObject param = JSONObject.fromObject(whereJson); + String taskCode = param.optString("task_code"); + if (StrUtil.isBlank(taskCode)) { + throw new BadRequestException("任务号不能为空,操作失败!"); + } + + TaskDto task = TaskService.findByCode(taskCode); + if (task == null) { + throw new BadRequestException(taskCode + "不存在,操作失败!"); + } + if ("2".equals(task.getTask_status())) { + throw new BadRequestException(taskCode + "已完成,操作失败!"); + } + + Instruction inst = InstructionService.findByTaskcode(taskCode); + if (ObjectUtil.isNotEmpty(inst)) { + if (Integer.parseInt(inst.getExecute_status()) >= 2) { + throw new BadRequestException("AGV已取货完成,无法取消!"); + } + InstructionService.cancel(inst.getInstruction_id()); + } + + String currentUsername = SecurityUtils.getCurrentUsername(); + String now = DateUtil.now(); + task.setUpdate_time(now); + task.setUpdate_by(currentUsername); + task.setTask_status("3"); + + WQLObject wo = WQLObject.getWQLObject("acs_task"); + JSONObject json = JSONObject.fromObject(task); + wo.update(json); + //清理缓存 + for (int i = 0; i < TaskService.findAllTaskFromCache().size(); i++) { + TaskDto taskDto = TaskService.findAllTaskFromCache().get(i); + if (taskDto.getTask_code().equals(taskCode)) { + TaskService.findAllTaskFromCache().remove(i); + } + } + } catch (Exception e) { + JSONObject resultJson = new JSONObject(); + resultJson.put("status", HttpStatus.BAD_REQUEST.value()); + resultJson.put("message", e.getMessage()); + log.info("gccCancelTask 响应参数:{}", resultJson); + return resultJson; + } + + JSONObject resultJson = new JSONObject(); + resultJson.put("status", HttpStatus.OK.value()); + resultJson.put("message", "操作成功!"); + log.info("gccCancelTask 响应参数:{}", resultJson); + return resultJson; + } } diff --git a/hd/nladmin-system/src/main/java/org/nl/acs/instruction/service/dto/InstructionDto.java b/hd/nladmin-system/src/main/java/org/nl/acs/instruction/service/dto/InstructionDto.java index 5bc0624..6cbf5f4 100644 --- a/hd/nladmin-system/src/main/java/org/nl/acs/instruction/service/dto/InstructionDto.java +++ b/hd/nladmin-system/src/main/java/org/nl/acs/instruction/service/dto/InstructionDto.java @@ -37,7 +37,7 @@ public class InstructionDto implements Serializable { * 执行状态 */ //暂定 0就绪 1请求取货 2取货完成 3请求放货 4放货完成 5取货完成离开 6放货完成离开 7请求进入区域 8请求离开区域 - private String execute_status; + private String execute_status = "0"; /** * 执行状态描述 diff --git a/hd/nladmin-system/src/main/java/org/nl/modules/quartz/task/AutoCreateInst.java b/hd/nladmin-system/src/main/java/org/nl/modules/quartz/task/AutoCreateInst.java index 844a7e7..0ee0c80 100644 --- a/hd/nladmin-system/src/main/java/org/nl/modules/quartz/task/AutoCreateInst.java +++ b/hd/nladmin-system/src/main/java/org/nl/modules/quartz/task/AutoCreateInst.java @@ -42,6 +42,8 @@ public class AutoCreateInst { protected BusinessLogger execute_log; protected NoRepeatBusinessLogger device_log; + private volatile boolean lock = false; + public AutoCreateInst() { this.execute_log = new BusinessLoggerImpl(BusinessDomain.device_execute.name()); this.device_log = BusinessLoggerFactory.getNoRepeatBusinessLogger(BusinessDomain.device_execute.name()); @@ -53,48 +55,51 @@ public class AutoCreateInst { * 创建指令前需要判断是否条件具备:起始位置是否有货、目标位置是否有货 */ public void run() throws Exception { - TaskService taskserver = SpringContextHolder.getBean(TaskService.class); - InstructionService instructionService = SpringContextHolder.getBean(InstructionService.class); - RouteLineService routeLineService = SpringContextHolder.getBean(RouteLineService.class); - AcsConfigService acsConfigService = SpringContextHolder.getBean(AcsConfigService.class); - List list = taskserver.queryByStauts("0"); - DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); - for (int i = 0; i < list.size(); i++) { + if (!lock) { + lock = true; + try { + TaskService taskserver = SpringContextHolder.getBean(TaskService.class); + InstructionService instructionService = SpringContextHolder.getBean(InstructionService.class); + RouteLineService routeLineService = SpringContextHolder.getBean(RouteLineService.class); + AcsConfigService acsConfigService = SpringContextHolder.getBean(AcsConfigService.class); + List list = taskserver.queryByStauts("0"); + DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); + for (int i = 0; i < list.size(); i++) { - TaskDto acsTask = list.get(i); - String taskid = acsTask.getTask_id(); - String taskcode = acsTask.getTask_code(); - String vehiclecode = acsTask.getVehicle_code(); - String priority = acsTask.getPriority(); - String start_point_code = acsTask.getStart_point_code(); - String start_device_code = acsTask.getStart_device_code(); - String route_plan_code = acsTask.getRoute_plan_code(); - String vehicleType = acsTask.getVehicle_type(); + TaskDto acsTask = list.get(i); + String taskid = acsTask.getTask_id(); + String taskcode = acsTask.getTask_code(); + String vehiclecode = acsTask.getVehicle_code(); + String priority = acsTask.getPriority(); + String start_point_code = acsTask.getStart_point_code(); + String start_device_code = acsTask.getStart_device_code(); + String route_plan_code = acsTask.getRoute_plan_code(); + String vehicleType = acsTask.getVehicle_type(); - //是否复合任务 =0非复合任务 - String compound_task = acsTask.getCompound_task(); - String next_point_code = acsTask.getNext_point_code(); - String next_device_code = acsTask.getNext_device_code(); - if (StrUtil.isEmpty(start_device_code)) { - acsTask.setRemark("起始设备不能为空"); - taskserver.updateByCodeFromCache(acsTask); - continue; - } - if (StrUtil.isEmpty(next_device_code)) { - acsTask.setRemark("目标设备不能为空"); - taskserver.updateByCodeFromCache(acsTask); - continue; - } - String maxInstnumber = acsConfigService.findConfigFromCache().get(AcsConfig.MAXINSTNUMBER); - if (ObjectUtils.isNotEmpty(maxInstnumber)) { - if (i >= Integer.parseInt(maxInstnumber)) { - acsTask.setRemark("系统参数配置最大指令数为:" + maxInstnumber + "无法生成指令"); - taskserver.updateByCodeFromCache(acsTask); - continue; - } - } + //是否复合任务 =0非复合任务 + String compound_task = acsTask.getCompound_task(); + String next_point_code = acsTask.getNext_point_code(); + String next_device_code = acsTask.getNext_device_code(); + if (StrUtil.isEmpty(start_device_code)) { + acsTask.setRemark("起始设备不能为空"); + taskserver.updateByCodeFromCache(acsTask); + continue; + } + if (StrUtil.isEmpty(next_device_code)) { + acsTask.setRemark("目标设备不能为空"); + taskserver.updateByCodeFromCache(acsTask); + continue; + } + String maxInstnumber = acsConfigService.findConfigFromCache().get(AcsConfig.MAXINSTNUMBER); + if (ObjectUtils.isNotEmpty(maxInstnumber)) { + if (i >= Integer.parseInt(maxInstnumber)) { + acsTask.setRemark("系统参数配置最大指令数为:" + maxInstnumber + "无法生成指令"); + taskserver.updateByCodeFromCache(acsTask); + continue; + } + } - //特殊任务 起点终点处理 + //特殊任务 起点终点处理 // if (StrUtil.equals("2", acsTask.getTask_type())) { // next_device_code = acsTask.getNext_device_code(); // if (StrUtil.equals(appService.findDeviceTypeByCode(next_device_code), "storage")) { @@ -110,299 +115,305 @@ public class AutoCreateInst { // } // } - /** - * 开始平均分解校验 - */ - String this_device_code = taskserver.queryAssignedByDevice(acsTask.getStart_device_code(), acsTask.getNext_device_code()); - if (StrUtil.isEmpty(this_device_code)) { - List shortPathsList = routeLineService.getShortPathLines(start_device_code, acsTask.getNext_device_code(), route_plan_code); - RouteLineDto routeLineDto = shortPathsList.get(0); - String path = routeLineDto.getPath(); - String type = routeLineDto.getType(); - String[] str = path.split("->"); - List pathlist = Arrays.asList(str); - int index = 0; - for (int m = 0; m < pathlist.size(); m++) { - if (pathlist.get(m).equals(start_device_code)) { - index = m + 1; - break; + /** + * 开始平均分解校验 + */ + String this_device_code = taskserver.queryAssignedByDevice(acsTask.getStart_device_code(), acsTask.getNext_device_code()); + if (StrUtil.isEmpty(this_device_code)) { + List shortPathsList = routeLineService.getShortPathLines(start_device_code, acsTask.getNext_device_code(), route_plan_code); + RouteLineDto routeLineDto = shortPathsList.get(0); + String path = routeLineDto.getPath(); + String type = routeLineDto.getType(); + String[] str = path.split("->"); + List pathlist = Arrays.asList(str); + int index = 0; + for (int m = 0; m < pathlist.size(); m++) { + if (pathlist.get(m).equals(start_device_code)) { + index = m + 1; + break; + } + } + next_device_code = pathlist.get(index); + } else { + next_device_code = this_device_code; } - } - next_device_code = pathlist.get(index); - } else { - next_device_code = this_device_code; - } - //校验路由关系 - List shortPathsList = routeLineService.getShortPathLines(start_device_code, next_device_code, route_plan_code); - if (ObjectUtils.isEmpty(shortPathsList)) { - acsTask.setRemark("路由不通无法生成指令"); - taskserver.updateByCodeFromCache(acsTask); - continue; - } - - if (!StrUtil.equals(shortPathsList.get(0).getType(), "1")) { - continue; - } - Device startdevice = appService.findDeviceByCode(start_device_code); - Device nextdevice = appService.findDeviceByCode(next_device_code); - if (StrUtil.equals(appService.findDeviceTypeByCode(next_device_code), "storage")) { - next_point_code = next_device_code + "-" + acsTask.getTo_y() + "-" + acsTask.getTo_z(); - } else { - next_point_code = next_device_code; - } - if (ObjectUtils.isEmpty(appService)) { - log.info("地址对应设备未找到"); - continue; - } - if (ObjectUtils.isEmpty(startdevice)) { - log.info("地址对应设备未找到"); - continue; - } - //普通站点 - StandardOrdinarySiteDeviceDriver standardOrdinarySiteDeviceDriver; - StandardInspectSiteDeviceDriver standardInspectSiteDeviceDriver; - StandardEmptyPalletSiteDeviceDriver standardEmptsyPalletSiteDeviceDriver; - StandardManipulatorInspectSiteDeviceDriver standardManipulatorInspectSiteDeviceDriver; - LampThreecolorDeviceDriver lampThreecolorDeviceDriver; - - String createTaskCheck = acsConfigService.findConfigFromCache().get(AcsConfig.CREATETASKCHECK); - - if (StrUtil.equals(createTaskCheck, "1")) { - if (startdevice.getDeviceDriver() instanceof StandardInspectSiteDeviceDriver) { - standardInspectSiteDeviceDriver = (StandardInspectSiteDeviceDriver) startdevice.getDeviceDriver(); - if (standardInspectSiteDeviceDriver.getMode() != 2) { - log.info("起点设备:" + startdevice.getDevice_code() + "设备未待机,任务号:" + taskcode); - acsTask.setRemark("起点设备:" + startdevice.getDevice_code() + "设备未待机,任务号:" + taskcode); + //校验路由关系 + List shortPathsList = routeLineService.getShortPathLines(start_device_code, next_device_code, route_plan_code); + if (ObjectUtils.isEmpty(shortPathsList)) { + acsTask.setRemark("路由不通无法生成指令"); taskserver.updateByCodeFromCache(acsTask); - this.execute_log.setResource(startdevice.getDevice_code(), startdevice.getDevice_code()); - this.execute_log.log("起点设备:" + startdevice.getDevice_code() + "设备未待机,任务号:" + taskcode); continue; } - if (standardInspectSiteDeviceDriver.getMove() == 0) { - log.info("目标设备:" + startdevice.getDevice_code() + "设备不满足放货条件,任务号:" + taskcode); - acsTask.setRemark("目标设备:" + startdevice.getDevice_code() + "设备不满足放货条件,任务号:" + taskcode); - taskserver.updateByCodeFromCache(acsTask); - this.execute_log.setResource(startdevice.getDevice_code(), startdevice.getDevice_code()); - this.execute_log.log("目标设备:" + startdevice.getDevice_code() + "设备不满足放货条件,任务号:" + taskcode); + + if (!StrUtil.equals(shortPathsList.get(0).getType(), "1")) { continue; } - } - if (startdevice.getDeviceDriver() instanceof StandardManipulatorInspectSiteDeviceDriver) { - standardManipulatorInspectSiteDeviceDriver = (StandardManipulatorInspectSiteDeviceDriver) startdevice.getDeviceDriver(); - if (standardManipulatorInspectSiteDeviceDriver.getMode() != 2) { - log.info("起点设备:" + startdevice.getDevice_code() + "设备未待机,任务号:" + taskcode); - acsTask.setRemark("起点设备:" + startdevice.getDevice_code() + "设备未待机,任务号:" + taskcode); - taskserver.updateByCodeFromCache(acsTask); - this.execute_log.setResource(startdevice.getDevice_code(), startdevice.getDevice_code()); - this.execute_log.log("起点设备:" + startdevice.getDevice_code() + "设备未待机,任务号:" + taskcode); - continue; + Device startdevice = appService.findDeviceByCode(start_device_code); + Device nextdevice = appService.findDeviceByCode(next_device_code); + if (StrUtil.equals(appService.findDeviceTypeByCode(next_device_code), "storage")) { + next_point_code = next_device_code + "-" + acsTask.getTo_y() + "-" + acsTask.getTo_z(); + } else { + next_point_code = next_device_code; } - if (standardManipulatorInspectSiteDeviceDriver.getMove() == 0) { - log.info("目标设备:" + startdevice.getDevice_code() + "设备不满足放货条件,任务号:" + taskcode); - acsTask.setRemark("目标设备:" + startdevice.getDevice_code() + "设备不满足放货条件,任务号:" + taskcode); - taskserver.updateByCodeFromCache(acsTask); - this.execute_log.setResource(startdevice.getDevice_code(), startdevice.getDevice_code()); - this.execute_log.log("目标设备:" + startdevice.getDevice_code() + "设备不满足放货条件,任务号:" + taskcode); + if (ObjectUtils.isEmpty(appService)) { + log.info("地址对应设备未找到"); continue; } - } - if (startdevice.getDeviceDriver() instanceof StandardEmptyPalletSiteDeviceDriver) { - standardEmptsyPalletSiteDeviceDriver = (StandardEmptyPalletSiteDeviceDriver) startdevice.getDeviceDriver(); - if (standardEmptsyPalletSiteDeviceDriver.getMode() != 2) { - log.info("目标设备:" + nextdevice.getDevice_code() + "设备未待机,任务号:" + taskcode); - acsTask.setRemark("目标设备:" + nextdevice.getDevice_code() + "设备未待机,任务号:" + taskcode); - taskserver.updateByCodeFromCache(acsTask); - this.execute_log.setResource(nextdevice.getDevice_code(), nextdevice.getDevice_code()); - this.execute_log.log("目标设备:" + nextdevice.getDevice_code() + "设备未待机,任务号:" + taskcode); + if (ObjectUtils.isEmpty(startdevice)) { + log.info("地址对应设备未找到"); continue; } + //普通站点 + StandardOrdinarySiteDeviceDriver standardOrdinarySiteDeviceDriver; + StandardInspectSiteDeviceDriver standardInspectSiteDeviceDriver; + StandardEmptyPalletSiteDeviceDriver standardEmptsyPalletSiteDeviceDriver; + StandardManipulatorInspectSiteDeviceDriver standardManipulatorInspectSiteDeviceDriver; + LampThreecolorDeviceDriver lampThreecolorDeviceDriver; - if (StrUtil.equals(acsTask.getTask_type(), TaskTypeEnum.APPLY_EMPTY.getCode())) { - int nowNumber = standardEmptsyPalletSiteDeviceDriver.getNumber(); - start_point_code = start_point_code + "." + nowNumber; - } - } + String createTaskCheck = acsConfigService.findConfigFromCache().get(AcsConfig.CREATETASKCHECK); - //目的点校验 - if (nextdevice.getDeviceDriver() instanceof StandardInspectSiteDeviceDriver) { - standardInspectSiteDeviceDriver = (StandardInspectSiteDeviceDriver) nextdevice.getDeviceDriver(); - if (standardInspectSiteDeviceDriver.getMode() != 2) { - log.info("目标设备:" + nextdevice.getDevice_code() + "设备未待机,任务号:" + taskcode); - acsTask.setRemark("目标设备:" + nextdevice.getDevice_code() + "设备未待机,任务号:" + taskcode); - taskserver.updateByCodeFromCache(acsTask); - this.execute_log.setResource(nextdevice.getDevice_code(), nextdevice.getDevice_code()); - this.execute_log.log("目标设备:" + nextdevice.getDevice_code() + "设备未待机,任务号:" + taskcode); - continue; + if (StrUtil.equals(createTaskCheck, "1")) { + if (startdevice.getDeviceDriver() instanceof StandardInspectSiteDeviceDriver) { + standardInspectSiteDeviceDriver = (StandardInspectSiteDeviceDriver) startdevice.getDeviceDriver(); + if (standardInspectSiteDeviceDriver.getMode() != 2) { + log.info("起点设备:" + startdevice.getDevice_code() + "设备未待机,任务号:" + taskcode); + acsTask.setRemark("起点设备:" + startdevice.getDevice_code() + "设备未待机,任务号:" + taskcode); + taskserver.updateByCodeFromCache(acsTask); + this.execute_log.setResource(startdevice.getDevice_code(), startdevice.getDevice_code()); + this.execute_log.log("起点设备:" + startdevice.getDevice_code() + "设备未待机,任务号:" + taskcode); + continue; + } + if (standardInspectSiteDeviceDriver.getMove() == 0) { + log.info("目标设备:" + startdevice.getDevice_code() + "设备不满足放货条件,任务号:" + taskcode); + acsTask.setRemark("目标设备:" + startdevice.getDevice_code() + "设备不满足放货条件,任务号:" + taskcode); + taskserver.updateByCodeFromCache(acsTask); + this.execute_log.setResource(startdevice.getDevice_code(), startdevice.getDevice_code()); + this.execute_log.log("目标设备:" + startdevice.getDevice_code() + "设备不满足放货条件,任务号:" + taskcode); + continue; + } + } + if (startdevice.getDeviceDriver() instanceof StandardManipulatorInspectSiteDeviceDriver) { + standardManipulatorInspectSiteDeviceDriver = (StandardManipulatorInspectSiteDeviceDriver) startdevice.getDeviceDriver(); + if (standardManipulatorInspectSiteDeviceDriver.getMode() != 2) { + log.info("起点设备:" + startdevice.getDevice_code() + "设备未待机,任务号:" + taskcode); + acsTask.setRemark("起点设备:" + startdevice.getDevice_code() + "设备未待机,任务号:" + taskcode); + taskserver.updateByCodeFromCache(acsTask); + this.execute_log.setResource(startdevice.getDevice_code(), startdevice.getDevice_code()); + this.execute_log.log("起点设备:" + startdevice.getDevice_code() + "设备未待机,任务号:" + taskcode); + continue; + } + if (standardManipulatorInspectSiteDeviceDriver.getMove() == 0) { + log.info("目标设备:" + startdevice.getDevice_code() + "设备不满足放货条件,任务号:" + taskcode); + acsTask.setRemark("目标设备:" + startdevice.getDevice_code() + "设备不满足放货条件,任务号:" + taskcode); + taskserver.updateByCodeFromCache(acsTask); + this.execute_log.setResource(startdevice.getDevice_code(), startdevice.getDevice_code()); + this.execute_log.log("目标设备:" + startdevice.getDevice_code() + "设备不满足放货条件,任务号:" + taskcode); + continue; + } + } + if (startdevice.getDeviceDriver() instanceof StandardEmptyPalletSiteDeviceDriver) { + standardEmptsyPalletSiteDeviceDriver = (StandardEmptyPalletSiteDeviceDriver) startdevice.getDeviceDriver(); + if (standardEmptsyPalletSiteDeviceDriver.getMode() != 2) { + log.info("目标设备:" + nextdevice.getDevice_code() + "设备未待机,任务号:" + taskcode); + acsTask.setRemark("目标设备:" + nextdevice.getDevice_code() + "设备未待机,任务号:" + taskcode); + taskserver.updateByCodeFromCache(acsTask); + this.execute_log.setResource(nextdevice.getDevice_code(), nextdevice.getDevice_code()); + this.execute_log.log("目标设备:" + nextdevice.getDevice_code() + "设备未待机,任务号:" + taskcode); + continue; + } + + if (StrUtil.equals(acsTask.getTask_type(), TaskTypeEnum.APPLY_EMPTY.getCode())) { + int nowNumber = standardEmptsyPalletSiteDeviceDriver.getNumber(); + start_point_code = start_point_code + "." + nowNumber; + } + } + + //目的点校验 + if (nextdevice.getDeviceDriver() instanceof StandardInspectSiteDeviceDriver) { + standardInspectSiteDeviceDriver = (StandardInspectSiteDeviceDriver) nextdevice.getDeviceDriver(); + if (standardInspectSiteDeviceDriver.getMode() != 2) { + log.info("目标设备:" + nextdevice.getDevice_code() + "设备未待机,任务号:" + taskcode); + acsTask.setRemark("目标设备:" + nextdevice.getDevice_code() + "设备未待机,任务号:" + taskcode); + taskserver.updateByCodeFromCache(acsTask); + this.execute_log.setResource(nextdevice.getDevice_code(), nextdevice.getDevice_code()); + this.execute_log.log("目标设备:" + nextdevice.getDevice_code() + "设备未待机,任务号:" + taskcode); + continue; + } + if (standardInspectSiteDeviceDriver.getMove() != 0) { + log.info("目标设备:" + nextdevice.getDevice_code() + "设备不满足放货条件,任务号:" + taskcode); + acsTask.setRemark("目标设备:" + nextdevice.getDevice_code() + "设备不满足放货条件,任务号:" + taskcode); + taskserver.updateByCodeFromCache(acsTask); + this.execute_log.setResource(nextdevice.getDevice_code(), nextdevice.getDevice_code()); + this.execute_log.log("目标设备:" + nextdevice.getDevice_code() + "设备不满足放货条件,任务号:" + taskcode); + continue; + } + if (startdevice.getDeviceDriver() instanceof StandardEmptyPalletSiteDeviceDriver) { + standardEmptsyPalletSiteDeviceDriver = (StandardEmptyPalletSiteDeviceDriver) startdevice.getDeviceDriver(); + if (next_device_code.equals("Q1") || next_device_code.equals("P1")) { + int number = standardEmptsyPalletSiteDeviceDriver.getNumber(); + start_device_code = start_device_code + "." + number; + start_point_code = start_point_code + "." + number; + } + } + } + + if (nextdevice.getDeviceDriver() instanceof StandardManipulatorInspectSiteDeviceDriver) { + standardManipulatorInspectSiteDeviceDriver = (StandardManipulatorInspectSiteDeviceDriver) nextdevice.getDeviceDriver(); + if (standardManipulatorInspectSiteDeviceDriver.getMode() != 2) { + log.info("目标设备:" + nextdevice.getDevice_code() + "设备未待机,任务号:" + taskcode); + acsTask.setRemark("目标设备:" + nextdevice.getDevice_code() + "设备未待机,任务号:" + taskcode); + taskserver.updateByCodeFromCache(acsTask); + this.execute_log.setResource(nextdevice.getDevice_code(), nextdevice.getDevice_code()); + this.execute_log.log("目标设备:" + nextdevice.getDevice_code() + "设备未待机,任务号:" + taskcode); + continue; + } + if (standardManipulatorInspectSiteDeviceDriver.getMove() != 0) { + log.info("目标设备:" + nextdevice.getDevice_code() + "设备不满足放货条件,任务号:" + taskcode); + acsTask.setRemark("目标设备:" + nextdevice.getDevice_code() + "设备不满足放货条件,任务号:" + taskcode); + taskserver.updateByCodeFromCache(acsTask); + this.execute_log.setResource(nextdevice.getDevice_code(), nextdevice.getDevice_code()); + this.execute_log.log("目标设备:" + nextdevice.getDevice_code() + "设备不满足放货条件,任务号:" + taskcode); + continue; + } + } + + + if (nextdevice.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { + standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) nextdevice.getDeviceDriver(); + if (standardOrdinarySiteDeviceDriver.getHasGoods() != 0) { + log.info("目标设备:" + nextdevice.getDevice_code() + "有货,无法生成任务,任务号:" + taskcode); + acsTask.setRemark("目标设备:" + nextdevice.getDevice_code() + "有货,无法生成任务,任务号:" + taskcode); + taskserver.updateByCodeFromCache(acsTask); + this.execute_log.setResource(nextdevice.getDevice_code(), nextdevice.getDevice_code()); + this.execute_log.log("目标设备:" + nextdevice.getDevice_code() + "有货,无法生成任务,任务号:" + taskcode); + continue; + } + } + + //校验 是否同任务是否存在相同终点、未完成的指令 + int sameqty = instructionService.querySameDestinationInst(next_point_code); + if (sameqty > 0) { + log.info("存在相同终点的指令,任务号:" + taskcode); + acsTask.setRemark("存在相同终点的指令,任务号:" + taskcode); + taskserver.updateByCodeFromCache(acsTask); + this.execute_log.setResource(nextdevice.getDevice_code(), nextdevice.getDevice_code()); + this.execute_log.log("存在相同终点的指令,任务号:" + taskcode); + continue; + } } - if (standardInspectSiteDeviceDriver.getMove() != 0) { - log.info("目标设备:" + nextdevice.getDevice_code() + "设备不满足放货条件,任务号:" + taskcode); - acsTask.setRemark("目标设备:" + nextdevice.getDevice_code() + "设备不满足放货条件,任务号:" + taskcode); - taskserver.updateByCodeFromCache(acsTask); - this.execute_log.setResource(nextdevice.getDevice_code(), nextdevice.getDevice_code()); - this.execute_log.log("目标设备:" + nextdevice.getDevice_code() + "设备不满足放货条件,任务号:" + taskcode); - continue; + + //空盘位生成指令需要另外逻辑 + if (nextdevice.getDeviceDriver() instanceof StandardEmptyPalletSiteDeviceDriver) { + standardEmptsyPalletSiteDeviceDriver = (StandardEmptyPalletSiteDeviceDriver) nextdevice.getDeviceDriver(); + if (standardEmptsyPalletSiteDeviceDriver.getMode() != 2) { + log.info(("目标设备:" + nextdevice.getDevice_code() + "设备未待机,任务号:" + taskcode)); + acsTask.setRemark("目标设备:" + nextdevice.getDevice_code() + "设备未待机"); + taskserver.updateByCodeFromCache(acsTask); + this.execute_log.setResource(nextdevice.getDevice_code(), nextdevice.getDevice_code()); + this.execute_log.log("目标设备:" + nextdevice.getDevice_code() + "设备未待机,任务号:" + taskcode); + continue; + } + int max_emptypalletnum = Integer.parseInt(nextdevice.getExtraValue().get("max_emptypalletnum").toString()); + int nowNumber = standardEmptsyPalletSiteDeviceDriver.getNumber(); + if (nowNumber == max_emptypalletnum) { + log.info("目标设备:" + nextdevice.getDevice_code() + "空盘位已满等待入库,任务号:" + taskcode); + acsTask.setRemark("目标设备:" + nextdevice.getDevice_code() + "空盘位已满等待入库,任务号:" + taskcode); + taskserver.updateByCodeFromCache(acsTask); + this.execute_log.setResource(nextdevice.getDevice_code(), nextdevice.getDevice_code()); + this.execute_log.log("目标设备:" + nextdevice.getDevice_code() + "空盘位已满等待入库,任务号:" + taskcode); + continue; + } + // 查看是否有相同终点的指令 + int sameqty = instructionService.querySameDestinationInst(next_point_code); + if (sameqty > 0) { + log.info("存在相同终点的指令,任务号:" + taskcode); + acsTask.setRemark("存在相同终点的指令,任务号:" + taskcode); + taskserver.updateByCodeFromCache(acsTask); + this.execute_log.setResource(nextdevice.getDevice_code(), nextdevice.getDevice_code()); + this.execute_log.log("存在相同终点的指令,任务号:" + taskcode); + continue; + } + next_point_code = next_point_code + "." + (nowNumber + sameqty + 1); } - if (startdevice.getDeviceDriver() instanceof StandardEmptyPalletSiteDeviceDriver){ + if (startdevice.getDeviceDriver() instanceof StandardEmptyPalletSiteDeviceDriver) { standardEmptsyPalletSiteDeviceDriver = (StandardEmptyPalletSiteDeviceDriver) startdevice.getDeviceDriver(); - if (next_device_code.equals("Q1") || next_device_code.equals("P1")){ - int number = standardEmptsyPalletSiteDeviceDriver.getNumber(); - start_device_code = start_device_code + "." + number; - start_point_code = start_point_code + "." + number; + + int sameqty = instructionService.querySameOriginInst(start_point_code); + if (sameqty > 0) { + log.info("存在相同终点的指令,任务号:" + taskcode); + acsTask.setRemark("存在相同终点的指令,任务号:" + taskcode); + taskserver.updateByCodeFromCache(acsTask); + this.execute_log.setResource(nextdevice.getDevice_code(), nextdevice.getDevice_code()); + this.execute_log.log("存在相同终点的指令,任务号:" + taskcode); + continue; } - } - } - if (nextdevice.getDeviceDriver() instanceof StandardManipulatorInspectSiteDeviceDriver) { - standardManipulatorInspectSiteDeviceDriver = (StandardManipulatorInspectSiteDeviceDriver) nextdevice.getDeviceDriver(); - if (standardManipulatorInspectSiteDeviceDriver.getMode() != 2) { - log.info("目标设备:" + nextdevice.getDevice_code() + "设备未待机,任务号:" + taskcode); - acsTask.setRemark("目标设备:" + nextdevice.getDevice_code() + "设备未待机,任务号:" + taskcode); - taskserver.updateByCodeFromCache(acsTask); - this.execute_log.setResource(nextdevice.getDevice_code(), nextdevice.getDevice_code()); - this.execute_log.log("目标设备:" + nextdevice.getDevice_code() + "设备未待机,任务号:" + taskcode); - continue; - } - if (standardManipulatorInspectSiteDeviceDriver.getMove() != 0) { - log.info("目标设备:" + nextdevice.getDevice_code() + "设备不满足放货条件,任务号:" + taskcode); - acsTask.setRemark("目标设备:" + nextdevice.getDevice_code() + "设备不满足放货条件,任务号:" + taskcode); - taskserver.updateByCodeFromCache(acsTask); - this.execute_log.setResource(nextdevice.getDevice_code(), nextdevice.getDevice_code()); - this.execute_log.log("目标设备:" + nextdevice.getDevice_code() + "设备不满足放货条件,任务号:" + taskcode); - continue; + if (!StrUtil.equals(acsTask.getEmptypallet_num(), "0")) { + Integer.parseInt(acsTask.getEmptypallet_num()); + int num = standardEmptsyPalletSiteDeviceDriver.getNumber() - Integer.parseInt(acsTask.getEmptypallet_num()) + 1 - sameqty; + if (num <= 0) { + acsTask.setRemark("叠盘位可用空盘数量不足无法生成"); + taskserver.updateByCodeFromCache(acsTask); + continue; + } else { + start_point_code = start_point_code + "." + num; + } + } else { + //目的点校验 + if (nextdevice.getDeviceDriver() instanceof StandardInspectSiteDeviceDriver) { + standardInspectSiteDeviceDriver = (StandardInspectSiteDeviceDriver) nextdevice.getDeviceDriver(); + if (next_device_code.equals("Q1") || next_device_code.equals("P1")) { + int number = standardEmptsyPalletSiteDeviceDriver.getNumber(); + start_device_code = start_device_code + "." + number; + start_point_code = start_point_code + "." + number; + } + } else { + start_point_code = start_point_code + "." + 1; + } + } } - } - + Instruction instdto = new Instruction(); + instdto.setInstruction_type(acsTask.getTask_type()); + instdto.setInstruction_id(IdUtil.simpleUUID()); + instdto.setRoute_plan_code(route_plan_code); + instdto.setRemark(acsTask.getRemark()); + instdto.setMaterial(acsTask.getMaterial()); + instdto.setQuantity(acsTask.getQuantity()); + instdto.setTask_id(taskid); + instdto.setTask_code(taskcode); + instdto.setVehicle_code(vehiclecode); + instdto.setRoute_plan_code(route_plan_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(priority); + instdto.setInstruction_status("0"); + instdto.setExecute_device_code(start_point_code); + instdto.setVehicle_type(vehicleType); + instdto.setMaterial(acsTask.getMaterial()); - if (nextdevice.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { - standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) nextdevice.getDeviceDriver(); - if (standardOrdinarySiteDeviceDriver.getHasGoods() != 0) { - log.info("目标设备:" + nextdevice.getDevice_code() + "有货,无法生成任务,任务号:" + taskcode); - acsTask.setRemark("目标设备:" + nextdevice.getDevice_code() + "有货,无法生成任务,任务号:" + taskcode); + try { + instructionService.create(instdto); + } catch (Exception e) { + acsTask.setRemark(e.getMessage()); taskserver.updateByCodeFromCache(acsTask); - this.execute_log.setResource(nextdevice.getDevice_code(), nextdevice.getDevice_code()); - this.execute_log.log("目标设备:" + nextdevice.getDevice_code() + "有货,无法生成任务,任务号:" + taskcode); continue; } - } - //校验 是否同任务是否存在相同终点、未完成的指令 - int sameqty = instructionService.querySameDestinationInst(next_point_code); - if (sameqty > 0) { - log.info("存在相同终点的指令,任务号:" + taskcode); - acsTask.setRemark("存在相同终点的指令,任务号:" + taskcode); - taskserver.updateByCodeFromCache(acsTask); - this.execute_log.setResource(nextdevice.getDevice_code(), nextdevice.getDevice_code()); - this.execute_log.log("存在相同终点的指令,任务号:" + taskcode); - continue; - } - } + //创建指令后修改任务状态 + acsTask.setTask_status("1"); + taskserver.update(acsTask); - //空盘位生成指令需要另外逻辑 - if (nextdevice.getDeviceDriver() instanceof StandardEmptyPalletSiteDeviceDriver) { - standardEmptsyPalletSiteDeviceDriver = (StandardEmptyPalletSiteDeviceDriver) nextdevice.getDeviceDriver(); - if (standardEmptsyPalletSiteDeviceDriver.getMode() != 2) { - log.info(("目标设备:" + nextdevice.getDevice_code() + "设备未待机,任务号:" + taskcode)); - acsTask.setRemark("目标设备:" + nextdevice.getDevice_code() + "设备未待机"); - taskserver.updateByCodeFromCache(acsTask); - this.execute_log.setResource(nextdevice.getDevice_code(), nextdevice.getDevice_code()); - this.execute_log.log("目标设备:" + nextdevice.getDevice_code() + "设备未待机,任务号:" + taskcode); - continue; - } - int max_emptypalletnum = Integer.parseInt(nextdevice.getExtraValue().get("max_emptypalletnum").toString()); - int nowNumber = standardEmptsyPalletSiteDeviceDriver.getNumber(); - if (nowNumber == max_emptypalletnum) { - log.info("目标设备:" + nextdevice.getDevice_code() + "空盘位已满等待入库,任务号:" + taskcode); - acsTask.setRemark("目标设备:" + nextdevice.getDevice_code() + "空盘位已满等待入库,任务号:" + taskcode); - taskserver.updateByCodeFromCache(acsTask); - this.execute_log.setResource(nextdevice.getDevice_code(), nextdevice.getDevice_code()); - this.execute_log.log("目标设备:" + nextdevice.getDevice_code() + "空盘位已满等待入库,任务号:" + taskcode); - continue; } - // 查看是否有相同终点的指令 - int sameqty = instructionService.querySameDestinationInst(next_point_code); - if (sameqty > 0) { - log.info("存在相同终点的指令,任务号:" + taskcode); - acsTask.setRemark("存在相同终点的指令,任务号:" + taskcode); - taskserver.updateByCodeFromCache(acsTask); - this.execute_log.setResource(nextdevice.getDevice_code(), nextdevice.getDevice_code()); - this.execute_log.log("存在相同终点的指令,任务号:" + taskcode); - continue; + } finally { + if (lock) { + lock = false; } - next_point_code = next_point_code + "." + (nowNumber + sameqty + 1); } - if (startdevice.getDeviceDriver() instanceof StandardEmptyPalletSiteDeviceDriver) { - standardEmptsyPalletSiteDeviceDriver = (StandardEmptyPalletSiteDeviceDriver) startdevice.getDeviceDriver(); - - int sameqty = instructionService.querySameOriginInst(start_point_code); - if (sameqty > 0) { - log.info("存在相同终点的指令,任务号:" + taskcode); - acsTask.setRemark("存在相同终点的指令,任务号:" + taskcode); - taskserver.updateByCodeFromCache(acsTask); - this.execute_log.setResource(nextdevice.getDevice_code(), nextdevice.getDevice_code()); - this.execute_log.log("存在相同终点的指令,任务号:" + taskcode); - continue; - } - - if (!StrUtil.equals(acsTask.getEmptypallet_num(), "0")) { - Integer.parseInt(acsTask.getEmptypallet_num()); - int num = standardEmptsyPalletSiteDeviceDriver.getNumber() - Integer.parseInt(acsTask.getEmptypallet_num()) + 1 - sameqty; - if (num <= 0) { - acsTask.setRemark("叠盘位可用空盘数量不足无法生成"); - taskserver.updateByCodeFromCache(acsTask); - continue; - } else { - start_point_code = start_point_code + "." + num; - } - } else { - //目的点校验 - if (nextdevice.getDeviceDriver() instanceof StandardInspectSiteDeviceDriver) { - standardInspectSiteDeviceDriver = (StandardInspectSiteDeviceDriver) nextdevice.getDeviceDriver(); - if (next_device_code.equals("Q1") || next_device_code.equals("P1")){ - int number = standardEmptsyPalletSiteDeviceDriver.getNumber(); - start_device_code = start_device_code + "." + number; - start_point_code = start_point_code + "." + number; - } - } else { - start_point_code = start_point_code + "." + 1; - } - } - } - Instruction instdto = new Instruction(); - instdto.setInstruction_type(acsTask.getTask_type()); - instdto.setInstruction_id(IdUtil.simpleUUID()); - instdto.setRoute_plan_code(route_plan_code); - instdto.setRemark(acsTask.getRemark()); - instdto.setMaterial(acsTask.getMaterial()); - instdto.setQuantity(acsTask.getQuantity()); - instdto.setTask_id(taskid); - instdto.setTask_code(taskcode); - instdto.setVehicle_code(vehiclecode); - instdto.setRoute_plan_code(route_plan_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(priority); - instdto.setInstruction_status("0"); - instdto.setExecute_device_code(start_point_code); - instdto.setVehicle_type(vehicleType); - instdto.setMaterial(acsTask.getMaterial()); - - try { - instructionService.create(instdto); - } catch (Exception e) { - acsTask.setRemark(e.getMessage()); - taskserver.updateByCodeFromCache(acsTask); - continue; - } - - //创建指令后修改任务状态 - acsTask.setTask_status("1"); - taskserver.update(acsTask); - } } } diff --git a/hd/nladmin-system/src/main/java/org/nl/modules/quartz/task/QueryXZAgvTaskStatus.java b/hd/nladmin-system/src/main/java/org/nl/modules/quartz/task/QueryXZAgvTaskStatus.java index 34f5cd6..91fc20d 100644 --- a/hd/nladmin-system/src/main/java/org/nl/modules/quartz/task/QueryXZAgvTaskStatus.java +++ b/hd/nladmin-system/src/main/java/org/nl/modules/quartz/task/QueryXZAgvTaskStatus.java @@ -18,7 +18,7 @@ import org.springframework.stereotype.Component; * 查询AGV任务状态 */ @Slf4j -@Component +@Component("queryXZAgvTaskStatus") public class QueryXZAgvTaskStatus { @Autowired @@ -33,33 +33,23 @@ public class QueryXZAgvTaskStatus { @Autowired TaskService taskService; - private boolean lock = false; + private volatile boolean lock = false; public void run() throws Exception { - - if (!this.lock) { + if (!lock) { + lock = true; try { - this.lock = true; + HttpResponse response = agvService.queryXZAgvInstStatus(); JSONObject jo = JSONArray.parseObject(response.body()); JSONArray ja = JSONArray.parseArray(jo.getString("list")); for (int i = 0; i < ja.size(); i++) { - JSONObject one = ja.getJSONObject(i); + JSONObject one = (JSONObject) ja.get(i); String inst_code = one.getString("id"); - Instruction inst = instructionService.findByInstCodeFromCache(inst_code); - if (ObjectUtil.isEmpty(inst)) { + Instruction inst = instructionService.findByCodeFromCache(inst_code); + if (ObjectUtil.isEmpty(inst)) continue; - } -// //子任务状态 待以后处理 -// JSONArray blocks = JSONArray.parseArray(one.getString("blocks")); -// for(int j=0;j