刘帅
2026-09-17 12732229b53d2280074cea3f91f3aa67b578ac7f
cloud-server-management/src/main/java/com/dsh/guns/modular/system/controller/system/SensitiveDataController.java
@@ -30,7 +30,7 @@
    public Map<String, Object> appUser(@PathVariable Integer id) {
        assertAdmin();
        Map<String, Object> result = appUserClient.sensitiveAppUser(id);
        writeAudit("app-user", id, result == null ? "NOT_FOUND" : "SUCCESS");
        writeAudit("app-user", id, userName(result), result == null ? "NOT_FOUND" : "SUCCESS");
        return result;
    }
@@ -46,7 +46,7 @@
            result.put("phone", employee.getPhone());
            result.put("idCard", employee.getIdCard());
        }
        writeAudit("employee", id, result == null ? "NOT_FOUND" : "SUCCESS");
        writeAudit("employee", id, employee == null ? null : employee.getName(), result == null ? "NOT_FOUND" : "SUCCESS");
        return result;
    }
@@ -54,7 +54,7 @@
    public Map<String, Object> student(@PathVariable Integer id) {
        assertAdmin();
        Map<String, Object> result = appUserClient.sensitiveStudent(id);
        writeAudit("student", id, result == null ? "NOT_FOUND" : "SUCCESS");
        writeAudit("student", id, userName(result), result == null ? "NOT_FOUND" : "SUCCESS");
        return result;
    }
@@ -64,7 +64,7 @@
        }
    }
    private void writeAudit(String resource, Integer targetUserId, String result) {
    private void writeAudit(String resource, Integer targetUserId, String targetUserName, String result) {
        Map<String, Object> audit = new HashMap<String, Object>();
        audit.put("traceId", UUID.randomUUID().toString().replace("-", ""));
        audit.put("sourceService", "mb-cloud-management");
@@ -74,11 +74,18 @@
        audit.put("operationName", "超级管理员查看敏感信息");
        audit.put("requestMethod", "GET");
        audit.put("requestUri", "/system/sensitive/" + resource + "/" + targetUserId);
        audit.put("requestParams", "targetUserId=" + targetUserId);
        // 敏感信息访问需同时记录对象名称,避免日志中只有无法识别的 ID。
        audit.put("requestParams", "targetUserId=" + targetUserId + ", targetUserName="
                + (targetUserName == null ? "-" : targetUserName));
        audit.put("userId", UserExt.getUser().getId());
        audit.put("userAccount", "admin");
        audit.put("result", result);
        audit.put("createdAt", new Date());
        auditWriter.append(audit);
    }
    private String userName(Map<String, Object> user) {
        if (user == null || user.get("name") == null) return null;
        return String.valueOf(user.get("name"));
    }
}