日志fix
This commit is contained in:
@@ -177,7 +177,7 @@ public class XgagvDeviceDriver extends AbstractOpcDeviceDriver implements Device
|
||||
// .build();
|
||||
// luceneExecuteLogService.deviceExecuteLog(logDto);
|
||||
luceneExecuteLogService.deviceExecuteLog(
|
||||
new LuceneLogDto(this.getDevice().getOpc_server_code(),this.getDevice().getOpc_plc_code(),this.device_code,ItemProtocol.to_home_relocation,this.last_home_relocation,this.home_relocation));
|
||||
new LuceneLogDto(this.getDevice().getOpc_server_code(),this.getDevice().getOpc_plc_code(),this.device_code,ItemProtocol.to_home_relocation,String.valueOf(this.last_home_relocation),String.valueOf(this.home_relocation)));
|
||||
}
|
||||
|
||||
if (stop != last_stop) {
|
||||
|
||||
@@ -166,7 +166,6 @@ public class BaoshijianSiteDeviceDriver extends AbstractOpcDeviceDriver implemen
|
||||
String message = null;
|
||||
try {
|
||||
device_code = this.getDeviceCode();
|
||||
log.info("123:"+device_code);
|
||||
x0 = this.itemProtocol.getX0();
|
||||
x1 = this.itemProtocol.getX1();
|
||||
x2 = this.itemProtocol.getX2();
|
||||
|
||||
@@ -39,7 +39,7 @@ public interface DeviceAppService {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
Map<String, List<List<OpcItemDto>>> findAllFormatProtocolFromDriver();
|
||||
Map<String, List<List<org.nl.acs.opc.OpcItemDto>>> findAllFormatProtocolFromDriver();
|
||||
|
||||
Map<String, List<List<OpcItemDto>>> findAllFormatProtocolFromDriverByPlc();
|
||||
|
||||
|
||||
@@ -128,7 +128,7 @@ public class DeviceAppServiceImpl implements DeviceAppService, ApplicationAutoIn
|
||||
while (var21.hasNext()) {
|
||||
String string = (String) var21.next();
|
||||
List<OpcItemDto> device = (List) deviceMap.get(string);
|
||||
if (temp.size() + device.size() > WcsConfig.opc_group_sync_max_item) {
|
||||
if (temp.size() + device.size() > org.nl.acs.opc.WcsConfig.opc_group_sync_max_item) {
|
||||
if (temp.size() > 0) {
|
||||
serverResult.add(temp);
|
||||
temp = new ArrayList();
|
||||
@@ -234,14 +234,13 @@ public class DeviceAppServiceImpl implements DeviceAppService, ApplicationAutoIn
|
||||
|
||||
@Override
|
||||
public <T extends DeviceDriver> List<T> findDeviceDriver(Class<T> clazz) {
|
||||
List<T> list = new ArrayList<>();
|
||||
List<Device> devices = new ArrayList<>(this.findAllDevice()); // Create a copy of the collection
|
||||
Iterator<Device> var3 = devices.iterator();
|
||||
List<T> list = new ArrayList();
|
||||
Iterator var3 = this.findAllDevice().iterator();
|
||||
|
||||
while (var3.hasNext()) {
|
||||
Device device = var3.next();
|
||||
Device device = (Device) var3.next();
|
||||
DeviceDriver deviceDriver = device.getDeviceDriver();
|
||||
// 查找某驱动的所有子类
|
||||
//查找某驱动的所有子类
|
||||
if (deviceDriver != null && clazz.isAssignableFrom(deviceDriver.getClass())) {
|
||||
list.add((T) device.getDeviceDriver());
|
||||
}
|
||||
@@ -250,7 +249,6 @@ public class DeviceAppServiceImpl implements DeviceAppService, ApplicationAutoIn
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Map<String, String> findDeviceOptions(DeviceType deviceType) {
|
||||
List<Device> list = this.findDevice(deviceType);
|
||||
|
||||
@@ -3,7 +3,7 @@ package org.nl.acs.opc;
|
||||
import java.util.List;
|
||||
|
||||
public interface DeviceManageService {
|
||||
List<DeviceManageDto> queryAllWithExtra();
|
||||
List<org.nl.acs.opc.DeviceManageDto> queryAllWithExtra();
|
||||
|
||||
List<DeviceManageDto> queryAllWithExtra(String device_code);
|
||||
}
|
||||
|
||||
@@ -1,24 +1,21 @@
|
||||
package org.nl.acs.opc;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.acs.opc.service.dto.OpcServerManageDto;
|
||||
import org.nl.acs.udw.UnifiedDataAccessor;
|
||||
import org.nl.acs.udw.UnifiedDataAccessorFactory;
|
||||
import org.nl.acs.udw.UnifiedDataAppService;
|
||||
import org.nl.common.enums.LogTypeEnum;
|
||||
import org.nl.config.SpringContextHolder;
|
||||
import org.nl.system.service.lucene.LuceneExecuteLogService;
|
||||
import org.nl.system.service.lucene.dto.LuceneLogDto;
|
||||
import org.openscada.opc.lib.da.*;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author 20220102CG\noblelift
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerConnectionStateListener {
|
||||
List<OpcItemDto> protocols;
|
||||
OpcServerManageDto OpcServer;
|
||||
@@ -31,8 +28,7 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC
|
||||
private int all_null;
|
||||
private Map<String, OpcItemDto> itemSearchCache;
|
||||
|
||||
// @Autowired
|
||||
// OpcServerService opcServerService;
|
||||
LuceneExecuteLogService lucene = SpringContextHolder.getBean(LuceneExecuteLogService.class);
|
||||
|
||||
|
||||
public DeviceOpcProtocolRunable() {
|
||||
@@ -59,12 +55,10 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC
|
||||
this.OpcServer = opcServer;
|
||||
}
|
||||
|
||||
|
||||
private OpcItemDto getItem(String item) {
|
||||
OpcItemDto x = (OpcItemDto) this.itemSearchCache.get(item);
|
||||
if (x == null) {
|
||||
Iterator var3 = this.protocols.iterator();
|
||||
|
||||
while (var3.hasNext()) {
|
||||
OpcItemDto dto = (OpcItemDto) var3.next();
|
||||
if (StrUtil.equals(item, dto.getItem_code())) {
|
||||
@@ -74,11 +68,9 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (OpcConfig.opc_item_read_using_callback) {
|
||||
@@ -88,8 +80,8 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void runOld() {
|
||||
OpcServerService opcServerService = SpringContextHolder.getBean(OpcServerService .class);
|
||||
while (true) {
|
||||
start:
|
||||
try {
|
||||
@@ -102,11 +94,11 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC
|
||||
server.disconnect();
|
||||
log.trace("清理server...");
|
||||
}
|
||||
OpcServerService opcServerService = SpringContextHolder.getBean(OpcServerService.class);
|
||||
group = opcServerService.getServer(this.getOpcServer().getOpc_code());
|
||||
// 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 = this.server.addGroup();
|
||||
|
||||
// group =opcServerService.getServer(this.getOpcServer().getOpc_code());
|
||||
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 = this.server.addGroup();
|
||||
List<String> itemsString = new ArrayList();
|
||||
Iterator var3 = this.protocols.iterator();
|
||||
|
||||
@@ -127,7 +119,7 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC
|
||||
try {
|
||||
Item item = group.addItem(string);
|
||||
itemsMap.put(string, item);
|
||||
log.trace("添加成功 {}", string);
|
||||
// log.trace("添加成功 {}", string);
|
||||
} catch (Exception var26) {
|
||||
err_message.append(string + ":" + var26.getMessage());
|
||||
if (!is_error) {
|
||||
@@ -139,13 +131,14 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC
|
||||
String tag;
|
||||
if (is_error) {
|
||||
tag = err_message.toString();
|
||||
log.warn("{}:{}", OpcConfig.resource_code, tag);
|
||||
// log.warn("{}:{}", OpcConfig.resource_code, tag);
|
||||
}
|
||||
|
||||
if (!OpcStartTag.is_run) {
|
||||
OpcStartTag.is_run = true;
|
||||
}
|
||||
|
||||
//线程名
|
||||
tag = "";
|
||||
if (log.isWarnEnabled()) {
|
||||
tag = Thread.currentThread().getName();
|
||||
@@ -153,26 +146,25 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC
|
||||
tag = tag + this.getOpcGroupID();
|
||||
}
|
||||
}
|
||||
|
||||
UnifiedDataAccessor accessor_value = UnifiedDataAccessorFactory.getAccessor(OpcConfig.udw_opc_value_key);
|
||||
boolean time_out = false;
|
||||
|
||||
label97:
|
||||
while (DeviceOpcSynchronizeAutoRun.isRun) {
|
||||
long begin = System.currentTimeMillis();
|
||||
if (log.isTraceEnabled()) {
|
||||
log.trace("{} 开始记时{}", tag, DateUtil.now());
|
||||
// log.trace("{} 开始记时{}", tag, DateUtil.now());
|
||||
}
|
||||
|
||||
Map<Item, ItemState> itemStatus = group.read(true, (Item[]) itemsMap.values().toArray(new Item[0]));
|
||||
long end = System.currentTimeMillis();
|
||||
long duration = end - begin;
|
||||
if (log.isTraceEnabled()) {
|
||||
log.trace("{} 读取耗时:{}", tag, duration);
|
||||
// log.trace("{} 读取耗时:{}", tag, duration);
|
||||
}
|
||||
|
||||
if (duration > 1000L) {
|
||||
if (!time_out) {
|
||||
log.warn("{} 读取超时 : {}", tag, duration);
|
||||
// log.warn("{} 读取超时 : {}", tag, duration);
|
||||
}
|
||||
|
||||
time_out = true;
|
||||
@@ -195,8 +187,7 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC
|
||||
String itemId = item.getId();
|
||||
Object his = accessor_value.getValue(itemId);
|
||||
if (!ObjectUtl.isEquals(itemState.getQuality(), QualityTypeValue.OPC_QUALITY_GOOD) && his != null) {
|
||||
log.warn("opc 值不健康 item: {}, 状态: {}", itemId, itemState.getQuality());
|
||||
valueAllNotNull = true;
|
||||
// log.warn("opc 值不健康 item: {}, 状态: {}", itemId, itemState.getQuality());
|
||||
}
|
||||
|
||||
if (!UnifiedDataAppService.isEquals(value, his)) {
|
||||
@@ -204,11 +195,10 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC
|
||||
if (true) {
|
||||
this.logItemChanged(itemId, accessor_value, value, itemDto);
|
||||
}
|
||||
if (!ObjectUtil.isEmpty(value)) {
|
||||
|
||||
accessor_value.setValue(itemId, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
end = System.currentTimeMillis();
|
||||
if (log.isTraceEnabled()) {
|
||||
@@ -229,30 +219,29 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC
|
||||
if (log.isWarnEnabled()) {
|
||||
log.warn("{} 所有内容都为空, all_null:{} ,暂定{}s", tag, all_null, 5000 + random);
|
||||
}
|
||||
|
||||
ThreadUtl.sleep((long) (5000 + random));
|
||||
ThreadUtl.sleep((long) ((new Random()).nextInt(3) + 1) * 1000);
|
||||
break start;
|
||||
} else if (this.all_null < 6) {
|
||||
if (log.isWarnEnabled()) {
|
||||
log.warn(tag + "重新创建server");
|
||||
log.warn("{} 所有内容都为空, all_null:{} ,暂定{}s", tag, all_null, 30000 + random);
|
||||
}
|
||||
// ThreadUtl.sleep((long) (30000 + random));
|
||||
ThreadUtl.sleep((long) ((new Random()).nextInt(3) + 1) * 1000);
|
||||
break start;
|
||||
} else if (this.all_null < 12) {
|
||||
if (log.isWarnEnabled()) {
|
||||
log.warn("{} 所有内容都为空, all_null:{} ,暂定{}ms", tag, all_null, '\uea60' + random);
|
||||
// log.warn("{} 所有内容都为空, all_null:{} ,暂定{}ms", tag, all_null, '\uea60' + random);
|
||||
}
|
||||
ThreadUtl.sleep((long) ((new Random()).nextInt(3) + 1) * 1000);
|
||||
break start;
|
||||
|
||||
ThreadUtl.sleep((long) ('\uea60' + random));
|
||||
} else {
|
||||
if (log.isWarnEnabled()) {
|
||||
log.warn("{} 所有内容都为空, all_null:{} ,暂定{}ms", tag, all_null, 120000 + random);
|
||||
// log.warn("{} 所有内容都为空, all_null:{} ,暂定{}ms", tag, all_null, 120000 + random);
|
||||
}
|
||||
|
||||
ThreadUtl.sleep((long) (120000 + random));
|
||||
// ThreadUtl.sleep((long) ((new Random()).nextInt(3) + 1) * 1000);
|
||||
// break start;
|
||||
}
|
||||
|
||||
++this.all_null;
|
||||
} else {
|
||||
this.all_null = 0;
|
||||
@@ -268,9 +257,9 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC
|
||||
try {
|
||||
this.server.disconnect();
|
||||
} catch (Exception var25) {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
this.server = null;
|
||||
if (!DeviceOpcSynchronizeAutoRun.isRun) {
|
||||
log.warn("opc线程停止2。。。");
|
||||
@@ -357,14 +346,12 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void connectionStateChanged(boolean connected) {
|
||||
if (!connected) {
|
||||
this.server = null;
|
||||
}
|
||||
|
||||
log.warn("opc server {} {}", this.getOpcGroupID(), connected ? "connected" : "disconnected");
|
||||
// log.warn("opc server {} {}", this.getOpcGroupID(), connected ? "connected" : "disconnected");
|
||||
}
|
||||
|
||||
private String getOpcGroupID() {
|
||||
@@ -379,9 +366,6 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC
|
||||
long seconds = mss % 60000L / 1000L;
|
||||
return days + " days " + hours + " hours " + minutes + " minutes " + seconds + " seconds ";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void changed(Item item, ItemState itemState) {
|
||||
String itemId = item.getId();
|
||||
|
||||
@@ -397,7 +381,7 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC
|
||||
// } else if (log.isInfoEnabled()) {
|
||||
// log.info("Item {} new value: {}, Timestamp: {}, Quality: {}", new Object[]{itemId, itemState.getValue(), itemState.getTimestamp().getTime(), itemState.getQuality()});
|
||||
// }
|
||||
log.trace("Item {} new value: {}, Timestamp: {}", new Object[]{itemId, itemState.getValue(), itemState.getTimestamp().getTime()});
|
||||
// log.trace("Item {} new value: {}, Timestamp: {}", new Object[]{itemId, itemState.getValue(), itemState.getTimestamp().getTime()});
|
||||
|
||||
OpcItemDto itemDto = this.getItem(itemId);
|
||||
// if (Boolean.TRUE.equals(itemDto.getNeed_log())) {
|
||||
@@ -413,6 +397,8 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC
|
||||
|
||||
private void logItemChanged(String itemId, UnifiedDataAccessor accessor_value, Object value, OpcItemDto itemDto) {
|
||||
Object his = accessor_value.getValue(itemId);
|
||||
itemDto.setHis_item_value(his);
|
||||
itemDto.setItem_value(value);
|
||||
List<String> relate_items = itemDto.getRelate_items();
|
||||
if (relate_items != null && !relate_items.isEmpty()) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
@@ -423,21 +409,23 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC
|
||||
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 {
|
||||
if(his instanceof int[]){
|
||||
if(!Arrays.equals((long[]) his, (long[]) value)){
|
||||
log.warn("设备:{}信号{}变更从{}->{};信号快照:{}", new Object[]{itemDto.getDevice_code(), itemId, his, value});
|
||||
}
|
||||
} else if(his instanceof String){
|
||||
if(!StrUtil.equals((CharSequence) his, (CharSequence) value)){
|
||||
log.warn("设备:{}信号{}变更从{}->{};信号快照:{}", new Object[]{itemDto.getDevice_code(), itemId, his, value});
|
||||
if (!itemDto.getItem_code().endsWith("heartbeat") && !itemDto.getItem_code().endsWith("time")) {
|
||||
// 存在上次点位值为null情况 则不记录日志
|
||||
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(itemDto.getHis_item_value()), String.valueOf(itemDto.getItem_value()));
|
||||
luceneLogDto.setLogType(LogTypeEnum.DEVICE_LOG.getDesc());
|
||||
log.info("{}", JSON.toJSONString(luceneLogDto));
|
||||
}
|
||||
} else {
|
||||
log.warn("设备:{}信号{}变更从{}->{};信号快照:{}", new Object[]{itemDto.getDevice_code(), itemId, his, value});
|
||||
// log.info("设备:{}信号{}变更从{}->{};信号快照:{}", new Object[]{itemDto.getDevice_code(), itemId, his, value});
|
||||
// 存在上次点位值为null情况 则不记录日志
|
||||
if (!itemDto.getItem_code().endsWith("heartbeat") && !itemDto.getItem_code().endsWith("time")) {
|
||||
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(itemDto.getHis_item_value()), String.valueOf(itemDto.getItem_value()));
|
||||
luceneLogDto.setLogType(LogTypeEnum.DEVICE_LOG.getDesc());
|
||||
log.info("{}", JSON.toJSONString(luceneLogDto));
|
||||
|
||||
}
|
||||
// this.businessLogger.setResource(itemDto.getDevice_code(), itemDto.getDevice_name()).log("信号{}变更从{}->{}", new Object[]{itemId, his, value});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,24 +1,17 @@
|
||||
package org.nl.acs.opc;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.lucene.util.NamedThreadFactory;
|
||||
import org.nl.acs.auto.run.AbstractAutoRunnable;
|
||||
import org.nl.acs.opc.service.dto.OpcServerManageDto;
|
||||
import org.nl.acs.udw.UnifiedDataAccessor;
|
||||
import org.nl.acs.udw.UnifiedDataAccessorFactory;
|
||||
import org.nl.acs.udw.UnifiedDataAppService;
|
||||
import org.nl.config.SpringContextHolder;
|
||||
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;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* OPC设备同步启动
|
||||
@@ -26,288 +19,66 @@ import java.util.regex.Pattern;
|
||||
@Component
|
||||
@Slf4j
|
||||
public class DeviceOpcSynchronizeAutoRun extends AbstractAutoRunnable {
|
||||
static boolean isRun = true;
|
||||
|
||||
public static boolean isRun = false;
|
||||
ExecutorService executorService = Executors.newCachedThreadPool();
|
||||
@Autowired
|
||||
private DeviceAppService deviceAppService;
|
||||
@Autowired
|
||||
private OpcServerManageService opcServerManageService;
|
||||
// @Autowired
|
||||
// LuceneExecuteLogService lucene;
|
||||
|
||||
static ExecutorService executorService;
|
||||
public static Map<String, OpcServerManageDto> opcServersConfig;
|
||||
public static Map<String, OpcItemDto> itemCodeOpcItemDtoMapping = new ConcurrentHashMap();
|
||||
|
||||
static boolean canRefreshOpcEntity = true;
|
||||
private long lastRefreshOpcEntityTime;
|
||||
static UnifiedDataAccessor udw;
|
||||
private static Map<String, Boolean> canReadOpcValues;
|
||||
private static volatile Map<String, OpcEntity> opcCodeOpcEntityMapping;
|
||||
|
||||
public DeviceOpcSynchronizeAutoRun() {
|
||||
this.lastRefreshOpcEntityTime = 0L;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCode() {
|
||||
return DeviceOpcSynchronizeAutoRun.class.getSimpleName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "opc设备同步器";
|
||||
}
|
||||
|
||||
static Group getGroup(String opcCode) throws Exception {
|
||||
OpcServerService opcServerService = SpringContextHolder.getBean(OpcServerService.class);
|
||||
return opcServerService.getServer(opcCode);
|
||||
@Override
|
||||
public void autoRun() throws Exception {
|
||||
{
|
||||
isRun = true;
|
||||
|
||||
Map<String, OpcServerManageDto> servers = this.opcServerManageService.queryAllServerMap();
|
||||
Map<String, List<List<OpcItemDto>>> pros;
|
||||
do{
|
||||
Thread.sleep(1000L);
|
||||
pros = this.deviceAppService.findAllFormatProtocolFromDriver();
|
||||
}while (ObjectUtil.isEmpty(pros));
|
||||
Set<String> keys = pros.keySet();
|
||||
Iterator var4 = keys.iterator();
|
||||
//代码执行一次
|
||||
while (var4.hasNext()) {
|
||||
String key = (String) var4.next();
|
||||
List<List<OpcItemDto>> list = (List) pros.get(key);
|
||||
OpcServerManageDto opcServer = (OpcServerManageDto) servers.get(key);
|
||||
Iterator var8 = list.iterator();
|
||||
while (var8.hasNext()) {
|
||||
List<OpcItemDto> groupProtols = (List) var8.next();
|
||||
DeviceOpcProtocolRunable runable = new DeviceOpcProtocolRunable();
|
||||
runable.setProtocols(groupProtols);
|
||||
runable.setOpcServer(opcServer);
|
||||
this.executorService.submit(runable);
|
||||
}
|
||||
}
|
||||
|
||||
static void submitTimeLimitTask(Runnable runnable, String opcCode) {
|
||||
CompletableFuture<Void> future = CompletableFuture.runAsync(runnable, executorService);
|
||||
|
||||
// try {
|
||||
// future.get(10L, TimeUnit.SECONDS);
|
||||
// } catch (InterruptedException var9) {
|
||||
// Thread.currentThread().interrupt();
|
||||
// } catch (ExecutionException var10) {
|
||||
// var10.printStackTrace();
|
||||
// } catch (TimeoutException var11) {
|
||||
// itemCodeOpcItemDtoMapping.keySet().forEach((key) -> {
|
||||
// udw.setValue(key, (Object) null);
|
||||
// });
|
||||
// canReadOpcValues = new ConcurrentHashMap<>();
|
||||
// System.out.println("opc设备同步器 任务执行超时,取消任务...");
|
||||
// future.cancel(true);
|
||||
// } finally {
|
||||
// canRefreshOpcEntity = true;
|
||||
// if (opcCode != null) {
|
||||
// canReadOpcValues.put(opcCode, true);
|
||||
// }
|
||||
//
|
||||
// }
|
||||
}
|
||||
|
||||
private ExecutorService createThreadPool() {
|
||||
ThreadPoolExecutor executor = new ThreadPoolExecutor(32, 32, 10L, TimeUnit.SECONDS, new LinkedBlockingQueue<>(), new NamedThreadFactory("opc-sync"));
|
||||
executor.allowCoreThreadTimeOut(true);
|
||||
return executor;
|
||||
}
|
||||
|
||||
public void autoRun() {
|
||||
OpcStartTag.is_run = true;
|
||||
opcServersConfig = this.opcServerManageService.queryAllServerMap();
|
||||
executorService = this.createThreadPool();
|
||||
opcCodeOpcEntityMapping = new ConcurrentHashMap();
|
||||
itemCodeOpcItemDtoMapping.keySet().forEach((key) -> {
|
||||
udw.setValue(key, (Object) null);
|
||||
});
|
||||
canRefreshOpcEntity = true;
|
||||
canReadOpcValues.clear();
|
||||
// 同步无光电设备信号
|
||||
//Map<String, List<List<OpcItemDto>>> pros1 = this.deviceAppService.findAllFormatProtocolFromDriver();
|
||||
//List<DeviceDriver> opcDrivers = this.deviceAppService.findDeviceDriver(DeviceDriver.class);
|
||||
|
||||
while (true) {
|
||||
this.refreshOpcEntity();
|
||||
Iterator var1 = opcServersConfig.keySet().iterator();
|
||||
|
||||
while (var1.hasNext()) {
|
||||
String opcCode = (String) var1.next();
|
||||
submitTimeLimitTask(() -> {
|
||||
boolean in = false;
|
||||
try {
|
||||
if (canReadOpcValues.computeIfAbsent(opcCode, (key) -> true)) {
|
||||
in = true;
|
||||
canReadOpcValues.put(opcCode, false);
|
||||
this.readOpcValues(opcCode);
|
||||
}
|
||||
} catch (Exception var3) {
|
||||
var3.printStackTrace();
|
||||
} finally {
|
||||
canRefreshOpcEntity = true;
|
||||
if (opcCode != null && in) {
|
||||
canReadOpcValues.put(opcCode, true);
|
||||
}
|
||||
}
|
||||
}, opcCode);
|
||||
}
|
||||
|
||||
ThreadUtl.sleep((long) OpcConfig.synchronized_millisecond);
|
||||
}
|
||||
}
|
||||
|
||||
private void readOpcValues(String opcCode) throws Exception {
|
||||
synchronized (opcCode.intern()) {
|
||||
OpcEntity opcEntity = (OpcEntity) opcCodeOpcEntityMapping.get(opcCode);
|
||||
if (opcEntity != null) {
|
||||
if (opcEntity.getItems().size() != 0) {
|
||||
long begin = System.currentTimeMillis();
|
||||
if (log.isTraceEnabled()) {
|
||||
log.trace("opc {} 开始计时{}", opcCode, begin);
|
||||
}
|
||||
|
||||
new HashMap();
|
||||
|
||||
Map<Item, ItemState> itemStatus;
|
||||
try {
|
||||
itemStatus = opcEntity.readAll();
|
||||
} catch (Exception var15) {
|
||||
itemStatus = opcEntity.readDividually();
|
||||
}
|
||||
|
||||
long end = System.currentTimeMillis();
|
||||
long duration = end - begin;
|
||||
if (log.isTraceEnabled()) {
|
||||
log.trace("opc {} 读取耗时:{}", opcCode, duration);
|
||||
}
|
||||
|
||||
if (duration > 1000L) {
|
||||
log.warn("opc {} 读取超时 : {}", opcCode, duration);
|
||||
}
|
||||
|
||||
// boolean allNull = itemStatus.entrySet().stream().map((map) -> {
|
||||
// return OpcUtl.getValue((Item)map.getKey(), (ItemState)map.getValue());
|
||||
// }).allMatch(Objects::isNull);
|
||||
// if (allNull) {
|
||||
// opcEntity.getItems().clear();
|
||||
// }
|
||||
|
||||
UnifiedDataAccessor udw = opcEntity.getUdw();
|
||||
|
||||
|
||||
Set<Item> items = itemStatus.keySet();
|
||||
Iterator var18 = items.iterator();
|
||||
|
||||
while (var18.hasNext()) {
|
||||
Item item = (Item) var18.next();
|
||||
ItemState itemState = (ItemState) itemStatus.get(item);
|
||||
Object nowValue = OpcUtl.getValue(item, itemState);
|
||||
String itemId = item.getId();
|
||||
Object historyValue = udw.getValue(itemId);
|
||||
if (!ObjectUtl.isEquals(itemState.getQuality(), QualityTypeValue.OPC_QUALITY_GOOD) && historyValue != null) {
|
||||
log.warn("opc 值不健康 item: {}, 状态: {}", itemId, itemState.getQuality());
|
||||
}
|
||||
if (!UnifiedDataAppService.isEquals(nowValue, historyValue)) {
|
||||
OpcItemDto itemDto = (OpcItemDto) itemCodeOpcItemDtoMapping.get(itemId);
|
||||
if (true) {
|
||||
this.logItemChanged(itemId, udw, nowValue, itemDto);
|
||||
}
|
||||
udw.setValue(itemId, nowValue);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void refreshOpcEntity() {
|
||||
if (canRefreshOpcEntity) {
|
||||
canRefreshOpcEntity = false;
|
||||
long now = System.currentTimeMillis();
|
||||
if (now - this.lastRefreshOpcEntityTime >= 20000L) {
|
||||
this.lastRefreshOpcEntityTime = now;
|
||||
submitTimeLimitTask(() -> {
|
||||
try {
|
||||
Map<String, List<List<OpcItemDto>>> protocol = this.deviceAppService.findAllFormatProtocolFromDriver();
|
||||
Iterator var2 = protocol.entrySet().iterator();
|
||||
|
||||
while (var2.hasNext()) {
|
||||
Entry<String, List<List<OpcItemDto>>> stringListEntry = (Entry) var2.next();
|
||||
String opcCode = (String) stringListEntry.getKey();
|
||||
List<List<OpcItemDto>> opcItemDtos = (List) stringListEntry.getValue();
|
||||
((OpcEntity) opcCodeOpcEntityMapping.computeIfAbsent(opcCode, OpcEntity::new)).reload(opcItemDtos);
|
||||
}
|
||||
} catch (Exception var6) {
|
||||
var6.printStackTrace();
|
||||
} finally {
|
||||
canRefreshOpcEntity = true;
|
||||
}
|
||||
|
||||
}, (String) null);
|
||||
Thread.sleep(3000L);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void logMessage(String errorMessage) {
|
||||
try {
|
||||
// issueLogger.setResource(OpcConfig.resource_code, OpcConfig.resource_name).setError(StringUtl.getString(100), "设备同步通信异常").log(errorMessage, new Object[0]);
|
||||
// businessLogger.setResource(OpcConfig.resource_code, OpcConfig.resource_name).setError(StringUtl.getString(100), "设备同步通信异常").log(errorMessage, new Object[0]);
|
||||
} catch (Exception var5) {
|
||||
var5.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void after() {
|
||||
OpcStartTag.is_run = false;
|
||||
opcCodeOpcEntityMapping.values().forEach((opcEntity) -> {
|
||||
opcEntity.cleanUdwCache();
|
||||
OpcServerService opcServerService = SpringContextHolder.getBean(OpcServerService.class);
|
||||
opcServerService.cleanGroups(opcEntity.getOpcCode());
|
||||
});
|
||||
opcCodeOpcEntityMapping = new ConcurrentHashMap();
|
||||
itemCodeOpcItemDtoMapping = new ConcurrentHashMap();
|
||||
executorService.shutdownNow();
|
||||
}
|
||||
|
||||
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()) {
|
||||
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 + ";");
|
||||
}
|
||||
if (!itemDto.getItem_code().endsWith("heartbeat") && !itemDto.getItem_code().endsWith("time") && !itemDto.getItem_code().endsWith("consumption")) {
|
||||
// 存在上次点位值为null情况 则不记录日志
|
||||
if(!(his instanceof Float) && !(value instanceof Float)){
|
||||
log.info(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 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());
|
||||
// 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 (!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));
|
||||
// }
|
||||
// }
|
||||
|
||||
if (!itemDto.getItem_code().endsWith("heartbeat") && !itemDto.getItem_code().endsWith("time") && !itemDto.getItem_code().endsWith("consumption")) {
|
||||
log.info(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));
|
||||
// if(!(his instanceof Float) && !(value instanceof Float)){
|
||||
// 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());
|
||||
// String logLevel = paramService.findByCode(AcsConfig.LOGLEVEL).getValue();
|
||||
// if(StrUtil.isNotEmpty(logLevel) && isNumeric(logLevel) && (luceneLogDto.getLog_level() >= Integer.parseInt(logLevel))){
|
||||
// log.info("{}", JSON.toJSONString(luceneLogDto));
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
static {
|
||||
udw = UnifiedDataAccessorFactory.getAccessor(OpcConfig.udw_opc_value_key);
|
||||
canReadOpcValues = new ConcurrentHashMap();
|
||||
opcCodeOpcEntityMapping = new ConcurrentHashMap();
|
||||
}
|
||||
|
||||
public static boolean isNumeric(String str) {
|
||||
return Pattern.compile("^[0-9]+$").matcher(str).matches();
|
||||
isRun = false;
|
||||
this.executorService.shutdownNow();
|
||||
this.executorService = Executors.newCachedThreadPool();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,172 +5,170 @@ import org.nl.acs.udw.UnifiedDataAccessorFactory;
|
||||
import org.openscada.opc.lib.da.Group;
|
||||
import org.openscada.opc.lib.da.Item;
|
||||
import org.openscada.opc.lib.da.ItemState;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class OpcEntity {
|
||||
@Autowired
|
||||
OpcServerService opcServerService;
|
||||
private final UnifiedDataAccessor udw;
|
||||
private Map<String, List<Item>> items;
|
||||
private Map<String, List<String>> someFailDevices;
|
||||
private String opcCode;
|
||||
|
||||
public OpcEntity(String opcCode) {
|
||||
this.udw = UnifiedDataAccessorFactory.getAccessor(OpcConfig.udw_opc_value_key);
|
||||
this.items = new ConcurrentHashMap();
|
||||
this.someFailDevices = new ConcurrentHashMap();
|
||||
this.opcCode = opcCode;
|
||||
}
|
||||
|
||||
public void reload(List<List<OpcItemDto>> opcItemDtos) {
|
||||
Map<String, List<String>> itemCodes = new ConcurrentHashMap();
|
||||
(opcItemDtos.stream().flatMap(Collection::stream).collect(Collectors.groupingBy(OpcItemDto::getDevice_code))).forEach((deviceCodes, opcItemDtoList) -> {
|
||||
itemCodes.put(deviceCodes, opcItemDtoList.stream().map(OpcItemDto::getItem_code).collect(Collectors.toList()));
|
||||
});
|
||||
DeviceOpcSynchronizeAutoRun.itemCodeOpcItemDtoMapping.putAll((Map)opcItemDtos.stream().flatMap(Collection::stream).collect(Collectors.toMap(OpcItemDto::getItem_code, (obj) -> {
|
||||
return obj;
|
||||
},(k, v) -> k)));
|
||||
if (this.items.size() == 0) {
|
||||
itemCodes.values().stream().flatMap(Collection::stream).forEach((key) -> {
|
||||
this.udw.setValue(key, (Object)null);
|
||||
});
|
||||
this.addItemsIntoGroup(itemCodes);
|
||||
} else {
|
||||
if (this.someFailDevices.size() > 0) {
|
||||
this.reAddDevices();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void reAddDevices() {
|
||||
Map<String, List<Item>> addItems = new ConcurrentHashMap();
|
||||
StringBuilder err_message = new StringBuilder();
|
||||
this.someFailDevices.forEach((deviceCode, itemCodesList) -> {
|
||||
itemCodesList.forEach((itemCode) -> {
|
||||
try {
|
||||
Group group = DeviceOpcSynchronizeAutoRun.getGroup(this.opcCode);
|
||||
((List)addItems.computeIfAbsent(deviceCode, (key) -> {
|
||||
return new ArrayList();
|
||||
})).add(group.addItem(itemCode));
|
||||
} catch (Exception var6) {
|
||||
err_message.append(itemCode).append(" 添加失败; ");
|
||||
}
|
||||
|
||||
});
|
||||
List<Item> deviceItems = (List)addItems.get(deviceCode);
|
||||
if (deviceItems != null && deviceItems.size() == itemCodesList.size()) {
|
||||
this.someFailDevices.remove(deviceCode);
|
||||
} else if (itemCodesList.size() == 0) {
|
||||
addItems.remove(deviceCode);
|
||||
} else {
|
||||
assert deviceItems != null;
|
||||
|
||||
((List)this.someFailDevices.get(deviceCode)).removeAll(deviceItems);
|
||||
}
|
||||
|
||||
synchronized(this.opcCode.intern()) {
|
||||
this.items.putAll(addItems);
|
||||
}
|
||||
|
||||
if (err_message.length() > 0) {
|
||||
String errMsg = err_message.toString();
|
||||
//this.log.warn("{}:{}", com.wxzd.wcs.opc.OpcConfig.resource_code, errMsg);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
private void addItemsIntoGroup(Map<String, List<String>> itemCodes) {
|
||||
try {
|
||||
Group group = DeviceOpcSynchronizeAutoRun.getGroup(this.opcCode);
|
||||
StringBuilder err_message = new StringBuilder();
|
||||
Map<String, List<Item>> items = new ConcurrentHashMap();
|
||||
itemCodes.forEach((deviceCode, itemCodesList) -> {
|
||||
itemCodesList.forEach((itemCode) -> {
|
||||
try {
|
||||
((List)items.computeIfAbsent(deviceCode, (key) -> {
|
||||
return new ArrayList();
|
||||
})).add(group.addItem(itemCode));
|
||||
} catch (Exception var7) {
|
||||
((List)this.someFailDevices.computeIfAbsent(deviceCode, (key) -> {
|
||||
return new ArrayList();
|
||||
})).add(itemCode);
|
||||
this.udw.setValue(itemCode, (Object)null);
|
||||
err_message.append(itemCode).append(" 添加失败; ");
|
||||
}
|
||||
|
||||
});
|
||||
List<Item> deviceItems = (List)items.get(deviceCode);
|
||||
if (deviceItems != null && deviceItems.size() != itemCodesList.size()) {
|
||||
items.remove(deviceCode);
|
||||
this.someFailDevices.put(deviceCode, itemCodesList);
|
||||
}
|
||||
|
||||
});
|
||||
synchronized(this.opcCode.intern()) {
|
||||
this.items = items;
|
||||
}
|
||||
|
||||
if (err_message.length() > 0) {
|
||||
String errMsg = err_message.toString();
|
||||
// this.log.warn("{}:{}", OpcConfig.resource_code, errMsg);
|
||||
}
|
||||
} catch (Exception var8) {
|
||||
var8.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void cleanUdwCache() {
|
||||
this.items.values().stream().flatMap(Collection::stream).map(Item::getId).forEach((key) -> {
|
||||
this.udw.setValue(key, (Object)null);
|
||||
});
|
||||
}
|
||||
|
||||
public Map<Item, ItemState> readAll() throws Exception {
|
||||
return opcServerService.getServer(this.opcCode).read(true, (Item[])this.items.values().stream().flatMap(Collection::stream).toArray((x$0) -> {
|
||||
return new Item[x$0];
|
||||
}));
|
||||
}
|
||||
|
||||
public Map<Item, ItemState> readDividually() {
|
||||
Map<Item, ItemState> result = new HashMap();
|
||||
CompletableFuture[] futures = (CompletableFuture[])this.items.entrySet().stream().map((entry) -> {
|
||||
return CompletableFuture.runAsync(() -> {
|
||||
try {
|
||||
Group group = DeviceOpcSynchronizeAutoRun.getGroup(this.opcCode);
|
||||
result.putAll(group.read(true, (Item[])((List)entry.getValue()).toArray(new Item[0])));
|
||||
} catch (Exception var5) {
|
||||
String deviceCode = (String)entry.getKey();
|
||||
// to do
|
||||
// this.someFailDevices.put(deviceCode, ((List)entry.getValue()).stream().map(Item::getId).collect(Collectors.toList()));
|
||||
this.items.remove(deviceCode);
|
||||
}
|
||||
|
||||
}, DeviceOpcSynchronizeAutoRun.executorService);
|
||||
}).toArray((x$0) -> {
|
||||
return new CompletableFuture[x$0];
|
||||
});
|
||||
CompletableFuture.allOf(futures).join();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public UnifiedDataAccessor getUdw() {
|
||||
return this.udw;
|
||||
}
|
||||
|
||||
public Map<String, List<Item>> getItems() {
|
||||
return this.items;
|
||||
}
|
||||
|
||||
public String getOpcCode() {
|
||||
return this.opcCode;
|
||||
}
|
||||
// OpcServerService opcServerService = SpringContextHolder.getBean(OpcServerService.class);
|
||||
// private final UnifiedDataAccessor udw;
|
||||
// private Map<String, List<Item>> items;
|
||||
// private Map<String, List<String>> someFailDevices;
|
||||
// private String opcCode;
|
||||
//
|
||||
// public OpcEntity(String opcCode) {
|
||||
// this.udw = UnifiedDataAccessorFactory.getAccessor(OpcConfig.udw_opc_value_key);
|
||||
// this.items = new ConcurrentHashMap();
|
||||
// this.someFailDevices = new ConcurrentHashMap();
|
||||
// this.opcCode = opcCode;
|
||||
// }
|
||||
//
|
||||
// public void reload(List<List<OpcItemDto>> opcItemDtos) {
|
||||
// Map<String, List<String>> itemCodes = new ConcurrentHashMap();
|
||||
// (opcItemDtos.stream().flatMap(Collection::stream).collect(Collectors.groupingBy(OpcItemDto::getDevice_code))).forEach((deviceCodes, opcItemDtoList) -> {
|
||||
// itemCodes.put(deviceCodes, opcItemDtoList.stream().map(OpcItemDto::getItem_code).collect(Collectors.toList()));
|
||||
// });
|
||||
// DeviceOpcSynchronizeAutoRun.itemCodeOpcItemDtoMapping.putAll((Map)opcItemDtos.stream().flatMap(Collection::stream).collect(Collectors.toMap(OpcItemDto::getItem_code, (obj) -> {
|
||||
// return obj;
|
||||
// },(k, v) -> k)));
|
||||
// if (this.items.size() == 0) {
|
||||
// itemCodes.values().stream().flatMap(Collection::stream).forEach((key) -> {
|
||||
// this.udw.setValue(key, (Object)null);
|
||||
// });
|
||||
// this.addItemsIntoGroup(itemCodes);
|
||||
// } else {
|
||||
// if (this.someFailDevices.size() > 0) {
|
||||
// this.reAddDevices();
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private void reAddDevices() {
|
||||
// Map<String, List<Item>> addItems = new ConcurrentHashMap();
|
||||
// StringBuilder err_message = new StringBuilder();
|
||||
// this.someFailDevices.forEach((deviceCode, itemCodesList) -> {
|
||||
// itemCodesList.forEach((itemCode) -> {
|
||||
// try {
|
||||
// Group group = DeviceOpcSynchronizeAutoRun.getGroup(this.opcCode);
|
||||
// ((List)addItems.computeIfAbsent(deviceCode, (key) -> {
|
||||
// return new ArrayList();
|
||||
// })).add(group.addItem(itemCode));
|
||||
// } catch (Exception var6) {
|
||||
// err_message.append(itemCode).append(" 添加失败; ");
|
||||
// }
|
||||
//
|
||||
// });
|
||||
// List<Item> deviceItems = (List)addItems.get(deviceCode);
|
||||
// if (deviceItems != null && deviceItems.size() == itemCodesList.size()) {
|
||||
// this.someFailDevices.remove(deviceCode);
|
||||
// } else if (itemCodesList.size() == 0) {
|
||||
// addItems.remove(deviceCode);
|
||||
// } else {
|
||||
// assert deviceItems != null;
|
||||
//
|
||||
// ((List)this.someFailDevices.get(deviceCode)).removeAll(deviceItems);
|
||||
// }
|
||||
//
|
||||
// synchronized(this.opcCode.intern()) {
|
||||
// this.items.putAll(addItems);
|
||||
// }
|
||||
//
|
||||
// if (err_message.length() > 0) {
|
||||
// String errMsg = err_message.toString();
|
||||
// //this.log.warn("{}:{}", com.wxzd.wcs.opc.OpcConfig.resource_code, errMsg);
|
||||
// }
|
||||
//
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// private void addItemsIntoGroup(Map<String, List<String>> itemCodes) {
|
||||
// try {
|
||||
// Group group = DeviceOpcSynchronizeAutoRun.getGroup(this.opcCode);
|
||||
// StringBuilder err_message = new StringBuilder();
|
||||
// Map<String, List<Item>> items = new ConcurrentHashMap();
|
||||
// itemCodes.forEach((deviceCode, itemCodesList) -> {
|
||||
// itemCodesList.forEach((itemCode) -> {
|
||||
// try {
|
||||
// ((List)items.computeIfAbsent(deviceCode, (key) -> {
|
||||
// return new ArrayList();
|
||||
// })).add(group.addItem(itemCode));
|
||||
// } catch (Exception var7) {
|
||||
// ((List)this.someFailDevices.computeIfAbsent(deviceCode, (key) -> {
|
||||
// return new ArrayList();
|
||||
// })).add(itemCode);
|
||||
// this.udw.setValue(itemCode, (Object)null);
|
||||
// err_message.append(itemCode).append(" 添加失败; ");
|
||||
// }
|
||||
//
|
||||
// });
|
||||
// List<Item> deviceItems = (List)items.get(deviceCode);
|
||||
// if (deviceItems != null && deviceItems.size() != itemCodesList.size()) {
|
||||
// items.remove(deviceCode);
|
||||
// this.someFailDevices.put(deviceCode, itemCodesList);
|
||||
// }
|
||||
//
|
||||
// });
|
||||
// synchronized(this.opcCode.intern()) {
|
||||
// this.items = items;
|
||||
// }
|
||||
//
|
||||
// if (err_message.length() > 0) {
|
||||
// String errMsg = err_message.toString();
|
||||
//// this.log.warn("{}:{}", OpcConfig.resource_code, errMsg);
|
||||
// }
|
||||
// } catch (Exception var8) {
|
||||
// var8.printStackTrace();
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// public void cleanUdwCache() {
|
||||
// this.items.values().stream().flatMap(Collection::stream).map(Item::getId).forEach((key) -> {
|
||||
// this.udw.setValue(key, (Object)null);
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// public Map<Item, ItemState> readAll() throws Exception {
|
||||
// return opcServerService.getServer(this.opcCode).read(true, (Item[])this.items.values().stream().flatMap(Collection::stream).toArray((x$0) -> {
|
||||
// return new Item[x$0];
|
||||
// }));
|
||||
// }
|
||||
//
|
||||
// public Map<Item, ItemState> readDividually() {
|
||||
// Map<Item, ItemState> result = new HashMap();
|
||||
// CompletableFuture[] futures = (CompletableFuture[])this.items.entrySet().stream().map((entry) -> {
|
||||
// return CompletableFuture.runAsync(() -> {
|
||||
// try {
|
||||
// Group group = DeviceOpcSynchronizeAutoRun.getGroup(this.opcCode);
|
||||
// result.putAll(group.read(true, (Item[])((List)entry.getValue()).toArray(new Item[0])));
|
||||
// } catch (Exception var5) {
|
||||
// String deviceCode = (String)entry.getKey();
|
||||
// // to do
|
||||
//// this.someFailDevices.put(deviceCode, ((List)entry.getValue()).stream().map(Item::getId).collect(Collectors.toList()));
|
||||
// this.items.remove(deviceCode);
|
||||
// }
|
||||
//
|
||||
// }, DeviceOpcSynchronizeAutoRun.executorService);
|
||||
// }).toArray((x$0) -> {
|
||||
// return new CompletableFuture[x$0];
|
||||
// });
|
||||
// CompletableFuture.allOf(futures).join();
|
||||
// return result;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// public UnifiedDataAccessor getUdw() {
|
||||
// return this.udw;
|
||||
// }
|
||||
//
|
||||
// public Map<String, List<Item>> getItems() {
|
||||
// return this.items;
|
||||
// }
|
||||
//
|
||||
// public String getOpcCode() {
|
||||
// return this.opcCode;
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
package org.nl.acs.opc;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class OpcItemDto {
|
||||
private String device_code;
|
||||
private String device_name;
|
||||
@@ -11,6 +14,7 @@ public class OpcItemDto {
|
||||
private String opc_plc_code;
|
||||
private String item_code;
|
||||
private Object item_value;
|
||||
private Object his_item_value;
|
||||
private Boolean need_log = Boolean.valueOf(false);
|
||||
private List<String> relate_items = new ArrayList();
|
||||
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package org.nl.config.lucene;
|
||||
/**
|
||||
* @author ldjun
|
||||
* @version 1.0
|
||||
* @date 2023年08月24日 13:00
|
||||
* @desc desc
|
||||
*/
|
||||
|
||||
import ch.qos.logback.classic.spi.ILoggingEvent;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import com.yomahub.tlog.core.context.AspectLogContext;
|
||||
import com.yomahub.tlog.core.enhance.logback.async.AspectLogbackAsyncAppender;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.MDC;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class AsyncLuceneAppender extends AspectLogbackAsyncAppender {
|
||||
|
||||
|
||||
@Override
|
||||
protected void append(ILoggingEvent event) {
|
||||
String traceId = AspectLogContext.getLogValue();
|
||||
if (StringUtils.isEmpty(traceId)){
|
||||
traceId = IdUtil.nanoId()+"@";
|
||||
AspectLogContext.putLogValue(traceId);
|
||||
}else {
|
||||
if (!traceId.contains("@")){
|
||||
AspectLogContext.putLogValue(traceId+"@");
|
||||
}
|
||||
}
|
||||
if (StringUtils.isNotEmpty(traceId)){
|
||||
MDC.put("traceId",traceId);
|
||||
Map<String, String> mdcPropertyMap = event.getMDCPropertyMap();
|
||||
if (mdcPropertyMap.getClass().getName().contains("SynchronizedMap")){
|
||||
mdcPropertyMap.put("traceId",traceId);
|
||||
}
|
||||
MDC.clear();
|
||||
}
|
||||
super.append(event);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,184 +1,178 @@
|
||||
package org.nl.config.lucene;//package org.nl.config.lucene;
|
||||
//
|
||||
//import com.alibaba.fastjson.JSONObject;
|
||||
//import org.apache.commons.io.FileUtils;
|
||||
//import org.apache.lucene.analysis.Analyzer;
|
||||
//import org.apache.lucene.document.Document;
|
||||
//import org.apache.lucene.document.Field;
|
||||
//import org.apache.lucene.document.TextField;
|
||||
//import org.apache.lucene.index.IndexWriter;
|
||||
//import org.apache.lucene.index.IndexWriterConfig;
|
||||
//import org.apache.lucene.store.Directory;
|
||||
//import org.apache.lucene.store.FSDirectory;
|
||||
//import org.springframework.beans.factory.annotation.Value;
|
||||
//import org.wltea.analyzer.lucene.IKAnalyzer;
|
||||
//
|
||||
//import java.io.BufferedReader;
|
||||
//import java.io.File;
|
||||
//import java.io.FileReader;
|
||||
//import java.io.IOException;
|
||||
//import java.nio.file.Paths;
|
||||
//import java.util.Set;
|
||||
//
|
||||
///**
|
||||
// * lucene索引器
|
||||
// */
|
||||
//public class Indexer {
|
||||
// /**
|
||||
// * 写索引实例
|
||||
// */
|
||||
// private IndexWriter writer;
|
||||
//
|
||||
// public IndexWriter getWriter() {
|
||||
// return writer;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 构造方法,实例化IndexWriter
|
||||
// *
|
||||
// * @param indexDir
|
||||
// * @throws Exception
|
||||
// */
|
||||
// public Indexer(String indexDir) throws Exception {
|
||||
// Directory dir = FSDirectory.open(Paths.get(indexDir));
|
||||
// //标准分词器,会自动去掉空格啊,is a the等单词
|
||||
//// Analyzer analyzer = new StandardAnalyzer();
|
||||
// Analyzer analyzer = new IKAnalyzer();
|
||||
// //将标准分词器配到写索引的配置中
|
||||
// IndexWriterConfig config = new IndexWriterConfig(analyzer);
|
||||
// //实例化写索引对象
|
||||
// writer = new IndexWriter(dir, config);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 索引指定目录下的所有文件
|
||||
// *
|
||||
// * @param dataDir
|
||||
// * @return
|
||||
// * @throws Exception
|
||||
// */
|
||||
// public int indexAll(String dataDir) throws Exception {
|
||||
// // 获取该路径下的所有文件
|
||||
// File[] files = new File(dataDir).listFiles();
|
||||
// if (null != files) {
|
||||
// for (File file : files) {
|
||||
// //调用下面的indexFile方法,对每个文件进行索引
|
||||
// indexFile(file);
|
||||
// }
|
||||
// }
|
||||
// //返回索引的文件数
|
||||
//// return writer.numDocs();
|
||||
// return writer.numRamDocs();
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 索引指定的文件
|
||||
// *
|
||||
// * @param file
|
||||
// * @throws Exception
|
||||
// */
|
||||
// private void indexFile(File file) throws Exception {
|
||||
// System.out.println("索引文件的路径:" + file.getCanonicalPath());
|
||||
// //调用下面的getDocument方法,获取该文件的document
|
||||
// Document doc = getDocument(file);
|
||||
// //添加索引文档
|
||||
// //Document doc = json2Doc(jsonDoc);
|
||||
//// Document doc = new Document();
|
||||
//// doc.add(new TextField("content", jsonDoc, Field.Store.YES));
|
||||
// Field fieldContent = new TextField("fieldContent", FileUtils.readFileToString(null, "UTF-8"), Field.Store.YES);
|
||||
//
|
||||
// //将doc添加到索引中
|
||||
// writer.addDocument(doc);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 获取文档,文档里再设置每个字段,就类似于数据库中的一行记录
|
||||
// *
|
||||
// * @param file
|
||||
// * @return
|
||||
// * @throws Exception
|
||||
// */
|
||||
// private Document getDocument(File file) throws Exception {
|
||||
package org.nl.config.lucene;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.lucene.analysis.Analyzer;
|
||||
import org.apache.lucene.document.Document;
|
||||
import org.apache.lucene.document.Field;
|
||||
import org.apache.lucene.document.TextField;
|
||||
import org.apache.lucene.index.IndexWriter;
|
||||
import org.apache.lucene.index.IndexWriterConfig;
|
||||
import org.apache.lucene.store.Directory;
|
||||
import org.apache.lucene.store.FSDirectory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.wltea.analyzer.lucene.IKAnalyzer;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* lucene索引器
|
||||
*/
|
||||
public class Indexer {
|
||||
/**
|
||||
* 写索引实例
|
||||
*/
|
||||
private IndexWriter writer;
|
||||
|
||||
public IndexWriter getWriter() {
|
||||
return writer;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造方法,实例化IndexWriter
|
||||
* @param indexDir
|
||||
* @throws Exception
|
||||
*/
|
||||
public Indexer(String indexDir) throws Exception {
|
||||
Directory dir = FSDirectory.open(Paths.get(indexDir));
|
||||
//标准分词器,会自动去掉空格啊,is a the等单词
|
||||
// Analyzer analyzer = new StandardAnalyzer();
|
||||
Analyzer analyzer = new IKAnalyzer();
|
||||
//将标准分词器配到写索引的配置中
|
||||
IndexWriterConfig config = new IndexWriterConfig(analyzer);
|
||||
//实例化写索引对象
|
||||
writer = new IndexWriter(dir, config);
|
||||
}
|
||||
|
||||
/**
|
||||
* 索引指定目录下的所有文件
|
||||
* @param dataDir
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public int indexAll(String dataDir) throws Exception {
|
||||
// 获取该路径下的所有文件
|
||||
File[] files = new File(dataDir).listFiles();
|
||||
if (null != files) {
|
||||
for (File file : files) {
|
||||
//调用下面的indexFile方法,对每个文件进行索引
|
||||
indexFile(file);
|
||||
}
|
||||
}
|
||||
//返回索引的文件数
|
||||
// return writer.numDocs();
|
||||
return writer.numRamDocs();
|
||||
}
|
||||
|
||||
/**
|
||||
* 索引指定的文件
|
||||
* @param file
|
||||
* @throws Exception
|
||||
*/
|
||||
private void indexFile(File file) throws Exception {
|
||||
System.out.println("索引文件的路径:" + file.getCanonicalPath());
|
||||
//调用下面的getDocument方法,获取该文件的document
|
||||
Document doc = getDocument(file);
|
||||
//添加索引文档
|
||||
//Document doc = json2Doc(jsonDoc);
|
||||
// Document doc = new Document();
|
||||
// //开始添加字段
|
||||
// //添加内容
|
||||
// doc.add(new TextField("contents", new FileReader(file)));
|
||||
// //添加文件名,并把这个字段存到索引文件里
|
||||
// doc.add(new TextField("fileName", file.getName(), Field.Store.YES));
|
||||
// //添加文件路径
|
||||
// doc.add(new TextField("fullPath", file.getCanonicalPath(), Field.Store.YES));
|
||||
// return doc;
|
||||
// }
|
||||
//
|
||||
// public Document json2Doc(String strDoc) {
|
||||
// Document doc = new Document();
|
||||
// JSONObject jsonDoc = JSONObject.parseObject(strDoc);
|
||||
// Set<String> keys = jsonDoc.keySet();
|
||||
// for (String key : keys) {
|
||||
// doc.add(new TextField(key, jsonDoc.getString(key), Field.Store.YES));
|
||||
// }
|
||||
// return doc;
|
||||
// }
|
||||
//
|
||||
// public void addLogIndex(String msg) throws IOException {
|
||||
// //步骤一:创建Directory对象,用于指定索引库的位置 RAMDirectory内存
|
||||
// Directory directory = FSDirectory.open(new File("D:\\lucene\\index").toPath());
|
||||
// //步骤二:创建一个IndexWriter对象,用于写索引
|
||||
//// Analyzer analyzer = new StandardAnalyzer();
|
||||
// IndexWriter indexWriter = new IndexWriter(directory, new IndexWriterConfig(new IKAnalyzer(false)));
|
||||
//// indexWriter.deleteAll();//清理所有索引库
|
||||
//// IndexWriter indexWriter=new IndexWriter(directory,new IndexWriterConfig(new StandardAnalyzer()));
|
||||
// //记录索引开始时间
|
||||
// long startTime = System.currentTimeMillis();
|
||||
// //步骤三:读取磁盘中文件,对应每一个文件创建一个文档对象
|
||||
// Document document = new Document();
|
||||
//// document.add(new TextField("fieldContent", device_id, Field.Store.YES));
|
||||
// document.add(new TextField("fieldContent", msg, Field.Store.YES));
|
||||
// indexWriter.addDocument(document);
|
||||
// //记录索引结束时间
|
||||
// long endTime = System.currentTimeMillis();
|
||||
// System.out.println("建立索引" + "共耗时" + (endTime - startTime) + "毫秒");
|
||||
// indexWriter.commit();
|
||||
// //步骤八:关闭资源
|
||||
// indexWriter.close();
|
||||
// System.out.println("建立索引成功-----关闭资源");
|
||||
// }
|
||||
//
|
||||
// //系统的日志文件路径
|
||||
// @Value("${logging.file.path}")
|
||||
// private String logUrl;
|
||||
//
|
||||
// public static void main(String[] args) throws IOException {
|
||||
// //步骤一:创建Directory对象,用于指定索引库的位置 RAMDirectory内存
|
||||
// Directory directory = FSDirectory.open(new File("D:\\lucene\\index").toPath());
|
||||
// //步骤二:创建一个IndexWriter对象,用于写索引
|
||||
//// Analyzer analyzer = new StandardAnalyzer();
|
||||
// IndexWriter indexWriter = new IndexWriter(directory, new IndexWriterConfig(new IKAnalyzer(false)));
|
||||
//
|
||||
// doc.add(new TextField("content", jsonDoc, Field.Store.YES));
|
||||
Field fieldContent=new TextField("fieldContent", FileUtils.readFileToString(null,"UTF-8"), Field.Store.YES);
|
||||
|
||||
//将doc添加到索引中
|
||||
writer.addDocument(doc);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文档,文档里再设置每个字段,就类似于数据库中的一行记录
|
||||
* @param file
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
private Document getDocument(File file) throws Exception {
|
||||
Document doc = new Document();
|
||||
//开始添加字段
|
||||
//添加内容
|
||||
doc.add(new TextField("contents", new FileReader(file)));
|
||||
//添加文件名,并把这个字段存到索引文件里
|
||||
doc.add(new TextField("fileName", file.getName(), Field.Store.YES));
|
||||
//添加文件路径
|
||||
doc.add(new TextField("fullPath", file.getCanonicalPath(), Field.Store.YES));
|
||||
return doc;
|
||||
}
|
||||
public Document json2Doc(String strDoc) {
|
||||
Document doc = new Document();
|
||||
JSONObject jsonDoc = JSONObject.parseObject(strDoc);
|
||||
Set<String> keys = jsonDoc.keySet();
|
||||
for (String key : keys) {
|
||||
doc.add(new TextField(key, jsonDoc.getString(key), Field.Store.YES));
|
||||
}
|
||||
return doc;
|
||||
}
|
||||
|
||||
public void addLogIndex(String msg) throws IOException {
|
||||
//步骤一:创建Directory对象,用于指定索引库的位置 RAMDirectory内存
|
||||
Directory directory = FSDirectory.open(new File("D:\\lucene\\index").toPath());
|
||||
//步骤二:创建一个IndexWriter对象,用于写索引
|
||||
// Analyzer analyzer = new StandardAnalyzer();
|
||||
IndexWriter indexWriter=new IndexWriter(directory,new IndexWriterConfig(new IKAnalyzer(false)));
|
||||
// indexWriter.deleteAll();//清理所有索引库
|
||||
//// indexWriter=new IndexWriter(directory,new IndexWriterConfig(new StandardAnalyzer()));
|
||||
// //记录索引开始时间
|
||||
// long startTime = System.currentTimeMillis();
|
||||
// //步骤三:读取磁盘中文件,对应每一个文件创建一个文档对象
|
||||
// File file = new File("D:\\testlog");
|
||||
// //步骤四:获取文件列表
|
||||
// File[] files = file.listFiles();
|
||||
// for (File item : files) {
|
||||
// BufferedReader bufferedReader = new BufferedReader(new FileReader(item));
|
||||
// String strLine = null;
|
||||
// while (null != (strLine = bufferedReader.readLine())) {
|
||||
// Document document = new Document();
|
||||
//// document.add(new Field());
|
||||
// document.add(new TextField("fieldContent", strLine, Field.Store.YES));
|
||||
// indexWriter.addDocument(document);
|
||||
// }
|
||||
// }
|
||||
// //记录索引结束时间
|
||||
// long endTime = System.currentTimeMillis();
|
||||
// System.out.println("建立索引" + "共耗时" + (endTime - startTime) + "毫秒");
|
||||
// indexWriter.commit();
|
||||
// //步骤八:关闭资源
|
||||
// indexWriter.close();
|
||||
// System.out.println("建立索引成功-----关闭资源");
|
||||
// }
|
||||
//}
|
||||
// IndexWriter indexWriter=new IndexWriter(directory,new IndexWriterConfig(new StandardAnalyzer()));
|
||||
//记录索引开始时间
|
||||
long startTime = System.currentTimeMillis();
|
||||
//步骤三:读取磁盘中文件,对应每一个文件创建一个文档对象
|
||||
Document document = new Document();
|
||||
// document.add(new TextField("fieldContent", device_id, Field.Store.YES));
|
||||
document.add(new TextField("fieldContent", msg, Field.Store.YES));
|
||||
indexWriter.addDocument(document);
|
||||
//记录索引结束时间
|
||||
long endTime = System.currentTimeMillis();
|
||||
System.out.println("建立索引"+ "共耗时" + (endTime-startTime) + "毫秒");
|
||||
indexWriter.commit();
|
||||
//步骤八:关闭资源
|
||||
indexWriter.close();
|
||||
System.out.println("建立索引成功-----关闭资源");
|
||||
}
|
||||
//系统的日志文件路径
|
||||
@Value("${logging.file.path}")
|
||||
private String logUrl;
|
||||
|
||||
public static void main(String[] args)throws IOException {
|
||||
//步骤一:创建Directory对象,用于指定索引库的位置 RAMDirectory内存
|
||||
Directory directory = FSDirectory.open(new File("D:\\lucene\\index").toPath());
|
||||
//步骤二:创建一个IndexWriter对象,用于写索引
|
||||
// Analyzer analyzer = new StandardAnalyzer();
|
||||
IndexWriter indexWriter=new IndexWriter(directory,new IndexWriterConfig(new IKAnalyzer(false)));
|
||||
|
||||
indexWriter.deleteAll();//清理所有索引库
|
||||
// IndexWriter indexWriter=new IndexWriter(directory,new IndexWriterConfig(new StandardAnalyzer()));
|
||||
//记录索引开始时间
|
||||
long startTime = System.currentTimeMillis();
|
||||
//步骤三:读取磁盘中文件,对应每一个文件创建一个文档对象
|
||||
File file=new File("D:\\testlog");
|
||||
//步骤四:获取文件列表
|
||||
File[] files = file.listFiles();
|
||||
for (File item:files) {
|
||||
BufferedReader bufferedReader = new BufferedReader(new FileReader(item));
|
||||
String strLine = null;
|
||||
while(null != (strLine = bufferedReader.readLine())){
|
||||
Document document = new Document();
|
||||
// document.add(new Field());
|
||||
document.add(new TextField("fieldContent", strLine, Field.Store.YES));
|
||||
indexWriter.addDocument(document);
|
||||
}
|
||||
}
|
||||
//记录索引结束时间
|
||||
long endTime = System.currentTimeMillis();
|
||||
System.out.println("建立索引"+ "共耗时" + (endTime-startTime) + "毫秒");
|
||||
indexWriter.commit();
|
||||
//步骤八:关闭资源
|
||||
indexWriter.close();
|
||||
System.out.println("建立索引成功-----关闭资源");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package org.nl.config.lucene;
|
||||
|
||||
/**
|
||||
* @Author: lyd
|
||||
* @Description: 定义lucene相关常量
|
||||
* @Date: 2023/8/25
|
||||
*/
|
||||
public class LogMessageConstant {
|
||||
/** 级别 */
|
||||
public final static String FIELD_LEVEL = "level";
|
||||
/** 时间 */
|
||||
public final static String FIELD_TIMESTAMP = "timestamp";
|
||||
/** 类的限定名 */
|
||||
public final static String FIELD_CLASS_NAME = "logger";
|
||||
/** 线程名 */
|
||||
public final static String FIELD_THREAD = "thread";
|
||||
/** 日志内容 */
|
||||
public final static String FIELD_MESSAGE = "message";
|
||||
public final static String FIELD_TRACEID = "tlogTraceId";
|
||||
// 定义颜色值
|
||||
/** 文本颜色:黑色 */
|
||||
public final static String COLOR_BLACK = "\u001B[30m";
|
||||
/** 文本颜色:红色 */
|
||||
public final static String COLOR_RED = "\u001B[31m";
|
||||
/** 文本颜色:绿色 */
|
||||
public final static String COLOR_GREEN = "\u001B[32m";
|
||||
/** 文本颜色:黄色 */
|
||||
public final static String COLOR_YELLOW = "\u001B[33m";
|
||||
/** 文本颜色:蓝色 */
|
||||
public final static String COLOR_BLUE = "\u001B[34m";
|
||||
/** 文本颜色:品红色 */
|
||||
public final static String COLOR_MAGENTA = "\u001B[35m";
|
||||
/** 文本颜色:青色 */
|
||||
public final static String COLOR_CYAN = "\u001B[36m";
|
||||
/** 文本颜色:白色 */
|
||||
public final static String COLOR_WHITE = "\u001B[37m";
|
||||
/** 文本颜色重置 */
|
||||
public final static String COLOR_RESET = "\u001B[0m";
|
||||
/** 背景颜色:黄色 */
|
||||
public final static String BACKGROUND_YELLOW = "\u001B[43m";
|
||||
|
||||
/** 索引路径 */
|
||||
public final static String INDEX_DIR = "D:\\lucene\\index";
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
package org.nl.config.lucene;
|
||||
/**
|
||||
* @author ldjun
|
||||
* @version 1.0
|
||||
* @date 2023年08月24日 13:00
|
||||
* @desc desc
|
||||
*/
|
||||
|
||||
import ch.qos.logback.classic.spi.ILoggingEvent;
|
||||
import ch.qos.logback.core.AppenderBase;
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.apache.lucene.analysis.Analyzer;
|
||||
import org.apache.lucene.document.Document;
|
||||
import org.apache.lucene.document.Field;
|
||||
import org.apache.lucene.document.NumericDocValuesField;
|
||||
import org.apache.lucene.document.StringField;
|
||||
import org.apache.lucene.index.IndexWriter;
|
||||
import org.apache.lucene.index.IndexWriterConfig;
|
||||
import org.apache.lucene.store.Directory;
|
||||
import org.apache.lucene.store.FSDirectory;
|
||||
import org.nl.system.service.lucene.dto.LuceneLogDto;
|
||||
import org.wltea.analyzer.lucene.IKAnalyzer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Map;
|
||||
|
||||
public class LuceneAppender extends AppenderBase<ILoggingEvent> {
|
||||
|
||||
private Directory index;
|
||||
private IndexWriter indexWriter;
|
||||
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
super.start();
|
||||
try {
|
||||
index = FSDirectory.open(Paths.get(LogMessageConstant.INDEX_DIR));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// 初始化 Lucene 索引
|
||||
Analyzer analyzer = new IKAnalyzer();
|
||||
IndexWriterConfig config = new IndexWriterConfig(analyzer);
|
||||
try {
|
||||
indexWriter = new IndexWriter(index, config);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void append(ILoggingEvent event) {
|
||||
String message = event.getFormattedMessage();
|
||||
try {
|
||||
// String[] split = message.split("@");
|
||||
LuceneLogDto luceneLogDto = JSONObject.parseObject(message, LuceneLogDto.class);
|
||||
Document document = new Document();
|
||||
try {
|
||||
//向document对象中添加域。
|
||||
Map<String, String> mdcPropertyMap = event.getMDCPropertyMap();
|
||||
String traceId = mdcPropertyMap.get("traceId");
|
||||
System.out.println("---追踪号---"+traceId);
|
||||
if (ObjectUtil.isNotEmpty(traceId)) {
|
||||
document.add(new StringField("trace_id", traceId, Field.Store.YES));
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(luceneLogDto.getDevice_code())) {
|
||||
document.add(new StringField("device_code", luceneLogDto.getDevice_code(), Field.Store.YES));
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(luceneLogDto.getContent())) {
|
||||
document.add(new StringField("fieldContent", luceneLogDto.getContent(), Field.Store.YES));
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(luceneLogDto.getMethod())) {
|
||||
document.add(new StringField("method", luceneLogDto.getMethod(), Field.Store.YES));
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(luceneLogDto.getStatus_code())) {
|
||||
document.add(new StringField("status_code", luceneLogDto.getStatus_code(), Field.Store.YES));
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(luceneLogDto.getRequestparam())) {
|
||||
document.add(new StringField("requestparam", luceneLogDto.getRequestparam(), Field.Store.YES));
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(luceneLogDto.getResponseparam())) {
|
||||
document.add(new StringField("responseparam", luceneLogDto.getResponseparam(), Field.Store.YES));
|
||||
}
|
||||
document.add(new StringField("logType", luceneLogDto.getLogType(), Field.Store.YES));
|
||||
document.add(new StringField("logTime", DateUtil.format(new DateTime(), "yyyy-MM-dd HH:mm:ss.SSS"), Field.Store.YES));
|
||||
document.add(new NumericDocValuesField("time",System.currentTimeMillis()));//排序
|
||||
|
||||
try {
|
||||
indexWriter.addDocument(document);
|
||||
indexWriter.commit();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return;
|
||||
}
|
||||
} catch (Exception e){
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
super.stop();
|
||||
try {
|
||||
indexWriter.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@ package org.nl.config.lucene;
|
||||
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.lucene.document.Document;
|
||||
@@ -15,10 +14,9 @@ import org.apache.lucene.store.FSDirectory;
|
||||
import org.apache.lucene.util.BytesRef;
|
||||
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* lucene查询器
|
||||
@@ -30,40 +28,27 @@ public class Searcher {
|
||||
//获取要查询的路径,也就是索引所在的位置
|
||||
Directory dir = FSDirectory.open(Paths.get(indexDir));
|
||||
IndexReader reader = DirectoryReader.open(dir);
|
||||
//构建IndexSearcher
|
||||
IndexSearcher searcher = new IndexSearcher(reader);
|
||||
//标准分词器,会自动去掉空格啊,is a the等单词
|
||||
// Analyzer analyzer = new StandardAnalyzer();
|
||||
// Analyzer analyzer = new IKAnalyzer(false);
|
||||
//查询解析器
|
||||
// QueryParser queryParser = new QueryParser("fieldContent", analyzer);
|
||||
|
||||
//记录索引开始时间
|
||||
long startTime = System.currentTimeMillis();
|
||||
// 实际上Lucene本身不支持分页。因此我们需要自己进行逻辑分页。我们要准备分页参数:
|
||||
int pageSize = Integer.parseInt(whereJson.get("size").toString());// 每页条数
|
||||
int pageNum = Integer.parseInt(whereJson.get("page").toString());// 当前页码
|
||||
int start = pageNum * pageSize;// 当前页的起始条数
|
||||
int end = start + pageSize;// 当前页的结束条数(不能包含)
|
||||
// 创建排序对象,需要排序字段SortField,参数:字段的名称、字段的类型、是否反转如果是false,升序。true降序
|
||||
Sort sort = new Sort(new SortField("logTime", SortField.Type.DOC,true));
|
||||
|
||||
TopDocs docs = null;
|
||||
BooleanQuery.Builder booleanQueryBuilder = new BooleanQuery.Builder();
|
||||
//时间范围查询
|
||||
String startDate = (String) whereJson.get("begin_time");
|
||||
String endDate = (String) whereJson.get("end_time");
|
||||
|
||||
if (startDate == null){
|
||||
Calendar calendar=Calendar.getInstance();
|
||||
calendar.set(1970, 0, 1);
|
||||
if (startDate == null){
|
||||
startDate = DateUtil.format(calendar.getTime(),"yyyy-MM-dd HH:mm:ss.SSS");
|
||||
}else{
|
||||
startDate = LuceneServiceAutoRun.getDate(startDate);
|
||||
startDate = getDate(startDate);
|
||||
}
|
||||
if (endDate == null){
|
||||
endDate = DateUtil.format(new DateTime(),"yyyy-MM-dd HH:mm:ss.SSS");
|
||||
} else {
|
||||
endDate = LuceneServiceAutoRun.getDate(endDate);
|
||||
endDate = getDate(endDate);
|
||||
}
|
||||
TermRangeQuery termRangeQuery = new TermRangeQuery("logTime", new BytesRef(startDate), new BytesRef(endDate), true, true);
|
||||
booleanQueryBuilder.add(termRangeQuery,BooleanClause.Occur.MUST);
|
||||
@@ -91,21 +76,19 @@ public class Searcher {
|
||||
WildcardQuery query = new WildcardQuery(new Term("fieldContent", "*"+(String) whereJson.get("blurry")+"*"));
|
||||
booleanQueryBuilder.add(query, BooleanClause.Occur.MUST);
|
||||
}
|
||||
docs = searcher.search(booleanQueryBuilder.build(), end,sort);
|
||||
//记录索引时间
|
||||
long endTime = System.currentTimeMillis();
|
||||
log.info("匹配{}共耗时{}毫秒",booleanQueryBuilder.build(),(endTime-startTime));
|
||||
log.info("查询到{}条日志文件", docs.totalHits.value);
|
||||
List<String> list = new ArrayList<>();
|
||||
ScoreDoc[] scoreDocs = docs.scoreDocs;
|
||||
if (end > docs.totalHits.value) end = (int) docs.totalHits.value;
|
||||
JSONArray array = new JSONArray();
|
||||
|
||||
for (int i = start; i < end; i++) {
|
||||
ScoreDoc scoreDoc = scoreDocs[i];
|
||||
TopFieldCollector collector = TopFieldCollector.create(new Sort(new SortField("time", SortField.Type.LONG,true)), 20000, 0);
|
||||
searcher.search(booleanQueryBuilder.build(), collector);
|
||||
TopDocs topDocs = collector.topDocs(pageNum*pageSize, pageSize);
|
||||
int totalSize = collector.getTotalHits();
|
||||
ScoreDoc[] scoreDocs = topDocs.scoreDocs;
|
||||
|
||||
List<JSONObject> list = new ArrayList<>();
|
||||
for (ScoreDoc scoreDoc : scoreDocs) {
|
||||
Document doc = reader.document(scoreDoc.doc);
|
||||
JSONObject object = new JSONObject();
|
||||
object.put("content",doc.get("fieldContent"));
|
||||
// object.put("trace_id",doc.get("trace_id"));
|
||||
object.put("device_code",doc.get("device_code"));
|
||||
object.put("logTime",doc.get("logTime"));
|
||||
object.put("method",doc.get("method"));
|
||||
@@ -113,28 +96,21 @@ public class Searcher {
|
||||
object.put("requestparam",doc.get("requestparam"));
|
||||
object.put("responseparam",doc.get("responseparam"));
|
||||
if(doc.get("fieldContent") != null) {
|
||||
array.add(object);
|
||||
list.add(object);
|
||||
}
|
||||
}
|
||||
for(Object logDto:array){
|
||||
log.info(logDto.toString());
|
||||
}
|
||||
reader.close();
|
||||
dir.close();
|
||||
JSONObject jo = new JSONObject();
|
||||
jo.put("content", array);
|
||||
jo.put("totalElements", docs.totalHits.value);
|
||||
jo.put("content", list);
|
||||
jo.put("totalElements", totalSize);
|
||||
return jo;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String indexDir = "D:\\lucene\\index";
|
||||
//查询这个字符串
|
||||
String q = "07.832";
|
||||
Map whereJson = null;
|
||||
try {
|
||||
search(indexDir, q,whereJson);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
public static String getDate(String timeString) throws ParseException {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX");//时间格式
|
||||
Date date = sdf.parse(timeString);
|
||||
timeString = DateUtil.format(date, "yyyy-MM-dd HH:mm:ss.SSS");//格式化后的时间
|
||||
return timeString;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
package org.nl.system.service.lucene;
|
||||
|
||||
import org.nl.system.service.lucene.dto.LuceneLogDto;
|
||||
|
||||
import java.io.IOException;
|
||||
import org.nl.system.service.lucene.dto.LuceneLogDto;
|
||||
|
||||
public interface LuceneExecuteLogService {
|
||||
/**
|
||||
@@ -26,7 +25,7 @@ public interface LuceneExecuteLogService {
|
||||
*
|
||||
* @param luceneLogDto 日志结果对象
|
||||
*/
|
||||
void interfaceExecuteLog(LuceneLogDto luceneLogDto) throws IOException;
|
||||
void interfaceExecuteLog(LuceneLogDto luceneLogDto);
|
||||
|
||||
/**
|
||||
* 设备执行日志,会保留历史记录
|
||||
|
||||
@@ -7,6 +7,11 @@ import java.util.Map;
|
||||
|
||||
|
||||
public interface LuceneService {
|
||||
/**
|
||||
* 获取labels和values树
|
||||
* @return
|
||||
*/
|
||||
// JSONArray getLabelsValues();
|
||||
|
||||
/**
|
||||
* 获取数据分页
|
||||
|
||||
@@ -69,18 +69,38 @@ public class LuceneLogDto {
|
||||
private String update_time;
|
||||
|
||||
|
||||
|
||||
public LuceneLogDto (final String opc_server_code,final String opc_plc_code,
|
||||
final String device_code,final String to_home,final int last_home,
|
||||
final int home) {
|
||||
super ();
|
||||
public LuceneLogDto(final String opc_server_code, final String opc_plc_code,
|
||||
final String device_code, final String to_home, final String last_home,
|
||||
final String home) {
|
||||
super();
|
||||
this.device_code = device_code;
|
||||
this.content = "信号"
|
||||
this.content = "信号 ["
|
||||
+ opc_server_code + "."
|
||||
+ opc_plc_code + "."
|
||||
+ device_code + "."
|
||||
+ to_home + "变更从"
|
||||
+ last_home + "->"
|
||||
+ to_home + "] 发生变更 "
|
||||
+ last_home + " -> "
|
||||
+ home;
|
||||
}
|
||||
|
||||
public LuceneLogDto(final String device_code, final String remark) {
|
||||
super();
|
||||
this.device_code = device_code;
|
||||
this.content = "设备 ["
|
||||
+ device_code
|
||||
+ "] - "
|
||||
+ remark;
|
||||
}
|
||||
|
||||
public LuceneLogDto(final LuceneLogDto dto) {
|
||||
super();
|
||||
this.device_code = device_code;
|
||||
this.method = method;
|
||||
|
||||
this.content = "设备 ["
|
||||
+ device_code
|
||||
+ "] - "
|
||||
+ remark;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,27 +1,15 @@
|
||||
package org.nl.system.service.lucene.impl;
|
||||
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.lucene.document.Document;
|
||||
import org.apache.lucene.document.Field;
|
||||
import org.apache.lucene.document.StringField;
|
||||
import org.apache.lucene.index.IndexWriter;
|
||||
import org.nl.common.enums.LogTypeEnum;
|
||||
import org.nl.config.lucene.DynamicLogger;
|
||||
import org.nl.config.lucene.LuceneServiceAutoRun;
|
||||
import org.nl.system.service.lucene.LuceneExecuteLogService;
|
||||
import org.nl.system.service.lucene.dto.LuceneLogDto;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.MDC;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author jlm
|
||||
* @description 服务实现
|
||||
@@ -32,69 +20,21 @@ import java.io.IOException;
|
||||
@Slf4j
|
||||
public class LuceneExecuteLogServiceImpl implements LuceneExecuteLogService {
|
||||
|
||||
//日志目录
|
||||
@Value("${logging.file.path}")
|
||||
private String logPath;
|
||||
|
||||
@Override
|
||||
public void deviceItemValue(String device_code, String key, String value) {
|
||||
String now = DateUtil.now();
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public void deviceExecuteLog(LuceneLogDto luceneLogDto) {
|
||||
luceneLogDto.setLogType(LogTypeEnum.DEVICE_LOG.getDesc());
|
||||
addIndex(luceneLogDto);
|
||||
log.info("{}", JSON.toJSONString(luceneLogDto));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void interfaceExecuteLog(LuceneLogDto luceneLogDto) throws IOException {
|
||||
public void interfaceExecuteLog(LuceneLogDto luceneLogDto) {
|
||||
luceneLogDto.setLogType(LogTypeEnum.INTERFACE_LOG.getDesc());
|
||||
addIndex(luceneLogDto);
|
||||
}
|
||||
|
||||
private void addIndex(LuceneLogDto luceneLogDto) throws IOException {
|
||||
IndexWriter indexWriter = LuceneServiceAutoRun.getIndexWriter();
|
||||
//创建一个Document对象
|
||||
Document document = new Document();
|
||||
try {
|
||||
//记录索引开始时间
|
||||
long startTime = System.currentTimeMillis();
|
||||
//向document对象中添加域。
|
||||
if (ObjectUtil.isNotEmpty(luceneLogDto.getDevice_code())) {
|
||||
document.add(new StringField("device_code", luceneLogDto.getDevice_code(), Field.Store.YES));
|
||||
// document.add(new TextField("device_code", luceneLogDto.getDevice_code(), Field.Store.YES));
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(luceneLogDto.getContent())) {
|
||||
document.add(new StringField("fieldContent", luceneLogDto.getContent(), Field.Store.YES));
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(luceneLogDto.getMethod())) {
|
||||
document.add(new StringField("method", luceneLogDto.getMethod(), Field.Store.YES));
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(luceneLogDto.getStatus_code())) {
|
||||
document.add(new StringField("status_code", luceneLogDto.getStatus_code(), Field.Store.YES));
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(luceneLogDto.getRequestparam())) {
|
||||
document.add(new StringField("requestparam", luceneLogDto.getRequestparam(), Field.Store.YES));
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(luceneLogDto.getResponseparam())) {
|
||||
document.add(new StringField("responseparam", luceneLogDto.getResponseparam(), Field.Store.YES));
|
||||
}
|
||||
document.add(new StringField("logType", luceneLogDto.getLogType(), Field.Store.YES));
|
||||
document.add(new StringField("logTime", DateUtil.format(new DateTime(), "yyyy-MM-dd HH:mm:ss.SSS"), Field.Store.YES));
|
||||
indexWriter.addDocument(document);
|
||||
//记录索引结束时间
|
||||
long endTime = System.currentTimeMillis();
|
||||
indexWriter.commit();
|
||||
//实现日志文件按业务独立生成日志文件到指定路径
|
||||
DynamicLogger loggerBuilder =new DynamicLogger(logPath+"\\"+luceneLogDto.getLogType()+"\\");
|
||||
Logger logger = loggerBuilder.getLogger(luceneLogDto.getDevice_code());
|
||||
// logger.info("设备{}建立索引共耗时{}毫秒",luceneLogDto.getDevice_code(),endTime-startTime);
|
||||
logger.info("{}",luceneLogDto.toString());
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
log.info("{}", JSON.toJSONString(luceneLogDto));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -20,10 +20,51 @@ import java.util.Map;
|
||||
@Slf4j
|
||||
public class LuceneServiceImpl implements LuceneService {
|
||||
|
||||
// @Value("${loki.url}")
|
||||
// private String lokiUrl;
|
||||
|
||||
// @Value("${loki.systemName}")
|
||||
// private String systemName;
|
||||
|
||||
//日志索引目录
|
||||
@Value("${lucene.index.path}")
|
||||
private String luceneUrl;
|
||||
|
||||
/**
|
||||
* 获取labels和values树
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
// @Override
|
||||
// public JSONArray getLabelsValues() {
|
||||
// JSONArray result = new JSONArray();
|
||||
// // 获取所有标签
|
||||
// String labelString = HttpUtil.get(lokiUrl + "/labels", CharsetUtil.CHARSET_UTF_8);
|
||||
// JSONObject parse = (JSONObject) JSONObject.parse(labelString);
|
||||
// JSONArray labels = parse.getJSONArray("data");
|
||||
// for (int i=0; i<labels.size(); i++) {
|
||||
// // 获取标签下的所有值
|
||||
// String valueString = HttpUtil.get(lokiUrl + "/label/" + labels.getString(i) + "/values", CharsetUtil.CHARSET_UTF_8);
|
||||
// JSONObject parse2 = (JSONObject) JSONObject.parse(valueString);
|
||||
// JSONArray values = parse2.getJSONArray("data");
|
||||
// JSONArray children = new JSONArray();
|
||||
// // 组成树形状态 两级
|
||||
// for (int j=0; j<values.size(); j++) {
|
||||
// JSONObject leaf = new JSONObject();
|
||||
// leaf.put("label", values.getString(j));
|
||||
// leaf.put("value", values.getString(j));
|
||||
// children.add(leaf);
|
||||
// }
|
||||
//
|
||||
// JSONObject node = new JSONObject();
|
||||
// node.put("label", labels.getString(i));
|
||||
// node.put("value", labels.getString(i));
|
||||
// node.put("children", children);
|
||||
// result.add(node);
|
||||
// }
|
||||
// return result;
|
||||
// }
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getAll(Map whereJson, Pageable page) {
|
||||
JSONObject jo = new JSONObject();
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<included>
|
||||
<springProperty scope="context" name="logPath" source="logging.file.path" defaultValue="logs"/>
|
||||
<property name="LOG_HOME" value="${logPath}"/>
|
||||
<!-- 按照每天生成日志文件 -->
|
||||
<appender name="AcsToWms" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
|
||||
<!--日志文件输出的文件名-->
|
||||
<FileNamePattern>${LOG_HOME}/ACS请求WMS/%d{yyyy-MM-dd}.%i.log</FileNamePattern>
|
||||
<!--日志文件保留天数-->
|
||||
<maxHistory>15</maxHistory>
|
||||
<!--单个日志最大容量 至少10MB才能看得出来-->
|
||||
<maxFileSize>100MB</maxFileSize>
|
||||
<!--所有日志最多占多大容量-->
|
||||
<totalSizeCap>2GB</totalSizeCap>
|
||||
</rollingPolicy>
|
||||
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
|
||||
<!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符-->
|
||||
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
|
||||
<charset>${log.charset}</charset>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<appender name="asyncFileAppender" class="ch.qos.logback.classic.AsyncAppender">
|
||||
<appender-ref ref="AcsToWms" />
|
||||
<!-- 设置队列大小,根据您的需求调整 -->
|
||||
<queueSize>512</queueSize>
|
||||
</appender>
|
||||
<logger name="org.nl.acs.ext.wms.service.impl.AcsToWmsServiceImpl" level="info" additivity="true">
|
||||
<appender-ref ref="asyncFileAppender"/>
|
||||
</logger>
|
||||
</included>
|
||||
@@ -10,7 +10,7 @@
|
||||
<!--日志文件保留天数-->
|
||||
<maxHistory>15</maxHistory>
|
||||
<!--单个日志最大容量 至少10MB才能看得出来-->
|
||||
<maxFileSize>50MB</maxFileSize>
|
||||
<maxFileSize>100MB</maxFileSize>
|
||||
<!--所有日志最多占多大容量-->
|
||||
<totalSizeCap>2GB</totalSizeCap>
|
||||
</rollingPolicy>
|
||||
@@ -21,13 +21,12 @@
|
||||
</encoder>
|
||||
|
||||
</appender>
|
||||
|
||||
<!-- <logger name="org.nl.start.Init" level="info" additivity="false">
|
||||
<appender-ref ref="FILE3"/>
|
||||
</logger>-->
|
||||
|
||||
<!-- 打印sql -->
|
||||
<logger name="org.nl.acs.device_driver.basedriver.agv.ndcone.AgvNdcOneDeviceDriver" level="info" additivity="false">
|
||||
<appender-ref ref="AgvNdcOneDeviceDriver"/>
|
||||
<appender name="asyncFileAppender" class="ch.qos.logback.classic.AsyncAppender">
|
||||
<appender-ref ref="AgvNdcOneDeviceDriver" />
|
||||
<!-- 设置队列大小,根据您的需求调整 -->
|
||||
<queueSize>512</queueSize>
|
||||
</appender>
|
||||
<logger name="org.nl.acs.device_driver.basedriver.agv.ndcone.AgvNdcOneDeviceDrive" level="info" additivity="true">
|
||||
<appender-ref ref="asyncFileAppender"/>
|
||||
</logger>
|
||||
</included>
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<!--日志文件保留天数-->
|
||||
<maxHistory>15</maxHistory>
|
||||
<!--单个日志最大容量 至少10MB才能看得出来-->
|
||||
<maxFileSize>50MB</maxFileSize>
|
||||
<maxFileSize>100MB</maxFileSize>
|
||||
<!--所有日志最多占多大容量-->
|
||||
<totalSizeCap>2GB</totalSizeCap>
|
||||
</rollingPolicy>
|
||||
@@ -21,13 +21,12 @@
|
||||
</encoder>
|
||||
|
||||
</appender>
|
||||
|
||||
<!-- <logger name="org.nl.start.Init" level="info" additivity="false">
|
||||
<appender-ref ref="FILE3"/>
|
||||
</logger>-->
|
||||
|
||||
<!-- 打印sql -->
|
||||
<logger name="org.nl.modules.quartz.task.AutoCreateInst" level="info" additivity="false">
|
||||
<appender-ref ref="AutoCreateInst"/>
|
||||
<appender name="asyncFileAppender" class="ch.qos.logback.classic.AsyncAppender">
|
||||
<appender-ref ref="AutoCreateInst" />
|
||||
<!-- 设置队列大小,根据您的需求调整 -->
|
||||
<queueSize>512</queueSize>
|
||||
</appender>
|
||||
<logger name="org.nl.modules.quartz.task.AutoCreateInst" level="info" additivity="true">
|
||||
<appender-ref ref="asyncFileAppender"/>
|
||||
</logger>
|
||||
</included>
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<!--日志文件保留天数-->
|
||||
<maxHistory>15</maxHistory>
|
||||
<!--单个日志最大容量 至少10MB才能看得出来-->
|
||||
<maxFileSize>50MB</maxFileSize>
|
||||
<maxFileSize>100MB</maxFileSize>
|
||||
<!--所有日志最多占多大容量-->
|
||||
<totalSizeCap>2GB</totalSizeCap>
|
||||
</rollingPolicy>
|
||||
@@ -21,13 +21,12 @@
|
||||
</encoder>
|
||||
|
||||
</appender>
|
||||
|
||||
<!-- <logger name="org.nl.start.Init" level="info" additivity="false">
|
||||
<appender-ref ref="FILE3"/>
|
||||
</logger>-->
|
||||
|
||||
<!-- 打印sql -->
|
||||
<logger name="org.nl.acs.device_driver.lnsh.lnsh_rgv.LnshRGVDeviceDriver" level="info" additivity="false">
|
||||
<appender-ref ref="LnshRGVDeviceDriver"/>
|
||||
<appender name="asyncFileAppender" class="ch.qos.logback.classic.AsyncAppender">
|
||||
<appender-ref ref="LnshRGVDeviceDriver" />
|
||||
<!-- 设置队列大小,根据您的需求调整 -->
|
||||
<queueSize>512</queueSize>
|
||||
</appender>
|
||||
<logger name="org.nl.acs.device_driver.lnsh.lnsh_rgv.LnshRGVDeviceDriver" level="info" additivity="true">
|
||||
<appender-ref ref="asyncFileAppender"/>
|
||||
</logger>
|
||||
</included>
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
|
||||
</appender>
|
||||
|
||||
<appender name="luceneAppender" class="org.nl.modules.lucene.common.LuceneAppender" />
|
||||
<appender name="luceneAppender" class="org.nl.config.lucene.LuceneAppender" />
|
||||
<appender name="asyncLuceneAppender" class="ch.qos.logback.classic.AsyncAppender">
|
||||
<appender-ref ref="luceneAppender" />
|
||||
<!-- 设置队列大小,根据您的需求调整 -->
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<!--日志文件保留天数-->
|
||||
<maxHistory>15</maxHistory>
|
||||
<!--单个日志最大容量 至少10MB才能看得出来-->
|
||||
<maxFileSize>50MB</maxFileSize>
|
||||
<maxFileSize>100MB</maxFileSize>
|
||||
<!--所有日志最多占多大容量-->
|
||||
<totalSizeCap>2GB</totalSizeCap>
|
||||
</rollingPolicy>
|
||||
@@ -22,12 +22,12 @@
|
||||
|
||||
</appender>
|
||||
|
||||
<!-- <logger name="org.nl.start.Init" level="info" additivity="false">
|
||||
<appender-ref ref="FILE3"/>
|
||||
</logger>-->
|
||||
|
||||
<!-- 打印sql -->
|
||||
<logger name="org.nl.acs.agv.server.impl.NDCAgvServiceImpl" level="info" additivity="false">
|
||||
<appender-ref ref="NDCAgvServiceImpl"/>
|
||||
<appender name="asyncFileAppender" class="ch.qos.logback.classic.AsyncAppender">
|
||||
<appender-ref ref="NDCAgvServiceImpl" />
|
||||
<!-- 设置队列大小,根据您的需求调整 -->
|
||||
<queueSize>512</queueSize>
|
||||
</appender>
|
||||
<logger name="org.nl.acs.agv.server.impl.NDCAgvServiceImpl" level="info" additivity="true">
|
||||
<appender-ref ref="asyncFileAppender"/>
|
||||
</logger>
|
||||
</included>
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<included>
|
||||
<springProperty scope="context" name="logPath" source="logging.file.path" defaultValue="logs"/>
|
||||
<property name="LOG_HOME" value="${logPath}"/>
|
||||
<!-- 按照每天生成日志文件 -->
|
||||
<appender name="NDCSocketConnectionAutoRun" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
|
||||
<!--日志文件输出的文件名-->
|
||||
<FileNamePattern>${LOG_HOME}/NDC交互日志/%d{yyyy-MM-dd}.%i.log</FileNamePattern>
|
||||
<!--日志文件保留天数-->
|
||||
<maxHistory>15</maxHistory>
|
||||
<!--单个日志最大容量 至少10MB才能看得出来-->
|
||||
<maxFileSize>100MB</maxFileSize>
|
||||
<!--所有日志最多占多大容量-->
|
||||
<totalSizeCap>2GB</totalSizeCap>
|
||||
</rollingPolicy>
|
||||
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
|
||||
<!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符-->
|
||||
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
|
||||
<charset>${log.charset}</charset>
|
||||
</encoder>
|
||||
|
||||
</appender>
|
||||
<appender name="asyncFileAppender" class="ch.qos.logback.classic.AsyncAppender">
|
||||
<appender-ref ref="NDCSocketConnectionAutoRun" />
|
||||
<!-- 设置队列大小,根据您的需求调整 -->
|
||||
<queueSize>512</queueSize>
|
||||
</appender>
|
||||
<logger name="org.nl.start.auto.run.NDCSocketConnectionAutoRun" level="info" additivity="true">
|
||||
<appender-ref ref="asyncFileAppender"/>
|
||||
</logger>
|
||||
</included>
|
||||
@@ -10,7 +10,7 @@
|
||||
<!--日志文件保留天数-->
|
||||
<maxHistory>15</maxHistory>
|
||||
<!--单个日志最大容量 至少10MB才能看得出来-->
|
||||
<maxFileSize>50MB</maxFileSize>
|
||||
<maxFileSize>100MB</maxFileSize>
|
||||
<!--所有日志最多占多大容量-->
|
||||
<totalSizeCap>2GB</totalSizeCap>
|
||||
</rollingPolicy>
|
||||
@@ -21,13 +21,12 @@
|
||||
</encoder>
|
||||
|
||||
</appender>
|
||||
|
||||
<!-- <logger name="org.nl.start.Init" level="info" additivity="false">
|
||||
<appender-ref ref="FILE3"/>
|
||||
</logger>-->
|
||||
|
||||
<!-- 打印sql -->
|
||||
<logger name="org.nl.acs.ext.wms.service.impl.WmsToAcsServiceImpl" level="info" additivity="false">
|
||||
<appender-ref ref="WmsToAcs"/>
|
||||
<appender name="asyncFileAppender" class="ch.qos.logback.classic.AsyncAppender">
|
||||
<appender-ref ref="WmsToAcs" />
|
||||
<!-- 设置队列大小,根据您的需求调整 -->
|
||||
<queueSize>512</queueSize>
|
||||
</appender>
|
||||
<logger name="org.nl.acs.ext.wms.service.impl.WmsToAcsServiceImpl" level="info" additivity="true">
|
||||
<appender-ref ref="asyncFileAppender"/>
|
||||
</logger>
|
||||
</included>
|
||||
|
||||
@@ -14,10 +14,13 @@ https://juejin.cn/post/6844903775631572999
|
||||
<property name="log.pattern"
|
||||
value="%black(%contextName-) %red(%d{yyyy-MM-dd HH:mm:ss.SSS}) %green([%thread]) %highlight(%-5level) %boldMagenta(%logger{36}) - %gray(%msg%n)"/>
|
||||
<springProperty scope="context" name="logPath" source="logging.file.path" defaultValue="logs"/>
|
||||
<springProperty scope="context" name="lokiUrl" source="loki.url"/>
|
||||
<springProperty scope="context" name="systemName" source="loki.systemName"/>
|
||||
<property name="LOKI_URL" value="${lokiUrl}"/>
|
||||
<property name="SYSTEM_NAME" value="${systemName}"/>
|
||||
<!--定义日志文件的存储地址 勿在 LogBack 的配置中使用相对路径-->
|
||||
<property name="LOG_HOME" value="${logPath}"/>
|
||||
<!--引入默认的一些设置-->
|
||||
<!--<include resource="log/XrToMes.xml"/>
|
||||
<include resource="log/MesToErp.xml"/>-->
|
||||
<include resource="log/AutoCreateInst.xml"/>
|
||||
<include resource="log/AcsToWms.xml"/>
|
||||
<include resource="log/WmsToAcs.xml"/>
|
||||
@@ -27,15 +30,12 @@ https://juejin.cn/post/6844903775631572999
|
||||
<include resource="log/LnshRGVDeviceDriver.xml"/>
|
||||
|
||||
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<withJansi>true</withJansi>
|
||||
<encoder class="com.yomahub.tlog.core.enhance.logback.AspectLogbackEncoder">
|
||||
<!-- <encoder>-->
|
||||
<encoder>
|
||||
<pattern>${log.pattern}</pattern>
|
||||
<charset>${log.charset}</charset>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<!--定义日志文件的存储地址 勿在 LogBack 的配置中使用相对路径-->
|
||||
<property name="LOG_HOME" value="${logPath}"/>
|
||||
<!-- 按照每天生成日志文件 -->
|
||||
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
|
||||
@@ -44,138 +44,108 @@ https://juejin.cn/post/6844903775631572999
|
||||
<!--日志文件保留天数-->
|
||||
<maxHistory>15</maxHistory>
|
||||
<!--单个日志最大容量 至少10MB才能看得出来-->
|
||||
<maxFileSize>50MB</maxFileSize>
|
||||
<maxFileSize>100MB</maxFileSize>
|
||||
<!--所有日志最多占多大容量-->
|
||||
<totalSizeCap>20GB</totalSizeCap>
|
||||
</rollingPolicy>
|
||||
|
||||
<encoder class="com.yomahub.tlog.core.enhance.logback.AspectLogbackEncoder">
|
||||
<!-- <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">-->
|
||||
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
|
||||
<!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符-->
|
||||
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
|
||||
</encoder>
|
||||
|
||||
</appender>
|
||||
|
||||
<!--异步到文件-->
|
||||
<!-- <appender name="asyncFileAppender" class="ch.qos.logback.classic.AsyncAppender">-->
|
||||
<appender name="asyncFileAppender" class="com.yomahub.tlog.core.enhance.logback.async.AspectLogbackAsyncAppender">
|
||||
<appender name="asyncFileAppender" class="ch.qos.logback.classic.AsyncAppender">
|
||||
<discardingThreshold>0</discardingThreshold>
|
||||
<queueSize>500</queueSize>
|
||||
<queueSize>200</queueSize>
|
||||
<appender-ref ref="FILE"/>
|
||||
</appender>
|
||||
|
||||
<appender name="MY_FILE" class="org.nl.system.service.lucene.LuceneDefaultAppender">
|
||||
<appender name="luceneAppender" class="org.nl.config.lucene.LuceneAppender" />
|
||||
<appender name="asyncLuceneAppender" class="ch.qos.logback.classic.AsyncAppender">
|
||||
<appender-ref ref="luceneAppender" />
|
||||
<!-- 设置队列大小,根据您的需求调整 -->
|
||||
<queueSize>512</queueSize>
|
||||
</appender>
|
||||
|
||||
|
||||
<!--添加loki-->
|
||||
<!--开发环境:打印控制台-->
|
||||
<springProfile name="dev">
|
||||
<root level="info">
|
||||
<appender-ref ref="asyncLuceneAppender"/>
|
||||
<appender-ref ref="asyncFileAppender"/>
|
||||
</root>
|
||||
<logger name="org.springframework" level="ERROR" additivity="false">
|
||||
<appender-ref ref="CONSOLE"/>
|
||||
<logger name="jdbc" level="ERROR" additivity="true">
|
||||
<appender-ref ref="asyncFileAppender"/>
|
||||
</logger>
|
||||
<logger name="org.apache" level="ERROR" additivity="false">
|
||||
<appender-ref ref="CONSOLE"/>
|
||||
<logger name="org.springframework" level="ERROR" additivity="true">
|
||||
<appender-ref ref="asyncFileAppender"/>
|
||||
</logger>
|
||||
<logger name="org.hibernate" level="ERROR" additivity="false">
|
||||
<appender-ref ref="CONSOLE"/>
|
||||
<logger name="org.hibernate" level="ERROR" additivity="true">
|
||||
<appender-ref ref="asyncFileAppender"/>
|
||||
</logger>
|
||||
<logger name="io.netty" level="ERROR" additivity="false">
|
||||
<appender-ref ref="CONSOLE"/>
|
||||
<logger name="org.quartz" level="ERROR" additivity="true">
|
||||
<appender-ref ref="asyncFileAppender"/>
|
||||
</logger>
|
||||
<logger name="jdbc" level="ERROR" additivity="false">
|
||||
<appender-ref ref="CONSOLE"/>
|
||||
<logger name="com.google" level="ERROR" additivity="true">
|
||||
<appender-ref ref="asyncFileAppender"/>
|
||||
</logger>
|
||||
<logger name="io.lettuce" level="ERROR" additivity="false">
|
||||
<appender-ref ref="CONSOLE"/>
|
||||
<logger name="org.redisson" level="ERROR" additivity="true">
|
||||
<appender-ref ref="asyncFileAppender"/>
|
||||
</logger>
|
||||
<logger name="com.fasterxml" level="ERROR" additivity="false">
|
||||
<appender-ref ref="CONSOLE"/>
|
||||
<logger name="org.nl.modules.wql" level="ERROR" additivity="true">
|
||||
<appender-ref ref="asyncFileAppender"/>
|
||||
</logger>
|
||||
<logger name="org.quartz" level="ERROR" additivity="false">
|
||||
<appender-ref ref="CONSOLE"/>
|
||||
<logger name="org.springframework.data" level="ERROR" additivity="true">
|
||||
<appender-ref ref="asyncFileAppender"/>
|
||||
</logger>
|
||||
<logger name="com.google" level="ERROR" additivity="false">
|
||||
<appender-ref ref="CONSOLE"/>
|
||||
</logger>
|
||||
<logger name="springfox" level="ERROR" additivity="false">
|
||||
<appender-ref ref="CONSOLE"/>
|
||||
</logger>
|
||||
<logger name="log4jdbc" level="ERROR" additivity="false">
|
||||
<appender-ref ref="CONSOLE"/>
|
||||
</logger>
|
||||
<logger name="nl.basjes" level="ERROR" additivity="false">
|
||||
<appender-ref ref="CONSOLE"/>
|
||||
<logger name="org.jinterop" level="ERROR" additivity="true">
|
||||
<appender-ref ref="asyncFileAppender"/>
|
||||
</logger>
|
||||
</springProfile>
|
||||
|
||||
<!--测试环境:打印控制台-->
|
||||
<springProfile name="test">
|
||||
<!-- 打印sql -->
|
||||
<logger name="org.nl.start.Init" level="info" additivity="false">
|
||||
<appender-ref ref="FILE"/>
|
||||
</logger>
|
||||
<root level="info">
|
||||
<appender-ref ref="CONSOLE"/>
|
||||
</root>
|
||||
</springProfile>
|
||||
|
||||
<!--生产环境:打印控制台和输出到文件-->
|
||||
<springProfile name="prod">
|
||||
<root level="debug">
|
||||
<appender-ref ref="asyncFileAppender"/>
|
||||
</root>
|
||||
<logger name="org.springframework" level="ERROR" additivity="false">
|
||||
<appender-ref ref="asyncFileAppender"/>
|
||||
</logger>
|
||||
<logger name="org.apache" level="ERROR" additivity="false">
|
||||
<appender-ref ref="asyncFileAppender"/>
|
||||
</logger>
|
||||
<logger name="org.hibernate" level="ERROR" additivity="false">
|
||||
<appender-ref ref="asyncFileAppender"/>
|
||||
</logger>
|
||||
<logger name="io.netty" level="ERROR" additivity="false">
|
||||
<appender-ref ref="asyncFileAppender"/>
|
||||
</logger>
|
||||
<logger name="jdbc" level="ERROR" additivity="false">
|
||||
<appender-ref ref="asyncFileAppender"/>
|
||||
</logger>
|
||||
<logger name="io.lettuce" level="ERROR" additivity="false">
|
||||
<appender-ref ref="asyncFileAppender"/>
|
||||
</logger>
|
||||
<logger name="com.fasterxml" level="ERROR" additivity="false">
|
||||
<appender-ref ref="asyncFileAppender"/>
|
||||
</logger>
|
||||
<logger name="org.quartz" level="ERROR" additivity="false">
|
||||
<appender-ref ref="asyncFileAppender"/>
|
||||
</logger>
|
||||
<logger name="com.google" level="ERROR" additivity="false">
|
||||
<appender-ref ref="asyncFileAppender"/>
|
||||
</logger>
|
||||
<logger name="springfox" level="ERROR" additivity="false">
|
||||
<appender-ref ref="asyncFileAppender"/>
|
||||
</logger>
|
||||
<logger name="log4jdbc" level="ERROR" additivity="false">
|
||||
<appender-ref ref="asyncFileAppender"/>
|
||||
</logger>
|
||||
<logger name="nl.basjes" level="ERROR" additivity="false">
|
||||
<appender-ref ref="asyncFileAppender"/>
|
||||
</logger>
|
||||
</springProfile>
|
||||
|
||||
|
||||
<!--测试环境:打印控制台-->
|
||||
<springProfile name="test">
|
||||
<root level="info">
|
||||
<appender-ref ref="asyncLuceneAppender"/>
|
||||
<appender-ref ref="asyncFileAppender"/>
|
||||
</root>
|
||||
<logger name="jdbc.audit" level="ERROR" additivity="false">
|
||||
<appender-ref ref="CONSOLE"/>
|
||||
<logger name="jdbc" level="ERROR" additivity="true">
|
||||
<appender-ref ref="asyncFileAppender"/>
|
||||
</logger>
|
||||
<logger name="jdbc.resultset" level="ERROR" additivity="false">
|
||||
<appender-ref ref="CONSOLE"/>
|
||||
<logger name="org.springframework" level="ERROR" additivity="true">
|
||||
<appender-ref ref="asyncFileAppender"/>
|
||||
</logger>
|
||||
<logger name="springfox.documentation" level="ERROR" additivity="false">
|
||||
<appender-ref ref="CONSOLE"/>
|
||||
<logger name="org.hibernate" level="ERROR" additivity="true">
|
||||
<appender-ref ref="asyncFileAppender"/>
|
||||
</logger>
|
||||
<logger name="jdbc.resultsettable" level="ERROR" additivity="false">
|
||||
<appender-ref ref="CONSOLE"/>
|
||||
<logger name="org.quartz" level="ERROR" additivity="true">
|
||||
<appender-ref ref="asyncFileAppender"/>
|
||||
</logger>
|
||||
<logger name="jdbc.sqlonly" level="ERROR" additivity="false">
|
||||
<appender-ref ref="CONSOLE"/>
|
||||
<logger name="com.google" level="ERROR" additivity="true">
|
||||
<appender-ref ref="asyncFileAppender"/>
|
||||
</logger>
|
||||
<logger name="org.redisson" level="ERROR" additivity="true">
|
||||
<appender-ref ref="asyncFileAppender"/>
|
||||
</logger>
|
||||
<logger name="org.nl.modules.wql" level="ERROR" additivity="true">
|
||||
<appender-ref ref="asyncFileAppender"/>
|
||||
</logger>
|
||||
<logger name="org.springframework.data" level="ERROR" additivity="true">
|
||||
<appender-ref ref="asyncFileAppender"/>
|
||||
</logger>
|
||||
<logger name="org.jinterop" level="ERROR" additivity="true">
|
||||
<appender-ref ref="asyncFileAppender"/>
|
||||
</logger>
|
||||
</springProfile>
|
||||
</configuration>
|
||||
|
||||
@@ -458,6 +458,12 @@
|
||||
<artifactId>lucene-queryparser</artifactId>
|
||||
<version>${lucene.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.yomahub</groupId>
|
||||
<artifactId>tlog-core</artifactId>
|
||||
<version>1.5.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ public class CockpitController {
|
||||
}
|
||||
|
||||
@PostMapping("/getTbxInfo")
|
||||
@Log("获取固化室信息")
|
||||
@Log("获取涂板线信息")
|
||||
@ApiOperation("获取涂板线信息")
|
||||
public ResponseEntity<Object> getTbxInfo() {
|
||||
return new ResponseEntity<>(cockpitService.getTbxInfo(), HttpStatus.OK);
|
||||
|
||||
@@ -15,7 +15,8 @@
|
||||
pw.operator,
|
||||
pw.create_name,
|
||||
pw.plan_qty,
|
||||
pw.real_qty
|
||||
pw.real_qty,
|
||||
pw.point_name
|
||||
FROM
|
||||
`pdm_bd_workorder` pw
|
||||
LEFT JOIN md_base_material mm ON mm.material_id = pw.material_id
|
||||
@@ -95,12 +96,13 @@
|
||||
m.material_name,
|
||||
v.material_qty
|
||||
FROM
|
||||
sch_base_point p,
|
||||
sch_base_vehiclematerialgroup v,
|
||||
md_base_material m
|
||||
sch_base_point p
|
||||
LEFT JOIN sch_base_vehiclematerialgroup v ON p.vehicle_code = v.vehicle_code
|
||||
LEFT JOIN md_base_material m ON m.material_id = v.material_id
|
||||
WHERE
|
||||
p.region_code = 'GH'
|
||||
AND p.vehicle_code = v.vehicle_code
|
||||
AND p.vehicle_code IS NOT NULL
|
||||
AND p.vehicle_code <![CDATA[<>]]> ""
|
||||
</select>
|
||||
|
||||
<update id="changePointQty">
|
||||
|
||||
@@ -5,7 +5,7 @@ import lombok.Data;
|
||||
@Data
|
||||
public class GhsPointVo {
|
||||
private String point_code;
|
||||
private String vehicle_name;
|
||||
private String material_name;
|
||||
private String group_id;
|
||||
private String material_qty;
|
||||
}
|
||||
|
||||
@@ -17,4 +17,5 @@ public class ManualWorkOrderVo {
|
||||
private String create_name;
|
||||
private String plan_qty;
|
||||
private String real_qty;
|
||||
private String point_name;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ spring:
|
||||
druid:
|
||||
db-type: com.alibaba.druid.pool.DruidDataSource
|
||||
driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy
|
||||
url: jdbc:log4jdbc:mysql://${DB_HOST:127.0.0.1}:${DB_PORT:3306}/${DB_NAME:tn_lms}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true
|
||||
url: jdbc:log4jdbc:mysql://${DB_HOST:127.0.0.1}:${DB_PORT:3306}/${DB_NAME:lms}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true
|
||||
# url: jdbc:log4jdbc:mysql://${DB_HOST:47.111.78.178}:${DB_PORT:3306}/${DB_NAME:stand_lms}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true
|
||||
username: ${DB_USER:root}
|
||||
password: ${DB_PWD:123456}
|
||||
@@ -55,6 +55,7 @@ spring:
|
||||
redis:
|
||||
#数据库索引
|
||||
database: ${REDIS_DB:2}
|
||||
# host: ${REDIS_HOST:10.44.101.112}
|
||||
host: ${REDIS_HOST:127.0.0.1}
|
||||
port: ${REDIS_PORT:6379}
|
||||
password: ${REDIS_PWD:}
|
||||
|
||||
Reference in New Issue
Block a user