mirror of
http://192.168.1.205:9980/cf_devdept2/cf_imes_server.git
synced 2026-08-13 21:32:07 +08:00
1、恢复operationlog;2、登录性能优化;
This commit is contained in:
+2
-2
@@ -31,12 +31,12 @@ public class OperateLogDO extends BaseDO {
|
||||
/**
|
||||
* {@link #javaMethodArgs} 的最大长度
|
||||
*/
|
||||
public static final Integer JAVA_METHOD_ARGS_MAX_LENGTH = 8000;
|
||||
public static final Integer JAVA_METHOD_ARGS_MAX_LENGTH = 1000;
|
||||
|
||||
/**
|
||||
* {@link #resultData} 的最大长度
|
||||
*/
|
||||
public static final Integer RESULT_MAX_LENGTH = 4000;
|
||||
public static final Integer RESULT_MAX_LENGTH = 1000;
|
||||
|
||||
/**
|
||||
* 日志主键
|
||||
|
||||
+42
-26
@@ -12,6 +12,8 @@ import com.cf.imes.framework.common.util.servlet.ServletUtils;
|
||||
import com.cf.imes.framework.common.util.validation.ValidationUtils;
|
||||
import com.cf.imes.framework.ip.core.service.IPQueryService;
|
||||
import com.cf.imes.framework.ip.core.service.dto.IPQueryDataRespDTO;
|
||||
import com.cf.imes.framework.organ.core.context.OrganContextHolder;
|
||||
import com.cf.imes.framework.organ.core.service.OrganFrameworkService;
|
||||
import com.cf.imes.module.system.api.logger.dto.LoginLogCreateReqDTO;
|
||||
import com.cf.imes.module.system.api.sms.SmsCodeApi;
|
||||
import com.cf.imes.module.system.api.social.dto.SocialUserRespDTO;
|
||||
@@ -29,7 +31,6 @@ import com.cf.imes.module.system.enums.logger.LoginLogTypeEnum;
|
||||
import com.cf.imes.module.system.enums.logger.LoginResultEnum;
|
||||
import com.cf.imes.module.system.enums.oauth2.OAuth2ClientConstants;
|
||||
import com.cf.imes.module.system.enums.sms.SmsSceneEnum;
|
||||
import com.cf.imes.module.system.service.dept.DeptService;
|
||||
import com.cf.imes.module.system.service.logger.LoginLogService;
|
||||
import com.cf.imes.module.system.service.member.MemberService;
|
||||
import com.cf.imes.module.system.service.oauth2.OAuth2TokenService;
|
||||
@@ -41,12 +42,15 @@ import com.cf.imes.module.system.enums.ErrorCodeConstants;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.Validator;
|
||||
import org.springframework.transaction.support.TransactionTemplate;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import static com.cf.imes.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
@@ -82,7 +86,7 @@ public class AdminAuthServiceImpl implements AdminAuthService {
|
||||
@Resource
|
||||
private OrganService organService;
|
||||
@Resource
|
||||
private DeptService deptService;
|
||||
private OrganFrameworkService organFrameworkService;
|
||||
|
||||
@Resource
|
||||
private SmsCodeService smsCodeService;
|
||||
@@ -90,6 +94,9 @@ public class AdminAuthServiceImpl implements AdminAuthService {
|
||||
@Resource
|
||||
private IPQueryService ipQueryService;
|
||||
|
||||
@Autowired
|
||||
private TransactionTemplate transactionTemplate;
|
||||
|
||||
/**
|
||||
* 验证码的开关,默认为 true
|
||||
*/
|
||||
@@ -116,9 +123,10 @@ public class AdminAuthServiceImpl implements AdminAuthService {
|
||||
}
|
||||
Long organId = user.getOrganId();
|
||||
// 校验机构有效性
|
||||
organService.validOrgan(organId);
|
||||
organFrameworkService.validOrgan(organId);
|
||||
// 校验部门有效性
|
||||
deptService.validUserLoginDept(user.getDeptId());
|
||||
OrganContextHolder.setOrganId(organId);
|
||||
organFrameworkService.validDept(user.getDeptId());
|
||||
// 校验密码
|
||||
if (!userService.isPasswordMatch(password, user.getPassword())) {
|
||||
createLoginLog(user.getId(), username, organId, logTypeEnum, LoginResultEnum.BAD_CREDENTIALS);
|
||||
@@ -222,28 +230,36 @@ public class AdminAuthServiceImpl implements AdminAuthService {
|
||||
|
||||
private void createLoginLog(Long userId, String username, Long organId,
|
||||
LoginLogTypeEnum logTypeEnum, LoginResultEnum loginResult) {
|
||||
String clientIP = getClientIP();
|
||||
// 插入登录日志
|
||||
LoginLogCreateReqDTO reqDTO = new LoginLogCreateReqDTO();
|
||||
reqDTO.setLogType(logTypeEnum.getType());
|
||||
reqDTO.setTraceId(TracerUtils.getTraceId());
|
||||
reqDTO.setUserId(userId);
|
||||
reqDTO.setUserType(getUserType().getValue());
|
||||
reqDTO.setUsername(username);
|
||||
reqDTO.setUserAgent(ServletUtils.getUserAgent());
|
||||
reqDTO.setUserIp(clientIP);
|
||||
reqDTO.setResult(loginResult.getResult());
|
||||
reqDTO.setOrganId(organId);
|
||||
// 设置登录时通过ip云服务查询到的地域信息
|
||||
if (ipQueryService.serviceEnable()) {
|
||||
IPQueryDataRespDTO ipQueryDataRespDTO = ipQueryService.querySource(clientIP);
|
||||
reqDTO.setRegion(StringUtils.join(ipQueryDataRespDTO.getProv(), ipQueryDataRespDTO.getCity(), ipQueryDataRespDTO.getArea()));
|
||||
}
|
||||
loginLogService.createLoginLog(reqDTO);
|
||||
// 更新最后登录时间
|
||||
if (userId != null && Objects.equals(LoginResultEnum.SUCCESS.getResult(), loginResult.getResult())) {
|
||||
userService.updateUserLogin(userId, clientIP);
|
||||
}
|
||||
// 手动控制事务
|
||||
transactionTemplate.executeWithoutResult(status -> {
|
||||
try {
|
||||
String clientIP = getClientIP();
|
||||
// 插入登录日志
|
||||
LoginLogCreateReqDTO reqDTO = new LoginLogCreateReqDTO();
|
||||
reqDTO.setLogType(logTypeEnum.getType());
|
||||
reqDTO.setTraceId(TracerUtils.getTraceId());
|
||||
reqDTO.setUserId(userId);
|
||||
reqDTO.setUserType(getUserType().getValue());
|
||||
reqDTO.setUsername(username);
|
||||
reqDTO.setUserAgent(ServletUtils.getUserAgent());
|
||||
reqDTO.setUserIp(clientIP);
|
||||
reqDTO.setResult(loginResult.getResult());
|
||||
reqDTO.setOrganId(organId);
|
||||
// 设置登录时通过ip云服务查询到的地域信息
|
||||
if (ipQueryService.serviceEnable()) {
|
||||
IPQueryDataRespDTO ipQueryDataRespDTO = ipQueryService.querySource(clientIP);
|
||||
reqDTO.setRegion(StringUtils.join(ipQueryDataRespDTO.getProv(), ipQueryDataRespDTO.getCity(), ipQueryDataRespDTO.getArea()));
|
||||
}
|
||||
loginLogService.createLoginLog(reqDTO);
|
||||
// 更新最后登录时间
|
||||
if (userId != null && Objects.equals(LoginResultEnum.SUCCESS.getResult(), loginResult.getResult())) {
|
||||
userService.updateUserLogin(userId, clientIP);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
status.setRollbackOnly(); // 显式标记事务回滚
|
||||
log.error("login log record error", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+4
-1
@@ -254,7 +254,10 @@ public class AdminUserServiceImpl implements AdminUserService {
|
||||
|
||||
@Override
|
||||
public void updateUserLogin(Long id, String loginIp) {
|
||||
userMapper.updateById(new AdminUserDO().setId(id).setLoginIp(loginIp).setLoginDate(LocalDateTime.now()));
|
||||
userMapper.update(new LambdaUpdateWrapper<AdminUserDO>()
|
||||
.eq(AdminUserDO::getId, id)
|
||||
.set(AdminUserDO::getLoginIp, loginIp)
|
||||
.set(AdminUserDO::getLoginDate, LocalDateTime.now()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user