Browse Source

rev:删除loki、添加lucene

master
gengby 11 months ago
parent
commit
02ad40b2ca
  1. 2
      acs/nladmin-system/.gitignore
  2. 45
      acs/nladmin-system/pom.xml
  3. 2
      acs/nladmin-system/src/main/java/org/nl/acs/device_driver/RouteUtil.java
  4. 45
      acs/nladmin-system/src/main/java/org/nl/acs/device_driver/maGang/MaGangConveyorDeviceDriver.java
  5. 35
      acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/AgvToAcsServiceImpl.java
  6. 40
      acs/nladmin-system/src/main/java/org/nl/modules/loki/rest/LokiController.java
  7. 25
      acs/nladmin-system/src/main/java/org/nl/modules/loki/service/LokiService.java
  8. 113
      acs/nladmin-system/src/main/java/org/nl/modules/loki/service/impl/LokiServiceImpl.java
  9. 43
      acs/nladmin-system/src/main/java/org/nl/modules/lucene/config/AsyncLuceneAppender.java
  10. 80
      acs/nladmin-system/src/main/java/org/nl/modules/lucene/config/LogMessageConstant.java
  11. 130
      acs/nladmin-system/src/main/java/org/nl/modules/lucene/config/LuceneAppender.java
  12. 23
      acs/nladmin-system/src/main/java/org/nl/modules/lucene/config/LuceneProperties.java
  13. 38
      acs/nladmin-system/src/main/java/org/nl/modules/lucene/config/LucenePropertyAndEncoder.java
  14. 44
      acs/nladmin-system/src/main/java/org/nl/modules/lucene/config/Property.java
  15. 15
      acs/nladmin-system/src/main/java/org/nl/modules/lucene/enums/LogTypeEnum.java
  16. 38
      acs/nladmin-system/src/main/java/org/nl/modules/lucene/rest/LuceneController.java
  17. 39
      acs/nladmin-system/src/main/java/org/nl/modules/lucene/service/LuceneExecuteLogService.java
  18. 18
      acs/nladmin-system/src/main/java/org/nl/modules/lucene/service/LuceneService.java
  19. 117
      acs/nladmin-system/src/main/java/org/nl/modules/lucene/service/dto/LuceneLogDto.java
  20. 51
      acs/nladmin-system/src/main/java/org/nl/modules/lucene/service/impl/LuceneExecuteLogServiceImpl.java
  21. 127
      acs/nladmin-system/src/main/java/org/nl/modules/lucene/service/impl/LuceneServiceImpl.java
  22. 6
      acs/nladmin-system/src/main/resources/config/application-prod.yml
  23. 8
      acs/nladmin-system/src/main/resources/config/application.yml
  24. 168
      acs/nladmin-system/src/main/resources/logback-spring.xml
  25. 18
      acs/nladmin-ui/src/views/monitor/lucene/api/lucene.js
  26. 39
      acs/nladmin-ui/src/views/monitor/lucene/index.vue
  27. 43
      acs/nladmin-ui/src/views/monitor/lucene/search.vue

2
acs/nladmin-system/.gitignore

