diff --git a/acs2/nladmin-system/src/main/java/org/nl/acs/agv/server/AgvWaitUtil.java b/acs2/nladmin-system/src/main/java/org/nl/acs/agv/server/AgvWaitUtil.java index 3f4b801..92ad2b3 100644 --- a/acs2/nladmin-system/src/main/java/org/nl/acs/agv/server/AgvWaitUtil.java +++ b/acs2/nladmin-system/src/main/java/org/nl/acs/agv/server/AgvWaitUtil.java @@ -44,7 +44,7 @@ public class AgvWaitUtil { // 标准版输送线驱动 StandardCoveyorControlDeviceDriver driver = (StandardCoveyorControlDeviceDriver) device.getDeviceDriver(); // 通知输送线申请取货-1 - driver.writing(1); + driver.writing("toCommand",1); // 判断是否满足条件:action = 1(允许取货) && move = 1(有货) if (driver.getMove() == 1 && driver.getAction() == 1) { String message = "允许AGV取货。"; @@ -83,7 +83,7 @@ public class AgvWaitUtil { // 标准版输送线驱动 StandardCoveyorControlDeviceDriver driver = (StandardCoveyorControlDeviceDriver) device.getDeviceDriver(); // 通知输送线取货完成-2 - driver.writing(2); + driver.writing("toCommand",2); if (driver.getMove() == 0) { String message = "允许AGV取货后离开。"; driver.setMessage(message); @@ -123,7 +123,7 @@ public class AgvWaitUtil { // 标准版输送线驱动 StandardCoveyorControlDeviceDriver driver = (StandardCoveyorControlDeviceDriver) device.getDeviceDriver(); // 通知输送线申请放货-3 - driver.writing(3); + driver.writing("toCommand",3); // 判断是否满足条件:action = 2(允许放货) && move = 0(无货) if (driver.getMove() == 0 && driver.getAction() == 2) { String message = "允许AGV放货。"; @@ -131,7 +131,7 @@ public class AgvWaitUtil { this.deviceExecuteLogService.deviceExecuteLog(deviceCode, "", "", message); flag = true; - if (taskDto.getIs_vehicle().equals("1")) { + if (ObjectUtil.isNotEmpty(taskDto.getIs_vehicle()) && taskDto.getIs_vehicle().equals("1")) { // 获取当前母载具号 taskDto.setVehicle_code(driver.getBarcode()); taskService.update(taskDto); @@ -170,7 +170,7 @@ public class AgvWaitUtil { // 标准版输送线驱动 StandardCoveyorControlDeviceDriver driver = (StandardCoveyorControlDeviceDriver) device.getDeviceDriver(); // 通知输送线放货完成-4 - driver.writing(4); + driver.writing("toCommand",4); if (driver.getMove() == 1) { String message = "允许AGV放货后离开。"; driver.setMessage(message); diff --git a/acs2/nladmin-system/src/main/java/org/nl/acs/agv/server/impl/XianGongAgvServiceImpl.java b/acs2/nladmin-system/src/main/java/org/nl/acs/agv/server/impl/XianGongAgvServiceImpl.java index f574cf1..3c5c9bb 100644 --- a/acs2/nladmin-system/src/main/java/org/nl/acs/agv/server/impl/XianGongAgvServiceImpl.java +++ b/acs2/nladmin-system/src/main/java/org/nl/acs/agv/server/impl/XianGongAgvServiceImpl.java @@ -147,7 +147,9 @@ public class XianGongAgvServiceImpl implements XianGongAgvService { // 三色灯驱动 LampThreecolorDeviceDriver driver = (LampThreecolorDeviceDriver) device.getDeviceDriver(); // 给三色灯写入进入命令0-离开,1-进入 - driver.writing(1,3); + String[] key = {"toCommand","toColor"}; + Integer[] value = {1,3}; + driver.writing(Arrays.asList(key),Arrays.asList(value)); // 判断是否允许进入 1-允许,0-不允许 if (driver.getAction() == 1) { @@ -184,12 +186,14 @@ public class XianGongAgvServiceImpl implements XianGongAgvService { // 三色灯驱动 LampThreecolorDeviceDriver driver = (LampThreecolorDeviceDriver) device.getDeviceDriver(); // 给三色灯写入进入命令0-离开,1-进入 - driver.writing(0,Integer.parseInt(device.getExtraValue().get("color").toString())); + String[] key = {"toCommand","toColor"}; + Integer[] value = {0,Integer.parseInt(device.getExtraValue().get("color").toString())}; + driver.writing(Arrays.asList(key),Arrays.asList(value)); // 判断是否允许离开 1-允许,0-不允许 if (driver.getAction() == 1) { // 判断是否清楚车号 - if (device.getExtraValue().get("color").toString().equals("1")) { + if (device.getExtraValue().get("is_clean").toString().equals("1")) { driver.setCar_no(""); } result.put("code", 200); diff --git a/acs2/nladmin-system/src/main/java/org/nl/acs/device/wql/task_inst.xls b/acs2/nladmin-system/src/main/java/org/nl/acs/device/wql/task_inst.xls index b386166..3ae1214 100644 Binary files a/acs2/nladmin-system/src/main/java/org/nl/acs/device/wql/task_inst.xls and b/acs2/nladmin-system/src/main/java/org/nl/acs/device/wql/task_inst.xls differ diff --git a/acs2/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_conveyor_control/ItemProtocol.java b/acs2/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_conveyor_control/ItemProtocol.java index df1ca69..805f5e3 100644 --- a/acs2/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_conveyor_control/ItemProtocol.java +++ b/acs2/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_conveyor_control/ItemProtocol.java @@ -1,137 +1,62 @@ package org.nl.acs.device_driver.basedriver.standard_conveyor_control; -import lombok.Getter; -import lombok.Setter; -import lombok.extern.slf4j.Slf4j; + import org.nl.acs.device.device_driver.standard_inspect.ItemDTO; +import org.nl.acs.device_driver.DeviceDriverBaseReader; -import java.util.ArrayList; import java.util.List; +import java.util.ArrayList; -@Slf4j -@Getter -@Setter -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_height = "height"; - public static String item_error = "error"; - public static String item_direction = "direction"; - public static String item_operation_type = "operation_type"; - public static String item_task = "task"; - 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_weight = "weight"; - - private StandardCoveyorControlDeviceDriver driver; - - public ItemProtocol(StandardCoveyorControlDeviceDriver driver) { - this.driver = driver; - } - - public int getHeartbeat() { - return this.getOpcIntegerValue(item_heartbeat); - } - - public String getBarcode() { - return this.getOpcStringValue(item_barcode); - } - - 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 getError() { - return this.getOpcIntegerValue(item_error); - } +public enum ItemProtocol implements DeviceDriverBaseReader.KeyProvider { + HEARTBEAT("heartbeat", "心跳", "DB600.B0"), + MODE("mode", "工作模式", "DB600.B1"), + MOVE("move", "光电信号", "DB600.B2"), + ACTION("action", "取放信号", "DB600.B3"), + ERROR("error", "报警信号", "DB600.B4"), + BARCODE("barcode", "托盘号", "DB600.D1"), + TO_COMMAND("toCommand", "下发命令", "DB601.W1"); - public int getOperation_type() { - return this.getOpcIntegerValue(item_operation_type); - } + private final String key; + private final String description; + private final String address; - public int getTask() { - return this.getOpcIntegerValue(item_task); + ItemProtocol(String key, String description, String address) { + this.key = key; + this.description = description; + this.address = address; } - public int getToCommand() { - return this.getOpcIntegerValue(item_to_command); + @Override + public String getKey() { + return this.key; } - public int getToTarget() { - return this.getOpcIntegerValue(item_to_target); + public String getDescription() { + return description; } - public int getToTask() { - 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 String getOpcStringValue(String protocol) { - String value = this.driver.getStringValue(protocol); - if (value == null) { - //throw new BusinessException("{} : {}", new Object[]{protocol, DeviceErrorProtocol.getMessage(10000)}); - } else { - return value; - } - return "0"; + public String getAddress() { + return address; } 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_move, "光电开关信号", "DB600.B2")); - list.add(new ItemDTO(item_action, "取放信号", "DB600.B3")); - list.add(new ItemDTO(item_ioaction, "进出类型", "DB600.B4")); - list.add(new ItemDTO(item_height, "高度类型", "DB600.B5")); - list.add(new ItemDTO(item_error, "报警信号", "DB600.B6")); - list.add(new ItemDTO(item_direction, "电机方向", "DB600.B7")); - list.add(new ItemDTO(item_operation_type, "作业类型", "DB600.B8")); - list.add(new ItemDTO(item_task, "任务号", "DB600.D22")); + List list = new ArrayList<>(); + for (ItemProtocol prop : values()) { + if (!prop.getKey().startsWith("to")) { + list.add(new ItemDTO(prop.getKey(), prop.getDescription(), prop.getAddress())); + } + } 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 list = new ArrayList<>(); + for (ItemProtocol prop : values()) { + if (prop.getKey().startsWith("to")) { + list.add(new ItemDTO(prop.getKey(), prop.getDescription(), prop.getAddress())); + } + } return list; } } - diff --git a/acs2/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_conveyor_control/StandardConveyorControlDefinition.java b/acs2/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_conveyor_control/StandardConveyorControlDefinition.java index a15474e..ab8834b 100644 --- a/acs2/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_conveyor_control/StandardConveyorControlDefinition.java +++ b/acs2/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_conveyor_control/StandardConveyorControlDefinition.java @@ -10,10 +10,6 @@ import org.springframework.stereotype.Service; import java.util.LinkedList; import java.util.List; -/** - * 检测站点驱动定义 - * 说明:该站点为普通带光电检测站点 - */ @Service public class StandardConveyorControlDefinition implements OpcDeviceDriverDefinition { @Override @@ -23,18 +19,17 @@ public class StandardConveyorControlDefinition implements OpcDeviceDriverDefinit @Override public String getDriverName() { - return "标准版-输送机-控制点"; + return "标准版-输送线"; } @Override public String getDriverDescription() { - return "标准版-输送机-控制点"; + return "标准版-输送线"; } @Override public DeviceDriver getDriverInstance(Device device) { return (new StandardCoveyorControlDeviceDriver()).setDevice(device).setDriverDefinition(this); - } @Override @@ -54,10 +49,8 @@ public class StandardConveyorControlDefinition implements OpcDeviceDriverDefinit return ItemProtocol.getReadableItemDtos(); } - @Override public List getWriteableItemDTOs() { return ItemProtocol.getWriteableItemDtos(); } - } diff --git a/acs2/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_conveyor_control/StandardCoveyorControlDeviceDriver.java b/acs2/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_conveyor_control/StandardCoveyorControlDeviceDriver.java index 67a9278..76d7e38 100644 --- a/acs2/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_conveyor_control/StandardCoveyorControlDeviceDriver.java +++ b/acs2/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/standard_conveyor_control/StandardCoveyorControlDeviceDriver.java @@ -1,485 +1,154 @@ package org.nl.acs.device_driver.basedriver.standard_conveyor_control; -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.Getter; -import lombok.Setter; import lombok.RequiredArgsConstructor; +import lombok.Setter; 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.DeviceDriverBaseReader; import org.nl.acs.device_driver.RouteableDeviceDriver; +import org.nl.acs.device_driver.StandardRequestMethod; import org.nl.acs.device_driver.driver.AbstractOpcDeviceDriver; import org.nl.acs.device_driver.driver.ExecutableDeviceDriver; -import org.nl.acs.ext.wms.service.AcsToWmsService; -import org.nl.acs.ext.wms.service.impl.AcsToWmsServiceImpl; -import org.nl.acs.instruction.service.InstructionService; -import org.nl.acs.instruction.service.dto.Instruction; -import org.nl.acs.log.service.DeviceExecuteLogService; import org.nl.acs.monitor.DeviceStageMonitor; import org.nl.acs.opc.Device; -import org.nl.acs.opc.DeviceAppService; -import org.nl.acs.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.service.ParamService; -import org.nl.modules.system.util.CodeUtil; -import org.nl.modules.wql.core.bean.WQLObject; +import org.nl.modules.lucene.service.LuceneExecuteLogService; +import org.nl.modules.lucene.service.dto.LuceneLogDto; import org.nl.modules.wql.util.SpringContextHolder; -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 @Getter @Setter @RequiredArgsConstructor -public class StandardCoveyorControlDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver, DeviceStageMonitor { - protected ItemProtocol itemProtocol = new ItemProtocol(this); - - DeviceAppService deviceAppservice = SpringContextHolder.getBean(DeviceAppService.class); - - InstructionService instructionService = SpringContextHolder.getBean("instructionServiceImpl"); - - DeviceService deviceservice = SpringContextHolder.getBean("deviceServiceImpl"); - - RouteLineService routelineserver = SpringContextHolder.getBean("routeLineServiceImpl"); - - TaskService taskserver = SpringContextHolder.getBean("taskServiceImpl"); - - RouteLineService routeLineService = SpringContextHolder.getBean(RouteLineService.class); - - AcsToWmsService acsToWmsService = SpringContextHolder.getBean(AcsToWmsServiceImpl.class); - - ParamService paramService = SpringContextHolder.getBean(ParamService.class); - DeviceExecuteLogService logServer = SpringContextHolder.getBean("deviceExecuteLogServiceImpl"); - - - String container; - String container_type_desc; - String last_container_type_desc; - String last_container; - //放货准备锁 - String putReadyLock = null; - //有货标记 - protected boolean has_goods_tag = false; +public class StandardCoveyorControlDeviceDriver extends AbstractOpcDeviceDriver implements + DeviceDriver, + ExecutableDeviceDriver, + RouteableDeviceDriver, + DeviceStageMonitor, + StandardRequestMethod, + DeviceDriverBaseReader { - int mode = 0; - int error = 0; - int move = 0; - int action = 0; - String barcode = null; - int task = 0; - //出入库模式 - int operation_type = 0; - int last_mode = 0; - int last_error = 0; - int last_move = 0; - int last_task = 0; + private final LuceneExecuteLogService logService = SpringContextHolder.getBean(LuceneExecuteLogService.class); - 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 Date instruction_apply_time = new Date(); - private int instruction_require_time_out = 3000; - //请求成功标记 - Boolean requireSucess = false; - //申请指令成功标记 - Boolean applySucess = false; - String inst_message; - - private int instruction_finished_time_out; + /** + * 心跳 + */ + private int heartbeat = 0; + private int lastHeartbeat = 0; + /** + * 工作模式 + */ + private int mode = 0; + private int lastMode = 0; + /** + * 光电信号 + */ + private int move = 0; + private int lastMove = 0; + /** + * 取放信号 + */ + private int action = 0; + private int lastAction = 0; + /** + * 报警信号 + */ + private int error = 0; + private int lastError = 0; + /** + * 托盘号 + */ + private String barcode; + private String lastBarcode; + /** + * 下发命令 + */ + private int toCommand = 0; + private int lastToCommand = 0; + /** + * 当前设备编号 + */ + private String currentDeviceCode; - int branchProtocol = 0; - //备注 - String remark; - //数量 - String qty; - //物料 - String material; - //当前指令 - Instruction inst = null; - //上次指令 - Instruction last_inst = null; + /** + * 消息 + */ + private String message; - //触摸屏手动触发任务 - private Boolean is_has_task = false; + /** + * 请求标记 + */ + boolean requireSuccess = false; - //申请搬运任务 - private Boolean apply_handling = false; - //申请物料 - private Boolean apply_material = false; + /** + * 请求时间 + */ + private long requireTime = System.currentTimeMillis(); - //暂定 0就绪 1请求取货 2取货完成 3请求放货 4放货完成 5取货完成离开 6放货完成离开 7请求进入区域 8请求离开区域 - int flag = 0; + /** + * 请求间隔时间 + */ + private long requireTimeOut = 3000L; - String device_code; + /** + * 设备异常标记 + */ + private boolean isError = false; @Override public Device getDevice() { return this.device; } - @Override - public void execute() throws Exception { - String message = null; - try { - device_code = this.getDeviceCode(); - mode = this.itemProtocol.getMode(); - error = this.itemProtocol.getError(); - move = this.itemProtocol.getMove(); - task = this.itemProtocol.getTask(); - action = this.itemProtocol.getAction(); - barcode = this.itemProtocol.getBarcode(); - hasGoods = this.itemProtocol.getMove(); - operation_type = this.itemProtocol.getOperation_type(); - if (mode != last_mode) { - } - if (move != last_move) { - if (move == 0) { - thingToNothing(); - } - this.setRequireSucess(false); - - } - if (error != last_error) { - } - - /* if (mode == 2 && move != 0 && task > 0) { - //inst_message - inst = instructionService.findByCodeFromCache(String.valueOf(task)); - if (inst != null) { - inst_message = "指令号:" + inst.getInstruction_code() + " " + inst.getStart_point_code() + " -> " + inst.getNext_point_code() + " 载具号:" + inst.getVehicle_code(); - if (StrUtil.equals(inst.getInstruction_status(), "1") && StrUtil.equals(this.getDeviceCode(), inst.getNext_device_code())) { - finish_instruction(); - } - if (StrUtil.equals(inst.getInstruction_status(), "0") && StrUtil.equals(this.getDeviceCode(), inst.getStart_device_code())) { - inst.setInstruction_status("1"); - instructionService.update(inst); - } - } - }*/ - } 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("设备运转模式:等待工作"); - break; - case 2: - //申请任务 - break; - case 3: - - break; - case 4: - //叫料 - - break; - case 5: - //申请空盘 - break; - case 6: - //申请入库 - break; - } - - - switch (flag) { - //取货完成 - case 1: - writing(2); - break; - //放货完成 - case 2: - writing(3); - break; - - } - - } - last_mode = mode; - last_error = error; - last_move = move; - last_task = task; - } - - public boolean exe_error() { - if (this.error == 0) { - return true; - } else { - log.debug("设备报警"); - return false; - } - } - - protected void thingToNothing() { - log.debug("从有货到无货 清理数据"); - this.setRequireSucess(false); - this.setApplySucess(false); - this.set_last_container(container, container_type_desc); - } - - public void set_last_container(String barcode, String type_desc) { - this.setInst_message(null); - this.setContainer(null); - 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); - server.disconnect(); - + public & KeyProvider, T> T getOpcValue(E item, Class fieldClassType) { + return (T) this.getValue(item.getKey()); } - public void executing(Server server, Map itemMap) { - ReadUtil.write(itemMap, server); - server.disconnect(); - } - - 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); - ReadUtil.write(itemMap, server); - server.disconnect(); - logServer.deviceExecuteLog(this.device_code, "", "", "to_command 写入 " + command); - } - - public void writing(int command, int target, int task) { - - 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(); - itemMap.put(to_command, command); - itemMap.put(to_target, target); - itemMap.put(to_task, task); - ReadUtil.write(itemMap, server); - server.disconnect(); - } - - 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); - server.disconnect(); - - } - - public boolean instruction_apply() throws Exception { - return false; - } - - 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.isBlank(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 synchronized boolean finish_instruction() throws Exception { - instructionService.finish(inst); - return true; + @Override + public void setLog(String key, Object newValue, Object oldValue) { + logService.deviceExecuteLog(new LuceneLogDto(this.currentDeviceCode, "自动线程读取信号:" + key + ",由" + oldValue + "->" + newValue)); } - public void apply_OutEmpty() { - + @Override + public void execute() { + this.currentDeviceCode = this.getDevice().getDevice_code(); + this.loadAssignData(currentDeviceCode, ItemProtocol.class); } - public synchronized boolean apply_InEmpty() throws Exception { - return false; + @Override + public void executeLogic() { + if (!this.online) { + this.message = "设备离线"; + } else if (this.mode == 0) { + this.message = "设备未联机"; + } else if (this.error != 0) { + this.message = "设备报警"; + this.isError = true; + } else { + this.isError = false; + this.message = ""; + //编写业务逻辑方法 + } } @Override - public JSONObject getDeviceStatusName() { - JSONObject jo = new JSONObject(); - String mode = ""; - String action = ""; - String move = ""; - if (this.getMode() == 0) { - mode = "未联机"; - } else if (this.getMode() == 1) { - mode = "单机"; - } else if (this.getMode() == 2) { - mode = "联机"; - } else if (this.getMode() == 3) { - mode = "运行中"; - } - - if (this.getMove() == 0) { - move = "无货"; - jo.put("hasGoods", false); - } else if (this.getMove() == 1) { - move = "有货"; - jo.put("hasGoods", true); - } else if (this.getMove() == 2) { - move = "有托盘有货"; - jo.put("hasGoods", true); - } - jo.put("device_name", this.getDevice().getDevice_name()); - jo.put("mode", mode); - jo.put("move", move); - jo.put("action", action); - jo.put("isOnline", this.getIsonline()); - jo.put("error", this.getError()); - jo.put("isError", this.getIserror()); - jo.put("task", this.getTask()); - return jo; + public JSONObject getDeviceStatusName() throws Exception { + JSONObject jo = new JSONObject(); + jo.put("device_code", this.currentDeviceCode); + jo.put("device_name", this.getDevice().getDevice_name()); + jo.put("driver_type", "standard_conveyor_control"); + jo.put("is_click", false); + jo.put("message", this.message); + jo.put("isOnline", this.online); + jo.put("isError", this.isError); + return jo; } @Override public void setDeviceStatus(JSONObject data) { - + } + } diff --git a/acs2/nladmin-system/src/main/java/org/nl/acs/device_driver/lamp_three_color/ItemProtocol.java b/acs2/nladmin-system/src/main/java/org/nl/acs/device_driver/lamp_three_color/ItemProtocol.java index ed01e38..7aa5518 100644 --- a/acs2/nladmin-system/src/main/java/org/nl/acs/device_driver/lamp_three_color/ItemProtocol.java +++ b/acs2/nladmin-system/src/main/java/org/nl/acs/device_driver/lamp_three_color/ItemProtocol.java @@ -1,80 +1,63 @@ package org.nl.acs.device_driver.lamp_three_color; -import lombok.extern.slf4j.Slf4j; + import org.nl.acs.device.device_driver.standard_inspect.ItemDTO; +import org.nl.acs.device_driver.DeviceDriverBaseReader; +import org.nl.acs.device_driver.ItemDto; -import java.util.ArrayList; import java.util.List; +import java.util.ArrayList; -@Slf4j -public class ItemProtocol { - public static String item_heartbeat = "heartbeat"; - public static String item_mode = "mode"; - public static String item_action = "action"; - public static String item_error = "error"; - public static String item_to_command = "toCommand"; - public static String item_to_color = "toColor"; - public static String item_color = "color"; - - - private LampThreecolorDeviceDriver driver; - - public ItemProtocol(LampThreecolorDeviceDriver driver) { - this.driver = driver; - } - - public int getHeartbeat() { - return this.getOpcIntegerValue(item_heartbeat); - } - - public int getColor() { - return this.getOpcIntegerValue(item_color); - } +public enum ItemProtocol implements DeviceDriverBaseReader.KeyProvider { + HEARTBEAT("heartbeat", "心跳", "DB51.B0"), + MODE("mode", "工作模式", "DB51.B1"), + ACTION("action", "是否允许进入", "DB51.B2"), + ERROR("error", "报警信号", "DB51.B4"), + COLOR("color", "颜色", "DB51.B5"), + TO_COMMAND("toCommand", "作业命令", "DB52.W2"), + TO_COLOR("toColor", "下发颜色", "DB52.W3"); - public int getMode() { - return this.getOpcIntegerValue(item_mode); - } + private final String key; + private final String description; + private final String address; - public int getAction() { - return this.getOpcIntegerValue(item_action); + ItemProtocol(String key, String description, String address) { + this.key = key; + this.description = description; + this.address = address; } - public int getError() { - return this.getOpcIntegerValue(item_error); + @Override + public String getKey() { + return this.key; } - public int getToCommand() { - return this.getOpcIntegerValue(item_to_command); + public String getDescription() { + return description; } - - public int getOpcIntegerValue(String protocol) { - Integer value = this.driver.getIntegeregerValue(protocol); - if (value == null) { - //log.error("读取错误!"); - } else { - return value; - } - return 0; - + public String getAddress() { + return address; } public static List getReadableItemDtos() { - ArrayList list = new ArrayList(); - list.add(new ItemDTO(item_heartbeat, "心跳", "DB51.B0")); - list.add(new ItemDTO(item_mode, "工作模式", "DB51.B1", Boolean.valueOf(true))); - list.add(new ItemDTO(item_action, "是否允许进入", "DB51.B2")); - list.add(new ItemDTO(item_error, "报警信号", "DB51.B4")); - list.add(new ItemDTO(item_color, "颜色", "DB51.B5")); + List list = new ArrayList<>(); + for (ItemProtocol prop : values()) { + if (!prop.getKey().startsWith("to")) { + list.add(new ItemDTO(prop.getKey(), prop.getDescription(), prop.getAddress())); + } + } return list; } public static List getWriteableItemDtos() { - ArrayList list = new ArrayList(); - list.add(new ItemDTO(item_to_command, "作业命令", "DB52.W2", Boolean.valueOf(true))); - list.add(new ItemDTO(item_to_color, "颜色", "DB52.W3", Boolean.valueOf(true))); + List list = new ArrayList<>(); + for (ItemProtocol prop : values()) { + if (prop.getKey().startsWith("to")) { + list.add(new ItemDTO(prop.getKey(), prop.getDescription(), prop.getAddress())); + } + } return list; } } - diff --git a/acs2/nladmin-system/src/main/java/org/nl/acs/device_driver/lamp_three_color/LampThreecolorDefinition.java b/acs2/nladmin-system/src/main/java/org/nl/acs/device_driver/lamp_three_color/LampThreecolorDefinition.java index 79915f5..ac6ce9b 100644 --- a/acs2/nladmin-system/src/main/java/org/nl/acs/device_driver/lamp_three_color/LampThreecolorDefinition.java +++ b/acs2/nladmin-system/src/main/java/org/nl/acs/device_driver/lamp_three_color/LampThreecolorDefinition.java @@ -1,19 +1,15 @@ package org.nl.acs.device_driver.lamp_three_color; - import org.nl.acs.device.device_driver.standard_inspect.ItemDTO; import org.nl.acs.device_driver.DeviceDriver; +import org.nl.acs.device_driver.ItemDto; import org.nl.acs.device_driver.definition.OpcDeviceDriverDefinition; 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 LampThreecolorDefinition implements OpcDeviceDriverDefinition { @Override @@ -34,7 +30,6 @@ public class LampThreecolorDefinition implements OpcDeviceDriverDefinition { @Override public DeviceDriver getDriverInstance(Device device) { return (new LampThreecolorDeviceDriver()).setDevice(device).setDriverDefinition(this); - } @Override @@ -45,22 +40,19 @@ public class LampThreecolorDefinition implements OpcDeviceDriverDefinition { @Override public List getFitDeviceTypes() { List types = new LinkedList(); - types.add(DeviceType.conveyor); + types.add(DeviceType.color); return types; } + @Override public List getReadableItemDTOs() { - return getReadableItemDtos2(); - } - - public static List getReadableItemDtos2() { return ItemProtocol.getReadableItemDtos(); } @Override public List getWriteableItemDTOs() { return ItemProtocol.getWriteableItemDtos(); - } + } } diff --git a/acs2/nladmin-system/src/main/java/org/nl/acs/device_driver/lamp_three_color/LampThreecolorDeviceDriver.java b/acs2/nladmin-system/src/main/java/org/nl/acs/device_driver/lamp_three_color/LampThreecolorDeviceDriver.java index 6efb55c..888aff9 100644 --- a/acs2/nladmin-system/src/main/java/org/nl/acs/device_driver/lamp_three_color/LampThreecolorDeviceDriver.java +++ b/acs2/nladmin-system/src/main/java/org/nl/acs/device_driver/lamp_three_color/LampThreecolorDeviceDriver.java @@ -2,120 +2,148 @@ package org.nl.acs.device_driver.lamp_three_color; import com.alibaba.fastjson.JSONObject; import lombok.Getter; -import lombok.Setter; import lombok.RequiredArgsConstructor; +import lombok.Setter; import lombok.extern.slf4j.Slf4j; import org.nl.acs.agv.server.impl.XianGongAgvServiceImpl; -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.DeviceDriverBaseReader; +import org.nl.acs.device_driver.RouteableDeviceDriver; +import org.nl.acs.device_driver.StandardRequestMethod; import org.nl.acs.device_driver.driver.AbstractOpcDeviceDriver; import org.nl.acs.device_driver.driver.ExecutableDeviceDriver; import org.nl.acs.ext.UnifiedResponse; -import org.nl.acs.instruction.service.InstructionService; +import org.nl.acs.monitor.DeviceStageMonitor; import org.nl.acs.opc.Device; -import org.nl.acs.route.service.RouteLineService; -import org.nl.acs.task.service.TaskService; +import org.nl.modules.lucene.service.LuceneExecuteLogService; +import org.nl.modules.lucene.service.dto.LuceneLogDto; import org.nl.modules.wql.util.SpringContextHolder; -import org.openscada.opc.lib.da.Server; -import org.springframework.beans.factory.annotation.Autowired; -import java.util.*; - -/** - * 检测站点驱动 - */ @Slf4j @Getter @Setter @RequiredArgsConstructor -public class LampThreecolorDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver { - protected ItemProtocol itemProtocol = new ItemProtocol(this); - - InstructionService instructionService = SpringContextHolder.getBean("instructionServiceImpl"); - - DeviceService deviceservice = SpringContextHolder.getBean("deviceServiceImpl"); - - RouteLineService routelineserver = SpringContextHolder.getBean("routeLineServiceImpl"); - - 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 action = 0; - int heartbeat = 0; - int color = 0; - int error = 0; - int move = 0; - int task = 0; - int last_action = 0; - int last_mode = 0; - int last_error = 0; - int last_move = 0; - int last_task = 0; - - String car_no = ""; - - boolean hasVehicle = false; - boolean isReady = false; - protected int instruction_num = 0; - protected int instruction_num_truth = 0; - protected boolean hasGoods = false; - 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; - boolean requireSucess = false; - - private int instruction_finished_time_out; - - int branchProtocol = 0; +public class LampThreecolorDeviceDriver extends AbstractOpcDeviceDriver implements + DeviceDriver, + ExecutableDeviceDriver, + RouteableDeviceDriver, + DeviceStageMonitor, + StandardRequestMethod, + DeviceDriverBaseReader { + + private final LuceneExecuteLogService logService = SpringContextHolder.getBean(LuceneExecuteLogService.class); + + /** + * 心跳 + */ + private int heartbeat = 0; + private int lastHeartbeat = 0; + /** + * 工作模式 + */ + private int mode = 0; + private int lastMode = 0; + /** + * 是否允许进入 + */ + private int action = 0; + private int lastAction = 0; + /** + * 报警信号 + */ + private int error = 0; + private int lastError = 0; + /** + * 颜色 + */ + private int color = 0; + private int lastColor = 0; + /** + * 作业命令 + */ + private int toCommand = 0; + private int lastToCommand = 0; + /** + * 下发颜色 + */ + private int toColor = 0; + private int lastToColor = 0; + /** + * 当前设备编号 + */ + private String currentDeviceCode; + + /** + * 消息 + */ + private String message; + + /** + * 请求标记 + */ + boolean requireSuccess = false; + + /** + * 请求时间 + */ + private long requireTime = System.currentTimeMillis(); + + /** + * 请求间隔时间 + */ + private long requireTimeOut = 3000L; + + /** + * 设备异常标记 + */ + private boolean isError = false; + + /** + * 车号 + */ + private String car_no; @Override public Device getDevice() { return this.device; } + @Override + public & KeyProvider, T> T getOpcValue(E item, Class fieldClassType) { + return (T) this.getValue(item.getKey()); + } + + @Override + public void setLog(String key, Object newValue, Object oldValue) { + logService.deviceExecuteLog(new LuceneLogDto(this.currentDeviceCode, "自动线程读取信号:" + key + ",由" + oldValue + "->" + newValue)); + } @Override public void execute() { - String message = null; - - String device_code = this.getDevice().getDevice_code(); - heartbeat = this.itemProtocol.getHeartbeat(); - mode = this.itemProtocol.getMode(); - action = this.itemProtocol.getAction(); - error = this.itemProtocol.getError(); - color = this.itemProtocol.getColor(); - if (mode != last_mode) { - } - if (action != last_action) { - } - if (error != last_error) { - } - last_action = action; - last_mode = mode; - last_error = error; + this.currentDeviceCode = this.getDevice().getDevice_code(); + this.loadAssignData(currentDeviceCode, ItemProtocol.class); + } + + @Override + public void executeLogic() { + + this.executeLogicBefore(); + if (!this.online) { + this.message = "设备离线"; + } else if (this.mode == 0) { + this.message = "设备未联机"; + } else if (this.error != 0) { + this.message = "设备报警"; + this.isError = true; + } else { + this.isError = false; + this.message = ""; + //编写业务逻辑方法 + } + } + + private void executeLogicBefore() { if (error == 1) { String[] carArr = {car_no}; JSONObject json = new JSONObject(); @@ -123,76 +151,26 @@ public class LampThreecolorDeviceDriver extends AbstractOpcDeviceDriver implemen // 请求下发agv急停 XianGongAgvServiceImpl xianGongAgv = SpringContextHolder.getBean(XianGongAgvServiceImpl.class); //创建订单序列 - UnifiedResponse response = xianGongAgv.sendOrderStopToXZ(json); - - if (!response.isSuccess()) { - } else { - } - } - - //message = StringFormatUtl.format("设备报警:{}", new Object[]{}); -// String manual_create_task = this.getDevice().getExtraValue().get("manual_create_task").toString(); - - - } - - public synchronized String getStatus() { - JSONObject jo = new JSONObject(); - - if (action == 1) { - jo.put("name", this.getDevice().getDevice_code()); - jo.put("status", "OPEN"); - - } else if (action == 2) { - jo.put("name", this.getDevice().getDevice_code()); - jo.put("status", "CLOSE"); - - } else { - jo.put("name", this.getDevice().getDevice_code()); - jo.put("status", "ERROR"); + xianGongAgv.sendOrderStopToXZ(json); } - return jo.toString(); - } - - - 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); - ReadUtil.write(itemMap, server); - server.disconnect(); - log.info("下发PLC信号:{},{}", to_command, command); - System.out.println("设备:" + devicecode + ",下发PLC信号:" + to_command + ",value:" + command); } - public void writing(int command,int color) { - String toCommand = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() - + "." + ItemProtocol.item_to_command; - - String toColor = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() - + "." + ItemProtocol.item_to_color; - - String opcservcerid = this.getDevice().getOpc_server_id(); - Server server = ReadUtil.getServer(opcservcerid); - Map itemMap = new HashMap(); - itemMap.put(toCommand, command); - itemMap.put(toColor, color); - ReadUtil.write(itemMap, server); - ReadUtil.write(itemMap, server); - server.disconnect(); - log.info("下发PLC信号:{},{}", toCommand, command); - log.info("下发PLC信号:{},{}", toColor, color); - System.out.println("设备:" + devicecode + ",下发PLC信号:" + toCommand + ",value:" + command); - System.out.println("设备:" + devicecode + ",下发PLC信号:" + toColor + ",value:" + color); + @Override + public JSONObject getDeviceStatusName() throws Exception { + JSONObject jo = new JSONObject(); + jo.put("device_code", this.currentDeviceCode); + jo.put("device_name", this.getDevice().getDevice_name()); + jo.put("driver_type", "lamp_three_color"); + jo.put("is_click", false); + jo.put("message", this.message); + jo.put("isOnline", this.online); + jo.put("isError", this.isError); + return jo; } - public synchronized void OpenOrClose(String type) { - writing(Integer.parseInt(type)); + @Override + public void setDeviceStatus(JSONObject data) { + } } diff --git a/acs2/nladmin-system/src/main/java/org/nl/config/mqtt2/MqttService.java b/acs2/nladmin-system/src/main/java/org/nl/config/mqtt2/MqttService.java index ead4dba..94b58dc 100644 --- a/acs2/nladmin-system/src/main/java/org/nl/config/mqtt2/MqttService.java +++ b/acs2/nladmin-system/src/main/java/org/nl/config/mqtt2/MqttService.java @@ -57,7 +57,7 @@ public class MqttService implements ApplicationAutoInitial { @Autowired private DeviceAppService deviceAppService; - + private final CountDownLatch latch = new CountDownLatch(1); private Mqtt3AsyncClient mqttClient; /** @@ -169,7 +169,7 @@ public class MqttService implements ApplicationAutoInitial { .serverHost(mqttConfig.getUrl()) .addDisconnectedListener((context -> { Throwable cause = context.getCause(); - log.error("mqtt client disconnected , {}", cause.getMessage()); + log.error("[MQTT 断开连接, {}]", cause.getMessage()); MqttClientReconnector reconnect = context.getReconnector(); reconnect.reconnect(true); reconnect.delay(RECONNECT_DELAY, TimeUnit.MILLISECONDS); @@ -188,11 +188,11 @@ public class MqttService implements ApplicationAutoInitial { .cleanSession(mqttConfig.getCleanSession()) .send() .thenAccept(connAck -> { - log.info("mqtt client connection success."); + log.info("[MQTT 连接成功]"); subscribeToTopics(Arrays.asList(mqttConfig.getTopics())); }) .exceptionally(throwable -> { - log.error("mqtt client connection failed: " + throwable.getMessage(), throwable); + log.error("[MQTT 连接失败, {}]", throwable.getMessage()); return null; }); @@ -201,6 +201,17 @@ public class MqttService implements ApplicationAutoInitial { String payload = new String(publish.getPayloadAsBytes(), StandardCharsets.UTF_8); messageArrived(topic, payload); }); + + Runtime.getRuntime().addShutdownHook(new Thread(() -> { + try { + latch.await(); + log.info("[MQTT 关闭程序]"); + System.out.println("[关闭程序]"); + } catch (InterruptedException e) { + e.printStackTrace(); + } + })); + } private void subscribeToTopics(List topics) { @@ -292,7 +303,7 @@ public class MqttService implements ApplicationAutoInitial { */ public void setOnline(String deviceCode, List tags) { Optional heartbeatPresent = tags.stream() - .filter(tag -> tag.getId().contains(HEARTBEAT) || tag.getId().contains("move")) + .filter(tag -> tag.getId().contains(HEARTBEAT)) .map(Tag::isQ) .findFirst(); heartbeatPresent.ifPresent(q -> { @@ -326,13 +337,26 @@ public class MqttService implements ApplicationAutoInitial { @PreDestroy public void cleanup() { - if (mqttClient != null) { - unloadTags(); - mqttClient.disconnect().thenAccept(disconnectAck -> { - threadPool.shutdown(); - log.info("Application Close, So MQTT client disconnected."); - }); - } + CompletableFuture mqttDisconnectFuture = CompletableFuture.runAsync(() -> { + if (mqttClient != null) { + mqttClient.disconnect().thenAccept(disconnectAck -> System.out.println("[关闭MQTT Client]")); + log.info("[关闭MQTT Client]"); + } + }); + mqttDisconnectFuture.thenRun(() -> { + this.unloadTags(); + log.info("[加载Tags到Redis]"); + System.out.println("[加载Tags到Redis]"); + }).thenRun(() -> { + threadPool.shutdown(); + log.info("[关闭线程池]"); + System.out.println("[关闭线程池]"); + }).exceptionally(throwable -> { + log.error("[关闭异常 {}]", throwable.getMessage()); + System.out.println("[关闭异常]" + throwable.getMessage()); + return null; + }).join(); + latch.countDown(); } private void loadTags() { diff --git a/acs2/nladmin-system/src/main/java/org/nl/modules/logicflow/service/impl/StageServiceImpl.java b/acs2/nladmin-system/src/main/java/org/nl/modules/logicflow/service/impl/StageServiceImpl.java index af7a08d..f418784 100644 --- a/acs2/nladmin-system/src/main/java/org/nl/modules/logicflow/service/impl/StageServiceImpl.java +++ b/acs2/nladmin-system/src/main/java/org/nl/modules/logicflow/service/impl/StageServiceImpl.java @@ -224,12 +224,7 @@ public class StageServiceImpl implements StageService { obj.put("device_name", standardCoveyorControlDeviceDriver.getDevice().getDevice_name()); jo.put("mode", mode); jo.put("move", move); - jo.put("hasGoods", standardCoveyorControlDeviceDriver.getHasGoods()); - jo.put("isOnline", standardCoveyorControlDeviceDriver.getIsonline()); jo.put("error", standardCoveyorControlDeviceDriver.getError()); - jo.put("isError", standardCoveyorControlDeviceDriver.getIserror()); - jo.put("requestSucess", standardCoveyorControlDeviceDriver.getRequireSucess()); - jo.put("applySucess", standardCoveyorControlDeviceDriver.getApplySucess()); jo.put("message", standardCoveyorControlDeviceDriver.getMessage()); } else if (device.getDeviceDriver() instanceof StandardAutodoorDeviceDriver) { standardAutodoorDeviceDriver = (StandardAutodoorDeviceDriver) device.getDeviceDriver(); diff --git a/acs2/nladmin-system/src/main/java/org/nl/start/auto/run/ElevatorSocketConnectionAutoRun.java b/acs2/nladmin-system/src/main/java/org/nl/start/auto/run/ElevatorSocketConnectionAutoRun.java index a0c022f..7964fef 100644 --- a/acs2/nladmin-system/src/main/java/org/nl/start/auto/run/ElevatorSocketConnectionAutoRun.java +++ b/acs2/nladmin-system/src/main/java/org/nl/start/auto/run/ElevatorSocketConnectionAutoRun.java @@ -48,7 +48,7 @@ public class ElevatorSocketConnectionAutoRun extends AbstractAutoRunnable { @Override public void autoRun() throws IOException, InterruptedException { - System.out.println("电梯链接开始"); +/* System.out.println("电梯链接开始"); String ip = "192.168.8.236"; int port = 502; InetSocketAddress socketAddress = new InetSocketAddress(ip, port); @@ -65,7 +65,7 @@ public class ElevatorSocketConnectionAutoRun extends AbstractAutoRunnable { throw new IllegalArgumentException("PLC端开连接!"); } Thread.sleep(5000); - } + }*/ } diff --git a/acs2/nladmin-system/src/main/resources/config/application-dev2.yml b/acs2/nladmin-system/src/main/resources/config/application-dev2.yml index ba3627a..2d990f2 100644 --- a/acs2/nladmin-system/src/main/resources/config/application-dev2.yml +++ b/acs2/nladmin-system/src/main/resources/config/application-dev2.yml @@ -6,9 +6,9 @@ spring: druid: db-type: com.alibaba.druid.pool.DruidDataSource driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy - url: jdbc:log4jdbc:mysql://${DB_HOST:127.0.0.1}:${DB_PORT:3306}/${DB_NAME:sdk_acs}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true&allowPublicKeyRetrieval=true + url: jdbc:log4jdbc:mysql://${DB_HOST:127.0.0.1}:${DB_PORT:3306}/${DB_NAME:sh_kn_acs}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true&allowPublicKeyRetrieval=true username: ${DB_USER:root} - password: ${DB_PWD:password} + password: ${DB_PWD:root} # 初始连接数 initial-size: 5 # 最小连接数 @@ -65,7 +65,7 @@ spring: url: 192.168.81.251 clientId: sdk_mqtt21 topics: - - SDK/# + - KN/# qoss: - 2 timeout: 30 diff --git a/acs2/nladmin-system/src/main/resources/config/application.yml b/acs2/nladmin-system/src/main/resources/config/application.yml index 9e96fc9..0602e94 100644 --- a/acs2/nladmin-system/src/main/resources/config/application.yml +++ b/acs2/nladmin-system/src/main/resources/config/application.yml @@ -2,7 +2,7 @@ spring: freemarker: check-template-location: false profiles: - active: prod + active: dev2 jackson: time-zone: GMT+8 data: