diff --git a/kicc-auth/src/main/java/com/cloud/kicc/auth/handler/kiccAuthenticationFailureEventHandler.java b/kicc-auth/src/main/java/com/cloud/kicc/auth/handler/KiccAuthenticationFailureEventHandler.java similarity index 81% rename from kicc-auth/src/main/java/com/cloud/kicc/auth/handler/kiccAuthenticationFailureEventHandler.java rename to kicc-auth/src/main/java/com/cloud/kicc/auth/handler/KiccAuthenticationFailureEventHandler.java index 398f6283..98f6fd53 100644 --- a/kicc-auth/src/main/java/com/cloud/kicc/auth/handler/kiccAuthenticationFailureEventHandler.java +++ b/kicc-auth/src/main/java/com/cloud/kicc/auth/handler/KiccAuthenticationFailureEventHandler.java @@ -26,7 +26,7 @@ import java.util.Optional; */ @Slf4j @Component -public class kiccAuthenticationFailureEventHandler extends AbstractAuthenticationFailureEventHandler { +public class KiccAuthenticationFailureEventHandler extends AbstractAuthenticationFailureEventHandler { /** * 处理登录失败方法 @@ -36,27 +36,16 @@ public class kiccAuthenticationFailureEventHandler extends AbstractAuthenticatio */ @Override public void handle(AuthenticationException authenticationException, Authentication authentication) { + Long startTime = System.currentTimeMillis(); log.info("用户:{} 登录失败,异常:{}", authentication.getPrincipal(), authenticationException.getLocalizedMessage()); SecurityContextHolder.getContext().setAuthentication(authentication); - KiccUser kiccUser = SecurityUtils.getUser(authentication); OperLog operLog = SysLogUtils.getSysLog(); operLog.setTitle("登录失败"); operLog.setType(LogTypeEnum.ERROR.getType()); operLog.setErrorMsg(authenticationException.getMessage()); - operLog.setOperName(kiccUser.getUsername()); - // 发送异步日志事件 - Long startTime = System.currentTimeMillis(); Long endTime = System.currentTimeMillis(); operLog.setExecuteTime((endTime - startTime) + "毫秒"); - - if (Optional.ofNullable(kiccUser).isPresent()) { - operLog.setCreateById(kiccUser.getId()); - operLog.setCreateByName(kiccUser.getUsername()); - - operLog.setUpdateById(kiccUser.getId()); - operLog.setUpdateByName(kiccUser.getUsername()); - } - + // 发送异步日志事件 SpringContextHolderUtil.publishEvent(new SysLogEvent(operLog)); } diff --git a/kicc-auth/src/main/java/com/cloud/kicc/auth/handler/kiccAuthenticationSuccessEventHandler.java b/kicc-auth/src/main/java/com/cloud/kicc/auth/handler/KiccAuthenticationSuccessEventHandler.java similarity index 80% rename from kicc-auth/src/main/java/com/cloud/kicc/auth/handler/kiccAuthenticationSuccessEventHandler.java rename to kicc-auth/src/main/java/com/cloud/kicc/auth/handler/KiccAuthenticationSuccessEventHandler.java index 4f117ec7..1a9c3f1a 100644 --- a/kicc-auth/src/main/java/com/cloud/kicc/auth/handler/kiccAuthenticationSuccessEventHandler.java +++ b/kicc-auth/src/main/java/com/cloud/kicc/auth/handler/KiccAuthenticationSuccessEventHandler.java @@ -24,7 +24,7 @@ import java.util.Optional; */ @Slf4j @Component -public class kiccAuthenticationSuccessEventHandler extends AbstractAuthenticationSuccessEventHandler { +public class KiccAuthenticationSuccessEventHandler extends AbstractAuthenticationSuccessEventHandler { /** * 处理登录成功方法 @@ -34,22 +34,14 @@ public class kiccAuthenticationSuccessEventHandler extends AbstractAuthenticatio */ @Override public void handle(Authentication authentication) { + Long startTime = System.currentTimeMillis(); log.info("用户:{} 登录成功", authentication.getPrincipal()); SecurityContextHolder.getContext().setAuthentication(authentication); OperLog operLog = SysLogUtils.getSysLog(); operLog.setTitle("登录成功"); - // 发送异步日志事件 - Long startTime = System.currentTimeMillis(); - KiccUser kiccUser = SecurityUtils.getUser(authentication); - if (Optional.ofNullable(kiccUser).isPresent()) { - operLog.setCreateById(kiccUser.getId()); - operLog.setCreateByName(kiccUser.getUsername()); - - operLog.setUpdateById(kiccUser.getId()); - operLog.setUpdateByName(kiccUser.getUsername()); - } Long endTime = System.currentTimeMillis(); operLog.setExecuteTime((endTime - startTime) + "毫秒"); + // 发送异步日志事件 SpringContextHolderUtil.publishEvent(new SysLogEvent(operLog)); } diff --git a/kicc-auth/src/main/java/com/cloud/kicc/auth/handler/kiccLogoutSuccessEventHandler.java b/kicc-auth/src/main/java/com/cloud/kicc/auth/handler/KiccLogoutSuccessEventHandler.java similarity index 84% rename from kicc-auth/src/main/java/com/cloud/kicc/auth/handler/kiccLogoutSuccessEventHandler.java rename to kicc-auth/src/main/java/com/cloud/kicc/auth/handler/KiccLogoutSuccessEventHandler.java index 5c811be0..fd46e8ab 100644 --- a/kicc-auth/src/main/java/com/cloud/kicc/auth/handler/kiccLogoutSuccessEventHandler.java +++ b/kicc-auth/src/main/java/com/cloud/kicc/auth/handler/KiccLogoutSuccessEventHandler.java @@ -27,7 +27,7 @@ import java.util.Optional; */ @Slf4j @Component -public class kiccLogoutSuccessEventHandler extends AbstractLogoutSuccessEventHandler { +public class KiccLogoutSuccessEventHandler extends AbstractLogoutSuccessEventHandler { /** * 处理退出成功方法 @@ -37,34 +37,21 @@ public class kiccLogoutSuccessEventHandler extends AbstractLogoutSuccessEventHan */ @Override public void handle(Authentication authentication) { + Long startTime = System.currentTimeMillis(); log.info("用户:{} 退出成功", authentication.getPrincipal()); SecurityContextHolder.getContext().setAuthentication(authentication); - KiccUser kiccUser = SecurityUtils.getUser(authentication); - OperLog operLog = SysLogUtils.getSysLog(); operLog.setTitle("退出成功"); - // 发送异步日志事件 - Long startTime = System.currentTimeMillis(); - Long endTime = System.currentTimeMillis(); - operLog.setExecuteTime((endTime - startTime) + "毫秒"); - // 设置对应的token WebUtil.getRequest().ifPresent(request -> operLog.setOperParam(request.getHeader(HttpHeaders.AUTHORIZATION))); - // 这边设置ServiceId if (authentication instanceof OAuth2Authentication) { OAuth2Authentication auth2Authentication = (OAuth2Authentication) authentication; operLog.setServiceId(auth2Authentication.getOAuth2Request().getClientId()); } - - if (Optional.ofNullable(kiccUser).isPresent()) { - operLog.setCreateById(kiccUser.getId()); - operLog.setCreateByName(kiccUser.getUsername()); - - operLog.setUpdateById(kiccUser.getId()); - operLog.setUpdateByName(kiccUser.getUsername()); - } - + Long endTime = System.currentTimeMillis(); + operLog.setExecuteTime((endTime - startTime) + "毫秒"); + // 发送异步日志事件 SpringContextHolderUtil.publishEvent(new SysLogEvent(operLog)); } diff --git a/kicc-common/kicc-common-log/src/main/java/com/cloud/kicc/common/log/aspect/SysLogAspect.java b/kicc-common/kicc-common-log/src/main/java/com/cloud/kicc/common/log/aspect/SysLogAspect.java index f98d9116..21c35c9a 100644 --- a/kicc-common/kicc-common-log/src/main/java/com/cloud/kicc/common/log/aspect/SysLogAspect.java +++ b/kicc-common/kicc-common-log/src/main/java/com/cloud/kicc/common/log/aspect/SysLogAspect.java @@ -27,31 +27,25 @@ public class SysLogAspect { @Around("@annotation(sysLog)") @SneakyThrows public Object around(ProceedingJoinPoint point, SysLog sysLog) { + Long startTime = System.currentTimeMillis(); String strClassName = point.getTarget().getClass().getName(); String strMethodName = point.getSignature().getName(); log.debug("[类名]:{},[方法]:{}", strClassName, strMethodName); - OperLog operLog = SysLogUtils.getSysLog(); operLog.setTitle(sysLog.value()); - - // 发送异步日志事件 - Long startTime = System.currentTimeMillis(); Object obj; - try { obj = point.proceed(); - } - catch (Exception e) { + } catch (Exception e) { operLog.setType(LogTypeEnum.ERROR.getType()); operLog.setErrorMsg(e.getMessage()); throw e; - } - finally { + } finally { Long endTime = System.currentTimeMillis(); operLog.setExecuteTime((endTime - startTime) + "毫秒"); + // 发送异步日志事件 SpringContextHolderUtil.publishEvent(new SysLogEvent(operLog)); } - return obj; } diff --git a/kicc-common/kicc-common-log/src/main/java/com/cloud/kicc/common/log/util/SysLogUtils.java b/kicc-common/kicc-common-log/src/main/java/com/cloud/kicc/common/log/util/SysLogUtils.java index 9dc7e8a6..85967e08 100644 --- a/kicc-common/kicc-common-log/src/main/java/com/cloud/kicc/common/log/util/SysLogUtils.java +++ b/kicc-common/kicc-common-log/src/main/java/com/cloud/kicc/common/log/util/SysLogUtils.java @@ -1,5 +1,6 @@ package com.cloud.kicc.common.log.util; +import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.URLUtil; import cn.hutool.extra.servlet.ServletUtil; import cn.hutool.http.HttpUtil; @@ -35,9 +36,7 @@ public class SysLogUtils { HttpServletRequest request = ((ServletRequestAttributes) Objects .requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest(); OperLog sysLog = new OperLog(); - sysLog.setOperIp(ServletUtil.getClientIP(request)); - sysLog.setType(LogTypeEnum.NORMAL.getType()); sysLog.setOperAddr(ServletUtil.getClientIP(request)); sysLog.setOperUrl(URLUtil.getPath(request.getRequestURI())); @@ -47,12 +46,13 @@ public class SysLogUtils { sysLog.setClientId(getClientId(request)); sysLog.setServiceId(getClientId(request)); sysLog.setOperTime(LocalDateTime.now()); - Objects.requireNonNull(getUser()); - sysLog.setOperName(getUser().getUsername()); - sysLog.setCreateById(getUser().getId()); - sysLog.setCreateByName(getUser().getUsername()); - sysLog.setUpdateById(getUser().getId()); - sysLog.setUpdateByName(getUser().getUsername()); + if (ObjectUtil.isNotEmpty(getUser())) { + sysLog.setOperName(getUser().getUsername()); + sysLog.setCreateById(getUser().getId()); + sysLog.setCreateByName(getUser().getUsername()); + sysLog.setUpdateById(getUser().getId()); + sysLog.setUpdateByName(getUser().getUsername()); + } return sysLog; } diff --git a/kicc-ui/src/store/modules/lock.ts b/kicc-ui/src/store/modules/lock.ts index 78ae17b1..2f51fde1 100644 --- a/kicc-ui/src/store/modules/lock.ts +++ b/kicc-ui/src/store/modules/lock.ts @@ -56,6 +56,7 @@ export const useLockStore = defineStore({ goHome: false, unLock: true }); + debugger if (res) this.resetLockInfo(); return res; } catch (error) { diff --git a/kicc-ui/src/store/modules/user.ts b/kicc-ui/src/store/modules/user.ts index 55cc8ea0..a03c15a1 100644 --- a/kicc-ui/src/store/modules/user.ts +++ b/kicc-ui/src/store/modules/user.ts @@ -102,7 +102,7 @@ export const useUserStore = defineStore({ try { const { goHome = true, unLock = false, ...loginParams } = params; const data = await loginApi(loginParams, unLock && { - // 使用微服务提供的专属客户端不需要写验证码进行登录 + // 使用微服务提供的锁屏专属客户端不需要写验证码进行登录 clientId: 'kicc_lock', clientSecret: 'kicc_lock' });