李永德 1 year ago
parent
commit
16d96b500f
  1. 4
      acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/agv/ndcone/AgvNdcOneDeviceDriver.java
  2. 2
      acs/nladmin-system/src/main/java/org/nl/acs/device_driver/driver/OpcDeviceDriver.java
  3. 1
      acs/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/converor_barcode/ConveyorBarcodeDeviceDriver.java
  4. 11
      acs/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_palletizing_manipulator_site/LnshPalletizingManipulatorSiteDeviceDriver.java
  5. 6
      acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/LmsUtil.java
  6. 25
      acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/WmsToAcsServiceImpl.java
  7. 61
      acs/nladmin-system/src/main/java/org/nl/acs/opc/DeviceOpcProtocolRunable.java
  8. 1
      acs/nladmin-system/src/main/java/org/nl/acs/opc/OpcItemDto.java
  9. 44
      acs/nladmin-system/src/main/java/org/nl/modules/lucene/common/LogMessageConstant.java
  10. 123
      acs/nladmin-system/src/main/java/org/nl/modules/lucene/common/LuceneAppender.java
  11. 79
      acs/nladmin-system/src/main/java/org/nl/modules/lucene/common/LuceneIndexWriter.java
  12. 3
      acs/nladmin-system/src/main/java/org/nl/modules/lucene/common/Searcher.java
  13. 81
      acs/nladmin-system/src/main/java/org/nl/modules/lucene/service/impl/LuceneExecuteLogServiceImpl.java
  14. 6
      acs/nladmin-system/src/main/resources/config/application-dev.yml
  15. 9
      acs/nladmin-system/src/main/resources/config/application-prod.yml
  16. 4
      acs/nladmin-system/src/main/resources/config/application.yml
  17. 9
      acs/nladmin-system/src/main/resources/log/Lucene.xml
  18. 13
      acs/nladmin-system/src/main/resources/logback-spring.xml
  19. 2
      lms/nladmin-system/nlsso-server/src/main/resources/logback-spring.xml
  20. 2
      lms/nladmin-ui/src/views/system/notice/NoticeIconReader.vue

4
acs/nladmin-system/src/main/java/org/nl/acs/device_driver/basedriver/agv/ndcone/AgvNdcOneDeviceDriver.java

@ -333,6 +333,7 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic
agv_message = conveyorPressStationDeviceDriver.getDevice_code() + message;
logService.deviceExecuteLog(device_code, "", "", message);
log.info("{},{}", device_code,message);
log.info("模式为{} 光电信号{} 取放信号{}",conveyorPressStationDeviceDriver.getMode(),conveyorPressStationDeviceDriver.getMove(),conveyorPressStationDeviceDriver.getIo_action());
lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, message));
}
}
@ -585,6 +586,7 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic
agv_message = conveyorPressStationDeviceDriver.getDevice_code() + message;
logService.deviceExecuteLog(device_code, "", "", message);
log.info("{},{}", device_code,message);
log.info("模式为{} 光电信号{} 取放信号{}",conveyorPressStationDeviceDriver.getMode(),conveyorPressStationDeviceDriver.getMove(),conveyorPressStationDeviceDriver.getIo_action());
lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, message));
}
}
@ -857,6 +859,7 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic
agv_message = conveyorPressStationDeviceDriver.getDevice_code() + message;
logService.deviceExecuteLog(device_code, "", "", message);
log.info("{},{}", device_code,message);
log.info("模式为{} 光电信号{} 取放信号{}",conveyorPressStationDeviceDriver.getMode(),conveyorPressStationDeviceDriver.getMove(),conveyorPressStationDeviceDriver.getIo_action());
lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, message));
}
}
@ -1114,6 +1117,7 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic
agv_message = conveyorPressStationDeviceDriver.getDevice_code() + message;
logService.deviceExecuteLog(device_code, "", "", message);
log.info("{},{}", device_code,message);
log.info("模式为{} 光电信号{} 取放信号{}",conveyorPressStationDeviceDriver.getMode(),conveyorPressStationDeviceDriver.getMove(),conveyorPressStationDeviceDriver.getIo_action());
lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, message));
}
}