@ -6,3 +6,5 @@
*/*.iml
/.gradle/
/target/*
/C:*
/D:*

45
acs/nladmin-system/pom.xml

@ -30,6 +30,7 @@
<!-- oshi监控需要指定jna版本, 问题详见 https://github.com/oshi/oshi/issues/1040 -->
<jna.version>5.9.0</jna.version>
<configuration.version>1.9</configuration.version>
<lucene.version>8.2.0</lucene.version>
</properties>
<dependencies>
@ -179,11 +180,11 @@
</dependency>
<!--loki-->
<!-- https://loki4j.github.io/loki-logback-appender/#quick-start -->
<dependency>
<!-- <dependency>
<groupId>com.github.loki4j</groupId>
<artifactId>loki-logback-appender-jdk8</artifactId>
<version>1.3.2</version>
</dependency>
</dependency>-->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
@ -295,6 +296,46 @@
<version>1.5.21</version>
</dependency>
<!-- Lucence核心包 -->
<dependency>
<groupId>com.yomahub</groupId>
<artifactId>tlog-all-spring-boot-starter</artifactId>
<version>1.5.0</version>
</dependency>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-core</artifactId>
<version>${lucene.version}</version>
</dependency>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-highlighter</artifactId>
<version>${lucene.version}</version>
</dependency>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-analyzers-common</artifactId>
<version>${lucene.version}</version>
</dependency>
<dependency>
<groupId>com.github.magese</groupId>
<artifactId>ik-analyzer</artifactId>
<version>${lucene.version}</version>
</dependency>
<!--支持中文分词 -->
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-analyzers-smartcn</artifactId>
<version>${lucene.version}</version>
</dependency>
<!-- Lucene查询解析包 -->
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-queryparser</artifactId>
<version>${lucene.version}</version>
</dependency>
<!--Mysql依赖包-->
<dependency>
<groupId>mysql</groupId>

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

@ -76,7 +76,7 @@ public class RouteUtil {
}
public static String getDeviceCode(String address) {
String device_code = "";
String device_code = address;
if (address.contains("INGET") || address.contains("INPUT")) {
device_code = address.substring(0, address.length() - 5);
} else if (address.contains("OUTGET") || address.contains("OUTPUT")) {

45
acs/nladmin-system/src/main/java/org/nl/acs/device_driver/maGang/MaGangConveyorDeviceDriver.java

@ -18,7 +18,6 @@ import org.nl.acs.device_driver.driver.ExecutableDeviceDriver;
import org.nl.acs.ext.wms.service.AcsToWmsService;
import org.nl.acs.ext.wms.service.impl.AcsToWmsServiceImpl;
import org.nl.acs.instruction.service.InstructionService;
import org.nl.acs.instruction.service.dto.Instruction;
import org.nl.acs.log.service.DeviceExecuteLogService;
import org.nl.acs.monitor.DeviceStageMonitor;
import org.nl.acs.opc.Device;
@ -26,6 +25,8 @@ import org.nl.acs.opc.DeviceAppService;
import org.nl.acs.route.service.RouteLineService;
import org.nl.acs.task.service.TaskService;
import org.nl.acs.task.service.dto.TaskDto;
import org.nl.modules.lucene.service.LuceneExecuteLogService;
import org.nl.modules.lucene.service.dto.LuceneLogDto;
import org.nl.modules.system.service.ParamService;
import org.nl.modules.system.util.CodeUtil;
import org.nl.modules.wql.util.SpringContextHolder;
@ -61,6 +62,8 @@ public class MaGangConveyorDeviceDriver extends AbstractOpcDeviceDriver implemen
DeviceExecuteLogService logServer = SpringContextHolder.getBean(DeviceExecuteLogService.class);
@Autowired
AgvService agvService = SpringContextHolder.getBean(AgvService.class);
@Autowired
LuceneExecuteLogService lucene = SpringContextHolder.getBean(LuceneExecuteLogService.class);
private Date instruction_require_time = new Date();
private Date instruction_finished_time = new Date();
@ -129,24 +132,11 @@ public class MaGangConveyorDeviceDriver extends AbstractOpcDeviceDriver implemen
}
}
if (mode != last_mode) {
if (mode == 3) {
if (mode == 3 || mode == 4) {
this.setRequireSucess(false);
}
logServer.deviceItemValue(this.device_code, "mode", String.valueOf(mode));
logServer.deviceExecuteLog(this.device_code, "", "", "信号mode:" + last_mode + "->" + mode);
}
if (move != last_move) {
logServer.deviceItemValue(this.device_code, "move", String.valueOf(move));
logServer.deviceExecuteLog(this.device_code, "", "", "信号move:" + last_move + "->" + move);
}
if (action != last_action) {
logServer.deviceItemValue(this.device_code, "action", String.valueOf(action));
logServer.deviceExecuteLog(this.device_code, "", "", "信号action:" + last_action + "->" + action);
}
if (error != last_error) {
logServer.deviceItemValue(this.device_code, "error", String.valueOf(error));
logServer.deviceExecuteLog(this.device_code, "", "", "信号error:" + last_error + "->" + error);
}
if (!this.itemProtocol.getIsonline()) {
this.setIsonline(false);
this.setIserror(true);
@ -166,8 +156,6 @@ public class MaGangConveyorDeviceDriver extends AbstractOpcDeviceDriver implemen
this.setIsonline(true);
this.setIserror(false);
message = "";
Instruction instruction = null;
List toInstructions;
//1#2#5#重机卷组申请任务
if (mode == 3 && !requireSucess) {
instruction_require();
@ -241,12 +229,11 @@ public class MaGangConveyorDeviceDriver extends AbstractOpcDeviceDriver implemen
taskDto.setCreate_time(now);
try {
taskserver.create(taskDto);
} catch (Exception e) {
logServer.deviceExecuteLog(this.device_code, "", "", this.device_code + ":创建任务失败," + String.valueOf(e.getMessage()));
}
logServer.deviceExecuteLog(this.device_code, "", "", this.device_code + ":创建任务成功");
this.writing(1);
this.setRequireSucess(true);
} catch (Exception e) {
lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, "任务创建失败,原因:" + e.getMessage()));
}
return true;
}
}
@ -305,12 +292,11 @@ public class MaGangConveyorDeviceDriver extends AbstractOpcDeviceDriver implemen
taskDto.setCreate_time(now);
try {
taskserver.create(taskDto);
} catch (Exception e) {
logServer.deviceExecuteLog(this.device_code, "", "", this.device_code + ":创建任务失败," + String.valueOf(e.getMessage()));
}
logServer.deviceExecuteLog(this.device_code, "", "", this.device_code + ":创建任务成功");
this.writing(1);
this.setRequireSucess(true);
} catch (Exception e) {
lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, "任务创建失败,原因:" + e.getMessage()));
}
return true;
}
}
@ -343,7 +329,7 @@ public class MaGangConveyorDeviceDriver extends AbstractOpcDeviceDriver implemen
Map<String, Object> itemMap = new HashMap<String, Object>();
itemMap.put(to_command, command);
ReadUtil.write(itemMap, server);
log.info("设备号{},kep点位名称{},下发信号{}", this.getDevice().getDevice_code(), to_command, String.valueOf(command));
lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, "kep点位名称:" + to_command + "下发信号值:" + command));
}
public void writing(int type, int command) {
@ -354,10 +340,9 @@ public class MaGangConveyorDeviceDriver extends AbstractOpcDeviceDriver implemen
Map<String, Object> itemMap = new HashMap<String, Object>();
if (type == 1) {
itemMap.put(to_command, command);
log.info("设备:" + device_code + ",下发PLC信号" + to_command + ",value:" + command);
}
ReadUtil.write(itemMap, server);
log.info("设备号{},kep点位名称{},下发信号{}", this.getDevice().getDevice_code(), to_command, String.valueOf(command));
lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, "kep点位名称:" + to_command + "下发信号值:" + command));
}
public void writing(String type, String value) {
@ -368,7 +353,7 @@ public class MaGangConveyorDeviceDriver extends AbstractOpcDeviceDriver implemen
Map<String, Object> itemMap = new HashMap<String, Object>();
itemMap.put(param, Integer.parseInt(value));
ReadUtil.write(itemMap, server);
log.info("设备号{},kep点位名称{},下发信号{}", this.getDevice().getDevice_code(), param, value);
lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, "kep点位名称:" + param + "下发信号值:" + value));
}
@Override

35
acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/AgvToAcsServiceImpl.java

@ -12,6 +12,9 @@ import org.nl.acs.instruction.service.dto.Instruction;
import org.nl.acs.opc.Device;
import org.nl.acs.opc.DeviceAppService;
import org.nl.modules.common.exception.BadRequestException;
import org.nl.modules.lucene.service.LuceneExecuteLogService;
import org.nl.modules.lucene.service.dto.LuceneLogDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
@ -22,8 +25,12 @@ import java.util.Map;
@Slf4j
public class AgvToAcsServiceImpl implements AgvToAcsService {
private final DeviceAppService deviceAppService;
private final InstructionService instructionService;
@Autowired
private DeviceAppService deviceAppService;
@Autowired
private InstructionService instructionService;
@Autowired
private LuceneExecuteLogService lucene;
@Override
public Map<String, Object> waitpointRequest(JSONObject param) {
@ -31,16 +38,16 @@ public class AgvToAcsServiceImpl implements AgvToAcsService {
String inst_code = param.getString("task_code");
//站点
String address = param.getString("address");
log.info("请求等待点,请求路径:{},请求参数:{},指令号:{},站点:{}", "api/agv/waitpointRequest", String.valueOf(param), inst_code, address);
String deviceCode = RouteUtil.getDeviceCode(address);
Instruction instructionDto = instructionService.findByCodeFromCache(inst_code);
if (ObjectUtil.isEmpty(instructionDto)) {
log.error("请求等待点,请求路径:{},请求参数:{},指令号:{},站点:{},请求失败:{}", "api/agv/waitpointRequest", String.valueOf(param), inst_code, address, "指令任务号不存在或指令已取消或者指令已完成!");
lucene.interfaceExecuteLog(new LuceneLogDto(deviceCode, "", inst_code, "waitpointRequest", "AGV请求等待点失败...指令任务号不存在或指令已取消或者指令已完成!"));
throw new BadRequestException("指令任务号不存在或指令已取消或者指令已完成!");
}
lucene.interfaceExecuteLog(new LuceneLogDto(deviceCode, instructionDto.getTask_code(), inst_code, "waitpointRequest", "AGV请求等待点..."));
Device device = deviceAppService.findDeviceByCode(deviceCode);
if (ObjectUtil.isEmpty(device)) {
log.error("请求等待点,请求路径:{},请求参数:{},指令号:{},站点:{},请求失败:{}", "api/agv/waitpointRequest", String.valueOf(param), inst_code, address, "设备号:'" + deviceCode + "'有误,请检查!");
lucene.interfaceExecuteLog(new LuceneLogDto(deviceCode, "", inst_code, "waitpointRequest", "AGV请求等待点失败...设备号有误,请求设备未配置!"));
throw new BadRequestException("设备号:'" + deviceCode + "'有误,请检查!");
}
MaGangConveyorDeviceDriver maGangConveyorDeviceDriver = (MaGangConveyorDeviceDriver) device.getDeviceDriver();
@ -54,11 +61,11 @@ public class AgvToAcsServiceImpl implements AgvToAcsService {
//判断是否满足取货条件
if (maGangConveyorDeviceDriver.getMove() == 1 && maGangConveyorDeviceDriver.getAction() == 1) {
//满足响应成功
log.info("请求等待点,请求路径:{},请求参数:{},指令号:{},站点:{},响应参数:{}", "api/agv/waitpointRequest", String.valueOf(param), inst_code, address, String.valueOf(map));
lucene.interfaceExecuteLog(new LuceneLogDto(deviceCode, "", inst_code, "waitpointRequest", "AGV请求取货点等待ACS反馈成功..."));
return map;
} else {
//不满足抛异常
log.error("请求等待点,请求路径:{},请求参数:{},指令号:{},站点:{},请求失败:{}", "api/agv/waitpointRequest", String.valueOf(param), inst_code, address, "不满足取货条件: move = 1 && action = 1");
lucene.interfaceExecuteLog(new LuceneLogDto(deviceCode, "", inst_code, "waitpointRequest", "AGV请求取货点ACS反馈失败...原因:不满足取货条件: move = 1 && action = 1"));
throw new BadRequestException("请求失败,不满足取货条件: move = 1 && action = 1");
}
}//取货完成等待
@ -67,11 +74,11 @@ public class AgvToAcsServiceImpl implements AgvToAcsService {
if (maGangConveyorDeviceDriver.getMove() == 0) {
//无货告诉设备取货完成
maGangConveyorDeviceDriver.writing("to_command", "2");
log.info("请求等待点,请求路径:{},请求参数:{},指令号:{},站点:{},响应参数:{}", "api/agv/waitpointRequest", String.valueOf(param), inst_code, address, String.valueOf(map));
lucene.interfaceExecuteLog(new LuceneLogDto(deviceCode, "", inst_code, "waitpointRequest", "AGV请求取货完成等待ACS反馈成功..."));
return map;
} else {
//有货抛异常
log.error("请求等待点,请求路径:{},请求参数:{},指令号:{},站点:{},请求失败:{}", "api/agv/waitpointRequest", String.valueOf(param), inst_code, address, "请求失败,取货完成后: move = 1!");
lucene.interfaceExecuteLog(new LuceneLogDto(deviceCode, "", inst_code, "waitpointRequest", "AGV请求取货点ACS反馈失败...原因:不满足取货完成条件: move = 0"));
throw new BadRequestException("请求失败,取货完成后: move = 1!");
}
}//放货前等待
@ -80,10 +87,10 @@ public class AgvToAcsServiceImpl implements AgvToAcsService {
maGangConveyorDeviceDriver.writing("to_command", "5");
//判断是否满足放货信号
if (maGangConveyorDeviceDriver.getMove() == 0 && maGangConveyorDeviceDriver.getAction() == 2) {
log.info("请求等待点,请求路径:{},请求参数:{},指令号:{},站点:{},响应参数:{}", "api/agv/waitpointRequest", String.valueOf(param), inst_code, address, String.valueOf(map));
lucene.interfaceExecuteLog(new LuceneLogDto(deviceCode, "", inst_code, "waitpointRequest", "AGV请求放货点等待ACS反馈成功..."));
return map;
} else {
log.error("请求等待点,请求路径:{},请求参数:{},指令号:{},站点:{},请求失败:{}", "api/agv/waitpointRequest", String.valueOf(param), inst_code, address, "放货前不满足放货条件: move = 0 && action = 2!");
lucene.interfaceExecuteLog(new LuceneLogDto(deviceCode, "", inst_code, "waitpointRequest", "AGV请求取货点ACS反馈失败...原因:不满足取货条件: move = 0 && action = 2"));
throw new BadRequestException("请求失败,放货前不满足放货条件: move = 0 && action = 2!");
}
}//放货完成等待
@ -91,14 +98,14 @@ public class AgvToAcsServiceImpl implements AgvToAcsService {
//放货完成后判断放货点是否有货
if (maGangConveyorDeviceDriver.getMove() == 1) {
maGangConveyorDeviceDriver.writing("to_command", "3");
log.info("请求等待点,请求路径:{},请求参数:{},指令号:{},站点:{},响应参数:{}", "api/agv/waitpointRequest", String.valueOf(param), inst_code, address, String.valueOf(map));
lucene.interfaceExecuteLog(new LuceneLogDto(deviceCode, "", inst_code, "waitpointRequest", "AGV请求放货完成等待ACS反馈成功..."));
return map;
} else {
log.error("请求等待点,请求路径:{},请求参数:{},指令号:{},站点:{},请求失败:{}", "api/agv/waitpointRequest", String.valueOf(param), inst_code, address, "放货完成后: move = 0 !");
lucene.interfaceExecuteLog(new LuceneLogDto(deviceCode, "", inst_code, "waitpointRequest", "AGV请求放货完成ACS反馈失败...原因:不满足取货完成条件: move = 1"));
throw new BadRequestException("请求失败,放货完成后: move = 0!");
}
}
log.error("请求等待点,请求路径:{},请求参数:{},指令号:{},站点:{},请求失败:{}", "api/agv/waitpointRequest", String.valueOf(param), inst_code, address, "请求失败,地址:'" + address + "'->有误!");
lucene.interfaceExecuteLog(new LuceneLogDto(deviceCode, "", inst_code, "waitpointRequest", "请求失败,AGV请求等待点地址:'" + address + "'->有误!"));
throw new BadRequestException("请求失败,地址:'" + address + "'->有误!");
}
}

40
acs/nladmin-system/src/main/java/org/nl/modules/loki/rest/LokiController.java

@ -1,40 +0,0 @@
package org.nl.modules.loki.rest;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nl.modules.common.annotation.RateLimiter;
import org.nl.modules.loki.service.LokiService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
/**
* @Author: lyd
* @Description: 日志监控
* @Date: 2022-08-15
*/
@RestController
@RequiredArgsConstructor
@Api(tags = "日志监控")
@RequestMapping("/api/loki")
@Slf4j
public class LokiController {
private final LokiService lokiService;
@GetMapping("/labels/values")
@ApiOperation("获取标签")
public ResponseEntity<Object> labelsValues() {
return new ResponseEntity<>(lokiService.getLabelsValues(), HttpStatus.OK);
}
@PostMapping("/logs")
@ApiOperation("获取日志")
@RateLimiter(value = 1, timeout = 300) // 限流
public ResponseEntity<Object> getLogData(@RequestBody JSONObject json) {
return new ResponseEntity<>(lokiService.getLogData(json), HttpStatus.OK);
}
}

