合并代码

This commit is contained in:
USER-20220102CG\noblelift
2024-05-13 15:14:20 +08:00
parent a05fa03de5
commit afc6f0de94

View File

@@ -1,8 +1,10 @@
package org.nl.acs.opc;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.apache.lucene.util.NamedThreadFactory;
import org.nl.acs.AcsConfig;
import org.nl.acs.auto.run.AbstractAutoRunnable;
import org.nl.acs.opc.service.dto.OpcServerManageDto;
import org.nl.acs.udw.UnifiedDataAccessor;
@@ -11,6 +13,7 @@ import org.nl.acs.udw.UnifiedDataAppService;
import org.nl.common.enums.LogTypeEnum;
import org.nl.config.SpringContextHolder;
import org.nl.config.lucene.service.dto.LuceneLogDto;
import org.nl.system.service.param.ISysParamService;
import org.openscada.opc.lib.da.Group;
import org.openscada.opc.lib.da.Item;
import org.openscada.opc.lib.da.ItemState;
@@ -20,6 +23,7 @@ import org.springframework.stereotype.Component;
import java.util.*;
import java.util.Map.Entry;
import java.util.concurrent.*;
import java.util.regex.Pattern;
/**
* OPC设备同步启动
@@ -250,6 +254,7 @@ public class DeviceOpcSynchronizeAutoRun extends AbstractAutoRunnable {
}
private void logItemChanged(String itemId, UnifiedDataAccessor accessor_value, Object value, OpcItemDto itemDto) {
ISysParamService paramService = SpringContextHolder.getBean(ISysParamService.class);
Object his = accessor_value.getValue(itemId);
List<String> relate_items = itemDto.getRelate_items();
if (relate_items != null && !relate_items.isEmpty()) {
@@ -264,34 +269,38 @@ public class DeviceOpcSynchronizeAutoRun extends AbstractAutoRunnable {
if (!itemDto.getItem_code().endsWith("heartbeat") && !itemDto.getItem_code().endsWith("time") && !itemDto.getItem_code().endsWith("consumption")) {
// 存在上次点位值为null情况 则不记录日志
if(!(his instanceof Float) && !(value instanceof Float)){
LuceneLogDto luceneLogDto = new LuceneLogDto(itemDto.getOpc_server_code(), itemDto.getOpc_plc_code(), itemDto.getDevice_code(), itemDto.getItem_code().substring(itemDto.getItem_code().lastIndexOf(".") + 1),
LuceneLogDto luceneLogDto = new LuceneLogDto(itemDto.getOpc_server_code(), itemDto.getOpc_plc_code(),4, itemDto.getDevice_code(), itemDto.getItem_code().substring(itemDto.getItem_code().lastIndexOf(".") + 1),
String.valueOf(his), String.valueOf(value));
luceneLogDto.setLogType(LogTypeEnum.DEVICE_LOG.getDesc());
log.info("{}", JSON.toJSONString(luceneLogDto));
String logLevel = paramService.findByCode(AcsConfig.LOGLEVEL).getValue();
if(StrUtil.isNotEmpty(logLevel) && isNumeric(logLevel) && (luceneLogDto.getLog_level() >= Integer.parseInt(logLevel))){
log.info("{}", JSON.toJSONString(luceneLogDto));
}
}
}
} else {
// if(his instanceof int[]){
// if(!Arrays.equals((long[]) his, (long[]) value)){
// log.warn("设备:{}信号{}变更从{}->{};信号快照:{}", new Object[]{itemDto.getDevice_code(), itemId, his, value});
// if (!itemDto.getItem_code().endsWith("heartbeat") && !itemDto.getItem_code().endsWith("time") && !itemDto.getItem_code().endsWith("consumption")) {
// if(!(his instanceof Float) && !(value instanceof Float)){
// LuceneLogDto luceneLogDto = 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));
// luceneLogDto.setLogType(LogTypeEnum.DEVICE_LOG.getDesc());
// log.info("{}", JSON.toJSONString(luceneLogDto));
// }
// } else if(his instanceof String){
// if(!StrUtil.equals((CharSequence) his, (CharSequence) value)){
// log.warn("设备:{}信号{}变更从{}->{};信号快照:{}", new Object[]{itemDto.getDevice_code(), itemId, his, value});
// }
// } else {
// log.warn("设备:{}信号{}变更从{}->{};信号快照:{}", new Object[]{itemDto.getDevice_code(), itemId, his, value});
// }
// log.warn("设备:{}信号{}变更从{}->{};信号快照:{}", new Object[]{itemDto.getDevice_code(), itemId, his, value});
if (!itemDto.getItem_code().endsWith("heartbeat") && !itemDto.getItem_code().endsWith("time") && !itemDto.getItem_code().endsWith("consumption")) {
if(!(his instanceof Float) && !(value instanceof Float)){
LuceneLogDto luceneLogDto = new LuceneLogDto(itemDto.getOpc_server_code(), itemDto.getOpc_plc_code(), itemDto.getDevice_code(), itemDto.getItem_code().substring(itemDto.getItem_code().lastIndexOf(".") + 1),
LuceneLogDto luceneLogDto = new LuceneLogDto(itemDto.getOpc_server_code(), itemDto.getOpc_plc_code(),4, itemDto.getDevice_code(), itemDto.getItem_code().substring(itemDto.getItem_code().lastIndexOf(".") + 1),
String.valueOf(his), String.valueOf(value));
luceneLogDto.setLogType(LogTypeEnum.DEVICE_LOG.getDesc());
log.info("{}", JSON.toJSONString(luceneLogDto));
String logLevel = paramService.findByCode(AcsConfig.LOGLEVEL).getValue();
if(StrUtil.isNotEmpty(logLevel) && isNumeric(logLevel) && (luceneLogDto.getLog_level() >= Integer.parseInt(logLevel))){
log.info("{}", JSON.toJSONString(luceneLogDto));
}
}
}
}
}
@@ -300,4 +309,8 @@ public class DeviceOpcSynchronizeAutoRun extends AbstractAutoRunnable {
canReadOpcValues = new ConcurrentHashMap();
opcCodeOpcEntityMapping = new ConcurrentHashMap();
}
public static boolean isNumeric(String str) {
return Pattern.compile("^[0-9]+$").matcher(str).matches();
}
}