fix udw
This commit is contained in:
@@ -1,18 +0,0 @@
|
|||||||
package org.nl.acs.device.service.impl;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class Test {
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
String device = "1001,1002";
|
|
||||||
List list = new ArrayList<>();
|
|
||||||
list.add("1001");
|
|
||||||
list.add("1002");
|
|
||||||
for (int i = 0; i < list.size(); i++) {
|
|
||||||
ConveyorDevice condev = new ConveyorDevice(list.get(i).toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -323,7 +323,7 @@ public class LnshPalletizingManipulatorDeviceDriver extends AbstractOpcDeviceDri
|
|||||||
json.put("producetask_code",order_No);
|
json.put("producetask_code",order_No);
|
||||||
json.put("device_code",this.device_code);
|
json.put("device_code",this.device_code);
|
||||||
json.put("material_code",material);
|
json.put("material_code",material);
|
||||||
json.put("qty",encoder_qty);
|
json.put("qty",order_qty);
|
||||||
json.put("type","2");
|
json.put("type","2");
|
||||||
enterProduction(json);
|
enterProduction(json);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -325,7 +325,7 @@ public class LnshPalletizingManipulatorSiteDeviceDriver extends AbstractOpcDevic
|
|||||||
json.put("producetask_code",order_No);
|
json.put("producetask_code",order_No);
|
||||||
json.put("device_code",this.device_code);
|
json.put("device_code",this.device_code);
|
||||||
json.put("material_code",material);
|
json.put("material_code",material);
|
||||||
json.put("qty",encoder_qty);
|
json.put("qty",order_qty);
|
||||||
json.put("type","2");
|
json.put("type","2");
|
||||||
enterProduction(json);
|
enterProduction(json);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -372,7 +372,7 @@ public class LnshRGVDeviceDriver extends AbstractOpcDeviceDriver implements Devi
|
|||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
//前工位申请任务
|
//前工位申请任务
|
||||||
if (move_1 == 0 && action_1 == 0 && task1 == 0 && action_2 == 1 && !requireSucess1) {
|
if (move_1 == 0 && action_1 == 0 && task1 == 0 && ( action_2 == 1 || action_2 == 2 )&& !requireSucess1) {
|
||||||
instruction_require();
|
instruction_require();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -6,28 +6,31 @@ import cn.hutool.core.util.StrUtil;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.nl.modules.udw.UnifiedDataAccessor;
|
import org.nl.modules.udw.UnifiedDataAccessor;
|
||||||
import org.nl.modules.udw.UnifiedDataAccessorFactory;
|
import org.nl.modules.udw.UnifiedDataAccessorFactory;
|
||||||
import org.openscada.opc.lib.da.Group;
|
import org.nl.modules.udw.UnifiedDataAppService;
|
||||||
import org.openscada.opc.lib.da.Item;
|
import org.nl.start.auto.run.DeviceOpcSynchronizeAutoRun;
|
||||||
import org.openscada.opc.lib.da.ItemState;
|
import org.openscada.opc.lib.da.*;
|
||||||
import org.openscada.opc.lib.da.Server;
|
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class DeviceOpcProtocolRunable implements Runnable {
|
public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerConnectionStateListener {
|
||||||
List<OpcItemDto> protocols;
|
List<OpcItemDto> protocols;
|
||||||
OpcServerManageDto OpcServer;
|
OpcServerManageDto OpcServer;
|
||||||
int error_num;
|
int error_num;
|
||||||
String message;
|
String message;
|
||||||
int maxResartNum;
|
int maxResartNum;
|
||||||
private Server server;
|
private Server server;
|
||||||
boolean flag =false;
|
boolean flag = false;
|
||||||
|
private int all_null;
|
||||||
|
private Map<String, OpcItemDto> itemSearchCache;
|
||||||
|
|
||||||
public DeviceOpcProtocolRunable() {
|
public DeviceOpcProtocolRunable() {
|
||||||
this.error_num = 0;
|
this.error_num = 0;
|
||||||
|
this.all_null = 0;
|
||||||
this.message = null;
|
this.message = null;
|
||||||
|
this.itemSearchCache = new HashMap();
|
||||||
this.server = null;
|
this.server = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,36 +50,48 @@ public class DeviceOpcProtocolRunable implements Runnable {
|
|||||||
this.OpcServer = opcServer;
|
this.OpcServer = opcServer;
|
||||||
}
|
}
|
||||||
|
|
||||||
OpcItemDto getItem(String item) {
|
|
||||||
Iterator var2 = this.protocols.iterator();
|
|
||||||
|
|
||||||
OpcItemDto dto;
|
private OpcItemDto getItem(String item) {
|
||||||
do {
|
OpcItemDto x = (OpcItemDto)this.itemSearchCache.get(item);
|
||||||
if (!var2.hasNext()) {
|
if (x == null) {
|
||||||
return null;
|
Iterator var3 = this.protocols.iterator();
|
||||||
|
|
||||||
|
while(var3.hasNext()) {
|
||||||
|
OpcItemDto dto = (OpcItemDto)var3.next();
|
||||||
|
if (StrUtil.equals(item, dto.getItem_code())) {
|
||||||
|
x = dto;
|
||||||
|
this.itemSearchCache.put(item, dto);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
dto = (OpcItemDto) var2.next();
|
return x;
|
||||||
} while (!StrUtil.equals(item, dto.getItem_code()));
|
|
||||||
|
|
||||||
return dto;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
while (true) {
|
if (OpcConfig.opc_item_read_using_callback) {
|
||||||
|
this.runNew();
|
||||||
|
} else {
|
||||||
|
this.runOld();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private void runOld() {
|
||||||
|
while(true) {
|
||||||
try {
|
try {
|
||||||
this.server = OpcServerUtl.getServerWithOutException(this.OpcServer.getOpc_host(), this.OpcServer.getCls_id(), this.OpcServer.getUser(), this.OpcServer.getPassword(), this.OpcServer.getDomain());
|
this.server = OpcServerUtl.getServerWithOutException(this.OpcServer.getOpc_host(), this.OpcServer.getCls_id(), this.OpcServer.getUser(), this.OpcServer.getPassword(), this.OpcServer.getDomain());
|
||||||
// Group group = server.addGroup(this.OpcServer.getOpc_host());
|
this.server.addStateListener(this);
|
||||||
Group group = server.addGroup(this.OpcServer.getOpc_code());
|
Group group = this.server.addGroup();
|
||||||
if(ObjectUtil.isEmpty(group)){
|
|
||||||
log.info("group is null ");
|
|
||||||
}
|
|
||||||
List<String> itemsString = new ArrayList();
|
List<String> itemsString = new ArrayList();
|
||||||
Iterator it = this.protocols.iterator();
|
Iterator var3 = this.protocols.iterator();
|
||||||
|
|
||||||
while (it.hasNext()) {
|
while(var3.hasNext()) {
|
||||||
OpcItemDto protocol = (OpcItemDto) it.next();
|
OpcItemDto protocol = (OpcItemDto)var3.next();
|
||||||
String item = protocol.getItem_code();
|
String item = protocol.getItem_code();
|
||||||
itemsString.add(item);
|
itemsString.add(item);
|
||||||
}
|
}
|
||||||
@@ -84,58 +99,60 @@ public class DeviceOpcProtocolRunable implements Runnable {
|
|||||||
Map<String, Item> itemsMap = new LinkedHashMap();
|
Map<String, Item> itemsMap = new LinkedHashMap();
|
||||||
boolean is_error = false;
|
boolean is_error = false;
|
||||||
StringBuilder err_message = new StringBuilder();
|
StringBuilder err_message = new StringBuilder();
|
||||||
Iterator var7 = itemsString.iterator();
|
Iterator var6 = itemsString.iterator();
|
||||||
|
|
||||||
while (var7.hasNext()) {
|
while(var6.hasNext()) {
|
||||||
String string = (String) var7.next();
|
String string = (String)var6.next();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
itemsMap.put(string, group.addItem(string));
|
Item item = group.addItem(string);
|
||||||
|
itemsMap.put(string, item);
|
||||||
log.trace("添加成功 {}", string);
|
log.trace("添加成功 {}", string);
|
||||||
} catch (Exception var29) {
|
} catch (Exception var26) {
|
||||||
err_message.append(string + ":" + var29.getMessage());
|
err_message.append(string + ":" + var26.getMessage());
|
||||||
if (!is_error) {
|
if (!is_error) {
|
||||||
is_error = true;
|
is_error = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String tag;
|
||||||
if (is_error) {
|
if (is_error) {
|
||||||
log.info("设备OPC数据同步配置异常");
|
tag = err_message.toString();
|
||||||
|
log.warn("{}:{}", OpcConfig.resource_code, tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!OpcStartTag.is_run) {
|
if (!OpcStartTag.is_run) {
|
||||||
OpcStartTag.is_run = true;
|
OpcStartTag.is_run = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//线程名
|
tag = "";
|
||||||
String tag = Thread.currentThread().getName();
|
if (log.isWarnEnabled()) {
|
||||||
if (this.OpcServer != null) {
|
tag = Thread.currentThread().getName();
|
||||||
tag = tag + this.OpcServer.getOpc_code();
|
if (this.OpcServer != null) {
|
||||||
|
tag = tag + this.getOpcGroupID();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
UnifiedDataAccessor accessor_value = UnifiedDataAccessorFactory.getAccessor(OpcConfig.udw_opc_value_key);
|
|
||||||
|
|
||||||
|
UnifiedDataAccessor accessor_value = UnifiedDataAccessorFactory.getAccessor(OpcConfig.udw_opc_value_key);
|
||||||
boolean time_out = false;
|
boolean time_out = false;
|
||||||
|
|
||||||
label97:
|
while(DeviceOpcSynchronizeAutoRun.isRun) {
|
||||||
while (true) {
|
|
||||||
long begin = System.currentTimeMillis();
|
long begin = System.currentTimeMillis();
|
||||||
Map<Item, ItemState> itemStatus = null;
|
if (log.isTraceEnabled()) {
|
||||||
try {
|
log.trace("{} 开始记时{}", tag, DateUtil.now());
|
||||||
itemStatus = group.read(true, (Item[]) itemsMap.values().toArray(new Item[0]));
|
|
||||||
} catch (Exception e){
|
|
||||||
System.out.println("数据同步异常:"+ this.getOpcServer().getOpc_code());
|
|
||||||
log.trace("数据同步异常:{}", this.getOpcServer().getOpc_code());
|
|
||||||
//e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Map<Item, ItemState> itemStatus = group.read(true, (Item[])itemsMap.values().toArray(new Item[0]));
|
||||||
long end = System.currentTimeMillis();
|
long end = System.currentTimeMillis();
|
||||||
log.trace("{} 开始记时{}", tag, DateUtil.now());
|
|
||||||
long duration = end - begin;
|
long duration = end - begin;
|
||||||
log.trace("{} 读取耗时:{}", tag, duration);
|
if (log.isTraceEnabled()) {
|
||||||
System.out.println("线程:"+tag + " 读取耗时:"+ duration);
|
log.trace("{} 读取耗时:{}", tag, duration);
|
||||||
|
}
|
||||||
|
|
||||||
if (duration > 1000L) {
|
if (duration > 1000L) {
|
||||||
if (!time_out) {
|
if (!time_out) {
|
||||||
log.warn(" {} 读取超时 : {}", tag, duration);
|
log.warn("{} 读取超时 : {}", tag, duration);
|
||||||
}
|
}
|
||||||
|
|
||||||
time_out = true;
|
time_out = true;
|
||||||
@@ -143,128 +160,192 @@ public class DeviceOpcProtocolRunable implements Runnable {
|
|||||||
time_out = false;
|
time_out = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ObjectUtil.isEmpty(itemStatus)) {
|
boolean valueAllNotNull = false;
|
||||||
System.out.println( tag + " :itemStatus is null");
|
|
||||||
log.warn(" {} 读取异常 : {} itemStatus is null", tag);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Set<Item> items = itemStatus.keySet();
|
Set<Item> items = itemStatus.keySet();
|
||||||
Iterator var18 = items.iterator();
|
Iterator var18 = items.iterator();
|
||||||
|
|
||||||
while (true) {
|
while(var18.hasNext()) {
|
||||||
Item item;
|
Item item = (Item)var18.next();
|
||||||
//当前值
|
ItemState itemState = (ItemState)itemStatus.get(item);
|
||||||
Object value;
|
Object value = OpcUtl.getValue(item, itemState);
|
||||||
//旧的值
|
if (value != null) {
|
||||||
Object his;
|
valueAllNotNull = true;
|
||||||
do {
|
|
||||||
if (!var18.hasNext()) {
|
|
||||||
end = System.currentTimeMillis();
|
|
||||||
log.trace("{}", itemsString);
|
|
||||||
log.trace("{} 计算完成耗时{}", tag, end - begin);
|
|
||||||
Thread.sleep((long) OpcConfig.synchronized_millisecond);
|
|
||||||
if (this.error_num != 0) {
|
|
||||||
this.error_num = 0;
|
|
||||||
this.message = null;
|
|
||||||
}
|
|
||||||
continue label97;
|
|
||||||
}
|
|
||||||
|
|
||||||
item = (Item) var18.next();
|
|
||||||
ItemState itemState = (ItemState) itemStatus.get(item);
|
|
||||||
value = OpcUtl.getValue(item, itemState);
|
|
||||||
his = accessor_value.getValue(item.getId());
|
|
||||||
if (!ObjectUtl.isEquals(itemState.getQuality(), QualityTypeValue.OPC_QUALITY_GOOD) && his != null) {
|
|
||||||
flag = true;
|
|
||||||
log.warn("线程 {} opc 值不健康 maxResartNum:{} ", tag);
|
|
||||||
log.warn("线程 {} opc 值不健康 item: {}, 状态: {},当前读取值:{}, 系统内存值{} ", tag, item.getId(), itemState.getQuality(), value, his);
|
|
||||||
}
|
|
||||||
if(flag){
|
|
||||||
if (this.server != null) {
|
|
||||||
try {
|
|
||||||
this.server.disconnect();
|
|
||||||
} catch (Exception var25) {
|
|
||||||
log.warn("{} : server disconnect", var25);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
DeviceOpcProtocolRunable runable = new DeviceOpcProtocolRunable();
|
|
||||||
runable.setProtocols(protocols);
|
|
||||||
runable.setOpcServer(OpcServer);
|
|
||||||
ExecutorService executorService = Executors.newCachedThreadPool();
|
|
||||||
executorService.submit(runable);
|
|
||||||
log.warn("opc 值不健康 item: {}, 重新创建连接,当前线程名:{}", item.getId(),tag);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} while (ObjectUtil.equal(value, his));//如果两次的值相等,不走下面的代码
|
|
||||||
|
|
||||||
if(flag){
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
OpcItemDto itemDto = this.getItem(item.getId());
|
|
||||||
//默认记录日志
|
|
||||||
if (true) {
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
//设备的ITEM项
|
|
||||||
List<String> relate_items = itemDto.getRelate_items();
|
|
||||||
Iterator var26 = relate_items.iterator();
|
|
||||||
|
|
||||||
while (var26.hasNext()) {
|
String itemId = item.getId();
|
||||||
String relate = (String) var26.next();
|
Object his = accessor_value.getValue(itemId);
|
||||||
Object obj = accessor_value.getValue(relate);
|
if (!ObjectUtl.isEquals(itemState.getQuality(), QualityTypeValue.OPC_QUALITY_GOOD) && his != null) {
|
||||||
sb.append("key:" + relate + "value:" + obj + ";");
|
log.warn("opc 值不健康 item: {}, 状态: {}", itemId, itemState.getQuality());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!UnifiedDataAppService.isEquals(value, his)) {
|
||||||
|
OpcItemDto itemDto = this.getItem(itemId);
|
||||||
|
if (true) {
|
||||||
|
this.logItemChanged(itemId, accessor_value, value, itemDto);
|
||||||
}
|
}
|
||||||
|
|
||||||
log.warn("信号{}变更从{}->{};信号快照:{}", new Object[]{item.getId(), his, value, sb});
|
accessor_value.setValue(itemId, value);
|
||||||
|
|
||||||
}
|
|
||||||
// accessor_value.setValueWithPersistence(item.getId(),accessor_value.getValue(item.getId()));
|
|
||||||
// accessor_value.getHistoryUnifiedData(item.getId());
|
|
||||||
//设置值
|
|
||||||
accessor_value.setValue(item.getId(), value);
|
|
||||||
if(flag){
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(flag){
|
|
||||||
break;
|
end = System.currentTimeMillis();
|
||||||
|
if (log.isTraceEnabled()) {
|
||||||
|
log.trace("{}", itemsString);
|
||||||
|
log.trace("{} 计算完成耗时{}", tag, end - begin);
|
||||||
|
}
|
||||||
|
|
||||||
|
ThreadUtl.sleep((long)OpcConfig.synchronized_millisecond);
|
||||||
|
if (this.error_num != 0) {
|
||||||
|
this.error_num = 0;
|
||||||
|
this.message = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!valueAllNotNull) {
|
||||||
|
int random = (new Random()).nextInt(10) + 1;
|
||||||
|
random *= 1000;
|
||||||
|
if (this.all_null < 3) {
|
||||||
|
if (log.isWarnEnabled()) {
|
||||||
|
log.warn("{} 所有内容都为空,暂定{}s", tag, 5000 + random);
|
||||||
|
}
|
||||||
|
|
||||||
|
ThreadUtl.sleep((long)(5000 + random));
|
||||||
|
} else if (this.all_null < 6) {
|
||||||
|
if (log.isWarnEnabled()) {
|
||||||
|
log.warn("{} 所有内容都为空,暂定{}s", tag, 30000 + random);
|
||||||
|
}
|
||||||
|
|
||||||
|
ThreadUtl.sleep((long)(30000 + random));
|
||||||
|
} else if (this.all_null < 12) {
|
||||||
|
if (log.isWarnEnabled()) {
|
||||||
|
log.warn("{} 所有内容都为空,暂定{}ms", tag, '\uea60' + random);
|
||||||
|
}
|
||||||
|
|
||||||
|
ThreadUtl.sleep((long)('\uea60' + random));
|
||||||
|
} else {
|
||||||
|
if (log.isWarnEnabled()) {
|
||||||
|
log.warn("{} 所有内容都为空,暂定{}ms", tag, 120000 + random);
|
||||||
|
}
|
||||||
|
|
||||||
|
ThreadUtl.sleep((long)(120000 + random));
|
||||||
|
}
|
||||||
|
|
||||||
|
++this.all_null;
|
||||||
|
} else {
|
||||||
|
this.all_null = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception var30) {
|
|
||||||
|
log.warn("opc线程停止。。。");
|
||||||
|
return;
|
||||||
|
} catch (Exception var27) {
|
||||||
if (this.server != null) {
|
if (this.server != null) {
|
||||||
try {
|
try {
|
||||||
this.server.disconnect();
|
this.server.disconnect();
|
||||||
} catch (Exception var25) {
|
} catch (Exception var25) {
|
||||||
log.warn("{} : server disconnect", var25);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.server = null;
|
this.server = null;
|
||||||
|
if (!DeviceOpcSynchronizeAutoRun.isRun) {
|
||||||
|
log.warn("opc线程停止2。。。");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
String error_message = "设备信息同步异常,"+var30;
|
String error_message = "设备信息同步异常";
|
||||||
if (!StrUtil.equals(this.message, error_message)) {
|
if (!StrUtil.equals(this.message, error_message)) {
|
||||||
log.warn("", var30);
|
log.warn(error_message, var27);
|
||||||
|
}
|
||||||
|
|
||||||
|
ThreadUtl.sleep((long)(OpcConfig.synchronized_exception_wait_second * 1000));
|
||||||
|
++this.error_num;
|
||||||
|
if (this.error_num > 3 && !StrUtil.equals(this.message, error_message)) {
|
||||||
|
this.message = error_message;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private void runNew() {
|
||||||
|
Async20Access accessor = null;
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
String opcGroupId = this.getOpcGroupID();
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (this.server == null) {
|
||||||
|
this.server = OpcServerUtl.getServerWithOutException(this.OpcServer.getOpc_host(), this.OpcServer.getCls_id(), this.OpcServer.getUser(), this.OpcServer.getPassword(), this.OpcServer.getDomain());
|
||||||
|
this.server.addStateListener(this);
|
||||||
|
accessor = new Async20Access(this.server, OpcConfig.synchronized_millisecond, true);
|
||||||
|
Iterator var9 = this.protocols.iterator();
|
||||||
|
|
||||||
|
while (var9.hasNext()) {
|
||||||
|
OpcItemDto protocol = (OpcItemDto) var9.next();
|
||||||
|
String itemId = protocol.getItem_code();
|
||||||
|
accessor.addItem(itemId, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
accessor.bind();
|
||||||
|
log.info("Async20Access bind {}", opcGroupId);
|
||||||
|
}
|
||||||
|
|
||||||
|
Thread.sleep((long) (OpcConfig.synchronized_exception_wait_second * 1000));
|
||||||
|
} catch (Exception var8) {
|
||||||
|
if (accessor != null) {
|
||||||
|
try {
|
||||||
|
log.warn("Async20Access unbind {}", opcGroupId);
|
||||||
|
accessor.unbind();
|
||||||
|
} catch (Exception var7) {
|
||||||
|
var7.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
accessor = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.server != null) {
|
||||||
|
try {
|
||||||
|
this.server.disconnect();
|
||||||
|
} catch (Exception var6) {
|
||||||
|
}
|
||||||
|
|
||||||
|
this.server = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (var8 instanceof InterruptedException) {
|
||||||
|
log.warn("OPC 同步线程(%s)被中断", opcGroupId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
log.warn("设备信息同步异常", var8);
|
||||||
|
ThreadUtl.sleep((long) (OpcConfig.synchronized_exception_wait_second * 1000));
|
||||||
|
String error_message = var8.getMessage();
|
||||||
|
if (error_message == null) {
|
||||||
|
error_message = var8.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
Thread.sleep((long) (OpcConfig.synchronized_exception_wait_second * 1000));
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
log.warn("OPC 读取线程读取异常{} :", e);
|
|
||||||
// Thread.currentThread().interrupt();不会真正停止线程
|
|
||||||
}
|
|
||||||
++this.error_num;
|
++this.error_num;
|
||||||
if (this.error_num > 3 && !StrUtil.equals(this.message, error_message)) {
|
if (this.error_num > 3 && !StrUtil.equals(this.message, error_message)) {
|
||||||
log.info("设备同步通信异常");
|
|
||||||
this.message = error_message;
|
this.message = error_message;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(flag){
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void connectionStateChanged(boolean connected) {
|
||||||
|
if (!connected) {
|
||||||
|
this.server = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
log.warn("opc server {} {}", this.getOpcGroupID(), connected ? "connected" : "disconnected");
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getOpcGroupID() {
|
||||||
|
String var10000 = this.OpcServer.getOpc_code();
|
||||||
|
return var10000 + "(" + this.protocols.size() + " items)";
|
||||||
|
}
|
||||||
|
|
||||||
public static String formatDuring(long mss) {
|
public static String formatDuring(long mss) {
|
||||||
long days = mss / 86400000L;
|
long days = mss / 86400000L;
|
||||||
long hours = mss % 86400000L / 3600000L;
|
long hours = mss % 86400000L / 3600000L;
|
||||||
@@ -272,4 +353,55 @@ public class DeviceOpcProtocolRunable implements Runnable {
|
|||||||
long seconds = mss % 60000L / 1000L;
|
long seconds = mss % 60000L / 1000L;
|
||||||
return days + " days " + hours + " hours " + minutes + " minutes " + seconds + " seconds ";
|
return days + " days " + hours + " hours " + minutes + " minutes " + seconds + " seconds ";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void changed(Item item, ItemState itemState) {
|
||||||
|
String itemId = item.getId();
|
||||||
|
|
||||||
|
try {
|
||||||
|
Object value = OpcUtl.getValue(item, itemState);
|
||||||
|
UnifiedDataAccessor accessor_value = UnifiedDataAccessorFactory.getAccessor(OpcConfig.udw_opc_value_key);
|
||||||
|
accessor_value.setValue(itemId, value);
|
||||||
|
|
||||||
|
if (value != null) {
|
||||||
|
if (log.isTraceEnabled()) {
|
||||||
|
log.trace("Item {} new value: {}, Timestamp: {}", new Object[]{itemId, itemState.getValue(), itemState.getTimestamp().getTime()});
|
||||||
|
}
|
||||||
|
} else if (log.isInfoEnabled()) {
|
||||||
|
log.info("Item {} new value: {}, Timestamp: {}, Quality: {}", new Object[]{itemId, itemState.getValue(), itemState.getTimestamp().getTime(), itemState.getQuality()});
|
||||||
|
}
|
||||||
|
|
||||||
|
OpcItemDto itemDto = this.getItem(itemId);
|
||||||
|
// if (Boolean.TRUE.equals(itemDto.getNeed_log())) {
|
||||||
|
// this.logItemChanged(itemId, accessor_value, value, itemDto);
|
||||||
|
// }
|
||||||
|
this.logItemChanged(itemId, accessor_value, value, itemDto);
|
||||||
|
|
||||||
|
} catch (Exception var7) {
|
||||||
|
log.error(itemId, var7);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void logItemChanged(String itemId, UnifiedDataAccessor accessor_value, Object value, OpcItemDto itemDto) {
|
||||||
|
Object his = accessor_value.getValue(itemId);
|
||||||
|
List<String> relate_items = itemDto.getRelate_items();
|
||||||
|
if (relate_items != null && !relate_items.isEmpty()) {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
Iterator var8 = relate_items.iterator();
|
||||||
|
|
||||||
|
while (var8.hasNext()) {
|
||||||
|
String relate = (String) var8.next();
|
||||||
|
Object obj = accessor_value.getValue(relate);
|
||||||
|
sb.append("key:" + relate + "value:" + obj + ";");
|
||||||
|
}
|
||||||
|
log.warn("设备:{}信号{}变更从{}->{};信号快照:{}", new Object[]{itemDto.getDevice_code(),itemId, his, value, sb});
|
||||||
|
// this.businessLogger.setResource(itemDto.getDevice_code(), itemDto.getDevice_name()).log("信号{}变更从{}->{};信号快照:{}", new Object[]{itemId, his, value, sb});
|
||||||
|
} else {
|
||||||
|
log.warn("设备:{}信号{}变更从{}->{};信号快照:{}", new Object[]{itemDto.getDevice_code(),itemId, his, value});
|
||||||
|
// this.businessLogger.setResource(itemDto.getDevice_code(), itemDto.getDevice_name()).log("信号{}变更从{}->{}", new Object[]{itemId, his, value});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,4 +10,5 @@ public class OpcConfig {
|
|||||||
public static String opc_server_default_group = "group";
|
public static String opc_server_default_group = "group";
|
||||||
public static String resource_code = "opc_sync";
|
public static String resource_code = "opc_sync";
|
||||||
public static String resource_name = "opc同步";
|
public static String resource_name = "opc同步";
|
||||||
|
public static boolean opc_item_read_using_callback = true;
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -13,12 +13,12 @@ spring:
|
|||||||
druid:
|
druid:
|
||||||
db-type: com.alibaba.druid.pool.DruidDataSource
|
db-type: com.alibaba.druid.pool.DruidDataSource
|
||||||
driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy
|
driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy
|
||||||
url: jdbc:log4jdbc:mysql://${DB_HOST:192.168.81.252}:${DB_PORT:3306}/${DB_NAME:jn_acs}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true
|
# url: jdbc:log4jdbc:mysql://${DB_HOST:192.168.81.252}:${DB_PORT:3306}/${DB_NAME:jn_acs}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true
|
||||||
# url: jdbc:log4jdbc:mysql://${DB_HOST:127.0.0.1}:${DB_PORT:3306}/${DB_NAME:rljn_acs}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true
|
url: jdbc:log4jdbc:mysql://${DB_HOST:127.0.0.1}:${DB_PORT:3306}/${DB_NAME:jn_acs}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true&allowPublicKeyRetrieval=true
|
||||||
username: ${DB_USER:root}
|
username: ${DB_USER:root}
|
||||||
# password: ${DB_PWD:P@ssw0rd}
|
# password: ${DB_PWD:P@ssw0rd}
|
||||||
password: ${DB_PWD:Root.123456}
|
# password: ${DB_PWD:Root.123456}
|
||||||
# password: ${DB_PWD:123456}
|
password: ${DB_PWD:123456}
|
||||||
# 初始连接数
|
# 初始连接数
|
||||||
initial-size: 5
|
initial-size: 5
|
||||||
# 最小连接数
|
# 最小连接数
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ https://juejin.cn/post/6844903775631572999
|
|||||||
<!--日志文件保留天数-->
|
<!--日志文件保留天数-->
|
||||||
<maxHistory>15</maxHistory>
|
<maxHistory>15</maxHistory>
|
||||||
<!--单个日志最大容量 至少10MB才能看得出来-->
|
<!--单个日志最大容量 至少10MB才能看得出来-->
|
||||||
<maxFileSize>200MB</maxFileSize>
|
<maxFileSize>50MB</maxFileSize>
|
||||||
<!--所有日志最多占多大容量-->
|
<!--所有日志最多占多大容量-->
|
||||||
<totalSizeCap>20GB</totalSizeCap>
|
<totalSizeCap>20GB</totalSizeCap>
|
||||||
</rollingPolicy>
|
</rollingPolicy>
|
||||||
|
|||||||
27
acs/qd/src/api/acs/history/acsDeviceErrorLog.js
Normal file
27
acs/qd/src/api/acs/history/acsDeviceErrorLog.js
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
import request from '@/utils/request'
|
||||||
|
|
||||||
|
export function add(data) {
|
||||||
|
return request({
|
||||||
|
url: 'api/deviceErrorLog',
|
||||||
|
method: 'post',
|
||||||
|
data
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export function del(ids) {
|
||||||
|
return request({
|
||||||
|
url: 'api/deviceErrorLog/',
|
||||||
|
method: 'delete',
|
||||||
|
data: ids
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export function edit(data) {
|
||||||
|
return request({
|
||||||
|
url: 'api/deviceErrorLog',
|
||||||
|
method: 'put',
|
||||||
|
data
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export default { add, edit, del }
|
||||||
28
acs/qd/src/api/acs/history/udwData.js
Normal file
28
acs/qd/src/api/acs/history/udwData.js
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
import request from '@/utils/request'
|
||||||
|
|
||||||
|
export function add(data) {
|
||||||
|
return request({
|
||||||
|
url: 'api/task',
|
||||||
|
method: 'post',
|
||||||
|
data
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export function del(ids) {
|
||||||
|
return request({
|
||||||
|
url: 'api/task/',
|
||||||
|
method: 'delete',
|
||||||
|
data: ids
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export function edit(data) {
|
||||||
|
return request({
|
||||||
|
url: 'api/task',
|
||||||
|
method: 'put',
|
||||||
|
data
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export default { edit, del }
|
||||||
|
|
||||||
181
acs/qd/src/views/acs/history/udwData/index.vue
Normal file
181
acs/qd/src/views/acs/history/udwData/index.vue
Normal file
@@ -0,0 +1,181 @@
|
|||||||
|
<template>
|
||||||
|
<div class="app-container">
|
||||||
|
<!--工具栏-->
|
||||||
|
<div class="head-container">
|
||||||
|
<div v-if="crud.props.searchToggle">
|
||||||
|
<!-- 搜索 -->
|
||||||
|
<el-select
|
||||||
|
v-model="form.unified_key"
|
||||||
|
placeholder="unified_key"
|
||||||
|
class="filter-item"
|
||||||
|
@change="crud.toQuery"
|
||||||
|
clearable
|
||||||
|
filterable
|
||||||
|
size="small">
|
||||||
|
<el-option v-for="(item,index) in unified_key" :key="index" :label="item.label" :value="item.value">
|
||||||
|
</el-option>
|
||||||
|
</el-select>
|
||||||
|
<el-input
|
||||||
|
v-model="query.code"
|
||||||
|
size="small"
|
||||||
|
clearable
|
||||||
|
placeholder="编号"
|
||||||
|
style="width: 200px;"
|
||||||
|
class="filter-item"
|
||||||
|
@keyup.enter.native="crud.toQuery"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<!--如果想在工具栏加入更多按钮,可以使用插槽方式, slot = 'left' or 'right'-->
|
||||||
|
<crudOperation :permission="permission" />
|
||||||
|
<!--表单组件-->
|
||||||
|
<el-dialog
|
||||||
|
:close-on-click-modal="false"
|
||||||
|
:before-close="crud.cancelCU"
|
||||||
|
:visible.sync="crud.status.cu > 0"
|
||||||
|
:title="crud.status.title"
|
||||||
|
width="500px"
|
||||||
|
>
|
||||||
|
<el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
|
||||||
|
<el-form-item label="unified_key">
|
||||||
|
<el-input v-model="form.unified_key" style="width: 370px;" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="编号">
|
||||||
|
<el-input v-model="form.key" style="width: 370px;" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="值">
|
||||||
|
<el-input v-model="form.value" style="width: 370px;" />
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
<div slot="footer" class="dialog-footer">
|
||||||
|
<el-button type="text" @click="crud.cancelCU">取消</el-button>
|
||||||
|
<el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
|
||||||
|
</div>
|
||||||
|
</el-dialog>
|
||||||
|
<!--表格渲染-->
|
||||||
|
<el-table
|
||||||
|
ref="table"
|
||||||
|
v-loading="crud.loading"
|
||||||
|
:data="crud.data"
|
||||||
|
size="small"
|
||||||
|
style="width: 100%;"
|
||||||
|
@selection-change="crud.selectionChangeHandler"
|
||||||
|
>
|
||||||
|
<el-table-column prop="unified_key" label="unified_key" />
|
||||||
|
<el-table-column prop="key" label="编号" />
|
||||||
|
<el-table-column prop="value" label="值" />
|
||||||
|
<el-table-column
|
||||||
|
v-permission="['admin','instruction:edit','instruction:del']"
|
||||||
|
fixed="left"
|
||||||
|
label="操作"
|
||||||
|
width="150px"
|
||||||
|
align="center"
|
||||||
|
>
|
||||||
|
<template slot-scope="scope">
|
||||||
|
<el-button slot="right" size="mini" style="margin-left: -1px;margin-right: 2px" type="text" @click="dialogFormVisible = true">
|
||||||
|
查询历史
|
||||||
|
</el-button>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
</el-table>
|
||||||
|
<!--分页组件-->
|
||||||
|
<pagination />
|
||||||
|
<!--弹窗设置设备与图标绑定与角度-->
|
||||||
|
<el-dialog title="历史" :visible.sync="dialogFormVisible" width="35%">
|
||||||
|
<el-form :model="form" size="small">
|
||||||
|
<el-form-item label="unified_key" prop="unified_key" label-width="100px">
|
||||||
|
<el-input v-model="form.unified_key" :disabled="true" />
|
||||||
|
</el-form-item>
|
||||||
|
|
||||||
|
<el-form-item label="code" prop="key" label-width="100px">
|
||||||
|
<el-input v-model="form.key" :disabled="true" />
|
||||||
|
</el-form-item>
|
||||||
|
|
||||||
|
</el-form>
|
||||||
|
</el-dialog>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import pagination from '@crud/Pagination'
|
||||||
|
import crudUdwData from '@/api/acs/history/udwData'
|
||||||
|
import CRUD, { crud, form, header, presenter } from '@crud/crud'
|
||||||
|
import crudOperation from '@crud/CRUD.operation'
|
||||||
|
import { getDicts } from '@/api/system/dict'
|
||||||
|
|
||||||
|
const defaultForm = {
|
||||||
|
unified_key: '',
|
||||||
|
key: null,
|
||||||
|
value: null,
|
||||||
|
last_modify_date: null
|
||||||
|
}
|
||||||
|
export default {
|
||||||
|
dicts: [],
|
||||||
|
name: 'UdwData',
|
||||||
|
components: { pagination, crudOperation },
|
||||||
|
mixins: [presenter(), header(), form(defaultForm), crud()],
|
||||||
|
cruds() {
|
||||||
|
return CRUD({
|
||||||
|
title: '数据源',
|
||||||
|
url: 'api/udw/',
|
||||||
|
idField: 'key',
|
||||||
|
sort: 'key',
|
||||||
|
query: {},
|
||||||
|
crudMethod: { ...crudUdwData },
|
||||||
|
optShow: {
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
unified_key: [
|
||||||
|
{
|
||||||
|
value: '1',
|
||||||
|
label: 'opc_value'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: '2',
|
||||||
|
label: 'cached'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: '3',
|
||||||
|
label: 'socket'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
permission: {
|
||||||
|
},
|
||||||
|
dialogFormVisible: false,
|
||||||
|
rules: {
|
||||||
|
},
|
||||||
|
form: {
|
||||||
|
unified_key: 'opc_value',
|
||||||
|
key: null,
|
||||||
|
value: null,
|
||||||
|
last_modify_date: null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
created() {
|
||||||
|
getDicts().then(data => {
|
||||||
|
this.dicts = data
|
||||||
|
})
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
// 钩子:在获取表格数据之前执行,false 则代表不获取数据
|
||||||
|
[CRUD.HOOK.beforeRefresh]() {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.el-dropdown-link {
|
||||||
|
cursor: pointer;
|
||||||
|
color: #409EFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
.el-icon-arrow-down {
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
Reference in New Issue
Block a user