diff --git a/nladmin-system/src/main/java/org/nl/acs/agv/server/impl/AgvServiceImpl.java b/nladmin-system/src/main/java/org/nl/acs/agv/server/impl/AgvServiceImpl.java index 14f915e..d846ff5 100644 --- a/nladmin-system/src/main/java/org/nl/acs/agv/server/impl/AgvServiceImpl.java +++ b/nladmin-system/src/main/java/org/nl/acs/agv/server/impl/AgvServiceImpl.java @@ -328,10 +328,15 @@ public class AgvServiceImpl implements AgvService { log.info("下发agv指令参数:{}", orderjo.toString()); - HttpResponse result = HttpRequest.post(agvurl) - .body(String.valueOf(orderjo))//表单内容 - .timeout(20000)//超时,毫秒 - .execute(); + HttpResponse result = null; + try { + result = HttpRequest.post(agvurl) + .body(String.valueOf(orderjo))//表单内容 + .timeout(20000)//超时,毫秒 + .execute(); + } catch (Exception e) { + throw new RuntimeException("下发agv失败!"); + } return result; } else { return null; @@ -610,10 +615,15 @@ public class AgvServiceImpl implements AgvService { agvurl = agvurl + ":" + agvport + "/v1/transportOrders/" + instCode + "/withdrawal"; log.info("删除agv指令请求agvurl:{}", agvurl); - HttpResponse result = HttpRequest.post(agvurl) - .timeout(20000)//超时,毫秒 - .execute(); - log.info("删除agv指令请求反馈:{}", result); + HttpResponse result = null; + try { + result = HttpRequest.post(agvurl) + .timeout(20000)//超时,毫秒 + .execute(); + log.info("删除agv指令请求反馈:{}", result); + } catch (Exception e) { + throw new RuntimeException("下发agv失败!"); + } return result; diff --git a/nladmin-system/src/main/java/org/nl/acs/device/device_driver/DriverTypeEnum.java b/nladmin-system/src/main/java/org/nl/acs/device/device_driver/DriverTypeEnum.java index 0085f62..df33776 100644 --- a/nladmin-system/src/main/java/org/nl/acs/device/device_driver/DriverTypeEnum.java +++ b/nladmin-system/src/main/java/org/nl/acs/device/device_driver/DriverTypeEnum.java @@ -9,47 +9,47 @@ import com.alibaba.fastjson.JSONObject; * https://blog.csdn.net/moneyshi/article/details/82978073 */ public enum DriverTypeEnum { - ORDINARY_SITE(1, "standard_ordinary_site", "普通站点", "conveyor"), + ORDINARY_SITE(1, "standard_ordinary_site", "普通站点", "station"), - WEIGHING_SITE(2, "weighing_site", "称重站点", "conveyor"), + WEIGHING_SITE(2, "weighing_site", "称重站点", "station"), - INSPECT_SITE(3, "standard_inspect_site", "检测站点", "conveyor"), + INSPECT_SITE(3, "standard_inspect_site", "检测站点", "station"), - NON_LINE_INSPECT_SITE(4, "non_line_inspect_site", "检测站点-无PLC", "conveyor"), + NON_LINE_INSPECT_SITE(4, "non_line_inspect_site", "检测站点-无PLC", "station"), - MACHINES_SITE(5, "machines_site", "机台设备-无光电", "conveyor"), + MACHINES_SITE(5, "machines_site", "机台设备-无光电", "station"), - SPECIAL_SITE(6, "standard_special_inspect_site", "专机设备交互站点", "conveyor"), + SPECIAL_SITE(6, "standard_special_inspect_site", "专机设备交互站点", "station"), - MANIPULATOR_SITE(7, "standard_manipulator_inspect_site", "区域管制设备交互站点", "conveyor"), + MANIPULATOR_SITE(7, "standard_manipulator_inspect_site", "区域管制设备交互站点", "station"), - NON_LINE_MANIPULATOR_SITE(8, "non_line_manipulator_inspect_site", "区域管制设备交互站点-无PLC", "conveyor"), + NON_LINE_MANIPULATOR_SITE(8, "non_line_manipulator_inspect_site", "区域管制设备交互站点-无PLC", "station"), AUTODOOR(9, "standard_autodoor", "标准版-自动门", "autodoor"), - STACK_EMPUYPALLET_SITE(10, "standard_emptypallet_site", "标准版-空盘叠盘站点", "conveyor"), + STACK_EMPUYPALLET_SITE(10, "standard_emptypallet_site", "标准版-空盘叠盘站点", "station"), - LAMP_THREE_COLOR(11, "lamp_three_color", "标准版-三色灯", "三色灯"), + LAMP_THREE_COLOR(11, "lamp_three_color", "标准版-三色灯", "alarmLamp"), - SPECIAL_ORDINARY_SITE(12, "special_ordinary_site", "特殊版-普通站点-关联锁定", "conveyor"), + SPECIAL_ORDINARY_SITE(12, "special_ordinary_site", "特殊版-普通站点-关联锁定", "station"), STORAGE(13, "standard_storage", "标准版-货架", "storage"), SCANNER(14, "standard_scanner", "标准版-扫码器", "scanner"), - INSPECT_CONVEYOR_CONTROL_WITH_SCANNER(15, "standard_conveyor_control_with_scanner", "标准版-输送机-控制点-关联扫码", "conveyor"), + INSPECT_CONVEYOR_CONTROL_WITH_SCANNER(15, "standard_conveyor_control_with_scanner", "标准版-输送机-控制点-关联扫码", "station"), INSPECT_CONVEYOR_CONTROL(16, "standard_conveyor_control", "标准版-输送机-控制点", "conveyor"), INSPECT_CONVEYOR_MONITOR(17, "standard_conveyor_monitor", "标准版-输送机-监控点", "conveyor"), - MANIPULATOR_INSPECT_SITE_NDC(18, "manipulator_inspect_site_NDC", "区域管制设备交互站点-NDC", "conveyor"), + MANIPULATOR_INSPECT_SITE_NDC(18, "manipulator_inspect_site_NDC", "区域管制设备交互站点-NDC", "station"), - FEEDBACK_AGV_STATUS_SITE(19, "feedback_agv_status_site", "上报AGV状态站点", "conveyor"), + FEEDBACK_AGV_STATUS_SITE(19, "feedback_agv_status_site", "上报AGV状态站点", "station"), MANIPULATOR_STACKING_SITE(20, "standard_manipulator_stacking_site", "机械手码垛驱动(区分托盘类型)", "conveyor"), - PHOTOELECTRIC_INSPECT_SITE(21, "standard_photoelectric_inspect_site", "光电检测站点(优先出库)", "conveyor"), + PHOTOELECTRIC_INSPECT_SITE(21, "standard_photoelectric_inspect_site", "光电检测站点(优先出库)", "station"), HAILIANG_PACKING(22, "hailiang_packing", "海亮项目-包装机", "conveyor"), @@ -57,9 +57,9 @@ public enum DriverTypeEnum { HAILIANG_COATING(24, "hailiang_coating", "海亮项目-裹膜机", "conveyor"), - NDXY_SPECIAL(25, "ndxy_special", "纽迪希亚专用", "conveyor"), + NDXY_SPECIAL(25, "ndxy_special", "纽迪希亚专用", "station"), - NDXY_SPECIAL_TWO(26, "ndxy_special_two", "纽迪希亚专用2", "conveyor"), + NDXY_SPECIAL_TWO(26, "ndxy_special_two", "纽迪希亚专用2", "station"), INSPECT_CONVEYOR_CONTROL_WITH_PLCSCANNER(27, "standard_conveyor_control_with_plcscanner", "标准版-输送机-控制点-PLC扫码", "conveyor"), @@ -75,11 +75,39 @@ public enum DriverTypeEnum { OUMULONGPLC(33, "oumulong_plc", "标准版-自动门-欧姆龙plc", "autodoor"), - TRAFFIC_LIGHT(34, "traffic_light", "标准版-交通灯-欧姆龙plc", "三色灯"), + TRAFFIC_LIGHT(34, "traffic_light", "标准版-交通灯-欧姆龙plc", "alarmLamp"), STANDARD_RGV(35, "standard_rgv", "标准版-RGV", "rgv"), - YKBK_SPECIAL(36, "ykbk_special", "伊科拜克默认物料", "conveyor"); + YKBK_SPECIAL(36, "ykbk_special", "伊科拜克默认物料", "station"), + + LNSH_MIXING_MILL(37, "lnsh_mixing_mill", "晟华-混碾机", "station"), + + LNSH_PRESS(38, "lnsh_press", "晟华-压力机", "station"), + + LNSH_PALLETIZING_MANIPULATOR(39, "lnsh_palletizing_manipulator", "晟华-码垛机械手", "station"), + + LNSH_KILN_TRUSS(40, "lnsh_kiln_truss", "晟华-入窑桁架", "station"), + + LNSH_OUT_KILN_TRUSS(41, "lnsh_out_kiln_truss", "晟华-出窑桁架", "station"), + + LNSH_KILN_LANE(42, "lnsh_kiln_lane", "晟华-窑车道", "station"), + + LNSH_FOLD_DISC_SITE(43, "lnsh_fold_disc_site", "晟华-叠盘工位", "station"), + + LNSH_PALLET_STORAGE(44, "lnsh_pallet_storage", "晟华-托盘存储线", "station"), + + LNSH_PACKAGE_PALLET_MANIPULATOR(45, "lnsh_package_pallet_manipulator", "晟华-包装码垛机械手", "station"), + + LNSH_LABELING_MACHINE(46, "lnsh_labeling_machine", "晟华-贴标机", "station"), + + LNSH_SPLIT_MANIPULATOR(47, "lnsh_split_manipulator", "晟华-拆垛机械手", "station"), + + LNSH_RGV(48, "lnsh_rgv", "晟华-RGV", "station"), + + LNSH_PACKAGE_LINE(49, "lnsh_package_line", "晟华-包装线", "station"), + + LNSH_STATION(50, "lnsh_station", "晟华-工位(交互模板)", "station"); //驱动索引 diff --git a/nladmin-system/src/main/java/org/nl/acs/device/rest/DeviceController.java b/nladmin-system/src/main/java/org/nl/acs/device/rest/DeviceController.java index dfdb620..ff6b4f1 100644 --- a/nladmin-system/src/main/java/org/nl/acs/device/rest/DeviceController.java +++ b/nladmin-system/src/main/java/org/nl/acs/device/rest/DeviceController.java @@ -49,6 +49,15 @@ public class DeviceController { return new ResponseEntity<>(deviceService.queryAll(whereJson, page), HttpStatus.OK); } + @GetMapping("/reload") + @Log("数据同步") + @ApiOperation("数据同步") + //@PreAuthorize("@el.check('task:list')") + public ResponseEntity reload() { + deviceService.reload(); + return new ResponseEntity<>(HttpStatus.OK); + } + @GetMapping("/protocol") @Log("查询设备协议") @ApiOperation("查询设备协议") diff --git a/nladmin-system/src/main/java/org/nl/acs/device/service/impl/DeviceAssignedServiceImpl.java b/nladmin-system/src/main/java/org/nl/acs/device/service/impl/DeviceAssignedServiceImpl.java index b089232..7bcd791 100644 --- a/nladmin-system/src/main/java/org/nl/acs/device/service/impl/DeviceAssignedServiceImpl.java +++ b/nladmin-system/src/main/java/org/nl/acs/device/service/impl/DeviceAssignedServiceImpl.java @@ -4,6 +4,7 @@ package org.nl.acs.device.service.impl; import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.IdUtil; +import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import lombok.RequiredArgsConstructor; @@ -167,19 +168,39 @@ public class DeviceAssignedServiceImpl implements DeviceAssignedService { } @Override - public List queryAssignedBydevice(String device_code, String task_nextdeice_code) { + public List queryAssignedBydevice(String device_code, String old_task_nextdevice_code) { WQLObject wo = WQLObject.getWQLObject("acs_device_assigned"); - JSONArray arr = wo.query("device_code ='" + device_code + "' and task_nextDevice_code= '" + task_nextdeice_code + "'").getResultJSONArray(0); + JSONArray arr = wo.query("device_code ='" + device_code + "'").getResultJSONArray(0); List list = new ArrayList(); for (int i = 0; i < arr.size(); i++) { JSONObject jo = arr.getJSONObject(i); - DeviceAssignedDto dto = new DeviceAssignedDto(); - dto.setAssigned_id(jo.getString("assigned_id")); - dto.setDevice_code(jo.getString("device_code")); - dto.setInst_nextdevice_code(jo.getString("inst_nextdevice_code")); - dto.setTask_nextdevice_code(jo.getString("task_nextdevice_code")); - dto.setParam(jo.getString("param")); - list.add(dto); + if(jo.getString("task_nextdevice_code").indexOf(",") != -1){ + String task_nextdevice_code[] = jo.getString("task_nextdevice_code").split(","); + for(int j=0;j getReadableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_heartbeat, "心跳", "DB600.B0")); + list.add(new ItemDto(item_mode, "工作状态", "DB600.B1", Boolean.valueOf(true))); + list.add(new ItemDto(item_status, "设备状态", "DB600.B2")); + list.add(new ItemDto(item_open_time, "开机时间", "DB600.B4")); + list.add(new ItemDto(item_close_time, "关机时间", "DB600.D5")); + list.add(new ItemDto(item_standby_time, "待机时间", "DB600.D6")); + list.add(new ItemDto(item_production_time, "生产时间", "DB600.D7")); + list.add(new ItemDto(item_error_time, "故障时间", "DB600.D8")); + list.add(new ItemDto(item_container_qty, "托盘数", "DB600.D8")); + return list; + } + + public static List getWriteableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_to_command, "下发命令反馈", "DB601.W2", Boolean.valueOf(true))); + list.add(new ItemDto(item_to_target, "下发目标站", "DB601.W4")); + list.add(new ItemDto(item_to_task, "下发任务号", "DB601.D8")); + return list; + } + +} + diff --git a/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_fold_disc_site/LnshFoldDiscSiteDefination.java b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_fold_disc_site/LnshFoldDiscSiteDefination.java new file mode 100644 index 0000000..e7c7d55 --- /dev/null +++ b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_fold_disc_site/LnshFoldDiscSiteDefination.java @@ -0,0 +1,75 @@ +package org.nl.acs.device_driver.lnsh.lnsh_fold_disc_site; + +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.ArrayList; +import java.util.LinkedList; +import java.util.List; + +/** + * 晟华叠盘工位 + */ +@Service +public class LnshFoldDiscSiteDefination implements OpcDeviceDriverDefination { + @Override + public String getDriverCode() { + return "lnsh_fold_disc_site"; + } + + @Override + public String getDriverName() { + return "晟华-叠盘工位"; + } + + @Override + public String getDriverDescription() { + return "晟华-叠盘工位"; + } + + @Override + public DeviceDriver getDriverInstance(Device device) { + return (new LnshFoldDiscSiteDeviceDriver()).setDevice(device).setDriverDefination(this); + } + + @Override + public Class getDeviceDriverType() { + return LnshFoldDiscSiteDeviceDriver.class; + } + + @Override + public List getFitDeviceTypes() { + List types = new LinkedList(); + types.add(DeviceType.conveyor); + return types; + } + + @Override + public List getReadableItemDtos() { + return getReadableItemDtos2(); + } + + public static List getReadableItemDtos2() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(ItemProtocol.item_heartbeat, "心跳", "DB600.B0")); + list.add(new ItemDto(ItemProtocol.item_mode, "工作状态", "DB600.B1", Boolean.valueOf(true))); + list.add(new ItemDto(ItemProtocol.item_status, "设备状态", "DB600.B2")); + list.add(new ItemDto(ItemProtocol.item_open_time, "开机时间", "DB600.B4")); + list.add(new ItemDto(ItemProtocol.item_close_time, "关机时间", "DB600.D5")); + list.add(new ItemDto(ItemProtocol.item_standby_time, "待机时间", "DB600.D6")); + list.add(new ItemDto(ItemProtocol.item_production_time, "生产时间", "DB600.D7")); + list.add(new ItemDto(ItemProtocol.item_error_time, "故障时间", "DB600.D8")); + list.add(new ItemDto(ItemProtocol.item_container_qty, "托盘数", "DB600.D8")); + return list; + } + + @Override + public List getWriteableItemDtos() { + return ItemProtocol.getWriteableItemDtos(); + } + +} diff --git a/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_fold_disc_site/LnshFoldDiscSiteDeviceDriver.java b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_fold_disc_site/LnshFoldDiscSiteDeviceDriver.java new file mode 100644 index 0000000..06eb47a --- /dev/null +++ b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_fold_disc_site/LnshFoldDiscSiteDeviceDriver.java @@ -0,0 +1,336 @@ +package org.nl.acs.device_driver.lnsh.lnsh_fold_disc_site; + +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.IdUtil; +import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSONObject; +import lombok.Data; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.device.device_driver.standard_inspect.ReadUtil; +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.instruction.service.InstructionService; +import org.nl.acs.instruction.service.dto.Instruction; +import org.nl.acs.opc.Device; +import org.nl.acs.opc.WcsConfig; +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.util.CodeUtil; +import org.nl.utils.SpringContextHolder; +import org.nl.wql.core.bean.WQLObject; +import org.openscada.opc.lib.da.Server; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.*; + +/** + * 晟华叠盘工位 + */ +@Slf4j +@Data +@RequiredArgsConstructor +public class LnshFoldDiscSiteDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver { + protected ItemProtocol itemProtocol = new ItemProtocol(this); + @Autowired + InstructionService instructionService = SpringContextHolder.getBean("instructionServiceImpl"); + @Autowired + DeviceService deviceservice = SpringContextHolder.getBean("deviceServiceImpl"); + @Autowired + RouteLineService routelineserver = SpringContextHolder.getBean("routeLineServiceImpl"); + @Autowired + TaskService taskserver = SpringContextHolder.getBean("taskServiceImpl"); + + + String container; + String container_type_desc; + String last_container_type_desc; + String last_container; + //放货准备锁 + String putReadyLock = null; + //有货标记 + protected boolean has_goods_tag = false; + + + String device_code; + int mode = 0; + int error = 0; + int move = 0; + int action; + int io_action; + int task = 0; + int container_type = 0; + int last_mode = 0; + int last_error = 0; + int last_move = 0; + int last_task = 0; + int last_container_type; + Boolean isonline = true; + int hasGoods = 0; + Boolean iserror = false; + + boolean hasVehicle = false; + boolean isReady = false; + protected int instruction_num = 0; + protected int instruction_num_truth = 0; + boolean isFold = false; + private String assemble_check_tag; + private Boolean sampleMode0; + private Boolean sampleMode3; + private Integer sampleError; + private Boolean sampleOnline; + protected String displayMessage = null; + public int display_message_time_out = 30000; + public Date display_message_time; + protected String current_stage_instruction_message; + protected String last_stage_instruction_message; + Integer heartbeat_tag; + private Date instruction_require_time = new Date(); + private Date instruction_finished_time = new Date(); + + private int instruction_require_time_out = 3000; + boolean requireSucess = false; + + private int instruction_finished_time_out; + + int heartbeat; + int last_heartbeat; + private Date checkHeartbeattime = new Date(); + private Date last_checkHeartbeattime = new Date(); + + int branchProtocol = 0; + //当前指令 + Instruction inst = null; + //上次指令 + Instruction last_inst = null; + + //触摸屏手动触发任务 + private Boolean is_has_task = false; + + String message; + + @Override + public Device getDevice() { + return this.device; + } + + + @Override + public void execute() { + String message = null; + try { + device_code = this.getDeviceCode(); + + mode = this.itemProtocol.getMode(); + + } catch (Exception var17) { + return; + } + + //急停 + if (this.isStop()) { + + //未在线无心跳 + } else 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); + message = ""; + Instruction instruction = null; + List toInstructions; + switch (mode) { + case 1: + log.debug("设备运转模式:等待工作"); + break; + case 2: + + break; + case 3: + + break; + case 4: + break; + } + } + + last_mode = mode; + last_error = error; + last_move = move; + last_task = task; + last_container_type = container_type; + } + + + protected void thingToNothing() throws Exception { + this.setRequireSucess(false); + } + + public void finish_instruction(Instruction instruction) throws Exception { + instruction_finished(instruction); + } + + /** + * 完成指令 + * + * @param instruction + * @return + */ + public boolean instruction_finished(Instruction instruction) throws Exception { + Date date = new Date(); + if (date.getTime() - this.instruction_finished_time.getTime() < (long) this.instruction_finished_time_out) { + log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_finished_time_out); + return false; + } else { + instructionService.finish(instruction.getInstruction_id()); + this.instruction_finished_time = date; + return true; + } + } + + /** + * 完成并创建下一条指令 + * + * @param instruction + * @param needCreateNext + * @return + */ + public boolean instruction_finished(Instruction instruction, boolean needCreateNext) { + Date date = new Date(); + if (date.getTime() - this.instruction_finished_time.getTime() < (long) this.instruction_finished_time_out) { + log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_finished_time_out); + return false; + } else { + this.instruction_finished_time = date; + return true; + } + } + + + private Instruction findInstruction() { + Instruction instruction = null; + if (this.instruction_num != 0) { + instruction = (Instruction) instructionService.findByCodeFromCache(String.valueOf(instruction_num)); + } + if (instruction != null) { + //可进行校验 + + + } else { + List container_instructions = new ArrayList(); + String barcode = this.getLast_container(); + + if (!StrUtil.isEmpty(barcode)) { + Map map = new HashMap(); + map.put("vehicle_code", barcode); + container_instructions = instructionService.queryAll(map); + } + + if (((List) container_instructions).size() > 1) { + log.debug("容器存在多个指令"); + } else { + if (((List) container_instructions).size() > 0) { + instruction = (Instruction) ((List) container_instructions).get(0); + } + } + } + return instruction; + } + + + public boolean exe_error() { + if (this.error == 0) { + return true; + } else { + log.debug("设备报警"); + return false; + } + } + + public void set_last_container(String barcode, String type_desc) { + this.set_last_container(barcode); + this.set_last_container_type_desc(type_desc); + } + + public void set_last_container(String barcode) { + } + + public void set_last_container_type_desc(String type) { + } + + public boolean exe_business() { + return true; + } + + public void executing(Server server, Map itemMap) { + ReadUtil.write(itemMap, server); + } + + + public boolean instruction_require(String container_code) { + return instruction_require(container_code, WcsConfig.task_container_type_default_desc); + } + + /** + * 请求指令 + * + * @param container_code + * @param container_type + */ + public synchronized boolean instruction_require(String container_code, String container_type) { + 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; + TaskDto dto = new TaskDto(); + String now = DateUtil.now(); + dto.setTask_id(IdUtil.simpleUUID()); + dto.setCreate_by(this.getDevice().getDevice_code()); + dto.setUpdate_by(this.getDevice().getDevice_code()); + dto.setStart_point_code(this.getDevice().getDevice_code()); + dto.setVehicle_code(container_code); + dto.setVehicle_type(container_type); + + String taskcode = CodeUtil.getNewCode("TASK_NO"); + dto.setTask_code("-" + taskcode); + dto.setTask_status("0"); + dto.setPriority("101"); + RouteLineDto jo = routelineserver.findByCode(this.getDevice().getDevice_code()); + String next_device_codecode = jo.getNext_device_code(); + if (StrUtil.isEmpty(next_device_codecode)) { + throw new RuntimeException("该设备未找到对应路由"); + } + dto.setNext_point_code(next_device_codecode); + dto.setUpdate_time(now); + dto.setCreate_time(now); + + WQLObject wo = WQLObject.getWQLObject("acs_task"); + JSONObject json = (JSONObject) JSONObject.toJSON(dto); + + wo.insert(json); + requireSucess = false; + return true; + } + } + +} diff --git a/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_kiln_lane/ItemProtocol.java b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_kiln_lane/ItemProtocol.java new file mode 100644 index 0000000..38d2a95 --- /dev/null +++ b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_kiln_lane/ItemProtocol.java @@ -0,0 +1,123 @@ +package org.nl.acs.device_driver.lnsh.lnsh_kiln_lane; + +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_status = "status"; + public static String item_open_time = "open_time"; + public static String item_standby_time = "standby_time "; + public static String item_production_time = "production_time"; + public static String item_error_time = "error_time"; + public static String item_car_sum = "car_sum"; + public static String item_nullCar_qty = "nullCar_qty"; + public static String item_burning_car_qty = "burning_car_qty"; + public static String item_to_command = "to_command"; + public static String item_to_material_code = "to_material_code"; + Boolean isonline; + + private LnshKilnLaneDeviceDriver driver; + + public ItemProtocol(LnshKilnLaneDeviceDriver driver) { + this.driver = driver; + } + + public int getHeartbeat() { + return this.getOpcIntegerValue(item_heartbeat); + } + + public int getMode() { + return this.getOpcIntegerValue(item_mode); + } + + public int getStatus() { + return this.getOpcIntegerValue(item_status); + } + + public int getOpen_time() { + return this.getOpcIntegerValue(item_open_time); + } + + public int getStandby_time() { + return this.getOpcIntegerValue(item_standby_time); + } + + public int getProduction_time() { + return this.getOpcIntegerValue(item_production_time); + } + + public int getError_time() { + return this.getOpcIntegerValue(item_error_time); + } + + public int getCar_sum() { + return this.getOpcIntegerValue(item_car_sum); + } + + public int getNullCar_qty() { + return this.getOpcIntegerValue(item_nullCar_qty); + } + + public int getBurning_car_qty() { + return this.getOpcIntegerValue(item_burning_car_qty); + } + + public int getToCommand() { + return this.getOpcIntegerValue(item_to_command); + } + + public int getTo_material_code() { + return this.getOpcIntegerValue(item_to_material_code); + } + + //是否有货 + public int hasGoods(int move) { + return move; + } + + + 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 static List getReadableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_heartbeat, "心跳", "DB600.B0")); + list.add(new ItemDto(item_mode, "工作状态", "DB600.B1", Boolean.valueOf(true))); + list.add(new ItemDto(item_status, "设备状态", "DB600.B3")); + list.add(new ItemDto(item_open_time, "开机时间", "DB600.B4")); + list.add(new ItemDto(item_standby_time, "待机时间", "DB600.D6")); + list.add(new ItemDto(item_production_time, "生产时间", "DB600.D7")); + list.add(new ItemDto(item_error_time, "故障时间", "DB600.D8")); + list.add(new ItemDto(item_car_sum, "窑车总数", "DB600.B4")); + list.add(new ItemDto(item_nullCar_qty, "空窑车数", "DB600.B6")); + list.add(new ItemDto(item_burning_car_qty, "在烧窑车数", "DB600.D8")); + return list; + } + + public static List getWriteableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_to_command, "下发命令", "DB601.W2", Boolean.valueOf(true))); + list.add(new ItemDto(item_to_material_code, "下发物料编号", "DB601.W4")); + return list; + } + +} + diff --git a/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_kiln_lane/LnshKilnLaneDefination.java b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_kiln_lane/LnshKilnLaneDefination.java new file mode 100644 index 0000000..e803a0c --- /dev/null +++ b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_kiln_lane/LnshKilnLaneDefination.java @@ -0,0 +1,76 @@ +package org.nl.acs.device_driver.lnsh.lnsh_kiln_lane; + +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.ArrayList; +import java.util.LinkedList; +import java.util.List; + +/** + * 晟华窑车道 + */ +@Service +public class LnshKilnLaneDefination implements OpcDeviceDriverDefination { + @Override + public String getDriverCode() { + return "lnsh_kiln_lane"; + } + + @Override + public String getDriverName() { + return "晟华-窑车道"; + } + + @Override + public String getDriverDescription() { + return "晟华-窑车道"; + } + + @Override + public DeviceDriver getDriverInstance(Device device) { + return (new LnshKilnLaneDeviceDriver()).setDevice(device).setDriverDefination(this); + } + + @Override + public Class getDeviceDriverType() { + return LnshKilnLaneDeviceDriver.class; + } + + @Override + public List getFitDeviceTypes() { + List types = new LinkedList(); + types.add(DeviceType.conveyor); + return types; + } + + @Override + public List getReadableItemDtos() { + return getReadableItemDtos2(); + } + + public static List getReadableItemDtos2() { + List list = new ArrayList(); + list.add(new ItemDto(ItemProtocol.item_heartbeat, "心跳", "DB600.B0")); + list.add(new ItemDto(ItemProtocol.item_mode, "工作状态", "DB600.B1", Boolean.valueOf(true))); + list.add(new ItemDto(ItemProtocol.item_status, "设备状态", "DB600.B3")); + list.add(new ItemDto(ItemProtocol.item_open_time, "开机时间", "DB600.B4")); + list.add(new ItemDto(ItemProtocol.item_standby_time, "待机时间", "DB600.D6")); + list.add(new ItemDto(ItemProtocol.item_production_time, "生产时间", "DB600.D7")); + list.add(new ItemDto(ItemProtocol.item_error_time, "故障时间", "DB600.D8")); + list.add(new ItemDto(ItemProtocol.item_car_sum, "窑车总数", "DB600.B4")); + list.add(new ItemDto(ItemProtocol.item_nullCar_qty, "空窑车数", "DB600.B6")); + list.add(new ItemDto(ItemProtocol.item_burning_car_qty, "在烧窑车数", "DB600.D8")); + return list; + } + + @Override + public List getWriteableItemDtos() { + return ItemProtocol.getWriteableItemDtos(); + } + +} diff --git a/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_kiln_lane/LnshKilnLaneDeviceDriver.java b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_kiln_lane/LnshKilnLaneDeviceDriver.java new file mode 100644 index 0000000..8e8c6d3 --- /dev/null +++ b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_kiln_lane/LnshKilnLaneDeviceDriver.java @@ -0,0 +1,334 @@ +package org.nl.acs.device_driver.lnsh.lnsh_kiln_lane; + +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.IdUtil; +import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSONObject; +import lombok.Data; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.device.device_driver.standard_inspect.ReadUtil; +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.instruction.service.InstructionService; +import org.nl.acs.instruction.service.dto.Instruction; +import org.nl.acs.opc.Device; +import org.nl.acs.opc.WcsConfig; +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.util.CodeUtil; +import org.nl.utils.SpringContextHolder; +import org.nl.wql.core.bean.WQLObject; +import org.openscada.opc.lib.da.Server; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.*; + +/** + * 晟华窑车道 + */ +@Slf4j +@Data +@RequiredArgsConstructor +public class LnshKilnLaneDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver { + protected ItemProtocol itemProtocol = new ItemProtocol(this); + @Autowired + InstructionService instructionService = SpringContextHolder.getBean("instructionServiceImpl"); + @Autowired + DeviceService deviceservice = SpringContextHolder.getBean("deviceServiceImpl"); + @Autowired + RouteLineService routelineserver = SpringContextHolder.getBean("routeLineServiceImpl"); + @Autowired + TaskService taskserver = SpringContextHolder.getBean("taskServiceImpl"); + + + String container; + String container_type_desc; + String last_container_type_desc; + String last_container; + //放货准备锁 + String putReadyLock = null; + //有货标记 + protected boolean has_goods_tag = false; + + + String device_code; + int mode = 0; + int error = 0; + int move = 0; + int action; + int io_action; + int task = 0; + int container_type = 0; + int last_mode = 0; + int last_error = 0; + int last_move = 0; + int last_task = 0; + int last_container_type; + Boolean isonline = true; + int hasGoods = 0; + Boolean iserror = false; + + boolean hasVehicle = false; + boolean isReady = false; + protected int instruction_num = 0; + protected int instruction_num_truth = 0; + boolean isFold = false; + private String assemble_check_tag; + private Boolean sampleMode0; + private Boolean sampleMode3; + private Integer sampleError; + private Boolean sampleOnline; + protected String displayMessage = null; + public int display_message_time_out = 30000; + public Date display_message_time; + protected String current_stage_instruction_message; + protected String last_stage_instruction_message; + Integer heartbeat_tag; + private Date instruction_require_time = new Date(); + private Date instruction_finished_time = new Date(); + + private int instruction_require_time_out = 3000; + boolean requireSucess = false; + + private int instruction_finished_time_out; + + int heartbeat; + int last_heartbeat; + private Date checkHeartbeattime = new Date(); + private Date last_checkHeartbeattime = new Date(); + + int branchProtocol = 0; + //当前指令 + Instruction inst = null; + //上次指令 + Instruction last_inst = null; + + //触摸屏手动触发任务 + private Boolean is_has_task = false; + + String message; + + @Override + public Device getDevice() { + return this.device; + } + + + @Override + public void execute() { + String message = null; + try { + device_code = this.getDeviceCode(); + + } catch (Exception var17) { + return; + } + + //急停 + if (this.isStop()) { + + //未在线无心跳 + } else 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); + message = ""; + Instruction instruction = null; + List toInstructions; + switch (mode) { + case 1: + log.debug("设备运转模式:等待工作"); + break; + case 2: + + break; + case 3: + + break; + case 4: + break; + } + } + + last_mode = mode; + last_error = error; + last_move = move; + last_task = task; + last_container_type = container_type; + } + + + protected void thingToNothing() throws Exception { + this.setRequireSucess(false); + } + + public void finish_instruction(Instruction instruction) throws Exception { + instruction_finished(instruction); + } + + /** + * 完成指令 + * + * @param instruction + * @return + */ + public boolean instruction_finished(Instruction instruction) throws Exception { + Date date = new Date(); + if (date.getTime() - this.instruction_finished_time.getTime() < (long) this.instruction_finished_time_out) { + log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_finished_time_out); + return false; + } else { + instructionService.finish(instruction.getInstruction_id()); + this.instruction_finished_time = date; + return true; + } + } + + /** + * 完成并创建下一条指令 + * + * @param instruction + * @param needCreateNext + * @return + */ + public boolean instruction_finished(Instruction instruction, boolean needCreateNext) { + Date date = new Date(); + if (date.getTime() - this.instruction_finished_time.getTime() < (long) this.instruction_finished_time_out) { + log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_finished_time_out); + return false; + } else { + this.instruction_finished_time = date; + return true; + } + } + + + private Instruction findInstruction() { + Instruction instruction = null; + if (this.instruction_num != 0) { + instruction = (Instruction) instructionService.findByCodeFromCache(String.valueOf(instruction_num)); + } + if (instruction != null) { + //可进行校验 + + + } else { + List container_instructions = new ArrayList(); + String barcode = this.getLast_container(); + + if (!StrUtil.isEmpty(barcode)) { + Map map = new HashMap(); + map.put("vehicle_code", barcode); + container_instructions = instructionService.queryAll(map); + } + + if (((List) container_instructions).size() > 1) { + log.debug("容器存在多个指令"); + } else { + if (((List) container_instructions).size() > 0) { + instruction = (Instruction) ((List) container_instructions).get(0); + } + } + } + return instruction; + } + + + public boolean exe_error() { + if (this.error == 0) { + return true; + } else { + log.debug("设备报警"); + return false; + } + } + + public void set_last_container(String barcode, String type_desc) { + this.set_last_container(barcode); + this.set_last_container_type_desc(type_desc); + } + + public void set_last_container(String barcode) { + } + + public void set_last_container_type_desc(String type) { + } + + public boolean exe_business() { + return true; + } + + public void executing(Server server, Map itemMap) { + ReadUtil.write(itemMap, server); + } + + + public boolean instruction_require(String container_code) { + return instruction_require(container_code, WcsConfig.task_container_type_default_desc); + } + + /** + * 请求指令 + * + * @param container_code + * @param container_type + */ + public synchronized boolean instruction_require(String container_code, String container_type) { + 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; + TaskDto dto = new TaskDto(); + String now = DateUtil.now(); + dto.setTask_id(IdUtil.simpleUUID()); + dto.setCreate_by(this.getDevice().getDevice_code()); + dto.setUpdate_by(this.getDevice().getDevice_code()); + dto.setStart_point_code(this.getDevice().getDevice_code()); + dto.setVehicle_code(container_code); + dto.setVehicle_type(container_type); + + String taskcode = CodeUtil.getNewCode("TASK_NO"); + dto.setTask_code("-" + taskcode); + dto.setTask_status("0"); + dto.setPriority("101"); + RouteLineDto jo = routelineserver.findByCode(this.getDevice().getDevice_code()); + String next_device_codecode = jo.getNext_device_code(); + if (StrUtil.isEmpty(next_device_codecode)) { + throw new RuntimeException("该设备未找到对应路由"); + } + dto.setNext_point_code(next_device_codecode); + dto.setUpdate_time(now); + dto.setCreate_time(now); + + WQLObject wo = WQLObject.getWQLObject("acs_task"); + JSONObject json = (JSONObject) JSONObject.toJSON(dto); + + wo.insert(json); + requireSucess = false; + return true; + } + } + +} diff --git a/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_kiln_truss/ItemProtocol.java b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_kiln_truss/ItemProtocol.java new file mode 100644 index 0000000..b16c777 --- /dev/null +++ b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_kiln_truss/ItemProtocol.java @@ -0,0 +1,141 @@ +package org.nl.acs.device_driver.lnsh.lnsh_kiln_truss; + +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_status = "status"; + public static String item_outKiln_move = "outKiln_move"; + public static String item_inKiln_move = "inKiln_move"; + public static String item_inKiln_barcode = "inKiln_barcode"; + public static String item_outKiln_barcode = "outKiln_barcode"; + public static String item_inKiln_device = "inKiln_device"; + public static String item_open_time = "open_time"; + public static String item_standby_time = "standby_time "; + public static String item_production_time = "production_time"; + public static String item_error_time = "error_time"; + public static String item_to_command = "to_command"; + public static String item_to_target = "to_target"; + public static String item_to_task = "to_task"; + Boolean isonline; + + private LnshKilnTrussDeviceDriver driver; + + public ItemProtocol(LnshKilnTrussDeviceDriver driver) { + this.driver = driver; + } + + public int getHeartbeat() { + return this.getOpcIntegerValue(item_heartbeat); + } + + public int getMode() { + return this.getOpcIntegerValue(item_mode); + } + + public int getStatus() { + return this.getOpcIntegerValue(item_status); + } + + public int getOutKiln_move() { + return this.getOpcIntegerValue(item_outKiln_move); + } + + public int getInKiln_move() { + return this.getOpcIntegerValue(item_inKiln_move); + } + + public int getInKiln_barcode() { + return this.getOpcIntegerValue(item_inKiln_barcode); + } + + public int getOutKiln_barcode() { + return this.getOpcIntegerValue(item_outKiln_barcode); + } + + public int getInKiln_device() { + return this.getOpcIntegerValue(item_inKiln_device); + } + + public int getOpen_time() { + return this.getOpcIntegerValue(item_open_time); + } + + public int getStandby_time() { + return this.getOpcIntegerValue(item_standby_time); + } + + public int getProduction_time() { + return this.getOpcIntegerValue(item_production_time); + } + + public int getError_time() { + return this.getOpcIntegerValue(item_error_time); + } + + public int getTo_command() { + return this.getOpcIntegerValue(item_to_command); + } + + public int getTo_target() { + return this.getOpcIntegerValue(item_to_target); + } + + public int getTo_task() { + return this.getOpcIntegerValue(item_to_task); + } + + //是否有货 + public int hasGoods(int move) { + return move; + } + + + 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 static List getReadableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_heartbeat, "心跳", "DB600.B0")); + list.add(new ItemDto(item_mode, "工作状态", "DB600.B1", Boolean.valueOf(true))); + list.add(new ItemDto(item_status, "设备状态", "DB600.B2")); + list.add(new ItemDto(item_outKiln_move, "出窑光电", "DB600.B2")); + list.add(new ItemDto(item_inKiln_move, "入窑光电", "DB600.B2")); + list.add(new ItemDto(item_inKiln_barcode, "入窑条码", "DB600.B2")); + list.add(new ItemDto(item_outKiln_barcode, "出窑条码", "DB600.B2")); + list.add(new ItemDto(item_inKiln_device, "入窑设备号", "DB600.B2")); + list.add(new ItemDto(item_open_time, "开机时间", "DB600.B4")); + list.add(new ItemDto(item_standby_time, "待机时间", "DB600.D6")); + list.add(new ItemDto(item_production_time, "生产时间", "DB600.D7")); + list.add(new ItemDto(item_error_time, "故障时间", "DB600.D8")); + return list; + } + + public static List getWriteableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_to_command, "下发命令反馈", "DB601.W2", Boolean.valueOf(true))); + list.add(new ItemDto(item_to_target, "下发目标站", "DB601.D8")); + list.add(new ItemDto(item_to_task, "下发任务号", "DB601.D8")); + return list; + } + +} + diff --git a/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_kiln_truss/LnshKilnTrussDefination.java b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_kiln_truss/LnshKilnTrussDefination.java new file mode 100644 index 0000000..1ea802c --- /dev/null +++ b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_kiln_truss/LnshKilnTrussDefination.java @@ -0,0 +1,78 @@ +package org.nl.acs.device_driver.lnsh.lnsh_kiln_truss; + +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.ArrayList; +import java.util.LinkedList; +import java.util.List; + +/** + * 晟华入窑桁架 + */ +@Service +public class LnshKilnTrussDefination implements OpcDeviceDriverDefination { + @Override + public String getDriverCode() { + return "lnsh_kiln_truss"; + } + + @Override + public String getDriverName() { + return "晟华-入窑桁架"; + } + + @Override + public String getDriverDescription() { + return "晟华-入窑桁架"; + } + + @Override + public DeviceDriver getDriverInstance(Device device) { + return (new LnshKilnTrussDeviceDriver()).setDevice(device).setDriverDefination(this); + } + + @Override + public Class getDeviceDriverType() { + return LnshKilnTrussDeviceDriver.class; + } + + @Override + public List getFitDeviceTypes() { + List types = new LinkedList(); + types.add(DeviceType.conveyor); + return types; + } + + @Override + public List getReadableItemDtos() { + return getReadableItemDtos2(); + } + + public static List getReadableItemDtos2() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(ItemProtocol.item_heartbeat, "心跳", "DB600.B0")); + list.add(new ItemDto(ItemProtocol.item_mode, "工作状态", "DB600.B1", Boolean.valueOf(true))); + list.add(new ItemDto(ItemProtocol.item_status, "设备状态", "DB600.B2")); + list.add(new ItemDto(ItemProtocol.item_outKiln_move, "出窑光电", "DB600.B2")); + list.add(new ItemDto(ItemProtocol.item_inKiln_move, "入窑光电", "DB600.B2")); + list.add(new ItemDto(ItemProtocol.item_inKiln_barcode, "入窑条码", "DB600.B2")); + list.add(new ItemDto(ItemProtocol.item_outKiln_barcode, "出窑条码", "DB600.B2")); + list.add(new ItemDto(ItemProtocol.item_inKiln_device, "入窑设备号", "DB600.B2")); + list.add(new ItemDto(ItemProtocol.item_open_time, "开机时间", "DB600.B4")); + list.add(new ItemDto(ItemProtocol.item_standby_time, "待机时间", "DB600.D6")); + list.add(new ItemDto(ItemProtocol.item_production_time, "生产时间", "DB600.D7")); + list.add(new ItemDto(ItemProtocol.item_error_time, "故障时间", "DB600.D8")); + return list; + } + + @Override + public List getWriteableItemDtos() { + return ItemProtocol.getWriteableItemDtos(); + } + +} diff --git a/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_kiln_truss/LnshKilnTrussDeviceDriver.java b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_kiln_truss/LnshKilnTrussDeviceDriver.java new file mode 100644 index 0000000..be61aa2 --- /dev/null +++ b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_kiln_truss/LnshKilnTrussDeviceDriver.java @@ -0,0 +1,347 @@ +package org.nl.acs.device_driver.lnsh.lnsh_kiln_truss; + +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.IdUtil; +import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSONObject; +import lombok.Data; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.device.device_driver.standard_inspect.ReadUtil; +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.instruction.service.InstructionService; +import org.nl.acs.instruction.service.dto.Instruction; +import org.nl.acs.opc.Device; +import org.nl.acs.opc.WcsConfig; +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.util.CodeUtil; +import org.nl.utils.SpringContextHolder; +import org.nl.wql.core.bean.WQLObject; +import org.openscada.opc.lib.da.Server; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.*; + +/** + * 晟华入窑桁架 + */ +@Slf4j +@Data +@RequiredArgsConstructor +public class LnshKilnTrussDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver { + protected ItemProtocol itemProtocol = new ItemProtocol(this); + @Autowired + InstructionService instructionService = SpringContextHolder.getBean("instructionServiceImpl"); + @Autowired + DeviceService deviceservice = SpringContextHolder.getBean("deviceServiceImpl"); + @Autowired + RouteLineService routelineserver = SpringContextHolder.getBean("routeLineServiceImpl"); + @Autowired + TaskService taskserver = SpringContextHolder.getBean("taskServiceImpl"); + + + String container; + String container_type_desc; + String last_container_type_desc; + String last_container; + //放货准备锁 + String putReadyLock = null; + //有货标记 + protected boolean has_goods_tag = false; + + + String device_code; + int mode = 0; + int error = 0; + int move = 0; + int action; + int io_action; + int task = 0; + int container_type = 0; + int last_mode = 0; + int last_error = 0; + int last_move = 0; + int last_task = 0; + int last_container_type; + Boolean isonline = true; + int hasGoods = 0; + Boolean iserror = false; + + boolean hasVehicle = false; + boolean isReady = false; + protected int instruction_num = 0; + protected int instruction_num_truth = 0; + boolean isFold = false; + private String assemble_check_tag; + private Boolean sampleMode0; + private Boolean sampleMode3; + private Integer sampleError; + private Boolean sampleOnline; + protected String displayMessage = null; + public int display_message_time_out = 30000; + public Date display_message_time; + protected String current_stage_instruction_message; + protected String last_stage_instruction_message; + Integer heartbeat_tag; + private Date instruction_require_time = new Date(); + private Date instruction_finished_time = new Date(); + + private int instruction_require_time_out = 3000; + boolean requireSucess = false; + + private int instruction_finished_time_out; + + int heartbeat; + int last_heartbeat; + private Date checkHeartbeattime = new Date(); + private Date last_checkHeartbeattime = new Date(); + + int branchProtocol = 0; + //当前指令 + Instruction inst = null; + //上次指令 + Instruction last_inst = null; + + //触摸屏手动触发任务 + private Boolean is_has_task = false; + + String message; + + @Override + public Device getDevice() { + return this.device; + } + + + @Override + public void execute() { + String message = null; + try { + device_code = this.getDeviceCode(); + + mode = this.itemProtocol.getMode(); + + if (mode != last_mode) { + this.setRequireSucess(false); + } + if (move != last_move) { + thingToNothing(); + } + if (error != last_error) { + } + if (container_type != last_container_type) { + } + + } catch (Exception var17) { + return; + } + + //急停 + if (this.isStop()) { + + //未在线无心跳 + } else 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); + message = ""; + Instruction instruction = null; + List toInstructions; + switch (mode) { + case 1: + log.debug("设备运转模式:等待工作"); + break; + case 2: + + break; + case 3: + + break; + case 4: + break; + } + } + + last_mode = mode; + last_error = error; + last_move = move; + last_task = task; + last_container_type = container_type; + } + + + protected void thingToNothing() throws Exception { + this.setRequireSucess(false); + } + + public void finish_instruction(Instruction instruction) throws Exception { + instruction_finished(instruction); + } + + /** + * 完成指令 + * + * @param instruction + * @return + */ + public boolean instruction_finished(Instruction instruction) throws Exception { + Date date = new Date(); + if (date.getTime() - this.instruction_finished_time.getTime() < (long) this.instruction_finished_time_out) { + log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_finished_time_out); + return false; + } else { + instructionService.finish(instruction.getInstruction_id()); + this.instruction_finished_time = date; + return true; + } + } + + /** + * 完成并创建下一条指令 + * + * @param instruction + * @param needCreateNext + * @return + */ + public boolean instruction_finished(Instruction instruction, boolean needCreateNext) { + Date date = new Date(); + if (date.getTime() - this.instruction_finished_time.getTime() < (long) this.instruction_finished_time_out) { + log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_finished_time_out); + return false; + } else { + this.instruction_finished_time = date; + return true; + } + } + + + private Instruction findInstruction() { + Instruction instruction = null; + if (this.instruction_num != 0) { + instruction = (Instruction) instructionService.findByCodeFromCache(String.valueOf(instruction_num)); + } + if (instruction != null) { + //可进行校验 + + + } else { + List container_instructions = new ArrayList(); + String barcode = this.getLast_container(); + + if (!StrUtil.isEmpty(barcode)) { + Map map = new HashMap(); + map.put("vehicle_code", barcode); + container_instructions = instructionService.queryAll(map); + } + + if (((List) container_instructions).size() > 1) { + log.debug("容器存在多个指令"); + } else { + if (((List) container_instructions).size() > 0) { + instruction = (Instruction) ((List) container_instructions).get(0); + } + } + } + return instruction; + } + + + public boolean exe_error() { + if (this.error == 0) { + return true; + } else { + log.debug("设备报警"); + return false; + } + } + + public void set_last_container(String barcode, String type_desc) { + this.set_last_container(barcode); + this.set_last_container_type_desc(type_desc); + } + + public void set_last_container(String barcode) { + } + + public void set_last_container_type_desc(String type) { + } + + public boolean exe_business() { + return true; + } + + public void executing(Server server, Map itemMap) { + ReadUtil.write(itemMap, server); + } + + + public boolean instruction_require(String container_code) { + return instruction_require(container_code, WcsConfig.task_container_type_default_desc); + } + + /** + * 请求指令 + * + * @param container_code + * @param container_type + */ + public synchronized boolean instruction_require(String container_code, String container_type) { + 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; + TaskDto dto = new TaskDto(); + String now = DateUtil.now(); + dto.setTask_id(IdUtil.simpleUUID()); + dto.setCreate_by(this.getDevice().getDevice_code()); + dto.setUpdate_by(this.getDevice().getDevice_code()); + dto.setStart_point_code(this.getDevice().getDevice_code()); + dto.setVehicle_code(container_code); + dto.setVehicle_type(container_type); + + String taskcode = CodeUtil.getNewCode("TASK_NO"); + dto.setTask_code("-" + taskcode); + dto.setTask_status("0"); + dto.setPriority("101"); + RouteLineDto jo = routelineserver.findByCode(this.getDevice().getDevice_code()); + String next_device_codecode = jo.getNext_device_code(); + if (StrUtil.isEmpty(next_device_codecode)) { + throw new RuntimeException("该设备未找到对应路由"); + } + dto.setNext_point_code(next_device_codecode); + dto.setUpdate_time(now); + dto.setCreate_time(now); + + WQLObject wo = WQLObject.getWQLObject("acs_task"); + JSONObject json = (JSONObject) JSONObject.toJSON(dto); + + wo.insert(json); + requireSucess = false; + return true; + } + } + +} diff --git a/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_labeling_machine/ItemProtocol.java b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_labeling_machine/ItemProtocol.java new file mode 100644 index 0000000..5f766e6 --- /dev/null +++ b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_labeling_machine/ItemProtocol.java @@ -0,0 +1,117 @@ +package org.nl.acs.device_driver.lnsh.lnsh_labeling_machine; + +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_status = "status"; + public static String item_open_time = "open_time"; + public static String item_close_time = "close_time"; + public static String item_standby_time = "standby_time "; + public static String item_production_time = "production_time"; + public static String item_error_time = "error_time"; + public static String item_labeling_qty = "labeling_qty"; + public static String item_to_command = "to_command"; + public static String item_to_material_code = "to_material_code"; + Boolean isonline; + + private LnshLabelingMachineDeviceDriver driver; + + public ItemProtocol(LnshLabelingMachineDeviceDriver driver) { + this.driver = driver; + } + + public int getHeartbeat() { + return this.getOpcIntegerValue(item_heartbeat); + } + + public int getMode() { + return this.getOpcIntegerValue(item_mode); + } + + public int getStatus() { + return this.getOpcIntegerValue(item_status); + } + + public int getOpen_time() { + return this.getOpcIntegerValue(item_open_time); + } + + public int getClose_time() { + return this.getOpcIntegerValue(item_close_time); + } + + public int getStandby_time() { + return this.getOpcIntegerValue(item_standby_time); + } + + public int getProduction_time() { + return this.getOpcIntegerValue(item_production_time); + } + + public int getError_time() { + return this.getOpcIntegerValue(item_error_time); + } + + public int getLabeling_qty() { + return this.getOpcIntegerValue(item_labeling_qty); + } + + public int getToCommand() { + return this.getOpcIntegerValue(item_to_command); + } + + public int getTo_material_code() { + return this.getOpcIntegerValue(item_to_material_code); + } + + //是否有货 + public int hasGoods(int move) { + return move; + } + + + 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 static List getReadableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_heartbeat, "心跳", "DB600.B0")); + list.add(new ItemDto(item_mode, "工作状态", "DB600.B1", Boolean.valueOf(true))); + list.add(new ItemDto(item_status, "设备状态", "DB600.B2")); + list.add(new ItemDto(item_open_time, "开机时间", "DB600.B4")); + list.add(new ItemDto(item_close_time, "关机时间", "DB600.D5")); + list.add(new ItemDto(item_standby_time, "待机时间", "DB600.D6")); + list.add(new ItemDto(item_production_time, "生产时间", "DB600.D7")); + list.add(new ItemDto(item_error_time, "故障时间", "DB600.D8")); + list.add(new ItemDto(item_labeling_qty, "贴标数量", "DB600.D8")); + return list; + } + + public static List getWriteableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_to_command, "下发命令", "DB601.W2", Boolean.valueOf(true))); + list.add(new ItemDto(item_to_material_code, "下发物料编号", "DB601.D8")); + return list; + } + +} + diff --git a/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_labeling_machine/LnshLabelingMachineDefination.java b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_labeling_machine/LnshLabelingMachineDefination.java new file mode 100644 index 0000000..dd72655 --- /dev/null +++ b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_labeling_machine/LnshLabelingMachineDefination.java @@ -0,0 +1,75 @@ +package org.nl.acs.device_driver.lnsh.lnsh_labeling_machine; + +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.ArrayList; +import java.util.LinkedList; +import java.util.List; + +/** + * 晟华贴标机 + */ +@Service +public class LnshLabelingMachineDefination implements OpcDeviceDriverDefination { + @Override + public String getDriverCode() { + return "lnsh_labeling_machine"; + } + + @Override + public String getDriverName() { + return "晟华-贴标机"; + } + + @Override + public String getDriverDescription() { + return "晟华-贴标机"; + } + + @Override + public DeviceDriver getDriverInstance(Device device) { + return (new LnshLabelingMachineDeviceDriver()).setDevice(device).setDriverDefination(this); + } + + @Override + public Class getDeviceDriverType() { + return LnshLabelingMachineDeviceDriver.class; + } + + @Override + public List getFitDeviceTypes() { + List types = new LinkedList(); + types.add(DeviceType.conveyor); + return types; + } + + @Override + public List getReadableItemDtos() { + return getReadableItemDtos2(); + } + + public static List getReadableItemDtos2() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(ItemProtocol.item_heartbeat, "心跳", "DB600.B0")); + list.add(new ItemDto(ItemProtocol.item_mode, "工作状态", "DB600.B1", Boolean.valueOf(true))); + list.add(new ItemDto(ItemProtocol.item_status, "设备状态", "DB600.B2")); + list.add(new ItemDto(ItemProtocol.item_open_time, "开机时间", "DB600.B4")); + list.add(new ItemDto(ItemProtocol.item_close_time, "关机时间", "DB600.D5")); + list.add(new ItemDto(ItemProtocol.item_standby_time, "待机时间", "DB600.D6")); + list.add(new ItemDto(ItemProtocol.item_production_time, "生产时间", "DB600.D7")); + list.add(new ItemDto(ItemProtocol.item_error_time, "故障时间", "DB600.D8")); + list.add(new ItemDto(ItemProtocol.item_labeling_qty, "贴标数量", "DB600.D8")); + return list; + } + + @Override + public List getWriteableItemDtos() { + return ItemProtocol.getWriteableItemDtos(); + } + +} diff --git a/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_labeling_machine/LnshLabelingMachineDeviceDriver.java b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_labeling_machine/LnshLabelingMachineDeviceDriver.java new file mode 100644 index 0000000..5e32ea4 --- /dev/null +++ b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_labeling_machine/LnshLabelingMachineDeviceDriver.java @@ -0,0 +1,348 @@ +package org.nl.acs.device_driver.lnsh.lnsh_labeling_machine; + +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.IdUtil; +import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSONObject; +import lombok.Data; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.device.device_driver.standard_inspect.ReadUtil; +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.instruction.service.InstructionService; +import org.nl.acs.instruction.service.dto.Instruction; +import org.nl.acs.opc.Device; +import org.nl.acs.opc.WcsConfig; +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.util.CodeUtil; +import org.nl.utils.SpringContextHolder; +import org.nl.wql.core.bean.WQLObject; +import org.openscada.opc.lib.da.Server; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.*; + +/** + * 晟华贴标机 + */ +@Slf4j +@Data +@RequiredArgsConstructor +public class LnshLabelingMachineDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver { + protected ItemProtocol itemProtocol = new ItemProtocol(this); + @Autowired + InstructionService instructionService = SpringContextHolder.getBean("instructionServiceImpl"); + @Autowired + DeviceService deviceservice = SpringContextHolder.getBean("deviceServiceImpl"); + @Autowired + RouteLineService routelineserver = SpringContextHolder.getBean("routeLineServiceImpl"); + @Autowired + TaskService taskserver = SpringContextHolder.getBean("taskServiceImpl"); + + + String container; + String container_type_desc; + String last_container_type_desc; + String last_container; + //放货准备锁 + String putReadyLock = null; + //有货标记 + protected boolean has_goods_tag = false; + + + String device_code; + int mode = 0; + int error = 0; + int move = 0; + int action; + int io_action; + int task = 0; + int container_type = 0; + int last_mode = 0; + int last_error = 0; + int last_move = 0; + int last_task = 0; + int last_container_type; + Boolean isonline = true; + int hasGoods = 0; + Boolean iserror = false; + + boolean hasVehicle = false; + boolean isReady = false; + protected int instruction_num = 0; + protected int instruction_num_truth = 0; + boolean isFold = false; + private String assemble_check_tag; + private Boolean sampleMode0; + private Boolean sampleMode3; + private Integer sampleError; + private Boolean sampleOnline; + protected String displayMessage = null; + public int display_message_time_out = 30000; + public Date display_message_time; + protected String current_stage_instruction_message; + protected String last_stage_instruction_message; + Integer heartbeat_tag; + private Date instruction_require_time = new Date(); + private Date instruction_finished_time = new Date(); + + private int instruction_require_time_out = 3000; + boolean requireSucess = false; + + private int instruction_finished_time_out; + + int heartbeat; + int last_heartbeat; + private Date checkHeartbeattime = new Date(); + private Date last_checkHeartbeattime = new Date(); + + int branchProtocol = 0; + //当前指令 + Instruction inst = null; + //上次指令 + Instruction last_inst = null; + + //触摸屏手动触发任务 + private Boolean is_has_task = false; + + String message; + + @Override + public Device getDevice() { + return this.device; + } + + + @Override + public void execute() { + String message = null; + try { + device_code = this.getDeviceCode(); + + mode = this.itemProtocol.getMode(); + + if (mode != last_mode) { + this.setRequireSucess(false); + } + if (move != last_move) { + thingToNothing(); + } + if (error != last_error) { + } + if (container_type != last_container_type) { + } + + } catch (Exception var17) { + return; + } + + //急停 + if (this.isStop()) { + + //未在线无心跳 + } else 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); + message = ""; + Instruction instruction = null; + List toInstructions; + switch (mode) { + case 1: + log.debug("设备运转模式:等待工作"); + break; + case 2: + + break; + case 3: + + break; + case 4: + break; + } + } + + last_mode = mode; + last_error = error; + last_move = move; + last_task = task; + last_container_type = container_type; + } + + + protected void thingToNothing() throws Exception { + this.setRequireSucess(false); + } + + public void finish_instruction(Instruction instruction) throws Exception { + instruction_finished(instruction); + } + + /** + * 完成指令 + * + * @param instruction + * @return + */ + public boolean instruction_finished(Instruction instruction) throws Exception { + Date date = new Date(); + if (date.getTime() - this.instruction_finished_time.getTime() < (long) this.instruction_finished_time_out) { + log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_finished_time_out); + return false; + } else { + instructionService.finish(instruction.getInstruction_id()); + this.instruction_finished_time = date; + return true; + } + } + + /** + * 完成并创建下一条指令 + * + * @param instruction + * @param needCreateNext + * @return + */ + public boolean instruction_finished(Instruction instruction, boolean needCreateNext) { + Date date = new Date(); + if (date.getTime() - this.instruction_finished_time.getTime() < (long) this.instruction_finished_time_out) { + log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_finished_time_out); + return false; + } else { + this.instruction_finished_time = date; + return true; + } + } + + + private Instruction findInstruction() { + Instruction instruction = null; + if (this.instruction_num != 0) { + instruction = (Instruction) instructionService.findByCodeFromCache(String.valueOf(instruction_num)); + } + if (instruction != null) { + //可进行校验 + + + } else { + List container_instructions = new ArrayList(); + String barcode = this.getLast_container(); + + if (!StrUtil.isEmpty(barcode)) { + Map map = new HashMap(); + map.put("vehicle_code", barcode); + container_instructions = instructionService.queryAll(map); + } + + if (((List) container_instructions).size() > 1) { + log.debug("容器存在多个指令"); + } else { + if (((List) container_instructions).size() > 0) { + instruction = (Instruction) ((List) container_instructions).get(0); + } + } + } + return instruction; + } + + + public boolean exe_error() { + if (this.error == 0) { + return true; + } else { + log.debug("设备报警"); + return false; + } + } + + public void set_last_container(String barcode, String type_desc) { + this.set_last_container(barcode); + this.set_last_container_type_desc(type_desc); + } + + public void set_last_container(String barcode) { + } + + public void set_last_container_type_desc(String type) { + } + + public boolean exe_business() { + return true; + } + + public void executing(Server server, Map itemMap) { + ReadUtil.write(itemMap, server); + } + + public boolean instruction_require(String container_code) { + return instruction_require(container_code, WcsConfig.task_container_type_default_desc); + } + + + + /** + * 请求指令 + * + * @param container_code + * @param container_type + */ + public synchronized boolean instruction_require(String container_code, String container_type) { + 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; + TaskDto dto = new TaskDto(); + String now = DateUtil.now(); + dto.setTask_id(IdUtil.simpleUUID()); + dto.setCreate_by(this.getDevice().getDevice_code()); + dto.setUpdate_by(this.getDevice().getDevice_code()); + dto.setStart_point_code(this.getDevice().getDevice_code()); + dto.setVehicle_code(container_code); + dto.setVehicle_type(container_type); + + String taskcode = CodeUtil.getNewCode("TASK_NO"); + dto.setTask_code("-" + taskcode); + dto.setTask_status("0"); + dto.setPriority("101"); + RouteLineDto jo = routelineserver.findByCode(this.getDevice().getDevice_code()); + String next_device_codecode = jo.getNext_device_code(); + if (StrUtil.isEmpty(next_device_codecode)) { + throw new RuntimeException("该设备未找到对应路由"); + } + dto.setNext_point_code(next_device_codecode); + dto.setUpdate_time(now); + dto.setCreate_time(now); + + WQLObject wo = WQLObject.getWQLObject("acs_task"); + JSONObject json = (JSONObject) JSONObject.toJSON(dto); + + wo.insert(json); + requireSucess = false; + return true; + } + } + +} diff --git a/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_mixing_mill/ItemProtocol.java b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_mixing_mill/ItemProtocol.java new file mode 100644 index 0000000..887a705 --- /dev/null +++ b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_mixing_mill/ItemProtocol.java @@ -0,0 +1,151 @@ +package org.nl.acs.device_driver.lnsh.lnsh_mixing_mill; + +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_status = "status"; + public static String item_error = "error"; + public static String item_open_time = "open_time"; + public static String item_standby_time = "standby_time "; + public static String item_production_time = "production_time"; + public static String item_error_time = "error_time"; + public static String item_weight = "weight"; + public static String item_order_No = "order_No"; + public static String item_mix_num = "mix_num"; + public static String item_material = "material"; + public static String item_to_command = "to_command"; + public static String item_to_error = "to_error"; + public static String item_to_task = "to_task"; + public static String item_to_weight = "to_weight"; + public static String item_to_material_code = "to_material_code"; + + + private LnshMixingMillDeviceDriver driver; + + public ItemProtocol(LnshMixingMillDeviceDriver driver) { + this.driver = driver; + } + + public int getMode() { + return this.getOpcIntegerValue(item_heartbeat); + } + + public int getStatus() { + return this.getOpcIntegerValue(item_status); + } + + public int getError() { + return this.getOpcIntegerValue(item_error); + } + + public int getOpen_time() { + return this.getOpcIntegerValue(item_open_time); + } + + public int getWeight() { + return this.getOpcIntegerValue(item_weight); + } + + public int getStandby_time() { + return this.getOpcIntegerValue(item_standby_time); + } + + public int getProduction_time() { + return this.getOpcIntegerValue(item_production_time); + } + + public int getError_time() { + return this.getOpcIntegerValue(item_error_time); + } + + public int getMaterial() { + return this.getOpcIntegerValue(item_material); + } + + public int getOrder_No() { + return this.getOpcIntegerValue(item_order_No); + } + + public int getMix_num() { + return this.getOpcIntegerValue(item_mix_num); + } + + public int getTo_error() { + return this.getOpcIntegerValue(item_to_error); + } + + public int getTo_task() { + return this.getOpcIntegerValue(item_to_task); + } + + public int getTo_command() { + return this.getOpcIntegerValue(item_to_command); + } + + public int getTo_weight() { + return this.getOpcIntegerValue(item_to_weight); + } + + public int getTo_material_code() { + return this.getOpcIntegerValue(item_to_material_code); + } + + //是否有货 + public int hasGoods(int move) { + return move; + } + + 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 static List getReadableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_heartbeat, "心跳", "DB600.B0")); + list.add(new ItemDto(item_mode, "工作状态", "DB600.B2", Boolean.valueOf(true))); + list.add(new ItemDto(item_status, "设备状态", "DB600.B3")); + list.add(new ItemDto(item_error, "故障代码", "DB600.B3")); + list.add(new ItemDto(item_open_time, "开机时间", "DB600.B4")); + list.add(new ItemDto(item_standby_time, "待机时间", "DB600.D6")); + list.add(new ItemDto(item_production_time, "生产时间", "DB600.D7")); + list.add(new ItemDto(item_error_time, "故障时间", "DB600.D8")); + list.add(new ItemDto(item_weight, "当前生产重量", "DB600.D8")); + list.add(new ItemDto(item_order_No, "工单号", "DB600.D8"));; + list.add(new ItemDto(item_mix_num, "碾次", "DB600.D8"));; + list.add(new ItemDto(item_material, "当前生产物料", "DB600.D9")); + return list; + } + + public static List getWriteableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_to_command, "反馈", "DB601.W2", Boolean.valueOf(true))); + list.add(new ItemDto(item_to_error, "error", "DB601.W2")); + list.add(new ItemDto(item_to_task, "工单号", "DB601.W2")); + list.add(new ItemDto(item_to_weight, "生产重量", "DB601.W2")); + list.add(new ItemDto(item_to_material_code, "下发物料编号", "DB601.W10")); + return list; + } + +} + diff --git a/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_mixing_mill/LnshMixingMillDefination.java b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_mixing_mill/LnshMixingMillDefination.java new file mode 100644 index 0000000..e99b3b9 --- /dev/null +++ b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_mixing_mill/LnshMixingMillDefination.java @@ -0,0 +1,80 @@ +package org.nl.acs.device_driver.lnsh.lnsh_mixing_mill; + +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.ArrayList; +import java.util.LinkedList; +import java.util.List; + +/** + * 晟华混碾机 + * + */ +@Service +public class LnshMixingMillDefination implements OpcDeviceDriverDefination { + @Override + public String getDriverCode() { + return "lnsh_mixing_mill"; + } + + @Override + public String getDriverName() { + return "晟华-混碾机"; + } + + @Override + public String getDriverDescription() { + return "晟华-混碾机"; + } + + @Override + public DeviceDriver getDriverInstance(Device device) { + return (new LnshMixingMillDeviceDriver()).setDevice(device).setDriverDefination(this); + + } + + @Override + public Class getDeviceDriverType() { + return LnshMixingMillDeviceDriver.class; + } + + @Override + public List getFitDeviceTypes() { + List types = new LinkedList(); + types.add(DeviceType.conveyor); + return types; + } + + @Override + public List getReadableItemDtos() { + return getReadableItemDtos2(); + } + + public static List getReadableItemDtos2() { + List list = new ArrayList(); + list.add(new ItemDto(ItemProtocol.item_heartbeat, "心跳", "DB600.B0")); + list.add(new ItemDto(ItemProtocol.item_mode, "工作状态", "DB600.B2", Boolean.valueOf(true))); + list.add(new ItemDto(ItemProtocol.item_status, "设备状态", "DB600.B3")); + list.add(new ItemDto(ItemProtocol.item_error, "故障代码", "DB600.B3")); + list.add(new ItemDto(ItemProtocol.item_open_time, "开机时间", "DB600.B4")); + list.add(new ItemDto(ItemProtocol.item_standby_time, "待机时间", "DB600.D6")); + list.add(new ItemDto(ItemProtocol.item_production_time, "生产时间", "DB600.D7")); + list.add(new ItemDto(ItemProtocol.item_error_time, "故障时间", "DB600.D8")); + list.add(new ItemDto(ItemProtocol.item_weight, "当前生产重量", "DB600.D8")); + list.add(new ItemDto(ItemProtocol.item_order_No, "工单号", "DB600.D8"));; + list.add(new ItemDto(ItemProtocol.item_mix_num, "碾次", "DB600.D8"));; + list.add(new ItemDto(ItemProtocol.item_material, "当前生产物料", "DB600.D9")); + return list; + } + + @Override + public List getWriteableItemDtos() { + return ItemProtocol.getWriteableItemDtos(); + } + +} diff --git a/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_mixing_mill/LnshMixingMillDeviceDriver.java b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_mixing_mill/LnshMixingMillDeviceDriver.java new file mode 100644 index 0000000..8bc820b --- /dev/null +++ b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_mixing_mill/LnshMixingMillDeviceDriver.java @@ -0,0 +1,325 @@ +package org.nl.acs.device_driver.lnsh.lnsh_mixing_mill; + +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.IdUtil; +import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSONObject; +import lombok.Data; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.device.device_driver.standard_inspect.ReadUtil; +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.instruction.service.InstructionService; +import org.nl.acs.instruction.service.dto.Instruction; +import org.nl.acs.opc.Device; +import org.nl.acs.opc.DeviceAppService; +import org.nl.acs.opc.DeviceAppServiceImpl; +import org.nl.acs.opc.WcsConfig; +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.util.CodeUtil; +import org.nl.utils.SpringContextHolder; +import org.nl.wql.core.bean.WQLObject; +import org.openscada.opc.lib.da.Server; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * 晟华混碾机 + */ +@Slf4j +@Data +@RequiredArgsConstructor +public class LnshMixingMillDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver { + protected ItemProtocol itemProtocol = new ItemProtocol(this); + @Autowired + InstructionService instructionService = SpringContextHolder.getBean("instructionServiceImpl"); + @Autowired + DeviceService deviceservice = SpringContextHolder.getBean("deviceServiceImpl"); + @Autowired + RouteLineService routelineserver = SpringContextHolder.getBean("routeLineServiceImpl"); + @Autowired + TaskService taskserver = SpringContextHolder.getBean("taskServiceImpl"); + String container; + String container_type_desc; + String last_container_type_desc; + String last_container; + //放货准备锁 + String putReadyLock = null; + //有货标记 + protected boolean has_goods_tag = false; + + int mode = 0; + int error = 0; + int last_mode = 0; + int last_error = 0; + Boolean isonline = true; + int hasGoods = 0; + String message = null; + Boolean iserror = false; + + + boolean hasVehicle = false; + boolean isReady = false; + protected int instruction_num = 0; + protected int instruction_num_truth = 0; + boolean isFold = false; + private String assemble_check_tag; + + protected String current_stage_instruction_message; + protected String last_stage_instruction_message; + Integer heartbeat_tag; + private Date instruction_require_time = new Date(); + private Date instruction_finished_time = new Date(); + + private int instruction_require_time_out; + boolean requireSucess = false; + + private int instruction_finished_time_out; + + int branchProtocol = 0; + //备注 + String remark; + //数量 + String qty; + //物料 + String material; + //批次 + String batch; + //当前指令 + Instruction inst = null; + //上次指令 + Instruction last_inst = null; + + //触摸屏手动触发任务 + private Boolean is_has_task = false; + + //申请搬运任务 + private Boolean apply_handling = false; + //申请物料 + private Boolean apply_material = false; + + //暂定 0就绪 1请求取货 2取货完成 3请求放货 4放货完成 5取货完成离开 6放货完成离开 7请求进入区域 8请求离开区域 + int flag; + + String devicecode; + + @Override + public Device getDevice() { + return this.device; + } + + + @Override + public void execute() { + String message = null; + try { + String device_code = this.getDeviceCode(); + mode = this.itemProtocol.getMode(); + + if (mode != last_mode) { + this.setRequireSucess(false); + } + if (error != last_error) { + } + + } catch (Exception var17) { + return; + } + + 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); + message = ""; + Instruction instruction = null; + List toInstructions; + switch (mode) { + case 1: + log.debug("设备运转模式:等待工作"); + return; + case 2: + if (material.length() > 0 && qty.length() > 0 && !requireSucess) { + this.instruction_require(container); + } + } + + switch (flag) { + //取货完成 + case 1: + writing(2); + return; + //放货完成 + case 2: + writing(3); + return; + + } + + } + last_mode = mode; + last_error = error; + + } + + + public boolean exe_error() { + if (this.error == 0) { + return true; + } else { + log.debug("设备报警"); + return false; + } + } + + protected void thingToNothing() { + log.debug("从有货到无货 清理数据"); + this.set_last_container(container, container_type_desc); + } + + public void set_last_container(String barcode, String type_desc) { + this.set_last_container(barcode); + this.set_last_container_type_desc(type_desc); + } + + public void set_last_container(String barcode) { + } + + public void set_last_container_type_desc(String type) { + } + + public boolean exe_business() { + return true; + } + + protected void executing(Instruction instruction) { + this.executing(1, instruction, ""); + } + + public void executing(int command, Instruction instruction, String appendMessage) { + String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + ItemProtocol.item_to_command; + String to_material_code = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + ItemProtocol.item_to_material_code; + if (appendMessage == null) { + appendMessage = ""; + } + if (instruction != null) { + instruction_num = Integer.parseInt(instruction.getInstruction_code()); + } + String opcservcerid = this.getDevice().getOpc_server_id(); + Server server = ReadUtil.getServer(opcservcerid); + Map itemMap = new HashMap(); + itemMap.put(to_command, 1); + ReadUtil.write(itemMap, server); + + } + + public void executing(Server server, Map itemMap) { + ReadUtil.write(itemMap, server); + } + + public void writing(int command) { + String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + ItemProtocol.item_to_command; + + String opcservcerid = this.getDevice().getOpc_server_id(); + Server server = ReadUtil.getServer(opcservcerid); + Map itemMap = new HashMap(); + itemMap.put(to_command, command); + ReadUtil.write(itemMap, server); + + } + + public void writing(int type, int command) { + String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + ItemProtocol.item_to_command; + String to_material_code = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + ItemProtocol.item_to_material_code; + String opcservcerid = this.getDevice().getOpc_server_id(); + Server server = ReadUtil.getServer(opcservcerid); + Map itemMap = new HashMap(); + if (type == 1) { + itemMap.put(to_command, command); + } else if (type == 2) { + itemMap.put(to_material_code, command); + + } + ReadUtil.write(itemMap, server); + + } + + public boolean instruction_require(String container_code) { + return instruction_require(container_code, WcsConfig.task_container_type_default_desc); + } + + /** + * 请求指令 + * + * @param container_code + * @param container_type + */ + public synchronized boolean instruction_require(String container_code, String container_type) { + 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; + TaskDto dto = new TaskDto(); + String now = DateUtil.now(); + dto.setTask_id(IdUtil.simpleUUID()); + dto.setCreate_by(this.getDevice().getDevice_code()); + dto.setUpdate_by(this.getDevice().getDevice_code()); + dto.setStart_point_code(this.getDevice().getDevice_code()); + dto.setVehicle_code(container_code); + dto.setVehicle_type(container_type); + + String taskcode = CodeUtil.getNewCode("TASK_NO"); + dto.setTask_code("-" + taskcode); + dto.setTask_status("0"); + dto.setPriority("101"); + RouteLineDto jo = routelineserver.findByCode(this.getDevice().getDevice_code()); + String next_device_codecode = jo.getNext_device_code(); + if (StrUtil.isEmpty(next_device_codecode)) { + throw new RuntimeException("该设备未找到对应路由"); + } + dto.setNext_point_code(next_device_codecode); + dto.setUpdate_time(now); + dto.setCreate_time(now); + + WQLObject wo = WQLObject.getWQLObject("acs_task"); + JSONObject json = (JSONObject) JSONObject.toJSON(dto); + + wo.insert(json); + requireSucess = false; + return true; + } + } + + +} diff --git a/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_out_kiln_truss/ItemProtocol.java b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_out_kiln_truss/ItemProtocol.java new file mode 100644 index 0000000..0f8dd14 --- /dev/null +++ b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_out_kiln_truss/ItemProtocol.java @@ -0,0 +1,129 @@ +package org.nl.acs.device_driver.lnsh.lnsh_out_kiln_truss; + +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_status = "status"; + public static String item_outKiln_move = "outKiln_move"; + public static String item_outKiln_barcode = "outKiln_barcode"; + public static String item_outKiln_device = "outKiln_device"; + public static String item_open_time = "open_time"; + public static String item_standby_time = "standby_time "; + public static String item_production_time = "production_time"; + public static String item_error_time = "error_time"; + public static String item_to_command = "to_command"; + public static String item_to_target = "to_target"; + public static String item_to_task = "to_task"; + Boolean isonline; + + private LnshOutKilnTrussDeviceDriver driver; + + public ItemProtocol(LnshOutKilnTrussDeviceDriver driver) { + this.driver = driver; + } + + public int getHeartbeat() { + return this.getOpcIntegerValue(item_heartbeat); + } + + public int getMode() { + return this.getOpcIntegerValue(item_mode); + } + + public int getStatus() { + return this.getOpcIntegerValue(item_status); + } + + public int getOutKiln_move() { + return this.getOpcIntegerValue(item_outKiln_move); + } + + public int getOutKiln_barcode() { + return this.getOpcIntegerValue(item_outKiln_barcode); + } + + public int getOutKiln_device() { + return this.getOpcIntegerValue(item_outKiln_device); + } + + public int getOpen_time() { + return this.getOpcIntegerValue(item_open_time); + } + + public int getStandby_time() { + return this.getOpcIntegerValue(item_standby_time); + } + + public int getProduction_time() { + return this.getOpcIntegerValue(item_production_time); + } + + public int getError_time() { + return this.getOpcIntegerValue(item_error_time); + } + + public int getToCommand() { + return this.getOpcIntegerValue(item_to_command); + } + + public int getToTarget() { + return this.getOpcIntegerValue(item_to_target); + } + + public int getToTask() { + return this.getOpcIntegerValue(item_to_task); + } + + //是否有货 + public int hasGoods(int move) { + return move; + } + + + 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 static List getReadableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_heartbeat, "心跳", "DB600.B0")); + list.add(new ItemDto(item_mode, "工作状态", "DB600.B1", Boolean.valueOf(true))); + list.add(new ItemDto(item_status, "设备状态", "DB600.B2")); + list.add(new ItemDto(item_outKiln_move, "出窑光电", "DB600.B2")); + list.add(new ItemDto(item_outKiln_barcode, "出窑条码", "DB600.B2")); + list.add(new ItemDto(item_outKiln_device, "出窑设备", "DB600.B2")); + list.add(new ItemDto(item_open_time, "开机时间", "DB600.B4")); + list.add(new ItemDto(item_standby_time, "待机时间", "DB600.D6")); + list.add(new ItemDto(item_production_time, "生产时间", "DB600.D7")); + list.add(new ItemDto(item_error_time, "故障时间", "DB600.D8")); + return list; + } + + public static List getWriteableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_to_command, "下发命令反馈", "DB601.W2", Boolean.valueOf(true))); + list.add(new ItemDto(item_to_target, "下发目标站", "DB601.W4")); + list.add(new ItemDto(item_to_task, "下发任务号", "DB601.D8")); + return list; + } + +} + diff --git a/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_out_kiln_truss/LnshOutKilnTrussDefination.java b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_out_kiln_truss/LnshOutKilnTrussDefination.java new file mode 100644 index 0000000..0ac8356 --- /dev/null +++ b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_out_kiln_truss/LnshOutKilnTrussDefination.java @@ -0,0 +1,76 @@ +package org.nl.acs.device_driver.lnsh.lnsh_out_kiln_truss; + +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.ArrayList; +import java.util.LinkedList; +import java.util.List; + +/** + * 晟华出窑桁架 + */ +@Service +public class LnshOutKilnTrussDefination implements OpcDeviceDriverDefination { + @Override + public String getDriverCode() { + return "lnsh_out_kiln_truss"; + } + + @Override + public String getDriverName() { + return "晟华-出窑桁架"; + } + + @Override + public String getDriverDescription() { + return "晟华-出窑桁架"; + } + + @Override + public DeviceDriver getDriverInstance(Device device) { + return (new LnshOutKilnTrussDeviceDriver()).setDevice(device).setDriverDefination(this); + } + + @Override + public Class getDeviceDriverType() { + return LnshOutKilnTrussDeviceDriver.class; + } + + @Override + public List getFitDeviceTypes() { + List types = new LinkedList(); + types.add(DeviceType.conveyor); + return types; + } + + @Override + public List getReadableItemDtos() { + return getReadableItemDtos2(); + } + + public static List getReadableItemDtos2() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(ItemProtocol.item_heartbeat, "心跳", "DB600.B0")); + list.add(new ItemDto(ItemProtocol.item_mode, "工作状态", "DB600.B1", Boolean.valueOf(true))); + list.add(new ItemDto(ItemProtocol.item_status, "设备状态", "DB600.B2")); + list.add(new ItemDto(ItemProtocol.item_outKiln_move, "出窑光电", "DB600.B2")); + list.add(new ItemDto(ItemProtocol.item_outKiln_barcode, "出窑条码", "DB600.B2")); + list.add(new ItemDto(ItemProtocol.item_outKiln_device, "出窑设备", "DB600.B2")); + list.add(new ItemDto(ItemProtocol.item_open_time, "开机时间", "DB600.B4")); + list.add(new ItemDto(ItemProtocol.item_standby_time, "待机时间", "DB600.D6")); + list.add(new ItemDto(ItemProtocol.item_production_time, "生产时间", "DB600.D7")); + list.add(new ItemDto(ItemProtocol.item_error_time, "故障时间", "DB600.D8")); + return list; + } + + @Override + public List getWriteableItemDtos() { + return ItemProtocol.getWriteableItemDtos(); + } + +} diff --git a/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_out_kiln_truss/LnshOutKilnTrussDeviceDriver.java b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_out_kiln_truss/LnshOutKilnTrussDeviceDriver.java new file mode 100644 index 0000000..8a9c7fc --- /dev/null +++ b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_out_kiln_truss/LnshOutKilnTrussDeviceDriver.java @@ -0,0 +1,346 @@ +package org.nl.acs.device_driver.lnsh.lnsh_out_kiln_truss; + +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.IdUtil; +import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSONObject; +import lombok.Data; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.device.device_driver.standard_inspect.ReadUtil; +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.instruction.service.InstructionService; +import org.nl.acs.instruction.service.dto.Instruction; +import org.nl.acs.opc.Device; +import org.nl.acs.opc.WcsConfig; +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.util.CodeUtil; +import org.nl.utils.SpringContextHolder; +import org.nl.wql.core.bean.WQLObject; +import org.openscada.opc.lib.da.Server; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.*; + +/** + * 晟华出窑桁架 + */ +@Slf4j +@Data +@RequiredArgsConstructor +public class LnshOutKilnTrussDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver { + protected ItemProtocol itemProtocol = new ItemProtocol(this); + @Autowired + InstructionService instructionService = SpringContextHolder.getBean("instructionServiceImpl"); + @Autowired + DeviceService deviceservice = SpringContextHolder.getBean("deviceServiceImpl"); + @Autowired + RouteLineService routelineserver = SpringContextHolder.getBean("routeLineServiceImpl"); + @Autowired + TaskService taskserver = SpringContextHolder.getBean("taskServiceImpl"); + + + String container; + String container_type_desc; + String last_container_type_desc; + String last_container; + //放货准备锁 + String putReadyLock = null; + //有货标记 + protected boolean has_goods_tag = false; + + + String device_code; + int mode = 0; + int error = 0; + int move = 0; + int action; + int io_action; + int task = 0; + int container_type = 0; + int last_mode = 0; + int last_error = 0; + int last_move = 0; + int last_task = 0; + int last_container_type; + Boolean isonline = true; + int hasGoods = 0; + Boolean iserror = false; + + boolean hasVehicle = false; + boolean isReady = false; + protected int instruction_num = 0; + protected int instruction_num_truth = 0; + boolean isFold = false; + private String assemble_check_tag; + private Boolean sampleMode0; + private Boolean sampleMode3; + private Integer sampleError; + private Boolean sampleOnline; + protected String displayMessage = null; + public int display_message_time_out = 30000; + public Date display_message_time; + protected String current_stage_instruction_message; + protected String last_stage_instruction_message; + Integer heartbeat_tag; + private Date instruction_require_time = new Date(); + private Date instruction_finished_time = new Date(); + + private int instruction_require_time_out = 3000; + boolean requireSucess = false; + + private int instruction_finished_time_out; + + int heartbeat; + int last_heartbeat; + private Date checkHeartbeattime = new Date(); + private Date last_checkHeartbeattime = new Date(); + + int branchProtocol = 0; + //当前指令 + Instruction inst = null; + //上次指令 + Instruction last_inst = null; + + //触摸屏手动触发任务 + private Boolean is_has_task = false; + + String message; + + @Override + public Device getDevice() { + return this.device; + } + + + @Override + public void execute() { + String message = null; + try { + device_code = this.getDeviceCode(); + + mode = this.itemProtocol.getMode(); + + if (mode != last_mode) { + this.setRequireSucess(false); + } + if (move != last_move) { + thingToNothing(); + } + if (error != last_error) { + } + if (container_type != last_container_type) { + } + + } catch (Exception var17) { + return; + } + + //急停 + if (this.isStop()) { + + //未在线无心跳 + } else 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); + message = ""; + Instruction instruction = null; + List toInstructions; + switch (mode) { + case 1: + log.debug("设备运转模式:等待工作"); + break; + case 2: + + break; + case 3: + + break; + case 4: + break; + } + } + + last_mode = mode; + last_error = error; + last_move = move; + last_task = task; + last_container_type = container_type; + } + + + protected void thingToNothing() throws Exception { + this.setRequireSucess(false); + } + + public void finish_instruction(Instruction instruction) throws Exception { + instruction_finished(instruction); + } + + /** + * 完成指令 + * + * @param instruction + * @return + */ + public boolean instruction_finished(Instruction instruction) throws Exception { + Date date = new Date(); + if (date.getTime() - this.instruction_finished_time.getTime() < (long) this.instruction_finished_time_out) { + log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_finished_time_out); + return false; + } else { + instructionService.finish(instruction.getInstruction_id()); + this.instruction_finished_time = date; + return true; + } + } + + /** + * 完成并创建下一条指令 + * + * @param instruction + * @param needCreateNext + * @return + */ + public boolean instruction_finished(Instruction instruction, boolean needCreateNext) { + Date date = new Date(); + if (date.getTime() - this.instruction_finished_time.getTime() < (long) this.instruction_finished_time_out) { + log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_finished_time_out); + return false; + } else { + this.instruction_finished_time = date; + return true; + } + } + + + private Instruction findInstruction() { + Instruction instruction = null; + if (this.instruction_num != 0) { + instruction = (Instruction) instructionService.findByCodeFromCache(String.valueOf(instruction_num)); + } + if (instruction != null) { + //可进行校验 + + + } else { + List container_instructions = new ArrayList(); + String barcode = this.getLast_container(); + + if (!StrUtil.isEmpty(barcode)) { + Map map = new HashMap(); + map.put("vehicle_code", barcode); + container_instructions = instructionService.queryAll(map); + } + + if (((List) container_instructions).size() > 1) { + log.debug("容器存在多个指令"); + } else { + if (((List) container_instructions).size() > 0) { + instruction = (Instruction) ((List) container_instructions).get(0); + } + } + } + return instruction; + } + + + public boolean exe_error() { + if (this.error == 0) { + return true; + } else { + log.debug("设备报警"); + return false; + } + } + + public void set_last_container(String barcode, String type_desc) { + this.set_last_container(barcode); + this.set_last_container_type_desc(type_desc); + } + + public void set_last_container(String barcode) { + } + + public void set_last_container_type_desc(String type) { + } + + public boolean exe_business() { + return true; + } + + public void executing(Server server, Map itemMap) { + ReadUtil.write(itemMap, server); + } + + public boolean instruction_require(String container_code) { + return instruction_require(container_code, WcsConfig.task_container_type_default_desc); + } + + /** + * 请求指令 + * + * @param container_code + * @param container_type + */ + public synchronized boolean instruction_require(String container_code, String container_type) { + 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; + TaskDto dto = new TaskDto(); + String now = DateUtil.now(); + dto.setTask_id(IdUtil.simpleUUID()); + dto.setCreate_by(this.getDevice().getDevice_code()); + dto.setUpdate_by(this.getDevice().getDevice_code()); + dto.setStart_point_code(this.getDevice().getDevice_code()); + dto.setVehicle_code(container_code); + dto.setVehicle_type(container_type); + + String taskcode = CodeUtil.getNewCode("TASK_NO"); + dto.setTask_code("-" + taskcode); + dto.setTask_status("0"); + dto.setPriority("101"); + RouteLineDto jo = routelineserver.findByCode(this.getDevice().getDevice_code()); + String next_device_codecode = jo.getNext_device_code(); + if (StrUtil.isEmpty(next_device_codecode)) { + throw new RuntimeException("该设备未找到对应路由"); + } + dto.setNext_point_code(next_device_codecode); + dto.setUpdate_time(now); + dto.setCreate_time(now); + + WQLObject wo = WQLObject.getWQLObject("acs_task"); + JSONObject json = (JSONObject) JSONObject.toJSON(dto); + + wo.insert(json); + requireSucess = false; + return true; + } + } + +} diff --git a/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_package_line/ItemProtocol.java b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_package_line/ItemProtocol.java new file mode 100644 index 0000000..882a915 --- /dev/null +++ b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_package_line/ItemProtocol.java @@ -0,0 +1,129 @@ +package org.nl.acs.device_driver.lnsh.lnsh_package_line; + +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_status = "status"; + public static String item_open_time = "open_time"; + public static String item_standby_time = "standby_time "; + public static String item_production_time = "production_time"; + public static String item_error_time = "error_time"; + public static String item_barcode = "barcode"; + public static String item_to_command = "to_command"; + public static String item_to_target = "to_target"; + public static String item_to_task = "to_task"; + public static String item_to_code_message = "to_code_message"; + public static String item_to_isPackage = "to_isPackage"; + Boolean isonline; + + private LnshPackageLineDeviceDriver driver; + + public ItemProtocol(LnshPackageLineDeviceDriver driver) { + this.driver = driver; + } + + public int getHeartbeat() { + return this.getOpcIntegerValue(item_heartbeat); + } + + public int getMode() { + return this.getOpcIntegerValue(item_mode); + } + + public int getStatus() { + return this.getOpcIntegerValue(item_status); + } + + public int getOpen_time() { + return this.getOpcIntegerValue(item_open_time); + } + + public int getStandby_time() { + return this.getOpcIntegerValue(item_standby_time); + } + + public int getProduction_time() { + return this.getOpcIntegerValue(item_production_time); + } + + public int getError_time() { + return this.getOpcIntegerValue(item_error_time); + } + + public int getBarcode() { + return this.getOpcIntegerValue(item_barcode); + } + + public int getTo_command() { + return this.getOpcIntegerValue(item_to_command); + } + + public int getTo_target() { + return this.getOpcIntegerValue(item_to_target); + } + + public int getTo_task() { + return this.getOpcIntegerValue(item_to_task); + } + + public int getTo_code_message() { + return this.getOpcIntegerValue(item_to_code_message); + } + + public int getTo_isPackage() { + return this.getOpcIntegerValue(item_to_isPackage); + } + + //是否有货 + public int hasGoods(int move) { + return move; + } + + + 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 static List getReadableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_heartbeat, "心跳", "DB600.B0")); + list.add(new ItemDto(item_mode, "工作状态", "DB600.B1", Boolean.valueOf(true))); + list.add(new ItemDto(item_status, "设备状态", "DB600.B2")); + list.add(new ItemDto(item_open_time, "开机时间", "DB600.B4")); + list.add(new ItemDto(item_standby_time, "待机时间", "DB600.D6")); + list.add(new ItemDto(item_production_time, "生产时间", "DB600.D7")); + list.add(new ItemDto(item_error_time, "故障时间", "DB600.D8")); + list.add(new ItemDto(item_barcode, "条码", "DB600.D8")); + return list; + } + + public static List getWriteableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_to_command, "下发命令", "DB601.W2", Boolean.valueOf(true))); + list.add(new ItemDto(item_to_target, "下发目标站", "DB601.W4")); + list.add(new ItemDto(item_to_task, "下发任务号", "DB601.D8")); + list.add(new ItemDto(item_to_code_message, "打码信息", "DB601.D8")); + list.add(new ItemDto(item_to_isPackage, "是否包装", "DB601.D8")); + return list; + } + +} + diff --git a/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_package_line/LnshPackageLineDefination.java b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_package_line/LnshPackageLineDefination.java new file mode 100644 index 0000000..ac7ba54 --- /dev/null +++ b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_package_line/LnshPackageLineDefination.java @@ -0,0 +1,74 @@ +package org.nl.acs.device_driver.lnsh.lnsh_package_line; + +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.ArrayList; +import java.util.LinkedList; +import java.util.List; + +/** + * 晟华包装线 + */ +@Service +public class LnshPackageLineDefination implements OpcDeviceDriverDefination { + @Override + public String getDriverCode() { + return "lnsh_package_line"; + } + + @Override + public String getDriverName() { + return "晟华-包装线"; + } + + @Override + public String getDriverDescription() { + return "晟华-包装线"; + } + + @Override + public DeviceDriver getDriverInstance(Device device) { + return (new LnshPackageLineDeviceDriver()).setDevice(device).setDriverDefination(this); + } + + @Override + public Class getDeviceDriverType() { + return LnshPackageLineDeviceDriver.class; + } + + @Override + public List getFitDeviceTypes() { + List types = new LinkedList(); + types.add(DeviceType.conveyor); + return types; + } + + @Override + public List getReadableItemDtos() { + return getReadableItemDtos2(); + } + + public static List getReadableItemDtos2() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(ItemProtocol.item_heartbeat, "心跳", "DB600.B0")); + list.add(new ItemDto(ItemProtocol.item_mode, "工作状态", "DB600.B1", Boolean.valueOf(true))); + list.add(new ItemDto(ItemProtocol.item_status, "设备状态", "DB600.B2")); + list.add(new ItemDto(ItemProtocol.item_open_time, "开机时间", "DB600.B4")); + list.add(new ItemDto(ItemProtocol.item_standby_time, "待机时间", "DB600.D6")); + list.add(new ItemDto(ItemProtocol.item_production_time, "生产时间", "DB600.D7")); + list.add(new ItemDto(ItemProtocol.item_error_time, "故障时间", "DB600.D8")); + list.add(new ItemDto(ItemProtocol.item_barcode, "条码", "DB600.D8")); + return list; + } + + @Override + public List getWriteableItemDtos() { + return ItemProtocol.getWriteableItemDtos(); + } + +} diff --git a/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_package_line/LnshPackageLineDeviceDriver.java b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_package_line/LnshPackageLineDeviceDriver.java new file mode 100644 index 0000000..62ec7e6 --- /dev/null +++ b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_package_line/LnshPackageLineDeviceDriver.java @@ -0,0 +1,346 @@ +package org.nl.acs.device_driver.lnsh.lnsh_package_line; + +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.IdUtil; +import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSONObject; +import lombok.Data; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.device.device_driver.standard_inspect.ReadUtil; +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.instruction.service.InstructionService; +import org.nl.acs.instruction.service.dto.Instruction; +import org.nl.acs.opc.Device; +import org.nl.acs.opc.WcsConfig; +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.util.CodeUtil; +import org.nl.utils.SpringContextHolder; +import org.nl.wql.core.bean.WQLObject; +import org.openscada.opc.lib.da.Server; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.*; + +/** + * 晟华包装线 + */ +@Slf4j +@Data +@RequiredArgsConstructor +public class LnshPackageLineDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver { + protected ItemProtocol itemProtocol = new ItemProtocol(this); + @Autowired + InstructionService instructionService = SpringContextHolder.getBean("instructionServiceImpl"); + @Autowired + DeviceService deviceservice = SpringContextHolder.getBean("deviceServiceImpl"); + @Autowired + RouteLineService routelineserver = SpringContextHolder.getBean("routeLineServiceImpl"); + @Autowired + TaskService taskserver = SpringContextHolder.getBean("taskServiceImpl"); + + + String container; + String container_type_desc; + String last_container_type_desc; + String last_container; + //放货准备锁 + String putReadyLock = null; + //有货标记 + protected boolean has_goods_tag = false; + + + String device_code; + int mode = 0; + int error = 0; + int move = 0; + int action; + int io_action; + int task = 0; + int container_type = 0; + int last_mode = 0; + int last_error = 0; + int last_move = 0; + int last_task = 0; + int last_container_type; + Boolean isonline = true; + int hasGoods = 0; + Boolean iserror = false; + + boolean hasVehicle = false; + boolean isReady = false; + protected int instruction_num = 0; + protected int instruction_num_truth = 0; + boolean isFold = false; + private String assemble_check_tag; + private Boolean sampleMode0; + private Boolean sampleMode3; + private Integer sampleError; + private Boolean sampleOnline; + protected String displayMessage = null; + public int display_message_time_out = 30000; + public Date display_message_time; + protected String current_stage_instruction_message; + protected String last_stage_instruction_message; + Integer heartbeat_tag; + private Date instruction_require_time = new Date(); + private Date instruction_finished_time = new Date(); + + private int instruction_require_time_out = 3000; + boolean requireSucess = false; + + private int instruction_finished_time_out; + + int heartbeat; + int last_heartbeat; + private Date checkHeartbeattime = new Date(); + private Date last_checkHeartbeattime = new Date(); + + int branchProtocol = 0; + //当前指令 + Instruction inst = null; + //上次指令 + Instruction last_inst = null; + + //触摸屏手动触发任务 + private Boolean is_has_task = false; + + String message; + + @Override + public Device getDevice() { + return this.device; + } + + + @Override + public void execute() { + String message = null; + try { + device_code = this.getDeviceCode(); + + mode = this.itemProtocol.getMode(); + + if (mode != last_mode) { + this.setRequireSucess(false); + } + if (move != last_move) { + thingToNothing(); + } + if (error != last_error) { + } + if (container_type != last_container_type) { + } + + } catch (Exception var17) { + return; + } + + //急停 + if (this.isStop()) { + + //未在线无心跳 + } else 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); + message = ""; + Instruction instruction = null; + List toInstructions; + switch (mode) { + case 1: + log.debug("设备运转模式:等待工作"); + break; + case 2: + + break; + case 3: + + break; + case 4: + break; + } + } + + last_mode = mode; + last_error = error; + last_move = move; + last_task = task; + last_container_type = container_type; + } + + + protected void thingToNothing() throws Exception { + this.setRequireSucess(false); + } + + public void finish_instruction(Instruction instruction) throws Exception { + instruction_finished(instruction); + } + + /** + * 完成指令 + * + * @param instruction + * @return + */ + public boolean instruction_finished(Instruction instruction) throws Exception { + Date date = new Date(); + if (date.getTime() - this.instruction_finished_time.getTime() < (long) this.instruction_finished_time_out) { + log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_finished_time_out); + return false; + } else { + instructionService.finish(instruction.getInstruction_id()); + this.instruction_finished_time = date; + return true; + } + } + + /** + * 完成并创建下一条指令 + * + * @param instruction + * @param needCreateNext + * @return + */ + public boolean instruction_finished(Instruction instruction, boolean needCreateNext) { + Date date = new Date(); + if (date.getTime() - this.instruction_finished_time.getTime() < (long) this.instruction_finished_time_out) { + log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_finished_time_out); + return false; + } else { + this.instruction_finished_time = date; + return true; + } + } + + + private Instruction findInstruction() { + Instruction instruction = null; + if (this.instruction_num != 0) { + instruction = (Instruction) instructionService.findByCodeFromCache(String.valueOf(instruction_num)); + } + if (instruction != null) { + //可进行校验 + + + } else { + List container_instructions = new ArrayList(); + String barcode = this.getLast_container(); + + if (!StrUtil.isEmpty(barcode)) { + Map map = new HashMap(); + map.put("vehicle_code", barcode); + container_instructions = instructionService.queryAll(map); + } + + if (((List) container_instructions).size() > 1) { + log.debug("容器存在多个指令"); + } else { + if (((List) container_instructions).size() > 0) { + instruction = (Instruction) ((List) container_instructions).get(0); + } + } + } + return instruction; + } + + + public boolean exe_error() { + if (this.error == 0) { + return true; + } else { + log.debug("设备报警"); + return false; + } + } + + public void set_last_container(String barcode, String type_desc) { + this.set_last_container(barcode); + this.set_last_container_type_desc(type_desc); + } + + public void set_last_container(String barcode) { + } + + public void set_last_container_type_desc(String type) { + } + + public boolean exe_business() { + return true; + } + + public void executing(Server server, Map itemMap) { + ReadUtil.write(itemMap, server); + } + + public boolean instruction_require(String container_code) { + return instruction_require(container_code, WcsConfig.task_container_type_default_desc); + } + + /** + * 请求指令 + * + * @param container_code + * @param container_type + */ + public synchronized boolean instruction_require(String container_code, String container_type) { + 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; + TaskDto dto = new TaskDto(); + String now = DateUtil.now(); + dto.setTask_id(IdUtil.simpleUUID()); + dto.setCreate_by(this.getDevice().getDevice_code()); + dto.setUpdate_by(this.getDevice().getDevice_code()); + dto.setStart_point_code(this.getDevice().getDevice_code()); + dto.setVehicle_code(container_code); + dto.setVehicle_type(container_type); + + String taskcode = CodeUtil.getNewCode("TASK_NO"); + dto.setTask_code("-" + taskcode); + dto.setTask_status("0"); + dto.setPriority("101"); + RouteLineDto jo = routelineserver.findByCode(this.getDevice().getDevice_code()); + String next_device_codecode = jo.getNext_device_code(); + if (StrUtil.isEmpty(next_device_codecode)) { + throw new RuntimeException("该设备未找到对应路由"); + } + dto.setNext_point_code(next_device_codecode); + dto.setUpdate_time(now); + dto.setCreate_time(now); + + WQLObject wo = WQLObject.getWQLObject("acs_task"); + JSONObject json = (JSONObject) JSONObject.toJSON(dto); + + wo.insert(json); + requireSucess = false; + return true; + } + } + +} diff --git a/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_package_pallet_manipulator/ItemProtocol.java b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_package_pallet_manipulator/ItemProtocol.java new file mode 100644 index 0000000..cfb0c87 --- /dev/null +++ b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_package_pallet_manipulator/ItemProtocol.java @@ -0,0 +1,179 @@ +package org.nl.acs.device_driver.lnsh.lnsh_package_pallet_manipulator; + +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_status = "status"; + public static String item_error = "error"; + public static String item_putStation = "putStation"; + public static String item_barcode = "barcode"; + public static String item_material = "material"; + public static String item_qty = "qty"; + public static String item_open_time = "open_time"; + public static String item_standby_time = "standby_time "; + public static String item_production_time = "production_time"; + public static String item_error_time = "error_time"; + public static String item_order_No = "order_No"; + public static String item_to_heartbeat = "to_heartbeat"; + public static String item_to_feedback = "to_feedback"; + public static String item_to_error = "to_error"; + public static String item_to_material_qty = "to_material_qty"; + public static String item_to_allow_pallet_qty = "to_allow_pallet_qty"; + public static String item_to_material_type = "to_material_type"; + public static String item_to_material_code = "to_material_code"; + public static String item_to_order_No = "to_order_No"; + + + private LnshPackagePalletManipulatorDeviceDriver driver; + + public ItemProtocol(LnshPackagePalletManipulatorDeviceDriver driver) { + this.driver = driver; + } + + public int getHeartbeat() { + return this.getOpcIntegerValue(item_heartbeat); + } + + public int getMode() { + return this.getOpcIntegerValue(item_mode); + } + + public int getStatus() { + return this.getOpcIntegerValue(item_status); + } + + public int getError() { + return this.getOpcIntegerValue(item_error); + } + + public int getPutStation() { + return this.getOpcIntegerValue(item_putStation); + } + + public int getBarcode() { + return this.getOpcIntegerValue(item_barcode); + } + + public int getMaterial() { + return this.getOpcIntegerValue(item_material); + } + + public int getQty() { + return this.getOpcIntegerValue(item_qty); + } + + public int getOpen_time() { + return this.getOpcIntegerValue(item_open_time); + } + + public int getStandby_time() { + return this.getOpcIntegerValue(item_standby_time); + } + + public int getProduction_time() { + return this.getOpcIntegerValue(item_production_time); + } + + public int getError_time() { + return this.getOpcIntegerValue(item_error_time); + } + + public int getOrder_No() { + return this.getOpcIntegerValue(item_order_No); + } + + public int getTo_heartbeat() { + return this.getOpcIntegerValue(item_to_heartbeat); + } + + public int getTo_feedback() { + return this.getOpcIntegerValue(item_to_feedback); + } + + public int getTo_error() { + return this.getOpcIntegerValue(item_to_error); + } + + public int getTo_material_qty() { + return this.getOpcIntegerValue(item_to_material_qty); + } + + public int getTo_allow_pallet_qty() { + return this.getOpcIntegerValue(item_to_allow_pallet_qty); + } + + public int getTo_material_type() { + return this.getOpcIntegerValue(item_to_material_type); + } + + public int getTo_material_code() { + return this.getOpcIntegerValue(item_to_material_code); + } + + public int getTo_order_No() { + return this.getOpcIntegerValue(item_to_order_No); + } + + //是否有货 + public int hasGoods(int move) { + return move; + } + + 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 static List getReadableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_heartbeat, "心跳", "DB600.B0")); + list.add(new ItemDto(item_mode, "工作状态", "DB600.B2", Boolean.valueOf(true))); + list.add(new ItemDto(item_status, "设备状态", "DB600.B3")); + list.add(new ItemDto(item_error, "故障代码", "DB600.B3")); + list.add(new ItemDto(item_putStation, "当前码盘工位", "DB600.B3")); + list.add(new ItemDto(item_barcode, "当前码盘工位条码", "DB600.B3")); + list.add(new ItemDto(item_material, "码盘工位当前物料", "DB600.B3")); + list.add(new ItemDto(item_qty, "数量", "DB600.B3")); + list.add(new ItemDto(item_open_time, "开机时间", "DB600.B4")); + list.add(new ItemDto(item_standby_time, "待机时间", "DB600.D6")); + list.add(new ItemDto(item_production_time, "生产时间", "DB600.D7")); + list.add(new ItemDto(item_error_time, "故障时间", "DB600.D8")); + list.add(new ItemDto(item_order_No, "工单号", "DB600.D9")); + return list; + } + + public static List getWriteableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_to_heartbeat, "心跳", "DB601.W0")); + list.add(new ItemDto(item_to_feedback, "机器人动作反馈", "DB601.W0")); + list.add(new ItemDto(item_to_error, "故障代码", "DB601.W0")); + list.add(new ItemDto(item_to_material_qty, "托盘上数量", "DB601.W0")); + list.add(new ItemDto(item_to_allow_pallet_qty, "允许码垛数量", "DB601.W0")); + list.add(new ItemDto(item_to_material_type, "托盘类型", "DB601.W0")); + list.add(new ItemDto(item_to_material_code, "下发物料编号", "DB601.W10")); + list.add(new ItemDto(item_to_order_No, "工单号", "DB601.W10")); + return list; + } + +} + diff --git a/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_package_pallet_manipulator/LnshPackagePalletManipulatorDefination.java b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_package_pallet_manipulator/LnshPackagePalletManipulatorDefination.java new file mode 100644 index 0000000..1840b0a --- /dev/null +++ b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_package_pallet_manipulator/LnshPackagePalletManipulatorDefination.java @@ -0,0 +1,81 @@ +package org.nl.acs.device_driver.lnsh.lnsh_package_pallet_manipulator; + +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.ArrayList; +import java.util.LinkedList; +import java.util.List; + +/** + * 晟华包装码垛机械手 + * + */ +@Service +public class LnshPackagePalletManipulatorDefination implements OpcDeviceDriverDefination { + @Override + public String getDriverCode() { + return "lnsh_package_pallet_manipulator"; + } + + @Override + public String getDriverName() { + return "晟华-包装码垛机械手"; + } + + @Override + public String getDriverDescription() { + return "晟华-包装码垛机械手"; + } + + @Override + public DeviceDriver getDriverInstance(Device device) { + return (new LnshPackagePalletManipulatorDeviceDriver()).setDevice(device).setDriverDefination(this); + + } + + @Override + public Class getDeviceDriverType() { + return LnshPackagePalletManipulatorDeviceDriver.class; + } + + @Override + public List getFitDeviceTypes() { + List types = new LinkedList(); + types.add(DeviceType.conveyor); + return types; + } + + @Override + public List getReadableItemDtos() { + return getReadableItemDtos2(); + } + + public static List getReadableItemDtos2() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(ItemProtocol.item_heartbeat, "心跳", "DB600.B0")); + list.add(new ItemDto(ItemProtocol.item_mode, "工作状态", "DB600.B2", Boolean.valueOf(true))); + list.add(new ItemDto(ItemProtocol.item_status, "设备状态", "DB600.B3")); + list.add(new ItemDto(ItemProtocol.item_error, "故障代码", "DB600.B3")); + list.add(new ItemDto(ItemProtocol.item_putStation, "当前码盘工位", "DB600.B3")); + list.add(new ItemDto(ItemProtocol.item_barcode, "当前码盘工位条码", "DB600.B3")); + list.add(new ItemDto(ItemProtocol.item_material, "码盘工位当前物料", "DB600.B3")); + list.add(new ItemDto(ItemProtocol.item_qty, "数量", "DB600.B3")); + list.add(new ItemDto(ItemProtocol.item_open_time, "开机时间", "DB600.B4")); + list.add(new ItemDto(ItemProtocol.item_standby_time, "待机时间", "DB600.D6")); + list.add(new ItemDto(ItemProtocol.item_production_time, "生产时间", "DB600.D7")); + list.add(new ItemDto(ItemProtocol.item_error_time, "故障时间", "DB600.D8")); + list.add(new ItemDto(ItemProtocol.item_order_No, "工单号", "DB600.D9")); + return list; + } + + @Override + public List getWriteableItemDtos() { + return ItemProtocol.getWriteableItemDtos(); + } + +} diff --git a/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_package_pallet_manipulator/LnshPackagePalletManipulatorDeviceDriver.java b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_package_pallet_manipulator/LnshPackagePalletManipulatorDeviceDriver.java new file mode 100644 index 0000000..2b387fb --- /dev/null +++ b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_package_pallet_manipulator/LnshPackagePalletManipulatorDeviceDriver.java @@ -0,0 +1,267 @@ +package org.nl.acs.device_driver.lnsh.lnsh_package_pallet_manipulator; + +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.IdUtil; +import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSONObject; +import lombok.Data; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.device.device_driver.standard_inspect.ReadUtil; +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.instruction.service.InstructionService; +import org.nl.acs.instruction.service.dto.Instruction; +import org.nl.acs.opc.Device; +import org.nl.acs.opc.WcsConfig; +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.util.CodeUtil; +import org.nl.utils.SpringContextHolder; +import org.nl.wql.core.bean.WQLObject; +import org.openscada.opc.lib.da.Server; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.Date; +import java.util.List; +import java.util.Map; + +/** + * 晟华干燥窑 + */ +@Slf4j +@Data +@RequiredArgsConstructor +public class LnshPackagePalletManipulatorDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver { + protected ItemProtocol itemProtocol = new ItemProtocol(this); + @Autowired + InstructionService instructionService = SpringContextHolder.getBean("instructionServiceImpl"); + @Autowired + DeviceService deviceservice = SpringContextHolder.getBean("deviceServiceImpl"); + @Autowired + RouteLineService routelineserver = SpringContextHolder.getBean("routeLineServiceImpl"); + @Autowired + TaskService taskserver = SpringContextHolder.getBean("taskServiceImpl"); + String container; + String container_type_desc; + String last_container_type_desc; + String last_container; + //放货准备锁 + String putReadyLock = null; + //有货标记 + protected boolean has_goods_tag = false; + + int mode = 0; + int error = 0; + int last_mode = 0; + int last_error = 0; + Boolean isonline = true; + int hasGoods = 0; + String message = null; + Boolean iserror = false; + + + boolean hasVehicle = false; + boolean isReady = false; + protected int instruction_num = 0; + protected int instruction_num_truth = 0; + boolean isFold = false; + private String assemble_check_tag; + + protected String current_stage_instruction_message; + protected String last_stage_instruction_message; + Integer heartbeat_tag; + private Date instruction_require_time = new Date(); + private Date instruction_finished_time = new Date(); + + private int instruction_require_time_out; + boolean requireSucess = false; + + private int instruction_finished_time_out; + + int branchProtocol = 0; + //备注 + String remark; + //数量 + String qty; + //物料 + String material; + //批次 + String batch; + //当前指令 + Instruction inst = null; + //上次指令 + Instruction last_inst = null; + + //触摸屏手动触发任务 + private Boolean is_has_task = false; + + //申请搬运任务 + private Boolean apply_handling = false; + //申请物料 + private Boolean apply_material = false; + + //暂定 0就绪 1请求取货 2取货完成 3请求放货 4放货完成 5取货完成离开 6放货完成离开 7请求进入区域 8请求离开区域 + int flag; + + String devicecode; + + @Override + public Device getDevice() { + return this.device; + } + + + @Override + public void execute() { + String message = null; + try { + String device_code = this.getDeviceCode(); + mode = this.itemProtocol.getMode(); + + if (mode != last_mode) { + this.setRequireSucess(false); + } + if (error != last_error) { + } + + } catch (Exception var17) { + return; + } + + 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); + message = ""; + Instruction instruction = null; + List toInstructions; + switch (mode) { + case 1: + log.debug("设备运转模式:等待工作"); + return; + case 2: + if (material.length() > 0 && qty.length() > 0 && !requireSucess) { + this.instruction_require(container); + } + } + + switch (flag) { + //取货完成 + case 1: + return; + //放货完成 + case 2: + return; + + } + + } + last_mode = mode; + last_error = error; + + } + + + public boolean exe_error() { + if (this.error == 0) { + return true; + } else { + log.debug("设备报警"); + return false; + } + } + + protected void thingToNothing() { + log.debug("从有货到无货 清理数据"); + this.set_last_container(container, container_type_desc); + } + + public void set_last_container(String barcode, String type_desc) { + this.set_last_container(barcode); + this.set_last_container_type_desc(type_desc); + } + + public void set_last_container(String barcode) { + } + + public void set_last_container_type_desc(String type) { + } + + public boolean exe_business() { + return true; + } + + public void executing(Server server, Map itemMap) { + ReadUtil.write(itemMap, server); + } + + public boolean instruction_require(String container_code) { + return instruction_require(container_code, WcsConfig.task_container_type_default_desc); + } + + /** + * 请求指令 + * + * @param container_code + * @param container_type + */ + public synchronized boolean instruction_require(String container_code, String container_type) { + 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; + TaskDto dto = new TaskDto(); + String now = DateUtil.now(); + dto.setTask_id(IdUtil.simpleUUID()); + dto.setCreate_by(this.getDevice().getDevice_code()); + dto.setUpdate_by(this.getDevice().getDevice_code()); + dto.setStart_point_code(this.getDevice().getDevice_code()); + dto.setVehicle_code(container_code); + dto.setVehicle_type(container_type); + + String taskcode = CodeUtil.getNewCode("TASK_NO"); + dto.setTask_code("-" + taskcode); + dto.setTask_status("0"); + dto.setPriority("101"); + RouteLineDto jo = routelineserver.findByCode(this.getDevice().getDevice_code()); + String next_device_codecode = jo.getNext_device_code(); + if (StrUtil.isEmpty(next_device_codecode)) { + throw new RuntimeException("该设备未找到对应路由"); + } + dto.setNext_point_code(next_device_codecode); + dto.setUpdate_time(now); + dto.setCreate_time(now); + + WQLObject wo = WQLObject.getWQLObject("acs_task"); + JSONObject json = (JSONObject) JSONObject.toJSON(dto); + + wo.insert(json); + requireSucess = false; + return true; + } + } + + +} diff --git a/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_pallet_storage/ItemProtocol.java b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_pallet_storage/ItemProtocol.java new file mode 100644 index 0000000..b14c111 --- /dev/null +++ b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_pallet_storage/ItemProtocol.java @@ -0,0 +1,129 @@ +package org.nl.acs.device_driver.lnsh.lnsh_pallet_storage; + +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_status = "status"; + public static String item_open_time = "open_time"; + public static String item_close_time = "close_time"; + public static String item_standby_time = "standby_time "; + public static String item_production_time = "production_time"; + public static String item_error_time = "error_time"; + public static String item_tray_crib_qty = "tray_crib_qty"; + public static String item_total_container = "total_container"; + public static String item_to_command = "to_command"; + public static String item_to_target = "to_target"; + public static String item_to_task = "to_task"; + Boolean isonline; + + private LnshPalletStorageDeviceDriver driver; + + public ItemProtocol(LnshPalletStorageDeviceDriver driver) { + this.driver = driver; + } + + public int getHeartbeat() { + return this.getOpcIntegerValue(item_heartbeat); + } + + public int getMode() { + return this.getOpcIntegerValue(item_mode); + } + + public int getStatus() { + return this.getOpcIntegerValue(item_status); + } + + public int getOpen_time() { + return this.getOpcIntegerValue(item_open_time); + } + + public int getClose_time() { + return this.getOpcIntegerValue(item_close_time); + } + + public int getStandby_time() { + return this.getOpcIntegerValue(item_standby_time); + } + + public int getProduction_time() { + return this.getOpcIntegerValue(item_production_time); + } + + public int getError_time() { + return this.getOpcIntegerValue(item_error_time); + } + + public int getTray_crib_qty() { + return this.getOpcIntegerValue(item_tray_crib_qty); + } + + public int getTotal_container() { + return this.getOpcIntegerValue(item_total_container); + } + + public int getToCommand() { + return this.getOpcIntegerValue(item_to_command); + } + + public int getToTarget() { + return this.getOpcIntegerValue(item_to_target); + } + + public int getToTask() { + return this.getOpcIntegerValue(item_to_task); + } + + //是否有货 + public int hasGoods(int move) { + return move; + } + + + 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 static List getReadableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_heartbeat, "心跳", "DB600.B0")); + list.add(new ItemDto(item_mode, "工作状态", "DB600.B1", Boolean.valueOf(true))); + list.add(new ItemDto(item_status, "设备状态", "DB600.B2")); + list.add(new ItemDto(item_open_time, "开机时间", "DB600.B4")); + list.add(new ItemDto(item_close_time, "关机时间", "DB600.D5")); + list.add(new ItemDto(item_standby_time, "待机时间", "DB600.D6")); + list.add(new ItemDto(item_production_time, "生产时间", "DB600.D7")); + list.add(new ItemDto(item_error_time, "故障时间", "DB600.D8")); + list.add(new ItemDto(item_tray_crib_qty, "托盘垛数", "DB600.D8")); + list.add(new ItemDto(item_total_container, "托盘总数量", "DB600.D8")); + return list; + } + + public static List getWriteableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_to_command, "下发命令", "DB601.W2", Boolean.valueOf(true))); + list.add(new ItemDto(item_to_target, "下发目标站", "DB601.W4")); + list.add(new ItemDto(item_to_task, "下发任务号", "DB601.D8")); + return list; + } + +} + diff --git a/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_pallet_storage/LnshPalletStorageDefination.java b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_pallet_storage/LnshPalletStorageDefination.java new file mode 100644 index 0000000..549b42c --- /dev/null +++ b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_pallet_storage/LnshPalletStorageDefination.java @@ -0,0 +1,76 @@ +package org.nl.acs.device_driver.lnsh.lnsh_pallet_storage; + +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.ArrayList; +import java.util.LinkedList; +import java.util.List; + +/** + * 晟华托盘存储线 + */ +@Service +public class LnshPalletStorageDefination implements OpcDeviceDriverDefination { + @Override + public String getDriverCode() { + return "lnsh_pallet_storage"; + } + + @Override + public String getDriverName() { + return "晟华-托盘存储线"; + } + + @Override + public String getDriverDescription() { + return "晟华-托盘存储线"; + } + + @Override + public DeviceDriver getDriverInstance(Device device) { + return (new LnshPalletStorageDeviceDriver()).setDevice(device).setDriverDefination(this); + } + + @Override + public Class getDeviceDriverType() { + return LnshPalletStorageDeviceDriver.class; + } + + @Override + public List getFitDeviceTypes() { + List types = new LinkedList(); + types.add(DeviceType.conveyor); + return types; + } + + @Override + public List getReadableItemDtos() { + return getReadableItemDtos2(); + } + + public static List getReadableItemDtos2() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(ItemProtocol.item_heartbeat, "心跳", "DB600.B0")); + list.add(new ItemDto(ItemProtocol.item_mode, "工作状态", "DB600.B1", Boolean.valueOf(true))); + list.add(new ItemDto(ItemProtocol.item_status, "设备状态", "DB600.B2")); + list.add(new ItemDto(ItemProtocol.item_open_time, "开机时间", "DB600.B4")); + list.add(new ItemDto(ItemProtocol.item_close_time, "关机时间", "DB600.D5")); + list.add(new ItemDto(ItemProtocol.item_standby_time, "待机时间", "DB600.D6")); + list.add(new ItemDto(ItemProtocol.item_production_time, "生产时间", "DB600.D7")); + list.add(new ItemDto(ItemProtocol.item_error_time, "故障时间", "DB600.D8")); + list.add(new ItemDto(ItemProtocol.item_tray_crib_qty, "托盘垛数", "DB600.D8")); + list.add(new ItemDto(ItemProtocol.item_total_container, "托盘总数量", "DB600.D8")); + return list; + } + + @Override + public List getWriteableItemDtos() { + return ItemProtocol.getWriteableItemDtos(); + } + +} diff --git a/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_pallet_storage/LnshPalletStorageDeviceDriver.java b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_pallet_storage/LnshPalletStorageDeviceDriver.java new file mode 100644 index 0000000..0d888fd --- /dev/null +++ b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_pallet_storage/LnshPalletStorageDeviceDriver.java @@ -0,0 +1,346 @@ +package org.nl.acs.device_driver.lnsh.lnsh_pallet_storage; + +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.IdUtil; +import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSONObject; +import lombok.Data; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.device.device_driver.standard_inspect.ReadUtil; +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.instruction.service.InstructionService; +import org.nl.acs.instruction.service.dto.Instruction; +import org.nl.acs.opc.Device; +import org.nl.acs.opc.WcsConfig; +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.util.CodeUtil; +import org.nl.utils.SpringContextHolder; +import org.nl.wql.core.bean.WQLObject; +import org.openscada.opc.lib.da.Server; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.*; + +/** + * 晟华托盘存储线 + */ +@Slf4j +@Data +@RequiredArgsConstructor +public class LnshPalletStorageDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver { + protected ItemProtocol itemProtocol = new ItemProtocol(this); + @Autowired + InstructionService instructionService = SpringContextHolder.getBean("instructionServiceImpl"); + @Autowired + DeviceService deviceservice = SpringContextHolder.getBean("deviceServiceImpl"); + @Autowired + RouteLineService routelineserver = SpringContextHolder.getBean("routeLineServiceImpl"); + @Autowired + TaskService taskserver = SpringContextHolder.getBean("taskServiceImpl"); + + + String container; + String container_type_desc; + String last_container_type_desc; + String last_container; + //放货准备锁 + String putReadyLock = null; + //有货标记 + protected boolean has_goods_tag = false; + + + String device_code; + int mode = 0; + int error = 0; + int move = 0; + int action; + int io_action; + int task = 0; + int container_type = 0; + int last_mode = 0; + int last_error = 0; + int last_move = 0; + int last_task = 0; + int last_container_type; + Boolean isonline = true; + int hasGoods = 0; + Boolean iserror = false; + + boolean hasVehicle = false; + boolean isReady = false; + protected int instruction_num = 0; + protected int instruction_num_truth = 0; + boolean isFold = false; + private String assemble_check_tag; + private Boolean sampleMode0; + private Boolean sampleMode3; + private Integer sampleError; + private Boolean sampleOnline; + protected String displayMessage = null; + public int display_message_time_out = 30000; + public Date display_message_time; + protected String current_stage_instruction_message; + protected String last_stage_instruction_message; + Integer heartbeat_tag; + private Date instruction_require_time = new Date(); + private Date instruction_finished_time = new Date(); + + private int instruction_require_time_out = 3000; + boolean requireSucess = false; + + private int instruction_finished_time_out; + + int heartbeat; + int last_heartbeat; + private Date checkHeartbeattime = new Date(); + private Date last_checkHeartbeattime = new Date(); + + int branchProtocol = 0; + //当前指令 + Instruction inst = null; + //上次指令 + Instruction last_inst = null; + + //触摸屏手动触发任务 + private Boolean is_has_task = false; + + String message; + + @Override + public Device getDevice() { + return this.device; + } + + + @Override + public void execute() { + String message = null; + try { + device_code = this.getDeviceCode(); + + mode = this.itemProtocol.getMode(); + + if (mode != last_mode) { + this.setRequireSucess(false); + } + if (move != last_move) { + thingToNothing(); + } + if (error != last_error) { + } + if (container_type != last_container_type) { + } + + } catch (Exception var17) { + return; + } + + //急停 + if (this.isStop()) { + + //未在线无心跳 + } else 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); + message = ""; + Instruction instruction = null; + List toInstructions; + switch (mode) { + case 1: + log.debug("设备运转模式:等待工作"); + break; + case 2: + + break; + case 3: + + break; + case 4: + break; + } + } + + last_mode = mode; + last_error = error; + last_move = move; + last_task = task; + last_container_type = container_type; + } + + + protected void thingToNothing() throws Exception { + this.setRequireSucess(false); + } + + public void finish_instruction(Instruction instruction) throws Exception { + instruction_finished(instruction); + } + + /** + * 完成指令 + * + * @param instruction + * @return + */ + public boolean instruction_finished(Instruction instruction) throws Exception { + Date date = new Date(); + if (date.getTime() - this.instruction_finished_time.getTime() < (long) this.instruction_finished_time_out) { + log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_finished_time_out); + return false; + } else { + instructionService.finish(instruction.getInstruction_id()); + this.instruction_finished_time = date; + return true; + } + } + + /** + * 完成并创建下一条指令 + * + * @param instruction + * @param needCreateNext + * @return + */ + public boolean instruction_finished(Instruction instruction, boolean needCreateNext) { + Date date = new Date(); + if (date.getTime() - this.instruction_finished_time.getTime() < (long) this.instruction_finished_time_out) { + log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_finished_time_out); + return false; + } else { + this.instruction_finished_time = date; + return true; + } + } + + + private Instruction findInstruction() { + Instruction instruction = null; + if (this.instruction_num != 0) { + instruction = (Instruction) instructionService.findByCodeFromCache(String.valueOf(instruction_num)); + } + if (instruction != null) { + //可进行校验 + + + } else { + List container_instructions = new ArrayList(); + String barcode = this.getLast_container(); + + if (!StrUtil.isEmpty(barcode)) { + Map map = new HashMap(); + map.put("vehicle_code", barcode); + container_instructions = instructionService.queryAll(map); + } + + if (((List) container_instructions).size() > 1) { + log.debug("容器存在多个指令"); + } else { + if (((List) container_instructions).size() > 0) { + instruction = (Instruction) ((List) container_instructions).get(0); + } + } + } + return instruction; + } + + + public boolean exe_error() { + if (this.error == 0) { + return true; + } else { + log.debug("设备报警"); + return false; + } + } + + public void set_last_container(String barcode, String type_desc) { + this.set_last_container(barcode); + this.set_last_container_type_desc(type_desc); + } + + public void set_last_container(String barcode) { + } + + public void set_last_container_type_desc(String type) { + } + + public boolean exe_business() { + return true; + } + + public void executing(Server server, Map itemMap) { + ReadUtil.write(itemMap, server); + } + + public boolean instruction_require(String container_code) { + return instruction_require(container_code, WcsConfig.task_container_type_default_desc); + } + + /** + * 请求指令 + * + * @param container_code + * @param container_type + */ + public synchronized boolean instruction_require(String container_code, String container_type) { + 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; + TaskDto dto = new TaskDto(); + String now = DateUtil.now(); + dto.setTask_id(IdUtil.simpleUUID()); + dto.setCreate_by(this.getDevice().getDevice_code()); + dto.setUpdate_by(this.getDevice().getDevice_code()); + dto.setStart_point_code(this.getDevice().getDevice_code()); + dto.setVehicle_code(container_code); + dto.setVehicle_type(container_type); + + String taskcode = CodeUtil.getNewCode("TASK_NO"); + dto.setTask_code("-" + taskcode); + dto.setTask_status("0"); + dto.setPriority("101"); + RouteLineDto jo = routelineserver.findByCode(this.getDevice().getDevice_code()); + String next_device_codecode = jo.getNext_device_code(); + if (StrUtil.isEmpty(next_device_codecode)) { + throw new RuntimeException("该设备未找到对应路由"); + } + dto.setNext_point_code(next_device_codecode); + dto.setUpdate_time(now); + dto.setCreate_time(now); + + WQLObject wo = WQLObject.getWQLObject("acs_task"); + JSONObject json = (JSONObject) JSONObject.toJSON(dto); + + wo.insert(json); + requireSucess = false; + return true; + } + } + +} diff --git a/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_palletizing_manipulator/ItemProtocol.java b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_palletizing_manipulator/ItemProtocol.java new file mode 100644 index 0000000..5ed418c --- /dev/null +++ b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_palletizing_manipulator/ItemProtocol.java @@ -0,0 +1,162 @@ +package org.nl.acs.device_driver.lnsh.lnsh_palletizing_manipulator; + +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_status = "status"; + public static String item_action = "action"; + public static String item_error = "error"; + public static String item_put_station = "put_station"; + public static String item_barcode = "barcode"; + public static String item_material = "material"; + public static String item_encoder_qty = "encoder_qty"; + public static String item_open_time = "open_time"; + public static String item_standby_time = "standby_time "; + public static String item_production_time = "production_time"; + public static String item_error_time = "error_time"; + public static String item_to_heartbeat = "to_heartbeat"; + public static String item_to_feedback = "to_feedback"; + public static String item_to_error = "to_error"; + public static String item_to_materialQty = "to_materialQty"; + public static String item_to_material_type = "to_material_type"; + public static String item_to_material_code = "to_material_code"; + + + private LnshPalletizingManipulatorDeviceDriver driver; + + public ItemProtocol(LnshPalletizingManipulatorDeviceDriver driver) { + this.driver = driver; + } + + public int getHeartbeat() { + return this.getOpcIntegerValue(item_heartbeat); + } + + public int getMode() { + return this.getOpcIntegerValue(item_mode); + } + + public int getStatus() { + return this.getOpcIntegerValue(item_status); + } + + public int getAction() { + return this.getOpcIntegerValue(item_action); + } + + public int getError() { + return this.getOpcIntegerValue(item_error); + } + + public int getPut_station() { + return this.getOpcIntegerValue(item_put_station); + } + + public int getBarcode() { + return this.getOpcIntegerValue(item_barcode); + } + + public int getMaterial() { + return this.getOpcIntegerValue(item_material); + } + + public int getEncoder_qty() { + return this.getOpcIntegerValue(item_encoder_qty); + } + + public int getOpen_time() { + return this.getOpcIntegerValue(item_open_time); + } + + public int getStandby_time() { + return this.getOpcIntegerValue(item_standby_time); + } + + public int getProduction_time() { + return this.getOpcIntegerValue(item_production_time); + } + + public int getError_time() { + return this.getOpcIntegerValue(item_error_time); + } + + public int getTo_heartbeat() { + return this.getOpcIntegerValue(item_to_heartbeat); + } + + public int getTo_feedback() { + return this.getOpcIntegerValue(item_to_feedback); + } + + public int getTo_error() { + return this.getOpcIntegerValue(item_to_error); + } + + public int getTo_materialQty() { + return this.getOpcIntegerValue(item_to_materialQty); + } + + public int getTo_material_type() { + return this.getOpcIntegerValue(item_to_material_type); + } + + public int getTo_material_code() { + return this.getOpcIntegerValue(item_to_material_code); + } + + 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 static List getReadableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_heartbeat, "心跳", "DB600.B0")); + list.add(new ItemDto(item_mode, "工作状态", "DB600.B2", Boolean.valueOf(true))); + list.add(new ItemDto(item_status, "设备状态", "DB600.B3")); + list.add(new ItemDto(item_action, "动作", "DB600.B3")); + list.add(new ItemDto(item_error, "故障代码", "DB600.B3")); + list.add(new ItemDto(item_put_station, "当前码盘工位", "DB600.B3")); + list.add(new ItemDto(item_barcode, "当前码盘工位条码", "DB600.B3")); + list.add(new ItemDto(item_material, "码盘工位当前物料", "DB600.B3")); + list.add(new ItemDto(item_encoder_qty, "码盘位当前码盘数量", "DB600.B3")); + list.add(new ItemDto(item_open_time, "开机时间", "DB600.B4")); + list.add(new ItemDto(item_standby_time, "待机时间", "DB600.D6")); + list.add(new ItemDto(item_production_time, "生产时间", "DB600.D7")); + list.add(new ItemDto(item_error_time, "故障时间", "DB600.D8")); + return list; + } + + public static List getWriteableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_to_heartbeat, "心跳", "DB601.W2")); + list.add(new ItemDto(item_to_feedback, "机器人动作反馈", "DB601.W2")); + list.add(new ItemDto(item_to_error, "故障代码", "DB601.W2")); + list.add(new ItemDto(item_to_materialQty, "托盘砖数量", "DB601.W2")); + list.add(new ItemDto(item_to_material_type, "箱型", "DB601.W2")); + list.add(new ItemDto(item_to_material_code, "下发物料编号", "DB601.W10")); + return list; + } + +} + diff --git a/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_palletizing_manipulator/LnshPalletizingManipulatorDefination.java b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_palletizing_manipulator/LnshPalletizingManipulatorDefination.java new file mode 100644 index 0000000..d44f6d0 --- /dev/null +++ b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_palletizing_manipulator/LnshPalletizingManipulatorDefination.java @@ -0,0 +1,81 @@ +package org.nl.acs.device_driver.lnsh.lnsh_palletizing_manipulator; + +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.ArrayList; +import java.util.LinkedList; +import java.util.List; + +/** + * 晟华码垛机械手 + * + */ +@Service +public class LnshPalletizingManipulatorDefination implements OpcDeviceDriverDefination { + @Override + public String getDriverCode() { + return "lnsh_palletizing_manipulator"; + } + + @Override + public String getDriverName() { + return "晟华-码垛机械手"; + } + + @Override + public String getDriverDescription() { + return "晟华-码垛机械手"; + } + + @Override + public DeviceDriver getDriverInstance(Device device) { + return (new LnshPalletizingManipulatorDeviceDriver()).setDevice(device).setDriverDefination(this); + + } + + @Override + public Class getDeviceDriverType() { + return LnshPalletizingManipulatorDeviceDriver.class; + } + + @Override + public List getFitDeviceTypes() { + List types = new LinkedList(); + types.add(DeviceType.conveyor); + return types; + } + + @Override + public List getReadableItemDtos() { + return getReadableItemDtos2(); + } + + public static List getReadableItemDtos2() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(ItemProtocol.item_heartbeat, "心跳", "DB600.B0")); + list.add(new ItemDto(ItemProtocol.item_mode, "工作状态", "DB600.B2", Boolean.valueOf(true))); + list.add(new ItemDto(ItemProtocol.item_status, "设备状态", "DB600.B3")); + list.add(new ItemDto(ItemProtocol.item_action, "动作", "DB600.B3")); + list.add(new ItemDto(ItemProtocol.item_error, "故障代码", "DB600.B3")); + list.add(new ItemDto(ItemProtocol.item_put_station, "当前码盘工位", "DB600.B3")); + list.add(new ItemDto(ItemProtocol.item_barcode, "当前码盘工位条码", "DB600.B3")); + list.add(new ItemDto(ItemProtocol.item_material, "码盘工位当前物料", "DB600.B3")); + list.add(new ItemDto(ItemProtocol.item_encoder_qty, "码盘位当前码盘数量", "DB600.B3")); + list.add(new ItemDto(ItemProtocol.item_open_time, "开机时间", "DB600.B4")); + list.add(new ItemDto(ItemProtocol.item_standby_time, "待机时间", "DB600.D6")); + list.add(new ItemDto(ItemProtocol.item_production_time, "生产时间", "DB600.D7")); + list.add(new ItemDto(ItemProtocol.item_error_time, "故障时间", "DB600.D8")); + return list; + } + + @Override + public List getWriteableItemDtos() { + return ItemProtocol.getWriteableItemDtos(); + } + +} diff --git a/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_palletizing_manipulator/LnshPalletizingManipulatorDeviceDriver.java b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_palletizing_manipulator/LnshPalletizingManipulatorDeviceDriver.java new file mode 100644 index 0000000..d0ffc16 --- /dev/null +++ b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_palletizing_manipulator/LnshPalletizingManipulatorDeviceDriver.java @@ -0,0 +1,313 @@ +package org.nl.acs.device_driver.lnsh.lnsh_palletizing_manipulator; + +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.IdUtil; +import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSONObject; +import lombok.Data; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.device.device_driver.standard_inspect.ReadUtil; +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.instruction.service.InstructionService; +import org.nl.acs.instruction.service.dto.Instruction; +import org.nl.acs.opc.Device; +import org.nl.acs.opc.WcsConfig; +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.util.CodeUtil; +import org.nl.utils.SpringContextHolder; +import org.nl.wql.core.bean.WQLObject; +import org.openscada.opc.lib.da.Server; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * 晟华码垛机械手 + */ +@Slf4j +@Data +@RequiredArgsConstructor +public class LnshPalletizingManipulatorDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver { + protected ItemProtocol itemProtocol = new ItemProtocol(this); + @Autowired + InstructionService instructionService = SpringContextHolder.getBean("instructionServiceImpl"); + @Autowired + DeviceService deviceservice = SpringContextHolder.getBean("deviceServiceImpl"); + @Autowired + RouteLineService routelineserver = SpringContextHolder.getBean("routeLineServiceImpl"); + @Autowired + TaskService taskserver = SpringContextHolder.getBean("taskServiceImpl"); + String container; + String container_type_desc; + String last_container_type_desc; + String last_container; + //放货准备锁 + String putReadyLock = null; + //有货标记 + protected boolean has_goods_tag = false; + + int mode = 0; + int error = 0; + int last_mode = 0; + int last_error = 0; + Boolean isonline = true; + int hasGoods = 0; + String message = null; + Boolean iserror = false; + + + boolean hasVehicle = false; + boolean isReady = false; + protected int instruction_num = 0; + protected int instruction_num_truth = 0; + boolean isFold = false; + private String assemble_check_tag; + + protected String current_stage_instruction_message; + protected String last_stage_instruction_message; + Integer heartbeat_tag; + private Date instruction_require_time = new Date(); + private Date instruction_finished_time = new Date(); + + private int instruction_require_time_out; + boolean requireSucess = false; + + private int instruction_finished_time_out; + + int branchProtocol = 0; + //备注 + String remark; + //数量 + String qty; + //物料 + String material; + //批次 + String batch; + //当前指令 + Instruction inst = null; + //上次指令 + Instruction last_inst = null; + + //触摸屏手动触发任务 + private Boolean is_has_task = false; + + //申请搬运任务 + private Boolean apply_handling = false; + //申请物料 + private Boolean apply_material = false; + + //暂定 0就绪 1请求取货 2取货完成 3请求放货 4放货完成 5取货完成离开 6放货完成离开 7请求进入区域 8请求离开区域 + int flag; + + String devicecode; + + @Override + public Device getDevice() { + return this.device; + } + + + @Override + public void execute() { + String message = null; + try { + String device_code = this.getDeviceCode(); + mode = this.itemProtocol.getMode(); + + if (mode != last_mode) { + this.setRequireSucess(false); + } + if (error != last_error) { + } + + } catch (Exception var17) { + return; + } + + 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); + message = ""; + Instruction instruction = null; + List toInstructions; + switch (mode) { + case 1: + log.debug("设备运转模式:等待工作"); + return; + case 2: + if (material.length() > 0 && qty.length() > 0 && !requireSucess) { + this.instruction_require(container); + } + } + + switch (flag) { + //取货完成 + case 1: + writing(2); + return; + //放货完成 + case 2: + writing(3); + return; + + } + + } + last_mode = mode; + last_error = error; + + } + + + public boolean exe_error() { + if (this.error == 0) { + return true; + } else { + log.debug("设备报警"); + return false; + } + } + + protected void thingToNothing() { + log.debug("从有货到无货 清理数据"); + this.set_last_container(container, container_type_desc); + } + + public void set_last_container(String barcode, String type_desc) { + this.set_last_container(barcode); + this.set_last_container_type_desc(type_desc); + } + + public void set_last_container(String barcode) { + } + + public void set_last_container_type_desc(String type) { + } + + public boolean exe_business() { + return true; + } + + protected void executing(Instruction instruction) { + this.executing(1, instruction, ""); + } + + public void executing(int command, Instruction instruction, String appendMessage) { + String to_material_code = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + ItemProtocol.item_to_material_code; + if (appendMessage == null) { + appendMessage = ""; + } + if (instruction != null) { + instruction_num = Integer.parseInt(instruction.getInstruction_code()); + } + String opcservcerid = this.getDevice().getOpc_server_id(); + Server server = ReadUtil.getServer(opcservcerid); + Map itemMap = new HashMap(); + ReadUtil.write(itemMap, server); + + } + + public void executing(Server server, Map itemMap) { + ReadUtil.write(itemMap, server); + } + + public void writing(int command) { + + String opcservcerid = this.getDevice().getOpc_server_id(); + Server server = ReadUtil.getServer(opcservcerid); + Map itemMap = new HashMap(); + ReadUtil.write(itemMap, server); + + } + + public void writing(int type, int command) { + String to_material_code = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + ItemProtocol.item_to_material_code; + String opcservcerid = this.getDevice().getOpc_server_id(); + Server server = ReadUtil.getServer(opcservcerid); + Map itemMap = new HashMap(); + if (type == 2) { + itemMap.put(to_material_code, command); + + } + ReadUtil.write(itemMap, server); + + } + + public boolean instruction_require(String container_code) { + return instruction_require(container_code, WcsConfig.task_container_type_default_desc); + } + + /** + * 请求指令 + * + * @param container_code + * @param container_type + */ + public synchronized boolean instruction_require(String container_code, String container_type) { + 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; + TaskDto dto = new TaskDto(); + String now = DateUtil.now(); + dto.setTask_id(IdUtil.simpleUUID()); + dto.setCreate_by(this.getDevice().getDevice_code()); + dto.setUpdate_by(this.getDevice().getDevice_code()); + dto.setStart_point_code(this.getDevice().getDevice_code()); + dto.setVehicle_code(container_code); + dto.setVehicle_type(container_type); + + String taskcode = CodeUtil.getNewCode("TASK_NO"); + dto.setTask_code("-" + taskcode); + dto.setTask_status("0"); + dto.setPriority("101"); + RouteLineDto jo = routelineserver.findByCode(this.getDevice().getDevice_code()); + String next_device_codecode = jo.getNext_device_code(); + if (StrUtil.isEmpty(next_device_codecode)) { + throw new RuntimeException("该设备未找到对应路由"); + } + dto.setNext_point_code(next_device_codecode); + dto.setUpdate_time(now); + dto.setCreate_time(now); + + WQLObject wo = WQLObject.getWQLObject("acs_task"); + JSONObject json = (JSONObject) JSONObject.toJSON(dto); + + wo.insert(json); + requireSucess = false; + return true; + } + } + + +} diff --git a/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_press/ItemProtocol.java b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_press/ItemProtocol.java new file mode 100644 index 0000000..31d244f --- /dev/null +++ b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_press/ItemProtocol.java @@ -0,0 +1,167 @@ +package org.nl.acs.device_driver.lnsh.lnsh_press; + +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_status = "status"; + public static String item_error = "error"; + public static String item_open_time = "open_time"; + public static String item_standby_time = "standby_time "; + public static String item_production_time = "production_time"; + public static String item_error_time = "error_time"; + public static String item_material = "material"; + public static String item_qty = "qty"; + public static String item_weight = "weight"; + public static String item_qualified = "qualified"; + public static String item_unqualified = "unqualified"; + public static String item_order_No = "order_No"; + public static String item_to_command = "to_command"; + public static String item_to_error = "to_error"; + public static String item_to_order_No = "to_order_No"; + public static String item_to_qty = "to_qty"; + public static String item_to_material_code = "to_material_code"; + + + private LnshPressDeviceDriver driver; + + public ItemProtocol(LnshPressDeviceDriver driver) { + this.driver = driver; + } + + public int getHeartbeat() { + return this.getOpcIntegerValue(item_heartbeat); + } + + public int getStatus() { + return this.getOpcIntegerValue(item_status); + } + + public int getMode() { + return this.getOpcIntegerValue(item_mode); + } + + public int getError() { + return this.getOpcIntegerValue(item_error); + } + + public int getOpen_time() { + return this.getOpcIntegerValue(item_open_time); + } + + public int getStandby_time() { + return this.getOpcIntegerValue(item_standby_time); + } + + public int getProduction_time() { + return this.getOpcIntegerValue(item_production_time); + } + + public int getError_time() { + return this.getOpcIntegerValue(item_error_time); + } + + public int getMaterial() { + return this.getOpcIntegerValue(item_material); + } + + public int getQty() { + return this.getOpcIntegerValue(item_qty); + } + + public int getWeight() { + return this.getOpcIntegerValue(item_weight); + } + + public int getQualified() { + return this.getOpcIntegerValue(item_qualified); + } + + public int getUnqualified() { + return this.getOpcIntegerValue(item_unqualified); + } + + public int getOrder_No() { + return this.getOpcIntegerValue(item_order_No); + } + + public int getTo_command() { + return this.getOpcIntegerValue(item_to_command); + } + + public int getTo_error() { + return this.getOpcIntegerValue(item_to_error); + } + + public int getTo_order_No() { + return this.getOpcIntegerValue(item_to_order_No); + } + + public int getTo_qty() { + return this.getOpcIntegerValue(item_to_qty); + } + + public int getTo_material_code() { + return this.getOpcIntegerValue(item_to_material_code); + } + + //是否有货 + public int hasGoods(int move) { + return move; + } + + 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 static List getReadableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_heartbeat, "心跳", "DB600.B0")); + list.add(new ItemDto(item_mode, "工作状态", "DB600.B2", Boolean.valueOf(true))); + list.add(new ItemDto(item_status, "设备状态", "DB600.B3")); + list.add(new ItemDto(item_error, "故障", "DB600.B3")); + list.add(new ItemDto(item_open_time, "开机时间", "DB600.B4")); + list.add(new ItemDto(item_standby_time, "待机时间", "DB600.D6")); + list.add(new ItemDto(item_production_time, "生产时间", "DB600.D7")); + list.add(new ItemDto(item_error_time, "故障时间", "DB600.D8")); + list.add(new ItemDto(item_material, "当前生产物料", "DB600.D9")); + list.add(new ItemDto(item_qty, "当前已生产数量", "DB600.D10")); + list.add(new ItemDto(item_weight, "当前已生产重量", "DB600.D10")); + list.add(new ItemDto(item_qualified, "当前已生产合格数", "DB600.D11")); + list.add(new ItemDto(item_unqualified, "当前已生产不合格数", "DB600.D12")); + list.add(new ItemDto(item_order_No, "工单号", "DB600.D13")); + return list; + } + + public static List getWriteableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_to_command, "反馈", "DB601.W2", Boolean.valueOf(true))); + list.add(new ItemDto(item_to_error, "error", "DB601.W2")); + list.add(new ItemDto(item_to_order_No, "工单号", "DB601.W2")); + list.add(new ItemDto(item_to_qty, "生产重量", "DB601.W2")); + list.add(new ItemDto(item_to_material_code, "下发物料编号", "DB601.W10")); + return list; + } + +} + diff --git a/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_press/LnshPressDefination.java b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_press/LnshPressDefination.java new file mode 100644 index 0000000..0ca16f6 --- /dev/null +++ b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_press/LnshPressDefination.java @@ -0,0 +1,82 @@ +package org.nl.acs.device_driver.lnsh.lnsh_press; + +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.ArrayList; +import java.util.LinkedList; +import java.util.List; + +/** + * 晟华压力机 + * + */ +@Service +public class LnshPressDefination implements OpcDeviceDriverDefination { + @Override + public String getDriverCode() { + return "lnsh_press"; + } + + @Override + public String getDriverName() { + return "晟华-压力机"; + } + + @Override + public String getDriverDescription() { + return "晟华-压力机"; + } + + @Override + public DeviceDriver getDriverInstance(Device device) { + return (new LnshPressDeviceDriver()).setDevice(device).setDriverDefination(this); + + } + + @Override + public Class getDeviceDriverType() { + return LnshPressDeviceDriver.class; + } + + @Override + public List getFitDeviceTypes() { + List types = new LinkedList(); + types.add(DeviceType.conveyor); + return types; + } + + @Override + public List getReadableItemDtos() { + return getReadableItemDtos2(); + } + + public static List getReadableItemDtos2() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(ItemProtocol.item_heartbeat, "心跳", "DB600.B0")); + list.add(new ItemDto(ItemProtocol.item_mode, "工作状态", "DB600.B2", Boolean.valueOf(true))); + list.add(new ItemDto(ItemProtocol.item_status, "设备状态", "DB600.B3")); + list.add(new ItemDto(ItemProtocol.item_error, "故障", "DB600.B3")); + list.add(new ItemDto(ItemProtocol.item_open_time, "开机时间", "DB600.B4")); + list.add(new ItemDto(ItemProtocol.item_standby_time, "待机时间", "DB600.D6")); + list.add(new ItemDto(ItemProtocol.item_production_time, "生产时间", "DB600.D7")); + list.add(new ItemDto(ItemProtocol.item_error_time, "故障时间", "DB600.D8")); + list.add(new ItemDto(ItemProtocol.item_material, "当前生产物料", "DB600.D9")); + list.add(new ItemDto(ItemProtocol.item_qty, "当前已生产数量", "DB600.D10")); + list.add(new ItemDto(ItemProtocol.item_weight, "当前已生产重量", "DB600.D10")); + list.add(new ItemDto(ItemProtocol.item_qualified, "当前已生产合格数", "DB600.D11")); + list.add(new ItemDto(ItemProtocol.item_unqualified, "当前已生产不合格数", "DB600.D12")); + list.add(new ItemDto(ItemProtocol.item_order_No, "工单号", "DB600.D13")); + return list; + } + + @Override + public List getWriteableItemDtos() { + return ItemProtocol.getWriteableItemDtos(); + } + +} diff --git a/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_press/LnshPressDeviceDriver.java b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_press/LnshPressDeviceDriver.java new file mode 100644 index 0000000..12dd35e --- /dev/null +++ b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_press/LnshPressDeviceDriver.java @@ -0,0 +1,313 @@ +package org.nl.acs.device_driver.lnsh.lnsh_press; + +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.IdUtil; +import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSONObject; +import lombok.Data; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.device.device_driver.standard_inspect.ReadUtil; +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.instruction.service.InstructionService; +import org.nl.acs.instruction.service.dto.Instruction; +import org.nl.acs.opc.Device; +import org.nl.acs.opc.WcsConfig; +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.util.CodeUtil; +import org.nl.utils.SpringContextHolder; +import org.nl.wql.core.bean.WQLObject; +import org.openscada.opc.lib.da.Server; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * 晟华压力机 + */ +@Slf4j +@Data +@RequiredArgsConstructor +public class LnshPressDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver { + protected ItemProtocol itemProtocol = new ItemProtocol(this); + @Autowired + InstructionService instructionService = SpringContextHolder.getBean("instructionServiceImpl"); + @Autowired + DeviceService deviceservice = SpringContextHolder.getBean("deviceServiceImpl"); + @Autowired + RouteLineService routelineserver = SpringContextHolder.getBean("routeLineServiceImpl"); + @Autowired + TaskService taskserver = SpringContextHolder.getBean("taskServiceImpl"); + String container; + String container_type_desc; + String last_container_type_desc; + String last_container; + //放货准备锁 + String putReadyLock = null; + //有货标记 + protected boolean has_goods_tag = false; + + int mode = 0; + int error = 0; + int last_mode = 0; + int last_error = 0; + Boolean isonline = true; + int hasGoods = 0; + String message = null; + Boolean iserror = false; + + + boolean hasVehicle = false; + boolean isReady = false; + protected int instruction_num = 0; + protected int instruction_num_truth = 0; + boolean isFold = false; + private String assemble_check_tag; + + protected String current_stage_instruction_message; + protected String last_stage_instruction_message; + Integer heartbeat_tag; + private Date instruction_require_time = new Date(); + private Date instruction_finished_time = new Date(); + + private int instruction_require_time_out; + boolean requireSucess = false; + + private int instruction_finished_time_out; + + int branchProtocol = 0; + //备注 + String remark; + //数量 + String qty; + //物料 + String material; + //批次 + String batch; + //当前指令 + Instruction inst = null; + //上次指令 + Instruction last_inst = null; + + //触摸屏手动触发任务 + private Boolean is_has_task = false; + + //申请搬运任务 + private Boolean apply_handling = false; + //申请物料 + private Boolean apply_material = false; + + //暂定 0就绪 1请求取货 2取货完成 3请求放货 4放货完成 5取货完成离开 6放货完成离开 7请求进入区域 8请求离开区域 + int flag; + + String devicecode; + + @Override + public Device getDevice() { + return this.device; + } + + + @Override + public void execute() { + String message = null; + try { + String device_code = this.getDeviceCode(); + mode = this.itemProtocol.getMode(); + + if (mode != last_mode) { + this.setRequireSucess(false); + } + if (error != last_error) { + } + + } catch (Exception var17) { + return; + } + + 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); + message = ""; + Instruction instruction = null; + List toInstructions; + switch (mode) { + case 1: + log.debug("设备运转模式:等待工作"); + return; + case 2: + if (material.length() > 0 && qty.length() > 0 && !requireSucess) { + this.instruction_require(container); + } + } + + switch (flag) { + //取货完成 + case 1: + writing(2); + return; + //放货完成 + case 2: + writing(3); + return; + + } + + } + last_mode = mode; + last_error = error; + + } + + + public boolean exe_error() { + if (this.error == 0) { + return true; + } else { + log.debug("设备报警"); + return false; + } + } + + protected void thingToNothing() { + log.debug("从有货到无货 清理数据"); + this.set_last_container(container, container_type_desc); + } + + public void set_last_container(String barcode, String type_desc) { + this.set_last_container(barcode); + this.set_last_container_type_desc(type_desc); + } + + public void set_last_container(String barcode) { + } + + public void set_last_container_type_desc(String type) { + } + + public boolean exe_business() { + return true; + } + + protected void executing(Instruction instruction) { + this.executing(1, instruction, ""); + } + + public void executing(int command, Instruction instruction, String appendMessage) { + String to_material_code = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + ItemProtocol.item_to_material_code; + if (appendMessage == null) { + appendMessage = ""; + } + if (instruction != null) { + instruction_num = Integer.parseInt(instruction.getInstruction_code()); + } + String opcservcerid = this.getDevice().getOpc_server_id(); + Server server = ReadUtil.getServer(opcservcerid); + Map itemMap = new HashMap(); + ReadUtil.write(itemMap, server); + + } + + public void executing(Server server, Map itemMap) { + ReadUtil.write(itemMap, server); + } + + public void writing(int command) { + + String opcservcerid = this.getDevice().getOpc_server_id(); + Server server = ReadUtil.getServer(opcservcerid); + Map itemMap = new HashMap(); + ReadUtil.write(itemMap, server); + + } + + public void writing(int type, int command) { + String to_material_code = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + ItemProtocol.item_to_material_code; + String opcservcerid = this.getDevice().getOpc_server_id(); + Server server = ReadUtil.getServer(opcservcerid); + Map itemMap = new HashMap(); + if (type == 2) { + itemMap.put(to_material_code, command); + + } + ReadUtil.write(itemMap, server); + + } + + public boolean instruction_require(String container_code) { + return instruction_require(container_code, WcsConfig.task_container_type_default_desc); + } + + /** + * 请求指令 + * + * @param container_code + * @param container_type + */ + public synchronized boolean instruction_require(String container_code, String container_type) { + 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; + TaskDto dto = new TaskDto(); + String now = DateUtil.now(); + dto.setTask_id(IdUtil.simpleUUID()); + dto.setCreate_by(this.getDevice().getDevice_code()); + dto.setUpdate_by(this.getDevice().getDevice_code()); + dto.setStart_point_code(this.getDevice().getDevice_code()); + dto.setVehicle_code(container_code); + dto.setVehicle_type(container_type); + + String taskcode = CodeUtil.getNewCode("TASK_NO"); + dto.setTask_code("-" + taskcode); + dto.setTask_status("0"); + dto.setPriority("101"); + RouteLineDto jo = routelineserver.findByCode(this.getDevice().getDevice_code()); + String next_device_codecode = jo.getNext_device_code(); + if (StrUtil.isEmpty(next_device_codecode)) { + throw new RuntimeException("该设备未找到对应路由"); + } + dto.setNext_point_code(next_device_codecode); + dto.setUpdate_time(now); + dto.setCreate_time(now); + + WQLObject wo = WQLObject.getWQLObject("acs_task"); + JSONObject json = (JSONObject) JSONObject.toJSON(dto); + + wo.insert(json); + requireSucess = false; + return true; + } + } + + +} diff --git a/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_rgv/ItemProtocol.java b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_rgv/ItemProtocol.java new file mode 100644 index 0000000..8743d75 --- /dev/null +++ b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_rgv/ItemProtocol.java @@ -0,0 +1,178 @@ +package org.nl.acs.device_driver.lnsh.lnsh_rgv; + +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_status = "status"; + public static String item_move_1 = "move_1"; + public static String item_move_2 = "move_2"; + public static String item_action_1 = "action_1"; + public static String item_action_2 = "action_2"; + public static String item_walk_y = "walk_y"; + public static String item_error = "error"; + public static String item_task1 = "task1"; + public static String item_task2 = "task2"; + public static String item_open_time = "open_time"; + public static String item_standby_time = "standby_time "; + public static String item_production_time = "production_time"; + public static String item_error_time = "error_time"; + public static String item_to_command = "to_command"; + public static String item_to_onset1 = "to_onset1"; + public static String item_to_target1 = "to_target1"; + public static String item_to_task = "to_task"; + public static String item_to_onset2 = "to_onset2"; + public static String item_to_target2 = "to_target2"; + + private LnshRGVDeviceDriver driver; + + public ItemProtocol(LnshRGVDeviceDriver driver) { + this.driver = driver; + } + + public int getHeartbeat() { + return this.getOpcIntegerValue(item_heartbeat); + } + + public int getMode() { + return this.getOpcIntegerValue(item_mode); + } + + public int getStatus() { + return this.getOpcIntegerValue(item_status); + } + + public int getError() { + return this.getOpcIntegerValue(item_error); + } + + public int getOpen_time() { + return this.getOpcIntegerValue(item_open_time); + } + + public int getStandby_time() { + return this.getOpcIntegerValue(item_standby_time); + } + + public int getProduction_time() { + return this.getOpcIntegerValue(item_production_time); + } + + public int getError_time() { + return this.getOpcIntegerValue(item_error_time); + } + + public int getMove_1() { + return this.getOpcIntegerValue(item_move_1); + } + + public int getMove_2() { + return this.getOpcIntegerValue(item_move_2); + } + + public int getAction_1() { + return this.getOpcIntegerValue(item_action_1); + } + + public int getAction_2() { + return this.getOpcIntegerValue(item_action_2); + } + + public int getWalk_y() { + return this.getOpcIntegerValue(item_walk_y); + } + + public int getTask1() { + return this.getOpcIntegerValue(item_task1); + } + + public int getTask2() { + return this.getOpcIntegerValue(item_task2); + } + + public int getTo_command() { + return this.getOpcIntegerValue(item_to_command); + } + + public int getTo_onset1() { + return this.getOpcIntegerValue(item_to_onset1); + } + + public int getTo_onset2() { + return this.getOpcIntegerValue(item_to_onset2); + } + + public int getTo_target1() { + return this.getOpcIntegerValue(item_to_target1); + } + + public int getTo_target2() { + return this.getOpcIntegerValue(item_to_target2); + } + + public int getTo_task() { + return this.getOpcIntegerValue(item_to_task); + } + + //是否有货 + public int hasGoods(int move) { + return move; + } + + 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 static List getReadableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_heartbeat, "心跳", "DB600.B0")); + list.add(new ItemDto(item_mode, "工作状态", "DB600.B2", Boolean.valueOf(true))); + list.add(new ItemDto(item_status, "设备状态", "DB600.B3")); + list.add(new ItemDto(item_move_1, "前工位光电信号", "DB600.B3")); + list.add(new ItemDto(item_move_2, "后工位光电信号", "DB600.B3")); + list.add(new ItemDto(item_action_1, "前工位动作信号", "DB600.B3")); + list.add(new ItemDto(item_action_2, "后工位动作信号", "DB600.B3")); + list.add(new ItemDto(item_walk_y, "行走列", "DB600.B3")); + list.add(new ItemDto(item_error, "车体报警", "DB600.B3")); + list.add(new ItemDto(item_task1, "前工位任务号", "DB600.B3")); + list.add(new ItemDto(item_task2, "后工位任务号", "DB600.B3")); + list.add(new ItemDto(item_open_time, "开机时间", "DB600.B4")); + list.add(new ItemDto(item_standby_time, "待机时间", "DB600.D6")); + list.add(new ItemDto(item_production_time, "生产时间", "DB600.D7")); + list.add(new ItemDto(item_error_time, "故障时间", "DB600.D8")); + return list; + } + + public static List getWriteableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_to_command, "下发命令", "DB601.W02")); + list.add(new ItemDto(item_to_onset1, "下发起始站", "DB601.W4")); + list.add(new ItemDto(item_to_target1, "下发目标站", "DB601.W6")); + list.add(new ItemDto(item_to_task, "下发任务号", "DB601.W10")); + list.add(new ItemDto(item_to_onset2, "下发起始站", "DB601.W10")); + list.add(new ItemDto(item_to_target2, "下发目标站", "DB601.W10")); + return list; + } + +} + diff --git a/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_rgv/LnshRGVDefination.java b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_rgv/LnshRGVDefination.java new file mode 100644 index 0000000..35b9731 --- /dev/null +++ b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_rgv/LnshRGVDefination.java @@ -0,0 +1,83 @@ +package org.nl.acs.device_driver.lnsh.lnsh_rgv; + +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.ArrayList; +import java.util.LinkedList; +import java.util.List; + +/** + * 晟华RGV + * + */ +@Service +public class LnshRGVDefination implements OpcDeviceDriverDefination { + @Override + public String getDriverCode() { + return "lnsh_rgv"; + } + + @Override + public String getDriverName() { + return "晟华-RGV"; + } + + @Override + public String getDriverDescription() { + return "晟华-RGV"; + } + + @Override + public DeviceDriver getDriverInstance(Device device) { + return (new LnshRGVDeviceDriver()).setDevice(device).setDriverDefination(this); + + } + + @Override + public Class getDeviceDriverType() { + return LnshRGVDeviceDriver.class; + } + + @Override + public List getFitDeviceTypes() { + List types = new LinkedList(); + types.add(DeviceType.conveyor); + return types; + } + + @Override + public List getReadableItemDtos() { + return getReadableItemDtos2(); + } + + public static List getReadableItemDtos2() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(ItemProtocol.item_heartbeat, "心跳", "DB600.B0")); + list.add(new ItemDto(ItemProtocol.item_mode, "工作状态", "DB600.B2", Boolean.valueOf(true))); + list.add(new ItemDto(ItemProtocol.item_status, "设备状态", "DB600.B3")); + list.add(new ItemDto(ItemProtocol.item_move_1, "前工位光电信号", "DB600.B3")); + list.add(new ItemDto(ItemProtocol.item_move_2, "后工位光电信号", "DB600.B3")); + list.add(new ItemDto(ItemProtocol.item_action_1, "前工位动作信号", "DB600.B3")); + list.add(new ItemDto(ItemProtocol.item_action_2, "后工位动作信号", "DB600.B3")); + list.add(new ItemDto(ItemProtocol.item_walk_y, "行走列", "DB600.B3")); + list.add(new ItemDto(ItemProtocol.item_error, "车体报警", "DB600.B3")); + list.add(new ItemDto(ItemProtocol.item_task1, "前工位任务号", "DB600.B3")); + list.add(new ItemDto(ItemProtocol.item_task2, "后工位任务号", "DB600.B3")); + list.add(new ItemDto(ItemProtocol.item_open_time, "开机时间", "DB600.B4")); + list.add(new ItemDto(ItemProtocol.item_standby_time, "待机时间", "DB600.D6")); + list.add(new ItemDto(ItemProtocol.item_production_time, "生产时间", "DB600.D7")); + list.add(new ItemDto(ItemProtocol.item_error_time, "故障时间", "DB600.D8")); + return list; + } + + @Override + public List getWriteableItemDtos() { + return ItemProtocol.getWriteableItemDtos(); + } + +} diff --git a/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_rgv/LnshRGVDeviceDriver.java b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_rgv/LnshRGVDeviceDriver.java new file mode 100644 index 0000000..d24c366 --- /dev/null +++ b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_rgv/LnshRGVDeviceDriver.java @@ -0,0 +1,305 @@ +package org.nl.acs.device_driver.lnsh.lnsh_rgv; + +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.IdUtil; +import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSONObject; +import lombok.Data; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.device.device_driver.standard_inspect.ReadUtil; +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.instruction.service.InstructionService; +import org.nl.acs.instruction.service.dto.Instruction; +import org.nl.acs.opc.Device; +import org.nl.acs.opc.WcsConfig; +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.util.CodeUtil; +import org.nl.utils.SpringContextHolder; +import org.nl.wql.core.bean.WQLObject; +import org.openscada.opc.lib.da.Server; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * 晟华RGV + */ +@Slf4j +@Data +@RequiredArgsConstructor +public class LnshRGVDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver { + protected ItemProtocol itemProtocol = new ItemProtocol(this); + @Autowired + InstructionService instructionService = SpringContextHolder.getBean("instructionServiceImpl"); + @Autowired + DeviceService deviceservice = SpringContextHolder.getBean("deviceServiceImpl"); + @Autowired + RouteLineService routelineserver = SpringContextHolder.getBean("routeLineServiceImpl"); + @Autowired + TaskService taskserver = SpringContextHolder.getBean("taskServiceImpl"); + String container; + String container_type_desc; + String last_container_type_desc; + String last_container; + //放货准备锁 + String putReadyLock = null; + //有货标记 + protected boolean has_goods_tag = false; + + int mode = 0; + int error = 0; + int last_mode = 0; + int last_error = 0; + Boolean isonline = true; + int hasGoods = 0; + String message = null; + Boolean iserror = false; + + + boolean hasVehicle = false; + boolean isReady = false; + protected int instruction_num = 0; + protected int instruction_num_truth = 0; + boolean isFold = false; + private String assemble_check_tag; + + protected String current_stage_instruction_message; + protected String last_stage_instruction_message; + Integer heartbeat_tag; + private Date instruction_require_time = new Date(); + private Date instruction_finished_time = new Date(); + + private int instruction_require_time_out; + boolean requireSucess = false; + + private int instruction_finished_time_out; + + int branchProtocol = 0; + //备注 + String remark; + //数量 + String qty; + //物料 + String material; + //批次 + String batch; + //当前指令 + Instruction inst = null; + //上次指令 + Instruction last_inst = null; + + //触摸屏手动触发任务 + private Boolean is_has_task = false; + + //申请搬运任务 + private Boolean apply_handling = false; + //申请物料 + private Boolean apply_material = false; + + //暂定 0就绪 1请求取货 2取货完成 3请求放货 4放货完成 5取货完成离开 6放货完成离开 7请求进入区域 8请求离开区域 + int flag; + + String devicecode; + + @Override + public Device getDevice() { + return this.device; + } + + + @Override + public void execute() { + String message = null; + try { + String device_code = this.getDeviceCode(); + mode = this.itemProtocol.getMode(); + + if (mode != last_mode) { + this.setRequireSucess(false); + } + if (error != last_error) { + } + + } catch (Exception var17) { + return; + } + + 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); + message = ""; + Instruction instruction = null; + List toInstructions; + switch (mode) { + case 1: + log.debug("设备运转模式:等待工作"); + return; + case 2: + if (material.length() > 0 && qty.length() > 0 && !requireSucess) { + this.instruction_require(container); + } + } + + switch (flag) { + //取货完成 + case 1: + writing(2); + return; + //放货完成 + case 2: + writing(3); + return; + + } + + } + last_mode = mode; + last_error = error; + + } + + + public boolean exe_error() { + if (this.error == 0) { + return true; + } else { + log.debug("设备报警"); + return false; + } + } + + protected void thingToNothing() { + log.debug("从有货到无货 清理数据"); + this.set_last_container(container, container_type_desc); + } + + public void set_last_container(String barcode, String type_desc) { + this.set_last_container(barcode); + this.set_last_container_type_desc(type_desc); + } + + public void set_last_container(String barcode) { + } + + public void set_last_container_type_desc(String type) { + } + + public boolean exe_business() { + return true; + } + + protected void executing(Instruction instruction) { + this.executing(1, instruction, ""); + } + + public void executing(int command, Instruction instruction, String appendMessage) { + if (appendMessage == null) { + appendMessage = ""; + } + if (instruction != null) { + instruction_num = Integer.parseInt(instruction.getInstruction_code()); + } + String opcservcerid = this.getDevice().getOpc_server_id(); + Server server = ReadUtil.getServer(opcservcerid); + Map itemMap = new HashMap(); + ReadUtil.write(itemMap, server); + + } + + public void executing(Server server, Map itemMap) { + ReadUtil.write(itemMap, server); + } + + public void writing(int command) { + + String opcservcerid = this.getDevice().getOpc_server_id(); + Server server = ReadUtil.getServer(opcservcerid); + Map itemMap = new HashMap(); + ReadUtil.write(itemMap, server); + + } + + public void writing(int type, int command) { + String opcservcerid = this.getDevice().getOpc_server_id(); + Server server = ReadUtil.getServer(opcservcerid); + Map itemMap = new HashMap(); + ReadUtil.write(itemMap, server); + + } + + public boolean instruction_require(String container_code) { + return instruction_require(container_code, WcsConfig.task_container_type_default_desc); + } + + /** + * 请求指令 + * + * @param container_code + * @param container_type + */ + public synchronized boolean instruction_require(String container_code, String container_type) { + 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; + TaskDto dto = new TaskDto(); + String now = DateUtil.now(); + dto.setTask_id(IdUtil.simpleUUID()); + dto.setCreate_by(this.getDevice().getDevice_code()); + dto.setUpdate_by(this.getDevice().getDevice_code()); + dto.setStart_point_code(this.getDevice().getDevice_code()); + dto.setVehicle_code(container_code); + dto.setVehicle_type(container_type); + + String taskcode = CodeUtil.getNewCode("TASK_NO"); + dto.setTask_code("-" + taskcode); + dto.setTask_status("0"); + dto.setPriority("101"); + RouteLineDto jo = routelineserver.findByCode(this.getDevice().getDevice_code()); + String next_device_codecode = jo.getNext_device_code(); + if (StrUtil.isEmpty(next_device_codecode)) { + throw new RuntimeException("该设备未找到对应路由"); + } + dto.setNext_point_code(next_device_codecode); + dto.setUpdate_time(now); + dto.setCreate_time(now); + + WQLObject wo = WQLObject.getWQLObject("acs_task"); + JSONObject json = (JSONObject) JSONObject.toJSON(dto); + + wo.insert(json); + requireSucess = false; + return true; + } + } + + +} diff --git a/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_split_manipulator/ItemProtocol.java b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_split_manipulator/ItemProtocol.java new file mode 100644 index 0000000..cc9f440 --- /dev/null +++ b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_split_manipulator/ItemProtocol.java @@ -0,0 +1,143 @@ +package org.nl.acs.device_driver.lnsh.lnsh_split_manipulator; + +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_error = "error"; + public static String item_getStation = "getStation"; + public static String item_barcode = "barcode"; + public static String item_open_time = "open_time"; + public static String item_standby_time = "standby_time "; + public static String item_production_time = "production_time"; + public static String item_error_time = "error_time"; + public static String item_material = "material"; + public static String item_total_split = "total_split"; + public static String item_to_heartbeat = "to_heartbeat"; + public static String item_to_feedback = "to_feedback"; + public static String item_to_error = "to_error"; + public static String item_to_material = "to_material"; + + + private LnshSplitManipulatorDeviceDriver driver; + + public ItemProtocol(LnshSplitManipulatorDeviceDriver driver) { + this.driver = driver; + } + + public int getHeartbeat() { + return this.getOpcIntegerValue(item_heartbeat); + } + + public int getMode() { + return this.getOpcIntegerValue(item_mode); + } + + public int getError() { + return this.getOpcIntegerValue(item_error); + } + + public int getBarcode() { + return this.getOpcIntegerValue(item_barcode); + } + + public int getOpen_time() { + return this.getOpcIntegerValue(item_open_time); + } + + public int getStandby_time() { + return this.getOpcIntegerValue(item_standby_time); + } + + public int getProduction_time() { + return this.getOpcIntegerValue(item_production_time); + } + + public int getError_time() { + return this.getOpcIntegerValue(item_error_time); + } + + public int getGetStation() { + return this.getOpcIntegerValue(item_getStation); + } + + public int getMaterial() { + return this.getOpcIntegerValue(item_material); + } + + public int getTotal_split() { + return this.getOpcIntegerValue(item_total_split); + } + + public int getTo_heartbeat() { + return this.getOpcIntegerValue(item_to_heartbeat); + } + + public int getTo_feedback() { + return this.getOpcIntegerValue(item_to_feedback); + } + + public int getTo_error() { + return this.getOpcIntegerValue(item_to_error); + } + + public int getTo_material() { + return this.getOpcIntegerValue(item_to_material); + } + + //是否有货 + public int hasGoods(int move) { + return move; + } + + 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 static List getReadableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_heartbeat, "心跳", "DB600.B0")); + list.add(new ItemDto(item_mode, "工作状态", "DB600.B2", Boolean.valueOf(true))); + list.add(new ItemDto(item_error, "故障", "DB600.B3")); + list.add(new ItemDto(item_getStation, "当前抓取工位", "DB600.B3")); + list.add(new ItemDto(item_barcode, "条码", "DB600.B3")); + list.add(new ItemDto(item_open_time, "开机时间", "DB600.B4")); + list.add(new ItemDto(item_standby_time, "待机时间", "DB600.D6")); + list.add(new ItemDto(item_production_time, "生产时间", "DB600.D7")); + list.add(new ItemDto(item_error_time, "故障时间", "DB600.D8")); + list.add(new ItemDto(item_material, "物料", "DB600.D8")); + list.add(new ItemDto(item_total_split, "累计拆垛数量", "DB600.D13")); + return list; + } + + public static List getWriteableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_to_heartbeat, "心跳", "DB601.W10")); + list.add(new ItemDto(item_to_feedback, "机器人动作反馈", "DB601.W10")); + list.add(new ItemDto(item_to_error, "故障代码", "DB601.W10")); + list.add(new ItemDto(item_to_material, "物料", "DB601.W10")); + return list; + } + +} + diff --git a/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_split_manipulator/LnshSplitManipulatorDefination.java b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_split_manipulator/LnshSplitManipulatorDefination.java new file mode 100644 index 0000000..2c6b73c --- /dev/null +++ b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_split_manipulator/LnshSplitManipulatorDefination.java @@ -0,0 +1,79 @@ +package org.nl.acs.device_driver.lnsh.lnsh_split_manipulator; + +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.ArrayList; +import java.util.LinkedList; +import java.util.List; + +/** + * 晟华拆垛机械手 + * + */ +@Service +public class LnshSplitManipulatorDefination implements OpcDeviceDriverDefination { + @Override + public String getDriverCode() { + return "lnsh_split_manipulator"; + } + + @Override + public String getDriverName() { + return "晟华-拆垛机械手"; + } + + @Override + public String getDriverDescription() { + return "晟华-拆垛机械手"; + } + + @Override + public DeviceDriver getDriverInstance(Device device) { + return (new LnshSplitManipulatorDeviceDriver()).setDevice(device).setDriverDefination(this); + + } + + @Override + public Class getDeviceDriverType() { + return LnshSplitManipulatorDeviceDriver.class; + } + + @Override + public List getFitDeviceTypes() { + List types = new LinkedList(); + types.add(DeviceType.conveyor); + return types; + } + + @Override + public List getReadableItemDtos() { + return getReadableItemDtos2(); + } + + public static List getReadableItemDtos2() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(ItemProtocol.item_heartbeat, "心跳", "DB600.B0")); + list.add(new ItemDto(ItemProtocol.item_mode, "工作状态", "DB600.B2", Boolean.valueOf(true))); + list.add(new ItemDto(ItemProtocol.item_error, "故障", "DB600.B3")); + list.add(new ItemDto(ItemProtocol.item_getStation, "当前抓取工位", "DB600.B3")); + list.add(new ItemDto(ItemProtocol.item_barcode, "条码", "DB600.B3")); + list.add(new ItemDto(ItemProtocol.item_open_time, "开机时间", "DB600.B4")); + list.add(new ItemDto(ItemProtocol.item_standby_time, "待机时间", "DB600.D6")); + list.add(new ItemDto(ItemProtocol.item_production_time, "生产时间", "DB600.D7")); + list.add(new ItemDto(ItemProtocol.item_error_time, "故障时间", "DB600.D8")); + list.add(new ItemDto(ItemProtocol.item_material, "物料", "DB600.D8")); + list.add(new ItemDto(ItemProtocol.item_total_split, "累计拆垛数量", "DB600.D13")); + return list; + } + + @Override + public List getWriteableItemDtos() { + return ItemProtocol.getWriteableItemDtos(); + } + +} diff --git a/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_split_manipulator/LnshSplitManipulatorDeviceDriver.java b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_split_manipulator/LnshSplitManipulatorDeviceDriver.java new file mode 100644 index 0000000..97d5c8c --- /dev/null +++ b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_split_manipulator/LnshSplitManipulatorDeviceDriver.java @@ -0,0 +1,305 @@ +package org.nl.acs.device_driver.lnsh.lnsh_split_manipulator; + +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.IdUtil; +import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSONObject; +import lombok.Data; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.device.device_driver.standard_inspect.ReadUtil; +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.instruction.service.InstructionService; +import org.nl.acs.instruction.service.dto.Instruction; +import org.nl.acs.opc.Device; +import org.nl.acs.opc.WcsConfig; +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.util.CodeUtil; +import org.nl.utils.SpringContextHolder; +import org.nl.wql.core.bean.WQLObject; +import org.openscada.opc.lib.da.Server; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * 晟华拆垛机械手 + */ +@Slf4j +@Data +@RequiredArgsConstructor +public class LnshSplitManipulatorDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver { + protected ItemProtocol itemProtocol = new ItemProtocol(this); + @Autowired + InstructionService instructionService = SpringContextHolder.getBean("instructionServiceImpl"); + @Autowired + DeviceService deviceservice = SpringContextHolder.getBean("deviceServiceImpl"); + @Autowired + RouteLineService routelineserver = SpringContextHolder.getBean("routeLineServiceImpl"); + @Autowired + TaskService taskserver = SpringContextHolder.getBean("taskServiceImpl"); + String container; + String container_type_desc; + String last_container_type_desc; + String last_container; + //放货准备锁 + String putReadyLock = null; + //有货标记 + protected boolean has_goods_tag = false; + + int mode = 0; + int error = 0; + int last_mode = 0; + int last_error = 0; + Boolean isonline = true; + int hasGoods = 0; + String message = null; + Boolean iserror = false; + + + boolean hasVehicle = false; + boolean isReady = false; + protected int instruction_num = 0; + protected int instruction_num_truth = 0; + boolean isFold = false; + private String assemble_check_tag; + + protected String current_stage_instruction_message; + protected String last_stage_instruction_message; + Integer heartbeat_tag; + private Date instruction_require_time = new Date(); + private Date instruction_finished_time = new Date(); + + private int instruction_require_time_out; + boolean requireSucess = false; + + private int instruction_finished_time_out; + + int branchProtocol = 0; + //备注 + String remark; + //数量 + String qty; + //物料 + String material; + //批次 + String batch; + //当前指令 + Instruction inst = null; + //上次指令 + Instruction last_inst = null; + + //触摸屏手动触发任务 + private Boolean is_has_task = false; + + //申请搬运任务 + private Boolean apply_handling = false; + //申请物料 + private Boolean apply_material = false; + + //暂定 0就绪 1请求取货 2取货完成 3请求放货 4放货完成 5取货完成离开 6放货完成离开 7请求进入区域 8请求离开区域 + int flag; + + String devicecode; + + @Override + public Device getDevice() { + return this.device; + } + + + @Override + public void execute() { + String message = null; + try { + String device_code = this.getDeviceCode(); + mode = this.itemProtocol.getMode(); + + if (mode != last_mode) { + this.setRequireSucess(false); + } + if (error != last_error) { + } + + } catch (Exception var17) { + return; + } + + 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); + message = ""; + Instruction instruction = null; + List toInstructions; + switch (mode) { + case 1: + log.debug("设备运转模式:等待工作"); + return; + case 2: + if (material.length() > 0 && qty.length() > 0 && !requireSucess) { + this.instruction_require(container); + } + } + + switch (flag) { + //取货完成 + case 1: + writing(2); + return; + //放货完成 + case 2: + writing(3); + return; + + } + + } + last_mode = mode; + last_error = error; + + } + + + public boolean exe_error() { + if (this.error == 0) { + return true; + } else { + log.debug("设备报警"); + return false; + } + } + + protected void thingToNothing() { + log.debug("从有货到无货 清理数据"); + this.set_last_container(container, container_type_desc); + } + + public void set_last_container(String barcode, String type_desc) { + this.set_last_container(barcode); + this.set_last_container_type_desc(type_desc); + } + + public void set_last_container(String barcode) { + } + + public void set_last_container_type_desc(String type) { + } + + public boolean exe_business() { + return true; + } + + protected void executing(Instruction instruction) { + this.executing(1, instruction, ""); + } + + public void executing(int command, Instruction instruction, String appendMessage) { + if (appendMessage == null) { + appendMessage = ""; + } + if (instruction != null) { + instruction_num = Integer.parseInt(instruction.getInstruction_code()); + } + String opcservcerid = this.getDevice().getOpc_server_id(); + Server server = ReadUtil.getServer(opcservcerid); + Map itemMap = new HashMap(); + ReadUtil.write(itemMap, server); + + } + + public void executing(Server server, Map itemMap) { + ReadUtil.write(itemMap, server); + } + + public void writing(int command) { + + String opcservcerid = this.getDevice().getOpc_server_id(); + Server server = ReadUtil.getServer(opcservcerid); + Map itemMap = new HashMap(); + ReadUtil.write(itemMap, server); + + } + + public void writing(int type, int command) { + String opcservcerid = this.getDevice().getOpc_server_id(); + Server server = ReadUtil.getServer(opcservcerid); + Map itemMap = new HashMap(); + ReadUtil.write(itemMap, server); + + } + + public boolean instruction_require(String container_code) { + return instruction_require(container_code, WcsConfig.task_container_type_default_desc); + } + + /** + * 请求指令 + * + * @param container_code + * @param container_type + */ + public synchronized boolean instruction_require(String container_code, String container_type) { + 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; + TaskDto dto = new TaskDto(); + String now = DateUtil.now(); + dto.setTask_id(IdUtil.simpleUUID()); + dto.setCreate_by(this.getDevice().getDevice_code()); + dto.setUpdate_by(this.getDevice().getDevice_code()); + dto.setStart_point_code(this.getDevice().getDevice_code()); + dto.setVehicle_code(container_code); + dto.setVehicle_type(container_type); + + String taskcode = CodeUtil.getNewCode("TASK_NO"); + dto.setTask_code("-" + taskcode); + dto.setTask_status("0"); + dto.setPriority("101"); + RouteLineDto jo = routelineserver.findByCode(this.getDevice().getDevice_code()); + String next_device_codecode = jo.getNext_device_code(); + if (StrUtil.isEmpty(next_device_codecode)) { + throw new RuntimeException("该设备未找到对应路由"); + } + dto.setNext_point_code(next_device_codecode); + dto.setUpdate_time(now); + dto.setCreate_time(now); + + WQLObject wo = WQLObject.getWQLObject("acs_task"); + JSONObject json = (JSONObject) JSONObject.toJSON(dto); + + wo.insert(json); + requireSucess = false; + return true; + } + } + + +} diff --git a/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_station/ItemProtocol.java b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_station/ItemProtocol.java new file mode 100644 index 0000000..b36e1fc --- /dev/null +++ b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_station/ItemProtocol.java @@ -0,0 +1,131 @@ +package org.nl.acs.device_driver.lnsh.lnsh_station; + +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_action = "action"; + public static String item_ioaction = "ioaction"; + public static String item_error = "error"; + public static String item_task = "task"; + public static String item_weight = "weight"; + public static String item_material = "material"; + public static String item_barcode = "barcode"; + public static String item_to_command = "to_command"; + public static String item_to_target = "to_target"; + public static String item_to_task = "to_task"; + + + Boolean isonline; + + private LnshStationDeviceDriver driver; + + public ItemProtocol(LnshStationDeviceDriver 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 getAction() { + return this.getOpcIntegerValue(item_action); + } + + public int getIoAction() { + return this.getOpcIntegerValue(item_ioaction); + } + + public int getError() { + return this.getOpcIntegerValue(item_error); + } + + public int getTask() { + return this.getOpcIntegerValue(item_task); + } + + public int getWeight() { + return this.getOpcIntegerValue(item_weight); + } + + public int getMaterial() { + return this.getOpcIntegerValue(item_material); + } + + public int getBarcode() { + return this.getOpcIntegerValue(item_barcode); + } + + public int getToCommand() { + return this.getOpcIntegerValue(item_to_command); + } + + public int getToTarget() { + return this.getOpcIntegerValue(item_to_target); + } + + public int getToTask() { + return this.getOpcIntegerValue(item_to_task); + } + + //是否有货 + public int hasGoods(int move) { + return move; + } + + + 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 static List getReadableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_heartbeat, "心跳", "DB600.B0")); + list.add(new ItemDto(item_mode, "工作状态", "DB600.B2", Boolean.valueOf(true))); + list.add(new ItemDto(item_move, "光电开关信号", "DB600.B3")); + list.add(new ItemDto(item_action, "取放信号", "DB600.B4")); + list.add(new ItemDto(item_ioaction, "进出信号", "DB600.B5")); + list.add(new ItemDto(item_error, "报警信号", "DB600.B7")); + list.add(new ItemDto(item_task, "任务号", "DB600.D10")); + list.add(new ItemDto(item_weight, "重量", "DB600.D14")); + list.add(new ItemDto(item_material, "物料", "DB600.D18")); + list.add(new ItemDto(item_barcode, "条码", "DB600.D68")); + return list; + } + + public static List getWriteableItemDtos() { + ArrayList list = new ArrayList(); + list.add(new ItemDto(item_to_command, "作业命令", "DB601.W2", Boolean.valueOf(true))); + list.add(new ItemDto(item_to_target, "目标站", "DB601.W4")); + list.add(new ItemDto(item_to_task, "任务号", "DB601.D8")); + return list; + } + +} + diff --git a/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_station/LnshStationDefination.java b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_station/LnshStationDefination.java new file mode 100644 index 0000000..4844194 --- /dev/null +++ b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_station/LnshStationDefination.java @@ -0,0 +1,78 @@ +package org.nl.acs.device_driver.lnsh.lnsh_station; + +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.ArrayList; +import java.util.LinkedList; +import java.util.List; + +/** + * 晟华-工位(交互模板) + * + */ +@Service +public class LnshStationDefination implements OpcDeviceDriverDefination { + @Override + public String getDriverCode() { + return "lnsh_station"; + } + + @Override + public String getDriverName() { + return "晟华-工位(交互模板)"; + } + + @Override + public String getDriverDescription() { + return "晟华-工位(交互模板)"; + } + + @Override + public DeviceDriver getDriverInstance(Device device) { + return (new LnshStationDeviceDriver()).setDevice(device).setDriverDefination(this); + + } + + @Override + public Class getDeviceDriverType() { + return LnshStationDeviceDriver.class; + } + + @Override + public List getFitDeviceTypes() { + List types = new LinkedList(); + types.add(DeviceType.conveyor); + return types; + } + + @Override + public List getReadableItemDtos() { + return getReadableItemDtos2(); + } + + public static List getReadableItemDtos2() { + List list = new ArrayList(); + list.add(new ItemDto(ItemProtocol.item_heartbeat, "心跳", "DB600.B0")); + list.add(new ItemDto(ItemProtocol.item_mode, "工作状态", "DB600.B2", Boolean.valueOf(true))); + list.add(new ItemDto(ItemProtocol.item_move, "光电开关信号", "DB600.B3")); + list.add(new ItemDto(ItemProtocol.item_action, "取放信号", "DB600.B4")); + list.add(new ItemDto(ItemProtocol.item_ioaction, "进出信号", "DB600.B5")); + list.add(new ItemDto(ItemProtocol.item_error, "报警信号", "DB600.B7")); + list.add(new ItemDto(ItemProtocol.item_task, "任务号", "DB600.D10")); + list.add(new ItemDto(ItemProtocol.item_weight, "重量", "DB600.D14")); + list.add(new ItemDto(ItemProtocol.item_material, "物料", "DB600.D18")); + list.add(new ItemDto(ItemProtocol.item_barcode, "条码", "DB600.D68")); + return list; + } + + @Override + public List getWriteableItemDtos() { + return ItemProtocol.getWriteableItemDtos(); + } + +} diff --git a/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_station/LnshStationDeviceDriver.java b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_station/LnshStationDeviceDriver.java new file mode 100644 index 0000000..1a68b92 --- /dev/null +++ b/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_station/LnshStationDeviceDriver.java @@ -0,0 +1,538 @@ +package org.nl.acs.device_driver.lnsh.lnsh_station; + +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.IdUtil; +import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import lombok.Data; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.device.device_driver.standard_inspect.ReadUtil; +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.device_driver.standard_emptypallet_site.StandardEmptyPalletSiteDeviceDriver; +import org.nl.acs.device_driver.standard_inspect_site.StandardInspectSiteDeviceDriver; +import org.nl.acs.instruction.service.InstructionService; +import org.nl.acs.instruction.service.dto.Instruction; +import org.nl.acs.opc.Device; +import org.nl.acs.opc.DeviceAppService; +import org.nl.acs.opc.DeviceAppServiceImpl; +import org.nl.acs.opc.WcsConfig; +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.util.CodeUtil; +import org.nl.utils.SpringContextHolder; +import org.nl.wql.core.bean.WQLObject; +import org.openscada.opc.lib.da.Server; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.*; + +/** + * 晟华-工位(交互模板) + */ +@Slf4j +@Data +@RequiredArgsConstructor +public class LnshStationDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver { + protected ItemProtocol itemProtocol = new ItemProtocol(this); + @Autowired + InstructionService instructionService = SpringContextHolder.getBean("instructionServiceImpl"); + @Autowired + DeviceService deviceservice = SpringContextHolder.getBean("deviceServiceImpl"); + @Autowired + RouteLineService routelineserver = SpringContextHolder.getBean("routeLineServiceImpl"); + @Autowired + TaskService taskserver = SpringContextHolder.getBean("taskServiceImpl"); + String container; + String container_type_desc; + String last_container_type_desc; + String last_container; + //放货准备锁 + String putReadyLock = null; + //有货标记 + protected boolean has_goods_tag = false; + String devicecode; + int mode = 0; + int error = 0; + int move = 0; + int actoin; + int io_action; + int task = 0; + int last_mode = 0; + int last_error = 0; + int last_move = 0; + int last_task = 0; + Boolean isonline = true; + int hasGoods = 0; + Boolean iserror = false; + + boolean hasVehicle = false; + boolean isReady = false; + protected int instruction_num = 0; + protected int instruction_num_truth = 0; + boolean isFold = false; + private String assemble_check_tag; + private Boolean sampleMode0; + private Boolean sampleMode3; + private Integer sampleError; + private Boolean sampleOnline; + protected String displayMessage = null; + public int display_message_time_out = 30000; + public Date display_message_time; + protected String current_stage_instruction_message; + protected String last_stage_instruction_message; + Integer heartbeat_tag; + private Date instruction_require_time = new Date(); + private Date instruction_finished_time = new Date(); + + private int instruction_require_time_out = 3000; + boolean requireSucess = false; + + private int instruction_finished_time_out; + + int heartbeat; + int last_heartbeat; + private Date checkHeartbeattime = new Date(); + private Date last_checkHeartbeattime = new Date(); + + + int branchProtocol = 0; + //当前指令 + Instruction inst = null; + //上次指令 + Instruction last_inst = null; + + //触摸屏手动触发任务 + private Boolean is_has_task = false; + + String message; + + @Override + public Device getDevice() { + return this.device; + } + + + @Override + public void execute() { + String message = null; + try { + String device_code = this.getDeviceCode(); + + mode = this.itemProtocol.getMode(); + error = this.itemProtocol.getError(); + move = this.itemProtocol.getMove(); + task = this.itemProtocol.getTask(); + hasGoods = this.itemProtocol.getMove(); + io_action = this.itemProtocol.getIoAction(); + actoin = this.itemProtocol.getAction(); + + if (mode != last_mode) { + this.setRequireSucess(false); + } + if (move != last_move) { + if (move == 0) { + thingToNothing(); + } + } + if (error != last_error) { + } + + } catch (Exception var17) { + return; + } + + //急停 + if (this.isStop()) { + + //未在线无心跳 + } else 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); + message = ""; + Instruction instruction = null; + List toInstructions; + switch (mode) { + case 1: + log.debug("设备运转模式:等待工作"); + break; + case 2: + break; + case 3: + //申请空盘 + if (!requireSucess && this.move == 0) { + applyEmpty(); + } + break; + case 4: + //申请搬运任务 + if (!requireSucess && this.move != 0) { + autoCreateTask(); + } + break; + case 5: + break; + } + } + + last_mode = mode; + last_error = error; + last_move = move; + last_task = task; + } + + /** + * 生成搬运任务 + * + * @return + */ + public synchronized boolean autoCreateTask() { + 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; + TaskDto dto = new TaskDto(); + String now = DateUtil.now(); + dto.setTask_id(IdUtil.simpleUUID()); + dto.setCreate_by(this.getDevice().getDevice_code()); + dto.setUpdate_by(this.getDevice().getDevice_code()); + dto.setStart_point_code(this.getDevice().getDevice_code()); + dto.setStart_device_code(this.getDevice().getDevice_code()); + dto.setTask_status("0"); + dto.setPriority("101"); + String next_device_code = ""; + + String plan_uuid = WQLObject.getWQLObject("acs_route_plan").query("plan_code= '" + dto.getRoute_plan_code() + "'").uniqueResult(0).getString("plan_uuid"); + JSONArray ja = routelineserver.queryNextLine(this.getDevice().getDevice_code(), plan_uuid); + DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); + for (int i = 0; i < ja.size(); i++) { + JSONObject jo = (JSONObject) ja.get(i); + next_device_code = jo.get("next_device_code").toString(); + Device nextdevice = appService.findDeviceByCode(next_device_code); + StandardInspectSiteDeviceDriver standardInspectSiteDeviceDriver; + if (nextdevice.getDeviceDriver() instanceof StandardInspectSiteDeviceDriver) { + standardInspectSiteDeviceDriver = (StandardInspectSiteDeviceDriver) nextdevice.getDeviceDriver(); + String maxTaskNum = WQLObject.getWQLObject("sys_param").query("code= 'onePointMaxTask' and is_active='1' ").uniqueResult(0).getString("value"); + + if (taskserver.checkAllowCreate(next_device_code) >= Integer.parseInt(maxTaskNum)) { + next_device_code = ""; + continue; + } + if (standardInspectSiteDeviceDriver.getMode() == 2 && standardInspectSiteDeviceDriver.getMove() == 0) { + break; + } + } + } + if (StrUtil.isEmpty(next_device_code)) { + throw new RuntimeException("该设备未找到对应路由"); + } + dto.setNext_point_code(next_device_code); + dto.setNext_device_code(next_device_code); + dto.setUpdate_time(now); + dto.setCreate_time(now); + String taskcode = CodeUtil.getNewCode("TASK_NO"); + dto.setTask_code("-" + taskcode); + try { + taskserver.create(dto); + } catch (Exception e) { + e.printStackTrace(); + } + this.setRequireSucess(true); + return true; + } + + } + + + public synchronized boolean applyEmpty() { + + 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; + TaskDto dto = new TaskDto(); + String now = DateUtil.now(); + dto.setTask_id(IdUtil.simpleUUID()); + dto.setCreate_by(this.getDevice().getDevice_code()); + dto.setUpdate_by(this.getDevice().getDevice_code()); + dto.setTask_status("0"); + dto.setPriority("101"); + String start_device_code = ""; + String plan_uuid = WQLObject.getWQLObject("acs_route_plan").query("plan_code= '" + dto.getRoute_plan_code() + "'").uniqueResult(0).getString("plan_uuid"); + + JSONArray ja = routelineserver.querySuperiorLine(this.getDevice().getDevice_code(), plan_uuid); + DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); + for (int i = 0; i < ja.size(); i++) { + JSONObject jo = (JSONObject) ja.get(i); + start_device_code = jo.get("device_code").toString(); + Device start_device = appService.findDeviceByCode(start_device_code); + StandardEmptyPalletSiteDeviceDriver standardEmptyPalletSiteDeviceDriver; + if (start_device.getDeviceDriver() instanceof StandardEmptyPalletSiteDeviceDriver) { + standardEmptyPalletSiteDeviceDriver = (StandardEmptyPalletSiteDeviceDriver) start_device.getDeviceDriver(); + //根据路由 寻找取空盘的设备 +// if(standardEmptyPalletSiteDeviceDriver.getNumber() < Integer.parseInt(standardEmptyPalletSiteDeviceDriver.getDevice().getExtraValue().get("max_emptypalletnum").toString()) ) { +// break; +// } + if (standardEmptyPalletSiteDeviceDriver.getMode() == 2 && standardEmptyPalletSiteDeviceDriver.getNumber() > 0) { + break; + } + } + } + dto.setTask_type("1"); + dto.setEmptypallet_num("1"); + dto.setNext_device_code(this.getDevice().getDevice_code()); + dto.setNext_point_code(this.getDevice().getDevice_code()); + dto.setStart_point_code(start_device_code); + dto.setStart_device_code(start_device_code); + if (StrUtil.isEmpty(start_device_code)) { + throw new RuntimeException("该设备未找到对应路由"); + } + dto.setUpdate_time(now); + dto.setCreate_time(now); + String taskcode = CodeUtil.getNewCode("TASK_NO"); + dto.setTask_code("-" + taskcode); + try { + taskserver.create(dto); + } catch (Exception e) { + e.printStackTrace(); + } + this.setRequireSucess(true); + this.setBranchProtocol(0); + return true; + } + } + + public void finish_instruction(Instruction instruction) throws Exception { + instruction_finished(instruction); + } + + /** + * 完成指令 + * + * @param instruction + * @return + */ + public boolean instruction_finished(Instruction instruction) throws Exception { + Date date = new Date(); + if (date.getTime() - this.instruction_finished_time.getTime() < (long) this.instruction_finished_time_out) { + log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_finished_time_out); + return false; + } else { + instructionService.finish(instruction.getInstruction_id()); + this.instruction_finished_time = date; + return true; + } + } + + /** + * 完成并创建下一条指令 + * + * @param instruction + * @param needCreateNext + * @return + */ + public boolean instruction_finished(Instruction instruction, boolean needCreateNext) { + Date date = new Date(); + if (date.getTime() - this.instruction_finished_time.getTime() < (long) this.instruction_finished_time_out) { + log.trace("触发时间因为小于{}毫秒,而被无视", this.instruction_finished_time_out); + return false; + } else { + this.instruction_finished_time = date; + return true; + } + } + + + private Instruction findInstruction() { + Instruction instruction = null; + if (this.instruction_num != 0) { + instruction = (Instruction) instructionService.findByCodeFromCache(String.valueOf(instruction_num)); + } + if (instruction != null) { + //可进行校验 + + + } else { + List container_instructions = new ArrayList(); + String barcode = this.getLast_container(); + + if (!StrUtil.isEmpty(barcode)) { + Map map = new HashMap(); + map.put("vehicle_code", barcode); + container_instructions = instructionService.queryAll(map); + } + + if (((List) container_instructions).size() > 1) { + log.debug("容器存在多个指令"); + } else { + if (((List) container_instructions).size() > 0) { + instruction = (Instruction) ((List) container_instructions).get(0); + } + } + } + return instruction; + } + + + public boolean exe_error() { + if (this.error == 0) { + return true; + } else { + log.debug("设备报警"); + return false; + } + } + + protected void thingToNothing() { + log.debug("从有货到无货 清理数据"); + this.set_last_container(container, container_type_desc); + this.setRequireSucess(false); + } + + public void set_last_container(String barcode, String type_desc) { + this.set_last_container(barcode); + this.set_last_container_type_desc(type_desc); + } + + public void set_last_container(String barcode) { + } + + public void set_last_container_type_desc(String type) { + } + + public boolean exe_business() { + return true; + } + + protected void executing(Instruction instruction) { + this.executing(1, instruction, ""); + } + + public void executing(int command, Instruction instruction, String appendMessage) { + String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + ItemProtocol.item_to_command; + String to_target = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + ItemProtocol.item_to_target; + String to_task = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + ItemProtocol.item_to_task; + if (appendMessage == null) { + appendMessage = ""; + } + if (instruction != null) { + instruction_num = Integer.parseInt(instruction.getInstruction_code()); + } + String opcservcerid = this.getDevice().getOpc_server_id(); + Server server = ReadUtil.getServer(opcservcerid); + Map itemMap = new HashMap(); + itemMap.put(to_command, 1); + itemMap.put(to_task, instruction_num); + ReadUtil.write(itemMap, server); + + } + + public void executing(Server server, Map itemMap) { + ReadUtil.write(itemMap, server); + } + + + public boolean instruction_require(String container_code) { + return instruction_require(container_code, WcsConfig.task_container_type_default_desc); + } + + /** + * 请求指令 + * + * @param container_code + * @param container_type + */ + public synchronized boolean instruction_require(String container_code, String container_type) { + 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; + TaskDto dto = new TaskDto(); + String now = DateUtil.now(); + dto.setTask_id(IdUtil.simpleUUID()); + dto.setCreate_by(this.getDevice().getDevice_code()); + dto.setUpdate_by(this.getDevice().getDevice_code()); + dto.setStart_point_code(this.getDevice().getDevice_code()); + dto.setVehicle_code(container_code); + dto.setVehicle_type(container_type); + + String taskcode = CodeUtil.getNewCode("TASK_NO"); + dto.setTask_code("-" + taskcode); + dto.setTask_status("0"); + dto.setPriority("101"); + RouteLineDto jo = routelineserver.findByCode(this.getDevice().getDevice_code()); + String next_device_codecode = jo.getNext_device_code(); + if (StrUtil.isEmpty(next_device_codecode)) { + throw new RuntimeException("该设备未找到对应路由"); + } + dto.setNext_point_code(next_device_codecode); + dto.setUpdate_time(now); + dto.setCreate_time(now); + + WQLObject wo = WQLObject.getWQLObject("acs_task"); + JSONObject json = (JSONObject) JSONObject.toJSON(dto); + + wo.insert(json); + requireSucess = false; + return true; + } + } + + public void writing(int type, int command) { + String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + ItemProtocol.item_to_command; + String to_target = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + ItemProtocol.item_to_target; + String to_task = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + + "." + ItemProtocol.item_to_task; + String opcservcerid = this.getDevice().getOpc_server_id(); + Server server = ReadUtil.getServer(opcservcerid); + Map itemMap = new HashMap(); + if (type == 1) { + itemMap.put(to_command, command); + } else if (type == 2) { + itemMap.put(to_target, command); + + } else if (type == 3) { + itemMap.put(to_task, command); + } + ReadUtil.write(itemMap, server); + + } + + public String toString() { + return ""; + } + +} diff --git a/nladmin-system/src/main/java/org/nl/acs/device_driver/standard_conveyor_control_with_plcscanner/StandardCoveyorControlWithPlcScannerDeviceDriver.java b/nladmin-system/src/main/java/org/nl/acs/device_driver/standard_conveyor_control_with_plcscanner/StandardCoveyorControlWithPlcScannerDeviceDriver.java index 97f2894..e698d37 100644 --- a/nladmin-system/src/main/java/org/nl/acs/device_driver/standard_conveyor_control_with_plcscanner/StandardCoveyorControlWithPlcScannerDeviceDriver.java +++ b/nladmin-system/src/main/java/org/nl/acs/device_driver/standard_conveyor_control_with_plcscanner/StandardCoveyorControlWithPlcScannerDeviceDriver.java @@ -638,8 +638,8 @@ public class StandardCoveyorControlWithPlcScannerDeviceDriver extends AbstractOp /** * 开始平均分配 */ - String this_coevice_code = taskserver.queryAssignedByDevice(device_code, task.getNext_device_code()); - if (StrUtil.isEmpty(this_coevice_code)) { + String this_device_code = taskserver.queryAssignedByDevice(device_code, task.getNext_device_code()); + if (StrUtil.isEmpty(this_device_code)) { List shortPathsList = routeLineService.getShortPathLines(start_device_code, task.getNext_device_code(), route_plan_code); RouteLineDto routeLineDto = shortPathsList.get(0); @@ -659,7 +659,7 @@ public class StandardCoveyorControlWithPlcScannerDeviceDriver extends AbstractOp } next_device_code = pathlist.get(index); } else { - next_device_code = this_coevice_code; + next_device_code = this_device_code; } //校验路由关系 List shortPathsList = routeLineService.getShortPathLines(start_device_code, next_device_code, route_plan_code); @@ -744,8 +744,8 @@ public class StandardCoveyorControlWithPlcScannerDeviceDriver extends AbstractOp /** * 开始平均分配 */ - String this_coevice_code = taskserver.queryAssignedByDevice(device_code, task.getNext_device_code()); - if (StrUtil.isEmpty(this_coevice_code)) { + String this_device_code = taskserver.queryAssignedByDevice(device_code, task.getNext_device_code()); + if (StrUtil.isEmpty(this_device_code)) { List shortPathsList = routeLineService.getShortPathLines(start_device_code, task.getNext_device_code(), route_plan_code); RouteLineDto routeLineDto = shortPathsList.get(0); @@ -765,7 +765,7 @@ public class StandardCoveyorControlWithPlcScannerDeviceDriver extends AbstractOp } next_device_code = pathlist.get(index); } else { - next_device_code = this_coevice_code; + next_device_code = this_device_code; } //校验路由关系 List shortPathsList = routeLineService.getShortPathLines(start_device_code, next_device_code, route_plan_code); diff --git a/nladmin-system/src/main/java/org/nl/acs/device_driver/standard_conveyor_control_with_scanner/StandardCoveyorControlWithScannerDeviceDriver.java b/nladmin-system/src/main/java/org/nl/acs/device_driver/standard_conveyor_control_with_scanner/StandardCoveyorControlWithScannerDeviceDriver.java index e84c85e..ee9b37f 100644 --- a/nladmin-system/src/main/java/org/nl/acs/device_driver/standard_conveyor_control_with_scanner/StandardCoveyorControlWithScannerDeviceDriver.java +++ b/nladmin-system/src/main/java/org/nl/acs/device_driver/standard_conveyor_control_with_scanner/StandardCoveyorControlWithScannerDeviceDriver.java @@ -458,8 +458,8 @@ public class StandardCoveyorControlWithScannerDeviceDriver extends AbstractOpcDe /** * 开始平均分配 */ - String this_coevice_code = taskserver.queryAssignedByDevice(device_code, task.getNext_device_code()); - if (StrUtil.isEmpty(this_coevice_code)) { + String this_device_code = taskserver.queryAssignedByDevice(device_code, task.getNext_device_code()); + if (StrUtil.isEmpty(this_device_code)) { List shortPathsList = routeLineService.getShortPathLines(start_device_code, task.getNext_device_code(), route_plan_code); RouteLineDto routeLineDto = shortPathsList.get(0); @@ -479,7 +479,7 @@ public class StandardCoveyorControlWithScannerDeviceDriver extends AbstractOpcDe } next_device_code = pathlist.get(index); } else { - next_device_code = this_coevice_code; + next_device_code = this_device_code; } //校验路由关系 List shortPathsList = routeLineService.getShortPathLines(start_device_code, next_device_code, route_plan_code); @@ -562,8 +562,8 @@ public class StandardCoveyorControlWithScannerDeviceDriver extends AbstractOpcDe /** * 开始平均分配 */ - String this_coevice_code = taskserver.queryAssignedByDevice(device_code, task.getNext_device_code()); - if (StrUtil.isEmpty(this_coevice_code)) { + String this_device_code = taskserver.queryAssignedByDevice(device_code, task.getNext_device_code()); + if (StrUtil.isEmpty(this_device_code)) { List shortPathsList = routeLineService.getShortPathLines(start_device_code, task.getNext_device_code(), route_plan_code); RouteLineDto routeLineDto = shortPathsList.get(0); @@ -583,7 +583,7 @@ public class StandardCoveyorControlWithScannerDeviceDriver extends AbstractOpcDe } next_device_code = pathlist.get(index); } else { - next_device_code = this_coevice_code; + next_device_code = this_device_code; } //校验路由关系 List shortPathsList = routeLineService.getShortPathLines(start_device_code, next_device_code, route_plan_code); diff --git a/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/WmsToAcsServiceImpl.java b/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/WmsToAcsServiceImpl.java index 0d93474..71c9eeb 100644 --- a/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/WmsToAcsServiceImpl.java +++ b/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/WmsToAcsServiceImpl.java @@ -68,7 +68,7 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { JSONArray errArr = new JSONArray(); for (int i = 0; i < tasks.size(); i++) { JSONObject task = tasks.getJSONObject(i); - String task_uuid = task.getString("task_uuid"); + String ext_task_uuid = task.getString("task_uuid"); String task_code = task.getString("task_code"); String start_point_code = task.getString("start_device_code"); String next_point_code = task.getString("next_device_code"); @@ -83,6 +83,9 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { if (StrUtil.isEmpty(next_point_code)) { throw new WDKException("终点不能为空"); } + if (StrUtil.isEmpty(ext_task_uuid)) { + throw new WDKException("外部系统标识不能为空"); + } JSONObject start_device_json = WQLObject.getWQLObject("acs_storage_cell").query("parent_storage_code ='" + start_point_code + "'").uniqueResult(0); if (!ObjectUtil.isEmpty(start_device_json)) { @@ -134,6 +137,7 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { } JSONObject jo = new JSONObject(); jo.put("task_code", task_code); + jo.put("ext_task_uuid", ext_task_uuid); jo.put("start_point_code", start_point_code); jo.put("next_point_code", next_point_code); jo.put("start_parent_code", start_point_code); @@ -146,9 +150,6 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { jo.put("remark", remark); jo.put("params", params); jo.put("task_type", StrUtil.isEmpty(task_type) ? 1 : Integer.parseInt(task_type)); - if (!StrUtil.isEmpty(task_uuid)) { - jo.put("task_id", task_uuid); - } // 如果是无光电的设备 指令完成变更起点、终点状态 JSONObject startjo = new JSONObject(); startjo.put("device_code", start_device_code); @@ -172,7 +173,7 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { e.printStackTrace(); JSONObject json = new JSONObject(); json.put("task_code", task_code); - json.put("task_uuid", task_uuid); + json.put("task_uuid", ext_task_uuid); json.put("message", e.getMessage()); errArr.add(json); } diff --git a/nladmin-system/src/main/java/org/nl/acs/instruction/rest/InstructionController.java b/nladmin-system/src/main/java/org/nl/acs/instruction/rest/InstructionController.java index c18ed84..b6dec60 100644 --- a/nladmin-system/src/main/java/org/nl/acs/instruction/rest/InstructionController.java +++ b/nladmin-system/src/main/java/org/nl/acs/instruction/rest/InstructionController.java @@ -48,6 +48,15 @@ public class InstructionController { return new ResponseEntity<>(instructionService.getAll(whereJson, page), HttpStatus.OK); } + @GetMapping("/reload") + @Log("数据同步") + @ApiOperation("数据同步") + //@PreAuthorize("@el.check('task:list')") + public ResponseEntity reload() { + instructionService.reload(); + return new ResponseEntity<>(HttpStatus.OK); + } + @GetMapping("/unfinish") @Log("查询所有未完成指令") @ApiOperation("查询所有未完成指令") diff --git a/nladmin-system/src/main/java/org/nl/acs/instruction/service/InstructionService.java b/nladmin-system/src/main/java/org/nl/acs/instruction/service/InstructionService.java index 2daaaf2..3342ef3 100644 --- a/nladmin-system/src/main/java/org/nl/acs/instruction/service/InstructionService.java +++ b/nladmin-system/src/main/java/org/nl/acs/instruction/service/InstructionService.java @@ -33,6 +33,11 @@ public interface InstructionService { */ Map getAll(Map whereJson, Pageable page); + /** + * 数据同步 + */ + void reload(); + /** * 查询指定任务的所有指令不分页 * diff --git a/nladmin-system/src/main/java/org/nl/acs/log/rest/LogsController.java b/nladmin-system/src/main/java/org/nl/acs/log/rest/LogsController.java index 481c96a..96de472 100644 --- a/nladmin-system/src/main/java/org/nl/acs/log/rest/LogsController.java +++ b/nladmin-system/src/main/java/org/nl/acs/log/rest/LogsController.java @@ -1,4 +1,3 @@ - package org.nl.acs.log.rest; @@ -17,6 +16,7 @@ import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletResponse; import java.io.IOException; +import java.text.ParseException; import java.util.Map; /** @@ -36,8 +36,8 @@ public class LogsController { @Log("查询日志") @ApiOperation("查询日志") //@PreAuthorize("@el.check('log:list')") - public ResponseEntity query(@RequestParam Map whereJson, Pageable page) { + public ResponseEntity query(@RequestParam Map whereJson, Pageable page) throws ParseException { return new ResponseEntity<>(logService.queryAll(whereJson, page), HttpStatus.OK); } - } + diff --git a/nladmin-system/src/main/java/org/nl/acs/log/service/LogServer.java b/nladmin-system/src/main/java/org/nl/acs/log/service/LogServer.java index a7facbe..52ea2ae 100644 --- a/nladmin-system/src/main/java/org/nl/acs/log/service/LogServer.java +++ b/nladmin-system/src/main/java/org/nl/acs/log/service/LogServer.java @@ -1,11 +1,13 @@ package org.nl.acs.log.service; +import com.alibaba.fastjson.JSONObject; import org.nl.acs.log.service.dto.LogDto; import org.springframework.data.domain.Pageable; import javax.servlet.http.HttpServletResponse; import java.io.IOException; +import java.text.ParseException; import java.util.List; import java.util.Map; @@ -23,25 +25,7 @@ public interface LogServer { * @param page 分页参数 * @return Map */ - Object queryAll(Map whereJson, Pageable page); - - - /** - * 根据ID查询 - * - * @param log_uuid ID - * @return Log - */ - LogDto findById(String log_uuid); - - /** - * 根据编码查询 - * - * @param code code - * @return Log - */ - LogDto findByCode(String code); - + Object queryAll(Map whereJson, Pageable page) throws ParseException; /** * @param task_code 任务编码 diff --git a/nladmin-system/src/main/java/org/nl/acs/log/service/impl/LogServerImpl.java b/nladmin-system/src/main/java/org/nl/acs/log/service/impl/LogServerImpl.java index 487c67a..ba92ed3 100644 --- a/nladmin-system/src/main/java/org/nl/acs/log/service/impl/LogServerImpl.java +++ b/nladmin-system/src/main/java/org/nl/acs/log/service/impl/LogServerImpl.java @@ -45,36 +45,29 @@ public class LogServerImpl implements LogServer { @Autowired private MongoTemplate mongoTemplate; -// @Override -// public Object queryAll(Map whereJson, Pageable page) { -// String task_code = MapUtil.getStr(whereJson, "task_code"); -// HashMap map = new HashMap<>(); -// map.put("flag", "1"); -// if (whereJson.get("blurry") != null) { -// map.put("blurry", "%" + whereJson.get("blurry") + "%"); -// } -// map.put("task_code", task_code); -// WO wo = WQL.getWO("Qlog_query_001"); -// JSONObject json = wo.addParamMap(map).pageQuery(WqlUtil.getHttpContext(page), "create_time desc"); -// Object parse = com.alibaba.fastjson.JSONObject.parse(json.toString()); -// return parse; -// } - @Override - public Map queryAll(Map whereJson, Pageable page) { - String log_type = (String) whereJson.get("log_type"); - if (StrUtil.isEmpty(log_type)) { - log_type = "default"; + public Object queryAll(Map whereJson, Pageable page) { + String blurry = (String) whereJson.get("blurry"); + String begin_time = (String) whereJson.get("begin_time"); + String end_time = (String) whereJson.get("end_time"); + + Query query = new Query().with(Sort.by("create_time")); + + if (StrUtil.isNotEmpty(blurry)) { + query.addCriteria(Criteria.where("method").is(blurry).regex("^.*" + blurry + ".*$")); + } + if (StrUtil.isNotEmpty(begin_time) && StrUtil.isNotEmpty(end_time)) { + query.addCriteria(Criteria.where("create_time") + .gte(begin_time) + .lte(end_time)); } - //查询条件 - Query query = Query.query(Criteria.where("source").is("nlAdmin")).with(Sort.by("date")); //根据条件得到的总条数 - long totalSize = mongoTemplate.count(query, Map.class, log_type); + long totalSize = mongoTemplate.count(query, LogDto.class,"interface_log"); //处理分页 query.skip(page.getPageNumber()).limit(page.getPageSize()); - List list = mongoTemplate.find(query,Map.class, log_type); + List list = mongoTemplate.find(query,LogDto.class, "interface_log"); //封装前端分页查询结果 JSONObject result = new JSONObject(); @@ -83,29 +76,12 @@ public class LogServerImpl implements LogServer { return result; } - @Override - public LogDto findById(String log_uuid) { - WQLObject wo = WQLObject.getWQLObject("acs_log"); - JSONObject json = wo.query("log_uuid ='" + log_uuid + "'").uniqueResult(0); - final LogDto obj = json.toJavaObject(LogDto.class); - return obj; - } - - @Override - public LogDto findByCode(String code) { - WQLObject wo = WQLObject.getWQLObject("acs_log"); - JSONObject json = wo.query("code ='" + code + "'").uniqueResult(0); - final LogDto obj = json.toJavaObject(LogDto.class); - return obj; - } - @Override public void log(String task_code, String method, String type, String requestParam, String responseParam, String status_code, String requesturl, String vehicle_code) { String currentUsername = SecurityUtils.getCurrentUsername(); String now = DateUtil.now(); LogDto logDto = new LogDto(); - logDto.setLog_uuid(IdUtil.simpleUUID()); logDto.setTask_code(task_code); logDto.setMethod(method); logDto.setLog_type(type); @@ -120,9 +96,6 @@ public class LogServerImpl implements LogServer { logDto.setUpdate_time(now); logDto.setCreate_time(now); - WQLObject wo = WQLObject.getWQLObject("acs_log"); - - JSONObject json = (JSONObject) JSONObject.toJSON(logDto); - wo.insert(json); + mongoTemplate.save(logDto,"interface_log"); } } diff --git a/nladmin-system/src/main/java/org/nl/acs/order/rest/CustomerbaseController.java b/nladmin-system/src/main/java/org/nl/acs/order/rest/CustomerbaseController.java new file mode 100644 index 0000000..d12e317 --- /dev/null +++ b/nladmin-system/src/main/java/org/nl/acs/order/rest/CustomerbaseController.java @@ -0,0 +1,75 @@ + +package org.nl.acs.order.rest; + + +import org.nl.acs.order.service.CustomerbaseService; +import org.nl.acs.order.service.dto.CustomerbaseDto; +import org.springframework.data.domain.Pageable; +import lombok.RequiredArgsConstructor; +import org.nl.annotation.Log; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; +import io.swagger.annotations.*; +import java.io.IOException; +import javax.servlet.http.HttpServletResponse; +import java.util.Map; +import lombok.extern.slf4j.Slf4j; + +/** +* @author wangs +* @date 2022-03-31 +**/ +@RestController +@RequiredArgsConstructor +@Api(tags = "order管理") +@RequestMapping("/api/customerbase") +@Slf4j +public class CustomerbaseController { + + private final CustomerbaseService customerbaseService; + + @GetMapping + @Log("查询order") + @ApiOperation("查询order") + //@PreAuthorize("@el.check('customerbase:list')") + public ResponseEntity query(@RequestParam Map whereJson, Pageable page){ + return new ResponseEntity<>(customerbaseService.queryAll(whereJson,page),HttpStatus.OK); + } + + @PostMapping + @Log("新增order") + @ApiOperation("新增order") + //@PreAuthorize("@el.check('customerbase:add')") + public ResponseEntity create(@Validated @RequestBody CustomerbaseDto dto){ + customerbaseService.create(dto); + return new ResponseEntity<>(HttpStatus.CREATED); + } + + @PutMapping + @Log("修改order") + @ApiOperation("修改order") + //@PreAuthorize("@el.check('customerbase:edit')") + public ResponseEntity update(@Validated @RequestBody CustomerbaseDto dto){ + customerbaseService.update(dto); + return new ResponseEntity<>(HttpStatus.NO_CONTENT); + } + + @Log("删除order") + @ApiOperation("删除order") + //@PreAuthorize("@el.check('customerbase:del')") + @DeleteMapping + public ResponseEntity delete(@RequestBody String[] ids) { + customerbaseService.deleteAll(ids); + return new ResponseEntity<>(HttpStatus.OK); + } + + @Log("导出order") + @ApiOperation("导出order") + @GetMapping(value = "/download") + //@PreAuthorize("@el.check('customerbase:list')") + public void download(HttpServletResponse response, @RequestParam Map whereJson) throws IOException { + customerbaseService.download(customerbaseService.queryAll(whereJson), response); + } +} diff --git a/nladmin-system/src/main/java/org/nl/acs/order/rest/MaterialbaseController.java b/nladmin-system/src/main/java/org/nl/acs/order/rest/MaterialbaseController.java new file mode 100644 index 0000000..3cf9b9f --- /dev/null +++ b/nladmin-system/src/main/java/org/nl/acs/order/rest/MaterialbaseController.java @@ -0,0 +1,76 @@ + +package org.nl.acs.order.rest; + + +import org.nl.acs.order.service.MaterialbaseService; +import org.nl.acs.order.service.dto.MaterialbaseDto; +import org.springframework.data.domain.Pageable; +import lombok.RequiredArgsConstructor; +import org.nl.annotation.Log; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; +import io.swagger.annotations.*; +import java.io.IOException; +import javax.servlet.http.HttpServletResponse; +import java.util.Map; +import lombok.extern.slf4j.Slf4j; + +/** +* @author wangs +* @date 2022-03-31 +**/ +@RestController +@RequiredArgsConstructor +@Api(tags = "物料维护") +@RequestMapping("/api/materialbase") +@Slf4j +public class MaterialbaseController { + + private final MaterialbaseService materialbaseService; + + @GetMapping + @Log("查询物料") + @ApiOperation("查询物料") + //@PreAuthorize("@el.check('materialbase:list')") + public ResponseEntity query(@RequestParam Map whereJson, Pageable page){ + return new ResponseEntity<>(materialbaseService.queryAll(whereJson,page),HttpStatus.OK); + } + + @PostMapping + @Log("新增order") + @ApiOperation("新增order") + //@PreAuthorize("@el.check('materialbase:add')") + public ResponseEntity create(@Validated @RequestBody MaterialbaseDto dto){ + materialbaseService.create(dto); + return new ResponseEntity<>(HttpStatus.CREATED); + } + + @PutMapping + @Log("修改order") + @ApiOperation("修改order") + //@PreAuthorize("@el.check('materialbase:edit')") + public ResponseEntity update(@Validated @RequestBody MaterialbaseDto dto){ + materialbaseService.update(dto); + return new ResponseEntity<>(HttpStatus.NO_CONTENT); + } + + @Log("删除order") + @ApiOperation("删除order") + //@PreAuthorize("@el.check('materialbase:del')") + @DeleteMapping + public ResponseEntity delete(@RequestBody String[] ids) { + materialbaseService.deleteAll(ids); + return new ResponseEntity<>(HttpStatus.OK); + } + + @Log("导出order") + @ApiOperation("导出order") + @GetMapping(value = "/download") + //@PreAuthorize("@el.check('materialbase:list')") + public void download(HttpServletResponse response, @RequestParam Map whereJson) throws IOException { + materialbaseService.download(materialbaseService.queryAll(whereJson), response); + } +} diff --git a/nladmin-system/src/main/java/org/nl/acs/order/rest/ProduceshiftorderController.java b/nladmin-system/src/main/java/org/nl/acs/order/rest/ProduceshiftorderController.java new file mode 100644 index 0000000..49b4329 --- /dev/null +++ b/nladmin-system/src/main/java/org/nl/acs/order/rest/ProduceshiftorderController.java @@ -0,0 +1,95 @@ + +package org.nl.acs.order.rest; + + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.order.service.ProduceshiftorderService; +import org.nl.acs.order.service.dto.ProduceshiftorderDto; +import org.nl.annotation.Log; +import org.springframework.data.domain.Pageable; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.util.Map; + +/** + * @author wangs + * @date 2022-01-21 + **/ +@RestController +@RequiredArgsConstructor +@Api(tags = "工单管理") +@RequestMapping("/api/produceshiftorder") +@Slf4j +public class ProduceshiftorderController { + + private final ProduceshiftorderService produceshiftorderService; + + @GetMapping + @Log("查询工单") + @ApiOperation("查询工单") + //@PreAuthorize("@el.check('produceshiftorder:list')") + public ResponseEntity query(@RequestParam Map whereJson, Pageable page) { + return new ResponseEntity<>(produceshiftorderService.queryAll(whereJson, page), HttpStatus.OK); + } + + @Log("查询工单明细") + @ApiOperation("查询工单") + @GetMapping(value = "/getDtl") + //@PreAuthorize("@el.check('produceshiftorder:list')") + public ResponseEntity getDtl(@RequestParam Map whereJson) { + return new ResponseEntity<>(produceshiftorderService.getDtl(whereJson), HttpStatus.OK); + } + + @PostMapping + @Log("新增工单") + @ApiOperation("新增工单") + //@PreAuthorize("@el.check('produceshiftorder:add')") + public ResponseEntity create(@Validated @RequestBody Map whereJson) { + produceshiftorderService.create(whereJson); + return new ResponseEntity<>(HttpStatus.CREATED); + } + + @PutMapping + @Log("修改工单") + @ApiOperation("修改工单") + //@PreAuthorize("@el.check('produceshiftorder:edit')") + public ResponseEntity update(@Validated @RequestBody ProduceshiftorderDto dto) { + produceshiftorderService.update(dto); + return new ResponseEntity<>(HttpStatus.NO_CONTENT); + } + + @Log("删除工单") + @ApiOperation("删除工单") + //@PreAuthorize("@el.check('produceshiftorder:del')") + @DeleteMapping + public ResponseEntity delete(@RequestBody String[] ids) { + produceshiftorderService.deleteAll(ids); + return new ResponseEntity<>(HttpStatus.OK); + } + + @Log("导出工单") + @ApiOperation("导出工单") + @GetMapping(value = "/download") + //@PreAuthorize("@el.check('produceshiftorder:list')") + public void download(HttpServletResponse response, @RequestParam Map whereJson) throws IOException { + produceshiftorderService.download(produceshiftorderService.queryAll(whereJson), response); + } + + @Log("导入工单excel") + @ApiOperation("导入工单excel") + @GetMapping("/importExcel/{id}") + public ResponseEntity importExcel(@PathVariable String id) { + produceshiftorderService.importExcel(id); + return new ResponseEntity<>(HttpStatus.OK); + } + + +} diff --git a/nladmin-system/src/main/java/org/nl/acs/order/service/CustomerbaseService.java b/nladmin-system/src/main/java/org/nl/acs/order/service/CustomerbaseService.java new file mode 100644 index 0000000..abdd688 --- /dev/null +++ b/nladmin-system/src/main/java/org/nl/acs/order/service/CustomerbaseService.java @@ -0,0 +1,73 @@ + +package org.nl.acs.order.service; + +import org.nl.acs.order.service.dto.CustomerbaseDto; +import org.springframework.data.domain.Pageable; +import java.util.Map; +import java.util.List; +import java.io.IOException; +import javax.servlet.http.HttpServletResponse; + +/** +* @description 服务接口 +* @author wangs +* @date 2022-03-31 +**/ +public interface CustomerbaseService { + + /** + * 查询数据分页 + * @param whereJson 条件 + * @param page 分页参数 + * @return Map + */ + Map queryAll(Map whereJson, Pageable page); + + /** + * 查询所有数据不分页 + * @param whereJson 条件参数 + * @return List + */ + List queryAll(Map whereJson); + + /** + * 根据ID查询 + * @param cust_id ID + * @return Customerbase + */ + CustomerbaseDto findById(String cust_id); + + /** + * 根据编码查询 + * @param code code + * @return Customerbase + */ + CustomerbaseDto findByCode(String code); + + + /** + * 创建 + * @param dto / + */ + void create(CustomerbaseDto dto); + + /** + * 编辑 + * @param dto / + */ + void update(CustomerbaseDto dto); + + /** + * 多选删除 + * @param ids / + */ + void deleteAll(String[] ids); + + /** + * 导出数据 + * @param dtos 待导出的数据 + * @param response / + * @throws IOException / + */ + void download(List dtos, HttpServletResponse response) throws IOException; +} diff --git a/nladmin-system/src/main/java/org/nl/acs/order/service/MaterialbaseService.java b/nladmin-system/src/main/java/org/nl/acs/order/service/MaterialbaseService.java new file mode 100644 index 0000000..ff9dbd0 --- /dev/null +++ b/nladmin-system/src/main/java/org/nl/acs/order/service/MaterialbaseService.java @@ -0,0 +1,75 @@ + +package org.nl.acs.order.service; + +import org.nl.acs.order.service.dto.MaterialbaseDto; +import org.springframework.data.domain.Pageable; +import java.util.Map; +import java.util.List; +import java.io.IOException; +import javax.servlet.http.HttpServletResponse; + +/** +* @description 服务接口 +* @author wangs +* @date 2022-03-31 +**/ +public interface MaterialbaseService { + + /** + * 查询数据分页 + * @param whereJson 条件 + * @param page 分页参数 + * @return Map + */ + Map queryAll(Map whereJson, Pageable page); + + /** + * 查询所有数据不分页 + * @param whereJson 条件参数 + * @return List + */ + List queryAll(Map whereJson); + + List queryAll(); + + /** + * 根据ID查询 + * @param material_id ID + * @return Materialbase + */ + MaterialbaseDto findById(String material_id); + + /** + * 根据编码查询 + * @param code code + * @return Materialbase + */ + MaterialbaseDto findByCode(String code); + + + /** + * 创建 + * @param dto / + */ + void create(MaterialbaseDto dto); + + /** + * 编辑 + * @param dto / + */ + void update(MaterialbaseDto dto); + + /** + * 多选删除 + * @param ids / + */ + void deleteAll(String[] ids); + + /** + * 导出数据 + * @param dtos 待导出的数据 + * @param response / + * @throws IOException / + */ + void download(List dtos, HttpServletResponse response) throws IOException; +} diff --git a/nladmin-system/src/main/java/org/nl/acs/order/service/ProduceshiftorderService.java b/nladmin-system/src/main/java/org/nl/acs/order/service/ProduceshiftorderService.java new file mode 100644 index 0000000..251d53b --- /dev/null +++ b/nladmin-system/src/main/java/org/nl/acs/order/service/ProduceshiftorderService.java @@ -0,0 +1,101 @@ + +package org.nl.acs.order.service; + +import com.alibaba.fastjson.JSONArray; +import org.nl.acs.order.service.dto.ProduceshiftorderDto; +import org.springframework.data.domain.Pageable; + +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.util.List; +import java.util.Map; + +/** + * @author wangs + * @description 服务接口 + * @date 2022-01-21 + **/ +public interface ProduceshiftorderService { + + /** + * 查询数据分页 + * + * @param whereJson 条件 + * @param page 分页参数 + * @return Map + */ + Map queryAll(Map whereJson, Pageable page); + + /** + * 查询所有数据不分页 + * + * @param whereJson 条件参数 + * @return List + */ + List queryAll(Map whereJson); + + /** + * 根据ID查询 + * + * @param order_id ID + * @return Produceshiftorder + */ + ProduceshiftorderDto findById(String order_id); + + /** + * 根据编码查询 + * + * @param code code + * @return Produceshiftorder + */ + ProduceshiftorderDto findByCode(String code); + + + /** + * 创建 + * + * @param / + */ + void create(Map whereJson); + + /** + * 编辑 + * + * @param dto / + */ + void update(ProduceshiftorderDto dto); + + /** + * 多选删除 + * + * @param ids / + */ + void deleteAll(String[] ids); + + /** + * 取消任务 + * + * @param ids + */ + void cancel(String ids) throws Exception; + + /** + * 导出数据 + * + * @param dtos 待导出的数据 + * @param response / + * @throws IOException / + */ + void download(List dtos, HttpServletResponse response) throws IOException; + + + /** + * 导入工单 + * + * @param id / + */ + void importExcel(String id); + + JSONArray getDtl(Map whereJson); + +} diff --git a/nladmin-system/src/main/java/org/nl/acs/order/service/dto/CustomerbaseDto.java b/nladmin-system/src/main/java/org/nl/acs/order/service/dto/CustomerbaseDto.java new file mode 100644 index 0000000..dcf6f3c --- /dev/null +++ b/nladmin-system/src/main/java/org/nl/acs/order/service/dto/CustomerbaseDto.java @@ -0,0 +1,65 @@ +package org.nl.acs.order.service.dto; + +import lombok.Data; +import java.io.Serializable; + import com.fasterxml.jackson.databind.annotation.JsonSerialize; + import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; + +/** +* @description / +* @author wangs +* @date 2022-03-31 +**/ +@Data +public class CustomerbaseDto implements Serializable { + + /** 客户标识 */ + /** 防止精度丢失 */ + @JsonSerialize(using= ToStringSerializer.class) + private String cust_id; + + /** 客户编码 */ + private String cust_code; + + /** 客户名称 */ + private String cust_name; + + /** 工商注册号 */ + private String register_no; + + /** 经营许可证号 */ + private String manage_lice_no; + + /** 营业执照 */ + private String busi_char_name; + + /** 邮政编码 */ + private String zip_code; + + /** 公司电话 */ + private String corp_tele_no; + + /** 公司地址 */ + private String corp_address; + + /** 创建者 */ + private String create_by; + + /** 创建时间 */ + private String create_time; + + /** 修改者 */ + private String update_by; + + /** 修改时间 */ + private String update_time; + + /** 是否启用 */ + private String is_used; + + /** 是否删除 */ + private String is_delete; + + /** 备注 */ + private String remark; +} diff --git a/nladmin-system/src/main/java/org/nl/acs/order/service/dto/MaterialbaseDto.java b/nladmin-system/src/main/java/org/nl/acs/order/service/dto/MaterialbaseDto.java new file mode 100644 index 0000000..cd968d9 --- /dev/null +++ b/nladmin-system/src/main/java/org/nl/acs/order/service/dto/MaterialbaseDto.java @@ -0,0 +1,87 @@ +package org.nl.acs.order.service.dto; + +import lombok.Data; + import java.math.BigDecimal; +import java.io.Serializable; + import com.fasterxml.jackson.databind.annotation.JsonSerialize; + import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; + +/** +* @description / +* @author wangs +* @date 2022-03-31 +**/ +@Data +public class MaterialbaseDto implements Serializable { + + /** 物料标识 */ + /** 防止精度丢失 */ + @JsonSerialize(using= ToStringSerializer.class) + private String material_id; + + /** 物料编码 */ + private String material_code; + + /** 物料名称 */ + private String material_name; + + /** 规格 */ + private String material_spec; + + /** 型号 */ + private String material_model; + + /** 基本计量单位 */ + private String base_unit_id; + + /** 工程图号 */ + private String print_no; + + /** 长度单位 */ + private String len_unit_id; + + /** 物料长度 */ + private BigDecimal length; + + /** 物料宽度 */ + private BigDecimal width; + + /** 物料高度 */ + private BigDecimal height; + + /** 重量单位 */ + private String weight_unit_id; + + /** 物料毛重 */ + private BigDecimal gross_weight; + + /** 物料净重 */ + private BigDecimal net_weight; + + /** 体积单位 */ + private String cubage_unit_id; + + /** 物料体积 */ + private BigDecimal cubage; + + /** 创建者 */ + private String create_by; + + /** 创建时间 */ + private String create_time; + + /** 修改者 */ + private String update_by; + + /** 修改时间 */ + private String update_time; + + /** 启用时间 */ + private String is_used_time; + + /** 是否启用 */ + private String is_used; + + /** 是否删除 */ + private String is_delete; +} diff --git a/nladmin-system/src/main/java/org/nl/acs/order/service/dto/ProduceshiftorderDto.java b/nladmin-system/src/main/java/org/nl/acs/order/service/dto/ProduceshiftorderDto.java new file mode 100644 index 0000000..320688d --- /dev/null +++ b/nladmin-system/src/main/java/org/nl/acs/order/service/dto/ProduceshiftorderDto.java @@ -0,0 +1,60 @@ +package org.nl.acs.order.service.dto; + +import lombok.Data; + import java.math.BigDecimal; +import java.io.Serializable; + import com.fasterxml.jackson.databind.annotation.JsonSerialize; + import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; + +/** +* @description / +* @author wangs +* @date 2022-03-18 +**/ +@Data +public class ProduceshiftorderDto implements Serializable { + + /** 工单标识 */ + /** 防止精度丢失 */ +// @JsonSerialize(using= ToStringSerializer.class) + private String order_id; + + /** 工单编码 */ + private String order_code; + + /** 是否已拆分 */ + private String is_unbundling; + + /** 工单状态 */ + private String order_status; + + /** 物料编码 */ + private String material_code; + + /** 物料名称 */ + private String material_name; + + /** 物料标识 */ + private String material_id; + + /** 规格型号 */ + private String material_spec; + + /** 创建者 */ + private String create_by; + + /** 创建时间 */ + private String create_time; + + /** 修改者 */ + private String update_by; + + /** 修改时间 */ + private String update_time; + + /** 是否删除 */ + private String is_deleted; + + /** 下料数量 */ + private String qty; +} diff --git a/nladmin-system/src/main/java/org/nl/acs/order/service/dto/ProduceshiftorderdetailDto.java b/nladmin-system/src/main/java/org/nl/acs/order/service/dto/ProduceshiftorderdetailDto.java new file mode 100644 index 0000000..e153e2c --- /dev/null +++ b/nladmin-system/src/main/java/org/nl/acs/order/service/dto/ProduceshiftorderdetailDto.java @@ -0,0 +1,99 @@ +package org.nl.acs.order.service.dto; + +import lombok.Data; +import java.math.BigDecimal; +import java.io.Serializable; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; + +/** + * @description / + * @author wangs + * @date 2022-03-18 + **/ +@Data +public class ProduceshiftorderdetailDto implements Serializable { + + /** 工单明细标识 */ + /** 防止精度丢失 */ +// @JsonSerialize(using= ToStringSerializer.class) + private String orderDetail_id; + + /** 工单明细编码 */ + private String orderDetail_code; + + /** 工单明细类型 */ + private String orderDetail_type; + + /** 优先级 */ + private BigDecimal priority; + + /** 顺序号 */ + private String sequence_number; + + /** 工单标识 */ + private String order_id; + + /** 工单编码 */ + private String order_code; + + /** 客户标识 */ + private String cust_id; + + /** 客户编码 */ + private String cust_code; + + /** 客户名称 */ + private String cust_name; + + /** 明细状态 */ + private String order_status; + + /** 客户明细数量 */ + private String detail_qty; + + /** 捆扎包数 */ + private String strap_pack_number; + + /** 当前捆扎包数 */ + private String present_strap_pack_number; + + /** 每捆数量 */ + private String strap_number; + + /** 捆扎尾料数量 */ + private String strap_tailint_number; + + /** 捆扎直径 */ + private String starp_diameter; + + /** 捆扎尾料直径 */ + private String starp_tailint_diameter; + + /** 刻字信息 */ + private String lettering_message; + + /** 当前刻字数量 */ + private String present_lettering_numer; + + /** 贴标信息 */ + private String labeling_message; + + /** 当前贴标数量 */ + private String present_labeling_number; + + /** 创建者 */ + private String create_by; + + /** 创建时间 */ + private String create_time; + + /** 修改者 */ + private String update_by; + + /** 修改时间 */ + private String update_time; + + /** 是否删除 */ + private String is_deleted; +} diff --git a/nladmin-system/src/main/java/org/nl/acs/order/service/impl/CustomerbaseServiceImpl.java b/nladmin-system/src/main/java/org/nl/acs/order/service/impl/CustomerbaseServiceImpl.java new file mode 100644 index 0000000..f368057 --- /dev/null +++ b/nladmin-system/src/main/java/org/nl/acs/order/service/impl/CustomerbaseServiceImpl.java @@ -0,0 +1,140 @@ + +package org.nl.acs.order.service.impl; + + +import lombok.RequiredArgsConstructor; +import org.nl.acs.order.service.CustomerbaseService; +import org.nl.acs.order.service.dto.CustomerbaseDto; +import org.nl.exception.BadRequestException; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import org.springframework.data.domain.Pageable; +import java.util.List; +import java.util.Map; +import java.io.IOException; +import javax.servlet.http.HttpServletResponse; +import java.util.ArrayList; +import java.util.LinkedHashMap; + +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.IdUtil; +import cn.hutool.core.bean.BeanUtil; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import org.nl.utils.SecurityUtils; +import org.nl.wql.core.bean.ResultBean; +import org.nl.wql.core.bean.WQLObject; +import org.nl.wql.util.WqlUtil; +import org.nl.utils.FileUtil; +import lombok.extern.slf4j.Slf4j; + +/** +* @description 服务实现 +* @author wangs +* @date 2022-03-31 +**/ +@Service +@RequiredArgsConstructor +@Slf4j +public class CustomerbaseServiceImpl implements CustomerbaseService { + + @Override + public Map queryAll(Map whereJson, Pageable page){ + WQLObject wo = WQLObject.getWQLObject("acs_customerbase"); + ResultBean rb = wo.pagequery(WqlUtil.getHttpContext(page), "", "update_time desc"); + final JSONObject json = rb.pageResult(); + return json; + } + + @Override + public List queryAll(Map whereJson){ + WQLObject wo = WQLObject.getWQLObject("acs_customerbase"); + JSONArray arr = wo.query().getResultJSONArray(0); + List list = arr.toJavaList(CustomerbaseDto.class); + return list; + } + + @Override + public CustomerbaseDto findById(String cust_id) { + WQLObject wo = WQLObject.getWQLObject("acs_customerbase"); + JSONObject json = wo.query("cust_id ='" + cust_id + "'").uniqueResult(0); + final CustomerbaseDto obj = (CustomerbaseDto) JSONObject.toJavaObject(json, CustomerbaseDto.class); + return obj; + } + + @Override + public CustomerbaseDto findByCode(String code) { + WQLObject wo = WQLObject.getWQLObject("acs_customerbase"); + JSONObject json = wo.query("code ='" + code + "'").uniqueResult(0); + final CustomerbaseDto obj = (CustomerbaseDto) JSONObject.toJavaObject(json, CustomerbaseDto.class); + return obj; + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void create(CustomerbaseDto dto) { + String currentUsername = SecurityUtils.getCurrentUsername(); + String now = DateUtil.now(); + + dto.setCust_id(IdUtil.simpleUUID()); + dto.setCreate_by(currentUsername); + dto.setUpdate_by(currentUsername); + dto.setUpdate_time(now); + dto.setCreate_time(now); + + WQLObject wo = WQLObject.getWQLObject("acs_customerbase"); + JSONObject json= (JSONObject) JSONObject.toJSON(dto); + wo.insert(json); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void update(CustomerbaseDto dto) { + CustomerbaseDto entity = this.findById(dto.getCust_id()); + if (entity == null) throw new BadRequestException("被删除或无权限,操作失败!"); + + String currentUsername = SecurityUtils.getCurrentUsername(); + String now = DateUtil.now(); + dto.setUpdate_time(now); + dto.setUpdate_by(currentUsername); + + WQLObject wo = WQLObject.getWQLObject("acs_customerbase"); + JSONObject json= (JSONObject) JSONObject.toJSON(dto); + wo.update(json); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void deleteAll(String[] ids) { + WQLObject wo = WQLObject.getWQLObject("acs_customerbase"); + for (String cust_id: ids) { + wo.delete("cust_id = '" + cust_id + "'"); + } + } + + @Override + public void download(List all, HttpServletResponse response) throws IOException { + List> list = new ArrayList<>(); + for (CustomerbaseDto customerbase : all) { + Map map = new LinkedHashMap<>(); + map.put("客户编码", customerbase.getCust_code()); + map.put("客户名称 ", customerbase.getCust_name()); + map.put("工商注册号", customerbase.getRegister_no()); + map.put("经营许可证号", customerbase.getManage_lice_no()); + map.put("营业执照", customerbase.getBusi_char_name()); + map.put("邮政编码", customerbase.getZip_code()); + map.put("公司电话", customerbase.getCorp_tele_no()); + map.put("公司地址", customerbase.getCorp_address()); + map.put("创建者", customerbase.getCreate_by()); + map.put("创建时间", customerbase.getCreate_time()); + map.put("修改者", customerbase.getUpdate_by()); + map.put("修改时间", customerbase.getUpdate_time()); + map.put("是否启用", customerbase.getIs_used()); + map.put("是否删除", customerbase.getIs_delete()); + map.put("备注", customerbase.getRemark()); + list.add(map); + } + FileUtil.downloadExcel(list, response); + } +} diff --git a/nladmin-system/src/main/java/org/nl/acs/order/service/impl/MaterialbaseServiceImpl.java b/nladmin-system/src/main/java/org/nl/acs/order/service/impl/MaterialbaseServiceImpl.java new file mode 100644 index 0000000..7273b6f --- /dev/null +++ b/nladmin-system/src/main/java/org/nl/acs/order/service/impl/MaterialbaseServiceImpl.java @@ -0,0 +1,158 @@ + +package org.nl.acs.order.service.impl; + + +import com.alibaba.fastjson.JSON; +import lombok.RequiredArgsConstructor; +import org.nl.acs.order.service.MaterialbaseService; +import org.nl.acs.order.service.dto.MaterialbaseDto; +import org.nl.exception.BadRequestException; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import org.springframework.data.domain.Pageable; +import java.util.List; +import java.util.Map; +import java.io.IOException; +import javax.servlet.http.HttpServletResponse; +import java.util.ArrayList; +import java.util.LinkedHashMap; + +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.IdUtil; +import cn.hutool.core.bean.BeanUtil; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import org.nl.utils.SecurityUtils; +import org.nl.wql.core.bean.ResultBean; +import org.nl.wql.core.bean.WQLObject; +import org.nl.wql.util.WqlUtil; +import org.nl.utils.FileUtil; +import lombok.extern.slf4j.Slf4j; + +/** +* @description 服务实现 +* @author wangs +* @date 2022-03-31 +**/ +@Service +@RequiredArgsConstructor +@Slf4j +public class MaterialbaseServiceImpl implements MaterialbaseService { + + @Override + public Map queryAll(Map whereJson, Pageable page){ + WQLObject wo = WQLObject.getWQLObject("acs_materialbase"); + ResultBean rb = wo.pagequery(WqlUtil.getHttpContext(page), "", "update_time desc"); + final JSONObject json = rb.pageResult(); + return json; + } + + @Override + public List queryAll(Map whereJson){ + WQLObject wo = WQLObject.getWQLObject("acs_materialbase"); + JSONArray arr = wo.query().getResultJSONArray(0); + List list = arr.toJavaList(MaterialbaseDto.class); + return list; + } + + + + @Override + public List queryAll(){ + WQLObject wo = WQLObject.getWQLObject("acs_materialbase"); + JSONArray arr = wo.query().getResultJSONArray(0); + List list = arr.toJavaList(MaterialbaseDto.class); + return list; + } + + @Override + public MaterialbaseDto findById(String material_id) { + WQLObject wo = WQLObject.getWQLObject("acs_materialbase"); + JSONObject json = wo.query("material_id ='" + material_id + "'").uniqueResult(0); + final MaterialbaseDto obj = (MaterialbaseDto) JSONObject.toJavaObject(json, MaterialbaseDto.class); + return obj; + } + + @Override + public MaterialbaseDto findByCode(String code) { + WQLObject wo = WQLObject.getWQLObject("acs_materialbase"); + JSONObject json = wo.query("code ='" + code + "'").uniqueResult(0); + final MaterialbaseDto obj = (MaterialbaseDto) JSONObject.toJavaObject(json, MaterialbaseDto.class); + return obj; + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void create(MaterialbaseDto dto) { + String currentUsername = SecurityUtils.getCurrentUsername(); + String now = DateUtil.now(); + + dto.setMaterial_id(IdUtil.simpleUUID()); + dto.setCreate_by(currentUsername); + dto.setUpdate_by(currentUsername); + dto.setUpdate_time(now); + dto.setCreate_time(now); + + WQLObject wo = WQLObject.getWQLObject("acs_materialbase"); + JSONObject json= (JSONObject) JSONObject.toJSON(dto); + wo.insert(json); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void update(MaterialbaseDto dto) { + MaterialbaseDto entity = this.findById(dto.getMaterial_id()); + if (entity == null) throw new BadRequestException("被删除或无权限,操作失败!"); + + String currentUsername = SecurityUtils.getCurrentUsername(); + String now = DateUtil.now(); + dto.setUpdate_time(now); + dto.setUpdate_by(currentUsername); + + WQLObject wo = WQLObject.getWQLObject("acs_materialbase"); + JSONObject json= (JSONObject) JSONObject.toJSON(dto); + wo.update(json); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void deleteAll(String[] ids) { + WQLObject wo = WQLObject.getWQLObject("acs_materialbase"); + for (String material_id: ids) { + wo.delete("material_id = '" + material_id + "'"); + } + } + + @Override + public void download(List all, HttpServletResponse response) throws IOException { + List> list = new ArrayList<>(); + for (MaterialbaseDto materialbase : all) { + Map map = new LinkedHashMap<>(); + map.put("物料编码", materialbase.getMaterial_code()); + map.put("物料名称 ", materialbase.getMaterial_name()); + map.put("规格", materialbase.getMaterial_spec()); + map.put("型号", materialbase.getMaterial_model()); + map.put("基本计量单位", materialbase.getBase_unit_id()); + map.put("工程图号", materialbase.getPrint_no()); + map.put("长度单位", materialbase.getLen_unit_id()); + map.put("物料长度", materialbase.getLength()); + map.put("物料宽度", materialbase.getWidth()); + map.put("物料高度", materialbase.getHeight()); + map.put("重量单位", materialbase.getWeight_unit_id()); + map.put("物料毛重", materialbase.getGross_weight()); + map.put("物料净重", materialbase.getNet_weight()); + map.put("体积单位", materialbase.getCubage_unit_id()); + map.put("物料体积", materialbase.getCubage()); + map.put("创建者", materialbase.getCreate_by()); + map.put("创建时间", materialbase.getCreate_time()); + map.put("修改者", materialbase.getUpdate_by()); + map.put("修改时间", materialbase.getUpdate_time()); + map.put("启用时间", materialbase.getIs_used_time()); + map.put("是否启用", materialbase.getIs_used()); + map.put("是否删除", materialbase.getIs_delete()); + list.add(map); + } + FileUtil.downloadExcel(list, response); + } +} diff --git a/nladmin-system/src/main/java/org/nl/acs/order/service/impl/ProduceshiftorderServiceImpl.java b/nladmin-system/src/main/java/org/nl/acs/order/service/impl/ProduceshiftorderServiceImpl.java new file mode 100644 index 0000000..c531aa5 --- /dev/null +++ b/nladmin-system/src/main/java/org/nl/acs/order/service/impl/ProduceshiftorderServiceImpl.java @@ -0,0 +1,234 @@ +package org.nl.acs.order.service.impl; + +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.map.MapUtil; +import cn.hutool.core.util.IdUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.nl.acs.order.service.ProduceshiftorderService; +import org.nl.acs.order.service.dto.CustomerbaseDto; +import org.nl.acs.order.service.dto.ProduceshiftorderDto; +import org.nl.acs.order.service.dto.ProduceshiftorderdetailDto; +import org.nl.exception.BadRequestException; +import org.nl.modules.system.util.CodeUtil; +import org.nl.utils.SecurityUtils; +import org.nl.wql.WQL; +import org.nl.wql.core.bean.ResultBean; +import org.nl.wql.core.bean.WQLObject; +import org.nl.wql.util.WqlUtil; +import org.springframework.data.domain.Pageable; +import org.springframework.data.mongodb.core.MongoTemplate; +import org.springframework.data.mongodb.core.query.Criteria; +import org.springframework.data.mongodb.core.query.Query; +import org.springframework.data.mongodb.core.query.Update; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @author wangs + * @description 服务实现 + * @date 2022-01-21 + **/ +@Service +@RequiredArgsConstructor +@Slf4j +public class ProduceshiftorderServiceImpl implements ProduceshiftorderService { + + private final MongoTemplate mongoTemplate; + + @Override + public Map queryAll(Map whereJson, Pageable page) { + WQLObject wo = WQLObject.getWQLObject("acs_produceshiftorder"); + String where = "1=1 and is_deleted= '0'"; + ResultBean rb = wo.pagequery(WqlUtil.getHttpContext(page), where, "order_id desc"); + final JSONObject json = rb.pageResult(); + JSONArray newja = new JSONArray(); + JSONArray ja = json.getJSONArray("content"); + for (int i = 0; i < ja.size(); i++) { + JSONObject jo = (JSONObject) ja.get(i); + JSONArray orderDteail_ja = WQLObject.getWQLObject("acs_produceshiftorderdetail").query("is_deleted= '0' and order_id ='" + jo.getString("order_id") + "'").getResultJSONArray(0); + if (orderDteail_ja.size() > 0) { + JSONArray children = new JSONArray(); + for (int j = 0; j < orderDteail_ja.size(); j++) { + JSONObject orderDteail_jo = orderDteail_ja.getJSONObject(j); + JSONObject new_jo = new JSONObject(); + new_jo.put("order_id", orderDteail_jo.getString("orderdetail_id")); + new_jo.put("order_code", orderDteail_jo.getString("orderdetail_code")); + new_jo.put("is_active", orderDteail_jo.getString("is_active")); + new_jo.put("is_delete", orderDteail_jo.getString("is_delete")); + new_jo.put("create_by", orderDteail_jo.getString("create_by")); + new_jo.put("create_time", orderDteail_jo.getString("create_time")); + new_jo.put("update_by", orderDteail_jo.getString("update_by")); + new_jo.put("update_time", orderDteail_jo.getString("update_time")); + new_jo.put("cust_id", orderDteail_jo.getString("cust_id")); + new_jo.put("cust_code", orderDteail_jo.getString("cust_code")); + new_jo.put("cust_name", orderDteail_jo.getString("cust_name")); + new_jo.put("order_qty", orderDteail_jo.getString("order_qty")); + new_jo.put("type", "orderDteail"); + jo.put("is_flag", "0"); + children.add(new_jo); + } + jo.put("children", children); + } + jo.put("type", "order"); + //区分工单明细 + jo.put("is_flag", "1"); + newja.add(jo); + } + json.put("content", newja); + System.out.println("json:" + json); + return json; + } + + @Override + public List queryAll(Map whereJson) { + return null; + } + + @Override + public ProduceshiftorderDto findById(String order_id) { + WQLObject wo = WQLObject.getWQLObject("acs_produceshiftorder"); + JSONObject json = wo.query("order_id ='" + order_id + "'").uniqueResult(0); + final ProduceshiftorderDto obj = JSONObject.toJavaObject(json, ProduceshiftorderDto.class); + return obj; + } + + @Override + public ProduceshiftorderDto findByCode(String code) { + return null; + } + + @Override + public void create(Map whereJson) { + JSONObject param=new JSONObject(whereJson); + String currentUsername = SecurityUtils.getCurrentUsername(); + ProduceshiftorderDto orderDto = new ProduceshiftorderDto(); + String material_id = MapUtil.getStr(whereJson, "material_id"); + String material_code = MapUtil.getStr(whereJson, "material_code"); + String material_name = MapUtil.getStr(whereJson, "material_name"); + String material_spec = MapUtil.getStr(whereJson, "material_spec"); + String qty = MapUtil.getStr(whereJson, "qty"); + + if(StrUtil.isEmpty(material_code)){ + throw new RuntimeException("物料编号不可为空!"); + } + JSONArray tableData = param.getJSONArray("tableData"); + if (ObjectUtil.isEmpty(tableData)){ + throw new BadRequestException("客户信息不可为空!"); + } + String order_code = CodeUtil.getNewCode("ORDER_NO"); + String order_id = IdUtil.simpleUUID(); + orderDto.setMaterial_code(material_code); + orderDto.setMaterial_name(material_name); + orderDto.setMaterial_spec(material_spec); + orderDto.setOrder_id(order_id); + orderDto.setOrder_code(order_code); + orderDto.setQty(qty); + orderDto.setOrder_status("0"); + orderDto.setIs_deleted("0"); + orderDto.setCreate_by(currentUsername); + + for(int i=0; i map = new HashMap<>(); + map.put("is_deleted","1"); + WQLObject.getWQLObject("acs_produceshiftorderdetail").update(map,"order_id = '"+ id + "'"); + + } + + @Override + public void download(List dtos, HttpServletResponse response) throws IOException { + + } + + @Override + public void importExcel(String id) { + + } + + @Override + public JSONArray getDtl(Map whereJson) { + String order_id = (String) whereJson.get("order_id"); + WQLObject wo = WQLObject.getWQLObject("acs_produceshiftorderdetail"); + JSONArray arr = wo.query("order_id = '"+order_id+"'").getResultJSONArray(0); + return arr; + } +} \ No newline at end of file diff --git a/nladmin-system/src/main/java/org/nl/acs/order/service/wql/QPRODUCESHIFTORDER.wql b/nladmin-system/src/main/java/org/nl/acs/order/service/wql/QPRODUCESHIFTORDER.wql new file mode 100644 index 0000000..cf132f7 --- /dev/null +++ b/nladmin-system/src/main/java/org/nl/acs/order/service/wql/QPRODUCESHIFTORDER.wql @@ -0,0 +1,52 @@ +[交易说明] + 交易名: 包装工单查询 + 所属模块: + 功能简述: + 版权所有: + 表引用: + 版本经历: + +[数据库] + --指定数据库,为空采用默认值,默认为db.properties中列出的第一个库 + +[IO定义] + ################################################# + ## 表字段对应输入参数 + ################################################# + 输入.flag TYPEAS s_string + + +[临时表] + --这边列出来的临时表就会在运行期动态创建 + +[临时变量] + --所有中间过程变量均可在此处定义 + +[业务过程] + + ########################################## + # 1、输入输出检查 # + ########################################## + + + ########################################## + # 2、主过程前处理 # + ########################################## + + + ########################################## + # 3、业务主过程 # + ########################################## + + IF 输入.flag = "1" + QUERY + SELECT + * + FROM + acs_produceshiftorder t + + ENDSELECT + ENDQUERY + ENDIF + + diff --git a/nladmin-system/src/main/java/org/nl/acs/order/service/wql/order.xls b/nladmin-system/src/main/java/org/nl/acs/order/service/wql/order.xls new file mode 100644 index 0000000..1c40ed3 Binary files /dev/null and b/nladmin-system/src/main/java/org/nl/acs/order/service/wql/order.xls differ diff --git a/nladmin-system/src/main/java/org/nl/acs/route/rest/RouteLineController.java b/nladmin-system/src/main/java/org/nl/acs/route/rest/RouteLineController.java index f8926d1..cc14de6 100644 --- a/nladmin-system/src/main/java/org/nl/acs/route/rest/RouteLineController.java +++ b/nladmin-system/src/main/java/org/nl/acs/route/rest/RouteLineController.java @@ -41,6 +41,15 @@ public class RouteLineController { return new ResponseEntity<>(routeLineService.queryAll(whereJson, page), HttpStatus.OK); } + @GetMapping("/reload") + @Log("数据同步") + @ApiOperation("数据同步") + //@PreAuthorize("@el.check('task:list')") + public ResponseEntity reload() throws SQLException { + routeLineService.reload(); + return new ResponseEntity<>(HttpStatus.OK); + } + @PostMapping @Log("新增路由路线") @ApiOperation("新增路由路线") diff --git a/nladmin-system/src/main/java/org/nl/acs/route/service/impl/RouteLineServiceImpl.java b/nladmin-system/src/main/java/org/nl/acs/route/service/impl/RouteLineServiceImpl.java index 21abce3..de91337 100644 --- a/nladmin-system/src/main/java/org/nl/acs/route/service/impl/RouteLineServiceImpl.java +++ b/nladmin-system/src/main/java/org/nl/acs/route/service/impl/RouteLineServiceImpl.java @@ -261,7 +261,7 @@ public class RouteLineServiceImpl implements RouteLineService, ApplicationAutoIn } } } - reload(); +// reload(); } @Override diff --git a/nladmin-system/src/main/java/org/nl/acs/stage/rest/StageActorController.java b/nladmin-system/src/main/java/org/nl/acs/stage/rest/StageActorController.java index 27f83cb..cf4fa52 100644 --- a/nladmin-system/src/main/java/org/nl/acs/stage/rest/StageActorController.java +++ b/nladmin-system/src/main/java/org/nl/acs/stage/rest/StageActorController.java @@ -2,6 +2,7 @@ package org.nl.acs.stage.rest; +import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import io.swagger.annotations.Api; @@ -86,7 +87,7 @@ public class StageActorController { String grid_width = String.valueOf(map.get("grid_width")); String grid_length = String.valueOf(map.get("grid_length")); - JSONArray actors = JSONArray.parseArray((map.get("list")).toString()); + JSONArray actors = JSONArray.parseArray((JSON.toJSONString(map.get("list")))); JSONObject mstForm = new JSONObject(); mstForm.put("stage_code", stage_code); mstForm.put("grid_width", grid_width); diff --git a/nladmin-system/src/main/java/org/nl/acs/task/rest/TaskController.java b/nladmin-system/src/main/java/org/nl/acs/task/rest/TaskController.java index 26417ad..7e9b0ca 100644 --- a/nladmin-system/src/main/java/org/nl/acs/task/rest/TaskController.java +++ b/nladmin-system/src/main/java/org/nl/acs/task/rest/TaskController.java @@ -43,6 +43,15 @@ public class TaskController { return new ResponseEntity<>(taskService.queryAllByCache(whereJson, page), HttpStatus.OK); } + @GetMapping("/reload") + @Log("数据同步") + @ApiOperation("数据同步") + //@PreAuthorize("@el.check('task:list')") + public ResponseEntity reload() { + taskService.reload(); + return new ResponseEntity<>(HttpStatus.OK); + } + @GetMapping("/getAll") @Log("历史查询任务") @ApiOperation("历史查询任务") diff --git a/nladmin-system/src/main/java/org/nl/acs/task/service/TaskService.java b/nladmin-system/src/main/java/org/nl/acs/task/service/TaskService.java index 9d24f71..9d84a3d 100644 --- a/nladmin-system/src/main/java/org/nl/acs/task/service/TaskService.java +++ b/nladmin-system/src/main/java/org/nl/acs/task/service/TaskService.java @@ -27,6 +27,11 @@ public interface TaskService { */ Map queryAll(Map whereJson, Pageable page); + /** + * 数据同步 + */ + void reload(); + /** * 在缓存中查询所有任务列表 * diff --git a/nladmin-system/src/main/java/org/nl/acs/task/service/dto/TaskDto.java b/nladmin-system/src/main/java/org/nl/acs/task/service/dto/TaskDto.java index df61300..96e79e0 100644 --- a/nladmin-system/src/main/java/org/nl/acs/task/service/dto/TaskDto.java +++ b/nladmin-system/src/main/java/org/nl/acs/task/service/dto/TaskDto.java @@ -212,4 +212,9 @@ public class TaskDto implements Serializable { * 终点父级编码 */ private String next_parent_code; + + /** + * 外部系统标识 + */ + private String ext_task_uuid; } diff --git a/nladmin-system/src/main/java/org/nl/acs/task/service/impl/TaskServiceImpl.java b/nladmin-system/src/main/java/org/nl/acs/task/service/impl/TaskServiceImpl.java index c974c40..f1be4fd 100644 --- a/nladmin-system/src/main/java/org/nl/acs/task/service/impl/TaskServiceImpl.java +++ b/nladmin-system/src/main/java/org/nl/acs/task/service/impl/TaskServiceImpl.java @@ -605,7 +605,7 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { if (!StrUtil.startWith(dto.getTask_code(), "-") && StrUtil.equals(hasWms, "1")) { TaskFeedbackDto feefbackdto = taskFeedbackService.findByCode(entity.getTask_code()); JSONObject feed_jo = new JSONObject(); - feed_jo.put("task_uuid", dto.getTask_id()); + feed_jo.put("ext_task_uuid", entity.getExt_task_uuid()); feed_jo.put("task_code", dto.getTask_code()); feed_jo.put("task_status", dto.getTask_status()); JSONArray ja = new JSONArray(); @@ -721,7 +721,7 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { if (!StrUtil.startWith(entity.getTask_code(), "-") && StrUtil.equals(hasWms, "1")) { TaskFeedbackDto feefbackdto = taskFeedbackService.findByCode(entity.getTask_code()); JSONObject feed_jo = new JSONObject(); - feed_jo.put("task_uuid", entity.getTask_id()); + feed_jo.put("ext_task_uuid", entity.getExt_task_uuid()); feed_jo.put("task_code", entity.getTask_code()); feed_jo.put("task_status", entity.getTask_status()); JSONArray ja = new JSONArray(); @@ -844,7 +844,7 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { String hasWms = acsConfigService.findConfigFromCache().get(AcsConfig.HASWMS); if (!StrUtil.startWith(entity.getTask_code(), "-") && StrUtil.equals(hasWms, "1")) { JSONObject feed_jo = new JSONObject(); - feed_jo.put("task_uuid", entity.getTask_id()); + feed_jo.put("ext_task_uuid", entity.getExt_task_uuid()); feed_jo.put("task_code", entity.getTask_code()); feed_jo.put("task_status", entity.getTask_status()); JSONArray ja = new JSONArray(); @@ -867,6 +867,7 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { TaskDto acsTask = this.findById(ids); if (acsTask == null) throw new BadRequestException("被删除或无权限,操作失败!"); AcsConfigService acsConfigService = SpringContextHolder.getBean(AcsConfigService.class); + DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); InstructionService instructionservice = SpringContextHolder.getBean("instructionServiceImpl"); InstructionDto inst = instructionservice.findByTaskid(ids, "instruction_status < 2 "); if (inst != null) throw new BadRequestException("有指令未完成!"); @@ -885,6 +886,35 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { String next_device_code = acsTask.getNext_device_code(); String maxInstnumber = acsConfigService.findConfigFromCache().get(AcsConfig.MAXINSTNUMBER); + /** + * 开始平均分解校验 + */ + String this_device_code = this.queryAssignedByDevice(acsTask.getStart_device_code(), acsTask.getNext_device_code()); + if (StrUtil.isEmpty(this_device_code)) { + List shortPathsList = routeLineService.getShortPathLines(start_device_code, acsTask.getNext_device_code(), route_plan_code); + RouteLineDto routeLineDto = shortPathsList.get(0); + String path = routeLineDto.getPath(); + String type = routeLineDto.getType(); + String[] str = path.split("->"); + List pathlist = Arrays.asList(str); + int index = 0; + for (int m = 0; m < pathlist.size(); m++) { + if (pathlist.get(m).equals(start_device_code)) { + index = m + 1; + break; + } + } + next_device_code = pathlist.get(index); + } else { + next_device_code = this_device_code; + } + + if (StrUtil.equals(appService.findDeviceTypeByCode(next_device_code), "storage")) { + next_point_code = next_device_code + "-" + acsTask.getTo_y() + "-" + acsTask.getTo_z(); + } else { + next_point_code = next_device_code; + } + Instruction instdto = new Instruction(); instdto.setInstruction_type(acsTask.getTask_type()); instdto.setInstruction_id(IdUtil.simpleUUID()); diff --git a/nladmin-system/src/main/java/org/nl/modules/log/MongoDBAppender.java b/nladmin-system/src/main/java/org/nl/modules/log/MongoDBAppender.java index 6af3945..5abe4fd 100644 --- a/nladmin-system/src/main/java/org/nl/modules/log/MongoDBAppender.java +++ b/nladmin-system/src/main/java/org/nl/modules/log/MongoDBAppender.java @@ -2,6 +2,7 @@ package org.nl.modules.log; import ch.qos.logback.classic.spi.ILoggingEvent; import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.ObjectUtil; import org.bson.Document; import org.slf4j.Marker; @@ -24,6 +25,8 @@ public class MongoDBAppender extends MongoDBAppenderBase { protected Document toMongoDocument(ILoggingEvent eventObject) { final Document doc = new Document(); + doc.append("_id",IdUtil.simpleUUID()); + doc.append("date", DateUtil.now()); doc.append("source", source); try { diff --git a/nladmin-system/src/main/java/org/nl/modules/log/MongoDBAppenderBase.java b/nladmin-system/src/main/java/org/nl/modules/log/MongoDBAppenderBase.java index 47bf023..3aece6e 100644 --- a/nladmin-system/src/main/java/org/nl/modules/log/MongoDBAppenderBase.java +++ b/nladmin-system/src/main/java/org/nl/modules/log/MongoDBAppenderBase.java @@ -25,7 +25,7 @@ public abstract class MongoDBAppenderBase extends UnsynchronizedAppenderBase< MongoDatabase db; private MongoCollection eventsCollection; - private String host = "47.97.157.227"; // 地址 + private String host = "192.168.81.251"; // 地址 private int port = 27017; // 端口号 private String dbName = "db"; // 库名 private String collectionName; // 集合名 diff --git a/nladmin-system/src/main/java/org/nl/modules/log/rest/RootLogController.java b/nladmin-system/src/main/java/org/nl/modules/log/rest/RootLogController.java index 0ad0ee4..3363c3b 100644 --- a/nladmin-system/src/main/java/org/nl/modules/log/rest/RootLogController.java +++ b/nladmin-system/src/main/java/org/nl/modules/log/rest/RootLogController.java @@ -11,16 +11,14 @@ import org.nl.modules.log.service.RootLogService; import org.springframework.data.domain.Pageable; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; +import java.text.ParseException; import java.util.Map; /** - * @author ldjun - * @date 2021-08-19 + * @author loujf + * @date 2021-04-02 **/ @RestController @RequiredArgsConstructor @@ -32,11 +30,18 @@ public class RootLogController { private final RootLogService rootLogService; @GetMapping - @Log("查询系统日志") - @ApiOperation("查询系统日志") - //@PreAuthorize("@el.check('point:list')") - public ResponseEntity query(@RequestParam Map whereJson, Pageable page) { + @Log("查询日志") + @ApiOperation("查询日志") + //@PreAuthorize("@el.check('log:list')") + public ResponseEntity query(@RequestParam Map whereJson, Pageable page) throws ParseException { return new ResponseEntity<>(rootLogService.queryAll(whereJson, page), HttpStatus.OK); } + @PostMapping( "/error") + @Log("查询异常详情") + @ApiOperation("查询异常详情") + public ResponseEntity findError(@RequestBody Map whereJson) { + return new ResponseEntity<>(rootLogService.findError(whereJson), HttpStatus.OK); + } + } diff --git a/nladmin-system/src/main/java/org/nl/modules/log/service/RootLogService.java b/nladmin-system/src/main/java/org/nl/modules/log/service/RootLogService.java index b76d889..9ad1227 100644 --- a/nladmin-system/src/main/java/org/nl/modules/log/service/RootLogService.java +++ b/nladmin-system/src/main/java/org/nl/modules/log/service/RootLogService.java @@ -2,6 +2,7 @@ package org.nl.modules.log.service; import org.springframework.data.domain.Pageable; +import java.text.ParseException; import java.util.Map; /** @@ -10,9 +11,19 @@ import java.util.Map; public interface RootLogService { /** * 查询数据分页 + * * @param whereJson 条件 - * @param page 分页参数 - * @return Map + * @param page 分页参数 + * @return Map */ - Map queryAll(Map whereJson, Pageable page); + Object queryAll(Map whereJson, Pageable page) throws ParseException; + + + /** + * 查询异常详情 + * + * @param whereJson + * @return Log + */ + String findError(Map whereJson); } diff --git a/nladmin-system/src/main/java/org/nl/modules/log/service/impl/RootLogServiceImpl.java b/nladmin-system/src/main/java/org/nl/modules/log/service/impl/RootLogServiceImpl.java index 3f15590..7efc415 100644 --- a/nladmin-system/src/main/java/org/nl/modules/log/service/impl/RootLogServiceImpl.java +++ b/nladmin-system/src/main/java/org/nl/modules/log/service/impl/RootLogServiceImpl.java @@ -1,10 +1,13 @@ package org.nl.modules.log.service.impl; +import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson.JSONObject; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.nl.acs.log.service.LogServer; import org.nl.modules.log.service.RootLogService; import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Sort; import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.mongodb.core.query.Criteria; import org.springframework.data.mongodb.core.query.Query; @@ -14,9 +17,9 @@ import java.util.List; import java.util.Map; /** - * @author ldjun + * @author loujf * @description 服务实现 - * @date 2021-08-19 + * @date 2022-04-02 **/ @Service @RequiredArgsConstructor @@ -25,24 +28,49 @@ public class RootLogServiceImpl implements RootLogService { private final MongoTemplate mongoTemplate; + private final LogServer logServer; + @Override - public Map queryAll(Map whereJson, Pageable page) { - //查询条件 - Query query = Query.query(Criteria.where("level").is("INFO")); + public Map queryAll(Map whereJson, Pageable page){ + String log_type = (String) whereJson.get("log_type"); + String log_level = (String) whereJson.get("log_level"); + String begin_time = (String) whereJson.get("begin_time"); + String end_time = (String) whereJson.get("end_time"); + + Query query = new Query().with(Sort.by("date")); + + if (StrUtil.isEmpty(log_type)) { + log_type = "default"; + } + if (StrUtil.isNotEmpty(log_level)){ + query.addCriteria(Criteria.where("level").is(log_level)); + } + if (StrUtil.isNotEmpty(begin_time) && StrUtil.isNotEmpty(end_time)) { + query.addCriteria(Criteria.where("date") + .gte(begin_time) + .lte(end_time)); + } //根据条件得到的总条数 - long totalSize = mongoTemplate.count(query, Map.class, "log_root"); + long totalSize = mongoTemplate.count(query, Map.class, log_type); //处理分页 query.skip(page.getPageNumber()).limit(page.getPageSize()); - List list = mongoTemplate.find(query, Map.class, "log_root"); - + List list = mongoTemplate.find(query,Map.class, log_type); //封装前端分页查询结果 JSONObject result = new JSONObject(); result.put("content", list); result.put("totalElements", totalSize); - - mongoTemplate.findById("",null,null); return result; } + + @Override + public String findError(Map map) { + String id = (String) map.get("id"); + String marker = (String) map.get("marker"); + Query query = Query.query(Criteria.where("_id").is(id)).with(Sort.by("date")); + JSONObject list = mongoTemplate.findOne(query,JSONObject.class,marker); + + return list.getString("message"); + } } diff --git a/nladmin-system/src/main/java/org/nl/modules/quartz/task/AutoCreateInst.java b/nladmin-system/src/main/java/org/nl/modules/quartz/task/AutoCreateInst.java index 8028932..8c1179c 100644 --- a/nladmin-system/src/main/java/org/nl/modules/quartz/task/AutoCreateInst.java +++ b/nladmin-system/src/main/java/org/nl/modules/quartz/task/AutoCreateInst.java @@ -7,7 +7,6 @@ import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.ObjectUtils; import org.nl.acs.config.AcsConfig; import org.nl.acs.config.server.AcsConfigService; -import org.nl.acs.device_driver.electric_fence.ElectricFenceDeviceDriver; import org.nl.acs.device_driver.lamp_three_color.LampThreecolorDeviceDriver; import org.nl.acs.device_driver.standard_emptypallet_site.StandardEmptyPalletSiteDeviceDriver; import org.nl.acs.device_driver.standard_inspect_site.StandardInspectSiteDeviceDriver; @@ -24,7 +23,6 @@ import org.nl.acs.task.service.TaskService; import org.nl.acs.task.service.dto.TaskDto; import org.nl.modules.log.LogMarkerTypeEnum; import org.nl.utils.SpringContextHolder; -import org.slf4j.MarkerFactory; import org.springframework.stereotype.Component; import java.util.Arrays; @@ -36,331 +34,11 @@ import java.util.List; @Slf4j @Component public class AutoCreateInst { - - /** * 根据任务状态创建指令、生成下一条指令 * 创建指令前需要判断是否条件具备:起始位置是否有货、目标位置是否有货 */ public void run() throws Exception { - TaskService taskserver = SpringContextHolder.getBean(TaskService.class); - InstructionService instructionService = SpringContextHolder.getBean(InstructionService.class); - RouteLineService routeLineService = SpringContextHolder.getBean(RouteLineService.class); - AcsConfigService acsConfigService = SpringContextHolder.getBean(AcsConfigService.class); - List list = taskserver.queryByStauts("0"); - DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); - for (int i = 0; i < list.size(); i++) { - TaskDto acsTask = list.get(i); - String taskid = acsTask.getTask_id(); - String taskcode = acsTask.getTask_code(); - String vehiclecode = acsTask.getVehicle_code(); - String priority = acsTask.getPriority(); - String start_point_code = acsTask.getStart_point_code(); - String start_device_code = acsTask.getStart_device_code(); - String route_plan_code = acsTask.getRoute_plan_code(); - String vehicleType = acsTask.getVehicle_type(); - //是否复合任务 =0非复合任务 - String compound_task = acsTask.getCompound_task(); - String next_point_code = acsTask.getNext_point_code(); - String next_device_code = acsTask.getNext_device_code(); - if (StrUtil.isEmpty(start_device_code)) { - log.info("起点设备:" + start_device_code + "起始设备不能为空,任务号:" + taskcode); - acsTask.setRemark("起始设备不能为空"); - taskserver.updateByCodeFromCache(acsTask); - continue; - } - if (StrUtil.isEmpty(next_device_code)) { - log.info("目标设备:" + next_device_code + "目标设备不能为空,任务号:" + taskcode); - acsTask.setRemark("目标设备不能为空"); - taskserver.updateByCodeFromCache(acsTask); - continue; - } - List instructions = instructionService.queryAll("instruction_status < 2"); - String maxInstnumber = acsConfigService.findConfigFromCache().get(AcsConfig.MAXINSTNUMBER); - if (ObjectUtils.isNotEmpty(maxInstnumber)) { - if (instructions.size() >= Integer.parseInt(maxInstnumber)) { - log.info("系统参数配置最大指令数为:" + maxInstnumber + "无法生成指令"); - acsTask.setRemark("系统参数配置最大指令数为:" + maxInstnumber + "无法生成指令"); - taskserver.updateByCodeFromCache(acsTask); - log.info(LogMarkerTypeEnum.getMarker(LogMarkerTypeEnum.AUTO_CREATE_INST),"系统参数配置最大指令数为:{}无法生成指令",maxInstnumber); - continue; - } - } -// JSONArray acs_deviceja = WQLObject.getWQLObject("acs_device").query("device_name").getResultJSONArray(0); -// for (int j = 0; j < acs_deviceja.size(); j++) { -// JSONObject json = acs_deviceja.getJSONObject(j); -// String device_code = json.optString("device_code"); -// Device deviceByCode = appService.findDeviceByCode(device_code); -// ElectricFenceDeviceDriver electricFenceDeviceDriver; -// if (deviceByCode.getDeviceDriver() instanceof ElectricFenceDeviceDriver) { -// electricFenceDeviceDriver = (ElectricFenceDeviceDriver) deviceByCode.getDeviceDriver(); -// if (electricFenceDeviceDriver.getSuspended()) { -// return; -// } -// } -// } - List allDevice = appService.findAllDevice(); - for (int j = 0; j < allDevice.size(); j++) { - Device deviceByCode = allDevice.get(j); - ElectricFenceDeviceDriver electricFenceDeviceDriver; - if (deviceByCode.getDeviceDriver() instanceof ElectricFenceDeviceDriver) { - electricFenceDeviceDriver = (ElectricFenceDeviceDriver) deviceByCode.getDeviceDriver(); - if (electricFenceDeviceDriver.getSuspended()) { - return; - } - } - } - //特殊任务 起点终点处理 -// if (StrUtil.equals("2", acsTask.getTask_type())) { -// next_device_code = acsTask.getNext_device_code(); -// if (StrUtil.equals(appService.findDeviceTypeByCode(next_device_code), "storage")) { -// next_point_code = next_device_code + "-" + acsTask.getTo_y() + "-" + acsTask.getTo_z(); -// } else { -// next_point_code = next_device_code; -// } -// if(taskserver.querySameTaskByType("2")>0){ -// acsTask.setRemark("该任务类型任务暂不允许生成指令"); -// log.debug("该任务类型任务暂不允许生成指令"); -// taskserver.updateByCodeFromCache(acsTask); -// continue; -// } -// } - - /** - * 开始平均分解校验 - */ - String this_coevice_code = taskserver.queryAssignedByDevice(acsTask.getStart_device_code(), acsTask.getNext_device_code()); - if (StrUtil.isEmpty(this_coevice_code)) { - List shortPathsList = routeLineService.getShortPathLines(start_device_code, acsTask.getNext_device_code(), route_plan_code); - RouteLineDto routeLineDto = shortPathsList.get(0); - String path = routeLineDto.getPath(); - String type = routeLineDto.getType(); - String[] str = path.split("->"); - List pathlist = Arrays.asList(str); - int index = 0; - for (int m = 0; m < pathlist.size(); m++) { - if (pathlist.get(m).equals(start_device_code)) { - index = m + 1; - break; - } - } - next_device_code = pathlist.get(index); - } else { - next_device_code = this_coevice_code; - } - //校验路由关系 - List shortPathsList = routeLineService.getShortPathLines(start_device_code, next_device_code, route_plan_code); - if (ObjectUtils.isEmpty(shortPathsList)) { - acsTask.setRemark("路由不通无法生成指令"); - taskserver.updateByCodeFromCache(acsTask); - continue; - } - - if (!StrUtil.equals(shortPathsList.get(0).getType(), "1")) { - continue; - } - Device startdevice = appService.findDeviceByCode(start_device_code); - Device nextdevice = appService.findDeviceByCode(next_device_code); - if (StrUtil.equals(appService.findDeviceTypeByCode(next_device_code), "storage")) { - next_point_code = next_device_code + "-" + acsTask.getTo_y() + "-" + acsTask.getTo_z(); - } else { - next_point_code = next_device_code; - } - if (ObjectUtils.isEmpty(appService)) { - log.info("地址对应设备未找到"); - continue; - } - if (ObjectUtils.isEmpty(startdevice)) { - log.info("地址对应设备未找到"); - continue; - } - //普通站点 - StandardOrdinarySiteDeviceDriver standardOrdinarySiteDeviceDriver; - StandardInspectSiteDeviceDriver standardInspectSiteDeviceDriver; - StandardEmptyPalletSiteDeviceDriver standardEmptsyPalletSiteDeviceDriver; - LampThreecolorDeviceDriver lampThreecolorDeviceDriver; - - String createTaskCheck = acsConfigService.findConfigFromCache().get(AcsConfig.CREATETASKCHECK); - - if (StrUtil.equals(createTaskCheck, "1")) { - if (startdevice.getDeviceDriver() instanceof StandardInspectSiteDeviceDriver) { - standardInspectSiteDeviceDriver = (StandardInspectSiteDeviceDriver) startdevice.getDeviceDriver(); - if (standardInspectSiteDeviceDriver.getMode() != 2) { - log.info("起点设备:" + startdevice.getDevice_code() + "设备未待机,任务号:" + taskcode); - acsTask.setRemark("起点设备:" + startdevice.getDevice_code() + "设备未待机,任务号:" + taskcode); - taskserver.updateByCodeFromCache(acsTask); - log.info(LogMarkerTypeEnum.getMarker(LogMarkerTypeEnum.AUTO_CREATE_INST),"起点设备:{}设备未待机,任务号:{}",startdevice.getDevice_code(),taskcode); - //this.execute_log.setResource(startdevice.getDevice_code(), startdevice.getDevice_code()); - //this.execute_log.log("起点设备:" + startdevice.getDevice_code() + "设备未待机,任务号:" + taskcode); - continue; - } - } - if (startdevice.getDeviceDriver() instanceof StandardEmptyPalletSiteDeviceDriver) { - standardEmptsyPalletSiteDeviceDriver = (StandardEmptyPalletSiteDeviceDriver) startdevice.getDeviceDriver(); - if (standardEmptsyPalletSiteDeviceDriver.getMode() != 2) { - log.info("目标设备:" + nextdevice.getDevice_code() + "设备未待机,任务号:" + taskcode); - acsTask.setRemark("目标设备:" + nextdevice.getDevice_code() + "设备未待机,任务号:" + taskcode); - taskserver.updateByCodeFromCache(acsTask); - log.info(LogMarkerTypeEnum.getMarker(LogMarkerTypeEnum.AUTO_CREATE_INST),"目标设备:{}设备未待机,任务号:{}",nextdevice.getDevice_code(),taskcode); - //this.execute_log.setResource(nextdevice.getDevice_code(), nextdevice.getDevice_code()); - //this.execute_log.log("目标设备:" + nextdevice.getDevice_code() + "设备未待机,任务号:" + taskcode); - continue; - } - - if (StrUtil.equals(acsTask.getTask_type(), TaskTypeEnum.APPLY_EMPTY.getCode())) { - int nowNumber = standardEmptsyPalletSiteDeviceDriver.getNumber(); - start_point_code = start_point_code + "." + nowNumber; - } - } - - //目的点校验 - if (nextdevice.getDeviceDriver() instanceof StandardInspectSiteDeviceDriver) { - standardInspectSiteDeviceDriver = (StandardInspectSiteDeviceDriver) nextdevice.getDeviceDriver(); - if (standardInspectSiteDeviceDriver.getMode() != 2) { - log.info("目标设备:" + nextdevice.getDevice_code() + "设备未待机,任务号:" + taskcode); - acsTask.setRemark("目标设备:" + nextdevice.getDevice_code() + "设备未待机,任务号:" + taskcode); - taskserver.updateByCodeFromCache(acsTask); - log.info(LogMarkerTypeEnum.getMarker(LogMarkerTypeEnum.AUTO_CREATE_INST),"目标设备:{}设备未待机,任务号:{}",nextdevice.getDevice_code(),taskcode); - //this.execute_log.setResource(nextdevice.getDevice_code(), nextdevice.getDevice_code()); - //this.execute_log.log("目标设备:" + nextdevice.getDevice_code() + "设备未待机,任务号:" + taskcode); - continue; - } - if (standardInspectSiteDeviceDriver.getMove() != 0) { - log.info("目标设备:" + nextdevice.getDevice_code() + "设备不满足放货条件,任务号:" + taskcode); - acsTask.setRemark("目标设备:" + nextdevice.getDevice_code() + "设备不满足放货条件,任务号:" + taskcode); - taskserver.updateByCodeFromCache(acsTask); - log.info(LogMarkerTypeEnum.getMarker(LogMarkerTypeEnum.AUTO_CREATE_INST),"目标设备:{}设备不满足放货条件,任务号:{}",nextdevice.getDevice_code(),taskcode); - //this.execute_log.setResource(nextdevice.getDevice_code(), nextdevice.getDevice_code()); - //this.execute_log.log("目标设备:" + nextdevice.getDevice_code() + "设备不满足放货条件,任务号:" + taskcode); - continue; - } - } - - - if (nextdevice.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { - standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) nextdevice.getDeviceDriver(); - if (standardOrdinarySiteDeviceDriver.getHasGoods() != 0) { - log.info("目标设备:" + nextdevice.getDevice_code() + "有货,无法生成任务,任务号:" + taskcode); - acsTask.setRemark("目标设备:" + nextdevice.getDevice_code() + "有货,无法生成任务,任务号:" + taskcode); - taskserver.updateByCodeFromCache(acsTask); - log.info(LogMarkerTypeEnum.getMarker(LogMarkerTypeEnum.AUTO_CREATE_INST),"目标设备:{}有货,无法生成任务,任务号:{}",nextdevice.getDevice_code(),taskcode); - //this.execute_log.setResource(nextdevice.getDevice_code(), nextdevice.getDevice_code()); - //this.execute_log.log("目标设备:" + nextdevice.getDevice_code() + "有货,无法生成任务,任务号:" + taskcode); - continue; - } - } - - //校验 是否同任务是否存在相同终点、未完成的指令 - int sameqty = instructionService.querySameDestinationInst(next_point_code); - if (sameqty > 0) { - log.info("存在相同终点的指令,任务号:" + taskcode); - acsTask.setRemark("存在相同终点的指令,任务号:" + taskcode); - taskserver.updateByCodeFromCache(acsTask); - log.info(LogMarkerTypeEnum.getMarker(LogMarkerTypeEnum.AUTO_CREATE_INST),"存在相同的指令,任务号:{}",taskcode); - //this.execute_log.setResource(nextdevice.getDevice_code(), nextdevice.getDevice_code()); - //this.execute_log.log("存在相同终点的指令,任务号:" + taskcode); - continue; - } - } - - //空盘位生成指令需要另外逻辑 - if (nextdevice.getDeviceDriver() instanceof StandardEmptyPalletSiteDeviceDriver) { - standardEmptsyPalletSiteDeviceDriver = (StandardEmptyPalletSiteDeviceDriver) nextdevice.getDeviceDriver(); - if (standardEmptsyPalletSiteDeviceDriver.getMode() != 2) { - log.info(("目标设备:" + nextdevice.getDevice_code() + "设备未待机,任务号:" + taskcode)); - acsTask.setRemark("目标设备:" + nextdevice.getDevice_code() + "设备未待机"); - taskserver.updateByCodeFromCache(acsTask); - log.info(LogMarkerTypeEnum.getMarker(LogMarkerTypeEnum.AUTO_CREATE_INST),"目标设备:{}设备未待机,任务号:{}",nextdevice.getDevice_code(),taskcode); - //this.execute_log.setResource(nextdevice.getDevice_code(), nextdevice.getDevice_code()); - //this.execute_log.log("目标设备:" + nextdevice.getDevice_code() + "设备未待机,任务号:" + taskcode); - continue; - } - int max_emptypalletnum = Integer.parseInt(nextdevice.getExtraValue().get("max_emptypalletnum").toString()); - int nowNumber = standardEmptsyPalletSiteDeviceDriver.getNumber(); - if (nowNumber == max_emptypalletnum) { - log.info("目标设备:" + nextdevice.getDevice_code() + "空盘位已满等待入库,任务号:" + taskcode); - acsTask.setRemark("目标设备:" + nextdevice.getDevice_code() + "空盘位已满等待入库,任务号:" + taskcode); - taskserver.updateByCodeFromCache(acsTask); - log.info(LogMarkerTypeEnum.getMarker(LogMarkerTypeEnum.AUTO_CREATE_INST),"目标设备:{}空盘位已满等待入库,任务号:{}",nextdevice.getDevice_code(),taskcode); - //this.execute_log.log("目标设备:" + nextdevice.getDevice_code() + "空盘位已满等待入库,任务号:" + taskcode); - continue; - } - // 查看是否有相同终点的指令 - int sameqty = instructionService.querySameDestinationInst(next_point_code); - if (sameqty > 0) { - log.info("存在相同终点的指令,任务号:" + taskcode); - acsTask.setRemark("存在相同终点的指令,任务号:" + taskcode); - taskserver.updateByCodeFromCache(acsTask); - log.info(LogMarkerTypeEnum.getMarker(LogMarkerTypeEnum.AUTO_CREATE_INST),"存在相同终点的指令,任务号:{}",taskcode); - //this.execute_log.setResource(nextdevice.getDevice_code(), nextdevice.getDevice_code()); - //this.execute_log.log("存在相同终点的指令,任务号:" + taskcode); - continue; - } - next_point_code = next_point_code + "." + (nowNumber + sameqty + 1); - } - if (startdevice.getDeviceDriver() instanceof StandardEmptyPalletSiteDeviceDriver) { - standardEmptsyPalletSiteDeviceDriver = (StandardEmptyPalletSiteDeviceDriver) startdevice.getDeviceDriver(); - - int sameqty = instructionService.querySameOriginInst(start_point_code); - if (sameqty > 0) { - log.info("存在相同终点的指令,任务号:" + taskcode); - acsTask.setRemark("存在相同终点的指令,任务号:" + taskcode); - taskserver.updateByCodeFromCache(acsTask); - log.info(LogMarkerTypeEnum.getMarker(LogMarkerTypeEnum.AUTO_CREATE_INST),"存在相同终点的指令,任务号:{}",taskcode); - //this.execute_log.setResource(nextdevice.getDevice_code(), nextdevice.getDevice_code()); - //this.execute_log.log("存在相同终点的指令,任务号:" + taskcode); - continue; - } - - if (!StrUtil.equals(acsTask.getEmptypallet_num(), "0")) { - Integer.parseInt(acsTask.getEmptypallet_num()); - int num = standardEmptsyPalletSiteDeviceDriver.getNumber() - Integer.parseInt(acsTask.getEmptypallet_num()) + 1 - sameqty; - if (num <= 0) { - acsTask.setRemark("叠盘位可用空盘数量不足无法生成"); - taskserver.updateByCodeFromCache(acsTask); - continue; - } else { - start_point_code = start_point_code + "." + num; - } - } else { - start_point_code = start_point_code + "." + 1; - } - } - Instruction instdto = new Instruction(); - instdto.setInstruction_type(acsTask.getTask_type()); - instdto.setInstruction_id(IdUtil.simpleUUID()); - instdto.setRoute_plan_code(route_plan_code); - instdto.setRemark(acsTask.getRemark()); - instdto.setMaterial(acsTask.getMaterial()); - instdto.setQuantity(acsTask.getQuantity()); - instdto.setTask_id(taskid); - instdto.setTask_code(taskcode); - instdto.setVehicle_code(vehiclecode); - String now = DateUtil.now(); - instdto.setCreate_time(now); - instdto.setCreate_by("auto"); - instdto.setStart_device_code(start_device_code); - instdto.setNext_device_code(next_device_code); - instdto.setStart_point_code(start_point_code); - instdto.setNext_point_code(next_point_code); - instdto.setPriority(priority); - instdto.setInstruction_status("0"); - instdto.setExecute_device_code(start_point_code); - instdto.setVehicle_type(vehicleType); - try { - instructionService.create(instdto); - } catch (Exception e) { - acsTask.setRemark(e.getMessage()); - taskserver.updateByCodeFromCache(acsTask); - continue; - } - log.info("任务号:" + taskcode + "的指令生成成功"); - log.info(LogMarkerTypeEnum.getMarker(LogMarkerTypeEnum.AUTO_CREATE_INST),"任务号:{}的指令生成成功",taskcode); - //创建指令后修改任务状态 - acsTask.setTask_status("1"); - taskserver.update(acsTask); - - } } } diff --git a/nladmin-system/src/main/java/org/nl/modules/quartz/task/ToAgvDevice.java b/nladmin-system/src/main/java/org/nl/modules/quartz/task/ToAgvDevice.java index 76f136c..3576d83 100644 --- a/nladmin-system/src/main/java/org/nl/modules/quartz/task/ToAgvDevice.java +++ b/nladmin-system/src/main/java/org/nl/modules/quartz/task/ToAgvDevice.java @@ -70,7 +70,7 @@ public class ToAgvDevice { SocketMsg deviceInfo = new SocketMsg(json, MsgType.INFO); WebSocketServer.sendInfo(deviceInfo, "toAgvDevice_data"); - // acsToWmsService.feedbackAgv(row); + acsToWmsService.feedbackAgv(agv_rows); } } diff --git a/nladmin-system/src/main/java/org/nl/modules/quartz/task/queryAOrderDterail.java b/nladmin-system/src/main/java/org/nl/modules/quartz/task/queryAOrderDterail.java new file mode 100644 index 0000000..ef86639 --- /dev/null +++ b/nladmin-system/src/main/java/org/nl/modules/quartz/task/queryAOrderDterail.java @@ -0,0 +1,90 @@ +/* + * Copyright 2019-2020 Zheng Jie + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.nl.modules.quartz.task; + +import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import lombok.extern.slf4j.Slf4j; +import org.nl.modules.mnt.websocket.MsgType; +import org.nl.modules.mnt.websocket.SocketMsg; +import org.nl.modules.mnt.websocket.WebSocketServer; +import org.nl.wql.core.bean.ResultBean; +import org.nl.wql.core.bean.WQLObject; +import org.nl.wql.util.WqlUtil; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Component; + +import java.io.IOException; + +/** + * 测试用 + * + * @author Zheng Jie + * @date 2019-01-08 + */ +@Slf4j +@Component +public class queryAOrderDterail { + + public void run() { + try { + WQLObject wo = WQLObject.getWQLObject("acs_produceshiftorder"); + String where = "1=1 and is_deleted= '0'"; + ResultBean rb = wo.query( where, "order_id desc"); + final JSONObject json = rb.pageResult(); + JSONArray newja = new JSONArray(); + JSONArray ja = json.getJSONArray("content"); + for (int i = 0; i < ja.size(); i++) { + JSONObject jo = (JSONObject) ja.get(i); + JSONArray orderDteail_ja = WQLObject.getWQLObject("acs_produceshiftorderdetail").query("is_deleted= '0' and order_id ='" + jo.getString("order_id") + "'").getResultJSONArray(0); + if (orderDteail_ja.size() > 0) { + JSONArray children = new JSONArray(); + for (int j = 0; j < orderDteail_ja.size(); j++) { + JSONObject orderDteail_jo = orderDteail_ja.getJSONObject(j); + JSONObject new_jo = new JSONObject(); + new_jo.put("order_id", orderDteail_jo.getString("orderdetail_id")); + new_jo.put("order_code", orderDteail_jo.getString("orderdetail_code")); + new_jo.put("is_active", orderDteail_jo.getString("is_active")); + new_jo.put("is_delete", orderDteail_jo.getString("is_delete")); + new_jo.put("create_by", orderDteail_jo.getString("create_by")); + new_jo.put("create_time", orderDteail_jo.getString("create_time")); + new_jo.put("update_by", orderDteail_jo.getString("update_by")); + new_jo.put("update_time", orderDteail_jo.getString("update_time")); + new_jo.put("customer_code", orderDteail_jo.getString("customer_code")); + new_jo.put("customer_name", orderDteail_jo.getString("customer_name")); + new_jo.put("order_qty", orderDteail_jo.getString("order_qty")); + new_jo.put("type", "orderDteail"); + jo.put("flag", "1"); + children.add(new_jo); + } + jo.put("children", children); + } + jo.put("type", "order"); + //区分工单明细 + jo.put("flag", "0"); + newja.add(jo); + } + json.put("content", newja); + System.out.println("json:" + json); + SocketMsg deviceInfo = new SocketMsg(json, MsgType.INFO); + WebSocketServer.sendInfo(deviceInfo, "queryAOrderDterail"); + } catch (IOException e) { + e.printStackTrace(); + } + } + +} diff --git a/nladmin-system/src/main/resources/config/application-dev.yml b/nladmin-system/src/main/resources/config/application-dev.yml index 6d94e87..fd4192d 100644 --- a/nladmin-system/src/main/resources/config/application-dev.yml +++ b/nladmin-system/src/main/resources/config/application-dev.yml @@ -8,7 +8,7 @@ spring: druid: db-type: com.alibaba.druid.pool.DruidDataSource driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy - url: jdbc:log4jdbc:mysql://${DB_HOST:192.168.81.252}:${DB_PORT:3306}/${DB_NAME:ndxy2_acs}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true + url: jdbc:log4jdbc:mysql://${DB_HOST:192.168.81.252}:${DB_PORT:3306}/${DB_NAME:hl_zgbz_acs}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true username: ${DB_USER:root} #password: ${DB_PWD:P@ssw0rd} password: ${DB_PWD:Root.123456} @@ -57,13 +57,13 @@ spring: multi-statement-alagvslow: true data: mongodb: - host: 47.97.157.227 + host: 192.168.81.251 port: 27017 database: nlacs redis: #数据库索引 database: ${REDIS_DB:0} - host: ${REDIS_HOST:47.97.157.227} + host: ${REDIS_HOST:127.0.0.1} port: ${REDIS_PORT:6379} password: ${REDIS_PWD:} #连接超时时间 @@ -160,5 +160,5 @@ jetcache: maxIdle: 200 maxTotal: 1000 uri: - - redis://47.97.157.227:6379 + - redis://127.0.0.1:6379 diff --git a/nladmin-system/src/main/resources/log/AcsToErp.xml b/nladmin-system/src/main/resources/log/AcsToErp.xml index 46f3bc9..3eef302 100644 --- a/nladmin-system/src/main/resources/log/AcsToErp.xml +++ b/nladmin-system/src/main/resources/log/AcsToErp.xml @@ -11,7 +11,7 @@ - + diff --git a/nladmin-system/src/main/resources/logback-spring.xml b/nladmin-system/src/main/resources/logback-spring.xml index 6f88ba8..0bb9721 100644 --- a/nladmin-system/src/main/resources/logback-spring.xml +++ b/nladmin-system/src/main/resources/logback-spring.xml @@ -58,7 +58,7 @@ https://juejin.cn/post/6844903775631572999 - 47.97.157.227 + 192.168.81.251 27017 @@ -116,9 +116,9 @@ https://juejin.cn/post/6844903775631572999 - - - + + +