2
acs/nladmin-system/src/main/java/org/nl/acs/device_driver/driver/OpcDeviceDriver.java

@ -24,7 +24,7 @@ public interface OpcDeviceDriver extends DeviceDriver {
//设备扩展表【acs_device_extra】
WQLObject extraTab = WQLObject.getWQLObject("acs_device_extra");
JSONArray arr = extraTab.query("filed_type='02' and device_id = '" + this.getDevice().getDevice_id() + "'").getResultJSONArray(0);
JSONArray arr = extraTab.query(" (filed_type='02' or filed_type='03' )and device_id = '" + this.getDevice().getDevice_id() + "'").getResultJSONArray(0);
for (int i = 0; i < arr.size(); i++) {
JSONObject json = arr.getJSONObject(i);
OpcItemDto dto = new OpcItemDto();

1
acs/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/converor_barcode/ConveyorBarcodeDeviceDriver.java

@ -458,6 +458,7 @@ public class ConveyorBarcodeDeviceDriver extends AbstractOpcDeviceDriver impleme
jo.put("isOnline", isonline);
jo.put("hasGoods", hasGoods);
jo.put("message", message);
jo.put("requireSucess",requireSucess);
return jo;
}

11
acs/nladmin-system/src/main/java/org/nl/acs/device_driver/lnsh/lnsh_palletizing_manipulator_site/LnshPalletizingManipulatorSiteDeviceDriver.java

@ -37,6 +37,7 @@ import org.nl.acs.opc.DeviceAppService;
import org.nl.acs.order.service.ProduceshiftorderService;
import org.nl.acs.route.service.RouteLineService;
import org.nl.acs.task.service.TaskService;
import org.nl.modules.lucene.enums.LogTypeEnum;
import org.nl.modules.lucene.service.LuceneExecuteLogService;
import org.nl.modules.lucene.service.dto.LuceneLogDto;
import org.nl.modules.wql.util.SpringContextHolder;
@ -898,8 +899,15 @@ public class LnshPalletizingManipulatorSiteDeviceDriver extends AbstractOpcDevic
ApplyTaskResponse resp = JSON.toJavaObject(JSONObject.parseObject(acsToWmsService.applyTask(request)),ApplyTaskResponse.class);
message = RequestMethodEnum.getName("apply_take_full_vehicle") + "apply_take_full_vehicle 接口请求LMS...";
lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, message + "参数:" + JSON.toJSONString(request)));
LuceneLogDto dto = new LuceneLogDto();
dto.setDevice_code(this.device_code);
dto.setLogType(LogTypeEnum.DEVICE_LOG.getDesc());
dto.setRemark(JSON.toJSONString(request));
lucene.deviceExecuteLog(dto);
// lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, message + "参数:" + JSON.toJSONString(request)));
// log.info("{}",JSON.toJSONString(dto));
// log.info("{}",JSON.toJSONString(new LuceneLogDto(this.device_code, message + "参数:" + JSON.toJSONString(request))));
if (resp.getCode() == 200) {
this.writing(200);
this.setRequireSucess(true);
@ -1200,7 +1208,6 @@ public class LnshPalletizingManipulatorSiteDeviceDriver extends AbstractOpcDevic
ReadUtil.write(itemMap, server);
ReadUtil.write(itemMap, server);
server.disconnect();
logServer.deviceExecuteLog(this.device_code, "", "", "to_command 写入 " + command);
lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, "to_command 写入 " + command));
}

6
acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/LmsUtil.java

@ -35,19 +35,19 @@ public class LmsUtil {
}
String liKu_wcs_url = paramService.findByCode("wmsurl").getValue();
try {
log.info("请求LMS参数:{}", JSON.toJSONString(requestParam));
// log.info("请求LMS参数:{}", JSON.toJSONString(requestParam));
String body = HttpRequest
.post(liKu_wcs_url + api).setConnectionTimeout(3000)
.body(JSON.toJSONString(requestParam))
.execute()
.body();
log.info("请求LMS参数返回参数:{}", body);
// log.info("请求LMS参数返回参数:{}", body);
return body;
} catch (Exception e) {
JSONObject result = new JSONObject();
result.put("code", "500");
result.put("message", e.getMessage());
log.info("请求LMS异常返回参数:{}", String.valueOf(result));
// log.info("请求LMS异常返回参数:{}", String.valueOf(result));
return String.valueOf(result);
}
}

