|
@ -7,6 +7,9 @@ import lombok.extern.slf4j.Slf4j; |
|
|
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.acs.udw.UnifiedDataAppService; |
|
|
import org.nl.acs.udw.UnifiedDataAppService; |
|
|
|
|
|
import org.nl.modules.lucene.service.LuceneExecuteLogService; |
|
|
|
|
|
import org.nl.modules.lucene.service.dto.LuceneLogDto; |
|
|
|
|
|
import org.nl.modules.wql.util.SpringContextHolder; |
|
|
import org.openscada.opc.lib.da.*; |
|
|
import org.openscada.opc.lib.da.*; |
|
|
|
|
|
|
|
|
import java.util.*; |
|
|
import java.util.*; |
|
@ -24,6 +27,9 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC |
|
|
private int all_null; |
|
|
private int all_null; |
|
|
private Map<String, OpcItemDto> itemSearchCache; |
|
|
private Map<String, OpcItemDto> itemSearchCache; |
|
|
|
|
|
|
|
|
|
|
|
LuceneExecuteLogService lucene = SpringContextHolder.getBean(LuceneExecuteLogService.class); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public DeviceOpcProtocolRunable() { |
|
|
public DeviceOpcProtocolRunable() { |
|
|
this.error_num = 0; |
|
|
this.error_num = 0; |
|
|
this.all_null = 0; |
|
|
this.all_null = 0; |
|
@ -48,10 +54,12 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC |
|
|
this.OpcServer = opcServer; |
|
|
this.OpcServer = opcServer; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private OpcItemDto getItem(String item) { |
|
|
private OpcItemDto getItem(String item) { |
|
|
OpcItemDto x = (OpcItemDto) this.itemSearchCache.get(item); |
|
|
OpcItemDto x = (OpcItemDto) this.itemSearchCache.get(item); |
|
|
if (x == null) { |
|
|
if (x == null) { |
|
|
Iterator var3 = this.protocols.iterator(); |
|
|
Iterator var3 = this.protocols.iterator(); |
|
|
|
|
|
|
|
|
while (var3.hasNext()) { |
|
|
while (var3.hasNext()) { |
|
|
OpcItemDto dto = (OpcItemDto) var3.next(); |
|
|
OpcItemDto dto = (OpcItemDto) var3.next(); |
|
|
if (StrUtil.equals(item, dto.getItem_code())) { |
|
|
if (StrUtil.equals(item, dto.getItem_code())) { |
|
@ -61,9 +69,11 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return x; |
|
|
return x; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public void run() { |
|
|
public void run() { |
|
|
if (OpcConfig.opc_item_read_using_callback) { |
|
|
if (OpcConfig.opc_item_read_using_callback) { |
|
@ -73,7 +83,9 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void runOld() { |
|
|
private void runOld() { |
|
|
|
|
|
OpcServerService opcServerService = SpringContextHolder.getBean(OpcServerService .class); |
|
|
while (true) { |
|
|
while (true) { |
|
|
start: |
|
|
start: |
|
|
try { |
|
|
try { |
|
@ -87,10 +99,10 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC |
|
|
log.trace("清理server..."); |
|
|
log.trace("清理server..."); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
this.server = OpcServerUtl.getServerWithOutException(this.OpcServer.getOpc_host(), this.OpcServer.getCls_id(), this.OpcServer.getUser(), this.OpcServer.getPassword(), this.OpcServer.getDomain()); |
|
|
group =opcServerService.getServer(this.getOpcServer().getOpc_code()); |
|
|
this.server.addStateListener(this); |
|
|
// this.server = OpcServerUtl.getServerWithOutException(this.OpcServer.getOpc_host(), this.OpcServer.getCls_id(), this.OpcServer.getUser(), this.OpcServer.getPassword(), this.OpcServer.getDomain());
|
|
|
group = this.server.addGroup(); |
|
|
// this.server.addStateListener(this);
|
|
|
|
|
|
// group = this.server.addGroup();
|
|
|
List<String> itemsString = new ArrayList(); |
|
|
List<String> itemsString = new ArrayList(); |
|
|
Iterator var3 = this.protocols.iterator(); |
|
|
Iterator var3 = this.protocols.iterator(); |
|
|
|
|
|
|
|
@ -130,7 +142,6 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC |
|
|
OpcStartTag.is_run = true; |
|
|
OpcStartTag.is_run = true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//线程名
|
|
|
|
|
|
tag = ""; |
|
|
tag = ""; |
|
|
if (log.isWarnEnabled()) { |
|
|
if (log.isWarnEnabled()) { |
|
|
tag = Thread.currentThread().getName(); |
|
|
tag = Thread.currentThread().getName(); |
|
@ -138,10 +149,10 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC |
|
|
tag = tag + this.getOpcGroupID(); |
|
|
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 (DeviceOpcSynchronizeAutoRun.isRun) { |
|
|
long begin = System.currentTimeMillis(); |
|
|
long begin = System.currentTimeMillis(); |
|
|
if (log.isTraceEnabled()) { |
|
|
if (log.isTraceEnabled()) { |
|
@ -154,6 +165,7 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC |
|
|
if (log.isTraceEnabled()) { |
|
|
if (log.isTraceEnabled()) { |
|
|
log.trace("{} 读取耗时:{}", 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); |
|
@ -180,6 +192,10 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC |
|
|
Object his = accessor_value.getValue(itemId); |
|
|
Object his = accessor_value.getValue(itemId); |
|
|
if (!ObjectUtl.isEquals(itemState.getQuality(), QualityTypeValue.OPC_QUALITY_GOOD) && his != null) { |
|
|
if (!ObjectUtl.isEquals(itemState.getQuality(), QualityTypeValue.OPC_QUALITY_GOOD) && his != null) { |
|
|
log.warn("opc 值不健康 item: {}, 状态: {}", itemId, itemState.getQuality()); |
|
|
log.warn("opc 值不健康 item: {}, 状态: {}", itemId, itemState.getQuality()); |
|
|
|
|
|
// valueAllNotNull = false;
|
|
|
|
|
|
|
|
|
|
|
|
ThreadUtl.sleep((long) ((new Random()).nextInt(3) +1) * 1000); |
|
|
|
|
|
break start; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (!UnifiedDataAppService.isEquals(value, his)) { |
|
|
if (!UnifiedDataAppService.isEquals(value, his)) { |
|
@ -187,10 +203,11 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC |
|
|
if (true) { |
|
|
if (true) { |
|
|
this.logItemChanged(itemId, accessor_value, value, itemDto); |
|
|
this.logItemChanged(itemId, accessor_value, value, itemDto); |
|
|
} |
|
|
} |
|
|
|
|
|
if(!ObjectUtil.isEmpty(value)){ |
|
|
accessor_value.setValue(itemId, value); |
|
|
accessor_value.setValue(itemId, value); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
end = System.currentTimeMillis(); |
|
|
end = System.currentTimeMillis(); |
|
|
if (log.isTraceEnabled()) { |
|
|
if (log.isTraceEnabled()) { |
|
@ -209,17 +226,17 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC |
|
|
random *= 1000; |
|
|
random *= 1000; |
|
|
if (this.all_null < 3) { |
|
|
if (this.all_null < 3) { |
|
|
if (log.isWarnEnabled()) { |
|
|
if (log.isWarnEnabled()) { |
|
|
log.warn("{} 所有内容都为空, all_null:{} ,暂定{}s", tag, all_null, 5000 + random); |
|
|
log.warn("{} 所有内容都为空, all_null:{} ,暂定{}s", tag, all_null,5000 + random); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
ThreadUtl.sleep((long) (5000 + random)); |
|
|
ThreadUtl.sleep((long) (5000 + random)); |
|
|
} else if (this.all_null < 6) { |
|
|
} else if (this.all_null < 6) { |
|
|
if (log.isWarnEnabled()) { |
|
|
if (log.isWarnEnabled()) { |
|
|
log.warn(tag + "重新创建server"); |
|
|
log.warn(tag + "重新创建server"); |
|
|
log.warn("{} 所有内容都为空, all_null:{} ,暂定{}s", tag, all_null, 30000 + random); |
|
|
log.warn("{} 所有内容都为空, all_null:{} ,暂定{}s", tag, all_null,30000 + random); |
|
|
} |
|
|
} |
|
|
// ThreadUtl.sleep((long) (30000 + random));
|
|
|
// ThreadUtl.sleep((long) (30000 + random));
|
|
|
ThreadUtl.sleep((long) ((new Random()).nextInt(3) + 1) * 1000); |
|
|
ThreadUtl.sleep((long) ((new Random()).nextInt(3) +1) * 1000); |
|
|
break start; |
|
|
break start; |
|
|
} else if (this.all_null < 12) { |
|
|
} else if (this.all_null < 12) { |
|
|
if (log.isWarnEnabled()) { |
|
|
if (log.isWarnEnabled()) { |
|
@ -233,8 +250,8 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
ThreadUtl.sleep((long) (120000 + random)); |
|
|
ThreadUtl.sleep((long) (120000 + random)); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
++this.all_null; |
|
|
++this.all_null; |
|
|
} else { |
|
|
} else { |
|
|
this.all_null = 0; |
|
|
this.all_null = 0; |
|
@ -250,9 +267,9 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC |
|
|
try { |
|
|
try { |
|
|
this.server.disconnect(); |
|
|
this.server.disconnect(); |
|
|
} catch (Exception var25) { |
|
|
} catch (Exception var25) { |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
this.server = null; |
|
|
this.server = null; |
|
|
if (!DeviceOpcSynchronizeAutoRun.isRun) { |
|
|
if (!DeviceOpcSynchronizeAutoRun.isRun) { |
|
|
log.warn("opc线程停止2。。。"); |
|
|
log.warn("opc线程停止2。。。"); |
|
@ -339,6 +356,7 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void connectionStateChanged(boolean connected) { |
|
|
public void connectionStateChanged(boolean connected) { |
|
|
if (!connected) { |
|
|
if (!connected) { |
|
|
this.server = null; |
|
|
this.server = null; |
|
@ -359,6 +377,8 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC |
|
|
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) { |
|
|
public void changed(Item item, ItemState itemState) { |
|
|
String itemId = item.getId(); |
|
|
String itemId = item.getId(); |
|
|
|
|
|
|
|
@ -400,11 +420,31 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC |
|
|
Object obj = accessor_value.getValue(relate); |
|
|
Object obj = accessor_value.getValue(relate); |
|
|
sb.append("key:" + relate + "value:" + obj + ";"); |
|
|
sb.append("key:" + relate + "value:" + obj + ";"); |
|
|
} |
|
|
} |
|
|
log.warn("设备:{}信号{}变更从{}->{};信号快照:{}", new Object[]{itemDto.getDevice_code(), itemId, his, value, sb}); |
|
|
//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});
|
|
|
if (!itemDto.getItem_code().endsWith("heartbeat") && !itemDto.getItem_code().endsWith("time")) { |
|
|
|
|
|
if(!ObjectUtil.equal(his,"null") || !ObjectUtil.equal(value,"null") || !ObjectUtil.isEmpty(his) || !ObjectUtil.isEmpty(value)){ |
|
|
|
|
|
// log.warn("{} 信号 {} 发生变更 {} -> {} 信号快照 {}", itemDto.getDevice_code(), itemCode, his, value, sb);
|
|
|
|
|
|
lucene.deviceExecuteLog(new LuceneLogDto(itemDto.getOpc_server_code(), itemDto.getOpc_plc_code(), itemDto.getDevice_code(), itemDto.getItem_code().substring(itemDto.getItem_code().lastIndexOf(".") + 1), String.valueOf(his), String.valueOf(value))); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
//log.warn("设备:{}信号{}变更从{}->{};信号快照:{}", new Object[]{itemDto.getDevice_code(), itemId, his, value});
|
|
|
|
|
|
if (!itemDto.getItem_code().endsWith("heartbeat") && !itemDto.getItem_code().endsWith("time")) { |
|
|
|
|
|
// 存在上次点位值为null情况 则不记录日志
|
|
|
|
|
|
if((ObjectUtil.equal(his,"null") || ObjectUtil.isEmpty(his)) || (ObjectUtil.equal(value,"null") || ObjectUtil.isEmpty(value)) ){ |
|
|
|
|
|
//lucene.deviceExecuteLog(new LuceneLogDto(itemDto.getOpc_server_code(), itemDto.getOpc_plc_code(), itemDto.getDevice_code(), itemDto.getItem_code().substring(itemDto.getItem_code().lastIndexOf(".") + 1), String.valueOf(his), String.valueOf(value)));
|
|
|
|
|
|
System.out.println("his:"+his + ",value:"+ value); |
|
|
} else { |
|
|
} else { |
|
|
log.warn("设备:{}信号{}变更从{}->{};信号快照:{}", new Object[]{itemDto.getDevice_code(), itemId, his, value}); |
|
|
lucene.deviceExecuteLog(new LuceneLogDto(itemDto.getOpc_server_code(), itemDto.getOpc_plc_code(), itemDto.getDevice_code(), itemDto.getItem_code().substring(itemDto.getItem_code().lastIndexOf(".") + 1), String.valueOf(his), String.valueOf(value))); |
|
|
// this.businessLogger.setResource(itemDto.getDevice_code(), itemDto.getDevice_name()).log("信号{}变更从{}->{}", new Object[]{itemId, his, value});
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// if(!ObjectUtil.equal(his,"null") || !ObjectUtil.equal(value,"null") || !ObjectUtil.isEmpty(his) || !ObjectUtil.isEmpty(value)){
|
|
|
|
|
|
// log.warn("{} 信号 {} 发生变更 {} -> {} 信号快照 {}", itemDto.getDevice_code(), itemCode, his, value, sb);
|
|
|
|
|
|
// lucene.deviceExecuteLog(new LuceneLogDto(itemDto.getOpc_server_code(), itemDto.getOpc_plc_code(), itemDto.getDevice_code(), itemDto.getItem_code().substring(itemDto.getItem_code().lastIndexOf(".") + 1), String.valueOf(his), String.valueOf(value)));
|
|
|
|
|
|
// }
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|