From 77ac88d8d4b06f08a5b115ce68c7cdc7e04a9b74 Mon Sep 17 00:00:00 2001 From: gengby <858962040@qq.com> Date: Mon, 6 Feb 2023 16:16:34 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/InstructionServiceImpl.java | 2728 +++++++++-------- .../task/service/impl/TaskServiceImpl.java | 10 +- 2 files changed, 1377 insertions(+), 1361 deletions(-) diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/instruction/service/impl/InstructionServiceImpl.java b/acs/nladmin-system/src/main/java/org/nl/acs/instruction/service/impl/InstructionServiceImpl.java index ebb514a99..e11f648ea 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/instruction/service/impl/InstructionServiceImpl.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/instruction/service/impl/InstructionServiceImpl.java @@ -53,6 +53,7 @@ import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.*; import java.util.concurrent.CopyOnWriteArrayList; +import java.util.function.Predicate; import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -66,1410 +67,1419 @@ import java.util.stream.Collectors; @Slf4j public class InstructionServiceImpl implements InstructionService, ApplicationAutoInitial { - List instructions = new CopyOnWriteArrayList(); + List instructions = new CopyOnWriteArrayList(); - @Autowired DeviceAppService deviceAppService; - @Autowired NDCAgvService ndcAgvService; - @Autowired ParamService paramService; - @Autowired RouteLineService routeLineService; - @Autowired TaskService taskService; - @Autowired AcsToLiKuService acsToLiKuService; + @Autowired + DeviceAppService deviceAppService; + @Autowired + NDCAgvService ndcAgvService; + @Autowired + ParamService paramService; + @Autowired + RouteLineService routeLineService; + @Autowired + TaskService taskService; + @Autowired + AcsToLiKuService acsToLiKuService; - @Override - public void autoInitial() { - this.reload(); - } - - @Override - public synchronized void reload() { - synchronized (TaskInstructionLock.class) { - this.instructions = this.queryAll("instruction_status <2 and is_delete =0"); - } - } - - @Override - public Map queryAll(Map whereJson, Pageable page) { - HashMap map = new HashMap<>(); - map.put("flag", "1"); - String code = (String) whereJson.get("code"); - String vehicle_code = (String) whereJson.get("vehicle_code"); - String material_type = (String) whereJson.get("material_type"); - String status = (String) whereJson.get("status"); - String point_code = (String) whereJson.get("point_code"); - String is_over = (String) whereJson.get("is_over"); - String instruction_type = (String) whereJson.get("instruction_type"); - if (!StrUtil.isEmpty(code)) { - map.put("code", code); - } - if (!StrUtil.isEmpty(vehicle_code)) { - map.put("vehicle_code", vehicle_code); - } - if (!StrUtil.isEmpty(material_type)) { - map.put("material_type", material_type); - } - if (!StrUtil.isEmpty(status)) { - map.put("status", status); - } - if (!StrUtil.isEmpty(point_code)) { - map.put("point_code", point_code); - } - if (!StrUtil.isEmpty(is_over)) { - map.put("is_over", is_over); - } - map.put("instruction_type", instruction_type); - - Integer currentPageNumber = page.getPageNumber() + 1; - Integer pageMaxSize = page.getPageSize(); - final JSONObject jo = - WQL.getWO("QINST_QUERY").addParamMap(map).pageQuery(WqlUtil.getHttpContext(page), ""); - JSONArray jsonArray = jo.getJSONArray("content"); - List instructions = jsonArray.toJavaList(Instruction.class); - List instDtoList = - instructions.stream() - .skip((currentPageNumber - 1) * pageMaxSize) - .limit(pageMaxSize) - .collect(Collectors.toList()); - jo.put("content", instDtoList); - jo.put("totalElements", jsonArray.size()); - return jo; - } - - @Override - public Map getAll(Map whereJson, Pageable page) { - HashMap map = new HashMap<>(); - map.put("flag", "2"); - String code = (String) whereJson.get("code"); - String vehicle_code = (String) whereJson.get("vehicle_code"); - String material_type = (String) whereJson.get("material_type"); - String status = (String) whereJson.get("status"); - String point_code = (String) whereJson.get("point_code"); - String create_time = (String) whereJson.get("createTime"); - String end_time = (String) whereJson.get("end_time"); - if (!StrUtil.isEmpty(code)) { - map.put("code", code); - } - if (!StrUtil.isEmpty(vehicle_code)) { - map.put("vehicle_code", vehicle_code); - } - if (!StrUtil.isEmpty(material_type)) { - map.put("material_type", material_type); - } - if (!StrUtil.isEmpty(status)) { - map.put("status", status); - } - if (!StrUtil.isEmpty(point_code)) { - map.put("point_code", point_code); - } - if (!StrUtil.isEmpty(create_time) && !StrUtil.isEmpty(end_time)) { - map.put("create_time", create_time); - map.put("end_time", end_time); + @Override + public void autoInitial() { + this.reload(); } - final JSONObject jo = - WQL.getWO("QINST_QUERY") - .addParamMap(map) - .pageQuery(WqlUtil.getHttpContext(page), "create_time desc"); - return jo; - } - - @Override - public Map getByTaskId(String id) { - WQLObject wo = WQLObject.getWQLObject("acs_instruction"); - JSONObject jsonObject = wo.query("task_id='" + id + "'").pageResult(); - JSONArray content = jsonObject.getJSONArray("content"); - JSONArray array = new JSONArray(); - for (int i = 0; i < content.size(); i++) { - JSONObject jo = (JSONObject) content.get(i); - JSONObject ins = new JSONObject(); - ins.put("task_id", jo.get("instruction_id")); - ins.put("task_code", jo.get("instruction_code")); - ins.put("task_status", jo.get("instruction_status")); - ins.put("start_point_code", jo.get("start_point_code")); - ins.put("next_point_code", jo.get("next_point_code")); - ins.put("matarial", jo.get("matarial")); - ins.put("remark", jo.get("remark")); - ins.put("create_by", jo.get("create_by")); - ins.put("create_time", jo.get("create_time")); - array.add(ins); + @Override + public synchronized void reload() { + List list = this.queryAll("instruction_status <2 and is_delete =0"); + this.instructions = new CopyOnWriteArrayList<>(list); } - jsonObject.put("content", array); - return jsonObject; - } - @Override - public List queryAll(Map whereJson) { - WQLObject wo = WQLObject.getWQLObject("acs_instruction"); - JSONArray arr = wo.query().getResultJSONArray(0); - List list = arr.toJavaList(Instruction.class); - return list; - } - - @Override - public List queryAll(String whereJson) { - WQLObject wo = WQLObject.getWQLObject("acs_instruction"); - JSONArray arr = wo.query(whereJson, "create_time").getResultJSONArray(0); - List list = arr.toJavaList(Instruction.class); - return list; - } - - @Override - public Instruction findById(String instruction_id) { - WQLObject wo = WQLObject.getWQLObject("acs_instruction"); - JSONObject json = wo.query("instruction_id ='" + instruction_id + "'").uniqueResult(0); - if (ObjectUtil.isNotEmpty(json)) { - final Instruction obj = json.toJavaObject(Instruction.class); - return obj; - } - return null; - } - - @Override - public Instruction findByCode(String code) { - WQLObject wo = WQLObject.getWQLObject("acs_instruction"); - JSONObject json = wo.query("instruction_code ='" + code + "'").uniqueResult(0); - if (ObjectUtil.isEmpty(json)) { - return null; - } - final Instruction obj = json.toJavaObject(Instruction.class); - return obj; - } - - @Override - public Instruction findByTaskcode(String code) { - WQLObject wo = WQLObject.getWQLObject("acs_instruction"); - JSONObject json = wo.query("task_code ='" + code + "'").uniqueResult(0); - final Instruction obj = json.toJavaObject(Instruction.class); - return obj; - } - - @Override - public Instruction findByTaskcodeAndStatus(String code) { - synchronized (InstructionServiceImpl.class) { - Iterator var3 = instructions.iterator(); - while (var3.hasNext()) { - Instruction instruction = (Instruction) var3.next(); - if (StrUtil.equals(instruction.getTask_code(), code) - && StrUtil.equals(instruction.getInstruction_status(), "0")) { - return instruction; + @Override + public Map queryAll(Map whereJson, Pageable page) { + HashMap map = new HashMap<>(); + map.put("flag", "1"); + String code = (String) whereJson.get("code"); + String vehicle_code = (String) whereJson.get("vehicle_code"); + String material_type = (String) whereJson.get("material_type"); + String status = (String) whereJson.get("status"); + String point_code = (String) whereJson.get("point_code"); + String is_over = (String) whereJson.get("is_over"); + String instruction_type = (String) whereJson.get("instruction_type"); + if (!StrUtil.isEmpty(code)) { + map.put("code", code); } - } - return null; - } - } - - @Override - public Instruction findByTaskid(String id, String wherecaluse) { - if (!StrUtil.isEmpty(wherecaluse)) { - wherecaluse = " and " + wherecaluse; - } - WQLObject wo = WQLObject.getWQLObject("acs_instruction"); - JSONObject json = wo.query("task_id ='" + id + "'" + wherecaluse).uniqueResult(0); - if (ObjectUtil.isNotEmpty(json)) { - return json.toJavaObject(Instruction.class); - } - return null; - } - - @Override - public void create(Instruction dto) { - dto = foramte(dto); - String task_code = dto.getTask_code(); - TaskDto task = taskService.findByCodeFromCache(task_code); - - String currentUsername = SecurityUtils.getCurrentUsername(); - String now = DateUtil.now(); - if (StrUtil.isEmpty(dto.getRoute_plan_code())) { - dto.setRoute_plan_code(task.getRoute_plan_code()); - } - if (StrUtil.isEmpty(dto.getPriority())) { - dto.setPriority(task.getPriority()); - } - if (StrUtil.isEmpty(dto.getInstruction_code())) { - dto.setInstruction_code(CodeUtil.getNewCode("INSTRUCT_NO")); - } - if (StrUtil.isEmpty(dto.getInstruction_id())) { - dto.setInstruction_id(IdUtil.simpleUUID()); - } - if (StrUtil.isEmpty(dto.getIs_send())) { - dto.setIs_send(task.getIs_send()); - } - if (StrUtil.isEmpty(dto.getLink_num())) { - dto.setIs_send(task.getLink_num()); - } - if (task.getTask_type().equals("1") || task.getTask_type().equals("2")) { - dto.setInstruction_type(task.getTask_type()); - } else if (false) { - - } else { - dto.setInstruction_type("3"); - } - - // 查询是否存在相同指令号 - // if (!StrUtil.isEmpty(dto.getVehicle_code() )) { - // Instruction inst_dto = findByContainer(dto.getVehicle_code()); - // if (inst_dto != null) { - // log.error("存在相同载具号任务,载具号"+dto.getVehicle_code()); - // throw new BadRequestException("存在相同载具号任务!"); - // } - // } - // 起点设备与终点设备相同则为初始指令 - if (StrUtil.equals(task.getStart_device_code(), dto.getStart_device_code())) { - if (!StrUtil.equals(dto.getCompound_inst(), "0") - && StrUtil.equals(task.getCompound_task(), "1")) { - dto.setCompound_inst("1"); - dto.setCompound_inst_data(task.getCompound_task_data()); - } - } - - dto.setCreate_by(currentUsername); - dto.setUpdate_by(currentUsername); - dto.setUpdate_time(now); - dto.setCreate_time(now); - dto.setStart_parent_code(task.getStart_parent_code()); - dto.setNext_parent_code(task.getNext_parent_code()); - - if (ObjectUtil.isNotEmpty(task.getTask_type())) { - dto.setInstruction_type(task.getTask_type()); - } - - DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); - Device startdevice = appService.findDeviceByCode(dto.getStart_device_code()); - - HongXiangConveyorDeviceDriver hongXiangConveyorDeviceDriver; - StandardCoveyorControlWithScannerDeviceDriver standardCoveyorControlWithScannerDeviceDriver; - - if (startdevice.getDeviceDriver() instanceof HongXiangConveyorDeviceDriver) { - hongXiangConveyorDeviceDriver = (HongXiangConveyorDeviceDriver) startdevice.getDeviceDriver(); - hongXiangConveyorDeviceDriver.writing(3, Integer.valueOf(dto.getInstruction_code())); - } - - try { - String start_device_code = dto.getStart_device_code(); - String next_device_code = dto.getNext_device_code(); - String route_plan_code = task.getRoute_plan_code(); - List shortPathsList = - routeLineService.getShortPathLines(start_device_code, next_device_code, route_plan_code); - RouteLineDto route = null; - for (int i = 0; i < shortPathsList.size(); i++) { - RouteLineDto routeLineDto = shortPathsList.get(i); - String route_device = routeLineDto.getDevice_code(); - String route_next_device = routeLineDto.getNext_device_code(); - if (route_device.equals(dto.getStart_device_code()) - && route_next_device.equals(dto.getNext_device_code())) { - route = routeLineDto; - break; + if (!StrUtil.isEmpty(vehicle_code)) { + map.put("vehicle_code", vehicle_code); } - } - if (ObjectUtil.isEmpty(route)) { - throw new BadRequestException("未查询到相关路由!"); - } - if (StrUtil.equals(shortPathsList.get(0).getType(), "1")) { - // 0为输送、立库任务 1 1楼叉车系统 2 2楼1区域AGV系统 3 2楼2区域AGV系统 - if (!StrUtil.equals(task.getAgv_system_type(), "0") - && ObjectUtil.isNotEmpty(task.getAgv_system_type())) { - NDCAgvService ndcAgvService = SpringContextHolder.getBean(NDCAgvService.class); - ndcAgvService.sendAgvInstToNDC(task.getAgv_system_type(), dto); - } else { - // Boolean result = createLkInst(task.getStorage_task_type(),dto); - Resp resp = acsToLiKuService.sendInst(task.getStorage_task_type(), dto); - if (StrUtil.equals(resp.result, "true")) { - dto.setSend_status("1"); - } else { - dto.setSend_status("2"); - } + if (!StrUtil.isEmpty(material_type)) { + map.put("material_type", material_type); } - } - } catch (Exception e) { - dto.setSend_status("2"); - e.printStackTrace(); - log.error(""); - } - - WQLObject wo = WQLObject.getWQLObject("acs_instruction"); - JSONObject json = (JSONObject) JSONObject.toJSON(dto); - - wo.insert(json); - instructions.add(dto); - } - - @Override - public void create2(Instruction dto) throws Exception { - dto = foramte(dto); - String task_code = dto.getTask_code(); - TaskDto task = taskService.findByCodeFromCache(task_code); - - WQLObject instwo = WQLObject.getWQLObject("acs_instruction"); - String currentUsername = SecurityUtils.getCurrentUsername(); - String now = DateUtil.now(); - if (StrUtil.isEmpty(dto.getRoute_plan_code())) { - dto.setRoute_plan_code(task.getRoute_plan_code()); - } - if (StrUtil.isEmpty(dto.getPriority())) { - dto.setPriority(task.getPriority()); - } - if (StrUtil.isEmpty(dto.getInstruction_code())) { - dto.setInstruction_code(CodeUtil.getNewCode("INSTRUCT_NO")); - } - if (StrUtil.isEmpty(dto.getInstruction_id())) { - dto.setInstruction_id(IdUtil.simpleUUID()); - } - if (StrUtil.isEmpty(dto.getIs_send())) { - dto.setIs_send(task.getIs_send()); - } - if (StrUtil.isEmpty(dto.getLink_num())) { - dto.setIs_send(task.getLink_num()); - } - if (task.getTask_type().equals("1") || task.getTask_type().equals("2")) { - dto.setInstruction_type(task.getTask_type()); - } else if (false) { - - } else { - dto.setInstruction_type("3"); - } - - // 起点设备与终点设备相同则为初始指令 - if (StrUtil.equals(task.getStart_device_code(), dto.getStart_device_code())) { - if (!StrUtil.equals(dto.getCompound_inst(), "0") - && StrUtil.equals(task.getCompound_task(), "1")) { - dto.setCompound_inst("1"); - dto.setCompound_inst_data(task.getCompound_task_data()); - } - } - - dto.setCreate_by(currentUsername); - dto.setUpdate_by(currentUsername); - dto.setUpdate_time(now); - dto.setCreate_time(now); - dto.setStart_parent_code(task.getStart_parent_code()); - dto.setNext_parent_code(task.getNext_parent_code()); - - if (ObjectUtil.isNotEmpty(task.getTask_type())) { - dto.setInstruction_type(task.getTask_type()); - } - - DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); - Device startdevice = appService.findDeviceByCode(dto.getStart_device_code()); - Device nextdevice = appService.findDeviceByCode(dto.getNext_device_code()); - - HongXiangConveyorDeviceDriver hongXiangConveyorDeviceDriver; - StandardCoveyorControlWithScannerDeviceDriver standardCoveyorControlWithScannerDeviceDriver; - - if (startdevice.getDeviceDriver() instanceof HongXiangConveyorDeviceDriver) { - hongXiangConveyorDeviceDriver = (HongXiangConveyorDeviceDriver) startdevice.getDeviceDriver(); - hongXiangConveyorDeviceDriver.writing(3, Integer.valueOf(dto.getInstruction_code())); - } - - try { - String start_device_code = dto.getStart_device_code(); - String next_device_code = dto.getNext_device_code(); - String route_plan_code = task.getRoute_plan_code(); - List shortPathsList = - routeLineService.getShortPathLines(start_device_code, next_device_code, route_plan_code); - RouteLineDto route = null; - for (int i = 0; i < shortPathsList.size(); i++) { - RouteLineDto routeLineDto = shortPathsList.get(i); - String route_device = routeLineDto.getDevice_code(); - String route_next_device = routeLineDto.getNext_device_code(); - if (route_device.equals(dto.getStart_device_code()) - && route_next_device.equals(dto.getNext_device_code())) { - route = routeLineDto; - break; + if (!StrUtil.isEmpty(status)) { + map.put("status", status); } - } - if (ObjectUtil.isEmpty(route)) { - throw new BadRequestException("未查询到相关路由!"); - } - if (StrUtil.equals(shortPathsList.get(0).getType(), "1")) { - // 0为输送、立库任务 1 1楼叉车系统 2 2楼1区域AGV系统 3 2楼2区域AGV系统 - if (!StrUtil.equals(task.getAgv_system_type(), "0") - && ObjectUtil.isNotEmpty(task.getAgv_system_type())) { - NDCAgvService ndcAgvService = SpringContextHolder.getBean(NDCAgvService.class); - ndcAgvService.sendAgvInstToNDC(task.getAgv_system_type(), dto); - } else { - // Boolean result = createLkInst(task.getStorage_task_type(),dto); + if (!StrUtil.isEmpty(point_code)) { + map.put("point_code", point_code); } - } - } catch (Exception e) { - dto.setSend_status("2"); - e.printStackTrace(); - } - - WQLObject wo = WQLObject.getWQLObject("acs_instruction"); - JSONObject json = (JSONObject) JSONObject.toJSON(dto); - - wo.insert(json); - instructions.add(dto); - } - - @Override - public void createAgain(Instruction dto) throws Exception { - String task_code = dto.getTask_code(); - TaskDto task = taskService.findByCodeFromCache(task_code); - WQLObject instwo = WQLObject.getWQLObject("acs_instruction"); - String currentUsername = SecurityUtils.getCurrentUsername(); - String now = DateUtil.now(); - if (StrUtil.isEmpty(dto.getRoute_plan_code())) { - dto.setRoute_plan_code(task.getRoute_plan_code()); - } - if (StrUtil.isEmpty(dto.getInstruction_code())) { - dto.setInstruction_code(CodeUtil.getNewCode("INSTRUCT_NO")); - } - if (StrUtil.isEmpty(dto.getInstruction_id())) { - dto.setInstruction_id(IdUtil.simpleUUID()); - } - List shortPathsList = - routeLineService.getShortPathLines( - dto.getStart_device_code(), dto.getNext_device_code(), dto.getRoute_plan_code()); - if (ObjectUtils.isEmpty(shortPathsList)) { - throw new Exception(dto.getStart_device_code() + "->" + dto.getNext_device_code() + "路由不通"); - } - String type = shortPathsList.get(0).getType(); - if (!StrUtil.equals(type, "0")) { - JSONObject instcheckjson = - instwo - .query( - " instruction_status <3 and next_point_code= '" - + dto.getNext_point_code() - + "'" - + " and start_point_code = '" - + dto.getStart_point_code() - + "'" - + " and task_id = '" - + dto.getTask_id() - + "'") - .uniqueResult(0); - if (instcheckjson != null) { - throw new Exception(dto.getTask_code() + ":该任务已存在待完成指令!"); - } - } - - if (!StrUtil.equals(dto.getCompound_inst(), "0") - && StrUtil.equals(task.getCompound_task(), "1")) { - dto.setCompound_inst("1"); - dto.setCompound_inst_data(task.getCompound_task_data()); - } - - dto.setCreate_by(currentUsername); - dto.setUpdate_by(currentUsername); - dto.setUpdate_time(now); - dto.setCreate_time(now); - - WQLObject wo = WQLObject.getWQLObject("acs_instruction"); - JSONObject json = (JSONObject) JSONObject.toJSON(dto); - - wo.insert(json); - - DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); - Device startdevice = appService.findDeviceByCode(dto.getStart_device_code()); - Device nextdevice = appService.findDeviceByCode(dto.getNext_device_code()); - - StandardInspectSiteDeviceDriver standardInspectSiteDeviceDriver; - StandardCoveyorControlWithScannerDeviceDriver standardCoveyorControlWithScannerDeviceDriver; - - if (!ObjectUtils.isEmpty(nextdevice.getExtraValue().get("link_three_lamp"))) { - String lamd_device = nextdevice.getExtraValue().get("link_three_lamp").toString(); - Device lamddevice = appService.findDeviceByCode(lamd_device); - } - - // != 0 为agv任务 - // if(!StrUtil.equals(type,"0")){ - // if (StrUtil.equals(paramService.findByCode(AcsConfig.AGVTYPE).getValue(), "1")) - // { - // agvService.sendAgvInstToMagic(dto); - // } else if (StrUtil.equals(paramService.findByCode(AcsConfig.AGVTYPE).getValue(), - // "2")) { - // agvService.sendAgvInstToNDC(dto); - // } else if (StrUtil.equals(paramService.findByCode(AcsConfig.AGVTYPE).getValue(), - // "3")) { - // agvService.addOrderSequences(dto); - // } - // } - instructions.add(dto); - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void update(Instruction dto) { - String currentUsername = SecurityUtils.getCurrentUsername(); - String now = DateUtil.now(); - dto.setUpdate_time(now); - dto.setUpdate_by(currentUsername); - WQLObject wo = WQLObject.getWQLObject("acs_instruction"); - JSONObject json = (JSONObject) JSONObject.toJSON(dto); - - wo.update(json); - - this.reload(); - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void deleteAll(String[] ids) throws Exception { - for (String instruction_id : ids) { - this.cancel(instruction_id); - } - } - - @Override - public void download(List all, HttpServletResponse response) throws IOException { - List> list = new ArrayList<>(); - for (Instruction instruction : all) { - Map map = new LinkedHashMap<>(); - map.put("任务标识", instruction.getTask_id()); - map.put("指令编码", instruction.getInstruction_code()); - map.put("指令由哪台设备做", instruction.getExecute_device_code()); - map.put("执行状态", instruction.getExecute_status()); - map.put("执行状态描述", instruction.getExecute_status_description()); - map.put("下一条指令由哪台设备做", instruction.getFollow_device_code()); - map.put("指令类型", instruction.getInstruction_type()); - map.put("指令状态", instruction.getInstruction_status()); - map.put("创建类型", instruction.getCreate_type()); - map.put("完成类型", instruction.getFinish_type()); - map.put("优先级", instruction.getPriority()); - map.put("执行编码", instruction.getExecute_code()); - map.put("执行信息", instruction.getExecute_message()); - map.put("起始点位编码", instruction.getStart_point_code()); - map.put("起始设备编码", instruction.getStart_device_code()); - map.put("目标点位编码", instruction.getNext_point_code()); - map.put("目标设备编码", instruction.getNext_device_code()); - map.put("排", instruction.getFrom_x()); - map.put("列", instruction.getFrom_y()); - map.put("层", instruction.getFrom_z()); - map.put("排", instruction.getTo_x()); - map.put("列", instruction.getTo_y()); - map.put("层", instruction.getTo_z()); - map.put("最后一条指令标识", instruction.getLast_instruction_id()); - map.put("是否允许修改", instruction.getCan_modify()); - map.put("备注", instruction.getRemark()); - map.put("是否启用", instruction.getIs_active()); - map.put("是否删除", instruction.getIs_delete()); - map.put("创建者", instruction.getCreate_by()); - map.put("创建时间", instruction.getCreate_time()); - map.put("修改者", instruction.getUpdate_by()); - map.put("修改时间", instruction.getUpdate_time()); - list.add(map); - } - FileUtil.downloadExcel(list, response); - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void finish(String id) { - Instruction entity = this.findById(id); - // if (entity == null) throw new BadRequestException("被删除或无权限,操作失败!"); - String currentUsername = SecurityUtils.getCurrentUsername(); - String now = DateUtil.now(); - entity.setUpdate_time(now); - entity.setUpdate_by(currentUsername); - entity.setInstruction_status("2"); - WQLObject wo = WQLObject.getWQLObject("acs_instruction"); - String instnextdevice = entity.getNext_device_code(); - String insttaskid = entity.getTask_id(); - WQLObject taskwo = WQLObject.getWQLObject("acs_task"); - DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); - Device startdevice = appService.findDeviceByCode(entity.getStart_device_code()); - if (ObjectUtils.isEmpty(startdevice)) { - log.debug("地址对应设备未找到"); - throw new BadRequestException("地址对应设备未找到"); - } - if (instnextdevice.indexOf(".") != -1) { - instnextdevice = instnextdevice.substring(0, instnextdevice.indexOf(".")); - } - Device device = appService.findDeviceByCode(instnextdevice); - if (device == null) { - log.debug("地址对应设备未找到"); - throw new BadRequestException("地址对应设备未找到"); - } - DeviceService deviceService = SpringContextHolder.getBean(DeviceServiceImpl.class); - - JSONObject jo1 = new JSONObject(); - jo1.put("device_code", instnextdevice); - - String start_device_code = entity.getStart_device_code(); - - Device deviceByCode = deviceAppService.findDeviceByCode(start_device_code); - if (deviceByCode == null) { - log.debug("地址对应设备未找到"); - throw new BadRequestException("地址对应设备未找到"); - } - - jo1.put("hasGoodStatus", "1"); - jo1.put("material_type", startdevice.getMaterial_type()); - - jo1.put("quantity", startdevice.getQuantity()); - jo1.put("remark", startdevice.getRemark()); - jo1.put("batch", startdevice.getBatch()); - jo1.put("vehicle_code", entity.getVehicle_code()); - jo1.put("islock", "0"); - jo1.put("barrels_code", startdevice.getBarrels_code()); - jo1.put("cooperate_code", startdevice.getCooperate_code()); - jo1.put("powder_name", startdevice.getPowder_name()); - jo1.put("barrels_status", startdevice.getBarrels_status()); - deviceService.changeDeviceStatus(jo1); - // 如果是无光电的设备 指令完成变更起点、终点状态 - JSONObject jo = new JSONObject(); - jo.put("device_code", entity.getStart_device_code()); - jo.put("hasGoodStatus", "0"); - jo.put("material_type", ""); - jo.put("quantity", ""); - jo.put("remark", ""); - jo.put("batch", ""); - jo.put("islock", "0"); - deviceService.changeDeviceStatus(jo); - - JSONObject json = (JSONObject) JSONObject.toJSON(entity); - wo.update(json); - JSONObject taskjson = taskwo.query("task_id ='" + insttaskid + "'").uniqueResult(0); - TaskDto obj = taskjson.toJavaObject(TaskDto.class); - // =0 则不用再次请求 - if (StrUtil.equals(obj.getRequest_again(), "0")) { - if (StrUtil.equals(obj.getNext_device_code(), instnextdevice)) { - taskService.finish(obj.getTask_id()); - } else { - finishAndCreateNextInst(entity); - } - } - - removeByCodeFromCache(entity.getInstruction_code()); - this.reload(); - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void finish(Instruction dto) { - String now = DateUtil.now(); - dto.setInstruction_status("2"); - WQLObject wo = WQLObject.getWQLObject("acs_instruction"); - JSONObject json = (JSONObject) JSONObject.toJSON(dto); - - wo.update(json); - String instnextdevice = dto.getNext_device_code(); - String insttaskid = dto.getTask_id(); - WQLObject taskwo = WQLObject.getWQLObject("acs_task"); - JSONObject taskjson = taskwo.query("task_id ='" + insttaskid + "'").uniqueResult(0); - TaskDto obj = taskjson.toJavaObject(TaskDto.class); - // =0 则不用再次请求 - if (StrUtil.equals(obj.getRequest_again(), "0")) { - if (StrUtil.equals(obj.getNext_device_code(), instnextdevice)) { - taskService.finish(obj.getTask_id()); - } else { - finishAndCreateNextInst(dto); - } - } - - DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); - DeviceService deviceService = SpringContextHolder.getBean(DeviceServiceImpl.class); - Device device = appService.findDeviceByCode(instnextdevice); - if (device == null) { - log.debug("地址对应设备未找到"); - return; - } - // 如果是无光电的设备 放货任务完成需要变更有货状态 - // StandardOrdinarySiteDeviceDriver standardOrdinarySiteDeviceDriver; - // if(device.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { - // standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) - // device.getDeviceDriver(); - // standardOrdinarySiteDeviceDriver.setMove(2); - // } - - // 如果是无光电的设备 指令完成变更起点、终点状态 - JSONObject jo = new JSONObject(); - jo.put("device_code", dto.getStart_point_code()); - jo.put("hasGoodStatus", "0"); - jo.put("material_type", ""); - jo.put("batch", ""); - deviceService.changeDeviceStatus(jo); - - JSONObject jo1 = new JSONObject(); - jo1.put("device_code", dto.getNext_point_code()); - jo1.put("hasGoodStatus", "1"); - jo1.put("material_type", dto.getMaterial()); - jo1.put("batch", dto.getBatch()); - deviceService.changeDeviceStatus(jo1); - - removeByCodeFromCache(dto.getInstruction_code()); - // this.reload(); - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void finishAndCreateNextInst(Instruction dto) { - dto = foramte(dto); - String device_code = dto.getNext_device_code(); - WQLObject taskwo = WQLObject.getWQLObject("acs_task"); - JSONObject taskjson = taskwo.query("task_id ='" + dto.getTask_id() + "'").uniqueResult(0); - TaskDto acsTask = taskjson.toJavaObject(TaskDto.class); - RouteLineService routeLineService = SpringContextHolder.getBean(RouteLineServiceImpl.class); - List list = - routeLineService.getShortPathLines( - dto.getNext_device_code(), acsTask.getNext_device_code(), acsTask.getRoute_plan_code()); - if (ObjectUtils.isEmpty(list)) { - throw new BadRequestException("路由不通"); - } - RouteLineDto routeLineDto = (RouteLineDto) list.get(0); - String[] path = routeLineDto.getPath().split("->"); - List pathlist = Arrays.asList(path); - int index = 0; - for (int m = 0; m < pathlist.size(); m++) { - if (pathlist.get(m).equals(dto.getNext_device_code())) { - index = m + 1; - break; - } - } - String next_device_code = pathlist.get(index); - String start_device_code = dto.getNext_device_code(); - String start_point_code = null; - String next_point_code = null; - String start_device = - deviceAppService - .findDeviceByCode(start_device_code) - .getDeviceDriverDefination() - .getFitDeviceTypes() - .get(0) - .name(); - String next_device = - deviceAppService - .findDeviceByCode(next_device_code) - .getDeviceDriverDefination() - .getFitDeviceTypes() - .get(0) - .name(); - if (StrUtil.equals("storage", start_device)) { - start_point_code = start_device_code + "-" + acsTask.getFrom_y() + "-" + acsTask.getFrom_z(); - } else { - start_point_code = start_device_code; - } - if (StrUtil.equals("storage", next_device)) { - next_point_code = next_device_code + "-" + acsTask.getTo_y() + "-" + acsTask.getTo_z(); - } else { - next_point_code = next_device_code; - } - Instruction instdto = new Instruction(); - instdto.setInstruction_id(IdUtil.simpleUUID()); - instdto.setRoute_plan_code(acsTask.getRoute_plan_code()); - instdto.setRemark(acsTask.getRemark()); - instdto.setMaterial(acsTask.getMaterial()); - instdto.setQuantity(acsTask.getQuantity()); - instdto.setTask_id(acsTask.getTask_id()); - instdto.setTask_code(acsTask.getTask_code()); - instdto.setVehicle_code(acsTask.getVehicle_code()); - String now = DateUtil.now(); - instdto.setCreate_time(now); - instdto.setCreate_by("auto"); - instdto.setStart_device_code(start_device_code); - instdto.setNext_device_code(next_device_code); - instdto.setStart_point_code(start_point_code); - instdto.setNext_point_code(next_point_code); - instdto.setPriority(acsTask.getPriority()); - instdto.setInstruction_status("0"); - instdto.setExecute_device_code(dto.getNext_device_code()); - try { - this.create(instdto); - } catch (Exception e) { - e.printStackTrace(); - log.error("完成并创建下一条指令", e.getMessage()); - } - } - - @Override - public void cancel(String id) throws Exception { - // flag= true时取消指令 - boolean flag = false; - Instruction entity = this.findById(id); - if (entity == null) { - throw new BadRequestException("被删除或无权限,操作失败!"); - } - TaskDto task = taskService.findByCodeFromCache(entity.getTask_code()); - if (StrUtil.isEmpty(entity.getRoute_plan_code())) { - entity.setRoute_plan_code(task.getRoute_plan_code()); - } - - // != 0 为agv任务 1=magic 2=NDC 3=XZ,4=ZHEDA - if (StrUtil.equals(paramService.findByCode(AcsConfig.AGVTYPE).getValue(), "1") - && !StrUtil.equals(entity.getSend_status(), "2")) { - MagicAgvService magicAgvService = SpringContextHolder.getBean(MagicAgvService.class); - magicAgvService.deleteAgvInst(entity.getInstruction_code()); - flag = true; - - } else if (StrUtil.equals(paramService.findByCode(AcsConfig.AGVTYPE).getValue(), "2")) { - // NDC agv指令不当场取消指令,需要等agv上报 - if (!StrUtil.isEmpty(entity.getAgv_jobno())) { - ndcAgvService.deleteAgvInstToNDC(entity); - } else { - flag = true; - } - } else if (StrUtil.equals(paramService.findByCode(AcsConfig.AGVTYPE).getValue(), "3") - && !StrUtil.equals(entity.getSend_status(), "2")) { - XianGongAgvService xianGongAgvService = SpringContextHolder.getBean(XianGongAgvService.class); - xianGongAgvService.deleteXZAgvInst(entity.getInstruction_code()); - flag = true; - } else { - flag = true; - } - - if (flag) { - - if (StrUtil.equals(entity.getInstruction_type(), "7")) { - CancelTaskRequest cancelTaskRequest = new CancelTaskRequest(); - cancelTaskRequest.setOrderId(entity.getInstruction_code()); - cancelTaskRequest.setPalletCode(entity.getVehicle_code()); - cancelTaskRequest.setSrcLocation(entity.getStart_point_code()); - cancelTaskRequest.setDestLocation(entity.getNext_point_code()); - // 1 入库,2 出库,3 移库,4 空托盘入库,5 空托盘出库 - int type = 0; - if (StrUtil.equals(task.getStorage_task_type(), "1")) { - type = 1; - } else if (StrUtil.equals(task.getStorage_task_type(), "2")) { - type = 4; - } else if (StrUtil.equals(task.getStorage_task_type(), "3")) { - type = 2; - } else if (StrUtil.equals(task.getStorage_task_type(), "4")) { - type = 5; - } else if (StrUtil.equals(task.getStorage_task_type(), "5")) { - type = 3; + if (!StrUtil.isEmpty(is_over)) { + map.put("is_over", is_over); } - cancelTaskRequest.setTaskType(type); - acsToLiKuService.cancelTask(cancelTaskRequest); - } + map.put("instruction_type", instruction_type); - String currentUsername = SecurityUtils.getCurrentUsername(); - String now = DateUtil.now(); - entity.setUpdate_time(now); - entity.setUpdate_by(currentUsername); - entity.setInstruction_status("3"); - WQLObject wo = WQLObject.getWQLObject("acs_instruction"); - JSONObject json = (JSONObject) JSONObject.toJSON(entity); - wo.update(json); - DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); - DeviceService deviceService = SpringContextHolder.getBean(DeviceServiceImpl.class); - - // 如果是无光电的设备 指令完成变更起点、终点状态 - JSONObject jo = new JSONObject(); - jo.put("device_code", entity.getStart_device_code()); - if (StrUtil.equals(entity.getMaterial(), "1")) { - jo.put("hasGoodStatus", "1"); - } else if (!StrUtil.equals(entity.getMaterial(), "1") - && !StrUtil.isEmpty(entity.getMaterial())) { - jo.put("hasGoodStatus", "2"); - } else { - jo.put("hasGoodStatus", "0"); - } - jo.put("material_type", entity.getMaterial()); - jo.put("batch", entity.getBatch()); - jo.put("islock", "false"); - deviceService.changeDeviceStatus(jo); - - JSONObject jo1 = new JSONObject(); - jo1.put("device_code", entity.getNext_device_code()); - jo.put("hasGoodStatus", "0"); - jo.put("material_type", ""); - jo.put("batch", ""); - jo1.put("islock", "false"); - deviceService.changeDeviceStatus(jo1); - - String instnextdevice = entity.getNext_device_code(); - Device device = appService.findDeviceByCode(instnextdevice); - if (device == null) { - log.debug("地址对应设备未找到"); - return; - } - removeByCodeFromCache(entity.getInstruction_code()); - } - this.reload(); - } - - @Override - public void forceCancel(String id) throws Exception { - // flag= true时取消指令 - boolean flag = false; - Instruction entity = this.findById(id); - if (entity == null) { - throw new BadRequestException("被删除或无权限,操作失败!"); - } - TaskDto task = taskService.findByCodeFromCache(entity.getTask_code()); - if (StrUtil.isEmpty(entity.getRoute_plan_code())) { - entity.setRoute_plan_code(task.getRoute_plan_code()); - } - String currentUsername = SecurityUtils.getCurrentUsername(); - String now = DateUtil.now(); - entity.setUpdate_time(now); - entity.setUpdate_by(currentUsername); - entity.setInstruction_status("3"); - WQLObject wo = WQLObject.getWQLObject("acs_instruction"); - JSONObject json = (JSONObject) JSONObject.toJSON(entity); - wo.update(json); - DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); - DeviceService deviceService = SpringContextHolder.getBean(DeviceServiceImpl.class); - // 如果是无光电的设备 指令完成变更起点、终点状态 - JSONObject jo = new JSONObject(); - jo.put("device_code", entity.getStart_device_code()); - if (StrUtil.equals(entity.getMaterial(), "1")) { - jo.put("hasGoodStatus", "1"); - } else if (!StrUtil.equals(entity.getMaterial(), "1") - && !StrUtil.isEmpty(entity.getMaterial())) { - jo.put("hasGoodStatus", "2"); - } else { - jo.put("hasGoodStatus", "0"); - } - jo.put("material_type", entity.getMaterial()); - jo.put("batch", entity.getBatch()); - jo.put("islock", "false"); - deviceService.changeDeviceStatus(jo); - - JSONObject jo1 = new JSONObject(); - jo1.put("device_code", entity.getNext_device_code()); - jo.put("hasGoodStatus", "0"); - jo.put("material_type", ""); - jo.put("batch", ""); - jo1.put("islock", "false"); - deviceService.changeDeviceStatus(jo1); - - String instnextdevice = entity.getNext_device_code(); - Device device = appService.findDeviceByCode(instnextdevice); - if (device == null) { - log.debug("地址对应设备未找到"); - return; - } - removeByCodeFromCache(entity.getInstruction_code()); - } - - @Override - public void cancelNOSendAgv(String id) throws Exception { - // flag= true时取消指令 - Instruction entity = this.findById(id); - if (entity == null) { - throw new BadRequestException("被删除或无权限,操作失败!"); - } - TaskDto task = taskService.findByCodeFromCache(entity.getTask_code()); - if (StrUtil.isEmpty(entity.getRoute_plan_code())) { - entity.setRoute_plan_code(task.getRoute_plan_code()); + Integer currentPageNumber = page.getPageNumber() + 1; + Integer pageMaxSize = page.getPageSize(); + final JSONObject jo = + WQL.getWO("QINST_QUERY").addParamMap(map).pageQuery(WqlUtil.getHttpContext(page), ""); + JSONArray jsonArray = jo.getJSONArray("content"); + List instructions = jsonArray.toJavaList(Instruction.class); + List instDtoList = + instructions.stream() + .skip((currentPageNumber - 1) * pageMaxSize) + .limit(pageMaxSize) + .collect(Collectors.toList()); + jo.put("content", instDtoList); + jo.put("totalElements", jsonArray.size()); + return jo; } - String currentUsername = SecurityUtils.getCurrentUsername(); - String now = DateUtil.now(); - entity.setUpdate_time(now); - entity.setUpdate_by(currentUsername); - entity.setInstruction_status("3"); - WQLObject wo = WQLObject.getWQLObject("acs_instruction"); - JSONObject json = (JSONObject) JSONObject.toJSON(entity); - wo.update(json); - DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); - DeviceService deviceService = SpringContextHolder.getBean(DeviceServiceImpl.class); - - // 如果是无光电的设备 指令完成变更起点、终点状态 - JSONObject jo = new JSONObject(); - jo.put("device_code", entity.getStart_device_code()); - if (StrUtil.equals(entity.getMaterial(), "1")) { - jo.put("hasGoodStatus", "1"); - } else if (!StrUtil.equals(entity.getMaterial(), "1") - && !StrUtil.isEmpty(entity.getMaterial())) { - jo.put("hasGoodStatus", "2"); - } else { - jo.put("hasGoodStatus", "0"); - } - jo.put("material_type", entity.getMaterial()); - jo.put("batch", entity.getBatch()); - jo.put("islock", "false"); - deviceService.changeDeviceStatus(jo); - - JSONObject jo1 = new JSONObject(); - jo1.put("device_code", entity.getNext_device_code()); - jo.put("hasGoodStatus", "0"); - jo.put("material_type", ""); - jo.put("batch", ""); - jo1.put("islock", "false"); - deviceService.changeDeviceStatus(jo1); - - String instnextdevice = entity.getNext_device_code(); - Device device = appService.findDeviceByCode(instnextdevice); - if (device == null) { - log.debug("地址对应设备未找到"); - return; - } - - removeByCodeFromCache(entity.getInstruction_code()); - } - - @Override - public Instruction findByLinkNumSend(String code) { - synchronized (InstructionServiceImpl.class) { - Iterator it = instructions.iterator(); - while (it.hasNext()) { - Instruction inst = it.next(); - if (StrUtil.equals(code, inst.getLink_num()) && StrUtil.equals(inst.getIs_send(), "1")) { - return inst; + @Override + public Map getAll(Map whereJson, Pageable page) { + HashMap map = new HashMap<>(); + map.put("flag", "2"); + String code = (String) whereJson.get("code"); + String vehicle_code = (String) whereJson.get("vehicle_code"); + String material_type = (String) whereJson.get("material_type"); + String status = (String) whereJson.get("status"); + String point_code = (String) whereJson.get("point_code"); + String create_time = (String) whereJson.get("createTime"); + String end_time = (String) whereJson.get("end_time"); + if (!StrUtil.isEmpty(code)) { + map.put("code", code); } - } - } - - return null; - } - - @Override - public List findByLinkNum(String code) { - synchronized (InstructionServiceImpl.class) { - List list = new ArrayList<>(); - Iterator it = instructions.iterator(); - while (it.hasNext()) { - Instruction inst = it.next(); - if (StrUtil.equals(code, inst.getLink_num()) && StrUtil.equals(inst.getIs_send(), "0")) { - list.add(inst); + if (!StrUtil.isEmpty(vehicle_code)) { + map.put("vehicle_code", vehicle_code); } - } - return list; - } - } - - @Override - public Instruction findByLinkNumNoSend(String code) { - synchronized (InstructionServiceImpl.class) { - Iterator it = instructions.iterator(); - while (it.hasNext()) { - Instruction inst = it.next(); - if (StrUtil.equals(code, inst.getLink_num()) && StrUtil.equals(inst.getIs_send(), "0")) { - return inst; + if (!StrUtil.isEmpty(material_type)) { + map.put("material_type", material_type); } - } - - return null; - } - } - - @Override - public Instruction findByCodeFromCache(String code) { - synchronized (InstructionServiceImpl.class) { - Iterator it = instructions.iterator(); - while (it.hasNext()) { - Instruction inst = it.next(); - if (StrUtil.equals(code, inst.getInstruction_code())) { - return inst; + if (!StrUtil.isEmpty(status)) { + map.put("status", status); } - } - return null; - } - } - - @Override - public Instruction findByBarcodeFromCache(String barcode) { - synchronized (InstructionServiceImpl.class) { - Iterator it = instructions.iterator(); - while (it.hasNext()) { - Instruction inst = it.next(); - if (StrUtil.equals(barcode, inst.getVehicle_code())) { - return inst; + if (!StrUtil.isEmpty(point_code)) { + map.put("point_code", point_code); } - } - return null; - } - } - - @Override - public Instruction findByIdFromCache(String id) { - synchronized (InstructionServiceImpl.class) { - Iterator it = instructions.iterator(); - while (it.hasNext()) { - Instruction inst = it.next(); - if (StrUtil.equals(id, inst.getInstruction_id())) { - return inst; + if (!StrUtil.isEmpty(create_time) && !StrUtil.isEmpty(end_time)) { + map.put("create_time", create_time); + map.put("end_time", end_time); } - } - return null; - } - } - @Override - public Instruction foramte(Instruction inst) { - String start_point_code = inst.getStart_point_code(); - String next_point_code = inst.getNext_point_code(); - String start_device_code = ""; - String next_device_code = ""; - if (StrUtil.contains(start_point_code, ".")) { - String[] point = start_point_code.split("\\."); - start_device_code = point[0]; - } else { - start_device_code = start_point_code; - } - if (StrUtil.contains(next_point_code, ".")) { - String[] point = next_point_code.split("\\."); - next_device_code = point[0]; - } else { - next_device_code = next_point_code; - } - if (StrUtil.contains(start_point_code, "-") && StrUtil.count(start_point_code, "-") == 2) { - String[] start_point = start_point_code.split("-"); - inst.setFrom_x(start_point[0]); - inst.setStart_device_code(start_point[0]); - inst.setFrom_y(start_point[1]); - inst.setFrom_z(start_point[2]); - } else { - String start_device = - deviceAppService - .findDeviceByCode(start_device_code) - .getDeviceDriverDefination() - .getFitDeviceTypes() - .get(0) - .name(); - if (StrUtil.equals("storage", start_device)) { - String[] start_point = start_point_code.split("-"); - inst.setFrom_x(start_point[0]); - inst.setStart_device_code(start_point[0]); - inst.setFrom_y(start_point[1]); - inst.setFrom_z(start_point[2]); - } else { - inst.setStart_device_code(start_device_code); - } + final JSONObject jo = + WQL.getWO("QINST_QUERY") + .addParamMap(map) + .pageQuery(WqlUtil.getHttpContext(page), "create_time desc"); + return jo; } - if (StrUtil.contains(next_point_code, "-") && StrUtil.count(next_point_code, "-") == 2) { - String[] next_point = next_point_code.split("-"); - inst.setTo_x(next_point[0]); - inst.setNext_device_code(next_point[0]); - inst.setTo_y(next_point[1]); - inst.setTo_z(next_point[2]); - } else { - - String next_device = - deviceAppService - .findDeviceByCode(next_device_code) - .getDeviceDriverDefination() - .getFitDeviceTypes() - .get(0) - .name(); - if (StrUtil.equals("storage", next_device)) { - String[] next_point = start_point_code.split("-"); - inst.setTo_x(next_point[0]); - inst.setNext_device_code(next_point[0]); - inst.setTo_y(next_point[1]); - inst.setTo_z(next_point[2]); - } else { - inst.setNext_device_code(next_device_code); - } + @Override + public Map getByTaskId(String id) { + WQLObject wo = WQLObject.getWQLObject("acs_instruction"); + JSONObject jsonObject = wo.query("task_id='" + id + "'").pageResult(); + JSONArray content = jsonObject.getJSONArray("content"); + JSONArray array = new JSONArray(); + for (int i = 0; i < content.size(); i++) { + JSONObject jo = (JSONObject) content.get(i); + JSONObject ins = new JSONObject(); + ins.put("task_id", jo.get("instruction_id")); + ins.put("task_code", jo.get("instruction_code")); + ins.put("task_status", jo.get("instruction_status")); + ins.put("start_point_code", jo.get("start_point_code")); + ins.put("next_point_code", jo.get("next_point_code")); + ins.put("matarial", jo.get("matarial")); + ins.put("remark", jo.get("remark")); + ins.put("create_by", jo.get("create_by")); + ins.put("create_time", jo.get("create_time")); + array.add(ins); + } + jsonObject.put("content", array); + return jsonObject; } - return inst; - } - @Override - public Instruction findByDeviceCodeFromCache(String devicecode) { - synchronized (InstructionServiceImpl.class) { - List instructionList = instructions; - ListUtil.sort( - instructionList, - new Comparator() { - @Override - public int compare(Instruction o1, Instruction o2) { - return o1.getCreate_time().compareTo(o2.getCreate_time()); + @Override + public List queryAll(Map whereJson) { + WQLObject wo = WQLObject.getWQLObject("acs_instruction"); + JSONArray arr = wo.query().getResultJSONArray(0); + List list = arr.toJavaList(Instruction.class); + return list; + } + + @Override + public List queryAll(String whereJson) { + WQLObject wo = WQLObject.getWQLObject("acs_instruction"); + JSONArray arr = wo.query(whereJson, "create_time").getResultJSONArray(0); + List list = arr.toJavaList(Instruction.class); + return list; + } + + @Override + public Instruction findById(String instruction_id) { + WQLObject wo = WQLObject.getWQLObject("acs_instruction"); + JSONObject json = wo.query("instruction_id ='" + instruction_id + "'").uniqueResult(0); + if (ObjectUtil.isNotEmpty(json)) { + final Instruction obj = json.toJavaObject(Instruction.class); + return obj; + } + return null; + } + + @Override + public Instruction findByCode(String code) { + WQLObject wo = WQLObject.getWQLObject("acs_instruction"); + JSONObject json = wo.query("instruction_code ='" + code + "'").uniqueResult(0); + if (ObjectUtil.isEmpty(json)) { + return null; + } + final Instruction obj = json.toJavaObject(Instruction.class); + return obj; + } + + @Override + public Instruction findByTaskcode(String code) { + WQLObject wo = WQLObject.getWQLObject("acs_instruction"); + JSONObject json = wo.query("task_code ='" + code + "'").uniqueResult(0); + final Instruction obj = json.toJavaObject(Instruction.class); + return obj; + } + + @Override + public Instruction findByTaskcodeAndStatus(String code) { + 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; + } } - }); - Iterator it = instructions.iterator(); - while (it.hasNext()) { - Instruction inst = it.next(); - if (StrUtil.equals(devicecode, inst.getStart_device_code()) - && inst.getInstruction_status().equals("0")) { - return inst; + return null; } - } } - return null; - } - - @Override - public List findAllInstFromCache() { - return instructions; - } - - @Override - public Integer querySameDestinationInst(String devicecode) { - synchronized (InstructionServiceImpl.class) { - int num = 0; - Iterator it = instructions.iterator(); - while (it.hasNext()) { - Instruction inst = it.next(); - // 处理空盘位站点 - String next_code = inst.getNext_point_code(); - if (next_code.indexOf(".") != -1) { - next_code = next_code.substring(0, next_code.indexOf(".")); + @Override + public Instruction findByTaskid(String id, String wherecaluse) { + if (!StrUtil.isEmpty(wherecaluse)) { + wherecaluse = " and " + wherecaluse; } - if (StrUtil.equals(devicecode, next_code)) { - num = num + 1; + WQLObject wo = WQLObject.getWQLObject("acs_instruction"); + JSONObject json = wo.query("task_id ='" + id + "'" + wherecaluse).uniqueResult(0); + if (ObjectUtil.isNotEmpty(json)) { + return json.toJavaObject(Instruction.class); } - } - - return num; + return null; } - } - @Override - public Integer querySameInstType(String inst_type) { - synchronized (InstructionServiceImpl.class) { - int num = 0; - Iterator it = instructions.iterator(); - while (it.hasNext()) { - Instruction inst = it.next(); - if (StrUtil.equals(inst.getInstruction_type(), inst_type)) { - num = num + 1; + @Override + public void create(Instruction dto) { + dto = foramte(dto); + String task_code = dto.getTask_code(); + TaskDto task = taskService.findByCodeFromCache(task_code); + + String currentUsername = SecurityUtils.getCurrentUsername(); + String now = DateUtil.now(); + if (StrUtil.isEmpty(dto.getRoute_plan_code())) { + dto.setRoute_plan_code(task.getRoute_plan_code()); } - } - return num; - } - } - - @Override - public Integer querySameOriginInst(String devicecode) { - synchronized (InstructionServiceImpl.class) { - int num = 0; - Iterator it = instructions.iterator(); - while (it.hasNext()) { - Instruction inst = it.next(); - // 处理空盘位站点 - String start_code = inst.getStart_point_code(); - if (start_code.indexOf(".") != -1) { - start_code = start_code.substring(0, start_code.indexOf(".")); + if (StrUtil.isEmpty(dto.getPriority())) { + dto.setPriority(task.getPriority()); } - if (StrUtil.equals(devicecode, start_code)) { - num = num + 1; + if (StrUtil.isEmpty(dto.getInstruction_code())) { + dto.setInstruction_code(CodeUtil.getNewCode("INSTRUCT_NO")); } - } - return num; - } - } - - @Override - public boolean removeByCodeFromCache(String code) { - synchronized (InstructionServiceImpl.class) { - Iterator iterator = instructions.iterator(); - while (iterator.hasNext()) { - Instruction instruction = iterator.next(); - if (instruction.getInstruction_code().equals(code)) { - iterator.remove(); - return true; + if (StrUtil.isEmpty(dto.getInstruction_id())) { + dto.setInstruction_id(IdUtil.simpleUUID()); } - } - return false; - } - } + if (StrUtil.isEmpty(dto.getIs_send())) { + dto.setIs_send(task.getIs_send()); + } + if (StrUtil.isEmpty(dto.getLink_num())) { + dto.setIs_send(task.getLink_num()); + } + if (task.getTask_type().equals("1") || task.getTask_type().equals("2")) { + dto.setInstruction_type(task.getTask_type()); + } else if (false) { - @Override - public boolean createLkInst(String type, Instruction dto) { - Class var3 = TaskInstructionLock.class; - synchronized (TaskInstructionLock.class) { - // 入库 - AcsToLiKuService acsToLiKuService = SpringContextHolder.getBean(AcsToLiKuService.class); - Resp resp = null; - if (StrUtil.equals(type, "1")) { - InStoreRequest request = new InStoreRequest(); - request.setFloorNo(Integer.parseInt(dto.getTo_z())); - request.setType(1); - request.setPalletCode(dto.getVehicle_code()); - request.setOrderId(dto.getInstruction_code()); - request.setSrcLocation(dto.getStart_point_code()); - request.setDestLocation(dto.getNext_point_code()); - resp = acsToLiKuService.inStore(request); - // 空托入库 - } else if (StrUtil.equals(type, "2")) { - InStoreRequest request = new InStoreRequest(); - request.setFloorNo(Integer.parseInt(dto.getTo_z())); - request.setType(2); - request.setPalletCode(dto.getVehicle_code()); - request.setOrderId(dto.getInstruction_code()); - request.setSrcLocation(dto.getStart_point_code()); - request.setDestLocation(dto.getNext_point_code()); - resp = acsToLiKuService.inStore(request); - // 出库 - } else if (StrUtil.equals(type, "3")) { - OutStoreRequest outStore = new OutStoreRequest(); - BaseStoreRequest baseReq = new BaseStoreRequest(); - List list = new ArrayList(); - baseReq.setOrderId(dto.getInstruction_code()); - baseReq.setSrcLocation(dto.getStart_point_code()); - baseReq.setDestLocation(dto.getNext_point_code()); - baseReq.setFloorNo(Integer.parseInt(dto.getFrom_z())); - baseReq.setPalletCode(dto.getVehicle_code()); - list.add(baseReq); - outStore.setOrderInfos(list); - outStore.setGroupId(dto.getInstruction_code()); - resp = acsToLiKuService.outStore(outStore); - // 空托出库 - } else if (StrUtil.equals(type, "4")) { - EmptyVehicleOutStoreRequest emptyVehicleOutStoreRequest = new EmptyVehicleOutStoreRequest(); - emptyVehicleOutStoreRequest.setOrderId(dto.getInstruction_code()); - emptyVehicleOutStoreRequest.setFloorNo(Integer.parseInt(dto.getFrom_z())); - emptyVehicleOutStoreRequest.setSrcLocation(dto.getStart_point_code()); - emptyVehicleOutStoreRequest.setDestLocation(dto.getNext_point_code()); - emptyVehicleOutStoreRequest.setPalletCode(dto.getVehicle_code()); - resp = acsToLiKuService.emptyVehicleOutStore(emptyVehicleOutStoreRequest); - // 转库 - } else if (StrUtil.equals(type, "5")) { - MoveStoreRequest moveStoreRequest = new MoveStoreRequest(); - BaseStoreRequest baseReq = new BaseStoreRequest(); - List list = new ArrayList(); - baseReq.setFloorNo(Integer.parseInt(dto.getFrom_z())); - baseReq.setPalletCode(dto.getVehicle_code()); - baseReq.setOrderId(dto.getInstruction_code()); - baseReq.setSrcLocation(dto.getStart_point_code()); - baseReq.setDestLocation(dto.getNext_point_code()); - list.add(baseReq); - moveStoreRequest.setGroupId(dto.getInstruction_code()); - moveStoreRequest.setOrderInfos(list); - resp = acsToLiKuService.moveStore(moveStoreRequest); - } - - if (ObjectUtil.isNotEmpty(resp)) { - if (StrUtil.equals(resp.getResult(), "true")) { - dto.setSend_status("1"); } else { - dto.setSend_status("2"); - dto.setRemark(resp.getData().toString()); - return false; + dto.setInstruction_type("3"); } - } else { - dto.setSend_status("2"); - dto.setRemark("ERROR"); - return false; - } - return true; - } - } - /* - * 判断是否为整数 - * @param str 传入的字符串 - * @return 是整数返回true,否则返回false - */ - public static boolean isInteger(String str) { - Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$"); - return pattern.matcher(str).matches(); - } + // 查询是否存在相同指令号 + // if (!StrUtil.isEmpty(dto.getVehicle_code() )) { + // Instruction inst_dto = findByContainer(dto.getVehicle_code()); + // if (inst_dto != null) { + // log.error("存在相同载具号任务,载具号"+dto.getVehicle_code()); + // throw new BadRequestException("存在相同载具号任务!"); + // } + // } + // 起点设备与终点设备相同则为初始指令 + if (StrUtil.equals(task.getStart_device_code(), dto.getStart_device_code())) { + if (!StrUtil.equals(dto.getCompound_inst(), "0") + && StrUtil.equals(task.getCompound_task(), "1")) { + dto.setCompound_inst("1"); + dto.setCompound_inst_data(task.getCompound_task_data()); + } + } - @Override - public void init(String id) { - Instruction inst = this.findById(id); - if (inst == null) { - throw new BadRequestException("指令不存在或已删除"); - } - if ("2".equals(inst.getInstruction_status())) { - throw new BadRequestException("指令已经完成"); + dto.setCreate_by(currentUsername); + dto.setUpdate_by(currentUsername); + dto.setUpdate_time(now); + dto.setCreate_time(now); + dto.setStart_parent_code(task.getStart_parent_code()); + dto.setNext_parent_code(task.getNext_parent_code()); + + if (ObjectUtil.isNotEmpty(task.getTask_type())) { + dto.setInstruction_type(task.getTask_type()); + } + + DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); + Device startdevice = appService.findDeviceByCode(dto.getStart_device_code()); + + HongXiangConveyorDeviceDriver hongXiangConveyorDeviceDriver; + StandardCoveyorControlWithScannerDeviceDriver standardCoveyorControlWithScannerDeviceDriver; + + if (startdevice.getDeviceDriver() instanceof HongXiangConveyorDeviceDriver) { + hongXiangConveyorDeviceDriver = (HongXiangConveyorDeviceDriver) startdevice.getDeviceDriver(); + hongXiangConveyorDeviceDriver.writing(3, Integer.valueOf(dto.getInstruction_code())); + } + + try { + String start_device_code = dto.getStart_device_code(); + String next_device_code = dto.getNext_device_code(); + String route_plan_code = task.getRoute_plan_code(); + List shortPathsList = + routeLineService.getShortPathLines(start_device_code, next_device_code, route_plan_code); + RouteLineDto route = null; + for (int i = 0; i < shortPathsList.size(); i++) { + RouteLineDto routeLineDto = shortPathsList.get(i); + String route_device = routeLineDto.getDevice_code(); + String route_next_device = routeLineDto.getNext_device_code(); + if (route_device.equals(dto.getStart_device_code()) + && route_next_device.equals(dto.getNext_device_code())) { + route = routeLineDto; + break; + } + } + if (ObjectUtil.isEmpty(route)) { + throw new BadRequestException("未查询到相关路由!"); + } + if (StrUtil.equals(shortPathsList.get(0).getType(), "1")) { + // 0为输送、立库任务 1 1楼叉车系统 2 2楼1区域AGV系统 3 2楼2区域AGV系统 + if (!StrUtil.equals(task.getAgv_system_type(), "0") + && ObjectUtil.isNotEmpty(task.getAgv_system_type())) { + NDCAgvService ndcAgvService = SpringContextHolder.getBean(NDCAgvService.class); + ndcAgvService.sendAgvInstToNDC(task.getAgv_system_type(), dto); + } else { + // Boolean result = createLkInst(task.getStorage_task_type(),dto); + Resp resp = acsToLiKuService.sendInst(task.getStorage_task_type(), dto); + if (StrUtil.equals(resp.result, "true")) { + dto.setSend_status("1"); + } else { + dto.setSend_status("2"); + } + } + } + } catch (Exception e) { + dto.setSend_status("2"); + e.printStackTrace(); + log.error(""); + } + + WQLObject wo = WQLObject.getWQLObject("acs_instruction"); + JSONObject json = (JSONObject) JSONObject.toJSON(dto); + + wo.insert(json); + instructions.add(dto); } - Device startDevice = deviceAppService.findDeviceByCode(inst.getStart_device_code()); - DeviceDriver startDeviceDriver = startDevice.getDeviceDriver(); - if (startDeviceDriver instanceof SiemensConveyorDeviceDriver) { - Device nextDevice = deviceAppService.findDeviceByCode(inst.getNext_device_code()); + @Override + public void create2(Instruction dto) throws Exception { + dto = foramte(dto); + String task_code = dto.getTask_code(); + TaskDto task = taskService.findByCodeFromCache(task_code); - List> list = new ArrayList<>(); - Map map = new HashMap<>(); - map.put("code", "to_target"); - map.put("value", nextDevice.getExtraValue().get("address").toString()); - list.add(map); - Map map2 = new HashMap<>(); - map2.put("code", "to_task"); - map2.put("value", inst.getInstruction_code()); - list.add(map2); - Map map3 = new HashMap<>(); - map3.put("code", "to_command"); - map3.put("value", "1"); - list.add(map3); - ((SiemensConveyorDeviceDriver) startDeviceDriver).writing(list); + WQLObject instwo = WQLObject.getWQLObject("acs_instruction"); + String currentUsername = SecurityUtils.getCurrentUsername(); + String now = DateUtil.now(); + if (StrUtil.isEmpty(dto.getRoute_plan_code())) { + dto.setRoute_plan_code(task.getRoute_plan_code()); + } + if (StrUtil.isEmpty(dto.getPriority())) { + dto.setPriority(task.getPriority()); + } + if (StrUtil.isEmpty(dto.getInstruction_code())) { + dto.setInstruction_code(CodeUtil.getNewCode("INSTRUCT_NO")); + } + if (StrUtil.isEmpty(dto.getInstruction_id())) { + dto.setInstruction_id(IdUtil.simpleUUID()); + } + if (StrUtil.isEmpty(dto.getIs_send())) { + dto.setIs_send(task.getIs_send()); + } + if (StrUtil.isEmpty(dto.getLink_num())) { + dto.setIs_send(task.getLink_num()); + } + if (task.getTask_type().equals("1") || task.getTask_type().equals("2")) { + dto.setInstruction_type(task.getTask_type()); + } else if (false) { + + } else { + dto.setInstruction_type("3"); + } + + // 起点设备与终点设备相同则为初始指令 + if (StrUtil.equals(task.getStart_device_code(), dto.getStart_device_code())) { + if (!StrUtil.equals(dto.getCompound_inst(), "0") + && StrUtil.equals(task.getCompound_task(), "1")) { + dto.setCompound_inst("1"); + dto.setCompound_inst_data(task.getCompound_task_data()); + } + } + + dto.setCreate_by(currentUsername); + dto.setUpdate_by(currentUsername); + dto.setUpdate_time(now); + dto.setCreate_time(now); + dto.setStart_parent_code(task.getStart_parent_code()); + dto.setNext_parent_code(task.getNext_parent_code()); + + if (ObjectUtil.isNotEmpty(task.getTask_type())) { + dto.setInstruction_type(task.getTask_type()); + } + + DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); + Device startdevice = appService.findDeviceByCode(dto.getStart_device_code()); + Device nextdevice = appService.findDeviceByCode(dto.getNext_device_code()); + + HongXiangConveyorDeviceDriver hongXiangConveyorDeviceDriver; + StandardCoveyorControlWithScannerDeviceDriver standardCoveyorControlWithScannerDeviceDriver; + + if (startdevice.getDeviceDriver() instanceof HongXiangConveyorDeviceDriver) { + hongXiangConveyorDeviceDriver = (HongXiangConveyorDeviceDriver) startdevice.getDeviceDriver(); + hongXiangConveyorDeviceDriver.writing(3, Integer.valueOf(dto.getInstruction_code())); + } + + try { + String start_device_code = dto.getStart_device_code(); + String next_device_code = dto.getNext_device_code(); + String route_plan_code = task.getRoute_plan_code(); + List shortPathsList = + routeLineService.getShortPathLines(start_device_code, next_device_code, route_plan_code); + RouteLineDto route = null; + for (int i = 0; i < shortPathsList.size(); i++) { + RouteLineDto routeLineDto = shortPathsList.get(i); + String route_device = routeLineDto.getDevice_code(); + String route_next_device = routeLineDto.getNext_device_code(); + if (route_device.equals(dto.getStart_device_code()) + && route_next_device.equals(dto.getNext_device_code())) { + route = routeLineDto; + break; + } + } + if (ObjectUtil.isEmpty(route)) { + throw new BadRequestException("未查询到相关路由!"); + } + if (StrUtil.equals(shortPathsList.get(0).getType(), "1")) { + // 0为输送、立库任务 1 1楼叉车系统 2 2楼1区域AGV系统 3 2楼2区域AGV系统 + if (!StrUtil.equals(task.getAgv_system_type(), "0") + && ObjectUtil.isNotEmpty(task.getAgv_system_type())) { + NDCAgvService ndcAgvService = SpringContextHolder.getBean(NDCAgvService.class); + ndcAgvService.sendAgvInstToNDC(task.getAgv_system_type(), dto); + } else { + // Boolean result = createLkInst(task.getStorage_task_type(),dto); + } + } + } catch (Exception e) { + dto.setSend_status("2"); + e.printStackTrace(); + } + + WQLObject wo = WQLObject.getWQLObject("acs_instruction"); + JSONObject json = (JSONObject) JSONObject.toJSON(dto); + + wo.insert(json); + instructions.add(dto); + } + + @Override + public void createAgain(Instruction dto) throws Exception { + String task_code = dto.getTask_code(); + TaskDto task = taskService.findByCodeFromCache(task_code); + WQLObject instwo = WQLObject.getWQLObject("acs_instruction"); + String currentUsername = SecurityUtils.getCurrentUsername(); + String now = DateUtil.now(); + if (StrUtil.isEmpty(dto.getRoute_plan_code())) { + dto.setRoute_plan_code(task.getRoute_plan_code()); + } + if (StrUtil.isEmpty(dto.getInstruction_code())) { + dto.setInstruction_code(CodeUtil.getNewCode("INSTRUCT_NO")); + } + if (StrUtil.isEmpty(dto.getInstruction_id())) { + dto.setInstruction_id(IdUtil.simpleUUID()); + } + List shortPathsList = + routeLineService.getShortPathLines( + dto.getStart_device_code(), dto.getNext_device_code(), dto.getRoute_plan_code()); + if (ObjectUtils.isEmpty(shortPathsList)) { + throw new Exception(dto.getStart_device_code() + "->" + dto.getNext_device_code() + "路由不通"); + } + String type = shortPathsList.get(0).getType(); + if (!StrUtil.equals(type, "0")) { + JSONObject instcheckjson = + instwo + .query( + " instruction_status <3 and next_point_code= '" + + dto.getNext_point_code() + + "'" + + " and start_point_code = '" + + dto.getStart_point_code() + + "'" + + " and task_id = '" + + dto.getTask_id() + + "'") + .uniqueResult(0); + if (instcheckjson != null) { + throw new Exception(dto.getTask_code() + ":该任务已存在待完成指令!"); + } + } + + if (!StrUtil.equals(dto.getCompound_inst(), "0") + && StrUtil.equals(task.getCompound_task(), "1")) { + dto.setCompound_inst("1"); + dto.setCompound_inst_data(task.getCompound_task_data()); + } + + dto.setCreate_by(currentUsername); + dto.setUpdate_by(currentUsername); + dto.setUpdate_time(now); + dto.setCreate_time(now); + + WQLObject wo = WQLObject.getWQLObject("acs_instruction"); + JSONObject json = (JSONObject) JSONObject.toJSON(dto); + + wo.insert(json); + + DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); + Device startdevice = appService.findDeviceByCode(dto.getStart_device_code()); + Device nextdevice = appService.findDeviceByCode(dto.getNext_device_code()); + + StandardInspectSiteDeviceDriver standardInspectSiteDeviceDriver; + StandardCoveyorControlWithScannerDeviceDriver standardCoveyorControlWithScannerDeviceDriver; + + if (!ObjectUtils.isEmpty(nextdevice.getExtraValue().get("link_three_lamp"))) { + String lamd_device = nextdevice.getExtraValue().get("link_three_lamp").toString(); + Device lamddevice = appService.findDeviceByCode(lamd_device); + } + + // != 0 为agv任务 + // if(!StrUtil.equals(type,"0")){ + // if (StrUtil.equals(paramService.findByCode(AcsConfig.AGVTYPE).getValue(), "1")) + // { + // agvService.sendAgvInstToMagic(dto); + // } else if (StrUtil.equals(paramService.findByCode(AcsConfig.AGVTYPE).getValue(), + // "2")) { + // agvService.sendAgvInstToNDC(dto); + // } else if (StrUtil.equals(paramService.findByCode(AcsConfig.AGVTYPE).getValue(), + // "3")) { + // agvService.addOrderSequences(dto); + // } + // } + instructions.add(dto); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void update(Instruction dto) { + String currentUsername = SecurityUtils.getCurrentUsername(); + String now = DateUtil.now(); + dto.setUpdate_time(now); + dto.setUpdate_by(currentUsername); + WQLObject wo = WQLObject.getWQLObject("acs_instruction"); + JSONObject json = (JSONObject) JSONObject.toJSON(dto); + + wo.update(json); + + this.reload(); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void deleteAll(String[] ids) throws Exception { + for (String instruction_id : ids) { + this.cancel(instruction_id); + } + } + + @Override + public void download(List all, HttpServletResponse response) throws IOException { + List> list = new ArrayList<>(); + for (Instruction instruction : all) { + Map map = new LinkedHashMap<>(); + map.put("任务标识", instruction.getTask_id()); + map.put("指令编码", instruction.getInstruction_code()); + map.put("指令由哪台设备做", instruction.getExecute_device_code()); + map.put("执行状态", instruction.getExecute_status()); + map.put("执行状态描述", instruction.getExecute_status_description()); + map.put("下一条指令由哪台设备做", instruction.getFollow_device_code()); + map.put("指令类型", instruction.getInstruction_type()); + map.put("指令状态", instruction.getInstruction_status()); + map.put("创建类型", instruction.getCreate_type()); + map.put("完成类型", instruction.getFinish_type()); + map.put("优先级", instruction.getPriority()); + map.put("执行编码", instruction.getExecute_code()); + map.put("执行信息", instruction.getExecute_message()); + map.put("起始点位编码", instruction.getStart_point_code()); + map.put("起始设备编码", instruction.getStart_device_code()); + map.put("目标点位编码", instruction.getNext_point_code()); + map.put("目标设备编码", instruction.getNext_device_code()); + map.put("排", instruction.getFrom_x()); + map.put("列", instruction.getFrom_y()); + map.put("层", instruction.getFrom_z()); + map.put("排", instruction.getTo_x()); + map.put("列", instruction.getTo_y()); + map.put("层", instruction.getTo_z()); + map.put("最后一条指令标识", instruction.getLast_instruction_id()); + map.put("是否允许修改", instruction.getCan_modify()); + map.put("备注", instruction.getRemark()); + map.put("是否启用", instruction.getIs_active()); + map.put("是否删除", instruction.getIs_delete()); + map.put("创建者", instruction.getCreate_by()); + map.put("创建时间", instruction.getCreate_time()); + map.put("修改者", instruction.getUpdate_by()); + map.put("修改时间", instruction.getUpdate_time()); + list.add(map); + } + FileUtil.downloadExcel(list, response); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void finish(String id) { + Instruction entity = this.findById(id); + // if (entity == null) throw new BadRequestException("被删除或无权限,操作失败!"); + String currentUsername = SecurityUtils.getCurrentUsername(); + String now = DateUtil.now(); + entity.setUpdate_time(now); + entity.setUpdate_by(currentUsername); + entity.setInstruction_status("2"); + WQLObject wo = WQLObject.getWQLObject("acs_instruction"); + String instnextdevice = entity.getNext_device_code(); + String insttaskid = entity.getTask_id(); + WQLObject taskwo = WQLObject.getWQLObject("acs_task"); + DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); + Device startdevice = appService.findDeviceByCode(entity.getStart_device_code()); + if (ObjectUtils.isEmpty(startdevice)) { + log.debug("地址对应设备未找到"); + throw new BadRequestException("地址对应设备未找到"); + } + if (instnextdevice.indexOf(".") != -1) { + instnextdevice = instnextdevice.substring(0, instnextdevice.indexOf(".")); + } + Device device = appService.findDeviceByCode(instnextdevice); + if (device == null) { + log.debug("地址对应设备未找到"); + throw new BadRequestException("地址对应设备未找到"); + } + DeviceService deviceService = SpringContextHolder.getBean(DeviceServiceImpl.class); + + JSONObject jo1 = new JSONObject(); + jo1.put("device_code", instnextdevice); + + String start_device_code = entity.getStart_device_code(); + + Device deviceByCode = deviceAppService.findDeviceByCode(start_device_code); + if (deviceByCode == null) { + log.debug("地址对应设备未找到"); + throw new BadRequestException("地址对应设备未找到"); + } + + jo1.put("hasGoodStatus", "1"); + jo1.put("material_type", startdevice.getMaterial_type()); + + jo1.put("quantity", startdevice.getQuantity()); + jo1.put("remark", startdevice.getRemark()); + jo1.put("batch", startdevice.getBatch()); + jo1.put("vehicle_code", entity.getVehicle_code()); + jo1.put("islock", "0"); + jo1.put("barrels_code", startdevice.getBarrels_code()); + jo1.put("cooperate_code", startdevice.getCooperate_code()); + jo1.put("powder_name", startdevice.getPowder_name()); + jo1.put("barrels_status", startdevice.getBarrels_status()); + deviceService.changeDeviceStatus(jo1); + // 如果是无光电的设备 指令完成变更起点、终点状态 + JSONObject jo = new JSONObject(); + jo.put("device_code", entity.getStart_device_code()); + jo.put("hasGoodStatus", "0"); + jo.put("material_type", ""); + jo.put("quantity", ""); + jo.put("remark", ""); + jo.put("batch", ""); + jo.put("islock", "0"); + deviceService.changeDeviceStatus(jo); + + JSONObject json = (JSONObject) JSONObject.toJSON(entity); + wo.update(json); + JSONObject taskjson = taskwo.query("task_id ='" + insttaskid + "'").uniqueResult(0); + TaskDto obj = taskjson.toJavaObject(TaskDto.class); + // =0 则不用再次请求 + if (StrUtil.equals(obj.getRequest_again(), "0")) { + if (StrUtil.equals(obj.getNext_device_code(), instnextdevice)) { + taskService.finish(obj.getTask_id()); + } else { + finishAndCreateNextInst(entity); + } + } + + removeByCodeFromCache(entity.getInstruction_code()); + this.reload(); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void finish(Instruction dto) { + String now = DateUtil.now(); + dto.setInstruction_status("2"); + WQLObject wo = WQLObject.getWQLObject("acs_instruction"); + JSONObject json = (JSONObject) JSONObject.toJSON(dto); + + wo.update(json); + String instnextdevice = dto.getNext_device_code(); + String insttaskid = dto.getTask_id(); + WQLObject taskwo = WQLObject.getWQLObject("acs_task"); + JSONObject taskjson = taskwo.query("task_id ='" + insttaskid + "'").uniqueResult(0); + TaskDto obj = taskjson.toJavaObject(TaskDto.class); + // =0 则不用再次请求 + if (StrUtil.equals(obj.getRequest_again(), "0")) { + if (StrUtil.equals(obj.getNext_device_code(), instnextdevice)) { + taskService.finish(obj.getTask_id()); + } else { + finishAndCreateNextInst(dto); + } + } + + DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); + DeviceService deviceService = SpringContextHolder.getBean(DeviceServiceImpl.class); + Device device = appService.findDeviceByCode(instnextdevice); + if (device == null) { + log.debug("地址对应设备未找到"); + return; + } + // 如果是无光电的设备 放货任务完成需要变更有货状态 + // StandardOrdinarySiteDeviceDriver standardOrdinarySiteDeviceDriver; + // if(device.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { + // standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) + // device.getDeviceDriver(); + // standardOrdinarySiteDeviceDriver.setMove(2); + // } + + // 如果是无光电的设备 指令完成变更起点、终点状态 + JSONObject jo = new JSONObject(); + jo.put("device_code", dto.getStart_point_code()); + jo.put("hasGoodStatus", "0"); + jo.put("material_type", ""); + jo.put("batch", ""); + deviceService.changeDeviceStatus(jo); + + JSONObject jo1 = new JSONObject(); + jo1.put("device_code", dto.getNext_point_code()); + jo1.put("hasGoodStatus", "1"); + jo1.put("material_type", dto.getMaterial()); + jo1.put("batch", dto.getBatch()); + deviceService.changeDeviceStatus(jo1); + + removeByCodeFromCache(dto.getInstruction_code()); + // this.reload(); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void finishAndCreateNextInst(Instruction dto) { + dto = foramte(dto); + String device_code = dto.getNext_device_code(); + WQLObject taskwo = WQLObject.getWQLObject("acs_task"); + JSONObject taskjson = taskwo.query("task_id ='" + dto.getTask_id() + "'").uniqueResult(0); + TaskDto acsTask = taskjson.toJavaObject(TaskDto.class); + RouteLineService routeLineService = SpringContextHolder.getBean(RouteLineServiceImpl.class); + List list = + routeLineService.getShortPathLines( + dto.getNext_device_code(), acsTask.getNext_device_code(), acsTask.getRoute_plan_code()); + if (ObjectUtils.isEmpty(list)) { + throw new BadRequestException("路由不通"); + } + RouteLineDto routeLineDto = (RouteLineDto) list.get(0); + String[] path = routeLineDto.getPath().split("->"); + List pathlist = Arrays.asList(path); + int index = 0; + for (int m = 0; m < pathlist.size(); m++) { + if (pathlist.get(m).equals(dto.getNext_device_code())) { + index = m + 1; + break; + } + } + String next_device_code = pathlist.get(index); + String start_device_code = dto.getNext_device_code(); + String start_point_code = null; + String next_point_code = null; + String start_device = + deviceAppService + .findDeviceByCode(start_device_code) + .getDeviceDriverDefination() + .getFitDeviceTypes() + .get(0) + .name(); + String next_device = + deviceAppService + .findDeviceByCode(next_device_code) + .getDeviceDriverDefination() + .getFitDeviceTypes() + .get(0) + .name(); + if (StrUtil.equals("storage", start_device)) { + start_point_code = start_device_code + "-" + acsTask.getFrom_y() + "-" + acsTask.getFrom_z(); + } else { + start_point_code = start_device_code; + } + if (StrUtil.equals("storage", next_device)) { + next_point_code = next_device_code + "-" + acsTask.getTo_y() + "-" + acsTask.getTo_z(); + } else { + next_point_code = next_device_code; + } + Instruction instdto = new Instruction(); + instdto.setInstruction_id(IdUtil.simpleUUID()); + instdto.setRoute_plan_code(acsTask.getRoute_plan_code()); + instdto.setRemark(acsTask.getRemark()); + instdto.setMaterial(acsTask.getMaterial()); + instdto.setQuantity(acsTask.getQuantity()); + instdto.setTask_id(acsTask.getTask_id()); + instdto.setTask_code(acsTask.getTask_code()); + instdto.setVehicle_code(acsTask.getVehicle_code()); + String now = DateUtil.now(); + instdto.setCreate_time(now); + instdto.setCreate_by("auto"); + instdto.setStart_device_code(start_device_code); + instdto.setNext_device_code(next_device_code); + instdto.setStart_point_code(start_point_code); + instdto.setNext_point_code(next_point_code); + instdto.setPriority(acsTask.getPriority()); + instdto.setInstruction_status("0"); + instdto.setExecute_device_code(dto.getNext_device_code()); + try { + this.create(instdto); + } catch (Exception e) { + e.printStackTrace(); + log.error("完成并创建下一条指令", e.getMessage()); + } + } + + @Override + public void cancel(String id) throws Exception { + // flag= true时取消指令 + boolean flag = false; + Instruction entity = this.findById(id); + if (entity == null) { + throw new BadRequestException("被删除或无权限,操作失败!"); + } + TaskDto task = taskService.findByCodeFromCache(entity.getTask_code()); + if (StrUtil.isEmpty(entity.getRoute_plan_code())) { + entity.setRoute_plan_code(task.getRoute_plan_code()); + } + + // != 0 为agv任务 1=magic 2=NDC 3=XZ,4=ZHEDA + if (StrUtil.equals(paramService.findByCode(AcsConfig.AGVTYPE).getValue(), "1") + && !StrUtil.equals(entity.getSend_status(), "2")) { + MagicAgvService magicAgvService = SpringContextHolder.getBean(MagicAgvService.class); + magicAgvService.deleteAgvInst(entity.getInstruction_code()); + flag = true; + + } else if (StrUtil.equals(paramService.findByCode(AcsConfig.AGVTYPE).getValue(), "2")) { + // NDC agv指令不当场取消指令,需要等agv上报 + if (!StrUtil.isEmpty(entity.getAgv_jobno())) { + ndcAgvService.deleteAgvInstToNDC(entity); + } else { + flag = true; + } + } else if (StrUtil.equals(paramService.findByCode(AcsConfig.AGVTYPE).getValue(), "3") + && !StrUtil.equals(entity.getSend_status(), "2")) { + XianGongAgvService xianGongAgvService = SpringContextHolder.getBean(XianGongAgvService.class); + xianGongAgvService.deleteXZAgvInst(entity.getInstruction_code()); + flag = true; + } else { + flag = true; + } + + if (flag) { + + if (StrUtil.equals(entity.getInstruction_type(), "7")) { + CancelTaskRequest cancelTaskRequest = new CancelTaskRequest(); + cancelTaskRequest.setOrderId(entity.getInstruction_code()); + cancelTaskRequest.setPalletCode(entity.getVehicle_code()); + cancelTaskRequest.setSrcLocation(entity.getStart_point_code()); + cancelTaskRequest.setDestLocation(entity.getNext_point_code()); + // 1 入库,2 出库,3 移库,4 空托盘入库,5 空托盘出库 + int type = 0; + if (StrUtil.equals(task.getStorage_task_type(), "1")) { + type = 1; + } else if (StrUtil.equals(task.getStorage_task_type(), "2")) { + type = 4; + } else if (StrUtil.equals(task.getStorage_task_type(), "3")) { + type = 2; + } else if (StrUtil.equals(task.getStorage_task_type(), "4")) { + type = 5; + } else if (StrUtil.equals(task.getStorage_task_type(), "5")) { + type = 3; + } + cancelTaskRequest.setTaskType(type); + acsToLiKuService.cancelTask(cancelTaskRequest); + } + + String currentUsername = SecurityUtils.getCurrentUsername(); + String now = DateUtil.now(); + entity.setUpdate_time(now); + entity.setUpdate_by(currentUsername); + entity.setInstruction_status("3"); + WQLObject wo = WQLObject.getWQLObject("acs_instruction"); + JSONObject json = (JSONObject) JSONObject.toJSON(entity); + wo.update(json); + DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); + DeviceService deviceService = SpringContextHolder.getBean(DeviceServiceImpl.class); + + // 如果是无光电的设备 指令完成变更起点、终点状态 + JSONObject jo = new JSONObject(); + jo.put("device_code", entity.getStart_device_code()); + if (StrUtil.equals(entity.getMaterial(), "1")) { + jo.put("hasGoodStatus", "1"); + } else if (!StrUtil.equals(entity.getMaterial(), "1") + && !StrUtil.isEmpty(entity.getMaterial())) { + jo.put("hasGoodStatus", "2"); + } else { + jo.put("hasGoodStatus", "0"); + } + jo.put("material_type", entity.getMaterial()); + jo.put("batch", entity.getBatch()); + jo.put("islock", "false"); + deviceService.changeDeviceStatus(jo); + + JSONObject jo1 = new JSONObject(); + jo1.put("device_code", entity.getNext_device_code()); + jo.put("hasGoodStatus", "0"); + jo.put("material_type", ""); + jo.put("batch", ""); + jo1.put("islock", "false"); + deviceService.changeDeviceStatus(jo1); + + String instnextdevice = entity.getNext_device_code(); + Device device = appService.findDeviceByCode(instnextdevice); + if (device == null) { + log.debug("地址对应设备未找到"); + return; + } + removeByCodeFromCache(entity.getInstruction_code()); + } + this.reload(); + } + + @Override + public void forceCancel(String id) throws Exception { + // flag= true时取消指令 + boolean flag = false; + Instruction entity = this.findById(id); + if (entity == null) { + throw new BadRequestException("被删除或无权限,操作失败!"); + } + TaskDto task = taskService.findByCodeFromCache(entity.getTask_code()); + if (StrUtil.isEmpty(entity.getRoute_plan_code())) { + entity.setRoute_plan_code(task.getRoute_plan_code()); + } + String currentUsername = SecurityUtils.getCurrentUsername(); + String now = DateUtil.now(); + entity.setUpdate_time(now); + entity.setUpdate_by(currentUsername); + entity.setInstruction_status("3"); + WQLObject wo = WQLObject.getWQLObject("acs_instruction"); + JSONObject json = (JSONObject) JSONObject.toJSON(entity); + wo.update(json); + DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); + DeviceService deviceService = SpringContextHolder.getBean(DeviceServiceImpl.class); + // 如果是无光电的设备 指令完成变更起点、终点状态 + JSONObject jo = new JSONObject(); + jo.put("device_code", entity.getStart_device_code()); + if (StrUtil.equals(entity.getMaterial(), "1")) { + jo.put("hasGoodStatus", "1"); + } else if (!StrUtil.equals(entity.getMaterial(), "1") + && !StrUtil.isEmpty(entity.getMaterial())) { + jo.put("hasGoodStatus", "2"); + } else { + jo.put("hasGoodStatus", "0"); + } + jo.put("material_type", entity.getMaterial()); + jo.put("batch", entity.getBatch()); + jo.put("islock", "false"); + deviceService.changeDeviceStatus(jo); + + JSONObject jo1 = new JSONObject(); + jo1.put("device_code", entity.getNext_device_code()); + jo.put("hasGoodStatus", "0"); + jo.put("material_type", ""); + jo.put("batch", ""); + jo1.put("islock", "false"); + deviceService.changeDeviceStatus(jo1); + + String instnextdevice = entity.getNext_device_code(); + Device device = appService.findDeviceByCode(instnextdevice); + if (device == null) { + log.debug("地址对应设备未找到"); + return; + } + removeByCodeFromCache(entity.getInstruction_code()); + } + + @Override + public void cancelNOSendAgv(String id) throws Exception { + // flag= true时取消指令 + Instruction entity = this.findById(id); + if (entity == null) { + throw new BadRequestException("被删除或无权限,操作失败!"); + } + TaskDto task = taskService.findByCodeFromCache(entity.getTask_code()); + if (StrUtil.isEmpty(entity.getRoute_plan_code())) { + entity.setRoute_plan_code(task.getRoute_plan_code()); + } + + String currentUsername = SecurityUtils.getCurrentUsername(); + String now = DateUtil.now(); + entity.setUpdate_time(now); + entity.setUpdate_by(currentUsername); + entity.setInstruction_status("3"); + WQLObject wo = WQLObject.getWQLObject("acs_instruction"); + JSONObject json = (JSONObject) JSONObject.toJSON(entity); + wo.update(json); + DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); + DeviceService deviceService = SpringContextHolder.getBean(DeviceServiceImpl.class); + + // 如果是无光电的设备 指令完成变更起点、终点状态 + JSONObject jo = new JSONObject(); + jo.put("device_code", entity.getStart_device_code()); + if (StrUtil.equals(entity.getMaterial(), "1")) { + jo.put("hasGoodStatus", "1"); + } else if (!StrUtil.equals(entity.getMaterial(), "1") + && !StrUtil.isEmpty(entity.getMaterial())) { + jo.put("hasGoodStatus", "2"); + } else { + jo.put("hasGoodStatus", "0"); + } + jo.put("material_type", entity.getMaterial()); + jo.put("batch", entity.getBatch()); + jo.put("islock", "false"); + deviceService.changeDeviceStatus(jo); + + JSONObject jo1 = new JSONObject(); + jo1.put("device_code", entity.getNext_device_code()); + jo.put("hasGoodStatus", "0"); + jo.put("material_type", ""); + jo.put("batch", ""); + jo1.put("islock", "false"); + deviceService.changeDeviceStatus(jo1); + + String instnextdevice = entity.getNext_device_code(); + Device device = appService.findDeviceByCode(instnextdevice); + if (device == null) { + log.debug("地址对应设备未找到"); + return; + } + + removeByCodeFromCache(entity.getInstruction_code()); + } + + @Override + public Instruction findByLinkNumSend(String code) { + 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; + } + } + } + + return null; + } + + @Override + public List findByLinkNum(String code) { + synchronized (InstructionServiceImpl.class) { + List list = new ArrayList<>(); + Iterator it = instructions.iterator(); + while (it.hasNext()) { + Instruction inst = it.next(); + if (StrUtil.equals(code, inst.getLink_num()) && StrUtil.equals(inst.getIs_send(), "0")) { + list.add(inst); + } + } + return list; + } + } + + @Override + public Instruction findByLinkNumNoSend(String code) { + synchronized (InstructionServiceImpl.class) { + Iterator it = instructions.iterator(); + while (it.hasNext()) { + Instruction inst = it.next(); + if (StrUtil.equals(code, inst.getLink_num()) && StrUtil.equals(inst.getIs_send(), "0")) { + return inst; + } + } + + 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 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); + } + } + + if (StrUtil.contains(next_point_code, "-") && StrUtil.count(next_point_code, "-") == 2) { + String[] next_point = next_point_code.split("-"); + inst.setTo_x(next_point[0]); + inst.setNext_device_code(next_point[0]); + inst.setTo_y(next_point[1]); + inst.setTo_z(next_point[2]); + } else { + + String next_device = + deviceAppService + .findDeviceByCode(next_device_code) + .getDeviceDriverDefination() + .getFitDeviceTypes() + .get(0) + .name(); + if (StrUtil.equals("storage", next_device)) { + String[] next_point = start_point_code.split("-"); + inst.setTo_x(next_point[0]); + inst.setNext_device_code(next_point[0]); + inst.setTo_y(next_point[1]); + inst.setTo_z(next_point[2]); + } else { + inst.setNext_device_code(next_device_code); + } + } + return inst; + } + + @Override + public Instruction findByDeviceCodeFromCache(String devicecode) { + 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()); + } + }); + Iterator it = instructions.iterator(); + while (it.hasNext()) { + Instruction inst = it.next(); + if (StrUtil.equals(devicecode, inst.getStart_device_code()) + && inst.getInstruction_status().equals("0")) { + return inst; + } + } + } + + return null; + } + + @Override + public List findAllInstFromCache() { + return instructions; + } + + @Override + public Integer querySameDestinationInst(String devicecode) { + 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 boolean removeByCodeFromCache(String code) { + synchronized (InstructionServiceImpl.class) { + CopyOnWriteArrayList instructions = (CopyOnWriteArrayList) this.instructions; + instructions.removeIf((instruction) -> { + instruction.getInstruction_code().equals(code); + return true; + }); +// while (iterator.hasNext()) { +// Instruction instruction = iterator.next(); +// if (instruction.getInstruction_code().equals(code)) { +// iterator.remove(); +// return true; +// } +// } + return true; + } + } + + @Override + public boolean createLkInst(String type, Instruction dto) { + Class var3 = TaskInstructionLock.class; + synchronized (TaskInstructionLock.class) { + // 入库 + AcsToLiKuService acsToLiKuService = SpringContextHolder.getBean(AcsToLiKuService.class); + Resp resp = null; + if (StrUtil.equals(type, "1")) { + InStoreRequest request = new InStoreRequest(); + request.setFloorNo(Integer.parseInt(dto.getTo_z())); + request.setType(1); + request.setPalletCode(dto.getVehicle_code()); + request.setOrderId(dto.getInstruction_code()); + request.setSrcLocation(dto.getStart_point_code()); + request.setDestLocation(dto.getNext_point_code()); + resp = acsToLiKuService.inStore(request); + // 空托入库 + } else if (StrUtil.equals(type, "2")) { + InStoreRequest request = new InStoreRequest(); + request.setFloorNo(Integer.parseInt(dto.getTo_z())); + request.setType(2); + request.setPalletCode(dto.getVehicle_code()); + request.setOrderId(dto.getInstruction_code()); + request.setSrcLocation(dto.getStart_point_code()); + request.setDestLocation(dto.getNext_point_code()); + resp = acsToLiKuService.inStore(request); + // 出库 + } else if (StrUtil.equals(type, "3")) { + OutStoreRequest outStore = new OutStoreRequest(); + BaseStoreRequest baseReq = new BaseStoreRequest(); + List list = new ArrayList(); + baseReq.setOrderId(dto.getInstruction_code()); + baseReq.setSrcLocation(dto.getStart_point_code()); + baseReq.setDestLocation(dto.getNext_point_code()); + baseReq.setFloorNo(Integer.parseInt(dto.getFrom_z())); + baseReq.setPalletCode(dto.getVehicle_code()); + list.add(baseReq); + outStore.setOrderInfos(list); + outStore.setGroupId(dto.getInstruction_code()); + resp = acsToLiKuService.outStore(outStore); + // 空托出库 + } else if (StrUtil.equals(type, "4")) { + EmptyVehicleOutStoreRequest emptyVehicleOutStoreRequest = new EmptyVehicleOutStoreRequest(); + emptyVehicleOutStoreRequest.setOrderId(dto.getInstruction_code()); + emptyVehicleOutStoreRequest.setFloorNo(Integer.parseInt(dto.getFrom_z())); + emptyVehicleOutStoreRequest.setSrcLocation(dto.getStart_point_code()); + emptyVehicleOutStoreRequest.setDestLocation(dto.getNext_point_code()); + emptyVehicleOutStoreRequest.setPalletCode(dto.getVehicle_code()); + resp = acsToLiKuService.emptyVehicleOutStore(emptyVehicleOutStoreRequest); + // 转库 + } else if (StrUtil.equals(type, "5")) { + MoveStoreRequest moveStoreRequest = new MoveStoreRequest(); + BaseStoreRequest baseReq = new BaseStoreRequest(); + List list = new ArrayList(); + baseReq.setFloorNo(Integer.parseInt(dto.getFrom_z())); + baseReq.setPalletCode(dto.getVehicle_code()); + baseReq.setOrderId(dto.getInstruction_code()); + baseReq.setSrcLocation(dto.getStart_point_code()); + baseReq.setDestLocation(dto.getNext_point_code()); + list.add(baseReq); + moveStoreRequest.setGroupId(dto.getInstruction_code()); + moveStoreRequest.setOrderInfos(list); + resp = acsToLiKuService.moveStore(moveStoreRequest); + } + + if (ObjectUtil.isNotEmpty(resp)) { + if (StrUtil.equals(resp.getResult(), "true")) { + dto.setSend_status("1"); + } else { + dto.setSend_status("2"); + dto.setRemark(resp.getData().toString()); + return false; + } + } else { + dto.setSend_status("2"); + dto.setRemark("ERROR"); + return false; + } + return true; + } + } + + /* + * 判断是否为整数 + * @param str 传入的字符串 + * @return 是整数返回true,否则返回false + */ + public static boolean isInteger(String str) { + Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$"); + return pattern.matcher(str).matches(); + } + + @Override + public void init(String id) { + Instruction inst = this.findById(id); + if (inst == null) { + throw new BadRequestException("指令不存在或已删除"); + } + if ("2".equals(inst.getInstruction_status())) { + throw new BadRequestException("指令已经完成"); + } + + Device startDevice = deviceAppService.findDeviceByCode(inst.getStart_device_code()); + DeviceDriver startDeviceDriver = startDevice.getDeviceDriver(); + if (startDeviceDriver instanceof SiemensConveyorDeviceDriver) { + Device nextDevice = deviceAppService.findDeviceByCode(inst.getNext_device_code()); + + List> list = new ArrayList<>(); + Map map = new HashMap<>(); + map.put("code", "to_target"); + map.put("value", nextDevice.getExtraValue().get("address").toString()); + list.add(map); + Map map2 = new HashMap<>(); + map2.put("code", "to_task"); + map2.put("value", inst.getInstruction_code()); + list.add(map2); + Map map3 = new HashMap<>(); + map3.put("code", "to_command"); + map3.put("value", "1"); + list.add(map3); + ((SiemensConveyorDeviceDriver) startDeviceDriver).writing(list); + } } - } } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/task/service/impl/TaskServiceImpl.java b/acs/nladmin-system/src/main/java/org/nl/acs/task/service/impl/TaskServiceImpl.java index 4960b2c97..a590928a3 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/task/service/impl/TaskServiceImpl.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/task/service/impl/TaskServiceImpl.java @@ -10,6 +10,7 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import lombok.RequiredArgsConstructor; +import lombok.Synchronized; import lombok.extern.slf4j.Slf4j; import org.nl.acs.AcsConfig; import org.nl.acs.agv.server.XianGongAgvService; @@ -88,7 +89,9 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { } public synchronized void reload() { - this.tasks = this.queryAll("task_status <2 and is_delete =0 order by create_time"); + List list = this.queryAll("task_status <2 and is_delete =0 order by create_time"); + + tasks = new CopyOnWriteArrayList<>(list); } @Override @@ -533,7 +536,9 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { JSONObject json = (JSONObject) JSONObject.toJSON(dto); wo.insert(json); - tasks.add(dto); + synchronized(TaskServiceImpl.class){ + tasks.add(dto); + } } /** @@ -804,6 +809,7 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { String hasWms = paramService.findByCode(AcsConfig.HASWMS).getValue(); if (!StrUtil.startWith(entity.getTask_code(), "-") && StrUtil.equals(hasWms, "1")) { TaskFeedbackDto feefbackdto = taskFeedbackService.findByCode(entity.getTask_code()); + System.out.println(feefbackdto == null); JSONObject feed_jo = new JSONObject(); feed_jo.put("task_id", entity.getTask_id()); feed_jo.put("task_code", entity.getTask_code());