25
acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/WmsToAcsServiceImpl.java

@ -276,14 +276,13 @@ public class WmsToAcsServiceImpl implements WmsToAcsService {
resp.setMessage("请求成功");
log.info("createFromWms - 返回参数 {}", JSON.toJSON(resp));
// LuceneLogDto logDto = LuceneLogDto.builder()
// .device_code("LMSTOACS")
// .requestparam(JSON.toJSON(resp).toString())
// .responseparam(JSON.toJSON(resp).toString())
// .status_code(String.valueOf(resp.getCode()))
// .method(tasks.getRequest_medthod_code())
// .build();
// lucene.interfaceExecuteLog(logDto);
LuceneLogDto logDto = LuceneLogDto.builder()
.requestparam(JSON.toJSON(resp).toString())
.responseparam(JSON.toJSON(resp).toString())
.status_code(String.valueOf(resp.getCode()))
.method(tasks.getRequest_medthod_code())
.build();
lucene.interfaceExecuteLog(logDto);
return (JSONObject) JSON.toJSON(resp);
} finally {
MDC.remove(log_file_type);
@ -550,6 +549,7 @@ public class WmsToAcsServiceImpl implements WmsToAcsService {
lnshSplitManipulatorDeviceDriver.writing(100);
is_flag = true;
}
//下发成功后,写入工单信息表记录
// ProduceshiftorderDto dto = new ProduceshiftorderDto();
@ -578,9 +578,14 @@ public class WmsToAcsServiceImpl implements WmsToAcsService {
resp.setRequestNo(request_no);
resp.setResponseDate(AgvUtil.getDate());
resp.setMessage("请求成功");
log.info("createOrder - 返回参数 {}", JSON.toJSON(resp));
LuceneLogDto logDto = LuceneLogDto.builder()
.requestparam(JSON.toJSON(resp).toString())
.responseparam(JSON.toJSON(resp).toString())
.status_code(String.valueOf(resp.getCode()))
.method(orders.getRequest_medthod_code())
.build();
lucene.interfaceExecuteLog(logDto);
return (JSONObject) JSON.toJSON(resp);
} finally {
MDC.remove(log_file_type);
}

61
acs/nladmin-system/src/main/java/org/nl/acs/opc/DeviceOpcProtocolRunable.java

@ -3,10 +3,12 @@ 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.udw.UnifiedDataAccessor;
import org.nl.acs.udw.UnifiedDataAccessorFactory;
import org.nl.acs.udw.UnifiedDataAppService;
import org.nl.modules.lucene.enums.LogTypeEnum;
import org.nl.modules.lucene.service.LuceneExecuteLogService;
import org.nl.modules.lucene.service.dto.LuceneLogDto;
import org.nl.modules.wql.util.SpringContextHolder;
@ -118,7 +120,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) {
@ -130,7 +132,7 @@ 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) {
@ -152,18 +154,18 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC
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;
@ -186,7 +188,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());
// log.warn("opc 值不健康 item: {}, 状态: {}", itemId, itemState.getQuality());
}
if (!UnifiedDataAppService.isEquals(value, his)) {
@ -218,29 +220,28 @@ 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 {
@ -351,7 +352,7 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC
this.server = null;
}
log.warn("opc server {} {}", this.getOpcGroupID(), connected ? "connected" : "disconnected");
// log.warn("opc server {} {}", this.getOpcGroupID(), connected ? "connected" : "disconnected");
}
private String getOpcGroupID() {
@ -381,7 +382,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())) {
@ -397,6 +398,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();
@ -407,24 +410,22 @@ public class DeviceOpcProtocolRunable implements Runnable, DataCallback, ServerC
Object obj = accessor_value.getValue(relate);
sb.append("key:" + relate + "value:" + obj + ";");
}
log.info("设备:{}信号{}变更从{}->{};信号快照:{}", new Object[]{itemDto.getDevice_code(), itemId, his, value, sb});
// 存在上次点位值为null情况 则不记录日志
if (!itemDto.getItem_code().endsWith("heartbeat") && !itemDto.getItem_code().endsWith("time")) {
if((ObjectUtil.equal(his,"null") || ObjectUtil.isEmpty(his)) || (ObjectUtil.equal(value,"null") || ObjectUtil.isEmpty(value)) ){
//lucene.deviceExecuteLog(new LuceneLogDto(itemDto.getOpc_server_code(), itemDto.getOpc_plc_code(), itemDto.getDevice_code(), itemDto.getItem_code().substring(itemDto.getItem_code().lastIndexOf(".") + 1), String.valueOf(his), String.valueOf(value)));
} else {
lucene.deviceExecuteLog(new LuceneLogDto(itemDto.getOpc_server_code(), itemDto.getOpc_plc_code(), itemDto.getDevice_code(), itemDto.getItem_code().substring(itemDto.getItem_code().lastIndexOf(".") + 1), String.valueOf(his), String.valueOf(value)));
}
// 存在上次点位值为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.info("设备:{}信号{}变更从{}->{};信号快照:{}", 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")) {
if((ObjectUtil.equal(his,"null") || ObjectUtil.isEmpty(his)) || (ObjectUtil.equal(value,"null") || ObjectUtil.isEmpty(value)) ){
//lucene.deviceExecuteLog(new LuceneLogDto(itemDto.getOpc_server_code(), itemDto.getOpc_plc_code(), itemDto.getDevice_code(), itemDto.getItem_code().substring(itemDto.getItem_code().lastIndexOf(".") + 1), String.valueOf(his), String.valueOf(value)));
} else {
lucene.deviceExecuteLog(new LuceneLogDto(itemDto.getOpc_server_code(), itemDto.getOpc_plc_code(), itemDto.getDevice_code(), itemDto.getItem_code().substring(itemDto.getItem_code().lastIndexOf(".") + 1), String.valueOf(his), String.valueOf(value)));
}
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));
}
}
}