25
acs/nladmin-system/src/main/java/org/nl/modules/loki/service/LokiService.java

@ -1,25 +0,0 @@
package org.nl.modules.loki.service;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
/**
* @Author: lyd
* @Description: 服务类
* @Date: 2022-08-15
*/
public interface LokiService {
/**
* 获取日志信息
* @param json
* @return
*/
JSONObject getLogData(JSONObject json);
/**
* 获取labels和values树
* @return
*/
JSONArray getLabelsValues();
}

113
acs/nladmin-system/src/main/java/org/nl/modules/loki/service/impl/LokiServiceImpl.java

@ -1,113 +0,0 @@
package org.nl.modules.loki.service.impl;
import cn.hutool.core.util.CharsetUtil;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.RequiredArgsConstructor;
import org.nl.modules.loki.service.LokiService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
/**
* @Author: lyd
* @Description: 实现类
* @Date: 2022-08-15
*/
@Service
@RequiredArgsConstructor
public class LokiServiceImpl implements LokiService {
@Value("${loki.url}")
private String lokiUrl;
@Value("${loki.systemName}")
private String systemName;
@Override
public JSONObject getLogData(JSONObject json) {
String logLabel = "";
String logLabelValue = "";
Long start = 0L;
Long end = 0L;
String text = "";
String limit = "100";
String direction = "backward";
if (json.get("logLabel") != null) logLabel = json.getString("logLabel");
if (json.get("logLabelValue") != null) logLabelValue = json.getString("logLabelValue");
if (json.get("text") != null) text = json.getString("text");
if (json.get("start") != null) start = json.getLong("start");
if (json.get("end") != null) end = json.getLong("end");
if (json.get("limits") != null) limit = json.getString("limits");
if (json.get("direction") != null) direction = json.getString("direction");
/**
* 组织参数
* 纳秒数
* 1660037391880000000
* 1641453208415000000
* http://localhost:3100/loki/api/v1/query_range?query={host="localhost"} |= ``&limit=1500&start=1641453208415000000&end=1660027623419419002
*/
JSONObject parse = null;
String query = lokiUrl + "/query_range?query={system=\"" + systemName + "\", " + logLabel + "=\"" + logLabelValue + "\"} |= `" + text + "`";
String result = "";
if (start==0L) {
result = HttpUtil.get(query + "&limit=" + limit + "&direction=" + direction, CharsetUtil.CHARSET_UTF_8);
} else {
result = HttpUtil.get(query + "&limit=" + limit + "&start=" + start + "&end=" + end + "&direction=" + direction, CharsetUtil.CHARSET_UTF_8);
}
try {
parse = (JSONObject) JSONObject.parse(result);
} catch (Exception e) {
// reslut的值可能为:too many outstanding requests,无法转化成Json
System.out.println("reslut:" + result);
// e.printStackTrace();
}
return parse;
}
/**
* 获取labels和values树
*
* @return
*/
@Override
public JSONArray getLabelsValues() {
/**
* [{
* label:
* value:
* children:[{
* label
* value
* }]
* }]
*/
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;
}
}

