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] =?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('定时任务销毁')