1
acs/nladmin-system/src/main/java/org/nl/acs/opc/OpcItemDto.java

@ -14,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();

44
acs/nladmin-system/src/main/java/org/nl/modules/lucene/common/LogMessageConstant.java

@ -0,0 +1,44 @@
package org.nl.modules.lucene.common;
/**
* @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";
}

123
acs/nladmin-system/src/main/java/org/nl/modules/lucene/common/LuceneAppender.java

@ -0,0 +1,123 @@
package org.nl.modules.lucene.common;
/**
* @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.*;
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.acs.opc.OpcItemDto;
import org.nl.modules.lucene.enums.LogTypeEnum;
import org.nl.modules.lucene.service.LuceneExecuteLogService;
import org.nl.modules.lucene.service.dto.LuceneLogDto;
import org.nl.modules.wql.util.SpringContextHolder;
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 {
LuceneLogDto luceneLogDto = JSONObject.parseObject(message, LuceneLogDto.class);
// 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());
//IndexWriter indexWriter = LuceneIndexWriter.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));
document.add(new NumericDocValuesField("logTime",System.currentTimeMillis()));//排序
//记录索引结束时间
long endTime = System.currentTimeMillis();
// log.info("建立索引共耗时{}毫秒", endTime - startTime);
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();
}
}
}

79
acs/nladmin-system/src/main/java/org/nl/modules/lucene/common/LuceneIndexWriter.java

@ -16,45 +16,45 @@ import java.text.SimpleDateFormat;
import java.util.Date;
public class LuceneIndexWriter {
private static IndexWriter indexWriter;
static {
try {
Directory directory = FSDirectory.open(new File(UrlConfig.luceneUrl).toPath());
IndexWriterConfig config = new IndexWriterConfig(new IKAnalyzer());
indexWriter = new IndexWriter(directory, config);
} catch (Exception e) {
e.printStackTrace();
}
/**当当前线程结束时,自动关闭IndexWriter,使用Runtime对象*/
Runtime.getRuntime().addShutdownHook(new Thread(){
@Override
public void run() {
try {
closeIndexWriter();
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**在线程结束时,自动关闭IndexWriter*/
public static IndexWriter getIndexWriter() {
return indexWriter;
}
/**关闭IndexWriter
* @throws IOException
* @throws CorruptIndexException */
public static void closeIndexWriter() throws Exception {
if(indexWriter != null) {
indexWriter.close();
}
}
public static void main(String[] args) throws IOException {
indexWriter.deleteAll();
}
// private static IndexWriter indexWriter;
//
// static {
// try {
// Directory directory = FSDirectory.open(new File(UrlConfig.luceneUrl).toPath());
// IndexWriterConfig config = new IndexWriterConfig(new IKAnalyzer());
// indexWriter = new IndexWriter(directory, config);
// } catch (Exception e) {
// e.printStackTrace();
// }
// /**当当前线程结束时,自动关闭IndexWriter,使用Runtime对象*/
// Runtime.getRuntime().addShutdownHook(new Thread(){
// @Override
// public void run() {
// try {
// closeIndexWriter();
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
// });
// }
// /**在线程结束时,自动关闭IndexWriter*/
// public static IndexWriter getIndexWriter() {
// return indexWriter;
// }
// /**关闭IndexWriter
// * @throws IOException
// * @throws CorruptIndexException */
// public static void closeIndexWriter() throws Exception {
// if(indexWriter != null) {
// indexWriter.close();
// }
// }
//
// public static void main(String[] args) throws IOException {
// indexWriter.deleteAll();
// }
//
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);
@ -62,5 +62,4 @@ public class LuceneIndexWriter {
return timeString;
}
}

3
acs/nladmin-system/src/main/java/org/nl/modules/lucene/common/Searcher.java

@ -36,6 +36,7 @@ public class Searcher {
//构建IndexSearcher
IndexSearcher searcher = new IndexSearcher(reader);
//标准分词器,会自动去掉空格啊,is a the等单词
Analyzer analyzer = new IKAnalyzer(true);
// Analyzer analyzer = new StandardAnalyzer();
// Analyzer analyzer = new IKAnalyzer(false);
//查询解析器
@ -49,7 +50,7 @@ public class Searcher {
int start = pageNum * pageSize;// 当前页的起始条数
int end = start + pageSize;// 当前页的结束条数(不能包含)
// 创建排序对象,需要排序字段SortField,参数:字段的名称、字段的类型、是否反转如果是false,升序。true降序
Sort sort = new Sort(new SortField("logTime", SortField.Type.DOC,true));
Sort sort = new Sort(new SortField("logTime", SortField.Type.LONG,true));
TopDocs docs = null;
BooleanQuery.Builder booleanQueryBuilder = new BooleanQuery.Builder();

81
acs/nladmin-system/src/main/java/org/nl/modules/lucene/service/impl/LuceneExecuteLogServiceImpl.java

@ -3,6 +3,7 @@ package org.nl.modules.lucene.service.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;
@ -35,57 +36,57 @@ public class LuceneExecuteLogServiceImpl implements LuceneExecuteLogService {
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) {
luceneLogDto.setLogType(LogTypeEnum.INTERFACE_LOG.getDesc());
addIndex(luceneLogDto);
// addIndex(luceneLogDto);
log.info("{}", JSON.toJSONString(luceneLogDto));
}
private void addIndex(LuceneLogDto luceneLogDto) {
IndexWriter indexWriter = LuceneIndexWriter.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();
log.info("建立索引共耗时{}毫秒", endTime - startTime);
indexWriter.commit();
MDC.put("DEVICECODE", luceneLogDto.getDevice_code());
} catch (Exception e) {
log.error(e.getMessage(), e);
}
// IndexWriter indexWriter = LuceneIndexWriter.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();
// log.info("建立索引共耗时{}毫秒", endTime - startTime);
// indexWriter.commit();
// MDC.put("DEVICECODE", luceneLogDto.getDevice_code());
// } catch (Exception e) {
// log.error(e.getMessage(), e);
// }
}
@Override

6
acs/nladmin-system/src/main/resources/config/application-dev.yml

@ -6,8 +6,8 @@ spring:
druid:
db-type: com.alibaba.druid.pool.DruidDataSource
driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy
url: jdbc:log4jdbc:mysql://${DB_HOST:10.93.41.198}:${DB_PORT:3306}/${DB_NAME:rl_mg_acs}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true
# url: jdbc:log4jdbc:mysql://${DB_HOST:192.168.81.252}:${DB_PORT:3306}/${DB_NAME:rl_mg_acs}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true
# url: jdbc:log4jdbc:mysql://${DB_HOST:10.93.41.198}:${DB_PORT:3306}/${DB_NAME:rl_mg_acs}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true
url: jdbc:log4jdbc:mysql://${DB_HOST:127.0.0.1}:${DB_PORT:3306}/${DB_NAME:rl_mg_acs}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true
username: ${DB_USER:root}
password: ${DB_PWD:123456}
# 初始连接数
@ -127,7 +127,7 @@ file:
avatarMaxSize: 5
logging:
file:
path: C:\log\wms
path: C:\log\ACS
config: classpath:logback-spring.xml
lucene:
index:

9
acs/nladmin-system/src/main/resources/config/application-prod.yml

@ -6,7 +6,8 @@ spring:
druid:
db-type: com.alibaba.druid.pool.DruidDataSource
driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy
url: jdbc:log4jdbc:mysql://${DB_HOST:192.168.4.210}:${DB_PORT:3306}/${DB_NAME:acs}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true
# url: jdbc:log4jdbc:mysql://${DB_HOST:10.93.41.198}:${DB_PORT:3306}/${DB_NAME:rl_mg_acs}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true
url: jdbc:log4jdbc:mysql://${DB_HOST:127.0.0.1}:${DB_PORT:3306}/${DB_NAME:rl_mg_acs}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false&useOldAliasMetadataBehavior=true
username: ${DB_USER:root}
password: ${DB_PWD:123456}
# 初始连接数
@ -52,7 +53,7 @@ spring:
multi-statement-allow: true
redis:
#数据库索引
database: ${REDIS_DB:2}
database: ${REDIS_DB:15}
host: ${REDIS_HOST:127.0.0.1}
port: ${REDIS_PORT:6379}
password: ${REDIS_PWD:}
@ -126,7 +127,7 @@ file:
avatarMaxSize: 5
logging:
file:
path: D:\log\acs
path: C:\log\ACS
config: classpath:logback-spring.xml
lucene:
index:
@ -153,5 +154,5 @@ sa-token:
token-prefix: Bearer
loki:
url: http://192.168.4.210:3100/loki/api/v1
url: http://localhost:3100/loki/api/v1
systemName: acs

4
acs/nladmin-system/src/main/resources/config/application.yml

@ -2,7 +2,7 @@ spring:
freemarker:
check-template-location: false
profiles:
active: dev
active: prod
jackson:
time-zone: GMT+8
data:
@ -44,7 +44,7 @@ rsa:
private_key: MIIBUwIBADANBgkqhkiG9w0BAQEFAASCAT0wggE5AgEAAkEA0vfvyTdGJkdbHkB8mp0f3FE0GYP3AYPaJF7jUd1M0XxFSE2ceK3k2kw20YvQ09NJKk+OMjWQl9WitG9pB6tSCQIDAQABAkA2SimBrWC2/wvauBuYqjCFwLvYiRYqZKThUS3MZlebXJiLB+Ue/gUifAAKIg1avttUZsHBHrop4qfJCwAI0+YRAiEA+W3NK/RaXtnRqmoUUkb59zsZUBLpvZgQPfj1MhyHDz0CIQDYhsAhPJ3mgS64NbUZmGWuuNKp5coY2GIj/zYDMJp6vQIgUueLFXv/eZ1ekgz2Oi67MNCk5jeTF2BurZqNLR3MSmUCIFT3Q6uHMtsB9Eha4u7hS31tj1UWE+D+ADzp59MGnoftAiBeHT7gDMuqeJHPL4b+kC+gzV4FGTfhR9q3tTbklZkD2A==
logging:
file:
path: C:\log\wms
path: C:\log\ACS
config: classpath:logback-spring.xml
# sa-token白名单配置
security:

9
acs/nladmin-system/src/main/resources/log/Lucene.xml

@ -23,12 +23,19 @@
</appender>
<appender name="luceneAppender" class="org.nl.modules.lucene.common.LuceneAppender" />
<appender name="asyncLuceneAppender" class="ch.qos.logback.classic.AsyncAppender">
<appender-ref ref="luceneAppender" />
<!-- 设置队列大小,根据您的需求调整 -->
<queueSize>512</queueSize>
</appender>
<!-- <logger name="org.nl.start.Init" level="info" additivity="false">
<appender-ref ref="FILE3"/>
</logger>-->
<!-- 打印sql -->
<logger name="org.nl.modules.lucene.service.impl.LuceneExecuteLogServiceImpl" level="info" additivity="false">
<logger name="org.nl.modules.lucene.service.impl.LuceneExecuteLogServiceImpl" level="info" additivity="true">
<appender-ref ref="FILE_LUCENE"/>
<appender-ref ref="asyncLuceneAppender"/>
</logger>
</included>

13
acs/nladmin-system/src/main/resources/logback-spring.xml

@ -57,10 +57,17 @@ https://juejin.cn/post/6844903775631572999
<!--异步到文件-->
<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="luceneAppender" class="org.nl.modules.lucene.common.LuceneAppender" />
<appender name="asyncLuceneAppender" class="ch.qos.logback.classic.AsyncAppender">
<appender-ref ref="luceneAppender" />
<!-- 设置队列大小,根据您的需求调整 -->
<queueSize>512</queueSize>
</appender>
<!--添加loki-->
<appender name="lokiAppender" class="com.github.loki4j.logback.Loki4jAppender">
<batchTimeoutMs>1000</batchTimeoutMs>
@ -85,10 +92,12 @@ https://juejin.cn/post/6844903775631572999
<appender-ref ref="CONSOLE"/>
<appender-ref ref="lokiAppender"/>
<appender-ref ref="asyncFileAppender"/>
<appender-ref ref="asyncLuceneAppender"/>
</root>
<!--logmanage -->
<logger name="org.nl.acs.log.service.impl.DeviceExecuteLogServiceImpl" level="info" additivity="false">
<appender-ref ref="lokiAppender" />
<appender-ref ref="asyncLuceneAppender"/>
</logger>
<logger name="jdbc.resultsettable" level="ERROR" additivity="false">
<appender-ref ref="CONSOLE"/>
@ -137,10 +146,12 @@ https://juejin.cn/post/6844903775631572999
<root level="info">
<appender-ref ref="asyncFileAppender"/>
<appender-ref ref="lokiAppender" />
<appender-ref ref="asyncLuceneAppender"/>
</root>
<logger name="org.nl.acs.log.service.impl.DeviceExecuteLogServiceImpl" level="info" additivity="false">
<appender-ref ref="asyncFileAppender"/>
<appender-ref ref="lokiAppender" />
<appender-ref ref="asyncLuceneAppender"/>
</logger>
<logger name="jdbc.resultsettable" level="ERROR" additivity="false">
<appender-ref ref="asyncFileAppender"/>

2
lms/nladmin-system/nlsso-server/src/main/resources/logback-spring.xml

@ -23,7 +23,7 @@ https://juejin.cn/post/6844903775631572999
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${log.pattern}</pattern>
<charset>${log.charset}</charset>
<!-- <charset>${log.charset}</charset>-->
</encoder>
</appender>

2
lms/nladmin-ui/src/views/system/notice/NoticeIconReader.vue

@ -4,7 +4,7 @@
:visible.sync="visible"
:modal-append-to-body="false"
:append-to-body="true"
width="40%">
width="60%">
<div style="margin-top: 5px">
<el-descriptions class="margin-top" :column="3" border>
<el-descriptions-item>

Loading…
Cancel
Save