修改日志查询参数
This commit is contained in:
parent
80e553fb23
commit
375d5945ea
@ -2,7 +2,9 @@ package com.cisd.tms.modules.log.aspect;
|
||||
|
||||
import com.cisd.tms.modules.log.annotation.AuditedOperation;
|
||||
import com.cisd.tms.modules.log.dto.OperationAuditCommand;
|
||||
import com.cisd.tms.modules.log.enums.AuthLevel;
|
||||
import com.cisd.tms.modules.log.enums.OperationResult;
|
||||
import com.cisd.tms.modules.log.enums.OperatorRoleCode;
|
||||
import com.cisd.tms.modules.log.service.OperationAuditService;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
@ -67,19 +69,14 @@ public class OperationAuditAspect {
|
||||
if (attributes != null) {
|
||||
HttpServletRequest request = attributes.getRequest();
|
||||
|
||||
|
||||
//todo 是否考虑未知情况
|
||||
Object roleObj = request.getAttribute(ATTR_ROLE_CODE);
|
||||
command.setOperatorRoleCode(roleObj != null ? roleObj.toString() : "UNKNOWN_ROLE");
|
||||
command.setOperatorRoleCode(OperatorRoleCode.valueOf(roleObj.toString()));
|
||||
|
||||
Object levelObj = request.getAttribute(ATTR_AUTH_LEVEL);
|
||||
command.setOperatorAuthLevel(levelObj != null ? levelObj.toString() : "UNKNOWN_AUTH_LEVEL");
|
||||
command.setOperatorAuthLevel(AuthLevel.valueOf(levelObj.toString()));
|
||||
|
||||
command.setRemoteIp(request.getRemoteAddr());
|
||||
} else {
|
||||
// 非 HTTP 请求上下文 (如定时任务触发)
|
||||
command.setOperatorRoleCode("UNKNOWN_ROLE");
|
||||
command.setOperatorAuthLevel("UNKNOWN_AUTH_LEVEL");
|
||||
command.setRemoteIp("127.0.0.1");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,16 +1,14 @@
|
||||
package com.cisd.tms.modules.log.dto;
|
||||
|
||||
import com.cisd.tms.modules.log.enums.ActionType;
|
||||
import com.cisd.tms.modules.log.enums.ModuleCode;
|
||||
import com.cisd.tms.modules.log.enums.OperationResult;
|
||||
import com.cisd.tms.modules.log.enums.*;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class OperationAuditCommand {
|
||||
private String operatorRoleCode;
|
||||
private String operatorAuthLevel;
|
||||
private OperatorRoleCode operatorRoleCode;
|
||||
private AuthLevel operatorAuthLevel;
|
||||
private ModuleCode moduleCode;
|
||||
private ActionType actionType;
|
||||
private String remoteIp;
|
||||
|
||||
@ -12,7 +12,10 @@ import java.time.LocalDateTime;
|
||||
public class OperationAuditLogPageRequest {
|
||||
|
||||
@Schema(description = "操作人角色", example = "SYSTEM_ADMIN")
|
||||
private String operatorRoleCode;
|
||||
private OperatorRoleCode operatorRoleCode;
|
||||
|
||||
@Schema(description = "操作人认证等级", example = "FULL")
|
||||
private AuthLevel operatorAuthLevel;
|
||||
|
||||
@Schema(description = "系统模块", example = "DEVICE")
|
||||
private ModuleCode moduleCode;
|
||||
|
||||
@ -15,13 +15,13 @@ public class OperationAuditLogPageResponse {
|
||||
private String logId;
|
||||
|
||||
@Schema(description = "操作人角色", example = "SYSTEM_ADMIN")
|
||||
private String operatorRoleCode;
|
||||
private OperatorRoleCode operatorRoleCode;
|
||||
|
||||
@Schema(description = "系统模块", example = "DEVICE")
|
||||
private ModuleCode moduleCode;
|
||||
|
||||
@Schema(description = "操作人认证等级", example = "FULL")
|
||||
private String operatorAuthLevel;
|
||||
private AuthLevel operatorAuthLevel;
|
||||
|
||||
@Schema(description = "操作类型 (如: ADD, UPDATE, DELETE)", example = "UPDATE")
|
||||
private ActionType actionType;
|
||||
|
||||
@ -12,10 +12,10 @@ import java.time.LocalDateTime;
|
||||
public class OperationAuditLogResponse {
|
||||
|
||||
@Schema(description = "操作人角色代码", example = "SYSTEM_ADMIN")
|
||||
private String operatorRoleCode;
|
||||
private OperatorRoleCode operatorRoleCode;
|
||||
|
||||
@Schema(description = "操作人认证等级", example = "LEVEL_2")
|
||||
private String operatorAuthLevel;
|
||||
@Schema(description = "操作人认证等级", example = "FULL")
|
||||
private AuthLevel operatorAuthLevel;
|
||||
|
||||
@Schema(description = "系统模块代码", example = "LOG_MANAGEMENT")
|
||||
private ModuleCode moduleCode;
|
||||
|
||||
@ -16,8 +16,8 @@ public class OperationAuditLogEntity {
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
private Long id;
|
||||
private String logId;
|
||||
private String operatorRoleCode;
|
||||
private String operatorAuthLevel;
|
||||
private OperatorRoleCode operatorRoleCode;
|
||||
private AuthLevel operatorAuthLevel;
|
||||
private ModuleCode moduleCode;
|
||||
private ActionType actionType;
|
||||
private String remoteIp;
|
||||
|
||||
@ -0,0 +1,6 @@
|
||||
package com.cisd.tms.modules.log.enums;
|
||||
|
||||
public enum AuthLevel {
|
||||
LIMITED,
|
||||
FULL
|
||||
}
|
||||
@ -0,0 +1,8 @@
|
||||
package com.cisd.tms.modules.log.enums;
|
||||
|
||||
public enum OperatorRoleCode {
|
||||
SUPER_ADMIN,
|
||||
KEY_ADMIN,
|
||||
AUDIT_ADMIN,
|
||||
OPS_ADMIN
|
||||
}
|
||||
@ -32,7 +32,8 @@ public class OperationAuditLogRepositoryImpl implements OperationAuditLogReposit
|
||||
IPage<OperationAuditLogEntity> page = new Page<>(req.getPageNum(), req.getPageSize());
|
||||
LambdaQueryWrapper<OperationAuditLogEntity> wrapper = new LambdaQueryWrapper<>();
|
||||
|
||||
wrapper.eq(StringUtils.isNotBlank(req.getOperatorRoleCode()), OperationAuditLogEntity::getOperatorRoleCode, req.getOperatorRoleCode())
|
||||
wrapper.eq(req.getOperatorRoleCode() != null, OperationAuditLogEntity::getOperatorRoleCode, req.getOperatorRoleCode())
|
||||
.eq(req.getOperatorAuthLevel() != null, OperationAuditLogEntity::getOperatorAuthLevel, req.getOperatorAuthLevel())
|
||||
.eq(req.getModuleCode() != null, OperationAuditLogEntity::getModuleCode, req.getModuleCode())
|
||||
.eq(req.getActionType() != null, OperationAuditLogEntity::getActionType, req.getActionType())
|
||||
.eq(req.getOperationResult() != null, OperationAuditLogEntity::getOperationResult, req.getOperationResult())
|
||||
|
||||
@ -8,7 +8,9 @@ import com.cisd.tms.modules.log.annotation.AuditedOperation;
|
||||
import com.cisd.tms.modules.log.dto.*;
|
||||
import com.cisd.tms.modules.log.entity.OperationAuditLogEntity;
|
||||
import com.cisd.tms.modules.log.enums.AuditStatus;
|
||||
import com.cisd.tms.modules.log.enums.AuthLevel;
|
||||
import com.cisd.tms.modules.log.enums.OperationResult;
|
||||
import com.cisd.tms.modules.log.enums.OperatorRoleCode;
|
||||
import com.cisd.tms.modules.log.repository.OperationAuditLogRepository;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@ -44,8 +46,8 @@ public class OperationAuditService {
|
||||
try {
|
||||
OperationAuditLogEntity entity = new OperationAuditLogEntity();
|
||||
|
||||
entity.setOperatorRoleCode(trim(command.getOperatorRoleCode()))
|
||||
.setOperatorAuthLevel(trim(command.getOperatorAuthLevel()))
|
||||
entity.setOperatorRoleCode(command.getOperatorRoleCode())
|
||||
.setOperatorAuthLevel(command.getOperatorAuthLevel())
|
||||
.setModuleCode(command.getModuleCode())
|
||||
.setActionType(command.getActionType())
|
||||
.setRemoteIp(trim(command.getRemoteIp()))
|
||||
@ -87,10 +89,11 @@ public class OperationAuditService {
|
||||
|
||||
// 从上下文中获取刚才解析出的用户信息
|
||||
Object roleObj = request.getAttribute(ATTR_ROLE_CODE);
|
||||
command.setOperatorRoleCode(roleObj != null ? roleObj.toString() : "UNKNOWN");
|
||||
// todo 是否考虑未知情况
|
||||
command.setOperatorRoleCode(OperatorRoleCode.valueOf(roleObj.toString()));
|
||||
|
||||
Object levelObj = request.getAttribute(ATTR_AUTH_LEVEL);
|
||||
command.setOperatorAuthLevel(levelObj != null ? levelObj.toString() : "UNKNOWN");
|
||||
command.setOperatorAuthLevel(AuthLevel.valueOf(levelObj.toString()));
|
||||
|
||||
command.setRemoteIp(request.getRemoteAddr());
|
||||
command.setErrorMessage(errorMsg);
|
||||
|
||||
@ -26,8 +26,8 @@ public class OperationAuditSigner {
|
||||
|
||||
public String buildAuditPayload(OperationAuditLogEntity entity) {
|
||||
return "log_id=" + trim(entity.getLogId()) + "\n" +
|
||||
"operator_role_code=" + trim(entity.getOperatorRoleCode()) + "\n" +
|
||||
"operator_auth_level=" + trim(entity.getOperatorAuthLevel()) + "\n" +
|
||||
"operator_role_code=" + entity.getOperatorRoleCode() + "\n" +
|
||||
"operator_auth_level=" + entity.getOperatorAuthLevel() + "\n" +
|
||||
"module_code=" + entity.getModuleCode() + "\n" +
|
||||
"action_type=" + entity.getActionType() + "\n" +
|
||||
"remote_ip=" + trim(entity.getRemoteIp()) + "\n" +
|
||||
|
||||
Loading…
Reference in New Issue
Block a user