rev 关闭日志、opc同步代码修改
This commit is contained in:
@@ -124,7 +124,7 @@ public class XianGongAgvServiceImpl implements XianGongAgvService {
|
|||||||
HttpResponse result = HttpRequest.get(agvurl)
|
HttpResponse result = HttpRequest.get(agvurl)
|
||||||
.timeout(20000)//超时,毫秒
|
.timeout(20000)//超时,毫秒
|
||||||
.execute();
|
.execute();
|
||||||
log.info("queryXZAgvDeviceStatus----查询agv状态数据数据:{}" + result.body());
|
// log.info("queryXZAgvDeviceStatus----查询agv状态数据数据:{}" + result.body());
|
||||||
return result;
|
return result;
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
@@ -456,7 +456,7 @@ public class XianGongAgvServiceImpl implements XianGongAgvService {
|
|||||||
String agvurl = paramService.findByCode(AcsConfig.AGVURL).getValue();
|
String agvurl = paramService.findByCode(AcsConfig.AGVURL).getValue();
|
||||||
String agvport = paramService.findByCode(AcsConfig.AGVPORT).getValue();
|
String agvport = paramService.findByCode(AcsConfig.AGVPORT).getValue();
|
||||||
agvurl = agvurl + ":" + agvport + "/blockGroupStatus";
|
agvurl = agvurl + ":" + agvport + "/blockGroupStatus";
|
||||||
log.info("获取互斥组参数:{},请求路径:{},请求参数:{}", String.valueOf(param), agvurl, String.valueOf(param));
|
// log.info("获取互斥组参数:{},请求路径:{},请求参数:{}", String.valueOf(param), agvurl, String.valueOf(param));
|
||||||
try {
|
try {
|
||||||
HttpResponse result = HttpRequest.post(agvurl)
|
HttpResponse result = HttpRequest.post(agvurl)
|
||||||
.body(JSON.toJSONString(param))//表单内容
|
.body(JSON.toJSONString(param))//表单内容
|
||||||
@@ -465,7 +465,7 @@ public class XianGongAgvServiceImpl implements XianGongAgvService {
|
|||||||
String body = result.body();
|
String body = result.body();
|
||||||
if (StrUtil.isNotEmpty(body)) {
|
if (StrUtil.isNotEmpty(body)) {
|
||||||
JSONArray jsonArray = JSONArray.parseArray(result.body());
|
JSONArray jsonArray = JSONArray.parseArray(result.body());
|
||||||
log.info("获取互斥组参数:{},请求路径:{},请求参数:{},响应参数{}", String.valueOf(param), agvurl, String.valueOf(param), String.valueOf(jsonArray));
|
// log.info("获取互斥组参数:{},请求路径:{},请求参数:{},响应参数{}", String.valueOf(param), agvurl, String.valueOf(param), String.valueOf(jsonArray));
|
||||||
return jsonArray;
|
return jsonArray;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -1,343 +1,242 @@
|
|||||||
|
|
||||||
package org.nl.acs.opc;
|
package org.nl.acs.opc;
|
||||||
|
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import com.alibaba.fastjson.JSON;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import org.nl.acs.auto.run.AutoRunService;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.nl.acs.auto.run.AutoRunServiceImpl;
|
|
||||||
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.openscada.opc.lib.da.Group;
|
||||||
import org.nl.modules.common.exception.BadRequestException;
|
import org.openscada.opc.lib.da.Item;
|
||||||
import org.nl.modules.wql.util.SpringContextHolder;
|
import org.openscada.opc.lib.da.ItemState;
|
||||||
import org.openscada.opc.lib.da.*;
|
import org.openscada.opc.lib.da.Server;
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerConnectionStateListener {
|
@Slf4j
|
||||||
private static final Logger log = LoggerFactory.getLogger(DeviceOpcProtocolRunable.class);
|
public class DeviceOpcProtocolRunable implements Runnable {
|
||||||
private List<OpcItemDto> protocols;
|
List<OpcItemDto> protocols;
|
||||||
private OpcServerManageDto opcServer;
|
OpcServerManageDto OpcServer;
|
||||||
private int error_num;
|
int error_num;
|
||||||
private int all_null;
|
String message;
|
||||||
private String message;
|
private Server server;
|
||||||
private Map<String, OpcItemDto> itemSearchCache;
|
|
||||||
private Server server;
|
|
||||||
|
|
||||||
|
public DeviceOpcProtocolRunable() {
|
||||||
|
this.error_num = 0;
|
||||||
|
this.message = null;
|
||||||
|
this.server = null;
|
||||||
|
}
|
||||||
|
|
||||||
public DeviceOpcProtocolRunable() {
|
public List<OpcItemDto> getProtocols() {
|
||||||
this.error_num = 0;
|
return this.protocols;
|
||||||
this.all_null = 0;
|
}
|
||||||
this.message = null;
|
|
||||||
this.itemSearchCache = new HashMap();
|
|
||||||
this.server = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<OpcItemDto> getProtocols() {
|
public void setProtocols(List<OpcItemDto> protocols) {
|
||||||
return this.protocols;
|
this.protocols = protocols;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setProtocols(List<OpcItemDto> protocols) {
|
public OpcServerManageDto getOpcServer() {
|
||||||
this.protocols = protocols;
|
return this.OpcServer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public OpcServerManageDto getOpcServer() {
|
public void setOpcServer(OpcServerManageDto opcServer) {
|
||||||
return this.opcServer;
|
this.OpcServer = opcServer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setOpcServer(OpcServerManageDto opcServer) {
|
OpcItemDto getItem(String item) {
|
||||||
this.opcServer = opcServer;
|
Iterator var2 = this.protocols.iterator();
|
||||||
}
|
|
||||||
|
|
||||||
private OpcItemDto getItem(String item) {
|
OpcItemDto dto;
|
||||||
OpcItemDto x = (OpcItemDto) this.itemSearchCache.get(item);
|
do {
|
||||||
if (x == null) {
|
if (!var2.hasNext()) {
|
||||||
Iterator var3 = this.protocols.iterator();
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
while (var3.hasNext()) {
|
dto = (OpcItemDto) var2.next();
|
||||||
OpcItemDto dto = (OpcItemDto) var3.next();
|
} while (!StrUtil.equals(item, dto.getItem_code()));
|
||||||
if (ObjectUtil.equals(item, dto.getItem_code())) {
|
|
||||||
x = dto;
|
return dto;
|
||||||
this.itemSearchCache.put(item, dto);
|
}
|
||||||
break;
|
|
||||||
}
|
@Override
|
||||||
|
public void run() {
|
||||||
|
while (true) {
|
||||||
|
try {
|
||||||
|
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());
|
||||||
|
Group group = server.addGroup(this.OpcServer.getOpc_code());
|
||||||
|
if(ObjectUtil.isEmpty(group)){
|
||||||
|
log.info("group is null ");
|
||||||
|
}
|
||||||
|
List<String> itemsString = new ArrayList();
|
||||||
|
Iterator it = this.protocols.iterator();
|
||||||
|
|
||||||
|
while (it.hasNext()) {
|
||||||
|
OpcItemDto protocol = (OpcItemDto) it.next();
|
||||||
|
String item = protocol.getItem_code();
|
||||||
|
itemsString.add(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, Item> itemsMap = new LinkedHashMap();
|
||||||
|
boolean is_error = false;
|
||||||
|
StringBuilder err_message = new StringBuilder();
|
||||||
|
Iterator var7 = itemsString.iterator();
|
||||||
|
|
||||||
|
while (var7.hasNext()) {
|
||||||
|
String string = (String) var7.next();
|
||||||
|
|
||||||
|
try {
|
||||||
|
itemsMap.put(string, group.addItem(string));
|
||||||
|
log.trace("添加成功 {}", string);
|
||||||
|
} catch (Exception var29) {
|
||||||
|
err_message.append(string + ":" + var29.getMessage());
|
||||||
|
if (!is_error) {
|
||||||
|
is_error = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return x;
|
if (is_error) {
|
||||||
}
|
log.info("设备OPC数据同步配置异常");
|
||||||
|
|
||||||
public void run() {
|
|
||||||
/* if (OpcConfig.opc_item_read_using_callback) {
|
|
||||||
this.runNew();
|
|
||||||
} else {
|
|
||||||
this.runOld();
|
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
this.runOld();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void runNew() {
|
if (!OpcStartTag.is_run) {
|
||||||
Async20Access accessor = null;
|
OpcStartTag.is_run = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//线程名
|
||||||
|
String tag = Thread.currentThread().getName();
|
||||||
|
if (this.OpcServer != null) {
|
||||||
|
tag = tag + this.OpcServer.getOpc_code();
|
||||||
|
}
|
||||||
|
UnifiedDataAccessor accessor_value = UnifiedDataAccessorFactory.getAccessor(OpcConfig.udw_opc_value_key);
|
||||||
|
|
||||||
|
boolean time_out = false;
|
||||||
|
|
||||||
|
label97:
|
||||||
while (true) {
|
while (true) {
|
||||||
String opcGroupId = this.getOpcGroupID();
|
long begin = System.currentTimeMillis();
|
||||||
|
Map<Item, ItemState> itemStatus = null;
|
||||||
try {
|
try {
|
||||||
if (this.server == null) {
|
itemStatus = group.read(true, (Item[]) itemsMap.values().toArray(new Item[0]));
|
||||||
this.server = OpcServerUtl.getServerWithOutException(this.opcServer.getOpc_host(), this.opcServer.getCls_id(), this.opcServer.getUser(), this.opcServer.getPassword(), this.opcServer.getDomain());
|
} catch (Exception e){
|
||||||
this.server.addStateListener(this);
|
System.out.println("数据同步异常:"+ this.getOpcServer().getOpc_code());
|
||||||
accessor = new Async20Access(this.server, OpcConfig.synchronized_millisecond, false);
|
log.trace("数据同步异常:{}", this.getOpcServer().getOpc_code());
|
||||||
Iterator var9 = this.protocols.iterator();
|
//e.printStackTrace();
|
||||||
|
}
|
||||||
while (var9.hasNext()) {
|
long end = System.currentTimeMillis();
|
||||||
OpcItemDto protocol = (OpcItemDto) var9.next();
|
log.trace("{} 开始记时{}", tag, DateUtil.now());
|
||||||
String itemId = protocol.getItem_code();
|
long duration = end - begin;
|
||||||
accessor.addItem(itemId, this);
|
log.trace("{} 读取耗时:{}", tag, duration);
|
||||||
}
|
// System.out.println("线程:"+tag + " 读取耗时:"+ duration);
|
||||||
|
if (duration > 1000L) {
|
||||||
accessor.bind();
|
if (!time_out) {
|
||||||
log.info("Async20Access bind {}", opcGroupId);
|
log.warn(" {} 读取超时 : {}", tag, duration);
|
||||||
}
|
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
++this.error_num;
|
|
||||||
if (this.error_num > 3 && !ObjectUtil.equal(this.message, error_message)) {
|
|
||||||
this.message = error_message;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void runOld() {
|
|
||||||
while (true) {
|
|
||||||
try {
|
|
||||||
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);
|
|
||||||
Group group = this.server.addGroup();
|
|
||||||
List<String> itemsString = new ArrayList();
|
|
||||||
Iterator var3 = this.protocols.iterator();
|
|
||||||
|
|
||||||
while (var3.hasNext()) {
|
|
||||||
OpcItemDto protocol = (OpcItemDto) var3.next();
|
|
||||||
String item = protocol.getItem_code();
|
|
||||||
itemsString.add(item);
|
|
||||||
}
|
|
||||||
// Map<String, Item> itemsMap = new LinkedHashMap();
|
|
||||||
boolean is_error = false;
|
|
||||||
StringBuilder err_message = new StringBuilder();
|
|
||||||
|
|
||||||
log.info("开始添加组数据.....");
|
|
||||||
long start = System.currentTimeMillis();
|
|
||||||
Map<String, Item> itemMap = group.addItems(itemsString.toArray(new String[itemsString.size()]));
|
|
||||||
Set itemSet = new HashSet(itemMap.values());
|
|
||||||
Item[] itemArr = new Item[itemSet.size()];
|
|
||||||
itemSet.toArray(itemArr);
|
|
||||||
long end = System.currentTimeMillis();
|
|
||||||
log.info("组数据添加完成.....{},耗时:{}毫秒", itemSet, (end - start));
|
|
||||||
String tag;
|
|
||||||
if (is_error) {
|
|
||||||
tag = err_message.toString();
|
|
||||||
log.warn("{}:{}", OpcConfig.resource_code, tag);
|
|
||||||
}
|
|
||||||
if (!OpcStartTag.is_run) {
|
|
||||||
OpcStartTag.is_run = true;
|
|
||||||
}
|
|
||||||
tag = "";
|
|
||||||
if (log.isWarnEnabled()) {
|
|
||||||
tag = Thread.currentThread().getName();
|
|
||||||
if (this.opcServer != null) {
|
|
||||||
tag = tag + this.getOpcGroupID();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
UnifiedDataAccessor accessor_value = UnifiedDataAccessorFactory.getAccessor(OpcConfig.udw_opc_value_key);
|
|
||||||
boolean time_out = false;
|
|
||||||
|
|
||||||
while (DeviceOpcSynchronizeAutoRun.isRun) {
|
|
||||||
log.info("开始读取组数据.....");
|
|
||||||
long begin = System.currentTimeMillis();
|
|
||||||
Map<Item, ItemState> itemStatus = group.read(true, itemArr);
|
|
||||||
long endRead = System.currentTimeMillis();
|
|
||||||
log.info("读取组数据完成.....,总共读取:{}条,耗时:{}毫秒", itemStatus.size(), (endRead - begin));
|
|
||||||
long duration = endRead - begin;
|
|
||||||
if (duration > 1000L) {
|
|
||||||
if (!time_out) {
|
|
||||||
log.warn("{} 读取超时 : {}", tag, duration);
|
|
||||||
}
|
|
||||||
time_out = true;
|
|
||||||
} else {
|
|
||||||
time_out = false;
|
|
||||||
}
|
|
||||||
boolean valueAllNotNull = false;
|
|
||||||
for (Item item : itemStatus.keySet()) {
|
|
||||||
ItemState itemState = itemStatus.get(item);
|
|
||||||
Object value = OpcUtl.getValue(item, itemState);
|
|
||||||
if (value == null) {
|
|
||||||
valueAllNotNull = true;
|
|
||||||
log.info("读取到值为空,设备号:{},健康值:{}", item.getId(), itemState.getQuality());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
String itemId = item.getId();
|
|
||||||
Object his = accessor_value.getValue(itemId);
|
|
||||||
if (!ObjectUtil.equals(itemState.getQuality(), QualityTypeValue.OPC_QUALITY_GOOD) && his != null) {
|
|
||||||
log.warn("opc 值不健康 item: {}, 状态: {}", itemId, itemState.getQuality());
|
|
||||||
}
|
|
||||||
if (!UnifiedDataAppService.isEquals(value, his)) {
|
|
||||||
OpcItemDto itemDto = this.getItem(itemId);
|
|
||||||
if (Boolean.TRUE.equals(itemDto.getNeed_log())) {
|
|
||||||
this.logItemChanged(itemId, accessor_value, value, itemDto);
|
|
||||||
}
|
|
||||||
accessor_value.setValue(itemId, value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (valueAllNotNull) {
|
|
||||||
ThreadUtl.sleep(3000L);
|
|
||||||
log.info("读取组数据不健康,重新读取......");
|
|
||||||
itemStatus = group.read(true, itemArr);
|
|
||||||
for (Item item : itemStatus.keySet()) {
|
|
||||||
ItemState itemState = itemStatus.get(item);
|
|
||||||
Object value = OpcUtl.getValue(item, itemState);
|
|
||||||
if (value == null){
|
|
||||||
log.info("再次读取组数据为空,终止读取,设备号:{}",item.getId());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
String itemId = item.getId();
|
|
||||||
Object his = accessor_value.getValue(itemId);
|
|
||||||
if (!UnifiedDataAppService.isEquals(value, his)) {
|
|
||||||
OpcItemDto itemDto = this.getItem(itemId);
|
|
||||||
if (Boolean.TRUE.equals(itemDto.getNeed_log())) {
|
|
||||||
this.logItemChanged(itemId, accessor_value, value, itemDto);
|
|
||||||
}
|
|
||||||
accessor_value.setValue(itemId, value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
end = System.currentTimeMillis();
|
|
||||||
ThreadUtl.sleep((long) OpcConfig.synchronized_millisecond);
|
|
||||||
}
|
|
||||||
|
|
||||||
log.warn("opc线程停止。。。");
|
|
||||||
return;
|
|
||||||
} catch (Exception var27) {
|
|
||||||
if (this.server != null) {
|
|
||||||
try {
|
|
||||||
this.server.dispose();
|
|
||||||
} catch (Exception var25) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.server = null;
|
|
||||||
if (!DeviceOpcSynchronizeAutoRun.isRun) {
|
|
||||||
log.warn("opc线程停止2。。。");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// String error_message = MessageFormatUtl.format("设备信息同步异常:{}", new Object[]{var27.getMessage()});
|
|
||||||
String error_message = "";
|
|
||||||
if (!ObjectUtil.equals(this.message, error_message)) {
|
|
||||||
log.warn(error_message, var27);
|
|
||||||
}
|
|
||||||
|
|
||||||
ThreadUtl.sleep((long) (OpcConfig.synchronized_exception_wait_second * 1000));
|
|
||||||
++this.error_num;
|
|
||||||
if (this.error_num > 3 && !ObjectUtil.equals(this.message, error_message)) {
|
|
||||||
this.message = error_message;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
time_out = true;
|
||||||
if (Boolean.TRUE.equals(itemDto.getNeed_log())) {
|
} else {
|
||||||
this.logItemChanged(itemId, accessor_value, value, itemDto);
|
time_out = false;
|
||||||
}
|
}
|
||||||
} catch (BadRequestException var7) {
|
|
||||||
log.error(itemId, var7);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
if(ObjectUtil.isEmpty(itemStatus)) {
|
||||||
|
System.out.println( tag + " :itemStatus is null");
|
||||||
|
log.warn(" {} 读取异常 : {} itemStatus is null", tag);
|
||||||
|
}
|
||||||
|
|
||||||
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()) {
|
Set<Item> items = itemStatus.keySet();
|
||||||
String relate = (String) var8.next();
|
Iterator var18 = items.iterator();
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
Item item;
|
||||||
|
//当前值
|
||||||
|
Object value;
|
||||||
|
//旧的值
|
||||||
|
Object his;
|
||||||
|
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) {
|
||||||
|
log.warn("opc 值不健康 item: {}, 状态: {},当前读取值:{}, 系统内存值{} ", item.getId(), itemState.getQuality(), value, his);
|
||||||
|
}
|
||||||
|
} while (ObjectUtil.equal(value, his));//如果两次的值相等,不走下面的代码
|
||||||
|
|
||||||
|
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 relate = (String) var26.next();
|
||||||
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[]{item.getId(), his, value, sb});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
// accessor_value.setValueWithPersistence(item.getId(),accessor_value.getValue(item.getId()));
|
||||||
|
// accessor_value.getHistoryUnifiedData(item.getId());
|
||||||
|
//设置值
|
||||||
|
accessor_value.setValue(item.getId(), value);
|
||||||
|
|
||||||
} else {
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception var30) {
|
||||||
|
if (this.server != null) {
|
||||||
|
try {
|
||||||
|
this.server.disconnect();
|
||||||
|
} catch (Exception var25) {
|
||||||
|
log.warn("{} : server disconnect", var25);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
this.server = null;
|
||||||
|
|
||||||
public void connectionStateChanged(boolean connected) {
|
String error_message = "设备信息同步异常,"+var30;
|
||||||
if (!connected) {
|
if (!StrUtil.equals(this.message, error_message)) {
|
||||||
this.server = null;
|
log.warn("", var30);
|
||||||
}
|
}
|
||||||
|
|
||||||
log.warn("opc server {} {}", this.getOpcGroupID(), connected ? "connected" : "disconnected");
|
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;
|
||||||
|
if (this.error_num > 3 && !StrUtil.equals(this.message, error_message)) {
|
||||||
|
log.info("设备同步通信异常");
|
||||||
|
this.message = error_message;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private String getOpcGroupID() {
|
public static String formatDuring(long mss) {
|
||||||
return this.opcServer.getOpc_code() + "(" + this.protocols.size() + " items)";
|
long days = mss / 86400000L;
|
||||||
}
|
long hours = mss % 86400000L / 3600000L;
|
||||||
|
long minutes = mss % 3600000L / 60000L;
|
||||||
|
long seconds = mss % 60000L / 1000L;
|
||||||
|
return days + " days " + hours + " hours " + minutes + " minutes " + seconds + " seconds ";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,72 @@
|
|||||||
|
package org.nl.acs.opc;
|
||||||
|
|
||||||
|
|
||||||
|
import org.nl.modules.wql.exception.WDKException;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class ObjectUtl {
|
||||||
|
private ObjectUtl() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isEquals(Object a, Object b) {
|
||||||
|
if (a == null && b == null) {
|
||||||
|
return true;
|
||||||
|
} else if (a != null && b != null) {
|
||||||
|
if (a.getClass().isArray()) {
|
||||||
|
if (a instanceof boolean[]) {
|
||||||
|
return Arrays.equals((boolean[]) ((boolean[]) a), (boolean[]) ((boolean[]) b));
|
||||||
|
} else if (a instanceof byte[]) {
|
||||||
|
return Arrays.equals((byte[]) ((byte[]) a), (byte[]) ((byte[]) b));
|
||||||
|
} else if (a instanceof int[]) {
|
||||||
|
return Arrays.equals((int[]) ((int[]) a), (int[]) ((int[]) b));
|
||||||
|
} else if (a instanceof long[]) {
|
||||||
|
return Arrays.equals((long[]) ((long[]) a), (long[]) ((long[]) b));
|
||||||
|
} else if (a instanceof double[]) {
|
||||||
|
return Arrays.equals((double[]) ((double[]) a), (double[]) ((double[]) b));
|
||||||
|
} else if (a instanceof short[]) {
|
||||||
|
return Arrays.equals((short[]) ((short[]) a), (short[]) ((short[]) b));
|
||||||
|
} else if (a instanceof char[]) {
|
||||||
|
return Arrays.equals((char[]) ((char[]) a), (char[]) ((char[]) b));
|
||||||
|
} else if (a instanceof float[]) {
|
||||||
|
return Arrays.equals((float[]) ((float[]) a), (float[]) ((float[]) b));
|
||||||
|
} else if (a instanceof Object[]) {
|
||||||
|
return Arrays.equals((Object[]) ((Object[]) a), (Object[]) ((Object[]) b));
|
||||||
|
} else {
|
||||||
|
throw new WDKException("未实现");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return Objects.equals(a, b);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isTrue(Boolean boolean_) {
|
||||||
|
return boolean_ != null && isEquals(boolean_, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isTrue(Boolean targetBoolean, boolean defaultBoolean) {
|
||||||
|
return targetBoolean == null ? defaultBoolean : targetBoolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isFalse(Boolean boolean_) {
|
||||||
|
return boolean_ != null && isEquals(boolean_, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static boolean isObject(Class<?> clazz) {
|
||||||
|
if (clazz == null) {
|
||||||
|
return false;
|
||||||
|
} else if (clazz.getClass().isArray()) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return Object.class.isAssignableFrom(clazz);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -895,6 +895,9 @@ public class TaskServiceImpl implements TaskService, ApplicationAutoInitial {
|
|||||||
instdto.setVehicle_type(vehicleType);
|
instdto.setVehicle_type(vehicleType);
|
||||||
|
|
||||||
instructionservice.create(instdto);
|
instructionservice.create(instdto);
|
||||||
|
|
||||||
|
acsTask.setTask_status("1");
|
||||||
|
this.update(acsTask);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package org.nl.modules.quartz.task;
|
|||||||
|
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import cn.hutool.core.util.IdUtil;
|
import cn.hutool.core.util.IdUtil;
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.ObjectUtils;
|
import org.apache.commons.lang3.ObjectUtils;
|
||||||
@@ -37,6 +38,7 @@ public class AutoCreateInst {
|
|||||||
DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class);
|
DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class);
|
||||||
|
|
||||||
List<TaskDto> list = taskserver.queryAll("task_status = '0'");
|
List<TaskDto> list = taskserver.queryAll("task_status = '0'");
|
||||||
|
System.out.println("查询到任务数量为:" + (ObjectUtil.isNotEmpty(list) ? list.size() : 0));
|
||||||
for (int i = 0; i < list.size(); i++) {
|
for (int i = 0; i < list.size(); i++) {
|
||||||
TaskDto acsTask = list.get(i);
|
TaskDto acsTask = list.get(i);
|
||||||
String taskid = acsTask.getTask_id();
|
String taskid = acsTask.getTask_id();
|
||||||
|
|||||||
@@ -84,6 +84,9 @@ https://juejin.cn/post/6844903775631572999
|
|||||||
<logger name="org.springframework" level="ERROR" additivity="false">
|
<logger name="org.springframework" level="ERROR" additivity="false">
|
||||||
<appender-ref ref="CONSOLE"/>
|
<appender-ref ref="CONSOLE"/>
|
||||||
</logger>
|
</logger>
|
||||||
|
<logger name="com.github.loki4j.client.pipeline" level="ERROR" additivity="false">
|
||||||
|
<appender-ref ref="CONSOLE"/>
|
||||||
|
</logger>
|
||||||
<logger name="org.apache" level="ERROR" additivity="false">
|
<logger name="org.apache" level="ERROR" additivity="false">
|
||||||
<appender-ref ref="CONSOLE"/>
|
<appender-ref ref="CONSOLE"/>
|
||||||
</logger>
|
</logger>
|
||||||
@@ -122,8 +125,8 @@ https://juejin.cn/post/6844903775631572999
|
|||||||
|
|
||||||
<!--生产环境:打印控制台和输出到文件-->
|
<!--生产环境:打印控制台和输出到文件-->
|
||||||
<springProfile name="prod">
|
<springProfile name="prod">
|
||||||
<root level="debug">
|
<root level="info">
|
||||||
<appender-ref ref="asyncFileAppender"/>
|
<!-- <appender-ref ref="asyncFileAppender"/>-->
|
||||||
<appender-ref ref="lokiAppender"/>
|
<appender-ref ref="lokiAppender"/>
|
||||||
<!-- <appender-ref ref="CONSOLE"/>-->
|
<!-- <appender-ref ref="CONSOLE"/>-->
|
||||||
</root>
|
</root>
|
||||||
|
|||||||
Reference in New Issue
Block a user