From 59309fda3aea11f140941ce97257f104032395d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=B1=9F=E7=8E=AE?= Date: Fri, 13 Oct 2023 14:23:19 +0800 Subject: [PATCH] fix --- .../driver/AbstractOpcDeviceDriver.java | 83 +++++++ .../HfKilnManipulatorDeviceDriver.java | 7 +- .../HfKilnTrussDeviceDriver.java | 7 +- .../HfGantryManipulatorDeviceDriver.java | 7 +- .../hf_rgv_two/HfRGVTwoDeviceDriver.java | 8 +- .../hf_station/HfStationDeviceDriver.java | 14 +- .../HfStationTwoDeviceDriver.java | 14 +- .../hf_two_rgv/HfTwoRGVDeviceDriver.java | 8 +- .../java/org/nl/acs/ext/wms/data/JsonUtl.java | 125 ++++++++++ .../wms/service/impl/WmsToAcsServiceImpl.java | 6 - .../service/impl/InstructionServiceImpl.java | 12 - .../java/org/nl/acs/opc/OpcServerService.java | 25 ++ .../org/nl/acs/opc/OpcServerServiceImpl.java | 226 ++++++++++++++++++ .../task/service/impl/TaskServiceImpl.java | 6 - 14 files changed, 485 insertions(+), 63 deletions(-) create mode 100644 acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/data/JsonUtl.java create mode 100644 acs/nladmin-system/src/main/java/org/nl/acs/opc/OpcServerService.java create mode 100644 acs/nladmin-system/src/main/java/org/nl/acs/opc/OpcServerServiceImpl.java diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/driver/AbstractOpcDeviceDriver.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/driver/AbstractOpcDeviceDriver.java index ebf13e5..94dabf7 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/driver/AbstractOpcDeviceDriver.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/driver/AbstractOpcDeviceDriver.java @@ -1,8 +1,17 @@ package org.nl.acs.device_driver.driver; +import org.nl.acs.ext.wms.data.JsonUtl; import org.nl.acs.opc.OpcConfig; +import org.nl.acs.opc.OpcServerService; +import org.nl.acs.opc.OpcServerServiceImpl; import org.nl.acs.udw.UnifiedDataAccessor; import org.nl.acs.udw.UnifiedDataAccessorFactory; +import org.nl.modules.wql.exception.WDKException; +import org.nl.modules.wql.util.SpringContextHolder; + +import java.util.Date; +import java.util.Iterator; +import java.util.Map; public class AbstractOpcDeviceDriver extends AbstractDeviceDriver implements OpcDeviceDriver { UnifiedDataAccessor opcUdw; @@ -15,4 +24,78 @@ public class AbstractOpcDeviceDriver extends AbstractDeviceDriver implements Opc public UnifiedDataAccessor getOpcValueAccessor() { return this.opcUdw; } + + public boolean control(Map itemValues) { + + Iterator> it = itemValues.entrySet().iterator(); + + ItemValue p2[]; + p2 = new ItemValue[itemValues.size()]; + int i=0; + while (it.hasNext()) { + Map.Entry entry = it.next(); + System.out.println("即将写入值:"+entry.getKey() + ":" + entry.getValue()); + p2[i] = new ItemValue(); + p2[i].setItem_code(entry.getKey()); + p2[i].setItem_value(entry.getValue()); + i++; + } + + return this.control(p2); + } + + public boolean control(ItemValue[] itemValues) { + if (itemValues != null && itemValues.length != 0) { + String this_items = JsonUtl.parseWithoutException(itemValues); + boolean need_write = false; + StringBuilder sb = new StringBuilder(); + ItemValue[] var5 = itemValues; + int var6 = itemValues.length; + +// for (int var7 = 0; var7 < var6; ++var7) { +// ItemValue itemValue = var5[var7]; +// String code = itemValue.getItem_code(); +// Object udw_value = this.getUdwValue(code); +// Object write_value = itemValue.getItem_value(); +// sb.append(code); +// sb.append(":"); +// sb.append(JsonUtl.parseWithoutException(udw_value)); +// sb.append(";"); +// if (!need_write && !UnifiedDataAppService.isEquals(udw_value, write_value)) { +// need_write = true; +// } else { +// log.warn("下发信号点位{} 当前写入值:{} 与系统内存值:{} 相同,不再写入 ", code, write_value, udw_value ); +// } +// } + need_write = true; + if (need_write) { + /*if (StringUtl.isEqual(this_items, this.last_items) && date.getTime() - this.sendTime.getTime() < (long) WcsConfig.opc_write_repeat_check) { + log.trace("发送时间因为小于{}毫秒,而被无视", WcsConfig.opc_write_repeat_check); + return false; + }*/ + /* this.execute_log.setResource(this.getDevice().getCode(), this.getDevice().getName()); + this.execute_log.log("原始记录{}->变更为{}", new Object[]{sb, this_items}); + OpcServerService opcServerService = OpcServerFactory.getOpcServerService();*/ + + OpcServerService opcServerService = SpringContextHolder.getBean(OpcServerServiceImpl.class); + + opcServerService.writeInteger(this.getOpcServer(), itemValues); + + UnifiedDataAccessor opcValueAccessor = this.getOpcValueAccessor(); + ItemValue[] var17 = itemValues; + int var18 = itemValues.length; + + for (int var19 = 0; var19 < var18; ++var19) { + ItemValue itemValue = var17[var19]; + String code = itemValue.getItem_code(); + Object value = itemValue.getItem_value(); + opcValueAccessor.setValue(code, value); + } + } + + return true; + } else { + throw new WDKException("下发 无内容"); + } + } } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/hongfeng/hf_kiln_manipulator/HfKilnManipulatorDeviceDriver.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/hongfeng/hf_kiln_manipulator/HfKilnManipulatorDeviceDriver.java index 11f3343..304fab7 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/hongfeng/hf_kiln_manipulator/HfKilnManipulatorDeviceDriver.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/hongfeng/hf_kiln_manipulator/HfKilnManipulatorDeviceDriver.java @@ -337,11 +337,10 @@ public class HfKilnManipulatorDeviceDriver extends AbstractOpcDeviceDriver imple public void writing(String param, String value) { String to_param = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + "." + param; - String opcservcerid = this.getDevice().getOpc_server_id(); - Server server = ReadUtil.getServer(opcservcerid); - Map itemMap = new HashMap(); + Map itemMap = new HashMap<>(); + itemMap.put(to_param, value); - ReadUtil.write(itemMap, server); + this.control(itemMap); logServer.writeLog("下发电气信号", this.getDevice_code(), "下发信号:" + to_param + "信号值:" + value); } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/hongfeng/hf_kiln_truss/HfKilnTrussDeviceDriver.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/hongfeng/hf_kiln_truss/HfKilnTrussDeviceDriver.java index a4ebc31..9fe1cde 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/hongfeng/hf_kiln_truss/HfKilnTrussDeviceDriver.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/hongfeng/hf_kiln_truss/HfKilnTrussDeviceDriver.java @@ -290,11 +290,10 @@ public class HfKilnTrussDeviceDriver extends AbstractOpcDeviceDriver implements public void writing(int command) { String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + "." + org.nl.acs.device_driver.hongfeng.hf_station_two.ItemProtocol.item_to_command; - String opcservcerid = this.getDevice().getOpc_server_id(); - Server server = ReadUtil.getServer(opcservcerid); - Map itemMap = new HashMap(); + Map itemMap = new HashMap<>(); + itemMap.put(to_command, command); - ReadUtil.write(itemMap, server); + this.control(itemMap); logServer.writeLog("下发电气信号", this.getDevice_code(), "下发信号:" + to_command + "信号值:" + command); } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/hongfeng/hf_manipulator/HfGantryManipulatorDeviceDriver.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/hongfeng/hf_manipulator/HfGantryManipulatorDeviceDriver.java index b517702..a7ab14d 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/hongfeng/hf_manipulator/HfGantryManipulatorDeviceDriver.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/hongfeng/hf_manipulator/HfGantryManipulatorDeviceDriver.java @@ -402,13 +402,10 @@ public class HfGantryManipulatorDeviceDriver extends AbstractOpcDeviceDriver imp String to_param = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + "." + param; - String opcservcerid = this.getDevice().getOpc_server_id(); - Server server = ReadUtil.getServer(opcservcerid); - Map itemMap = new HashMap(); + Map itemMap = new HashMap<>(); itemMap.put(to_param, value); -// itemMap.put(to_param, Integer.parseInt(value)); - ReadUtil.write(itemMap, server); + this.control(itemMap); logServer.writeLog("下发电气信号", this.getDevice_code(), "下发信号:" + to_param + "信号值:" + value); } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/hongfeng/hf_rgv_two/HfRGVTwoDeviceDriver.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/hongfeng/hf_rgv_two/HfRGVTwoDeviceDriver.java index a7cea95..07e3da7 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/hongfeng/hf_rgv_two/HfRGVTwoDeviceDriver.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/hongfeng/hf_rgv_two/HfRGVTwoDeviceDriver.java @@ -577,12 +577,10 @@ public class HfRGVTwoDeviceDriver extends AbstractOpcDeviceDriver implements Dev String to_param = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + "." + param; - String opcservcerid = this.getDevice().getOpc_server_id(); - Server server = ReadUtil.getServer(opcservcerid); - Map itemMap = new HashMap(); - itemMap.put(to_param, Integer.parseInt(value)); + Map itemMap = new HashMap<>(); - ReadUtil.write(itemMap, server); + itemMap.put(to_param, value); + this.control(itemMap); logServer.writeLog("下发电气信号", this.getDevice_code(), "下发信号:" + to_param + "信号值:" + value); } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/hongfeng/hf_station/HfStationDeviceDriver.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/hongfeng/hf_station/HfStationDeviceDriver.java index 93e34a3..c9ccc74 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/hongfeng/hf_station/HfStationDeviceDriver.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/hongfeng/hf_station/HfStationDeviceDriver.java @@ -664,22 +664,20 @@ public class HfStationDeviceDriver extends AbstractOpcDeviceDriver implements De 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(); + Map itemMap = new HashMap<>(); + itemMap.put(to_command, command); - ReadUtil.write(itemMap, server); + this.control(itemMap); logServer.writeLog("下发电气信号", this.getDevice_code(), "下发信号:" + to_command + "信号值:" + command); } public void writing(String param, String value) { String to_param = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + "." + param; - String opcservcerid = this.getDevice().getOpc_server_id(); - Server server = ReadUtil.getServer(opcservcerid); - Map itemMap = new HashMap(); + Map itemMap = new HashMap<>(); + itemMap.put(to_param, value); - ReadUtil.write(itemMap, server); + this.control(itemMap); logServer.writeLog("下发电气信号", this.getDevice_code(), "下发信号:" + to_param + "信号值:" + value); } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/hongfeng/hf_station_two/HfStationTwoDeviceDriver.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/hongfeng/hf_station_two/HfStationTwoDeviceDriver.java index 71d185c..c4ea451 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/hongfeng/hf_station_two/HfStationTwoDeviceDriver.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/hongfeng/hf_station_two/HfStationTwoDeviceDriver.java @@ -516,22 +516,20 @@ public class HfStationTwoDeviceDriver extends AbstractOpcDeviceDriver implements 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(); + Map itemMap = new HashMap<>(); + itemMap.put(to_command, command); - ReadUtil.write(itemMap, server); + this.control(itemMap); logServer.writeLog("下发电气信号", this.getDevice_code(), "下发信号:" + to_command + "信号值:" + command); } public void writing(String param, String value) { String to_param = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + "." + param; - String opcservcerid = this.getDevice().getOpc_server_id(); - Server server = ReadUtil.getServer(opcservcerid); - Map itemMap = new HashMap(); + Map itemMap = new HashMap<>(); + itemMap.put(to_param, value); - ReadUtil.write(itemMap, server); + this.control(itemMap); logServer.writeLog("下发电气信号", this.getDevice_code(), "下发信号:" + to_param + "信号值:" + value); } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/hongfeng/hf_two_rgv/HfTwoRGVDeviceDriver.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/hongfeng/hf_two_rgv/HfTwoRGVDeviceDriver.java index 1123807..31cc967 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/hongfeng/hf_two_rgv/HfTwoRGVDeviceDriver.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/hongfeng/hf_two_rgv/HfTwoRGVDeviceDriver.java @@ -694,12 +694,10 @@ public class HfTwoRGVDeviceDriver extends AbstractOpcDeviceDriver implements Dev String to_param = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code() + "." + param; - String opcservcerid = this.getDevice().getOpc_server_id(); - Server server = ReadUtil.getServer(opcservcerid); - Map itemMap = new HashMap(); - itemMap.put(to_param, Integer.parseInt(value)); + Map itemMap = new HashMap<>(); - ReadUtil.write(itemMap, server); + itemMap.put(to_param, value); + this.control(itemMap); logServer.writeLog("下发电气信号", this.getDevice_code(), "下发信号:" + to_param + "信号值:" + value); } diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/data/JsonUtl.java b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/data/JsonUtl.java new file mode 100644 index 0000000..d60d403 --- /dev/null +++ b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/data/JsonUtl.java @@ -0,0 +1,125 @@ +package org.nl.acs.ext.wms.data; + +import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JavaType; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.module.SimpleModule; +import com.fasterxml.jackson.databind.type.TypeFactory; + +import java.io.IOException; +import java.util.List; +import java.util.Map; + +public class JsonUtl { + private static ObjectMapper objectMapper = null; + private static ObjectMapper objectMapperLog = null; + + private JsonUtl() { + } + + private static ObjectMapper init() { + ObjectMapper objectMapper = new ObjectMapper(); + SimpleModule simpleModule = new SimpleModule(); +// simpleModule.addSerializer(Enum.class, new EnumSerializer()); +// simpleModule.addSerializer(Date.class, new DateSerializer()); +// simpleModule.addDeserializer(Enum.class, new EnumDeserializer()); +// simpleModule.addDeserializer(Date.class, new DateDeserializers.DateDeserializer()); + objectMapper.registerModule(simpleModule); + objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + return objectMapper; + } + + public static ObjectMapper getInstance() { + if (objectMapper == null) { + Class var0 = JsonUtl.class; + synchronized(JsonUtl.class) { + if (objectMapper == null) { + objectMapper = init(); + } + } + } + + return objectMapper; + } + + public static ObjectMapper getInstanceLog() { + if (objectMapperLog == null) { + Class var0 = JsonUtl.class; + synchronized(JsonUtl.class) { + if (objectMapperLog == null) { + objectMapperLog = init(); + objectMapperLog.setSerializationInclusion(Include.NON_NULL); + } + } + } + + return objectMapperLog; + } + + public static ObjectMapper getObjectMapper() { + return getInstance(); + } + + public static String parse(Object object) throws RuntimeException { + try { + return getObjectMapper().writeValueAsString(object); + } catch (JsonProcessingException var2) { + throw new RuntimeException(var2); + } + } + + public static String parseWithoutException(Object object) { + try { + return parse(object); + } catch (Exception var2) { + return null; + } + } + + public static String parseLog(Object object) { + try { + return getInstanceLog().writeValueAsString(object); + } catch (Exception var2) { + return null; + } + } + + public static T format(String json, Class clazz) throws RuntimeException { + try { + return getObjectMapper().readValue(json, clazz); + } catch (IOException var3) { + throw new RuntimeException(var3); + } + } + + public static List formatList(String json, Class clazz) throws RuntimeException { + try { + JavaType type = getObjectMapper().getTypeFactory().constructParametricType(List.class, new Class[]{clazz}); + return (List)getObjectMapper().readValue(json, type); + } catch (IOException var3) { + throw new RuntimeException(var3); + } + } + + public static Map formatMap(String json, Class clazzKey, Class clazzValue) throws RuntimeException { + try { + JavaType type = getObjectMapper().getTypeFactory().constructParametricType(Map.class, new Class[]{clazzKey, clazzValue}); + return (Map)getObjectMapper().readValue(json, type); + } catch (IOException var4) { + throw new RuntimeException(var4); + } + } + + public static List> formatListTwo(String json, Class clazz) throws RuntimeException { + try { + TypeFactory typeFactory = getObjectMapper().getTypeFactory(); + JavaType type = typeFactory.constructParametrizedType(List.class, List.class, new Class[]{clazz}); + type = typeFactory.constructParametrizedType(List.class, List.class, new JavaType[]{type}); + return (List)getObjectMapper().readValue(json, type); + } catch (IOException var4) { + throw new RuntimeException(var4); + } + } +} diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/WmsToAcsServiceImpl.java b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/WmsToAcsServiceImpl.java index ee87eb2..4f32289 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/WmsToAcsServiceImpl.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/WmsToAcsServiceImpl.java @@ -119,12 +119,6 @@ public class WmsToAcsServiceImpl implements WmsToAcsService { if (taskDto != null) { throw new WDKException("不能存在相同的任务号!"); } - if (!StrUtil.isEmpty(vehicle_code)) { - TaskDto vehicle_dto = taskService.findByContainer(vehicle_code); - if (vehicle_dto != null) { - throw new WDKException("已存在该载具号的任务!"); - } - } JSONObject jo = new JSONObject(); jo.put("task_code", task_code); jo.put("task_id", IdUtil.simpleUUID()); diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/instruction/service/impl/InstructionServiceImpl.java b/acs/nladmin-system/src/main/java/org/nl/acs/instruction/service/impl/InstructionServiceImpl.java index 29aa0e2..e7bb956 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/instruction/service/impl/InstructionServiceImpl.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/instruction/service/impl/InstructionServiceImpl.java @@ -384,12 +384,6 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu if (instcheckjson != null) { throw new Exception(dto.getTask_code() + ":该任务已存在待完成指令!"); } - if (!StrUtil.isEmpty(dto.getVehicle_code())) { - Instruction inst_dto = this.findByContainer(dto.getVehicle_code()); - if (ObjectUtils.isNotEmpty(inst_dto) && !StrUtil.equals(inst_dto.getTask_id(), dto.getTask_id())) { - throw new WDKException("已存在该载具号的指令!"); - } - } //起点设备与终点设备相同则为初始指令 if (StrUtil.equals(task.getStart_device_code(), dto.getStart_device_code())) { if (!StrUtil.equals(dto.getCompound_inst(), "0") && StrUtil.equals(task.getCompound_task(), "1")) { @@ -430,12 +424,6 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu if (instcheckjson2 != null) { throw new Exception(dto.getTask_code() + ":该任务已存在待完成指令!"); } - if (!StrUtil.isEmpty(dto2.getVehicle_code())) { - Instruction inst_dto2 = this.findByContainer(dto2.getVehicle_code()); - if (ObjectUtils.isNotEmpty(inst_dto2) && !StrUtil.equals(inst_dto2.getTask_id(), dto2.getTask_id())) { - throw new WDKException("已存在该载具号的指令!"); - } - } //起点设备与终点设备相同则为初始指令 if (StrUtil.equals(task2.getStart_device_code(), dto2.getStart_device_code())) { if (!StrUtil.equals(dto2.getCompound_inst(), "0") && StrUtil.equals(task2.getCompound_task(), "1")) { diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/opc/OpcServerService.java b/acs/nladmin-system/src/main/java/org/nl/acs/opc/OpcServerService.java new file mode 100644 index 0000000..6341f02 --- /dev/null +++ b/acs/nladmin-system/src/main/java/org/nl/acs/opc/OpcServerService.java @@ -0,0 +1,25 @@ +package org.nl.acs.opc; + +import org.nl.acs.device_driver.driver.ItemValue; +import org.openscada.opc.lib.da.Group; + +/** + * @author ldjun + * @version 1.0 + * @date 2023年02月01日 11:26 + * @desc desc + */ +public interface OpcServerService { + + void reload(); + + Group getServer(String var1); + + Group getServerByNewConn(String var1); + + void writeInteger(String var1, ItemValue... var2); + + void writeIntegerByNewConn(String var1, ItemValue... var2); + + void clearServer(String var1); +} diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/opc/OpcServerServiceImpl.java b/acs/nladmin-system/src/main/java/org/nl/acs/opc/OpcServerServiceImpl.java new file mode 100644 index 0000000..e36e3bf --- /dev/null +++ b/acs/nladmin-system/src/main/java/org/nl/acs/opc/OpcServerServiceImpl.java @@ -0,0 +1,226 @@ +package org.nl.acs.opc; + +import cn.hutool.core.util.StrUtil; +import org.jinterop.dcom.common.JIException; +import org.nl.acs.auto.initial.ApplicationAutoInitial; +import org.nl.acs.device_driver.driver.ItemValue; +import org.openscada.opc.lib.common.NotConnectedException; +import org.openscada.opc.lib.da.Group; +import org.openscada.opc.lib.da.Server; +import org.openscada.opc.lib.da.UnknownGroupException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.net.UnknownHostException; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +/** + * @author ldjun + * @version 1.0 + * @date 2023年02月01日 11:27 + * @desc desc + */ +@Service +public class OpcServerServiceImpl implements OpcServerService, ApplicationAutoInitial { + + private static final Logger log = LoggerFactory.getLogger(OpcServerServiceImpl.class); + @Autowired OpcServerManageService opcServerManageService; + Map opcServerManageDtos = new HashMap(); + Map servers = Collections.synchronizedMap(new HashMap()); + Map groups = Collections.synchronizedMap(new HashMap()); + + public OpcServerServiceImpl() {} + + public void autoInitial() throws Exception { + this.reload(); + if (OpcConfig.auto_start_opc) { + Thread t = + new Thread() { + public void run() { + Iterator var1 = OpcServerServiceImpl.this.opcServerManageDtos.values().iterator(); + + while (var1.hasNext()) { + OpcServerManageDto dto = (OpcServerManageDto) var1.next(); + + try { + OpcServerServiceImpl.this.getServer(dto.getOpc_code()); + OpcServerServiceImpl.log.info("加载opc server {}", dto.getOpc_code()); + } catch (Exception var4) { + OpcServerServiceImpl.log.warn("启动无法载入servers", var4); + } + } + } + }; + t.start(); + } + } + + public synchronized void reload() { + this.opcServerManageDtos = this.opcServerManageService.queryAllServerMap(); + this.opcServerManageDtos = Collections.synchronizedMap(this.opcServerManageDtos); + } + + public Group getServer(String code) { + synchronized(this.buildLock(code)) { + Group group = null; + group = (Group)this.groups.get(code); + if (group != null) { + label68: { + Group var10000; + try { + if (!group.isActive()) { + break label68; + } + + var10000 = group; + } catch (JIException var14) { + log.error(code, var14); + break label68; + } + + return var10000; + } + } + + Server server = (Server)this.servers.get(code); + boolean needcreate = false; + String groupName = code; + if (server == null) { + needcreate = true; + } else { + try { + group = server.findGroup(groupName); + } catch (UnknownHostException | JIException | UnknownGroupException | NotConnectedException | IllegalArgumentException var13) { + log.error(code, var13); + needcreate = true; + } + } + + if (needcreate) { + OpcServerManageDto dto = (OpcServerManageDto)this.opcServerManageDtos.get(code); + if (dto == null) { + throw new RuntimeException(code+"不存在"); + } + +// if (server!=null){ +// server.disconnect(); +// server=null; +// } + + if (server == null) { + server = OpcServerUtl.getServerWithOutException(dto.getOpc_host(), StrUtil.trim(dto.getCls_id()), dto.getUser(), dto.getPassword(), StrUtil.trim(dto.getDomain())); } + + try { + group = server.addGroup(groupName); + } catch (Exception var12) { + this.clearServer(code); + ThreadUtl.sleep(5000L); + log.warn("获取opc出错重新获取", code, var12); + server = OpcServerUtl.getServerWithOutException(dto.getOpc_host(), StrUtil.trim(dto.getCls_id()), dto.getUser(), dto.getPassword(), StrUtil.trim(dto.getDomain())); + try { + group = server.addGroup(groupName); + } catch (Exception var11) { + throw new RuntimeException(var12); + } + } + + this.servers.put(code, server); + this.groups.put(code, group); + } + + return group; + } + } + + public Group getServerByNewConn(String code) { + synchronized(this.buildLock(code)) { + + Server server = (Server)this.servers.get(code); + if (server!=null){ + this.clearServer(code); + } + + OpcServerManageDto dto = (OpcServerManageDto)this.opcServerManageDtos.get(code); + if (dto == null) { + throw new RuntimeException(code+"不存在"); + } + +// if (server == null) { + server = OpcServerUtl.getServerWithOutException(dto.getOpc_host(), StrUtil.trim(dto.getCls_id()), dto.getUser(), dto.getPassword(), StrUtil.trim(dto.getDomain())); +// } + String groupName = code; + Group group = null; + + try { + group = server.addGroup(groupName); + } catch (Exception var12) { + this.clearServer(code); + ThreadUtl.sleep(2000L); + log.warn("获取opc出错重新获取", code, var12); + server = OpcServerUtl.getServerWithOutException(dto.getOpc_host(), StrUtil.trim(dto.getCls_id()), dto.getUser(), dto.getPassword(), StrUtil.trim(dto.getDomain())); + try { + group = server.addGroup(groupName); + } catch (Exception var11) { + throw new RuntimeException(var12); + } + } + + this.servers.put(code, server); + this.groups.put(code, group); + return group; + } + } + + public void clearServer(String code) { + synchronized(this.buildLock(code)) { + try { + Server server = (Server)this.servers.get(code); + server.disconnect(); + } catch (Exception var5) { + } + + this.servers.remove(code); + this.groups.remove(code); + } + } + + public void writeInteger(String code, ItemValue... values) { + try { + Group group = this.getServer(code); + OpcUtl.writeValue(group, values); + } catch (Exception var4) { + this.clearServer(code); + log.info("写入出错opc server {} 重新加载", code, var4); + ThreadUtl.sleep(1000L); + throw var4; + } + } + + public void writeIntegerByNewConn(String code, ItemValue... values) { + try { + Group group = this.getServerByNewConn(code); + OpcUtl.writeValue(group, values); + } catch (Exception var4) { + this.clearServer(code); + log.info("写入出错opc server {} 重新加载", code, var4); + ThreadUtl.sleep(1000L); + throw var4; + } + } + + private String buildLock(String key) { + if (StrUtil.isEmpty(key)) { + key = ""; + } + StringBuilder builder = new StringBuilder(); + builder.append("OpcServerService."); + builder.append(key); + String lock = builder.toString().intern(); + return lock; + } +} diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/task/service/impl/TaskServiceImpl.java b/acs/nladmin-system/src/main/java/org/nl/acs/task/service/impl/TaskServiceImpl.java index 884afc7..a76f52a 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/task/service/impl/TaskServiceImpl.java +++ b/acs/nladmin-system/src/main/java/org/nl/acs/task/service/impl/TaskServiceImpl.java @@ -310,12 +310,6 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial { @Transactional(rollbackFor = Exception.class) public void create(TaskDto dto) throws Exception { dto = foramte(dto); - if (!StrUtil.isEmpty(dto.getVehicle_code())) { - TaskDto vehicle_dto = this.findByContainer(dto.getVehicle_code()); - if (vehicle_dto != null) { - throw new WDKException("已存在该载具号的任务!"); - } - } String currentUsername = SecurityUtils.getCurrentUsername(); String now = DateUtil.now(); String task_uuid = dto.getTask_id();