From c3048a5f0145227aa2e00ef84755ad014676a0c3 Mon Sep 17 00:00:00 2001 From: lyd <1419499670@qq.com> Date: Tue, 11 Oct 2022 11:09:52 +0800 Subject: [PATCH 1/8] =?UTF-8?q?loki=E6=B3=A8=E8=A7=A3=E5=92=8C=E5=88=87?= =?UTF-8?q?=E9=9D=A2=E5=86=99=E5=85=A5=E6=97=A5=E5=BF=97=E3=80=81=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E7=AE=A1=E7=90=86=E5=AE=9A=E6=97=B6=E5=99=A8=E9=94=80?= =?UTF-8?q?=E6=AF=81=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rest/MobileAuthorizationController.java | 7 ++- .../src/main/java/org/nl/wms/log/LokiLog.java | 15 +++++ .../java/org/nl/wms/log/LokiLogAspect.java | 63 +++++++++++++++++++ .../main/java/org/nl/wms/log/LokiLogType.java | 17 +++++ .../src/main/resources/logback-spring.xml | 5 +- nladmin-ui/src/views/loki/view/index.vue | 7 +++ 6 files changed, 110 insertions(+), 4 deletions(-) create mode 100644 nladmin-system/src/main/java/org/nl/wms/log/LokiLog.java create mode 100644 nladmin-system/src/main/java/org/nl/wms/log/LokiLogAspect.java create mode 100644 nladmin-system/src/main/java/org/nl/wms/log/LokiLogType.java diff --git a/nladmin-system/src/main/java/org/nl/modules/security/rest/MobileAuthorizationController.java b/nladmin-system/src/main/java/org/nl/modules/security/rest/MobileAuthorizationController.java index b59f5162e..de0e34b7c 100644 --- a/nladmin-system/src/main/java/org/nl/modules/security/rest/MobileAuthorizationController.java +++ b/nladmin-system/src/main/java/org/nl/modules/security/rest/MobileAuthorizationController.java @@ -9,8 +9,10 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.nl.modules.common.config.RsaProperties; import org.nl.modules.common.exception.BadRequestException; import org.nl.modules.common.utils.RedisUtils; +import org.nl.modules.common.utils.RsaUtils; import org.nl.modules.common.utils.dto.CurrentUser; import org.nl.modules.security.service.dto.AuthUserDto; import org.nl.modules.system.service.RoleService; @@ -48,8 +50,8 @@ public class MobileAuthorizationController { @SaIgnore public ResponseEntity login(@Validated @RequestBody AuthUserDto authUser, HttpServletRequest request) throws Exception { // 密码解密 - 前端的加密规则: encrypt(根据实际更改) - String password = authUser.getPassword(); -// String password = RsaUtils.decryptByPrivateKey(RsaProperties.privateKey, authUser.getPassword()); +// String password = authUser.getPassword(); + String password = RsaUtils.decryptByPrivateKey(RsaProperties.privateKey, authUser.getPassword()); // 校验数据库 // 根据用户名查询,在比对密码 UserDto userDto = userService.findByName(authUser.getUsername()); // 拿不到已经抛出异常 @@ -75,7 +77,6 @@ public class MobileAuthorizationController { // 返回 token 与 用户信息 JSONObject jsonObject = new JSONObject(); - jsonObject.put("roles", permissionList); jsonObject.put("user", userDto); Map authInfo = new HashMap(2) {{ put("token", StpUtil.getTokenValue()); diff --git a/nladmin-system/src/main/java/org/nl/wms/log/LokiLog.java b/nladmin-system/src/main/java/org/nl/wms/log/LokiLog.java new file mode 100644 index 000000000..890d7d882 --- /dev/null +++ b/nladmin-system/src/main/java/org/nl/wms/log/LokiLog.java @@ -0,0 +1,15 @@ +package org.nl.wms.log; + +import java.lang.annotation.*; + +/** + * @author: lyd + * @description: 自定义日志注解,用作LOKI日志分类 + * @Date: 2022/10/10 + */ +@Retention(RetentionPolicy.RUNTIME) +@Target({ ElementType.METHOD}) +@Documented +public @interface LokiLog { + LokiLogType type() default LokiLogType.DEFAULT; +} diff --git a/nladmin-system/src/main/java/org/nl/wms/log/LokiLogAspect.java b/nladmin-system/src/main/java/org/nl/wms/log/LokiLogAspect.java new file mode 100644 index 000000000..fd682cb41 --- /dev/null +++ b/nladmin-system/src/main/java/org/nl/wms/log/LokiLogAspect.java @@ -0,0 +1,63 @@ +package org.nl.wms.log; + +import com.alibaba.fastjson.JSONObject; +import lombok.extern.slf4j.Slf4j; +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.Signature; +import org.aspectj.lang.annotation.Around; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Pointcut; +import org.aspectj.lang.reflect.MethodSignature; +import org.slf4j.MDC; +import org.springframework.stereotype.Component; + +import java.lang.reflect.Method; + + +/** + * @author: lyd + * @description: 自定义日志切面:https://cloud.tencent.com/developer/article/1655923 + * @Date: 2022/10/10 + */ +@Aspect +@Slf4j +@Component +public class LokiLogAspect { + /** + * 切到所有OperatorLog注解修饰的方法 + */ + @Pointcut("@annotation(org.nl.wms.log.LokiLog)") + public void operatorLog() { + // 空方法 + } + + /** + * 利用@Around环绕增强 + * + * @return + */ + @Around("operatorLog()") + public synchronized Object around(ProceedingJoinPoint pjp) throws Throwable { +// ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); +// HttpServletRequest request = attributes.getRequest(); +// HttpServletResponse response = attributes.getResponse(); + + Signature signature = pjp.getSignature(); + MethodSignature methodSignature = (MethodSignature) signature; + Method method = methodSignature.getMethod(); + LokiLog lokiLog = method.getAnnotation(LokiLog.class); + + // 获取描述信息 + LokiLogType logType = lokiLog.type(); + + MDC.put("log_file_type", logType.name()); + log.info("入参:" + JSONObject.toJSONString(pjp.getArgs())); + + Object proceed = pjp.proceed(); + + log.info("返回参数:" + JSONObject.toJSONString(proceed)); + MDC.remove("log_file_type"); + return proceed; + + } +} diff --git a/nladmin-system/src/main/java/org/nl/wms/log/LokiLogType.java b/nladmin-system/src/main/java/org/nl/wms/log/LokiLogType.java new file mode 100644 index 000000000..dc971d166 --- /dev/null +++ b/nladmin-system/src/main/java/org/nl/wms/log/LokiLogType.java @@ -0,0 +1,17 @@ +package org.nl.wms.log; + +/** + * @author: lyd + * @description: + * @Date: 2022/10/11 + */ +public enum LokiLogType { + DEFAULT( "默认"), + LMS_TO_MES( "LMS请求MES"), + MES_TO_LMS( "MES请求LMS"); + + private String desc; + LokiLogType(String desc) { + + } +} diff --git a/nladmin-system/src/main/resources/logback-spring.xml b/nladmin-system/src/main/resources/logback-spring.xml index 84ff0e00e..dedc8ce67 100644 --- a/nladmin-system/src/main/resources/logback-spring.xml +++ b/nladmin-system/src/main/resources/logback-spring.xml @@ -79,12 +79,15 @@ https://juejin.cn/post/6844903775631572999 - + + + + diff --git a/nladmin-ui/src/views/loki/view/index.vue b/nladmin-ui/src/views/loki/view/index.vue index c7966c5fa..3ce8a1ff2 100644 --- a/nladmin-ui/src/views/loki/view/index.vue +++ b/nladmin-ui/src/views/loki/view/index.vue @@ -216,6 +216,13 @@ export default { created() { this.initLabelOptions() }, + // 关闭定时器 - 加了缓存就必须使用deactivated + deactivated() { + // js提供的clearInterval方法用来清除定时器 + console.log('定时任务销毁') + clearInterval(this.timer) + window.removeEventListener('scroll', this.handleScroll) + }, beforeDestroy() { // js提供的clearInterval方法用来清除定时器 console.log('定时任务销毁') From 8e4ab7792008f3ade896fe6d568d5cdbd63f747e Mon Sep 17 00:00:00 2001 From: ldj_willow Date: Tue, 11 Oct 2022 11:13:15 +0800 Subject: [PATCH 2/8] =?UTF-8?q?=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...箔LMS系统接口.postman_collection.json | 154 ++++++++++++++++++ .../org/nl/modules/quartz/task/TestTask.java | 4 +- .../nl/modules/quartz/utils/ExecutionJob.java | 22 +-- .../src/main/resources/logback-spring.xml | 6 + 4 files changed, 163 insertions(+), 23 deletions(-) create mode 100644 doc/兰州铜箔LMS系统接口.postman_collection.json diff --git a/doc/兰州铜箔LMS系统接口.postman_collection.json b/doc/兰州铜箔LMS系统接口.postman_collection.json new file mode 100644 index 000000000..e38700bc8 --- /dev/null +++ b/doc/兰州铜箔LMS系统接口.postman_collection.json @@ -0,0 +1,154 @@ +{ + "info": { + "_postman_id": "3fab44b6-d4fb-4afd-81ad-31f1ec49c8c4", + "name": "兰州铜箔LMS系统接口", + "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" + }, + "item": [ + { + "name": "手持请求LMS", + "description": "", + "item": [ + { + "name": "登录", + "request": { + "method": "GET", + "header": [], + "body": {}, + "url": { + "raw": "http://localhost:8010/api/param/getStageCodeByCode", + "protocol": "http", + "host": [ + "localhost" + ], + "port": "8010", + "path": [ + "api", + "param", + "getStageCodeByCode" + ] + } + }, + "response": [] + } + ] + }, + { + "name": "LMS请求MES", + "description": "", + "item": [ + { + "name": "http://localhost:8010/api/param/getStageCodeByCode", + "request": { + "method": "GET", + "header": [], + "body": {}, + "url": { + "raw": "http://localhost:8010/api/param/getStageCodeByCode", + "protocol": "http", + "host": [ + "localhost" + ], + "port": "8010", + "path": [ + "api", + "param", + "getStageCodeByCode" + ] + } + }, + "response": [] + } + ] + }, + { + "name": "MES请求LMS", + "description": "", + "item": [], + "auth": { + "type": "bearer", + "bearer": [ + { + "key": "token", + "value": "Bearer eyJhbGciOiJIUzUxMiJ9.eyJqdGkiOiI2ZjI2OGMxZjAyOTE0MTNiOWU3YThmMTM2ZTc2MWJkYSIsImF1dGgiOiJhZG1pbiIsInN1YiI6ImFkbWluIn0.lKxY3Wc_efzmBXXAS_dDC_Sfh32kZInxYmaxBzg83e5gviSJPPKolNt4IlCCaGM8HOc_yKByiIu8YFlgQif01Q", + "type": "string" + } + ] + } + }, + { + "name": "LMS请求CRM", + "description": "", + "item": [] + }, + { + "name": "CRM请求MES", + "description": "", + "item": [] + }, + { + "name": "ACS请求LMS", + "description": "", + "item": [], + "event": [ + { + "listen": "prerequest", + "script": { + "id": "2f9e1cf4-d33b-4c2c-85fb-546f276da5b7", + "type": "text/javascript", + "exec": [ + "" + ] + } + }, + { + "listen": "test", + "script": { + "id": "d7ddf3ac-5ecf-4a01-ae1c-c491bd7b645b", + "type": "text/javascript", + "exec": [ + "" + ] + } + } + ] + }, + { + "name": "LMS请求ACS", + "description": "", + "item": [], + "event": [ + { + "listen": "prerequest", + "script": { + "id": "2f9e1cf4-d33b-4c2c-85fb-546f276da5b7", + "type": "text/javascript", + "exec": [ + "" + ] + } + }, + { + "listen": "test", + "script": { + "id": "d7ddf3ac-5ecf-4a01-ae1c-c491bd7b645b", + "type": "text/javascript", + "exec": [ + "" + ] + } + } + ] + }, + { + "name": "SAP请求LMS", + "description": "", + "item": [] + }, + { + "name": "LMS请求SAP", + "description": "", + "item": [] + } + ] +} \ No newline at end of file diff --git a/nladmin-system/src/main/java/org/nl/modules/quartz/task/TestTask.java b/nladmin-system/src/main/java/org/nl/modules/quartz/task/TestTask.java index 6a0b518c9..2d99ded81 100644 --- a/nladmin-system/src/main/java/org/nl/modules/quartz/task/TestTask.java +++ b/nladmin-system/src/main/java/org/nl/modules/quartz/task/TestTask.java @@ -16,7 +16,6 @@ package org.nl.modules.quartz.task; import lombok.extern.slf4j.Slf4j; -import org.nl.modules.wql.core.bean.WQLObject; import org.springframework.stereotype.Component; /** @@ -29,7 +28,6 @@ import org.springframework.stereotype.Component; public class TestTask { public void run(){ - log.info("run 执行成功"); } @@ -38,7 +36,7 @@ public class TestTask { } public void run2(){ - WQLObject.getWQLObject("sys_param"); +// int i= 1/0; log.info("run2 执行成功"); } } diff --git a/nladmin-system/src/main/java/org/nl/modules/quartz/utils/ExecutionJob.java b/nladmin-system/src/main/java/org/nl/modules/quartz/utils/ExecutionJob.java index 0ea11bfea..d735ced2a 100644 --- a/nladmin-system/src/main/java/org/nl/modules/quartz/utils/ExecutionJob.java +++ b/nladmin-system/src/main/java/org/nl/modules/quartz/utils/ExecutionJob.java @@ -105,29 +105,11 @@ public class ExecutionJob extends QuartzJobBean { //更新状态 quartzJobService.updateIsPause(quartzJob); } -// if (quartzJob.getEmail() != null) { -// EmailService emailService = SpringContextHolder.getBean(EmailService.class); -// // 邮箱报警 -// EmailVo emailVo = taskAlarm(quartzJob, ThrowableUtil.getStackTrace(e)); -// emailService.send(emailVo, emailService.find()); -// } - } finally { + //异常时候打印日志 log.info(logDto.toString()); + } finally { quartzLogRepository.save(logDto); } } -// private EmailVo taskAlarm(QuartzJob quartzJob, String msg) { -// EmailVo emailVo = new EmailVo(); -// emailVo.setSubject("定时任务【" + quartzJob.getJobName() + "】执行失败,请尽快处理!"); -// Map data = new HashMap<>(16); -// data.put("task", quartzJob); -// data.put("msg", msg); -// TemplateEngine engine = TemplateUtil.createEngine(new TemplateConfig("template", TemplateConfig.ResourceMode.CLASSPATH)); -// Template template = engine.getTemplate("email/taskAlarm.ftl"); -// emailVo.setContent(template.render(data)); -// List emails = Arrays.asList(quartzJob.getEmail().split("[,,]")); -// emailVo.setTos(emails); -// return emailVo; -// } } diff --git a/nladmin-system/src/main/resources/logback-spring.xml b/nladmin-system/src/main/resources/logback-spring.xml index 84ff0e00e..b1d27a20e 100644 --- a/nladmin-system/src/main/resources/logback-spring.xml +++ b/nladmin-system/src/main/resources/logback-spring.xml @@ -85,6 +85,9 @@ https://juejin.cn/post/6844903775631572999 + + + @@ -106,6 +109,9 @@ https://juejin.cn/post/6844903775631572999 + + + From 91357f87da9fd4b8dc7517e33631ff8bda0b7792 Mon Sep 17 00:00:00 2001 From: ldj_willow Date: Tue, 11 Oct 2022 11:16:15 +0800 Subject: [PATCH 3/8] =?UTF-8?q?=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/org/nl/modules/quartz/utils/ExecutionJob.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nladmin-system/src/main/java/org/nl/modules/quartz/utils/ExecutionJob.java b/nladmin-system/src/main/java/org/nl/modules/quartz/utils/ExecutionJob.java index d735ced2a..ee4f68570 100644 --- a/nladmin-system/src/main/java/org/nl/modules/quartz/utils/ExecutionJob.java +++ b/nladmin-system/src/main/java/org/nl/modules/quartz/utils/ExecutionJob.java @@ -107,8 +107,9 @@ public class ExecutionJob extends QuartzJobBean { } //异常时候打印日志 log.info(logDto.toString()); - } finally { quartzLogRepository.save(logDto); + } finally { + } } From 2914a93d0e6d0bb14355a2756f783cb94c102547 Mon Sep 17 00:00:00 2001 From: ldj_willow Date: Tue, 11 Oct 2022 14:04:29 +0800 Subject: [PATCH 4/8] =?UTF-8?q?=E6=97=A5=E5=BF=97=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/nl/modules/logging/aspect/LogAspect.java | 4 ++-- .../modules/logging/service/impl/LogServiceImpl.java | 11 ++--------- nladmin-ui/src/views/monitor/log/errorLog.vue | 8 ++++---- nladmin-ui/src/views/monitor/log/index.vue | 4 ++-- nladmin-ui/src/views/monitor/online/index.vue | 2 +- 5 files changed, 11 insertions(+), 18 deletions(-) diff --git a/nladmin-system/src/main/java/org/nl/modules/logging/aspect/LogAspect.java b/nladmin-system/src/main/java/org/nl/modules/logging/aspect/LogAspect.java index e4730e1d8..24e8e05f4 100644 --- a/nladmin-system/src/main/java/org/nl/modules/logging/aspect/LogAspect.java +++ b/nladmin-system/src/main/java/org/nl/modules/logging/aspect/LogAspect.java @@ -28,6 +28,7 @@ import org.aspectj.lang.reflect.MethodSignature; import org.nl.modules.common.utils.RequestHolder; import org.nl.modules.common.utils.SecurityUtils; import org.nl.modules.common.utils.StringUtils; +import org.nl.modules.common.utils.ThrowableUtil; import org.nl.modules.logging.domain.Log; import org.nl.modules.logging.service.LogService; import org.springframework.stereotype.Component; @@ -132,8 +133,7 @@ public class LogAspect { public void logAfterThrowing(JoinPoint joinPoint, Throwable e) { Log log = new Log("ERROR",System.currentTimeMillis() - currentTime.get()); currentTime.remove(); - // log.setExceptionDetail(ThrowableUtil.getStackTrace(e).getBytes()); - // log.setExceptionDetail(null); + log.setExceptionDetail(ThrowableUtil.getStackTrace(e).getBytes()); HttpServletRequest request = RequestHolder.getHttpServletRequest(); logService.save(getUsername(), StringUtils.getBrowser(request), StringUtils.getIp(request), (ProceedingJoinPoint)joinPoint, log); } diff --git a/nladmin-system/src/main/java/org/nl/modules/logging/service/impl/LogServiceImpl.java b/nladmin-system/src/main/java/org/nl/modules/logging/service/impl/LogServiceImpl.java index 197e98740..caaffddfe 100644 --- a/nladmin-system/src/main/java/org/nl/modules/logging/service/impl/LogServiceImpl.java +++ b/nladmin-system/src/main/java/org/nl/modules/logging/service/impl/LogServiceImpl.java @@ -19,8 +19,8 @@ import cn.hutool.core.lang.Dict; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.json.JSONUtil; -import com.alibaba.fastjson.JSONObject; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.reflect.MethodSignature; import org.nl.modules.common.utils.PageUtil; @@ -33,10 +33,6 @@ import org.nl.modules.logging.service.LogService; import org.nl.modules.logging.service.dto.LogQueryCriteria; import org.nl.modules.logging.service.mapstruct.LogErrorMapper; import org.nl.modules.logging.service.mapstruct.LogSmallMapper; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.slf4j.Marker; -import org.slf4j.MarkerFactory; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; @@ -57,9 +53,8 @@ import java.util.Map; */ @Service @RequiredArgsConstructor +@Slf4j public class LogServiceImpl implements LogService { - private static final Marker MARKER = MarkerFactory.getMarker("request"); - private static final Logger log = LoggerFactory.getLogger(LogServiceImpl.class); private final LogRepository logRepository; private final LogErrorMapper logErrorMapper; private final LogSmallMapper logSmallMapper; @@ -107,9 +102,7 @@ public class LogServiceImpl implements LogService { logDto.setMethod(methodName); logDto.setUsername(username); logDto.setParams(getParameter(method, joinPoint.getArgs())); - // logDto.setParams(""); logDto.setBrowser(browser); - log.info(MARKER,JSONObject.toJSONString(logDto)); logRepository.save(logDto); } diff --git a/nladmin-ui/src/views/monitor/log/errorLog.vue b/nladmin-ui/src/views/monitor/log/errorLog.vue index 33c392a89..ae322c625 100644 --- a/nladmin-ui/src/views/monitor/log/errorLog.vue +++ b/nladmin-ui/src/views/monitor/log/errorLog.vue @@ -33,9 +33,9 @@ - - - + + + @@ -78,7 +78,7 @@ export default { add: false, edit: false, del: false, - download: true + download: false } }, methods: { diff --git a/nladmin-ui/src/views/monitor/log/index.vue b/nladmin-ui/src/views/monitor/log/index.vue index 36da85d65..ca3206ec2 100644 --- a/nladmin-ui/src/views/monitor/log/index.vue +++ b/nladmin-ui/src/views/monitor/log/index.vue @@ -34,7 +34,7 @@ - +