43
acs/nladmin-system/src/main/java/org/nl/modules/lucene/config/AsyncLuceneAppender.java

@ -0,0 +1,43 @@
package org.nl.modules.lucene.config;
/**
* @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);
}
}

80
acs/nladmin-system/src/main/java/org/nl/modules/lucene/config/LogMessageConstant.java

@ -0,0 +1,80 @@
package org.nl.modules.lucene.config;
/**
* @Author: lyd
* @Description: 定义lucene相关常量
* @Date: 2023/8/25
*/
public class LogMessageConstant {
/**
*
*/
public final static String SORT_NAME = "time";
/**
* 级别
*/
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 = "E:\\lucene\\index";
}

130
acs/nladmin-system/src/main/java/org/nl/modules/lucene/config/LuceneAppender.java

@ -0,0 +1,130 @@
package org.nl.modules.lucene.config;
/**
* @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 com.alibaba.ttl.TransmittableThreadLocal;
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.modules.lucene.service.dto.LuceneLogDto;
import org.springframework.beans.factory.config.YamlPropertiesFactoryBean;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.wltea.analyzer.lucene.IKAnalyzer;
import java.io.IOException;
import java.nio.file.Paths;
import java.util.List;
import java.util.Map;
import java.util.Properties;
public class LuceneAppender extends AppenderBase<ILoggingEvent> {
public static final TransmittableThreadLocal<String> traceIdTL = new TransmittableThreadLocal();
public LuceneProperties properties;
public static Directory index;
private List<LucenePropertyAndEncoder> encoders;
public static IndexWriter indexWriter;
@Override
public void start() {
super.start();
try {
init();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void init() throws IOException {
Resource resource = new ClassPathResource("config/application.yml");
YamlPropertiesFactoryBean yamlPropertiesFactoryBean = new YamlPropertiesFactoryBean();
yamlPropertiesFactoryBean.setResources(resource);
Properties properties = yamlPropertiesFactoryBean.getObject();
// 获取配置值
String luceneDir = properties.getProperty("lucene.index.path");
System.out.println("---index地址----" + luceneDir);
index = FSDirectory.open(Paths.get(luceneDir));
// 初始化 Lucene 索引
Analyzer analyzer = new IKAnalyzer();
IndexWriterConfig config = new IndexWriterConfig(analyzer);
indexWriter = new IndexWriter(index, config);
}
@Override
protected void append(ILoggingEvent event) {
String message = event.getFormattedMessage();
String[] split = message.split("@");
LuceneLogDto luceneLogDto = JSONObject.parseObject(split[1], 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("logTime",System.currentTimeMillis()));//排序
try {
indexWriter.addDocument(document);
indexWriter.commit();
} catch (IOException e) {
e.printStackTrace();
}
} catch (Exception e) {
return;
}
}
@Override
public void stop() {
super.stop();
try {
indexWriter.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public void setProperties(LuceneProperties properties) {
this.properties = properties;
}
}

23
acs/nladmin-system/src/main/java/org/nl/modules/lucene/config/LuceneProperties.java

@ -0,0 +1,23 @@
package org.nl.modules.lucene.config;
import java.util.ArrayList;
import java.util.List;
public class LuceneProperties {
private List<Property> properties;
public LuceneProperties() {
this.properties = new ArrayList<Property>();
}
public List<Property> getProperties() {
return properties;
}
public void addProperty(Property property) {
properties.add(property);
}
}

38
acs/nladmin-system/src/main/java/org/nl/modules/lucene/config/LucenePropertyAndEncoder.java

@ -0,0 +1,38 @@
package org.nl.modules.lucene.config;
import ch.qos.logback.classic.PatternLayout;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.Context;
import ch.qos.logback.core.pattern.PatternLayoutBase;
/*
* @author ZZQ
* @Date 2023/12/22 18:11
*/
public class LucenePropertyAndEncoder {
private Property property;
private PatternLayoutBase layout = new PatternLayout();
public LucenePropertyAndEncoder(Property property, Context context) {
this.property = property;
this.layout.setContext(context);
this.layout.setPattern(String.valueOf(property.getValue()));
this.layout.setPostCompileProcessor(null);
this.layout.start();
}
public String encode(ILoggingEvent event) {
return layout.doLayout(event);
}
public String getName() {
return property.getName();
}
public boolean allowEmpty() {
return property.isAllowEmpty();
}
}

