diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device/device_driver/DriverTypeEnum.java b/acs/nladmin-system/src/main/java/org/nl/acs/device/device_driver/DriverTypeEnum.java index 893c1e309..d4f54e4a7 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device/device_driver/DriverTypeEnum.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device/device_driver/DriverTypeEnum.java @@ -41,8 +41,9 @@ public enum DriverTypeEnum { PLUG_PULL_DEVICE_SITE(15, "plug_pull_device_site", "插拔轴站点", "conveyor"), - SIEMENS_CONVEYOR_LABELING(16, "siemens_conveyor_labeling", "西门子-输送机驱动-贴标", "conveyor"); + SIEMENS_CONVEYOR_LABELING(16, "siemens_conveyor_labeling", "西门子-输送机驱动-贴标", "conveyor"), + SIEMENS_CONVEYOR_CKK(17, "siemens_conveyor_ckk", "西门子-输送机驱动-出库口", "conveyor"); //驱动索引 diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device/service/impl/DeviceServiceImpl.java b/acs/nladmin-system/src/main/java/org/nl/acs/device/service/impl/DeviceServiceImpl.java index 1828cd986..30da2be0e 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device/service/impl/DeviceServiceImpl.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device/service/impl/DeviceServiceImpl.java @@ -24,6 +24,7 @@ import org.nl.acs.device_driver.DeviceDriverDefination; import org.nl.acs.device_driver.ScannerDeviceDriver; import org.nl.acs.device_driver.basedriver.oven_manipulator.OvenGantryManipulatorDeviceDriver; import org.nl.acs.device_driver.basedriver.siemens_conveyor.SiemensConveyorDeviceDriver; +import org.nl.acs.device_driver.basedriver.siemens_conveyor_ckk.SiemensConveyorCkkDeviceDriver; import org.nl.acs.device_driver.basedriver.siemens_conveyor_labeling.SiemensConveyorLabelingDeviceDriver; import org.nl.acs.device_driver.basedriver.slit_two_manipulator.SlitTwoManipulatorDeviceDriver; import org.nl.acs.device_driver.basedriver.standard_conveyor_control_with_scanner.StandardCoveyorControlWithScannerDeviceDriver; @@ -949,6 +950,9 @@ public class DeviceServiceImpl implements DeviceService, ApplicationAutoInitial } else if (device.getDeviceDriver() instanceof OvenGantryManipulatorDeviceDriver) { OvenGantryManipulatorDeviceDriver ovenGantryManipulatorDeviceDriver = (OvenGantryManipulatorDeviceDriver) device.getDeviceDriver(); ovenGantryManipulatorDeviceDriver.setDeviceStatus(form); + } else if (device.getDeviceDriver() instanceof SiemensConveyorCkkDeviceDriver) { + SiemensConveyorCkkDeviceDriver siemensConveyorCkkDeviceDriver = (SiemensConveyorCkkDeviceDriver) device.getDeviceDriver(); + siemensConveyorCkkDeviceDriver.setDeviceStatus(form); } } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor_ckk/ItemProtocol.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor_ckk/ItemProtocol.java new file mode 100644 index 000000000..6d64f74c0 --- /dev/null +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor_ckk/ItemProtocol.java @@ -0,0 +1,132 @@ +package org.nl.acs.device_driver.basedriver.siemens_conveyor_ckk; + +import cn.hutool.core.util.StrUtil; +import lombok.Data; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.device.device_driver.standard_inspect.ItemDto; + +import java.util.ArrayList; +import java.util.List; + +@Slf4j +@Data +public class ItemProtocol { + + //心跳 + public static String item_heartbeat = "heartbeat"; + //工作模式 + public static String item_mode = "mode"; + //光电信号 + public static String item_move = "move"; + //托盘方向 + public static String item_carrier_direction = "carrier_direction"; + //报警 + public static String item_error = "error"; + //任务号 + public static String item_task = "task"; + + //下发命令 + public static String item_to_command = "to_command"; + //下发目标站 + public static String item_to_target = "to_target"; + //下发托盘类型 + public static String item_to_container_type = "to_container_type"; + //下发任务号 + public static String item_to_task = "to_task"; + //困扎次数 + public static String item_to_strap_times = "to_strap_times"; + //木箱长度 + public static String item_to_length = "to_length"; + //木箱宽度 + public static String item_to_weight = "to_weight"; + //木箱高度 + public static String item_to_height = "to_height"; + + + private SiemensConveyorCkkDeviceDriver driver; + + public ItemProtocol(SiemensConveyorCkkDeviceDriver driver) { + this.driver = driver; + } + + public int getHeartbeat() { + return this.getOpcIntegerValue(item_heartbeat); + } + + public int getMode() { + return this.getOpcIntegerValue(item_mode); + } + + public int getMove() { + return this.getOpcIntegerValue(item_move); + } + + public int getCarrier_direction() { + return this.getOpcIntegerValue(item_carrier_direction); + } + + public int getError() { + return this.getOpcIntegerValue(item_error); + } + + public int getTask() { + return this.getOpcIntegerValue(item_task); + } + + + Boolean isonline; + + public int getOpcIntegerValue(String protocol) { + Integer value = this.driver.getIntegeregerValue(protocol); + if (value == null) { + // log.error(this.getDriver().getDeviceCode() + ":protocol " + protocol + " 信号同步异常!"); + setIsonline(false); + } else { + setIsonline(true); + return value; + } + return 0; + + } + + public String getOpcStringValue(String protocol) { + String value = this.driver.getStringValue(protocol); + if (StrUtil.isEmpty(value)) { + + } else { + return value; + } + return "0"; + } + + public static List getReadableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_heartbeat, "心跳", "DB600.B0")); + list.add(new ItemDto(item_mode, "工作模式", "DB600.B2")); + list.add(new ItemDto(item_move, "光电信号", "DB600.B3")); + list.add(new ItemDto(item_carrier_direction, "托盘方向", "DB600.B4")); + list.add(new ItemDto(item_error, "报警信号", "DB600.B6")); + list.add(new ItemDto(item_task, "任务号", "DB600.D10")); + return list; + } + + public static List getWriteableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_to_command, "下发命令", "DB601.W2")); + list.add(new ItemDto(item_to_target, "下发目标站", "DB601.W4")); + list.add(new ItemDto(item_to_container_type, "下发托盘类型", "DB601.W6")); + list.add(new ItemDto(item_to_task, "下发任务号", "DB601.D8")); + list.add(new ItemDto(item_to_strap_times, "困扎次数", "DB601.W12")); + list.add(new ItemDto(item_to_length, "木箱长度", "DB601.W14")); + list.add(new ItemDto(item_to_weight, "木箱宽度", "DB601.W16")); + list.add(new ItemDto(item_to_height, "木箱高度", "DB601.W18")); + return list; + } + + @Override + public String toString() { + return ""; + } + +} + diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor_ckk/SiemensConveyorCkkDefination.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor_ckk/SiemensConveyorCkkDefination.java new file mode 100644 index 000000000..248dc8fa9 --- /dev/null +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor_ckk/SiemensConveyorCkkDefination.java @@ -0,0 +1,64 @@ +package org.nl.acs.device_driver.basedriver.siemens_conveyor_ckk; + +import org.nl.acs.device.device_driver.standard_inspect.ItemDto; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.defination.OpcDeviceDriverDefination; +import org.nl.acs.opc.Device; +import org.nl.acs.opc.DeviceType; +import org.springframework.stereotype.Service; + +import java.util.LinkedList; +import java.util.List; + +/** + * 西门子-输送机驱动 + * + */ +@Service +public class SiemensConveyorCkkDefination implements OpcDeviceDriverDefination { + @Override + public String getDriverCode() { + return "siemens_conveyor_ckk"; + } + + @Override + public String getDriverName() { + return "西门子-输送机驱动-出库口"; + } + + @Override + public String getDriverDescription() { + return "西门子-输送机驱动-出库口"; + } + + @Override + public DeviceDriver getDriverInstance(Device device) { + return (new SiemensConveyorCkkDeviceDriver()).setDevice(device).setDriverDefination(this); + + } + + @Override + public Class getDeviceDriverType() { + return SiemensConveyorCkkDeviceDriver.class; + } + + @Override + public List getFitDeviceTypes() { + List types = new LinkedList(); + types.add(DeviceType.station); + return types; + } + + @Override + public List getReadableItemDtos() { + return ItemProtocol.getReadableItemDtos(); + } + + + + @Override + public List getWriteableItemDtos() { + return ItemProtocol.getWriteableItemDtos(); + } + +} diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor_ckk/SiemensConveyorCkkDeviceDriver.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor_ckk/SiemensConveyorCkkDeviceDriver.java new file mode 100644 index 000000000..e562ef2c8 --- /dev/null +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/siemens_conveyor_ckk/SiemensConveyorCkkDeviceDriver.java @@ -0,0 +1,912 @@ +package org.nl.acs.device_driver.basedriver.siemens_conveyor_ckk; + +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.IdUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import cn.hutool.http.HttpResponse; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import lombok.Data; +import lombok.RequiredArgsConstructor; +import lombok.SneakyThrows; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.ObjectUtils; +import org.nl.acs.AcsConfig; +import org.nl.acs.agv.server.NDCAgvService; +import org.nl.acs.device.service.DeviceService; +import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.RouteableDeviceDriver; +import org.nl.acs.device_driver.driver.AbstractOpcDeviceDriver; +import org.nl.acs.device_driver.driver.ExecutableDeviceDriver; +import org.nl.acs.ext.wms.data.ApplyLabelingAndBindingRequest; +import org.nl.acs.ext.wms.data.ApplyLabelingAndBindingResponse; +import org.nl.acs.ext.wms.service.AcsToWmsService; +import org.nl.acs.instruction.service.InstructionService; +import org.nl.acs.instruction.service.dto.Instruction; +import org.nl.acs.log.service.DeviceExecuteLogService; +import org.nl.acs.monitor.DeviceStageMonitor; +import org.nl.acs.opc.Device; +import org.nl.acs.opc.DeviceAppService; +import org.nl.acs.route.service.RouteLineService; +import org.nl.acs.route.service.dto.RouteLineDto; +import org.nl.acs.task.service.TaskService; +import org.nl.acs.task.service.dto.TaskDto; +import org.nl.modules.system.service.ParamService; +import org.nl.modules.wql.core.bean.WQLObject; +import org.nl.modules.wql.util.SpringContextHolder; +import org.openscada.opc.lib.da.Server; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.*; + +/** + * 西门子-输送机驱动-出库口 + */ +@Slf4j +@Data +@RequiredArgsConstructor +public class SiemensConveyorCkkDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver, DeviceStageMonitor { + protected ItemProtocol itemProtocol = new ItemProtocol(this); + @Autowired + InstructionService instructionService = SpringContextHolder.getBean(InstructionService.class); + @Autowired + DeviceService deviceservice = SpringContextHolder.getBean(DeviceService.class); + @Autowired + RouteLineService routelineserver = SpringContextHolder.getBean(RouteLineService.class); + @Autowired + TaskService taskserver = SpringContextHolder.getBean(TaskService.class); + @Autowired + DeviceAppService deviceAppservice = SpringContextHolder.getBean(DeviceAppService.class); + @Autowired + RouteLineService routeLineService = SpringContextHolder.getBean(RouteLineService.class); + @Autowired + ParamService paramService = SpringContextHolder.getBean(ParamService.class); + @Autowired + AcsToWmsService acsToWmsService = SpringContextHolder.getBean(AcsToWmsService.class); + @Autowired + DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl"); + @Autowired + NDCAgvService agvService = SpringContextHolder.getBean(NDCAgvService.class); + //当前指令 + Instruction inst = null; + + //工作模式 + int mode = 0; + int last_mode = 0; + //光电信号 + int move = 0; + int last_move = 0; + //托盘方向 + int carrier_direction = 0; + int last_carrier_direction = 0; + //报警信号 + int error = 0; + int last_error = 0; + //任务号 + int task = 0; + int last_task = 0; + int agvphase = 0; + String task_code = null; + + int phase = 0; + int index = 0; + Boolean isonline = true; + int hasGoods = 0; + String message = null; + Boolean iserror = false; + + Integer heartbeat_tag; + private Date instruction_require_time = new Date(); + private Date require_apply_labeling_time = new Date(); + private Date require_apply_strangulation_time = new Date(); + private Date require_empty_in_time = new Date(); + private Date require_empty_out_time = new Date(); + + private int instruction_require_time_out = 3000; + //行架机械手申请任务成功标识 + boolean requireSucess = false; + boolean requireApplyLabelingSuccess = false; + boolean requireApplyLaStrangulationSuccess = false; + boolean requireEmptyInSuccess = false; + boolean requireEmptyOutSuccess = false; + boolean requiresShipDeviceUpdate = true; + private int instruction_finished_time_out; + + int branchProtocol = 0; + String inst_message; + String last_inst_message; + + //当前指令 + + //暂定 0就绪 1请求取货 2取货完成 3请求放货 4放货完成 5取货完成离开 6放货完成离开 7请求进入区域 8请求离开区域 + int flag; + + String device_code; + + String vehicle_code; + String last_vehicle_code; + + @Override + public Device getDevice() { + return this.device; + } + + + @Override + public void execute() { + try { + device_code = this.getDeviceCode(); + mode = this.itemProtocol.getMode(); + move = this.itemProtocol.getMove(); + carrier_direction = this.itemProtocol.getCarrier_direction(); + error = this.itemProtocol.getError(); + task = this.itemProtocol.getTask(); + if (mode != last_mode) { + if (mode == 2) { + requireSucess = false; + requireApplyLabelingSuccess = false; + requireApplyLaStrangulationSuccess = false; + requireEmptyInSuccess = false; + requireEmptyOutSuccess = false; + logServer.deviceExecuteLog(this.device_code, "", "", "信号mode:" + last_mode + "->" + mode + "复位请求标记"); + } + logServer.deviceItemValue(this.device_code, "mode", String.valueOf(mode)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号mode:" + last_mode + "->" + mode); + } + if (move != last_move) { + message = null; + if (move == 0 ) { + inst_message = null; + requireSucess = false; + this.clearWrite(); + } + logServer.deviceItemValue(this.device_code, "move", String.valueOf(move)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号move:" + last_move + "->" + move); + } + if (carrier_direction != last_carrier_direction) { + logServer.deviceItemValue(this.device_code, "carrier_direction", String.valueOf(carrier_direction)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号carrier_direction:" + last_carrier_direction + "->" + carrier_direction); + } + if (error != last_error) { + logServer.deviceItemValue(this.device_code, "error", String.valueOf(error)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号error:" + last_error + "->" + error); + } + if (task != last_task) { + logServer.deviceItemValue(this.device_code, "task", String.valueOf(task)); + logServer.deviceExecuteLog(this.device_code, "", "", "信号task:" + last_task + "->" + task); + } + + if (move != 0 && task > 0) { + inst = instructionService.findByCodeFromCache(String.valueOf(task)); + if (inst != null) { + inst_message = "当前指令号:" + inst.getInstruction_code() + " " + inst.getStart_point_code() + "->" + inst.getNext_point_code() + " 载具号:" + inst.getVehicle_code(); + vehicle_code = inst.getVehicle_code(); + task_code = inst.getTask_code(); + if (StrUtil.equals(inst.getInstruction_status(), "0") && StrUtil.equals(this.getDeviceCode(), inst.getStart_device_code())) { + inst.setInstruction_status("1"); + inst.setExecute_device_code(this.device_code); + instructionService.update(inst); + logServer.deviceExecuteLog(device_code, "", "", "入库输送线任务开始反馈执行中状态,反馈成功,指令号:" + task); + } + if (StrUtil.equals(inst.getInstruction_status(), "1")) { + if (!StrUtil.equals(inst.getExecute_code(), this.device_code)) { + inst.setExecute_device_code(this.device_code); + instructionService.update(inst); + } + } + } else { +// logServer.deviceExecuteLog(device_code, "", "", "输送线任务开始反馈任务状态,反馈失败,查询不到指令号:" + task); + message = "输送线任务反馈状态,查询不到指令号:" + task +"指令已完成"; + inst_message = null; + } + } + + } catch (Exception var17) { + inst_message = var17.getMessage(); + logServer.deviceExecuteLog(this.getDevice_code(), "", "", "读取信号值时出现异常:" + var17.getMessage()); + } + +// if (!this.itemProtocol.getIsonline()) { +// this.setIsonline(false); +// this.setIserror(true); +// message = "信号量同步异常"; +// //未联机 +// } else + if (mode == 0) { + this.setIsonline(false); + this.setIserror(true); + message = "未联机"; + //有报警 +// } else if (error != 0) { +// this.setIsonline(false); +// this.setIserror(true); +// message = "有报警"; +// //无报警 + } else { + this.setIsonline(true); + this.setIserror(false); + Instruction instruction = null; + List toInstructions; + + + switch (mode) { + case 1: + log.debug("设备运转模式:等待工作"); + break; + case 2: + //申请任务 + if (move > 0 && !requireSucess) { + try { + instruction_require(); + } catch (Exception e) { + e.printStackTrace(); + } + } + break; + case 4: + break; + case 5: + break; + case 6: + break; + case 7: + break; + case 8: + break; + } + } + last_mode = mode; + last_move = move; + last_carrier_direction = carrier_direction; + last_error = error; + last_task = task; + } + + private void shipDeviceUpdate() { + JSONObject param = new JSONObject() {{ + put("device_code", device_code); + }}; + + HttpResponse response = acsToWmsService.shipDeviceUpdate(param); + if (response == null || response.getStatus() == 200) { + this.requiresShipDeviceUpdate = true; + } + } + + + public boolean exe_error() { + if (this.error == 0) { + return true; + } else { + log.debug("设备报警"); + return false; + } + } + + public void clearWrite() { + + List list = new ArrayList(); + Map map = new HashMap(); + map.put("code", "to_target"); + map.put("value", "0"); + list.add(map); + Map map2 = new HashMap(); + map2.put("code", "to_task"); + map2.put("value", "0"); + list.add(map2); + Map map3 = new HashMap(); + map3.put("code", "to_command"); + map3.put("value", "0"); + list.add(map3); + Map map4 = new HashMap(); + map4.put("code", "to_strap_times"); + map4.put("value", "0"); + list.add(map4); + Map map5 = new HashMap(); + map5.put("code", "to_length"); + map5.put("value", "0"); + list.add(map5); + Map map6 = new HashMap(); + map6.put("code", "to_weight"); + map6.put("value", "0"); + list.add(map6); + Map map7 = new HashMap(); + map7.put("code", "to_height"); + map7.put("value", "0"); + list.add(map7); + this.writing(list); + message = null; + vehicle_code = null; + } + + public boolean exe_business() { + return true; + } + + public synchronized boolean finish_instruction() throws Exception { + instructionService.finish(inst); +// requireSucess = false; + return true; + } + + + protected void thingToNothing() throws Exception { + requireSucess = false; + } + + + public void writing(String param, String value) { + + String to_param = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + param; + //String opcservcerid = this.getDevice().getOpc_server_id(); +//Server server = ReadUtil.getServer(opcservcerid); + Map itemMap = new HashMap(); + + itemMap.put(to_param, Integer.parseInt(value)); +// itemMap.put(to_param, Integer.parseInt(value)); + this.control(itemMap); + logServer.deviceExecuteLog(device_code, "", "", "下发电气信号设备号:" + device_code + ",下发电气:" + to_param + ",下发电气值:" + value); + } + + public void executing(Server server, Map itemMap) { + this.control(itemMap); + } + + public void writing(int command) { + + //String opcservcerid = this.getDevice().getOpc_server_id(); +//Server server = ReadUtil.getServer(opcservcerid); + Map itemMap = new HashMap(); + this.control(itemMap); + + } + + @Override + public JSONObject getDeviceStatusName() { + JSONObject jo = new JSONObject(); + String mode = ""; + String move = ""; + String carrier_direction = ""; + if (this.getMode() == 0) { + mode = "脱机"; + } else if (this.getMode() == 1) { + mode = "单机"; + } else if (this.getMode() == 2) { + mode = "待机"; + } else if (this.getMode() == 3) { + mode = "运行中"; + } else if (this.getMode() == 4) { + mode = "申请捆扎中"; + } else if (this.getMode() == 5) { + mode = "申请贴标中"; + } else if (this.getMode() == 6) { + mode = "申请空盘入库中"; + } else if (this.getMode() == 7) { + mode = "申请空盘出库中"; + } else if (this.getMode() == 8) { + mode = "申请AGV任务中"; + } + + if (this.getMove() == 0) { + move = "无货"; + jo.put("hasGoods", false); + } else if (this.getMove() == 1) { + move = "有货"; + jo.put("hasGoods", true); + } else if (this.getMove() == 2) { + move = "有托盘有货"; + jo.put("hasGoods", true); + } + + if (this.carrier_direction == 1) { + carrier_direction = "正转"; + } else if (this.carrier_direction == 2) { + carrier_direction = "反转"; + } + String requireSucess = "0"; + if (this.requireSucess) { + requireSucess = "1"; + } + jo.put("device_name", this.getDevice().getDevice_name()); + jo.put("mode", mode); + jo.put("move", move); + jo.put("carrier_direction", carrier_direction); + jo.put("task", task); + jo.put("last_task", last_task); + jo.put("task_code", task_code); + +// jo.put("barcode", barcode); +// jo.put("last_task", last_task); + jo.put("inst_message", this.inst_message); + jo.put("last_inst_message", this.last_inst_message); + jo.put("isOnline", this.getIsonline()); + jo.put("error", this.getError()); + jo.put("isError", this.getIserror()); + jo.put("message", this.getMessage()); + jo.put("is_click", true); + jo.put("requireSucess", requireSucess); + jo.put("driver_type", "siemens_conveyor"); + return jo; + } + + @Override + public void setDeviceStatus(JSONObject data) { + String requestSucess = data.getString("requireSucess"); + if (StrUtil.equals(requestSucess, "0")) { + this.requireSucess = false; + } else if (StrUtil.equals(requestSucess, "1")) { + this.requireSucess = true; + } + } + + public void writing(List list) { + +// String opcservcerid = this.getDevice().getOpc_server_id(); +// Server server = ReadUtil.getServer(opcservcerid); + Map itemMap = new HashMap(); + for (int i = 0; i < list.size(); i++) { + Object ob = list.get(i); + JSONObject json = (JSONObject) JSONObject.toJSON(ob); + if (!StrUtil.isEmpty(json.getString("value"))) { + String to_param = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + json.getString("code"); + itemMap.put(to_param, json.getString("value")); + } + } + logServer.deviceExecuteLog(device_code, "", "", "下发电气信号:" + itemMap); + this.control(itemMap); + + } + + + /** + * 请求指令 + */ + public synchronized boolean instruction_require() { + Date date = new Date(); + if (date.getTime() - this.instruction_require_time.getTime() < (long) this.instruction_require_time_out) { + log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); + return false; + } else { + this.instruction_require_time = date; + if (task > 0) { + Instruction instruction = instructionService.findByCodeFromCache(String.valueOf(task)); + if (ObjectUtil.isEmpty(instruction)) { + instruction = instructionService.findByCode(String.valueOf(task)); + } + if(StrUtil.equals(instruction.getInstruction_status(),"1")){ + if (StrUtil.equals(this.getDeviceCode(), inst.getNext_device_code())) { + vehicle_code = inst.getVehicle_code(); + inst.setExecute_device_code(this.device_code); + try { + finish_instruction(); + } catch (Exception e) { + e.printStackTrace(); + } + logServer.deviceExecuteLog(device_code, "", "", "入库输送线任务开始反馈完成状态,反馈成功,指令号:" + task); + } + } + } else { + logServer.deviceExecuteLog(device_code, "", "", "申请输送任务电气设备任务号:" + task + "异常"); + message = "申请输送任务电气设备任务号:" + task + "异常"; + return false; + } + + //判断是否存在起点相同 任务状态就绪的任务 + TaskDto taskdto = taskserver.findByStartCodeAndReady(device_code); + if (!ObjectUtil.isEmpty(taskdto)) { +// if (!ObjectUtils.isEmpty(instructionService.findByBarcodeFromCache(container_code))) { +// return false; +// } + //需要判断当前设备是否已经存在就绪的指令 如果存在就直接下发 不存在则创建 + Instruction inst = instructionService.findByTaskcodeAndStatus(taskdto.getTask_code()); + if (ObjectUtil.isNotEmpty(inst)) { + List list = new ArrayList(); + Map map = new HashMap(); + + if (StrUtil.isNotEmpty(taskdto.getTo_z())) { + if (StrUtil.equals(taskdto.getTo_z(), "01")) { + map.put("code", "to_target"); + map.put("value", "102"); + } else if (StrUtil.equals(taskdto.getTo_z(), "02")) { + map.put("code", "to_target"); + map.put("value", "201"); + } else if (StrUtil.equals(taskdto.getTo_z(), "03")) { + map.put("code", "to_target"); + map.put("value", "301"); + } + } + 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); + this.writing(list); + if (task != Integer.parseInt(inst.getInstruction_code())) { + this.writing(list); + message = "重新下发电气信号"; + logServer.deviceExecuteLog(device_code, "", "", inst.getInstruction_code() + "再次下发电气信号"); + } + message = "下发电气任务号成功"; + requireSucess = true; + return true; + } + + // type 5 输送任务 + if (!StrUtil.equals(taskdto.getTask_type(), "5")) { + return false; + } + String taskid = taskdto.getTask_id(); + String taskcode = taskdto.getTask_code(); + String vehiclecode = taskdto.getVehicle_code(); + String priority = taskdto.getPriority(); + String start_point_code = taskdto.getStart_point_code(); + String start_device_code = taskdto.getStart_device_code(); + String route_plan_code = taskdto.getRoute_plan_code(); + String next_device_code = ""; + + /** + * 开始平均分配 + */ + String this_coevice_code = taskserver.queryAssignedByDevice(device_code, taskdto.getNext_device_code()); + if (StrUtil.isEmpty(this_coevice_code)) { + List shortPathsList = routeLineService.getShortPathLines(start_device_code, taskdto.getNext_device_code(), route_plan_code); + RouteLineDto routeLineDto = shortPathsList.get(0); + + String path = routeLineDto.getPath(); + String type = routeLineDto.getType(); + String[] str = path.split("->"); + + List pathlist = Arrays.asList(str); + int index = 0; + for (int m = 0; m < pathlist.size(); m++) { + if (pathlist.get(m).equals(start_device_code)) { + index = m + 1; + break; + } + } + next_device_code = pathlist.get(index); + } else { + next_device_code = this_coevice_code; + } + //校验路由关系 + List shortPathsList = routeLineService.getShortPathLines(start_device_code, next_device_code, route_plan_code); + if (ObjectUtils.isEmpty(shortPathsList)) { + throw new RuntimeException("路由不通!"); + } + + Device startdevice = deviceAppservice.findDeviceByCode(start_device_code); + Device nextdevice = deviceAppservice.findDeviceByCode(next_device_code); + String next_point_code; + if (StrUtil.equals(deviceAppservice.findDeviceTypeByCode(next_device_code), "storage")) { + next_point_code = taskdto.getTo_x() + "-" + taskdto.getTo_y() + "-" + taskdto.getTo_z(); + } else { + next_point_code = next_device_code; + } + Instruction instdto = new Instruction(); + instdto.setInstruction_id(IdUtil.simpleUUID()); + instdto.setRoute_plan_code(route_plan_code); + instdto.setRemark(taskdto.getRemark()); + instdto.setMaterial(taskdto.getMaterial()); + instdto.setQuantity(taskdto.getQuantity()); + instdto.setTask_id(taskid); + instdto.setTask_code(taskcode); + instdto.setVehicle_code(vehiclecode); + String now = DateUtil.now(); + instdto.setCreate_time(now); + instdto.setCreate_by("auto"); + instdto.setStart_device_code(start_device_code); + instdto.setNext_device_code(next_device_code); + instdto.setStart_point_code(start_point_code); + instdto.setNext_point_code(next_point_code); + instdto.setPriority(priority); + instdto.setInstruction_status("0"); + instdto.setExecute_device_code(start_point_code); + try { + instructionService.create(instdto); + } catch (Exception e) { + e.printStackTrace(); + log.error("指令创建失败!",e.getMessage()); + return false; + } + //创建指令后修改任务状态 + taskdto.setTask_status("1"); + taskserver.update(taskdto); + requireSucess = true; + String next_addr = nextdevice.getExtraValue().get("address").toString(); + + List list = new ArrayList(); + Map map = new HashMap(); + map.put("code", "to_target"); + map.put("value", next_addr); + list.add(map); + Map map2 = new HashMap(); + map2.put("code", "to_task"); + map2.put("value", instdto.getInstruction_code()); + list.add(map2); + Map map3 = new HashMap(); + map3.put("code", "to_command"); + map3.put("value", "1"); + list.add(map3); + this.writing(list); + if (task != Integer.parseInt(inst.getInstruction_code())) { + this.writing(list); + message = "重新下发电气信号"; + logServer.deviceExecuteLog(device_code, "", "", inst.getInstruction_code() + "再次下发电气信号"); + } + } else { + //如果不存在则直接找对应指令 + Instruction inst = instructionService.findByDeviceCodeFromCache(this.device_code); + if (ObjectUtil.isEmpty(inst)) { + return false; + } + + Device nextdevice = deviceAppservice.findDeviceByCode(inst.getNext_device_code()); + String next_addr = nextdevice.getExtraValue().get("address").toString(); + + List list = new ArrayList(); + Map map = new HashMap(); + map.put("code", "to_target"); + map.put("value", next_addr); + 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); + this.writing(list); + if (task != Integer.parseInt(inst.getInstruction_code())) { + this.writing(list); + logServer.deviceExecuteLog(device_code, "", "", inst.getInstruction_code() + "再次下发电气信号"); + } + requireSucess = true; + } + return true; + } + } + + //申请贴标 + public synchronized void applyLabeling() { + Date date = new Date(); + if (date.getTime() - this.require_apply_labeling_time.getTime() < (long) this.instruction_require_time_out) { + log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); + return; + } else { + this.require_apply_labeling_time = date; + String vehicle_code = ""; + if (task > 0) { + Instruction instruction = instructionService.findByCodeFromCache(String.valueOf(task)); + vehicle_code = instruction.getVehicle_code(); + } else { + logServer.deviceExecuteLog(device_code, "", "", "申请贴标电气设备任务号:" + task + "异常"); + message = "申请贴标电气设备任务号:" + task + "异常"; + throw new RuntimeException("任务号为空!"); + } + if (StrUtil.isEmpty(vehicle_code)) { + logServer.deviceExecuteLog(device_code, "", "", "申请贴标电气设备任务号:" + task + "未找到载具号"); + message = "申请贴标电气设备任务号:" + task + "未找到载具号"; + throw new RuntimeException("载具号为空!"); + } + ApplyLabelingAndBindingRequest applyLabelingAndBindingRequest = + new ApplyLabelingAndBindingRequest(); + JSONObject device_json = WQLObject.getWQLObject("acs_storage_cell").query("storage_code ='" + this.device_code + "'").uniqueResult(0); + String start_point_code = null; + if (!ObjectUtil.isEmpty(device_json)) { + start_point_code = (String) device_json.get("parent_storage_code") == null ? this.device_code : (String) device_json.get("parent_storage_code"); + } + applyLabelingAndBindingRequest.setDevice_code(start_point_code); + applyLabelingAndBindingRequest.setType("1"); + applyLabelingAndBindingRequest.setVehicle_code(vehicle_code); + ApplyLabelingAndBindingResponse applyLabelingAndBindingResponse = acsToWmsService.applyLabelingAndBindingRequest(applyLabelingAndBindingRequest); + + if (applyLabelingAndBindingResponse.getstatus() == 200) { + message = "申请贴标成功"; + List list = new ArrayList(); + Map map = new HashMap(); + map.put("code", "to_command"); + map.put("value", "5"); + list.add(map); + this.writing(list); + this.writing(list); + message = "申请贴标下发电气信号成功"; + requireApplyLabelingSuccess = true; + } else { + message = "申请贴标失败," + applyLabelingAndBindingResponse.getMessage(); + } + } + } + + //申请捆扎 + @SneakyThrows + public synchronized void applyLaStrangulation() { + Date date = new Date(); + if (date.getTime() - this.require_apply_strangulation_time.getTime() < (long) this.instruction_require_time_out) { + log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); + return; + } else { + this.require_apply_strangulation_time = date; + String vehicle_code = ""; + if (task > 0) { + Instruction instruction = instructionService.findByCodeFromCache(String.valueOf(task)); + if(ObjectUtil.isEmpty(instruction)){ + message = "申请捆扎电气设备任务号:" + task + "未找到对应指令"; + throw new RuntimeException("该电气任务号未找到对应指令!"); + } + vehicle_code = instruction.getVehicle_code(); + } else { + logServer.deviceExecuteLog(device_code, "", "", "申请捆扎电气设备任务号:" + task + "异常"); + message = "申请捆扎电气设备任务号:" + task + "异常"; + throw new RuntimeException("任务号为空!"); + } + if (StrUtil.isEmpty(vehicle_code)) { + logServer.deviceExecuteLog(device_code, "", "", "申请捆扎电气设备任务号:" + task + "未找到载具号"); + message = "申请捆扎电气设备任务号:" + task + "未找到载具号"; + throw new RuntimeException("载具号为空!"); + } + ApplyLabelingAndBindingRequest applyLabelingAndBindingRequest = + new ApplyLabelingAndBindingRequest(); + JSONObject device_json = WQLObject.getWQLObject("acs_storage_cell").query("storage_code ='" + this.device_code + "'").uniqueResult(0); + String start_point_code = null; + if (!ObjectUtil.isEmpty(device_json)) { + start_point_code = (String) device_json.get("parent_storage_code") == null ? this.device_code : (String) device_json.get("parent_storage_code"); + } + applyLabelingAndBindingRequest.setDevice_code(start_point_code); + applyLabelingAndBindingRequest.setType("2"); + applyLabelingAndBindingRequest.setVehicle_code(vehicle_code); + ApplyLabelingAndBindingResponse applyLabelingAndBindingResponse = acsToWmsService.applyLabelingAndBindingRequest(applyLabelingAndBindingRequest); + if (applyLabelingAndBindingResponse.getstatus() == 200) { + if (ObjectUtil.isNotEmpty(applyLabelingAndBindingResponse.getData())) { + Map datas = applyLabelingAndBindingResponse.getData(); + String length = datas.get("box_length").toString(); + String width = datas.get("box_width").toString(); + String box_high = datas.get("box_high").toString(); + String bundle_times = datas.get("bundle_times").toString(); + + List list = new ArrayList(); + Map map = new HashMap(); + map.put("code", "to_length"); + map.put("value", length); + list.add(map); + Map map2 = new HashMap(); + map2.put("code", "to_weight"); + map2.put("value", width); + list.add(map2); + Map map3 = new HashMap(); + map3.put("code", "to_height"); + map3.put("value", box_high); + list.add(map3); + Map map4 = new HashMap(); + map4.put("code", "to_strap_times"); + map4.put("value", bundle_times); + list.add(map4); + Map map5 = new HashMap(); + map5.put("code", "to_command"); + map5.put("value", "4"); + list.add(map5); + this.writing(list); +// this.writing(list); + + message = "申请捆扎成功"; + requireSucess = true; + } else { + message = "未返回尺寸信息"; + } + + } else { + message = applyLabelingAndBindingResponse.getMessage(); + } + + } + } + + public synchronized void emptyIn() { + Date date = new Date(); + if (date.getTime() - this.require_empty_in_time.getTime() < (long) this.instruction_require_time_out) { + log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); + return; + } else { + this.require_empty_in_time = date; + + if (StrUtil.equals(paramService.findByCode(AcsConfig.HASWMS).getValue(), "1")) { + message = "申请空盘入库任务中..."; + JSONObject apply = new JSONObject(); + apply.put("device_code", device_code); + apply.put("type", "2"); + String str = acsToWmsService.applyTaskToWms(apply); + JSONObject jo = JSON.parseObject(str); + if (ObjectUtil.isEmpty(jo)) { + message = "申请空盘入库接口不通"; + requireEmptyInSuccess = true; + } else { + if (jo.getInteger("status") == 200) { + message = "申请空盘入库成功"; + requireEmptyInSuccess = true; + } else { + requireEmptyInSuccess = true; + message = "申请空盘入库失败," + jo.get("message").toString(); + } + } + + } + } + } + + public synchronized void applyAgvTask() { + Date date = new Date(); + if (date.getTime() - this.instruction_require_time.getTime() < (long) this.instruction_require_time_out) { + log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); + return; + } else { + this.instruction_require_time = date; + if (StrUtil.equals(paramService.findByCode(AcsConfig.HASWMS).getValue(), "1")) { + Instruction instruction = instructionService.findByCode(String.valueOf(task)); + if(ObjectUtil.isEmpty(instruction)){ + message = "指令号"+task+"未找到对应指令"; + return; + } + message = "申请AGV搬运任务中..."; + JSONObject apply = new JSONObject(); + apply.put("device_code", device_code); + apply.put("type", "4"); + apply.put("vehicle_code", instruction.getVehicle_code()); + String str = acsToWmsService.applyTaskToWms(apply); + JSONObject jo = JSON.parseObject(str); + if (ObjectUtil.isEmpty(jo)) { + message = "申请AGV搬运任务接口不通"; + requireSucess = true; + } else { + if (jo.getInteger("status") == 200) { + message = "申请AGV搬运任务成功"; + requireSucess = true; + } else { + requireSucess = true; + message = "申请AGV搬运任务失败," + jo.get("message").toString(); + } + } + + } + } + } + + public synchronized void emptyOut() { + Date date = new Date(); + if (date.getTime() - this.require_empty_out_time.getTime() < (long) this.instruction_require_time_out) { + log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_require_time_out); + return; + } else { + this.require_empty_out_time = date; + if (StrUtil.equals(paramService.findByCode(AcsConfig.HASWMS).getValue(), "1")) { + message = "申请空盘出库任务中..."; + JSONObject apply = new JSONObject(); + apply.put("device_code", device_code); + apply.put("type", "3"); + String str = acsToWmsService.applyTaskToWms(apply); + JSONObject jo = JSON.parseObject(str); + if (ObjectUtil.isEmpty(jo)) { + message = "申请空盘出库接口不通"; + requireSucess = true; + } else { + if (jo.getInteger("status") == 200) { + message = "申请空盘出库成功"; + requireSucess = true; + } else { + requireSucess = true; + message = "申请空盘出库失败," + jo.get("message").toString(); + } + } + + } + } + } + + +} diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/driver/ExecutableDeviceDriver.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/driver/ExecutableDeviceDriver.java index 326d18963..3e3fe95bf 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/driver/ExecutableDeviceDriver.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/driver/ExecutableDeviceDriver.java @@ -5,16 +5,16 @@ import org.nl.acs.device_driver.DeviceDriver; public interface ExecutableDeviceDriver extends DeviceDriver { default void executeAuto() { -// try { -// this.execute(); -// } catch (Throwable var6) { -// String message = "线程调用异常:" + var6.getMessage(); -// Log.error(message); -// } finally { -// } + try { this.execute(); + } catch (Throwable var6) { + String message = "线程调用异常:" + var6.getMessage(); + Log.error(message); + } finally { + } +// this.execute(); } - void execute(); + void execute() throws Exception; } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/LiKuToAcsServiceImpl.java b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/LiKuToAcsServiceImpl.java index 79149fc11..b9feaf4c8 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/LiKuToAcsServiceImpl.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/LiKuToAcsServiceImpl.java @@ -118,8 +118,8 @@ public class LiKuToAcsServiceImpl implements LiKuToAcsService { inst.setCarno(carNo); instructionService.update(inst); } else if(StrUtil.equals(status,"3")){ - inst.setInstruction_status("2"); - instructionService.finish(inst.getInstruction_id()); +// inst.setInstruction_status("1"); +// instructionService.finish(inst.getInstruction_id()); } else if(StrUtil.equals(status,"4")){ //5 取消指令 diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/instruction/common/InstructStatusEnum.java b/acs/nladmin-system/src/main/java/org/nl/acs/instruction/common/InstructStatusEnum.java index dafc5d227..46c0b4614 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/instruction/common/InstructStatusEnum.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/instruction/common/InstructStatusEnum.java @@ -1,4 +1,6 @@ package org.nl.acs.instruction.common; public class InstructStatusEnum { + + } 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 9efcd6577..a27ae5eaf 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/instruction/service/impl/InstructionServiceImpl.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/instruction/service/impl/InstructionServiceImpl.java @@ -1,5 +1,7 @@ + package org.nl.acs.instruction.service.impl; + import cn.hutool.core.collection.ListUtil; import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.IdUtil; @@ -62,1448 +64,1390 @@ import java.util.stream.Collectors; * @author ldjun * @description 服务实现 * @date 2021-03-18 - */ + **/ @Service @RequiredArgsConstructor @Slf4j public class InstructionServiceImpl implements InstructionService, ApplicationAutoInitial { - List instructions = new CopyOnWriteArrayList(); + List instructions = new CopyOnWriteArrayList(); - @Autowired DeviceAppService deviceAppService; - @Autowired NDCAgvService ndcAgvService; - @Autowired ParamService paramService; - @Autowired RouteLineService routeLineService; - @Autowired TaskService taskService; - @Autowired AcsToLiKuService acsToLiKuService; + @Autowired + DeviceAppService deviceAppService; + @Autowired + NDCAgvService ndcAgvService; + @Autowired + ParamService paramService; + @Autowired + RouteLineService routeLineService; + @Autowired + TaskService taskService; + @Autowired + AcsToLiKuService acsToLiKuService; - @Override - public void autoInitial() { - this.reload(); - } - - @Override - public synchronized void reload() { - this.instructions = this.queryAll("instruction_status <2 and is_delete =0"); - } - - @Override - public Map queryAll(Map whereJson, Pageable page) { - /*WQLObject wo = WQLObject.getWQLObject("acs_instruction"); - ResultBean rb = wo.pagequery(WqlUtil.getHttpContext(page), "instruction_status < 2 and is_delete =0 ", "update_time desc"); - */ - // this.reload(); - HashMap map = new HashMap<>(); - map.put("flag", "1"); - String code = (String) whereJson.get("code"); - String vehicle_code = (String) whereJson.get("vehicle_code"); - String material_type = (String) whereJson.get("material_type"); - String status = (String) whereJson.get("status"); - String point_code = (String) whereJson.get("point_code"); - String is_over = (String) whereJson.get("is_over"); - String instruction_type = (String) whereJson.get("instruction_type"); - if (!StrUtil.isEmpty(code)) { - map.put("code", code); - } - if (!StrUtil.isEmpty(vehicle_code)) { - map.put("vehicle_code", vehicle_code); - } - if (!StrUtil.isEmpty(material_type)) { - map.put("material_type", material_type); - } - if (!StrUtil.isEmpty(status)) { - map.put("status", status); - } - if (!StrUtil.isEmpty(point_code)) { - map.put("point_code", point_code); - } - if (!StrUtil.isEmpty(is_over)) { - map.put("is_over", is_over); - } - map.put("instruction_type", instruction_type); - - Integer currentPageNumber = page.getPageNumber() + 1; - Integer pageMaxSize = page.getPageSize(); - final JSONObject jo = - WQL.getWO("QINST_QUERY").addParamMap(map).pageQuery(WqlUtil.getHttpContext(page), ""); - JSONArray jsonArray = jo.getJSONArray("content"); - List instructions = jsonArray.toJavaList(Instruction.class); - List instDtoList = - instructions.stream() - .skip((currentPageNumber - 1) * pageMaxSize) - .limit(pageMaxSize) - .collect(Collectors.toList()); - jo.put("content", instDtoList); - jo.put("totalElements", jsonArray.size()); - return jo; - } - - @Override - public Map getAll(Map whereJson, Pageable page) { - HashMap map = new HashMap<>(); - map.put("flag", "2"); - String code = (String) whereJson.get("code"); - String vehicle_code = (String) whereJson.get("vehicle_code"); - String material_type = (String) whereJson.get("material_type"); - String status = (String) whereJson.get("status"); - String point_code = (String) whereJson.get("point_code"); - String create_time = (String) whereJson.get("createTime"); - String end_time = (String) whereJson.get("end_time"); - if (!StrUtil.isEmpty(code)) { - map.put("code", code); - } - if (!StrUtil.isEmpty(vehicle_code)) { - map.put("vehicle_code", vehicle_code); - } - if (!StrUtil.isEmpty(material_type)) { - map.put("material_type", material_type); - } - if (!StrUtil.isEmpty(status)) { - map.put("status", status); - } - if (!StrUtil.isEmpty(point_code)) { - map.put("point_code", point_code); - } - if (!StrUtil.isEmpty(create_time) && !StrUtil.isEmpty(end_time)) { - map.put("create_time", create_time); - map.put("end_time", end_time); + @Override + public 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() { + this.instructions = this.queryAll("instruction_status <2 and is_delete =0"); } - jsonObject.put("content", array); - return jsonObject; - } - @Override - public List queryAll(Map whereJson) { - WQLObject wo = WQLObject.getWQLObject("acs_instruction"); - JSONArray arr = wo.query().getResultJSONArray(0); - List list = arr.toJavaList(Instruction.class); - return list; - } - - @Override - public List queryAll(String whereJson) { - WQLObject wo = WQLObject.getWQLObject("acs_instruction"); - JSONArray arr = wo.query(whereJson).getResultJSONArray(0); - List list = arr.toJavaList(Instruction.class); - return list; - } - - @Override - public Instruction findById(String instruction_id) { - WQLObject wo = WQLObject.getWQLObject("acs_instruction"); - JSONObject json = wo.query("instruction_id ='" + instruction_id + "'").uniqueResult(0); - if (ObjectUtil.isNotEmpty(json)) { - final Instruction obj = json.toJavaObject(Instruction.class); - return obj; - } - return null; - } - - @Override - public Instruction findByCode(String code) { - WQLObject wo = WQLObject.getWQLObject("acs_instruction"); - JSONObject json = wo.query("instruction_code ='" + code + "'").uniqueResult(0); - if (ObjectUtil.isEmpty(json)) { - return null; - } - final Instruction obj = json.toJavaObject(Instruction.class); - return obj; - } - - @Override - public Instruction findByTaskcode(String code) { - WQLObject wo = WQLObject.getWQLObject("acs_instruction"); - JSONObject json = wo.query("task_code ='" + code + "'").uniqueResult(0); - final Instruction obj = json.toJavaObject(Instruction.class); - return obj; - } - - @Override - public Instruction findByTaskcodeAndStatus(String code) { - Iterator var3 = instructions.iterator(); - while (var3.hasNext()) { - Instruction instruction = (Instruction) var3.next(); - if (StrUtil.equals(instruction.getTask_code(), code) - && StrUtil.equals(instruction.getInstruction_status(), "0")) { - return instruction; - } - } - return null; - } - - @Override - public Instruction findByTaskid(String id, String wherecaluse) { - if (!StrUtil.isEmpty(wherecaluse)) { - wherecaluse = " and " + wherecaluse; - } - WQLObject wo = WQLObject.getWQLObject("acs_instruction"); - JSONObject json = wo.query("task_id ='" + id + "'" + wherecaluse).uniqueResult(0); - if (ObjectUtil.isNotEmpty(json)) { - return json.toJavaObject(Instruction.class); - } - return null; - } - - @Override - public void create(Instruction dto) { - Class var2 = TaskInstructionLock.class; - synchronized (TaskInstructionLock.class) { - dto = foramte(dto); - String task_code = dto.getTask_code(); - TaskDto task = taskService.findByCodeFromCache(task_code); - - WQLObject instwo = WQLObject.getWQLObject("acs_instruction"); - String currentUsername = SecurityUtils.getCurrentUsername(); - String now = DateUtil.now(); - if (StrUtil.isEmpty(dto.getRoute_plan_code())) { - dto.setRoute_plan_code(task.getRoute_plan_code()); - } - if (StrUtil.isEmpty(dto.getPriority())) { - dto.setPriority(task.getPriority()); - } - if (StrUtil.isEmpty(dto.getInstruction_code())) { - dto.setInstruction_code(CodeUtil.getNewCode("INSTRUCT_NO")); - } - if (StrUtil.isEmpty(dto.getInstruction_id())) { - dto.setInstruction_id(IdUtil.simpleUUID()); - } - if (StrUtil.isEmpty(dto.getIs_send())) { - dto.setIs_send(task.getIs_send()); - } - if (StrUtil.isEmpty(dto.getLink_num())) { - dto.setIs_send(task.getLink_num()); - } - if (task.getTask_type().equals("1") || task.getTask_type().equals("2")) { - dto.setInstruction_type(task.getTask_type()); - } else if (false) { - - } 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()); + @Override + public Map queryAll(Map whereJson, Pageable page) { + /*WQLObject wo = WQLObject.getWQLObject("acs_instruction"); + ResultBean rb = wo.pagequery(WqlUtil.getHttpContext(page), "instruction_status < 2 and is_delete =0 ", "update_time desc"); + */ +// this.reload(); + HashMap map = new HashMap<>(); + map.put("flag", "1"); + String code = (String) whereJson.get("code"); + String vehicle_code = (String) whereJson.get("vehicle_code"); + String material_type = (String) whereJson.get("material_type"); + String status = (String) whereJson.get("status"); + String point_code = (String) whereJson.get("point_code"); + String is_over = (String) whereJson.get("is_over"); + String instruction_type = (String) whereJson.get("instruction_type"); + if (!StrUtil.isEmpty(code)) { + map.put("code", code); } - } - - 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(vehicle_code)) { + map.put("vehicle_code", vehicle_code); } - if (ObjectUtil.isEmpty(route)) { - throw new BadRequestException("未查询到相关路由!"); + if (!StrUtil.isEmpty(material_type)) { + map.put("material_type", material_type); } - 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(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); + } + + final JSONObject jo = WQL.getWO("QINST_QUERY").addParamMap(map).pageQuery(WqlUtil.getHttpContext(page), "create_time desc"); + return jo; + } + + @Override + public Map getByTaskId(String id) { + WQLObject wo = WQLObject.getWQLObject("acs_instruction"); + JSONObject jsonObject = wo.query("task_id='" + id + "'").pageResult(); + JSONArray content = jsonObject.getJSONArray("content"); + JSONArray array = new JSONArray(); + for (int i = 0; i < content.size(); i++) { + JSONObject jo = (JSONObject) content.get(i); + JSONObject ins = new JSONObject(); + ins.put("task_id", jo.get("instruction_id")); + ins.put("task_code", jo.get("instruction_code")); + ins.put("task_status", jo.get("instruction_status")); + ins.put("start_point_code", jo.get("start_point_code")); + ins.put("next_point_code", jo.get("next_point_code")); + ins.put("matarial", jo.get("matarial")); + ins.put("remark", jo.get("remark")); + ins.put("create_by", jo.get("create_by")); + ins.put("create_time", jo.get("create_time")); + array.add(ins); + } + jsonObject.put("content", array); + return jsonObject; + } + + @Override + public List queryAll(Map whereJson) { + WQLObject wo = WQLObject.getWQLObject("acs_instruction"); + JSONArray arr = wo.query().getResultJSONArray(0); + List list = arr.toJavaList(Instruction.class); + return list; + } + + @Override + public List queryAll(String whereJson) { + WQLObject wo = WQLObject.getWQLObject("acs_instruction"); + JSONArray arr = wo.query(whereJson).getResultJSONArray(0); + List list = arr.toJavaList(Instruction.class); + return list; + } + + @Override + public Instruction findById(String instruction_id) { + WQLObject wo = WQLObject.getWQLObject("acs_instruction"); + JSONObject json = wo.query("instruction_id ='" + instruction_id + "'").uniqueResult(0); + if (ObjectUtil.isNotEmpty(json)) { + final Instruction obj = json.toJavaObject(Instruction.class); + return obj; + } + return null; + } + + @Override + public Instruction findByCode(String code) { + WQLObject wo = WQLObject.getWQLObject("acs_instruction"); + JSONObject json = wo.query("instruction_code ='" + code + "'").uniqueResult(0); + if (ObjectUtil.isEmpty(json)){ + return null; + } + final Instruction obj = json.toJavaObject(Instruction.class); + return obj; + } + + @Override + public Instruction findByTaskcode(String code) { + WQLObject wo = WQLObject.getWQLObject("acs_instruction"); + JSONObject json = wo.query("task_code ='" + code + "'").uniqueResult(0); + final Instruction obj = json.toJavaObject(Instruction.class); + return obj; + } + + @Override + public Instruction findByTaskcodeAndStatus(String code) { + 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; } - } } - } 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); + return null; } - } - @Override - public void create2(Instruction dto) throws Exception { - Class var2 = TaskInstructionLock.class; - synchronized (TaskInstructionLock.class) { - dto = foramte(dto); - String task_code = dto.getTask_code(); - TaskDto task = taskService.findByCodeFromCache(task_code); - - WQLObject instwo = WQLObject.getWQLObject("acs_instruction"); - String currentUsername = SecurityUtils.getCurrentUsername(); - String now = DateUtil.now(); - if (StrUtil.isEmpty(dto.getRoute_plan_code())) { - dto.setRoute_plan_code(task.getRoute_plan_code()); - } - if (StrUtil.isEmpty(dto.getPriority())) { - dto.setPriority(task.getPriority()); - } - if (StrUtil.isEmpty(dto.getInstruction_code())) { - dto.setInstruction_code(CodeUtil.getNewCode("INSTRUCT_NO")); - } - if (StrUtil.isEmpty(dto.getInstruction_id())) { - dto.setInstruction_id(IdUtil.simpleUUID()); - } - if (StrUtil.isEmpty(dto.getIs_send())) { - dto.setIs_send(task.getIs_send()); - } - if (StrUtil.isEmpty(dto.getLink_num())) { - dto.setIs_send(task.getLink_num()); - } - if (task.getTask_type().equals("1") || task.getTask_type().equals("2")) { - dto.setInstruction_type(task.getTask_type()); - } else if (false) { - - } else { - dto.setInstruction_type("3"); - } - - // 起点设备与终点设备相同则为初始指令 - if (StrUtil.equals(task.getStart_device_code(), dto.getStart_device_code())) { - if (!StrUtil.equals(dto.getCompound_inst(), "0") - && StrUtil.equals(task.getCompound_task(), "1")) { - dto.setCompound_inst("1"); - dto.setCompound_inst_data(task.getCompound_task_data()); + @Override + public Instruction findByTaskid(String id, String wherecaluse) { + if (!StrUtil.isEmpty(wherecaluse)) { + wherecaluse = " and " + wherecaluse; } - } - - 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; - } + 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); } - if (ObjectUtil.isEmpty(route)) { - throw new BadRequestException("未查询到相关路由!"); + return null; + } + + @Override + public void create(Instruction dto) { + Class var2 = TaskInstructionLock.class; + synchronized(TaskInstructionLock.class) { + dto = foramte(dto); + String task_code = dto.getTask_code(); + TaskDto task = taskService.findByCodeFromCache(task_code); + + WQLObject instwo = WQLObject.getWQLObject("acs_instruction"); + String currentUsername = SecurityUtils.getCurrentUsername(); + String now = DateUtil.now(); + if (StrUtil.isEmpty(dto.getRoute_plan_code())) { + dto.setRoute_plan_code(task.getRoute_plan_code()); + } + if (StrUtil.isEmpty(dto.getPriority())) { + dto.setPriority(task.getPriority()); + } + if (StrUtil.isEmpty(dto.getInstruction_code())) { + dto.setInstruction_code(CodeUtil.getNewCode("INSTRUCT_NO")); + } + if (StrUtil.isEmpty(dto.getInstruction_id())) { + dto.setInstruction_id(IdUtil.simpleUUID()); + } + if (StrUtil.isEmpty(dto.getIs_send())) { + dto.setIs_send(task.getIs_send()); + } + if (StrUtil.isEmpty(dto.getLink_num())) { + dto.setIs_send(task.getLink_num()); + } + if (task.getTask_type().equals("1") || task.getTask_type().equals("2")) { + dto.setInstruction_type(task.getTask_type()); + } else if (false) { + + } 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); + 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); } - 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); - } + } + + + @Override + public void create2(Instruction dto) throws Exception { + Class var2 = TaskInstructionLock.class; + synchronized(TaskInstructionLock.class) { + dto = foramte(dto); + String task_code = dto.getTask_code(); + TaskDto task = taskService.findByCodeFromCache(task_code); + + WQLObject instwo = WQLObject.getWQLObject("acs_instruction"); + String currentUsername = SecurityUtils.getCurrentUsername(); + String now = DateUtil.now(); + if (StrUtil.isEmpty(dto.getRoute_plan_code())) { + dto.setRoute_plan_code(task.getRoute_plan_code()); + } + if (StrUtil.isEmpty(dto.getPriority())) { + dto.setPriority(task.getPriority()); + } + if (StrUtil.isEmpty(dto.getInstruction_code())) { + dto.setInstruction_code(CodeUtil.getNewCode("INSTRUCT_NO")); + } + if (StrUtil.isEmpty(dto.getInstruction_id())) { + dto.setInstruction_id(IdUtil.simpleUUID()); + } + if (StrUtil.isEmpty(dto.getIs_send())) { + dto.setIs_send(task.getIs_send()); + } + if (StrUtil.isEmpty(dto.getLink_num())) { + dto.setIs_send(task.getLink_num()); + } + if (task.getTask_type().equals("1") || task.getTask_type().equals("2")) { + dto.setInstruction_type(task.getTask_type()); + } else if (false) { + + } else { + dto.setInstruction_type("3"); + } + + + //起点设备与终点设备相同则为初始指令 + if (StrUtil.equals(task.getStart_device_code(), dto.getStart_device_code())) { + if (!StrUtil.equals(dto.getCompound_inst(), "0") && StrUtil.equals(task.getCompound_task(), "1")) { + dto.setCompound_inst("1"); + dto.setCompound_inst_data(task.getCompound_task_data()); + } + } + + dto.setCreate_by(currentUsername); + dto.setUpdate_by(currentUsername); + dto.setUpdate_time(now); + dto.setCreate_time(now); + dto.setStart_parent_code(task.getStart_parent_code()); + dto.setNext_parent_code(task.getNext_parent_code()); + + if (ObjectUtil.isNotEmpty(task.getTask_type())) { + dto.setInstruction_type(task.getTask_type()); + } + + DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); + Device startdevice = appService.findDeviceByCode(dto.getStart_device_code()); + Device nextdevice = appService.findDeviceByCode(dto.getNext_device_code()); + + HongXiangConveyorDeviceDriver hongXiangConveyorDeviceDriver; + StandardCoveyorControlWithScannerDeviceDriver standardCoveyorControlWithScannerDeviceDriver; + + if (startdevice.getDeviceDriver() instanceof HongXiangConveyorDeviceDriver) { + hongXiangConveyorDeviceDriver = (HongXiangConveyorDeviceDriver) startdevice.getDeviceDriver(); + hongXiangConveyorDeviceDriver.writing(3, Integer.valueOf(dto.getInstruction_code())); + } + + try { + String start_device_code = dto.getStart_device_code(); + String next_device_code = dto.getNext_device_code(); + String route_plan_code = task.getRoute_plan_code(); + List shortPathsList = routeLineService.getShortPathLines(start_device_code, next_device_code, route_plan_code); + RouteLineDto route = null; + for (int i = 0; i < shortPathsList.size(); i++) { + RouteLineDto routeLineDto = shortPathsList.get(i); + String route_device = routeLineDto.getDevice_code(); + String route_next_device = routeLineDto.getNext_device_code(); + if (route_device.equals(dto.getStart_device_code()) && route_next_device.equals(dto.getNext_device_code())) { + route = routeLineDto; + break; + } + } + if (ObjectUtil.isEmpty(route)) { + throw new BadRequestException("未查询到相关路由!"); + } + if (StrUtil.equals(shortPathsList.get(0).getType(), "1")){ + // 0为输送、立库任务 1 1楼叉车系统 2 2楼1区域AGV系统 3 2楼2区域AGV系统 + if (!StrUtil.equals(task.getAgv_system_type(), "0") && ObjectUtil.isNotEmpty(task.getAgv_system_type())) { + NDCAgvService ndcAgvService = SpringContextHolder.getBean(NDCAgvService.class); + ndcAgvService.sendAgvInstToNDC(task.getAgv_system_type(),dto); + } else { +// Boolean result = createLkInst(task.getStorage_task_type(),dto); + } + } + } catch (Exception e) { + dto.setSend_status("2"); + e.printStackTrace(); + } + + WQLObject wo = WQLObject.getWQLObject("acs_instruction"); + JSONObject json = (JSONObject) JSONObject.toJSON(dto); + + wo.insert(json); + instructions.add(dto); } - } catch (Exception e) { - dto.setSend_status("2"); - e.printStackTrace(); - } - - WQLObject wo = WQLObject.getWQLObject("acs_instruction"); - JSONObject json = (JSONObject) JSONObject.toJSON(dto); - - wo.insert(json); - instructions.add(dto); } - } - @Override - public void createAgain(Instruction dto) throws Exception { - Class var2 = TaskInstructionLock.class; - synchronized (TaskInstructionLock.class) { - String task_code = dto.getTask_code(); - TaskDto task = taskService.findByCodeFromCache(task_code); - WQLObject instwo = WQLObject.getWQLObject("acs_instruction"); - String currentUsername = SecurityUtils.getCurrentUsername(); - String now = DateUtil.now(); - if (StrUtil.isEmpty(dto.getRoute_plan_code())) { - dto.setRoute_plan_code(task.getRoute_plan_code()); - } - if (StrUtil.isEmpty(dto.getInstruction_code())) { - dto.setInstruction_code(CodeUtil.getNewCode("INSTRUCT_NO")); - } - if (StrUtil.isEmpty(dto.getInstruction_id())) { - dto.setInstruction_id(IdUtil.simpleUUID()); - } - List shortPathsList = - routeLineService.getShortPathLines( - dto.getStart_device_code(), dto.getNext_device_code(), dto.getRoute_plan_code()); - if (ObjectUtils.isEmpty(shortPathsList)) { - throw new Exception(dto.getStart_device_code() + "->" + dto.getNext_device_code() + "路由不通"); - } - String type = shortPathsList.get(0).getType(); - if (!StrUtil.equals(type, "0")) { - JSONObject instcheckjson = - instwo - .query( - " instruction_status <3 and next_point_code= '" - + dto.getNext_point_code() - + "'" - + " and start_point_code = '" - + dto.getStart_point_code() - + "'" - + " and task_id = '" - + dto.getTask_id() - + "'") - .uniqueResult(0); - if (instcheckjson != null) { - throw new Exception(dto.getTask_code() + ":该任务已存在待完成指令!"); + + + @Override + public void createAgain(Instruction dto) throws Exception { + Class var2 = TaskInstructionLock.class; + synchronized(TaskInstructionLock.class) { + String task_code = dto.getTask_code(); + TaskDto task = taskService.findByCodeFromCache(task_code); + WQLObject instwo = WQLObject.getWQLObject("acs_instruction"); + String currentUsername = SecurityUtils.getCurrentUsername(); + String now = DateUtil.now(); + if (StrUtil.isEmpty(dto.getRoute_plan_code())) { + dto.setRoute_plan_code(task.getRoute_plan_code()); + } + if (StrUtil.isEmpty(dto.getInstruction_code())) { + dto.setInstruction_code(CodeUtil.getNewCode("INSTRUCT_NO")); + } + if (StrUtil.isEmpty(dto.getInstruction_id())) { + dto.setInstruction_id(IdUtil.simpleUUID()); + } + List shortPathsList = routeLineService.getShortPathLines(dto.getStart_device_code(), dto.getNext_device_code(), dto.getRoute_plan_code()); + if (ObjectUtils.isEmpty(shortPathsList)) { + throw new Exception(dto.getStart_device_code() + "->" + dto.getNext_device_code() + "路由不通"); + } + String type = shortPathsList.get(0).getType(); + if (!StrUtil.equals(type, "0")) { + JSONObject instcheckjson = instwo.query(" instruction_status <3 and next_point_code= '" + dto.getNext_point_code() + "'" + " and start_point_code = '" + dto.getStart_point_code() + "'" + " and task_id = '" + dto.getTask_id() + "'").uniqueResult(0); + if (instcheckjson != null) { + throw new Exception(dto.getTask_code() + ":该任务已存在待完成指令!"); + } + } + + if (!StrUtil.equals(dto.getCompound_inst(), "0") && StrUtil.equals(task.getCompound_task(), "1")) { + dto.setCompound_inst("1"); + dto.setCompound_inst_data(task.getCompound_task_data()); + } + + dto.setCreate_by(currentUsername); + dto.setUpdate_by(currentUsername); + dto.setUpdate_time(now); + dto.setCreate_time(now); + + WQLObject wo = WQLObject.getWQLObject("acs_instruction"); + JSONObject json = (JSONObject) JSONObject.toJSON(dto); + + wo.insert(json); + + + DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); + Device startdevice = appService.findDeviceByCode(dto.getStart_device_code()); + Device nextdevice = appService.findDeviceByCode(dto.getNext_device_code()); + + StandardInspectSiteDeviceDriver standardInspectSiteDeviceDriver; + StandardCoveyorControlWithScannerDeviceDriver standardCoveyorControlWithScannerDeviceDriver; + + if (!ObjectUtils.isEmpty(nextdevice.getExtraValue().get("link_three_lamp"))) { + String lamd_device = nextdevice.getExtraValue().get("link_three_lamp").toString(); + Device lamddevice = appService.findDeviceByCode(lamd_device); + + } + + + // != 0 为agv任务 +// if(!StrUtil.equals(type,"0")){ +// if (StrUtil.equals(paramService.findByCode(AcsConfig.AGVTYPE).getValue(), "1")) { +// agvService.sendAgvInstToMagic(dto); +// } else if (StrUtil.equals(paramService.findByCode(AcsConfig.AGVTYPE).getValue(), "2")) { +// agvService.sendAgvInstToNDC(dto); +// } else if (StrUtil.equals(paramService.findByCode(AcsConfig.AGVTYPE).getValue(), "3")) { +// agvService.addOrderSequences(dto); +// } +// } + instructions.add(dto); } - } - - 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) { - Class var2 = TaskInstructionLock.class; - synchronized (TaskInstructionLock.class) { - String currentUsername = SecurityUtils.getCurrentUsername(); - String now = DateUtil.now(); - dto.setUpdate_time(now); - dto.setUpdate_by(currentUsername); - WQLObject wo = WQLObject.getWQLObject("acs_instruction"); - JSONObject json = (JSONObject) JSONObject.toJSON(dto); - - wo.update(json); - - // Iterator iterator = instructions.iterator(); - // while (iterator.hasNext()) { - // Instruction instruction = iterator.next(); - // if (instruction.getInstruction_code().equals(dto.getInstruction_code())) { - // iterator.remove(); - // } - // } - // if (StrUtil.equals(dto.getInstruction_status(), "0") || - // StrUtil.equals(dto.getInstruction_status(), "1")) { - // instructions.add(dto); - // } - this.reload(); - } - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void deleteAll(String[] ids) throws Exception { - for (String instruction_id : ids) { - this.cancel(instruction_id); - } - } - - @Override - public void download(List all, HttpServletResponse response) throws IOException { - List> list = new ArrayList<>(); - for (Instruction instruction : all) { - Map map = new LinkedHashMap<>(); - map.put("任务标识", instruction.getTask_id()); - map.put("指令编码", instruction.getInstruction_code()); - map.put("指令由哪台设备做", instruction.getExecute_device_code()); - map.put("执行状态", instruction.getExecute_status()); - map.put("执行状态描述", instruction.getExecute_status_description()); - map.put("下一条指令由哪台设备做", instruction.getFollow_device_code()); - map.put("指令类型", instruction.getInstruction_type()); - map.put("指令状态", instruction.getInstruction_status()); - map.put("创建类型", instruction.getCreate_type()); - map.put("完成类型", instruction.getFinish_type()); - map.put("优先级", instruction.getPriority()); - map.put("执行编码", instruction.getExecute_code()); - map.put("执行信息", instruction.getExecute_message()); - map.put("起始点位编码", instruction.getStart_point_code()); - map.put("起始设备编码", instruction.getStart_device_code()); - map.put("目标点位编码", instruction.getNext_point_code()); - map.put("目标设备编码", instruction.getNext_device_code()); - map.put("排", instruction.getFrom_x()); - map.put("列", instruction.getFrom_y()); - map.put("层", instruction.getFrom_z()); - map.put("排", instruction.getTo_x()); - map.put("列", instruction.getTo_y()); - map.put("层", instruction.getTo_z()); - map.put("最后一条指令标识", instruction.getLast_instruction_id()); - map.put("是否允许修改", instruction.getCan_modify()); - map.put("备注", instruction.getRemark()); - map.put("是否启用", instruction.getIs_active()); - map.put("是否删除", instruction.getIs_delete()); - map.put("创建者", instruction.getCreate_by()); - map.put("创建时间", instruction.getCreate_time()); - map.put("修改者", instruction.getUpdate_by()); - map.put("修改时间", instruction.getUpdate_time()); - list.add(map); - } - FileUtil.downloadExcel(list, response); - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void finish(String id) { - Instruction entity = this.findById(id); - // if (entity == null) throw new BadRequestException("被删除或无权限,操作失败!"); - String currentUsername = SecurityUtils.getCurrentUsername(); - String now = DateUtil.now(); - entity.setUpdate_time(now); - entity.setUpdate_by(currentUsername); - entity.setInstruction_status("2"); - WQLObject wo = WQLObject.getWQLObject("acs_instruction"); - String instnextdevice = entity.getNext_device_code(); - String insttaskid = entity.getTask_id(); - WQLObject taskwo = WQLObject.getWQLObject("acs_task"); - DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); - Device startdevice = appService.findDeviceByCode(entity.getStart_device_code()); - if (ObjectUtils.isEmpty(startdevice)) { - log.debug("地址对应设备未找到"); - throw new BadRequestException("地址对应设备未找到"); - } - if (instnextdevice.indexOf(".") != -1) { - instnextdevice = instnextdevice.substring(0, instnextdevice.indexOf(".")); - } - Device device = appService.findDeviceByCode(instnextdevice); - if (device == null) { - log.debug("地址对应设备未找到"); - throw new BadRequestException("地址对应设备未找到"); - } - DeviceService deviceService = SpringContextHolder.getBean(DeviceServiceImpl.class); - - JSONObject jo1 = new JSONObject(); - jo1.put("device_code", instnextdevice); - - String start_device_code = entity.getStart_device_code(); - - Device deviceByCode = deviceAppService.findDeviceByCode(start_device_code); - if (deviceByCode == null) { - log.debug("地址对应设备未找到"); - throw new BadRequestException("地址对应设备未找到"); } - jo1.put("hasGoodStatus", "1"); - jo1.put("material_type", startdevice.getMaterial_type()); + @Override + @Transactional(rollbackFor = Exception.class) + public void update(Instruction dto) { + Class var2 = TaskInstructionLock.class; + synchronized(TaskInstructionLock.class) { + String currentUsername = SecurityUtils.getCurrentUsername(); + String now = DateUtil.now(); + dto.setUpdate_time(now); + dto.setUpdate_by(currentUsername); + WQLObject wo = WQLObject.getWQLObject("acs_instruction"); + JSONObject json = (JSONObject) JSONObject.toJSON(dto); - 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); + wo.update(json); - JSONObject json = (JSONObject) JSONObject.toJSON(entity); - wo.update(json); - JSONObject taskjson = taskwo.query("task_id ='" + insttaskid + "'").uniqueResult(0); - TaskDto obj = taskjson.toJavaObject(TaskDto.class); - // =0 则不用再次请求 - if (StrUtil.equals(obj.getRequest_again(), "0")) { - if (StrUtil.equals(obj.getNext_device_code(), instnextdevice)) { - taskService.finish(obj.getTask_id()); - } else { - finishAndCreateNextInst(entity); - } - } - - removeByCodeFromCache(entity.getInstruction_code()); - this.reload(); - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void finish(Instruction dto) { - Class var2 = TaskInstructionLock.class; - synchronized (TaskInstructionLock.class) { - String now = DateUtil.now(); - dto.setInstruction_status("2"); - WQLObject wo = WQLObject.getWQLObject("acs_instruction"); - JSONObject json = (JSONObject) JSONObject.toJSON(dto); - - 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); +// Iterator iterator = instructions.iterator(); +// while (iterator.hasNext()) { +// Instruction instruction = iterator.next(); +// if (instruction.getInstruction_code().equals(dto.getInstruction_code())) { +// iterator.remove(); +// } +// } +// if (StrUtil.equals(dto.getInstruction_status(), "0") || StrUtil.equals(dto.getInstruction_status(), "1")) { +// instructions.add(dto); +// } + this.reload(); } - } - - DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); - DeviceService deviceService = SpringContextHolder.getBean(DeviceServiceImpl.class); - Device device = appService.findDeviceByCode(instnextdevice); - if (device == null) { - log.debug("地址对应设备未找到"); - return; - } - // 如果是无光电的设备 放货任务完成需要变更有货状态 - // StandardOrdinarySiteDeviceDriver standardOrdinarySiteDeviceDriver; - // if(device.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { - // standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) - // device.getDeviceDriver(); - // standardOrdinarySiteDeviceDriver.setMove(2); - // } - - // 如果是无光电的设备 指令完成变更起点、终点状态 - JSONObject jo = new JSONObject(); - jo.put("device_code", dto.getStart_point_code()); - jo.put("hasGoodStatus", "0"); - jo.put("material_type", ""); - jo.put("batch", ""); - deviceService.changeDeviceStatus(jo); - - JSONObject jo1 = new JSONObject(); - jo1.put("device_code", dto.getNext_point_code()); - jo1.put("hasGoodStatus", "1"); - jo1.put("material_type", dto.getMaterial()); - jo1.put("batch", dto.getBatch()); - deviceService.changeDeviceStatus(jo1); - - removeByCodeFromCache(dto.getInstruction_code()); - this.reload(); } - } - @Override - public void finishAndCreateNextInst(Instruction dto) { - dto = foramte(dto); - String device_code = dto.getNext_device_code(); - WQLObject taskwo = WQLObject.getWQLObject("acs_task"); - JSONObject taskjson = taskwo.query("task_id ='" + dto.getTask_id() + "'").uniqueResult(0); - TaskDto acsTask = taskjson.toJavaObject(TaskDto.class); - RouteLineService routeLineService = SpringContextHolder.getBean(RouteLineServiceImpl.class); - List list = - routeLineService.getShortPathLines( - dto.getNext_device_code(), acsTask.getNext_device_code(), acsTask.getRoute_plan_code()); - if (ObjectUtils.isEmpty(list)) { - throw new BadRequestException("路由不通"); - } - RouteLineDto routeLineDto = (RouteLineDto) list.get(0); - String[] path = routeLineDto.getPath().split("->"); - List pathlist = Arrays.asList(path); - int index = 0; - for (int m = 0; m < pathlist.size(); m++) { - if (pathlist.get(m).equals(dto.getNext_device_code())) { - index = m + 1; - break; - } - } - String next_device_code = pathlist.get(index); - String start_device_code = dto.getNext_device_code(); - String start_point_code = null; - String next_point_code = null; - String start_device = - deviceAppService - .findDeviceByCode(start_device_code) - .getDeviceDriverDefination() - .getFitDeviceTypes() - .get(0) - .name(); - String next_device = - deviceAppService - .findDeviceByCode(next_device_code) - .getDeviceDriverDefination() - .getFitDeviceTypes() - .get(0) - .name(); - if (StrUtil.equals("storage", start_device)) { - start_point_code = start_device_code + "-" + acsTask.getFrom_y() + "-" + acsTask.getFrom_z(); - } else { - start_point_code = start_device_code; - } - if (StrUtil.equals("storage", next_device)) { - next_point_code = next_device_code + "-" + acsTask.getTo_y() + "-" + acsTask.getTo_z(); - } else { - next_point_code = next_device_code; - } - Instruction instdto = new Instruction(); - instdto.setInstruction_id(IdUtil.simpleUUID()); - instdto.setRoute_plan_code(acsTask.getRoute_plan_code()); - instdto.setRemark(acsTask.getRemark()); - instdto.setMaterial(acsTask.getMaterial()); - instdto.setQuantity(acsTask.getQuantity()); - instdto.setTask_id(acsTask.getTask_id()); - instdto.setTask_code(acsTask.getTask_code()); - instdto.setVehicle_code(acsTask.getVehicle_code()); - String now = DateUtil.now(); - instdto.setCreate_time(now); - instdto.setCreate_by("auto"); - instdto.setStart_device_code(start_device_code); - instdto.setNext_device_code(next_device_code); - instdto.setStart_point_code(start_point_code); - instdto.setNext_point_code(next_point_code); - instdto.setPriority(acsTask.getPriority()); - instdto.setInstruction_status("0"); - instdto.setExecute_device_code(dto.getNext_device_code()); - try { - this.create(instdto); - } catch (Exception e) { - e.printStackTrace(); - log.error("完成并创建下一条指令", e.getMessage()); - } - } - - @Override - public void cancel(String id) throws Exception { - Class var2 = TaskInstructionLock.class; - synchronized (TaskInstructionLock.class) { - // flag= true时取消指令 - boolean flag = false; - Instruction entity = this.findById(id); - if (entity == null) { - throw new BadRequestException("被删除或无权限,操作失败!"); - } - TaskDto task = taskService.findByCodeFromCache(entity.getTask_code()); - if (StrUtil.isEmpty(entity.getRoute_plan_code())) { - entity.setRoute_plan_code(task.getRoute_plan_code()); - } - - // != 0 为agv任务 1=magic 2=NDC 3=XZ,4=ZHEDA - if (StrUtil.equals(paramService.findByCode(AcsConfig.AGVTYPE).getValue(), "1") - && !StrUtil.equals(entity.getSend_status(), "2")) { - MagicAgvService magicAgvService = SpringContextHolder.getBean(MagicAgvService.class); - magicAgvService.deleteAgvInst(entity.getInstruction_code()); - flag = true; - - } else if (StrUtil.equals(paramService.findByCode(AcsConfig.AGVTYPE).getValue(), "2")) { - // NDC agv指令不当场取消指令,需要等agv上报 - if (!StrUtil.isEmpty(entity.getAgv_jobno())) { - ndcAgvService.deleteAgvInstToNDC(entity); - } else { - flag = true; + @Override + @Transactional(rollbackFor = Exception.class) + public void deleteAll(String[] ids) throws Exception { + for (String instruction_id : ids) { + this.cancel(instruction_id); } - } 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); + @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("3"); + entity.setInstruction_status("2"); WQLObject wo = WQLObject.getWQLObject("acs_instruction"); - JSONObject json = (JSONObject) JSONObject.toJSON(entity); - wo.update(json); + 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()); - 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("quantity", ""); + jo.put("remark", ""); jo.put("batch", ""); - jo1.put("islock", "false"); - deviceService.changeDeviceStatus(jo1); + jo.put("islock", "0"); + deviceService.changeDeviceStatus(jo); - String instnextdevice = entity.getNext_device_code(); - Device device = appService.findDeviceByCode(instnextdevice); - if (device == null) { - log.debug("地址对应设备未找到"); - return; + 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(); + this.reload(); } - } - @Override - public void forceCancel(String id) throws Exception { - Class var2 = TaskInstructionLock.class; - synchronized (TaskInstructionLock.class) { - // flag= true时取消指令 - boolean flag = false; - Instruction entity = this.findById(id); - if (entity == null) { - throw new BadRequestException("被删除或无权限,操作失败!"); - } - TaskDto task = taskService.findByCodeFromCache(entity.getTask_code()); - if (StrUtil.isEmpty(entity.getRoute_plan_code())) { - entity.setRoute_plan_code(task.getRoute_plan_code()); - } - String currentUsername = SecurityUtils.getCurrentUsername(); - String now = DateUtil.now(); - entity.setUpdate_time(now); - entity.setUpdate_by(currentUsername); - entity.setInstruction_status("3"); - WQLObject wo = WQLObject.getWQLObject("acs_instruction"); - JSONObject json = (JSONObject) JSONObject.toJSON(entity); - wo.update(json); - DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); - DeviceService deviceService = SpringContextHolder.getBean(DeviceServiceImpl.class); - // 如果是无光电的设备 指令完成变更起点、终点状态 - JSONObject jo = new JSONObject(); - jo.put("device_code", entity.getStart_device_code()); - if (StrUtil.equals(entity.getMaterial(), "1")) { - jo.put("hasGoodStatus", "1"); - } else if (!StrUtil.equals(entity.getMaterial(), "1") - && !StrUtil.isEmpty(entity.getMaterial())) { - jo.put("hasGoodStatus", "2"); - } else { - jo.put("hasGoodStatus", "0"); - } - jo.put("material_type", entity.getMaterial()); - jo.put("batch", entity.getBatch()); - jo.put("islock", "false"); - deviceService.changeDeviceStatus(jo); + @Override + @Transactional(rollbackFor = Exception.class) + public void finish(Instruction dto) { + Class var2 = TaskInstructionLock.class; + synchronized(TaskInstructionLock.class) { + String now = DateUtil.now(); + dto.setInstruction_status("2"); + WQLObject wo = WQLObject.getWQLObject("acs_instruction"); + JSONObject json = (JSONObject) JSONObject.toJSON(dto); - 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); + 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); + } + } - String instnextdevice = entity.getNext_device_code(); - Device device = appService.findDeviceByCode(instnextdevice); - if (device == null) { - log.debug("地址对应设备未找到"); - return; - } - removeByCodeFromCache(entity.getInstruction_code()); + DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); + DeviceService deviceService = SpringContextHolder.getBean(DeviceServiceImpl.class); + Device device = appService.findDeviceByCode(instnextdevice); + if (device == null) { + log.debug("地址对应设备未找到"); + return; + } + // 如果是无光电的设备 放货任务完成需要变更有货状态 +// StandardOrdinarySiteDeviceDriver standardOrdinarySiteDeviceDriver; +// if(device.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { +// standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) device.getDeviceDriver(); +// standardOrdinarySiteDeviceDriver.setMove(2); +// } + + // 如果是无光电的设备 指令完成变更起点、终点状态 + JSONObject jo = new JSONObject(); + jo.put("device_code", dto.getStart_point_code()); + jo.put("hasGoodStatus", "0"); + jo.put("material_type", ""); + jo.put("batch", ""); + deviceService.changeDeviceStatus(jo); + + JSONObject jo1 = new JSONObject(); + jo1.put("device_code", dto.getNext_point_code()); + jo1.put("hasGoodStatus", "1"); + jo1.put("material_type", dto.getMaterial()); + jo1.put("batch", dto.getBatch()); + deviceService.changeDeviceStatus(jo1); + + removeByCodeFromCache(dto.getInstruction_code()); +// this.reload(); + } } - } - @Override - public void cancelNOSendAgv(String id) throws Exception { - Class var2 = TaskInstructionLock.class; - synchronized (TaskInstructionLock.class) { - // flag= true时取消指令 - Instruction entity = this.findById(id); - if (entity == null) { - throw new BadRequestException("被删除或无权限,操作失败!"); - } - TaskDto task = taskService.findByCodeFromCache(entity.getTask_code()); - if (StrUtil.isEmpty(entity.getRoute_plan_code())) { - entity.setRoute_plan_code(task.getRoute_plan_code()); - } - - String currentUsername = SecurityUtils.getCurrentUsername(); - String now = DateUtil.now(); - entity.setUpdate_time(now); - entity.setUpdate_by(currentUsername); - entity.setInstruction_status("3"); - WQLObject wo = WQLObject.getWQLObject("acs_instruction"); - JSONObject json = (JSONObject) JSONObject.toJSON(entity); - wo.update(json); - DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); - DeviceService deviceService = SpringContextHolder.getBean(DeviceServiceImpl.class); - - // 如果是无光电的设备 指令完成变更起点、终点状态 - JSONObject jo = new JSONObject(); - jo.put("device_code", entity.getStart_device_code()); - if (StrUtil.equals(entity.getMaterial(), "1")) { - jo.put("hasGoodStatus", "1"); - } else if (!StrUtil.equals(entity.getMaterial(), "1") - && !StrUtil.isEmpty(entity.getMaterial())) { - jo.put("hasGoodStatus", "2"); - } else { - jo.put("hasGoodStatus", "0"); - } - jo.put("material_type", entity.getMaterial()); - jo.put("batch", entity.getBatch()); - jo.put("islock", "false"); - deviceService.changeDeviceStatus(jo); - - JSONObject jo1 = new JSONObject(); - jo1.put("device_code", entity.getNext_device_code()); - jo.put("hasGoodStatus", "0"); - jo.put("material_type", ""); - jo.put("batch", ""); - jo1.put("islock", "false"); - deviceService.changeDeviceStatus(jo1); - - String instnextdevice = entity.getNext_device_code(); - Device device = appService.findDeviceByCode(instnextdevice); - if (device == null) { - log.debug("地址对应设备未找到"); - return; - } - - removeByCodeFromCache(entity.getInstruction_code()); + @Override + public 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 Instruction findByLinkNumSend(String code) { - Iterator it = instructions.iterator(); - while (it.hasNext()) { - Instruction inst = it.next(); - if (StrUtil.equals(code, inst.getLink_num()) && StrUtil.equals(inst.getIs_send(), "1")) { + @Override + public void cancel(String id) throws Exception { + Class var2 = TaskInstructionLock.class; + synchronized(TaskInstructionLock.class) { + //flag= true时取消指令 + boolean flag = false; + Instruction entity = this.findById(id); + if (entity == null) { + throw new BadRequestException("被删除或无权限,操作失败!"); + } + TaskDto task = taskService.findByCodeFromCache(entity.getTask_code()); + if (StrUtil.isEmpty(entity.getRoute_plan_code())) { + entity.setRoute_plan_code(task.getRoute_plan_code()); + } + + // != 0 为agv任务 1=magic 2=NDC 3=XZ,4=ZHEDA + if (StrUtil.equals(paramService.findByCode(AcsConfig.AGVTYPE).getValue(), "1") + && !StrUtil.equals(entity.getSend_status(), "2")) { + MagicAgvService magicAgvService = SpringContextHolder.getBean(MagicAgvService.class); + magicAgvService.deleteAgvInst(entity.getInstruction_code()); + flag = true; + + } else if (StrUtil.equals(paramService.findByCode(AcsConfig.AGVTYPE).getValue(), "2")) { + //NDC agv指令不当场取消指令,需要等agv上报 + if (!StrUtil.isEmpty(entity.getAgv_jobno())) { + ndcAgvService.deleteAgvInstToNDC(entity); + } else { + flag = true; + } + } else if (StrUtil.equals(paramService.findByCode(AcsConfig.AGVTYPE).getValue(), "3") + && !StrUtil.equals(entity.getSend_status(), "2")) { + XianGongAgvService xianGongAgvService = SpringContextHolder.getBean(XianGongAgvService.class); + xianGongAgvService.deleteXZAgvInst(entity.getInstruction_code()); + flag = true; + } else { + flag = true; + } + + if (flag) { + + if(StrUtil.equals(entity.getInstruction_type(),"7")){ + CancelTaskRequest cancelTaskRequest = new CancelTaskRequest(); + cancelTaskRequest.setOrderId(entity.getInstruction_code()); + cancelTaskRequest.setPalletCode(entity.getVehicle_code()); + cancelTaskRequest.setSrcLocation(entity.getStart_point_code()); + cancelTaskRequest.setDestLocation(entity.getNext_point_code()); + //1 入库,2 出库,3 移库,4 空托盘入库,5 空托盘出库 + int type = 0; + if(StrUtil.equals(task.getStorage_task_type(),"1")){ + type = 1; + } else if (StrUtil.equals(task.getStorage_task_type(),"2")){ + type = 4; + } else if (StrUtil.equals(task.getStorage_task_type(),"3")){ + type = 2; + } else if (StrUtil.equals(task.getStorage_task_type(),"4")){ + type = 5; + } else if (StrUtil.equals(task.getStorage_task_type(),"5")){ + type = 3; + } + cancelTaskRequest.setTaskType(type); + acsToLiKuService.cancelTask(cancelTaskRequest); + } + + + String currentUsername = SecurityUtils.getCurrentUsername(); + String now = DateUtil.now(); + entity.setUpdate_time(now); + entity.setUpdate_by(currentUsername); + entity.setInstruction_status("3"); + WQLObject wo = WQLObject.getWQLObject("acs_instruction"); + JSONObject json = (JSONObject) JSONObject.toJSON(entity); + wo.update(json); + DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); + DeviceService deviceService = SpringContextHolder.getBean(DeviceServiceImpl.class); + + // 如果是无光电的设备 指令完成变更起点、终点状态 + JSONObject jo = new JSONObject(); + jo.put("device_code", entity.getStart_device_code()); + if (StrUtil.equals(entity.getMaterial(), "1")) { + jo.put("hasGoodStatus", "1"); + } else if (!StrUtil.equals(entity.getMaterial(), "1") && !StrUtil.isEmpty(entity.getMaterial())) { + jo.put("hasGoodStatus", "2"); + } else { + jo.put("hasGoodStatus", "0"); + } + jo.put("material_type", entity.getMaterial()); + jo.put("batch", entity.getBatch()); + jo.put("islock", "false"); + deviceService.changeDeviceStatus(jo); + + JSONObject jo1 = new JSONObject(); + jo1.put("device_code", entity.getNext_device_code()); + jo.put("hasGoodStatus", "0"); + jo.put("material_type", ""); + jo.put("batch", ""); + jo1.put("islock", "false"); + deviceService.changeDeviceStatus(jo1); + + String instnextdevice = entity.getNext_device_code(); + Device device = appService.findDeviceByCode(instnextdevice); + if (device == null) { + log.debug("地址对应设备未找到"); + return; + } + removeByCodeFromCache(entity.getInstruction_code()); + } + this.reload(); + } + } + + @Override + public void forceCancel(String id) throws Exception { + Class var2 = TaskInstructionLock.class; + synchronized(TaskInstructionLock.class) { + //flag= true时取消指令 + boolean flag = false; + Instruction entity = this.findById(id); + if (entity == null) { + throw new BadRequestException("被删除或无权限,操作失败!"); + } + TaskDto task = taskService.findByCodeFromCache(entity.getTask_code()); + if (StrUtil.isEmpty(entity.getRoute_plan_code())) { + entity.setRoute_plan_code(task.getRoute_plan_code()); + } + String currentUsername = SecurityUtils.getCurrentUsername(); + String now = DateUtil.now(); + entity.setUpdate_time(now); + entity.setUpdate_by(currentUsername); + entity.setInstruction_status("3"); + WQLObject wo = WQLObject.getWQLObject("acs_instruction"); + JSONObject json = (JSONObject) JSONObject.toJSON(entity); + wo.update(json); + DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); + DeviceService deviceService = SpringContextHolder.getBean(DeviceServiceImpl.class); + // 如果是无光电的设备 指令完成变更起点、终点状态 + JSONObject jo = new JSONObject(); + jo.put("device_code", entity.getStart_device_code()); + if (StrUtil.equals(entity.getMaterial(), "1")) { + jo.put("hasGoodStatus", "1"); + } else if (!StrUtil.equals(entity.getMaterial(), "1") && !StrUtil.isEmpty(entity.getMaterial())) { + jo.put("hasGoodStatus", "2"); + } else { + jo.put("hasGoodStatus", "0"); + } + jo.put("material_type", entity.getMaterial()); + jo.put("batch", entity.getBatch()); + jo.put("islock", "false"); + deviceService.changeDeviceStatus(jo); + + JSONObject jo1 = new JSONObject(); + jo1.put("device_code", entity.getNext_device_code()); + jo.put("hasGoodStatus", "0"); + jo.put("material_type", ""); + jo.put("batch", ""); + jo1.put("islock", "false"); + deviceService.changeDeviceStatus(jo1); + + String instnextdevice = entity.getNext_device_code(); + Device device = appService.findDeviceByCode(instnextdevice); + if (device == null) { + log.debug("地址对应设备未找到"); + return; + } + removeByCodeFromCache(entity.getInstruction_code()); + } + + } + + + @Override + public void cancelNOSendAgv(String id) throws Exception { + Class var2 = TaskInstructionLock.class; + synchronized(TaskInstructionLock.class) { + //flag= true时取消指令 + Instruction entity = this.findById(id); + if (entity == null) { + throw new BadRequestException("被删除或无权限,操作失败!"); + } + TaskDto task = taskService.findByCodeFromCache(entity.getTask_code()); + if (StrUtil.isEmpty(entity.getRoute_plan_code())) { + entity.setRoute_plan_code(task.getRoute_plan_code()); + } + + String currentUsername = SecurityUtils.getCurrentUsername(); + String now = DateUtil.now(); + entity.setUpdate_time(now); + entity.setUpdate_by(currentUsername); + entity.setInstruction_status("3"); + WQLObject wo = WQLObject.getWQLObject("acs_instruction"); + JSONObject json = (JSONObject) JSONObject.toJSON(entity); + wo.update(json); + DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); + DeviceService deviceService = SpringContextHolder.getBean(DeviceServiceImpl.class); + + // 如果是无光电的设备 指令完成变更起点、终点状态 + JSONObject jo = new JSONObject(); + jo.put("device_code", entity.getStart_device_code()); + if (StrUtil.equals(entity.getMaterial(), "1")) { + jo.put("hasGoodStatus", "1"); + } else if (!StrUtil.equals(entity.getMaterial(), "1") && !StrUtil.isEmpty(entity.getMaterial())) { + jo.put("hasGoodStatus", "2"); + } else { + jo.put("hasGoodStatus", "0"); + } + jo.put("material_type", entity.getMaterial()); + jo.put("batch", entity.getBatch()); + jo.put("islock", "false"); + deviceService.changeDeviceStatus(jo); + + JSONObject jo1 = new JSONObject(); + jo1.put("device_code", entity.getNext_device_code()); + jo.put("hasGoodStatus", "0"); + jo.put("material_type", ""); + jo.put("batch", ""); + jo1.put("islock", "false"); + deviceService.changeDeviceStatus(jo1); + + String instnextdevice = entity.getNext_device_code(); + Device device = appService.findDeviceByCode(instnextdevice); + if (device == null) { + log.debug("地址对应设备未找到"); + return; + } + + removeByCodeFromCache(entity.getInstruction_code()); + } + } + + + @Override + public Instruction findByLinkNumSend(String code) { + Iterator it = instructions.iterator(); + while (it.hasNext()){ + Instruction inst = it.next(); + if (StrUtil.equals(code, inst.getLink_num()) && StrUtil.equals(inst.getIs_send(), "1")) { + return inst; + } + } + + return null; + } + + + @Override + public List findByLinkNum(String code) { + List list = new ArrayList<>(); + Iterator it = instructions.iterator(); + while (it.hasNext()){ + Instruction inst = it.next(); + if (StrUtil.equals(code, inst.getLink_num()) && StrUtil.equals(inst.getIs_send(), "0")) { + list.add(inst); + } + } + return list; + } + + @Override + public Instruction findByLinkNumNoSend(String code) { + Iterator it = instructions.iterator(); + while (it.hasNext()){ + Instruction inst = it.next(); + if (StrUtil.equals(code, inst.getLink_num()) && StrUtil.equals(inst.getIs_send(), "0")) { + return inst; + } + } + + return null; + } + + @Override + public Instruction findByCodeFromCache(String code) { + Iterator it = instructions.iterator(); + while (it.hasNext()){ + Instruction inst = it.next(); + if (StrUtil.equals(code, inst.getInstruction_code())) { + return inst; + } + } + return null; + } + + + @Override + public Instruction findByBarcodeFromCache(String barcode) { + Iterator it = instructions.iterator(); + while (it.hasNext()){ + Instruction inst = it.next(); + if (StrUtil.equals(barcode, inst.getVehicle_code())) { + return inst; + } + } + return null; + } + + @Override + public Instruction findByIdFromCache(String id) { + Iterator it = instructions.iterator(); + while (it.hasNext()){ + Instruction inst = it.next(); + if (StrUtil.equals(id, inst.getInstruction_id())) { + return inst; + } + } + return null; + } + + @Override + public Instruction foramte(Instruction inst) { + String start_point_code = inst.getStart_point_code(); + String next_point_code = inst.getNext_point_code(); + String start_device_code = ""; + String next_device_code = ""; + if (StrUtil.contains(start_point_code, ".")) { + String[] point = start_point_code.split("\\."); + start_device_code = point[0]; + } else { + start_device_code = start_point_code; + } + if (StrUtil.contains(next_point_code, ".")) { + String[] point = next_point_code.split("\\."); + next_device_code = point[0]; + } else { + next_device_code = next_point_code; + } + if (StrUtil.contains(start_point_code, "-") && StrUtil.count(start_point_code, "-") == 2) { + String[] start_point = start_point_code.split("-"); + inst.setFrom_x(start_point[0]); + inst.setStart_device_code(start_point[0]); + inst.setFrom_y(start_point[1]); + inst.setFrom_z(start_point[2]); + } else { + String start_device = deviceAppService.findDeviceByCode(start_device_code).getDeviceDriverDefination().getFitDeviceTypes().get(0).name(); + if (StrUtil.equals("storage", start_device)) { + String[] start_point = start_point_code.split("-"); + inst.setFrom_x(start_point[0]); + inst.setStart_device_code(start_point[0]); + inst.setFrom_y(start_point[1]); + inst.setFrom_z(start_point[2]); + } else { + inst.setStart_device_code(start_device_code); + } + } + + if (StrUtil.contains(next_point_code, "-") && StrUtil.count(next_point_code, "-") == 2) { + String[] next_point = next_point_code.split("-"); + inst.setTo_x(next_point[0]); + inst.setNext_device_code(next_point[0]); + inst.setTo_y(next_point[1]); + inst.setTo_z(next_point[2]); + } else { + + String next_device = deviceAppService.findDeviceByCode(next_device_code).getDeviceDriverDefination().getFitDeviceTypes().get(0).name(); + if (StrUtil.equals("storage", next_device)) { + String[] next_point = start_point_code.split("-"); + inst.setTo_x(next_point[0]); + inst.setNext_device_code(next_point[0]); + inst.setTo_y(next_point[1]); + inst.setTo_z(next_point[2]); + } else { + inst.setNext_device_code(next_device_code); + } + } return inst; - } } - return null; - } + @Override + public Instruction findByDeviceCodeFromCache(String devicecode) { - @Override - public List findByLinkNum(String code) { - List list = new ArrayList<>(); - Iterator it = instructions.iterator(); - while (it.hasNext()) { - Instruction inst = it.next(); - if (StrUtil.equals(code, inst.getLink_num()) && StrUtil.equals(inst.getIs_send(), "0")) { - list.add(inst); - } - } - return list; - } - - @Override - public Instruction findByLinkNumNoSend(String code) { - Iterator it = instructions.iterator(); - while (it.hasNext()) { - Instruction inst = it.next(); - if (StrUtil.equals(code, inst.getLink_num()) && StrUtil.equals(inst.getIs_send(), "0")) { - return inst; - } - } - - return null; - } - - @Override - public Instruction findByCodeFromCache(String code) { - Iterator it = instructions.iterator(); - while (it.hasNext()) { - Instruction inst = it.next(); - if (StrUtil.equals(code, inst.getInstruction_code())) { - return inst; - } - } - return null; - } - - @Override - public Instruction findByBarcodeFromCache(String barcode) { - Iterator it = instructions.iterator(); - while (it.hasNext()) { - Instruction inst = it.next(); - if (StrUtil.equals(barcode, inst.getVehicle_code())) { - return inst; - } - } - return null; - } - - @Override - public Instruction findByIdFromCache(String id) { - Iterator it = instructions.iterator(); - while (it.hasNext()) { - Instruction inst = it.next(); - if (StrUtil.equals(id, inst.getInstruction_id())) { - return inst; - } - } - return null; - } - - @Override - public Instruction foramte(Instruction inst) { - String start_point_code = inst.getStart_point_code(); - String next_point_code = inst.getNext_point_code(); - String start_device_code = ""; - String next_device_code = ""; - if (StrUtil.contains(start_point_code, ".")) { - String[] point = start_point_code.split("\\."); - start_device_code = point[0]; - } else { - start_device_code = start_point_code; - } - if (StrUtil.contains(next_point_code, ".")) { - String[] point = next_point_code.split("\\."); - next_device_code = point[0]; - } else { - next_device_code = next_point_code; - } - if (StrUtil.contains(start_point_code, "-") && StrUtil.count(start_point_code, "-") == 2) { - String[] start_point = start_point_code.split("-"); - inst.setFrom_x(start_point[0]); - inst.setStart_device_code(start_point[0]); - inst.setFrom_y(start_point[1]); - inst.setFrom_z(start_point[2]); - } else { - String start_device = - deviceAppService - .findDeviceByCode(start_device_code) - .getDeviceDriverDefination() - .getFitDeviceTypes() - .get(0) - .name(); - if (StrUtil.equals("storage", start_device)) { - String[] start_point = start_point_code.split("-"); - inst.setFrom_x(start_point[0]); - inst.setStart_device_code(start_point[0]); - inst.setFrom_y(start_point[1]); - inst.setFrom_z(start_point[2]); - } else { - inst.setStart_device_code(start_device_code); - } - } - - if (StrUtil.contains(next_point_code, "-") && StrUtil.count(next_point_code, "-") == 2) { - String[] next_point = next_point_code.split("-"); - inst.setTo_x(next_point[0]); - inst.setNext_device_code(next_point[0]); - inst.setTo_y(next_point[1]); - inst.setTo_z(next_point[2]); - } else { - - String next_device = - deviceAppService - .findDeviceByCode(next_device_code) - .getDeviceDriverDefination() - .getFitDeviceTypes() - .get(0) - .name(); - if (StrUtil.equals("storage", next_device)) { - String[] next_point = start_point_code.split("-"); - inst.setTo_x(next_point[0]); - inst.setNext_device_code(next_point[0]); - inst.setTo_y(next_point[1]); - inst.setTo_z(next_point[2]); - } else { - inst.setNext_device_code(next_device_code); - } - } - return inst; - } - - @Override - public Instruction findByDeviceCodeFromCache(String devicecode) { - - List instructionList = instructions; - try { - ListUtil.sort( - instructionList, - new Comparator() { + List instructionList = instructions; + ListUtil.sort(instructionList, new Comparator() { @Override public int compare(Instruction o1, Instruction o2) { - return o1.getCreate_time().compareTo(o2.getCreate_time()); + return o1.getCreate_time().compareTo(o2.getCreate_time()); + } + }); + for (int i = 0; i < instructionList.size(); i++) { + Instruction inst = instructionList.get(i); + if (StrUtil.equals(devicecode, inst.getStart_device_code()) && inst.getInstruction_status().equals("0")) { + return inst; } - }); - 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; } - } - } catch (Exception e) { - log.warn("指令排序按照创建时间执执行失败!重新执行"); - //失败之后重新查找指令 - return findByDeviceCodeFromCache(devicecode); + return null; } - return null; - } - - @Override - public List findAllInstFromCache() { - return instructions; - } - - @Override - public Integer querySameDestinationInst(String devicecode) { - int num = 0; - Iterator it = instructions.iterator(); - while (it.hasNext()) { - Instruction inst = it.next(); - // 处理空盘位站点 - String next_code = inst.getNext_point_code(); - if (next_code.indexOf(".") != -1) { - next_code = next_code.substring(0, next_code.indexOf(".")); - } - if (StrUtil.equals(devicecode, next_code)) { - num = num + 1; - } + @Override + public List findAllInstFromCache() { + return instructions; } - return num; - } - @Override - public Integer querySameInstType(String inst_type) { - int num = 0; - Iterator it = instructions.iterator(); - while (it.hasNext()) { - Instruction inst = it.next(); - if (StrUtil.equals(inst.getInstruction_type(), inst_type)) { - num = num + 1; - } - } - return num; - } - - @Override - public Integer querySameOriginInst(String devicecode) { - int num = 0; - Iterator it = instructions.iterator(); - while (it.hasNext()) { - Instruction inst = it.next(); - // 处理空盘位站点 - String start_code = inst.getStart_point_code(); - if (start_code.indexOf(".") != -1) { - start_code = start_code.substring(0, start_code.indexOf(".")); - } - if (StrUtil.equals(devicecode, start_code)) { - num = num + 1; - } - } - return num; - } - - @Override - public boolean removeByCodeFromCache(String code) { - - Iterator iterator = instructions.iterator(); - while (iterator.hasNext()) { - Instruction instruction = iterator.next(); - if (instruction.getInstruction_code().equals(code)) { - iterator.remove(); - return true; - } - } - return false; - } - - @Override - public boolean createLkInst(String type, Instruction dto) { - Class var3 = TaskInstructionLock.class; - synchronized (TaskInstructionLock.class) { - // 入库 - AcsToLiKuService acsToLiKuService = SpringContextHolder.getBean(AcsToLiKuService.class); - Resp resp = null; - if (StrUtil.equals(type, "1")) { - InStoreRequest request = new InStoreRequest(); - request.setFloorNo(Integer.parseInt(dto.getTo_z())); - request.setType(1); - request.setPalletCode(dto.getVehicle_code()); - request.setOrderId(dto.getInstruction_code()); - request.setSrcLocation(dto.getStart_point_code()); - request.setDestLocation(dto.getNext_point_code()); - resp = acsToLiKuService.inStore(request); - // 空托入库 - } else if (StrUtil.equals(type, "2")) { - InStoreRequest request = new InStoreRequest(); - request.setFloorNo(Integer.parseInt(dto.getTo_z())); - request.setType(2); - request.setPalletCode(dto.getVehicle_code()); - request.setOrderId(dto.getInstruction_code()); - request.setSrcLocation(dto.getStart_point_code()); - request.setDestLocation(dto.getNext_point_code()); - resp = acsToLiKuService.inStore(request); - // 出库 - } else if (StrUtil.equals(type, "3")) { - OutStoreRequest outStore = new OutStoreRequest(); - BaseStoreRequest baseReq = new BaseStoreRequest(); - List list = new ArrayList(); - baseReq.setOrderId(dto.getInstruction_code()); - baseReq.setSrcLocation(dto.getStart_point_code()); - baseReq.setDestLocation(dto.getNext_point_code()); - baseReq.setFloorNo(Integer.parseInt(dto.getFrom_z())); - baseReq.setPalletCode(dto.getVehicle_code()); - list.add(baseReq); - outStore.setOrderInfos(list); - outStore.setGroupId(dto.getInstruction_code()); - resp = acsToLiKuService.outStore(outStore); - // 空托出库 - } else if (StrUtil.equals(type, "4")) { - EmptyVehicleOutStoreRequest emptyVehicleOutStoreRequest = new EmptyVehicleOutStoreRequest(); - emptyVehicleOutStoreRequest.setOrderId(dto.getInstruction_code()); - emptyVehicleOutStoreRequest.setFloorNo(Integer.parseInt(dto.getFrom_z())); - emptyVehicleOutStoreRequest.setSrcLocation(dto.getStart_point_code()); - emptyVehicleOutStoreRequest.setDestLocation(dto.getNext_point_code()); - emptyVehicleOutStoreRequest.setPalletCode(dto.getVehicle_code()); - resp = acsToLiKuService.emptyVehicleOutStore(emptyVehicleOutStoreRequest); - // 转库 - } else if (StrUtil.equals(type, "5")) { - MoveStoreRequest moveStoreRequest = new MoveStoreRequest(); - BaseStoreRequest baseReq = new BaseStoreRequest(); - List list = new ArrayList(); - baseReq.setFloorNo(Integer.parseInt(dto.getFrom_z())); - baseReq.setPalletCode(dto.getVehicle_code()); - baseReq.setOrderId(dto.getInstruction_code()); - baseReq.setSrcLocation(dto.getStart_point_code()); - baseReq.setDestLocation(dto.getNext_point_code()); - list.add(baseReq); - moveStoreRequest.setGroupId(dto.getInstruction_code()); - moveStoreRequest.setOrderInfos(list); - resp = acsToLiKuService.moveStore(moveStoreRequest); - } - - if (ObjectUtil.isNotEmpty(resp)) { - if (StrUtil.equals(resp.getResult(), "true")) { - dto.setSend_status("1"); - } else { - dto.setSend_status("2"); - dto.setRemark(resp.getData().toString()); - return false; + @Override + public Integer querySameDestinationInst(String devicecode) { + int num = 0; + Iterator it = instructions.iterator(); + while (it.hasNext()){ + Instruction inst = it.next(); + //处理空盘位站点 + String next_code = inst.getNext_point_code(); + if (next_code.indexOf(".") != -1) { + next_code = next_code.substring(0, next_code.indexOf(".")); + } + if (StrUtil.equals(devicecode, next_code)) { + num = num + 1; + } + } + + return num; + } + + @Override + public Integer querySameInstType(String inst_type) { + int num = 0; + Iterator it = instructions.iterator(); + while (it.hasNext()){ + Instruction inst = it.next(); + if (StrUtil.equals(inst.getInstruction_type(), inst_type)) { + num = num + 1; + } + } + return num; + } + + @Override + public Integer querySameOriginInst(String devicecode) { + int num = 0; + Iterator it = instructions.iterator(); + while (it.hasNext()){ + Instruction inst = it.next(); + //处理空盘位站点 + String start_code = inst.getStart_point_code(); + if (start_code.indexOf(".") != -1) { + start_code = start_code.substring(0, start_code.indexOf(".")); + } + if (StrUtil.equals(devicecode, start_code)) { + num = num + 1; + } + } + return num; + } + + @Override + public boolean removeByCodeFromCache(String code) { + + Iterator iterator = instructions.iterator(); + while (iterator.hasNext()) { + Instruction instruction = iterator.next(); + if (instruction.getInstruction_code().equals(code)) { + iterator.remove(); + return true; + } } - } else { - dto.setSend_status("2"); - dto.setRemark("ERROR"); return false; - } - return true; - } - } - - public Instruction findByContainer(String container_code) { - Iterator var3 = instructions.iterator(); - - while (var3.hasNext()) { - Instruction instruction = (Instruction) var3.next(); - if (StrUtil.equals(instruction.getVehicle_code(), container_code)) { - return instruction; - } } - return null; - } - /* - * 判断是否为整数 - * @param str 传入的字符串 - * @return 是整数返回true,否则返回false - */ - public static boolean isInteger(String str) { - Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$"); - return pattern.matcher(str).matches(); - } + @Override + public 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); + } - @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("指令已经完成"); + 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; + } } - 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); + public Instruction findByContainer(String container_code) { + Iterator var3 = instructions.iterator(); + + while (var3.hasNext()) { + Instruction instruction = (Instruction) var3.next(); + if (StrUtil.equals(instruction.getVehicle_code(), container_code)) { + return instruction; + } + } + + return null; + } + + /* + * 判断是否为整数 + * @param str 传入的字符串 + * @return 是整数返回true,否则返回false + */ + public static boolean isInteger(String str) { + Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$"); + return pattern.matcher(str).matches(); + } + + @Override + public void init(String id) { + Instruction inst = this.findById(id); + if (inst == null) { + throw new BadRequestException("指令不存在或已删除"); + } + if ("2".equals(inst.getInstruction_status())) { + throw new BadRequestException("指令已经完成"); + } + + Device startDevice = deviceAppService.findDeviceByCode(inst.getStart_device_code()); + DeviceDriver startDeviceDriver = startDevice.getDeviceDriver(); + if (startDeviceDriver instanceof SiemensConveyorDeviceDriver) { + Device nextDevice = deviceAppService.findDeviceByCode(inst.getNext_device_code()); + + List> list = new ArrayList<>(); + Map map = new HashMap<>(); + map.put("code", "to_target"); + map.put("value", nextDevice.getExtraValue().get("address").toString()); + list.add(map); + Map map2 = new HashMap<>(); + map2.put("code", "to_task"); + map2.put("value", inst.getInstruction_code()); + list.add(map2); + Map map3 = new HashMap<>(); + map3.put("code", "to_command"); + map3.put("value", "1"); + list.add(map3); + ((SiemensConveyorDeviceDriver) startDeviceDriver).writing(list); + } } - } } diff --git a/acs/nladmin-ui/src/views/acs/device/config.vue b/acs/nladmin-ui/src/views/acs/device/config.vue index 8877dfa29..477cdc6d1 100644 --- a/acs/nladmin-ui/src/views/acs/device/config.vue +++ b/acs/nladmin-ui/src/views/acs/device/config.vue @@ -94,6 +94,7 @@ import hongxiang_device from '@/views/acs/device/driver/hongxiang_device' import hongxiang_conveyor from '@/views/acs/device/driver/hongxiang_conveyor' import plug_pull_device_site from '@/views/acs/device/driver/plug_pull_device_site' import siemens_conveyor_labeling from '@/views/acs/device/driver/siemens_conveyor_labeling' +import siemens_conveyor_ckk from '@/views/acs/device/driver/siemens_conveyor_ckk' export default { name: 'DeviceConfig', @@ -118,7 +119,8 @@ export default { siemens_conveyor, slit_two_manipulator, plug_pull_device_site, - siemens_conveyor_labeling + siemens_conveyor_labeling, + siemens_conveyor_ckk }, dicts: ['device_type'], mixins: [crud], diff --git a/acs/nladmin-ui/src/views/acs/device/driver/siemens_conveyor_ckk.vue b/acs/nladmin-ui/src/views/acs/device/driver/siemens_conveyor_ckk.vue new file mode 100644 index 000000000..5ac1fdee1 --- /dev/null +++ b/acs/nladmin-ui/src/views/acs/device/driver/siemens_conveyor_ckk.vue @@ -0,0 +1,513 @@ + + + + +