fix
This commit is contained in:
@@ -1,8 +1,17 @@
|
|||||||
package org.nl.acs.device_driver.driver;
|
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.OpcConfig;
|
||||||
|
import org.nl.acs.opc.OpcServerService;
|
||||||
|
import org.nl.acs.opc.OpcServerServiceImpl;
|
||||||
import org.nl.acs.udw.UnifiedDataAccessor;
|
import org.nl.acs.udw.UnifiedDataAccessor;
|
||||||
import org.nl.acs.udw.UnifiedDataAccessorFactory;
|
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 {
|
public class AbstractOpcDeviceDriver extends AbstractDeviceDriver implements OpcDeviceDriver {
|
||||||
UnifiedDataAccessor opcUdw;
|
UnifiedDataAccessor opcUdw;
|
||||||
@@ -15,4 +24,78 @@ public class AbstractOpcDeviceDriver extends AbstractDeviceDriver implements Opc
|
|||||||
public UnifiedDataAccessor getOpcValueAccessor() {
|
public UnifiedDataAccessor getOpcValueAccessor() {
|
||||||
return this.opcUdw;
|
return this.opcUdw;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean control(Map<String, Object> itemValues) {
|
||||||
|
|
||||||
|
Iterator<Map.Entry<String, Object>> it = itemValues.entrySet().iterator();
|
||||||
|
|
||||||
|
ItemValue p2[];
|
||||||
|
p2 = new ItemValue[itemValues.size()];
|
||||||
|
int i=0;
|
||||||
|
while (it.hasNext()) {
|
||||||
|
Map.Entry<String, Object> 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("下发 无内容");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -337,11 +337,10 @@ public class HfKilnManipulatorDeviceDriver extends AbstractOpcDeviceDriver imple
|
|||||||
public void writing(String param, String value) {
|
public void writing(String param, String value) {
|
||||||
String to_param = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code()
|
String to_param = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code()
|
||||||
+ "." + param;
|
+ "." + param;
|
||||||
String opcservcerid = this.getDevice().getOpc_server_id();
|
Map<String, Object> itemMap = new HashMap<>();
|
||||||
Server server = ReadUtil.getServer(opcservcerid);
|
|
||||||
Map<String, Object> itemMap = new HashMap<String, Object>();
|
|
||||||
itemMap.put(to_param, value);
|
itemMap.put(to_param, value);
|
||||||
ReadUtil.write(itemMap, server);
|
this.control(itemMap);
|
||||||
logServer.writeLog("下发电气信号", this.getDevice_code(), "下发信号:" + to_param + "信号值:" + value);
|
logServer.writeLog("下发电气信号", this.getDevice_code(), "下发信号:" + to_param + "信号值:" + value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -290,11 +290,10 @@ public class HfKilnTrussDeviceDriver extends AbstractOpcDeviceDriver implements
|
|||||||
public void writing(int command) {
|
public void writing(int command) {
|
||||||
String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code()
|
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;
|
+ "." + org.nl.acs.device_driver.hongfeng.hf_station_two.ItemProtocol.item_to_command;
|
||||||
String opcservcerid = this.getDevice().getOpc_server_id();
|
Map<String, Object> itemMap = new HashMap<>();
|
||||||
Server server = ReadUtil.getServer(opcservcerid);
|
|
||||||
Map<String, Object> itemMap = new HashMap<String, Object>();
|
|
||||||
itemMap.put(to_command, command);
|
itemMap.put(to_command, command);
|
||||||
ReadUtil.write(itemMap, server);
|
this.control(itemMap);
|
||||||
logServer.writeLog("下发电气信号", this.getDevice_code(), "下发信号:" + to_command + "信号值:" + command);
|
logServer.writeLog("下发电气信号", this.getDevice_code(), "下发信号:" + to_command + "信号值:" + command);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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()
|
String to_param = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code()
|
||||||
+ "." + param;
|
+ "." + param;
|
||||||
String opcservcerid = this.getDevice().getOpc_server_id();
|
Map<String, Object> itemMap = new HashMap<>();
|
||||||
Server server = ReadUtil.getServer(opcservcerid);
|
|
||||||
Map<String, Object> itemMap = new HashMap<String, Object>();
|
|
||||||
|
|
||||||
itemMap.put(to_param, value);
|
itemMap.put(to_param, value);
|
||||||
// itemMap.put(to_param, Integer.parseInt(value));
|
this.control(itemMap);
|
||||||
ReadUtil.write(itemMap, server);
|
|
||||||
logServer.writeLog("下发电气信号", this.getDevice_code(), "下发信号:" + to_param + "信号值:" + value);
|
logServer.writeLog("下发电气信号", this.getDevice_code(), "下发信号:" + to_param + "信号值:" + value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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()
|
String to_param = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code()
|
||||||
+ "." + param;
|
+ "." + param;
|
||||||
String opcservcerid = this.getDevice().getOpc_server_id();
|
Map<String, Object> itemMap = new HashMap<>();
|
||||||
Server server = ReadUtil.getServer(opcservcerid);
|
|
||||||
Map<String, Object> itemMap = new HashMap<String, Object>();
|
|
||||||
itemMap.put(to_param, Integer.parseInt(value));
|
|
||||||
|
|
||||||
ReadUtil.write(itemMap, server);
|
itemMap.put(to_param, value);
|
||||||
|
this.control(itemMap);
|
||||||
logServer.writeLog("下发电气信号", this.getDevice_code(), "下发信号:" + to_param + "信号值:" + value);
|
logServer.writeLog("下发电气信号", this.getDevice_code(), "下发信号:" + to_param + "信号值:" + value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -664,22 +664,20 @@ public class HfStationDeviceDriver extends AbstractOpcDeviceDriver implements De
|
|||||||
public void writing(int command) {
|
public void writing(int command) {
|
||||||
String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code()
|
String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code()
|
||||||
+ "." + ItemProtocol.item_to_command;
|
+ "." + ItemProtocol.item_to_command;
|
||||||
String opcservcerid = this.getDevice().getOpc_server_id();
|
Map<String, Object> itemMap = new HashMap<>();
|
||||||
Server server = ReadUtil.getServer(opcservcerid);
|
|
||||||
Map<String, Object> itemMap = new HashMap<String, Object>();
|
|
||||||
itemMap.put(to_command, command);
|
itemMap.put(to_command, command);
|
||||||
ReadUtil.write(itemMap, server);
|
this.control(itemMap);
|
||||||
logServer.writeLog("下发电气信号", this.getDevice_code(), "下发信号:" + to_command + "信号值:" + command);
|
logServer.writeLog("下发电气信号", this.getDevice_code(), "下发信号:" + to_command + "信号值:" + command);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writing(String param, String value) {
|
public void writing(String param, String value) {
|
||||||
String to_param = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code()
|
String to_param = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code()
|
||||||
+ "." + param;
|
+ "." + param;
|
||||||
String opcservcerid = this.getDevice().getOpc_server_id();
|
Map<String, Object> itemMap = new HashMap<>();
|
||||||
Server server = ReadUtil.getServer(opcservcerid);
|
|
||||||
Map<String, Object> itemMap = new HashMap<String, Object>();
|
|
||||||
itemMap.put(to_param, value);
|
itemMap.put(to_param, value);
|
||||||
ReadUtil.write(itemMap, server);
|
this.control(itemMap);
|
||||||
logServer.writeLog("下发电气信号", this.getDevice_code(), "下发信号:" + to_param + "信号值:" + value);
|
logServer.writeLog("下发电气信号", this.getDevice_code(), "下发信号:" + to_param + "信号值:" + value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -516,22 +516,20 @@ public class HfStationTwoDeviceDriver extends AbstractOpcDeviceDriver implements
|
|||||||
public void writing(int command) {
|
public void writing(int command) {
|
||||||
String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code()
|
String to_command = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code()
|
||||||
+ "." + ItemProtocol.item_to_command;
|
+ "." + ItemProtocol.item_to_command;
|
||||||
String opcservcerid = this.getDevice().getOpc_server_id();
|
Map<String, Object> itemMap = new HashMap<>();
|
||||||
Server server = ReadUtil.getServer(opcservcerid);
|
|
||||||
Map<String, Object> itemMap = new HashMap<String, Object>();
|
|
||||||
itemMap.put(to_command, command);
|
itemMap.put(to_command, command);
|
||||||
ReadUtil.write(itemMap, server);
|
this.control(itemMap);
|
||||||
logServer.writeLog("下发电气信号", this.getDevice_code(), "下发信号:" + to_command + "信号值:" + command);
|
logServer.writeLog("下发电气信号", this.getDevice_code(), "下发信号:" + to_command + "信号值:" + command);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writing(String param, String value) {
|
public void writing(String param, String value) {
|
||||||
String to_param = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code()
|
String to_param = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code()
|
||||||
+ "." + param;
|
+ "." + param;
|
||||||
String opcservcerid = this.getDevice().getOpc_server_id();
|
Map<String, Object> itemMap = new HashMap<>();
|
||||||
Server server = ReadUtil.getServer(opcservcerid);
|
|
||||||
Map<String, Object> itemMap = new HashMap<String, Object>();
|
|
||||||
itemMap.put(to_param, value);
|
itemMap.put(to_param, value);
|
||||||
ReadUtil.write(itemMap, server);
|
this.control(itemMap);
|
||||||
logServer.writeLog("下发电气信号", this.getDevice_code(), "下发信号:" + to_param + "信号值:" + value);
|
logServer.writeLog("下发电气信号", this.getDevice_code(), "下发信号:" + to_param + "信号值:" + value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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()
|
String to_param = this.getDevice().getOpc_server_code() + "." + this.getDevice().getOpc_plc_code() + "." + this.getDevice().getDevice_code()
|
||||||
+ "." + param;
|
+ "." + param;
|
||||||
String opcservcerid = this.getDevice().getOpc_server_id();
|
Map<String, Object> itemMap = new HashMap<>();
|
||||||
Server server = ReadUtil.getServer(opcservcerid);
|
|
||||||
Map<String, Object> itemMap = new HashMap<String, Object>();
|
|
||||||
itemMap.put(to_param, Integer.parseInt(value));
|
|
||||||
|
|
||||||
ReadUtil.write(itemMap, server);
|
itemMap.put(to_param, value);
|
||||||
|
this.control(itemMap);
|
||||||
logServer.writeLog("下发电气信号", this.getDevice_code(), "下发信号:" + to_param + "信号值:" + value);
|
logServer.writeLog("下发电气信号", this.getDevice_code(), "下发信号:" + to_param + "信号值:" + value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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> T format(String json, Class<T> clazz) throws RuntimeException {
|
||||||
|
try {
|
||||||
|
return getObjectMapper().readValue(json, clazz);
|
||||||
|
} catch (IOException var3) {
|
||||||
|
throw new RuntimeException(var3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> List<T> formatList(String json, Class<T> 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 <T, U> Map<T, U> formatMap(String json, Class<T> clazzKey, Class<U> 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 <T> List<List<T>> formatListTwo(String json, Class<T> 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -119,12 +119,6 @@ public class WmsToAcsServiceImpl implements WmsToAcsService {
|
|||||||
if (taskDto != null) {
|
if (taskDto != null) {
|
||||||
throw new WDKException("不能存在相同的任务号!");
|
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();
|
JSONObject jo = new JSONObject();
|
||||||
jo.put("task_code", task_code);
|
jo.put("task_code", task_code);
|
||||||
jo.put("task_id", IdUtil.simpleUUID());
|
jo.put("task_id", IdUtil.simpleUUID());
|
||||||
|
|||||||
@@ -384,12 +384,6 @@ public class InstructionServiceImpl implements InstructionService, ApplicationAu
|
|||||||
if (instcheckjson != null) {
|
if (instcheckjson != null) {
|
||||||
throw new Exception(dto.getTask_code() + ":该任务已存在待完成指令!");
|
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(task.getStart_device_code(), dto.getStart_device_code())) {
|
||||||
if (!StrUtil.equals(dto.getCompound_inst(), "0") && StrUtil.equals(task.getCompound_task(), "1")) {
|
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) {
|
if (instcheckjson2 != null) {
|
||||||
throw new Exception(dto.getTask_code() + ":该任务已存在待完成指令!");
|
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(task2.getStart_device_code(), dto2.getStart_device_code())) {
|
||||||
if (!StrUtil.equals(dto2.getCompound_inst(), "0") && StrUtil.equals(task2.getCompound_task(), "1")) {
|
if (!StrUtil.equals(dto2.getCompound_inst(), "0") && StrUtil.equals(task2.getCompound_task(), "1")) {
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
@@ -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<String, OpcServerManageDto> opcServerManageDtos = new HashMap();
|
||||||
|
Map<String, Server> servers = Collections.synchronizedMap(new HashMap());
|
||||||
|
Map<String, Group> 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -310,12 +310,6 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
|
|||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void create(TaskDto dto) throws Exception {
|
public void create(TaskDto dto) throws Exception {
|
||||||
dto = foramte(dto);
|
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 currentUsername = SecurityUtils.getCurrentUsername();
|
||||||
String now = DateUtil.now();
|
String now = DateUtil.now();
|
||||||
String task_uuid = dto.getTask_id();
|
String task_uuid = dto.getTask_id();
|
||||||
|
|||||||
Reference in New Issue
Block a user