44
acs/nladmin-system/src/main/java/org/nl/modules/lucene/config/Property.java

@ -0,0 +1,44 @@
package org.nl.modules.lucene.config;
/*
* @author ZZQ
* @Date 2023/12/26 15:30
*/
public class Property {
private String name;
private String value;
private boolean allowEmpty;
public Property() {
}
public Property(String name, String value, boolean allowEmpty) {
this.name = name;
this.value = value;
this.allowEmpty = allowEmpty;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public boolean isAllowEmpty() {
return allowEmpty;
}
public void setAllowEmpty(boolean allowEmpty) {
this.allowEmpty = allowEmpty;
}
}

15
acs/nladmin-system/src/main/java/org/nl/modules/lucene/enums/LogTypeEnum.java

@ -0,0 +1,15 @@
package org.nl.modules.lucene.enums;
public enum LogTypeEnum {
DEVICE_LOG("设备日志"),
INTERFACE_LOG("接口日志");
private String desc;
LogTypeEnum(String desc) {
this.desc = desc;
}
public String getDesc() {
return desc;
}
}

38
acs/nladmin-system/src/main/java/org/nl/modules/lucene/rest/LuceneController.java

@ -0,0 +1,38 @@
package org.nl.modules.lucene.rest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nl.modules.logging.annotation.Log;
import org.nl.modules.lucene.service.LuceneService;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;
@RestController
@RequiredArgsConstructor
@Api(tags = "日志检索")
@RequestMapping("/api/lucene")
@Slf4j
public class LuceneController {
private final LuceneService luceneService;
@GetMapping("/getAll")
@Log("日志检索")
@ApiOperation("日志检索")
//@PreAuthorize("@el.check('task:list')")
public ResponseEntity<Object> get(@RequestParam Map whereJson, Pageable page) {
return new ResponseEntity<>(luceneService.getAll(whereJson, page), HttpStatus.OK);
}
}

39
acs/nladmin-system/src/main/java/org/nl/modules/lucene/service/LuceneExecuteLogService.java

@ -0,0 +1,39 @@
package org.nl.modules.lucene.service;
import org.nl.modules.lucene.service.dto.LuceneLogDto;
public interface LuceneExecuteLogService {
/**
* 设备光电变化实时光电信号
*
* @param device_code 设备编号
* @param key plc信号
* @param value plc信号值
*/
void deviceItemValue(String device_code, String key, String value);
/**
* 设备执行日志,会保留历史记录
*
* @param luceneLogDto 日志结果对象
*/
void deviceExecuteLog(LuceneLogDto luceneLogDto);
/**
* 接口日志,会保留历史记录
*
* @param luceneLogDto 日志结果对象
*/
void interfaceExecuteLog(LuceneLogDto luceneLogDto);
/**
* 设备执行日志,会保留历史记录
*
* @param name 日志名称
* @param message 日志信息
*/
void extLog(String name, String message);
}

18
acs/nladmin-system/src/main/java/org/nl/modules/lucene/service/LuceneService.java

@ -0,0 +1,18 @@
package org.nl.modules.lucene.service;
import org.springframework.data.domain.Pageable;
import java.util.Map;
public interface LuceneService {
/**
* 获取数据分页
*
* @param whereJson 条件
* @param page 分页参数
* @return Map<String, Object>
*/
Map<String, Object> getAll(Map whereJson, Pageable page);
}

117
acs/nladmin-system/src/main/java/org/nl/modules/lucene/service/dto/LuceneLogDto.java

@ -0,0 +1,117 @@
package org.nl.modules.lucene.service.dto;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class LuceneLogDto {
/* 日志标识 */
private String log_uuid;
/*日志类型*/
private String logType;
/*设备编号*/
private String device_code;
/*内容详情*/
private String content;
/* 任务编码 */
private String task_code;
/* 指令编码 */
private String instruct_code;
/* 任务标识 */
private String task_id;
/* 载具号 */
private String vehicle_code;
/* 备注 */
private String remark;
/* 日志类型 */
private String log_type;
/* 方法 */
private String method;
/* 请求参数 */
private String requestparam;
/* 响应参数 */
private String responseparam;
/* 请求地址 */
private String requesturl;
/* 状态码 */
private String status_code;
/* 是否删除 1:是;0:否 */
private String is_delete;
/* 创建者 */
private String create_by;
/* 创建时间 YYYY-MM-DD hh:mm:ss */
private String create_time;
/* 修改者 */
private String update_by;
/* 修改时间 */
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 String last_home,
final String home) {
super();
this.device_code = device_code;
this.content = "信号 ["
+ opc_server_code + "."
+ opc_plc_code + "."
+ device_code + "."
+ to_home + "] 发生变更 "
+ last_home + " -> "
+ home;
}
public LuceneLogDto(final String device_code, final String task_code,
final String instruct_code, final String method,
final String remark){
super();
this.device_code = device_code;
this.task_code = task_code;
this.instruct_code = instruct_code;
this.method = method;
this.content = remark;
}
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;
}
}

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

