diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_conveyor_control_with_scanner/StandardCoveyorControlWithScannerDeviceDriver.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_conveyor_control_with_scanner/StandardCoveyorControlWithScannerDeviceDriver.java index d3c6646f8..1ddc0e543 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_conveyor_control_with_scanner/StandardCoveyorControlWithScannerDeviceDriver.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_conveyor_control_with_scanner/StandardCoveyorControlWithScannerDeviceDriver.java @@ -728,7 +728,10 @@ public class StandardCoveyorControlWithScannerDeviceDriver extends AbstractOpcDe requireSucess = true; applySucess = false; } else { - message = jo.get("message").toString(); + if (jo.get("message")!=null){ + message = jo.get("message").toString(); + } + List list = new ArrayList(); Map map = new HashMap(); map.put("code","to_target"); 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 8b592e916..b14761d60 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 @@ -1,7 +1,5 @@ - package org.nl.acs.instruction.service.impl; - import cn.hutool.core.collection.ListUtil; import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.IdUtil; @@ -64,1411 +62,1462 @@ import java.util.stream.Collectors; * @author ldjun * @description 服务实现 * @date 2021-03-18 - **/ + */ @Service @RequiredArgsConstructor @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 void autoInitial() { + this.reload(); + } + + @Override + public synchronized void reload() { + Class var1 = TaskInstructionLock.class; + synchronized (TaskInstructionLock.class) { + this.instructions = this.queryAll("instruction_status <2 and is_delete =0"); + } + } + + @Override + public Map queryAll(Map whereJson, Pageable page) { + /*WQLObject wo = WQLObject.getWQLObject("acs_instruction"); + ResultBean rb = wo.pagequery(WqlUtil.getHttpContext(page), "instruction_status < 2 and is_delete =0 ", "update_time desc"); + */ + // this.reload(); + 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 synchronized void reload() { - Class var1 = TaskInstructionLock.class; - synchronized(TaskInstructionLock.class) { - this.instructions = this.queryAll("instruction_status <2 and is_delete =0"); + 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); + } + 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).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; } + } + return null; } - @Override - public Map queryAll(Map whereJson, Pageable page) { - /*WQLObject wo = WQLObject.getWQLObject("acs_instruction"); - ResultBean rb = wo.pagequery(WqlUtil.getHttpContext(page), "instruction_status < 2 and is_delete =0 ", "update_time desc"); - */ -// this.reload(); - 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 Instruction findByTaskid(String id, String wherecaluse) { + if (!StrUtil.isEmpty(wherecaluse)) { + wherecaluse = " and " + wherecaluse; } - - @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); - } - - final JSONObject jo = WQL.getWO("QINST_QUERY").addParamMap(map).pageQuery(WqlUtil.getHttpContext(page), "create_time desc"); - return jo; + 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 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 void create(Instruction dto) { + Class var2 = TaskInstructionLock.class; + synchronized (TaskInstructionLock.class) { + 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.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()); } - 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; - } + 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()); - @Override - public List queryAll(String whereJson) { - WQLObject wo = WQLObject.getWQLObject("acs_instruction"); - JSONArray arr = wo.query(whereJson).getResultJSONArray(0); - List list = arr.toJavaList(Instruction.class); - return list; - } + if (ObjectUtil.isNotEmpty(task.getTask_type())) { + dto.setInstruction_type(task.getTask_type()); + } - @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; + 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; + } } - 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; + if (ObjectUtil.isEmpty(route)) { + throw new BadRequestException("未查询到相关路由!"); } - 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; - } - } - 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) { - Class var2 = TaskInstructionLock.class; - synchronized(TaskInstructionLock.class) { - 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) { - + 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.setInstruction_type("3"); + dto.setSend_status("2"); } - - //查询是否存在相同指令号 -// 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()); - 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); - 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); + } } + } 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 { + Class var2 = TaskInstructionLock.class; + synchronized (TaskInstructionLock.class) { + 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 (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 { + Class var2 = TaskInstructionLock.class; + synchronized (TaskInstructionLock.class) { + 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) { + synchronized (TaskInstructionLock.class) { + 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()); - @Override - public void create2(Instruction dto) throws Exception { - Class var2 = TaskInstructionLock.class; - synchronized(TaskInstructionLock.class) { - dto = foramte(dto); - String task_code = dto.getTask_code(); - TaskDto task = taskService.findByCodeFromCache(task_code); + 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); - 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); - } + 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) { + Class var2 = TaskInstructionLock.class; + synchronized (TaskInstructionLock.class) { + String now = DateUtil.now(); + dto.setInstruction_status("2"); + WQLObject wo = WQLObject.getWQLObject("acs_instruction"); + JSONObject json = (JSONObject) JSONObject.toJSON(dto); - @Override - public void createAgain(Instruction dto) throws Exception { - Class var2 = TaskInstructionLock.class; - synchronized(TaskInstructionLock.class) { - 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); + 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 update(Instruction dto) { - Class var2 = TaskInstructionLock.class; - synchronized(TaskInstructionLock.class) { - 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); + @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()); + } + } - wo.update(json); + @Override + public void cancel(String id) throws Exception { + Class var2 = TaskInstructionLock.class; + synchronized (TaskInstructionLock.class) { + // 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()); + } -// Iterator iterator = instructions.iterator(); -// while (iterator.hasNext()) { -// Instruction instruction = iterator.next(); -// if (instruction.getInstruction_code().equals(dto.getInstruction_code())) { -// iterator.remove(); -// } -// } -// if (StrUtil.equals(dto.getInstruction_status(), "0") || StrUtil.equals(dto.getInstruction_status(), "1")) { -// instructions.add(dto); -// } - this.reload(); + // != 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; + } - @Override - @Transactional(rollbackFor = Exception.class) - public void deleteAll(String[] ids) throws Exception { - for (String instruction_id : ids) { - this.cancel(instruction_id); + 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); } - } - @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"); + entity.setInstruction_status("3"); WQLObject wo = WQLObject.getWQLObject("acs_instruction"); - String instnextdevice = entity.getNext_device_code(); - String insttaskid = entity.getTask_id(); - WQLObject taskwo = WQLObject.getWQLObject("acs_task"); + JSONObject json = (JSONObject) JSONObject.toJSON(entity); + wo.update(json); 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"); + 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 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); - } - } + 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(); + } + this.reload(); + } + } + + @Override + public void forceCancel(String id) throws Exception { + Class var2 = TaskInstructionLock.class; + synchronized (TaskInstructionLock.class) { + // 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 { + Class var2 = TaskInstructionLock.class; + synchronized (TaskInstructionLock.class) { + // 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) { + 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 - @Transactional(rollbackFor = Exception.class) - public void finish(Instruction dto) { - Class var2 = TaskInstructionLock.class; - synchronized(TaskInstructionLock.class) { - String now = DateUtil.now(); - dto.setInstruction_status("2"); - WQLObject wo = WQLObject.getWQLObject("acs_instruction"); - JSONObject json = (JSONObject) JSONObject.toJSON(dto); + return null; + } - 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 + 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); } - } - - @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 { - Class var2 = TaskInstructionLock.class; - synchronized(TaskInstructionLock.class) { - //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 { - Class var2 = TaskInstructionLock.class; - synchronized(TaskInstructionLock.class) { - //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()); - } - + } + return list; } - @Override - public void cancelNOSendAgv(String id) throws Exception { - Class var2 = TaskInstructionLock.class; - synchronized(TaskInstructionLock.class) { - //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 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; } + } + + 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; + } + } + return null; } - @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); - } - } + @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; + } + } + 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; + } + } + 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); + } } - @Override - public Instruction findByDeviceCodeFromCache(String devicecode) { + 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 { - List instructionList = instructions; - try { - 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; - } + 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) { + 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()); } - } catch (Exception e) { - log.warn("指令排序按照创建时间执执行失败!重新执行"); - //失败之后重新查找指令 - return findByDeviceCodeFromCache(devicecode); + }); + 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; + 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(".")); + } + if (StrUtil.equals(devicecode, next_code)) { + num = num + 1; + } + } + + return num; + } + } + + @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; + } + } + 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.equals(devicecode, start_code)) { + num = num + 1; + } + } + return num; } - @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) { - - Iterator iterator = instructions.iterator(); - while (iterator.hasNext()) { - Instruction instruction = iterator.next(); - if (instruction.getInstruction_code().equals(code)) { - iterator.remove(); - return true; - } - } - return 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; - } - } else { - dto.setSend_status("2"); - dto.setRemark("ERROR"); - return false; - } - return true; - } - } - - - public Instruction findByContainer(String container_code) { - Iterator var3 = instructions.iterator(); - - while (var3.hasNext()) { - Instruction instruction = (Instruction) var3.next(); - if (StrUtil.equals(instruction.getVehicle_code(), container_code)) { - return instruction; - } - } - - return null; - } - - /* - * 判断是否为整数 - * @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); - } + @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; } + } + return 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; + } + } 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/service/impl/DeviceExecuteLogServiceImpl.java b/acs/nladmin-system/src/main/java/org/nl/acs/log/service/impl/DeviceExecuteLogServiceImpl.java index c1aa7c670..c31e5026b 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/log/service/impl/DeviceExecuteLogServiceImpl.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/log/service/impl/DeviceExecuteLogServiceImpl.java @@ -1,11 +1,10 @@ - package org.nl.acs.log.service.impl; - import cn.hutool.core.date.DateUtil; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.nl.acs.log.service.DeviceExecuteLogService; +import org.nl.acs.opc.OpcUtl; import org.slf4j.MDC; import org.springframework.stereotype.Service; @@ -13,45 +12,41 @@ import org.springframework.stereotype.Service; * @author loujf * @description 服务实现 * @date 2022-02-25 - **/ + */ @Service @RequiredArgsConstructor @Slf4j public class DeviceExecuteLogServiceImpl implements DeviceExecuteLogService { + @Override + public void deviceItemValue(String device_code, String key, String value) { + String now = DateUtil.now(); + } - @Override - public void deviceItemValue(String device_code, String key, String value) { - String now = DateUtil.now(); - - + @Override + public void deviceExecuteLog( + String device_code, String vehicle_code, String inst_code, String message) { + try { + MDC.put("device_code_log", device_code); + log.info("{},{}", device_code, message); + } catch (Exception e) { + e.printStackTrace(); + } finally { + MDC.remove("device_code_log"); + System.out.println("successNum:" + OpcUtl.successNum); + System.out.println("errNum:" + OpcUtl.errNum); } + } - @Override - public void deviceExecuteLog(String device_code, String vehicle_code, String inst_code, String message) { - try { - MDC.put("device_code_log", device_code); - log.info("{},{}", device_code, message); - } catch (Exception e){ - e.printStackTrace(); - } - - finally { - MDC.remove("device_code_log"); - } - } - - @Override - public void extLog(String name, String message) { - try { - MDC.put(name, name); - log.info("{}", message); - } catch (Exception e){ - e.printStackTrace(); - } finally { - MDC.remove(name); - } + @Override + public void extLog(String name, String message) { + try { + MDC.put(name, name); + log.info("{}", message); + } catch (Exception e) { + e.printStackTrace(); + } finally { + MDC.remove(name); } + } } - - diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/opc/OpcUtl.java b/acs/nladmin-system/src/main/java/org/nl/acs/opc/OpcUtl.java index efa8113be..3a8accea4 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/opc/OpcUtl.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/opc/OpcUtl.java @@ -18,10 +18,14 @@ import java.util.concurrent.Executors; @Slf4j public class OpcUtl { - private static int timeout = 300000; + private static int timeout = 1*60*1000; private static String key = "rpc.socketTimeout"; - private static int successNum=0; - private static int errNum=0; + public static int successNum=0; + public static int errNum=0; + + static { + checkTimeout(); + } public static void checkTimeout() { if (Integer.getInteger(key, 0).intValue() != timeout) { 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 5257ec240..a54ed1430 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 @@ -82,7 +82,7 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { @Override public void autoInitial() throws Exception { Class var1 = TaskInstructionLock.class; - synchronized(TaskInstructionLock.class) { + synchronized (TaskInstructionLock.class) { this.reload(); } } @@ -138,6 +138,9 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { @Override public Map queryAllByCache(Map whereJson, Pageable page) { + synchronized (TaskServiceImpl.class){ + + this.reload(); String task_code = (String) whereJson.get("task_code"); String vehicle_code = (String) whereJson.get("vehicle_code"); @@ -201,6 +204,7 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { jo.put("content", taskDtoList); jo.put("totalElements", taskList.size()); return jo; + } } @Override @@ -288,107 +292,119 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { @Override public List queryTaskByDeviceCode(String device_code) { - List list = new ArrayList<>(); - Iterator iterator = tasks.iterator(); - while (iterator.hasNext()) { - TaskDto task = iterator.next(); - if (task.getStart_device_code().equals(device_code) - && StrUtil.equals(task.getTask_status(), "0")) { - list.add(task); + synchronized (TaskServiceImpl.class) { + List list = new ArrayList<>(); + Iterator iterator = tasks.iterator(); + while (iterator.hasNext()) { + TaskDto task = iterator.next(); + if (task.getStart_device_code().equals(device_code) + && StrUtil.equals(task.getTask_status(), "0")) { + list.add(task); + } } + return list; } - return list; } @Override public List queryTaskByStartDeviceCode(String start_device_code) { - List list = new ArrayList<>(); - Iterator iterator = tasks.iterator(); - while (iterator.hasNext()) { - TaskDto task = iterator.next(); - if (!StrUtil.equals(task.getTask_type(), "6")) { - continue; - } - if ((task.getStart_device_code().equals(start_device_code) - || task.getStart_device_code2().equals(start_device_code)) - && StrUtil.equals(task.getTask_status(), "0")) { - list.add(task); + synchronized (TaskServiceImpl.class) { + List list = new ArrayList<>(); + Iterator iterator = tasks.iterator(); + while (iterator.hasNext()) { + TaskDto task = iterator.next(); + if (!StrUtil.equals(task.getTask_type(), "6")) { + continue; + } + if ((task.getStart_device_code().equals(start_device_code) + || task.getStart_device_code2().equals(start_device_code)) + && StrUtil.equals(task.getTask_status(), "0")) { + list.add(task); + } } + return list; } - return list; } @Override public List queryTaskByBackDeviceCode(String back_start_device_code) { - List list = new ArrayList<>(); - Iterator iterator = tasks.iterator(); - while (iterator.hasNext()) { - TaskDto task = iterator.next(); - if (!StrUtil.equals(task.getTask_type(), "6")) { - continue; - } - if (task.getStart_device_code().equals(back_start_device_code) - && StrUtil.equals(task.getTask_status(), "0")) { - list.add(task); + synchronized (TaskServiceImpl.class) { + List list = new ArrayList<>(); + Iterator iterator = tasks.iterator(); + while (iterator.hasNext()) { + TaskDto task = iterator.next(); + if (!StrUtil.equals(task.getTask_type(), "6")) { + continue; + } + if (task.getStart_device_code().equals(back_start_device_code) + && StrUtil.equals(task.getTask_status(), "0")) { + list.add(task); + } } + return list; } - return list; } @Override public List queryTaskByDeviceCodeAndStatus(String device_code) { - List list = new ArrayList<>(); - Iterator iterator = tasks.iterator(); - while (iterator.hasNext()) { - TaskDto task = iterator.next(); - if (task.getStart_device_code().equals(device_code) - && StrUtil.equals(task.getTask_status(), "1")) { - Instruction instruction = instructionService.findByTaskcodeAndStatus(task.getTask_code()); - if (ObjectUtil.isNotEmpty(instruction)) { - list.add(task); + synchronized (TaskServiceImpl.class) { + List list = new ArrayList<>(); + Iterator iterator = tasks.iterator(); + while (iterator.hasNext()) { + TaskDto task = iterator.next(); + if (task.getStart_device_code().equals(device_code) + && StrUtil.equals(task.getTask_status(), "1")) { + Instruction instruction = instructionService.findByTaskcodeAndStatus(task.getTask_code()); + if (ObjectUtil.isNotEmpty(instruction)) { + list.add(task); + } } } + return list; } - return list; } public List queryTaskByStartAndIntStatus(String head_start_device_code) { - List list = new ArrayList<>(); - Iterator iterator = tasks.iterator(); - while (iterator.hasNext()) { - TaskDto task = iterator.next(); - if (!StrUtil.equals(task.getTask_type(), "6")) { - continue; - } - if ((task.getStart_device_code().equals(head_start_device_code) - || task.getStart_device_code2().equals(head_start_device_code)) - && StrUtil.equals(task.getTask_status(), "1")) { - Instruction instruction = instructionService.findByTaskcodeAndStatus(task.getTask_code()); - if (ObjectUtil.isNotEmpty(instruction)) { - list.add(task); + synchronized (TaskServiceImpl.class) { + List list = new ArrayList<>(); + Iterator iterator = tasks.iterator(); + while (iterator.hasNext()) { + TaskDto task = iterator.next(); + if (!StrUtil.equals(task.getTask_type(), "6")) { + continue; + } + if ((task.getStart_device_code().equals(head_start_device_code) + || task.getStart_device_code2().equals(head_start_device_code)) + && StrUtil.equals(task.getTask_status(), "1")) { + Instruction instruction = instructionService.findByTaskcodeAndStatus(task.getTask_code()); + if (ObjectUtil.isNotEmpty(instruction)) { + list.add(task); + } } } + return list; } - return list; } public List queryTaskByNextAndIntStatus(String back_start_device_code) { - List list = new ArrayList<>(); - Iterator iterator = tasks.iterator(); - while (iterator.hasNext()) { - TaskDto task = iterator.next(); - if (!StrUtil.equals(task.getTask_type(), "6")) { - continue; - } - if ((task.getStart_device_code().equals(back_start_device_code)) - && StrUtil.equals(task.getTask_status(), "1")) { - Instruction instruction = instructionService.findByTaskcodeAndStatus(task.getTask_code()); - if (ObjectUtil.isNotEmpty(instruction)) { - list.add(task); + synchronized (TaskServiceImpl.class) { + List list = new ArrayList<>(); + Iterator iterator = tasks.iterator(); + while (iterator.hasNext()) { + TaskDto task = iterator.next(); + if (!StrUtil.equals(task.getTask_type(), "6")) { + continue; + } + if ((task.getStart_device_code().equals(back_start_device_code)) + && StrUtil.equals(task.getTask_status(), "1")) { + Instruction instruction = instructionService.findByTaskcodeAndStatus(task.getTask_code()); + if (ObjectUtil.isNotEmpty(instruction)) { + list.add(task); + } } } + return list; } - return list; } @Override @@ -637,116 +653,118 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { @Override @Transactional(rollbackFor = Exception.class) public void update(TaskDto dto) { - TaskDto entity = this.findById(dto.getTask_id()); - if (entity == null) { - throw new BadRequestException("被删除或无权限,操作失败!"); - } - - String currentUsername = SecurityUtils.getCurrentUsername(); - String now = DateUtil.now(); - dto.setUpdate_time(now); - dto.setUpdate_by(currentUsername); - - WQLObject wo = WQLObject.getWQLObject("acs_task"); - JSONObject json = (JSONObject) JSONObject.toJSON(dto); - - wo.update(json); - - Iterator iterator = tasks.iterator(); - while (iterator.hasNext()) { - TaskDto task = iterator.next(); - if (task.getTask_code().equals(dto.getTask_code())) { - iterator.remove(); + synchronized (TaskServiceImpl.class) { + TaskDto entity = this.findById(dto.getTask_id()); + if (entity == null) { + throw new BadRequestException("被删除或无权限,操作失败!"); } - } - if (StrUtil.equals(dto.getTask_status(), "0") || StrUtil.equals(dto.getTask_status(), "1")) { - tasks.add(dto); - } - // 判断是否为WMS下发的任务,如果是反馈任务状态给WMS - String hasWms = paramService.findByCode(AcsConfig.HASWMS).getValue(); - if (!StrUtil.startWith(dto.getTask_code(), "-") && StrUtil.equals(hasWms, "1")) { - TaskFeedbackDto feefbackdto = taskFeedbackService.findByCode(entity.getTask_code()); - JSONObject feed_jo = new JSONObject(); - feed_jo.put("task_id", entity.getExt_task_id()); - feed_jo.put("task_code", dto.getTask_code()); - feed_jo.put("task_status", dto.getTask_status()); - JSONArray ja = new JSONArray(); - ja.add(feed_jo); - String message = null; - HttpResponse body = null; - boolean flag = false; - try { - body = acstowmsService.feedbackTaskStatusToWms(ja); - } catch (Exception e) { - flag = true; - message = e.getMessage(); - e.printStackTrace(); - } finally { - } - if (flag) { - if (ObjectUtil.isEmpty(feefbackdto)) { - feefbackdto = new TaskFeedbackDto(); - feefbackdto.setTask_id(entity.getTask_id()); - feefbackdto.setTask_code(entity.getTask_code()); - feefbackdto.setTask_status(entity.getTask_status()); - feefbackdto.setVehicle_type(entity.getVehicle_type()); - feefbackdto.setVehicle_code(entity.getVehicle_code()); - feefbackdto.setStart_device_code(entity.getStart_device_code()); - feefbackdto.setStart_point_code(entity.getStart_point_code()); - feefbackdto.setNext_device_code(entity.getNext_device_code()); - feefbackdto.setNext_point_code(entity.getNext_point_code()); - feefbackdto.setError_code("400"); - feefbackdto.setIs_finished("0"); - feefbackdto.setRemark(message); - taskFeedbackService.create(feefbackdto); - } else { - feefbackdto.setTask_status(entity.getTask_status()); - feefbackdto.setStart_device_code(entity.getStart_device_code()); - feefbackdto.setStart_point_code(entity.getStart_point_code()); - feefbackdto.setNext_device_code(entity.getNext_device_code()); - feefbackdto.setNext_point_code(entity.getNext_point_code()); - feefbackdto.setError_code("400"); - feefbackdto.setRemark(message); - taskFeedbackService.update(feefbackdto); + String currentUsername = SecurityUtils.getCurrentUsername(); + String now = DateUtil.now(); + dto.setUpdate_time(now); + dto.setUpdate_by(currentUsername); + + WQLObject wo = WQLObject.getWQLObject("acs_task"); + JSONObject json = (JSONObject) JSONObject.toJSON(dto); + + wo.update(json); + + Iterator iterator = tasks.iterator(); + while (iterator.hasNext()) { + TaskDto task = iterator.next(); + if (task.getTask_code().equals(dto.getTask_code())) { + iterator.remove(); } - } else { - int status = body.getStatus(); - JSONObject jo = JSONObject.parseObject(body.body()); - if (ObjectUtil.isEmpty(feefbackdto)) { - feefbackdto = new TaskFeedbackDto(); - feefbackdto.setTask_id(entity.getTask_id()); - feefbackdto.setTask_code(entity.getTask_code()); - feefbackdto.setTask_status(entity.getTask_status()); - feefbackdto.setVehicle_type(entity.getVehicle_type()); - feefbackdto.setVehicle_code(entity.getVehicle_code()); - feefbackdto.setError_code(String.valueOf(body.getStatus())); - feefbackdto.setStart_device_code(entity.getStart_device_code()); - feefbackdto.setStart_point_code(entity.getNext_point_code()); - feefbackdto.setNext_device_code(entity.getNext_device_code()); - feefbackdto.setNext_point_code(entity.getNext_point_code()); - if (status == 200) { - if (StrUtil.equals(entity.getTask_status(), "2")) { - feefbackdto.setIs_finished("1"); - } else { - feefbackdto.setIs_finished("0"); - } - } else { + } + if (StrUtil.equals(dto.getTask_status(), "0") || StrUtil.equals(dto.getTask_status(), "1")) { + tasks.add(dto); + } + // 判断是否为WMS下发的任务,如果是反馈任务状态给WMS + String hasWms = paramService.findByCode(AcsConfig.HASWMS).getValue(); + if (!StrUtil.startWith(dto.getTask_code(), "-") && StrUtil.equals(hasWms, "1")) { + TaskFeedbackDto feefbackdto = taskFeedbackService.findByCode(entity.getTask_code()); + JSONObject feed_jo = new JSONObject(); + feed_jo.put("task_id", entity.getExt_task_id()); + feed_jo.put("task_code", dto.getTask_code()); + feed_jo.put("task_status", dto.getTask_status()); + JSONArray ja = new JSONArray(); + ja.add(feed_jo); + String message = null; + HttpResponse body = null; + boolean flag = false; + try { + body = acstowmsService.feedbackTaskStatusToWms(ja); + } catch (Exception e) { + flag = true; + message = e.getMessage(); + e.printStackTrace(); + } finally { + + } + if (flag) { + if (ObjectUtil.isEmpty(feefbackdto)) { + feefbackdto = new TaskFeedbackDto(); + feefbackdto.setTask_id(entity.getTask_id()); + feefbackdto.setTask_code(entity.getTask_code()); + feefbackdto.setTask_status(entity.getTask_status()); + feefbackdto.setVehicle_type(entity.getVehicle_type()); + feefbackdto.setVehicle_code(entity.getVehicle_code()); + feefbackdto.setStart_device_code(entity.getStart_device_code()); + feefbackdto.setStart_point_code(entity.getStart_point_code()); + feefbackdto.setNext_device_code(entity.getNext_device_code()); + feefbackdto.setNext_point_code(entity.getNext_point_code()); + feefbackdto.setError_code("400"); feefbackdto.setIs_finished("0"); - feefbackdto.setRemark(jo.getString("message")); - } - taskFeedbackService.create(feefbackdto); - } else { - feefbackdto.setTask_status(entity.getTask_status()); - if (status == 200) { + feefbackdto.setRemark(message); + taskFeedbackService.create(feefbackdto); } else { - if (StrUtil.equals(entity.getTask_status(), "2")) { - feefbackdto.setIs_finished("1"); + feefbackdto.setTask_status(entity.getTask_status()); + feefbackdto.setStart_device_code(entity.getStart_device_code()); + feefbackdto.setStart_point_code(entity.getStart_point_code()); + feefbackdto.setNext_device_code(entity.getNext_device_code()); + feefbackdto.setNext_point_code(entity.getNext_point_code()); + feefbackdto.setError_code("400"); + feefbackdto.setRemark(message); + taskFeedbackService.update(feefbackdto); + } + } else { + int status = body.getStatus(); + JSONObject jo = JSONObject.parseObject(body.body()); + if (ObjectUtil.isEmpty(feefbackdto)) { + feefbackdto = new TaskFeedbackDto(); + feefbackdto.setTask_id(entity.getTask_id()); + feefbackdto.setTask_code(entity.getTask_code()); + feefbackdto.setTask_status(entity.getTask_status()); + feefbackdto.setVehicle_type(entity.getVehicle_type()); + feefbackdto.setVehicle_code(entity.getVehicle_code()); + feefbackdto.setError_code(String.valueOf(body.getStatus())); + feefbackdto.setStart_device_code(entity.getStart_device_code()); + feefbackdto.setStart_point_code(entity.getNext_point_code()); + feefbackdto.setNext_device_code(entity.getNext_device_code()); + feefbackdto.setNext_point_code(entity.getNext_point_code()); + if (status == 200) { + if (StrUtil.equals(entity.getTask_status(), "2")) { + feefbackdto.setIs_finished("1"); + } else { + feefbackdto.setIs_finished("0"); + } } else { feefbackdto.setIs_finished("0"); + feefbackdto.setRemark(jo.getString("message")); } + taskFeedbackService.create(feefbackdto); + } else { + feefbackdto.setTask_status(entity.getTask_status()); + if (status == 200) { + } else { + if (StrUtil.equals(entity.getTask_status(), "2")) { + feefbackdto.setIs_finished("1"); + } else { + feefbackdto.setIs_finished("0"); + } + } + taskFeedbackService.update(feefbackdto); } - taskFeedbackService.update(feefbackdto); } } } @@ -899,16 +917,16 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { wo.update(json); try { - Iterator it = tasks.iterator(); - // 清理缓存 - while (it.hasNext()){ - TaskDto taskDto = it.next(); - if (taskDto.getTask_id().equals(id)) { - tasks.remove(taskDto); - } + Iterator it = tasks.iterator(); + // 清理缓存 + while (it.hasNext()) { + TaskDto taskDto = it.next(); + if (taskDto.getTask_id().equals(id)) { + tasks.remove(taskDto); } + } } catch (Exception e) { - e.printStackTrace(); + e.printStackTrace(); } // 判断是否为WMS下发的任务,如果是反馈任务状态给WMS String hasWms = paramService.findByCode(AcsConfig.HASWMS).getValue(); @@ -1251,15 +1269,17 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { @Override public boolean removeByCodeFromCache(String code) { - Iterator iterator = tasks.iterator(); - while (iterator.hasNext()) { - TaskDto task = iterator.next(); - if (task.getTask_code().equals(code)) { - iterator.remove(); - return true; + synchronized (TaskServiceImpl.class) { + Iterator iterator = tasks.iterator(); + while (iterator.hasNext()) { + TaskDto task = iterator.next(); + if (task.getTask_code().equals(code)) { + iterator.remove(); + return true; + } } + return false; } - return false; } @Override @@ -1268,41 +1288,47 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { } public TaskDto findByContainer(String container_code) { - Iterator var3 = tasks.iterator(); + synchronized (TaskServiceImpl.class) { + Iterator var3 = tasks.iterator(); - while (var3.hasNext()) { - TaskDto task = (TaskDto) var3.next(); - if (StrUtil.equals(task.getVehicle_code(), container_code)) { - return task; + while (var3.hasNext()) { + TaskDto task = (TaskDto) var3.next(); + if (StrUtil.equals(task.getVehicle_code(), container_code)) { + return task; + } } - } - return null; + return null; + } } public TaskDto findByCodeFromCache(String task_code) { - Iterator var3 = tasks.iterator(); + synchronized (TaskServiceImpl.class) { + Iterator var3 = tasks.iterator(); - while (var3.hasNext()) { - TaskDto task = (TaskDto) var3.next(); - if (StrUtil.equals(task.getTask_code(), task_code)) { - return task; + while (var3.hasNext()) { + TaskDto task = (TaskDto) var3.next(); + if (StrUtil.equals(task.getTask_code(), task_code)) { + return task; + } } + return null; } - return null; } @Override public TaskDto findByNextCode(String device_code) { - Iterator var3 = tasks.iterator(); + synchronized (TaskServiceImpl.class) { + Iterator var3 = tasks.iterator(); - while (var3.hasNext()) { - TaskDto task = (TaskDto) var3.next(); - if (StrUtil.equals(task.getNext_device_code(), device_code)) { - return task; + while (var3.hasNext()) { + TaskDto task = (TaskDto) var3.next(); + if (StrUtil.equals(task.getNext_device_code(), device_code)) { + return task; + } } + return null; } - return null; } @Override @@ -1317,32 +1343,36 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { @Override public TaskDto findByStartCodeAndReady(String device_code) { - Iterator var3 = tasks.iterator(); + synchronized (TaskServiceImpl.class) { + Iterator var3 = tasks.iterator(); - while (var3.hasNext()) { - TaskDto task = (TaskDto) var3.next(); - // if (!StrUtil.equals(task.getTask_type(), "5")) { - // continue; - // } - if (StrUtil.equals(task.getStart_device_code(), device_code) - && StrUtil.equals(task.getTask_status(), "0")) { - return task; + while (var3.hasNext()) { + TaskDto task = (TaskDto) var3.next(); + // if (!StrUtil.equals(task.getTask_type(), "5")) { + // continue; + // } + if (StrUtil.equals(task.getStart_device_code(), device_code) + && StrUtil.equals(task.getTask_status(), "0")) { + return task; + } } + return null; } - return null; } @Override public TaskDto findByStartCode(String device_code) { - Iterator var3 = tasks.iterator(); + synchronized (TaskServiceImpl.class) { + Iterator var3 = tasks.iterator(); - while (var3.hasNext()) { - TaskDto task = (TaskDto) var3.next(); - if (StrUtil.equals(task.getStart_device_code(), device_code)) { - return task; + while (var3.hasNext()) { + TaskDto task = (TaskDto) var3.next(); + if (StrUtil.equals(task.getStart_device_code(), device_code)) { + return task; + } } + return null; } - return null; } @Override @@ -1484,14 +1514,16 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { @Override public void updateByCodeFromCache(TaskDto dto) { - Iterator iterator = tasks.iterator(); - while (iterator.hasNext()) { - TaskDto task = iterator.next(); - if (task.getTask_code().equals(dto.getTask_code())) { - iterator.remove(); + 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); } - tasks.add(dto); } @Override @@ -1537,59 +1569,67 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { @Override public Integer querySameDeviceReadyTask(String start_device, String next_device, String status) { - int num = 0; - Iterator iterator = tasks.iterator(); - while (iterator.hasNext()) { - TaskDto task = iterator.next(); - if (StrUtil.equals(task.getStart_device_code(), start_device) - && StrUtil.equals(task.getNext_device_code(), next_device) - && StrUtil.equals(task.getTask_status(), status)) { - num++; - } - } - - return num; - } - - @Override - public Integer querySameTaskByType(String taskType) { - int num = 0; - Iterator iterator = tasks.iterator(); - while (iterator.hasNext()) { - TaskDto task = iterator.next(); - if (task.getTask_type().equals(taskType) && task.getTask_status().equals("1")) { - num++; - } - } - - return num; - } - - @Override - public Integer querySameOriginTask(String code) { - int num = 0; - Iterator iterator = tasks.iterator(); - while (iterator.hasNext()) { - TaskDto task = iterator.next(); - if (StrUtil.equals(task.getStart_device_code(),code)) { - num++; - } - } - - return num; - } - - @Override - public Integer querySameDestinationTask(String code) { + synchronized (TaskServiceImpl.class) { int num = 0; Iterator iterator = tasks.iterator(); while (iterator.hasNext()) { TaskDto task = iterator.next(); - if (StrUtil.equals(task.getNext_device_code(),code)) { + if (StrUtil.equals(task.getStart_device_code(), start_device) + && StrUtil.equals(task.getNext_device_code(), next_device) + && StrUtil.equals(task.getTask_status(), status)) { num++; } } return num; + } + } + + @Override + public Integer querySameTaskByType(String taskType) { + synchronized (TaskServiceImpl.class) { + int num = 0; + Iterator iterator = tasks.iterator(); + while (iterator.hasNext()) { + TaskDto task = iterator.next(); + if (task.getTask_type().equals(taskType) && task.getTask_status().equals("1")) { + num++; + } + } + + return num; + } + } + + @Override + public Integer querySameOriginTask(String code) { + synchronized (TaskServiceImpl.class) { + int num = 0; + Iterator iterator = tasks.iterator(); + while (iterator.hasNext()) { + TaskDto task = iterator.next(); + if (StrUtil.equals(task.getStart_device_code(), code)) { + num++; + } + } + + return num; + } + } + + @Override + public Integer querySameDestinationTask(String code) { + synchronized (TaskServiceImpl.class) { + int num = 0; + Iterator iterator = tasks.iterator(); + while (iterator.hasNext()) { + TaskDto task = iterator.next(); + if (StrUtil.equals(task.getNext_device_code(), code)) { + num++; + } + } + + return num; + } } }