From 02ad40b2caa21d98c891fb59fa7c505992a042fa Mon Sep 17 00:00:00 2001 From: gengby <858962040@qq.com> Date: Wed, 3 Jan 2024 17:25:04 +0800 Subject: [PATCH] =?UTF-8?q?rev:=E5=88=A0=E9=99=A4loki=E3=80=81=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0lucene?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- acs/nladmin-system/.gitignore | 2 + acs/nladmin-system/pom.xml | 45 ++++- .../org/nl/acs/device_driver/RouteUtil.java | 2 +- .../maGang/MaGangConveyorDeviceDriver.java | 45 ++--- .../wms/service/impl/AgvToAcsServiceImpl.java | 35 ++-- .../nl/modules/loki/rest/LokiController.java | 40 ----- .../nl/modules/loki/service/LokiService.java | 25 --- .../loki/service/impl/LokiServiceImpl.java | 113 ------------ .../lucene/config/AsyncLuceneAppender.java | 43 +++++ .../lucene/config/LogMessageConstant.java | 80 +++++++++ .../modules/lucene/config/LuceneAppender.java | 130 ++++++++++++++ .../lucene/config/LuceneProperties.java | 23 +++ .../config/LucenePropertyAndEncoder.java | 38 ++++ .../nl/modules/lucene/config/Property.java | 44 +++++ .../nl/modules/lucene/enums/LogTypeEnum.java | 15 ++ .../modules/lucene/rest/LuceneController.java | 38 ++++ .../service/LuceneExecuteLogService.java | 39 ++++ .../modules/lucene/service/LuceneService.java | 18 ++ .../lucene/service/dto/LuceneLogDto.java | 117 ++++++++++++ .../impl/LuceneExecuteLogServiceImpl.java | 51 ++++++ .../service/impl/LuceneServiceImpl.java | 127 +++++++++++++ .../resources/config/application-prod.yml | 6 +- .../src/main/resources/config/application.yml | 8 +- .../src/main/resources/logback-spring.xml | 168 +++--------------- .../src/views/monitor/lucene/api/lucene.js | 18 ++ .../src/views/monitor/lucene/index.vue | 43 ++--- .../src/views/monitor/lucene/search.vue | 45 ++++- 27 files changed, 955 insertions(+), 403 deletions(-) delete mode 100644 acs/nladmin-system/src/main/java/org/nl/modules/loki/rest/LokiController.java delete mode 100644 acs/nladmin-system/src/main/java/org/nl/modules/loki/service/LokiService.java delete mode 100644 acs/nladmin-system/src/main/java/org/nl/modules/loki/service/impl/LokiServiceImpl.java create mode 100644 acs/nladmin-system/src/main/java/org/nl/modules/lucene/config/AsyncLuceneAppender.java create mode 100644 acs/nladmin-system/src/main/java/org/nl/modules/lucene/config/LogMessageConstant.java create mode 100644 acs/nladmin-system/src/main/java/org/nl/modules/lucene/config/LuceneAppender.java create mode 100644 acs/nladmin-system/src/main/java/org/nl/modules/lucene/config/LuceneProperties.java create mode 100644 acs/nladmin-system/src/main/java/org/nl/modules/lucene/config/LucenePropertyAndEncoder.java create mode 100644 acs/nladmin-system/src/main/java/org/nl/modules/lucene/config/Property.java create mode 100644 acs/nladmin-system/src/main/java/org/nl/modules/lucene/enums/LogTypeEnum.java create mode 100644 acs/nladmin-system/src/main/java/org/nl/modules/lucene/rest/LuceneController.java create mode 100644 acs/nladmin-system/src/main/java/org/nl/modules/lucene/service/LuceneExecuteLogService.java create mode 100644 acs/nladmin-system/src/main/java/org/nl/modules/lucene/service/LuceneService.java create mode 100644 acs/nladmin-system/src/main/java/org/nl/modules/lucene/service/dto/LuceneLogDto.java create mode 100644 acs/nladmin-system/src/main/java/org/nl/modules/lucene/service/impl/LuceneExecuteLogServiceImpl.java create mode 100644 acs/nladmin-system/src/main/java/org/nl/modules/lucene/service/impl/LuceneServiceImpl.java create mode 100644 acs/nladmin-ui/src/views/monitor/lucene/api/lucene.js diff --git a/acs/nladmin-system/.gitignore b/acs/nladmin-system/.gitignore index caa1a2a..82d97ca 100644 --- a/acs/nladmin-system/.gitignore +++ b/acs/nladmin-system/.gitignore @@ -6,3 +6,5 @@ */*.iml /.gradle/ /target/* +/C:* +/D:* diff --git a/acs/nladmin-system/pom.xml b/acs/nladmin-system/pom.xml index 207ff62..e3e103c 100644 --- a/acs/nladmin-system/pom.xml +++ b/acs/nladmin-system/pom.xml @@ -30,6 +30,7 @@ 5.9.0 1.9 + 8.2.0 @@ -179,11 +180,11 @@ - + org.apache.httpcomponents httpclient @@ -295,6 +296,46 @@ 1.5.21 + + + com.yomahub + tlog-all-spring-boot-starter + 1.5.0 + + + org.apache.lucene + lucene-core + ${lucene.version} + + + org.apache.lucene + lucene-highlighter + ${lucene.version} + + + org.apache.lucene + lucene-analyzers-common + ${lucene.version} + + + com.github.magese + ik-analyzer + ${lucene.version} + + + + + org.apache.lucene + lucene-analyzers-smartcn + ${lucene.version} + + + + org.apache.lucene + lucene-queryparser + ${lucene.version} + + mysql diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/RouteUtil.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/RouteUtil.java index 4f74ab7..f2179d4 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/RouteUtil.java +++ b/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")) { diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/maGang/MaGangConveyorDeviceDriver.java b/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/maGang/MaGangConveyorDeviceDriver.java index 8049cb5..e26d6a8 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/device_driver/maGang/MaGangConveyorDeviceDriver.java +++ b/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); + this.writing(1); + this.setRequireSucess(true); } catch (Exception e) { - logServer.deviceExecuteLog(this.device_code, "", "", this.device_code + ":创建任务失败," + String.valueOf(e.getMessage())); + lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, "任务创建失败,原因:" + e.getMessage())); } - logServer.deviceExecuteLog(this.device_code, "", "", this.device_code + ":创建任务成功"); - this.writing(1); - this.setRequireSucess(true); return true; } } @@ -305,12 +292,11 @@ public class MaGangConveyorDeviceDriver extends AbstractOpcDeviceDriver implemen taskDto.setCreate_time(now); try { taskserver.create(taskDto); + this.writing(1); + this.setRequireSucess(true); } catch (Exception e) { - logServer.deviceExecuteLog(this.device_code, "", "", this.device_code + ":创建任务失败," + String.valueOf(e.getMessage())); + lucene.deviceExecuteLog(new LuceneLogDto(this.device_code, "任务创建失败,原因:" + e.getMessage())); } - logServer.deviceExecuteLog(this.device_code, "", "", this.device_code + ":创建任务成功"); - this.writing(1); - this.setRequireSucess(true); return true; } } @@ -343,7 +329,7 @@ public class MaGangConveyorDeviceDriver extends AbstractOpcDeviceDriver implemen Map itemMap = new HashMap(); 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 itemMap = new HashMap(); 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 itemMap = new HashMap(); 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 diff --git a/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/AgvToAcsServiceImpl.java b/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/AgvToAcsServiceImpl.java index ad86808..10841a4 100644 --- a/acs/nladmin-system/src/main/java/org/nl/acs/ext/wms/service/impl/AgvToAcsServiceImpl.java +++ b/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 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 + "'->有误!"); } } diff --git a/acs/nladmin-system/src/main/java/org/nl/modules/loki/rest/LokiController.java b/acs/nladmin-system/src/main/java/org/nl/modules/loki/rest/LokiController.java deleted file mode 100644 index e498cb6..0000000 --- a/acs/nladmin-system/src/main/java/org/nl/modules/loki/rest/LokiController.java +++ /dev/null @@ -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 labelsValues() { - return new ResponseEntity<>(lokiService.getLabelsValues(), HttpStatus.OK); - } - - @PostMapping("/logs") - @ApiOperation("获取日志") - @RateLimiter(value = 1, timeout = 300) // 限流 - public ResponseEntity getLogData(@RequestBody JSONObject json) { - return new ResponseEntity<>(lokiService.getLogData(json), HttpStatus.OK); - } -} diff --git a/acs/nladmin-system/src/main/java/org/nl/modules/loki/service/LokiService.java b/acs/nladmin-system/src/main/java/org/nl/modules/loki/service/LokiService.java deleted file mode 100644 index 10101c9..0000000 --- a/acs/nladmin-system/src/main/java/org/nl/modules/loki/service/LokiService.java +++ /dev/null @@ -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(); -} diff --git a/acs/nladmin-system/src/main/java/org/nl/modules/loki/service/impl/LokiServiceImpl.java b/acs/nladmin-system/src/main/java/org/nl/modules/loki/service/impl/LokiServiceImpl.java deleted file mode 100644 index f6eeb49..0000000 --- a/acs/nladmin-system/src/main/java/org/nl/modules/loki/service/impl/LokiServiceImpl.java +++ /dev/null @@ -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 mdcPropertyMap = event.getMDCPropertyMap(); + if (mdcPropertyMap.getClass().getName().contains("SynchronizedMap")){ + mdcPropertyMap.put("traceId",traceId); + } + MDC.clear(); + } + super.append(event); + } + +} diff --git a/acs/nladmin-system/src/main/java/org/nl/modules/lucene/config/LogMessageConstant.java b/acs/nladmin-system/src/main/java/org/nl/modules/lucene/config/LogMessageConstant.java new file mode 100644 index 0000000..57ae26f --- /dev/null +++ b/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"; + +} diff --git a/acs/nladmin-system/src/main/java/org/nl/modules/lucene/config/LuceneAppender.java b/acs/nladmin-system/src/main/java/org/nl/modules/lucene/config/LuceneAppender.java new file mode 100644 index 0000000..34f3033 --- /dev/null +++ b/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 { + + public static final TransmittableThreadLocal traceIdTL = new TransmittableThreadLocal(); + public LuceneProperties properties; + public static Directory index; + private List 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 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; + + } +} diff --git a/acs/nladmin-system/src/main/java/org/nl/modules/lucene/config/LuceneProperties.java b/acs/nladmin-system/src/main/java/org/nl/modules/lucene/config/LuceneProperties.java new file mode 100644 index 0000000..5df7ade --- /dev/null +++ b/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 properties; + + public LuceneProperties() { + this.properties = new ArrayList(); + } + + public List getProperties() { + return properties; + } + + public void addProperty(Property property) { + properties.add(property); + } + +} diff --git a/acs/nladmin-system/src/main/java/org/nl/modules/lucene/config/LucenePropertyAndEncoder.java b/acs/nladmin-system/src/main/java/org/nl/modules/lucene/config/LucenePropertyAndEncoder.java new file mode 100644 index 0000000..3b07504 --- /dev/null +++ b/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(); + } +} + diff --git a/acs/nladmin-system/src/main/java/org/nl/modules/lucene/config/Property.java b/acs/nladmin-system/src/main/java/org/nl/modules/lucene/config/Property.java new file mode 100644 index 0000000..643075c --- /dev/null +++ b/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; + } +} diff --git a/acs/nladmin-system/src/main/java/org/nl/modules/lucene/enums/LogTypeEnum.java b/acs/nladmin-system/src/main/java/org/nl/modules/lucene/enums/LogTypeEnum.java new file mode 100644 index 0000000..96b2d23 --- /dev/null +++ b/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; + } +} diff --git a/acs/nladmin-system/src/main/java/org/nl/modules/lucene/rest/LuceneController.java b/acs/nladmin-system/src/main/java/org/nl/modules/lucene/rest/LuceneController.java new file mode 100644 index 0000000..c32761d --- /dev/null +++ b/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 get(@RequestParam Map whereJson, Pageable page) { + return new ResponseEntity<>(luceneService.getAll(whereJson, page), HttpStatus.OK); + } +} diff --git a/acs/nladmin-system/src/main/java/org/nl/modules/lucene/service/LuceneExecuteLogService.java b/acs/nladmin-system/src/main/java/org/nl/modules/lucene/service/LuceneExecuteLogService.java new file mode 100644 index 0000000..e4b0db1 --- /dev/null +++ b/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); + + +} diff --git a/acs/nladmin-system/src/main/java/org/nl/modules/lucene/service/LuceneService.java b/acs/nladmin-system/src/main/java/org/nl/modules/lucene/service/LuceneService.java new file mode 100644 index 0000000..480ae5e --- /dev/null +++ b/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 + */ + Map getAll(Map whereJson, Pageable page); +} diff --git a/acs/nladmin-system/src/main/java/org/nl/modules/lucene/service/dto/LuceneLogDto.java b/acs/nladmin-system/src/main/java/org/nl/modules/lucene/service/dto/LuceneLogDto.java new file mode 100644 index 0000000..8d6de18 --- /dev/null +++ b/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; + } + +} diff --git a/acs/nladmin-system/src/main/java/org/nl/modules/lucene/service/impl/LuceneExecuteLogServiceImpl.java b/acs/nladmin-system/src/main/java/org/nl/modules/lucene/service/impl/LuceneExecuteLogServiceImpl.java new file mode 100644 index 0000000..17ceffd --- /dev/null +++ b/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); + } + } +} diff --git a/acs/nladmin-system/src/main/java/org/nl/modules/lucene/service/impl/LuceneServiceImpl.java b/acs/nladmin-system/src/main/java/org/nl/modules/lucene/service/impl/LuceneServiceImpl.java new file mode 100644 index 0000000..6c10ee4 --- /dev/null +++ b/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 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 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; + } + +} diff --git a/acs/nladmin-system/src/main/resources/config/application-prod.yml b/acs/nladmin-system/src/main/resources/config/application-prod.yml index b9595fb..ba4f63b 100644 --- a/acs/nladmin-system/src/main/resources/config/application-prod.yml +++ b/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 diff --git a/acs/nladmin-system/src/main/resources/config/application.yml b/acs/nladmin-system/src/main/resources/config/application.yml index a4d00ab..d51c943 100644 --- a/acs/nladmin-system/src/main/resources/config/application.yml +++ b/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 diff --git a/acs/nladmin-system/src/main/resources/logback-spring.xml b/acs/nladmin-system/src/main/resources/logback-spring.xml index db1a341..0a5d959 100644 --- a/acs/nladmin-system/src/main/resources/logback-spring.xml +++ b/acs/nladmin-system/src/main/resources/logback-spring.xml @@ -14,10 +14,11 @@ https://juejin.cn/post/6844903775631572999 - + - + + - @@ -48,170 +47,45 @@ https://juejin.cn/post/6844903775631572999 %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n - 0 - 500 + 200 - - - - 1000 - - ${LOKI_URL}/push - - - - system=${SYSTEM_NAME},level=%level,logType=%X{log_file_type:-logType} - - - ${log.pattern} - - true - + + + + + 512 - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + - - - - - - - - - - - - - - - diff --git a/acs/nladmin-ui/src/views/monitor/lucene/api/lucene.js b/acs/nladmin-ui/src/views/monitor/lucene/api/lucene.js new file mode 100644 index 0000000..674bb2c --- /dev/null +++ b/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 } diff --git a/acs/nladmin-ui/src/views/monitor/lucene/index.vue b/acs/nladmin-ui/src/views/monitor/lucene/index.vue index 49b7e27..03a3beb 100644 --- a/acs/nladmin-ui/src/views/monitor/lucene/index.vue +++ b/acs/nladmin-ui/src/views/monitor/lucene/index.vue @@ -1,20 +1,8 @@ - - - - 清空 - - + + - - - - - + + + + + + + + + + + + + - + @@ -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))] } }) }, diff --git a/acs/nladmin-ui/src/views/monitor/lucene/search.vue b/acs/nladmin-ui/src/views/monitor/lucene/search.vue index bfb9c19..a3657aa 100644 --- a/acs/nladmin-ui/src/views/monitor/lucene/search.vue +++ b/acs/nladmin-ui/src/views/monitor/lucene/search.vue @@ -1,10 +1,50 @@ + + + + + @@ -16,12 +56,13 @@ v-model="query.createTime" type="datetimerange" :picker-options="pickerOptions" + format="yyyy-MM-dd HH:mm:ss" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" align="right" /> - +