@ -0,0 +1,51 @@
package org.nl.modules.lucene.service.impl;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nl.modules.lucene.enums.LogTypeEnum;
import org.nl.modules.lucene.service.LuceneExecuteLogService;
import org.nl.modules.lucene.service.dto.LuceneLogDto;
import org.slf4j.MDC;
import org.springframework.stereotype.Service;
/**
* @author jlm
* @description 服务实现
* @date 2023-04-11
*/
@Service
@RequiredArgsConstructor
@Slf4j
public class LuceneExecuteLogServiceImpl implements LuceneExecuteLogService {
@Override
public void deviceItemValue(String device_code, String key, String value) {
String now = DateUtil.now();
}
@Override
public void deviceExecuteLog(LuceneLogDto luceneLogDto) {
luceneLogDto.setLogType(LogTypeEnum.DEVICE_LOG.getDesc());
log.info("{}", JSON.toJSONString(luceneLogDto));
}
@Override
public void interfaceExecuteLog(LuceneLogDto luceneLogDto) {
luceneLogDto.setLogType(LogTypeEnum.INTERFACE_LOG.getDesc());
log.info("{}", JSON.toJSONString(luceneLogDto));
}
@Override
public void extLog(String name, String message) {
try {
MDC.put(name, name);
log.info("{}", message);
} catch (Exception e) {
e.printStackTrace();
} finally {
MDC.remove(name);
}
}
}

127
acs/nladmin-system/src/main/java/org/nl/modules/lucene/service/impl/LuceneServiceImpl.java

@ -0,0 +1,127 @@
package org.nl.modules.lucene.service.impl;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSONObject;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.lucene.document.Document;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.*;
import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.util.BytesRef;
import org.nl.modules.lucene.service.LuceneService;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import java.nio.file.Paths;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
@Service
@RequiredArgsConstructor
@Slf4j
public class LuceneServiceImpl implements LuceneService {
//日志索引目录
@Override
public Map<String, Object> getAll(Map whereJson, Pageable page) {
//获取要查询的路径,也就是索引所在的位置
try {
FSDirectory directory = FSDirectory.open(Paths.get("C:\\acs\\lucene\\index"));
DirectoryReader open = DirectoryReader.open(directory);
IndexSearcher searcher = new IndexSearcher(open);
// 实际上Lucene本身不支持分页。因此我们需要自己进行逻辑分页。我们要准备分页参数:
int pageSize = Integer.parseInt(whereJson.get("size").toString());// 每页条数
int pageNum = Integer.parseInt(whereJson.get("page").toString());// 当前页码
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);
startDate = DateUtil.format(calendar.getTime(),"yyyy-MM-dd HH:mm:ss.SSS");
}else{
startDate = getDate(startDate);
}
if (endDate == null){
endDate = DateUtil.format(new DateTime(),"yyyy-MM-dd HH:mm:ss.SSS");
} else {
endDate = getDate(endDate);
}
TermRangeQuery termRangeQuery = new TermRangeQuery("logTime", new BytesRef(startDate), new BytesRef(endDate), true, true);
booleanQueryBuilder.add(termRangeQuery,BooleanClause.Occur.MUST);
if (whereJson.get("device_code") != null){
Query termQuery = new TermQuery(new Term("device_code", (String) whereJson.get("device_code")));
booleanQueryBuilder.add(termQuery,BooleanClause.Occur.MUST);
}
if (whereJson.get("method") != null){
Query termQuery = new TermQuery(new Term("method", (String) whereJson.get("method")));
booleanQueryBuilder.add(termQuery,BooleanClause.Occur.MUST);
}
if (whereJson.get("status_code") != null){
Query termQuery = new TermQuery(new Term("status_code", (String) whereJson.get("status_code")));
booleanQueryBuilder.add(termQuery,BooleanClause.Occur.MUST);
}
if (whereJson.get("requestparam") != null){
WildcardQuery query = new WildcardQuery(new Term("requestparam", "*"+(String) whereJson.get("requestparam")+"*"));
booleanQueryBuilder.add(query,BooleanClause.Occur.MUST);
}
if (whereJson.get("responseparam") != null){
WildcardQuery query = new WildcardQuery(new Term("responseparam", "*"+(String) whereJson.get("responseparam")+"*"));
booleanQueryBuilder.add(query,BooleanClause.Occur.MUST);
}
if (whereJson.get("blurry") != null) {
WildcardQuery query = new WildcardQuery(new Term("fieldContent", "*"+(String) whereJson.get("blurry")+"*"));
booleanQueryBuilder.add(query, BooleanClause.Occur.MUST);
}
TopFieldCollector collector = TopFieldCollector.create(new Sort(new SortField("logTime", 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 = open.document(scoreDoc.doc);
JSONObject object = new JSONObject();
object.put("content",doc.get("fieldContent"));
object.put("device_code",doc.get("device_code"));
object.put("logTime",doc.get("logTime"));
object.put("method",doc.get("method"));
object.put("status_code",doc.get("status_code"));
object.put("requestparam",doc.get("requestparam"));
object.put("responseparam",doc.get("responseparam"));
if(doc.get("fieldContent") != null) {
list.add(object);
}
}
open.close();
directory.close();
JSONObject jo = new JSONObject();
jo.put("content", list);
jo.put("totalElements", totalSize);
return jo;
} catch (Exception e) {
log.error("索引查询为空", e);
throw new NullPointerException("索引查询为空");
}
}
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;
}
}

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

