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