@ -149,9 +149,9 @@ sa-token:
# token 前缀
token-prefix: Bearer
loki:
url: http://localhost:3100/loki/api/v1
systemName: acs
#loki:
# url: http://localhost:3100/loki/api/v1
# systemName: acs
agvToAcs:
addr: http://192.168.0.214:8010

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

@ -2,7 +2,7 @@ spring:
freemarker:
check-template-location: false
profiles:
active: prod
active: dev
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:
@ -78,3 +78,7 @@ security:
- /api/localStorage/pictures
# 参数
- /api/param/getValueByCode
lucene:
index:
path: C:\acs\lucene\index

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

@ -14,10 +14,11 @@ 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="lokiUrl" source="loki.url"/>-->
<springProperty scope="context" name="systemName" source="loki.systemName"/>
<property name="LOKI_URL" value="${lokiUrl}"/>
<!-- <property name="LOKI_URL" value="${lokiUrl}"/>-->
<property name="SYSTEM_NAME" value="${systemName}"/>
<!--定义日志文件的存储地址 勿在 LogBack 的配置中使用相对路径-->
<property name="LOG_HOME" value="${logPath}"/>
<!--引入默认的一些设置-->
<!--<include resource="log/XrToMes.xml"/>
@ -30,8 +31,6 @@ https://juejin.cn/post/6844903775631572999
</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">
@ -48,170 +47,45 @@ https://juejin.cn/post/6844903775631572999
<!--格式化输出:%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">
<discardingThreshold>0</discardingThreshold>
<queueSize>500</queueSize>
<queueSize>200</queueSize>
<appender-ref ref="FILE"/>
</appender>
<!--添加loki-->
<appender name="lokiAppender" class="com.github.loki4j.logback.Loki4jAppender">
<batchTimeoutMs>1000</batchTimeoutMs>
<http class="com.github.loki4j.logback.ApacheHttpSender">
<url>${LOKI_URL}/push</url>
</http>
<format>
<label>
<pattern>system=${SYSTEM_NAME},level=%level,logType=%X{log_file_type:-logType}</pattern>
</label>
<message>
<pattern>${log.pattern}</pattern>
</message>
<sortByTime>true</sortByTime>
</format>
<appender name="luceneAppender" class="org.nl.modules.lucene.config.LuceneAppender"/>
<appender name="asyncLuceneAppender" class="org.nl.modules.lucene.config.AsyncLuceneAppender">
<appender-ref ref="luceneAppender"/>
<!-- 设置队列大小,根据您的需求调整 -->
<queueSize>512</queueSize>
</appender>
<!--开发环境:打印控制台-->
<springProfile name="dev">
<root level="debug">
<root level="info">
<appender-ref ref="asyncLuceneAppender"/>
<appender-ref ref="CONSOLE"/>
<appender-ref ref="lokiAppender" />
</root>
<logger name="org.springframework" level="ERROR" additivity="false">
<appender-ref ref="CONSOLE"/>
</logger>
<logger name="com.github.loki4j.client.pipeline" level="ERROR" additivity="false">
<appender-ref ref="CONSOLE"/>
</logger>
<logger name="org.apache" level="ERROR" additivity="false">
<appender-ref ref="CONSOLE"/>
</logger>
<logger name="org.hibernate" level="ERROR" additivity="false">
<appender-ref ref="CONSOLE"/>
</logger>
<logger name="io.netty" level="ERROR" additivity="false">
<appender-ref ref="CONSOLE"/>
</logger>
<logger name="jdbc" level="ERROR" additivity="false">
<appender-ref ref="CONSOLE"/>
</logger>
<logger name="io.lettuce" level="ERROR" additivity="false">
<appender-ref ref="CONSOLE"/>
</logger>
<logger name="com.fasterxml" level="ERROR" additivity="false">
<appender-ref ref="CONSOLE"/>
</logger>
<logger name="org.quartz" level="ERROR" additivity="false">
<appender-ref ref="CONSOLE"/>
</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>
</springProfile>
<!--生产环境:打印控制台和输出到文件-->
<springProfile name="prod">
<!--测试环境:打印控制台-->
<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="asyncFileAppender"/>-->
<appender-ref ref="lokiAppender"/>
<!-- <appender-ref ref="CONSOLE"/>-->
<appender-ref ref="CONSOLE"/>
</root>
<logger name="org.springframework" level="ERROR" additivity="false">
<appender-ref ref="asyncFileAppender"/>
<appender-ref ref="lokiAppender"/>
</logger>
<logger name="org.apache" level="ERROR" additivity="false">
<appender-ref ref="asyncFileAppender"/>
<appender-ref ref="lokiAppender"/>
</logger>
<logger name="org.hibernate" level="ERROR" additivity="false">
<appender-ref ref="asyncFileAppender"/>
<appender-ref ref="lokiAppender"/>
</logger>
<logger name="io.netty" level="ERROR" additivity="false">
<appender-ref ref="asyncFileAppender"/>
<appender-ref ref="lokiAppender"/>
</logger>
<logger name="jdbc" level="ERROR" additivity="false">
<appender-ref ref="asyncFileAppender"/>
<appender-ref ref="lokiAppender"/>
</logger>
<logger name="io.lettuce" level="ERROR" additivity="false">
<appender-ref ref="asyncFileAppender"/>
<appender-ref ref="lokiAppender"/>
</logger>
<logger name="com.fasterxml" level="ERROR" additivity="false">
<appender-ref ref="asyncFileAppender"/>
<appender-ref ref="lokiAppender"/>
</logger>
<logger name="org.quartz" level="ERROR" additivity="false">
<appender-ref ref="asyncFileAppender"/>
<appender-ref ref="lokiAppender"/>
</logger>
<logger name="com.google" level="ERROR" additivity="false">
<appender-ref ref="asyncFileAppender"/>
<appender-ref ref="lokiAppender"/>
</logger>
<logger name="springfox" level="ERROR" additivity="false">
<appender-ref ref="asyncFileAppender"/>
<appender-ref ref="lokiAppender"/>
</logger>
<logger name="log4jdbc" level="ERROR" additivity="false">
<appender-ref ref="asyncFileAppender"/>
<appender-ref ref="lokiAppender"/>
</logger>
<logger name="nl.basjes" level="ERROR" additivity="false">
<appender-ref ref="asyncFileAppender"/>
<appender-ref ref="lokiAppender"/>
</logger>
<logger name="org.jinterop" level="ERROR" additivity="false">
<appender-ref ref="asyncFileAppender"/>
<appender-ref ref="lokiAppender"/>
</logger>
<logger name="org.openscada" level="ERROR" additivity="false">
<appender-ref ref="asyncFileAppender"/>
<appender-ref ref="lokiAppender"/>
</logger>
<logger name="org.nl.modules.wql" level="info" additivity="false">
<appender-ref ref="asyncFileAppender"/>
<appender-ref ref="lokiAppender"/>
</logger>
</springProfile>
<!--测试环境:打印控制台-->
<springProfile name="test">
<!--生产环境:打印控制台和输出到文件-->
<springProfile name="prod">
<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>
<logger name="jdbc.resultset" level="ERROR" additivity="false">
<appender-ref ref="CONSOLE"/>
</logger>
<logger name="springfox.documentation" level="ERROR" additivity="false">
<appender-ref ref="CONSOLE"/>
</logger>
<logger name="jdbc.resultsettable" level="ERROR" additivity="false">
<appender-ref ref="CONSOLE"/>
</logger>
<logger name="jdbc.sqlonly" level="ERROR" additivity="false">
<appender-ref ref="CONSOLE"/>
</logger>
</springProfile>
</configuration>

18
acs/nladmin-ui/src/views/monitor/lucene/api/lucene.js

@ -0,0 +1,18 @@
import request from '@/utils/request'
export function getLogData(param) {
return request({
url: 'api/lucene/getAll',
method: 'get',
data: param
})
}
export function labelsValues() {
return request({
url: 'api/loki/labels/values',
method: 'get'
})
}
export default { getLogData, labelsValues }

39
acs/nladmin-ui/src/views/monitor/lucene/index.vue

@ -2,19 +2,7 @@
<div class="app-container">
<div class="head-container">
<Search />
<crudOperation>
<el-button
slot="left"
class="filter-item"
type="danger"
icon="el-icon-delete"
size="mini"
:loading="crud.delAllLoading"
@click="confirmDelAll()"
>
清空
</el-button>
</crudOperation>
<crudOperation />
</div>
<!--表格渲染-->
<el-table
@ -24,11 +12,19 @@
style="width: 100%;"
@selection-change="crud.selectionChangeHandler"
>
<el-table-column type="selection" width="55"/>
<el-table-column v-if="false" prop="id" label="id"/>
<el-table-column prop="resource_name" label="资源号"/>
<el-table-column prop="create_datetime" label="创建时间"/>
<el-table-column prop="content" label="内容详情"/>
<!-- <el-table-column type="selection" width="55"/>-->
<!-- <el-table-column v-if="false" prop="id" label="id"/>-->
<el-table-column prop="operate" width="50" label="操作" />
<el-table-column prop="device_code" label="设备号" min-width="130" show-overflow-tooltip />
<!-- <el-table-column prop="trace_id" label="链路追踪" /> -->
<el-table-column prop="task_code" label="任务编号" />
<el-table-column prop="instruct_code" label="指令编号" />
<el-table-column prop="method" label="方法" />
<el-table-column prop="status_code" label="状态码" />
<el-table-column prop="requestparam" label="请求参数" />
<el-table-column prop="responseparam" label="返回参数" />
<el-table-column prop="logTime" width="170" label="记录时间" />
<el-table-column prop="content" width="500" label="内容详情" />
</el-table>
<!--分页组件-->
@ -43,14 +39,13 @@ import crudOperation from '@crud/CRUD.operation'
import pagination from '@crud/Pagination'
import { delAll } from '@/api/acs/lucene/log'
const start = new Date()
export default {
name: 'LuceneLog',
components: { Search, pagination, crudOperation },
mixins: [presenter(), header(), crud()],
cruds() {
cruds: function() {
return CRUD({
title: '系统参数', url: 'api/lucene', idField: 'id', sort: 'id,desc',
title: '系统参数', url: 'api/lucene/getAll', idField: 'id', sort: 'id,desc',
queryOnPresenterCreated: true,
optShow: {
add: false,
@ -64,7 +59,7 @@ export default {
page: 0
},
query: {
createTime: [start.setTime(start.getTime() - 3600 * 1000 * 0.5), new Date()]
createTime: [new Date(new Date().setTime(new Date().getTime() - 3600 * 1000)), new Date(new Date().setTime(new Date().getTime() + 3600 * 1000))]
}
})
},

43
acs/nladmin-ui/src/views/monitor/lucene/search.vue

@ -1,10 +1,50 @@
<template>
<div v-if="crud.props.searchToggle">
<el-input
v-model="query.device_code"
clearable
size="small"
placeholder="请输入你要搜索的设备号"
style="width: 200px;"
class="filter-item"
/>
<el-input
v-model="query.method"
clearable
size="small"
placeholder="请输入你要搜索的方法名"
style="width: 200px;"
class="filter-item"
/>
<el-input
v-model="query.status_code"
clearable
size="small"
placeholder="请输入你要搜索的状态码"
style="width: 200px;"
class="filter-item"
/>
<el-input
v-model="query.requestparam"
clearable
size="small"
placeholder="请输入你要搜索的请求参数"
style="width: 200px;"
class="filter-item"
/>
<el-input
v-model="query.responseparam"
clearable
size="small"
placeholder="请输入你要搜索的返回参数"
style="width: 200px;"
class="filter-item"
/>
<el-input
v-model="query.blurry"
clearable
size="small"
placeholder="请输入你要搜索的内容"
placeholder="请输入你要搜索的内容详情"
style="width: 200px;"
class="filter-item"
/>
@ -16,6 +56,7 @@
v-model="query.createTime"
type="datetimerange"
:picker-options="pickerOptions"
format="yyyy-MM-dd HH:mm:ss"
range-separator="至"
start-placeholder="开始日期"
end-placeholder="结束日期"

Loading…
Cancel
Save