!106 feat(syslog): 操作日志和登录日志记录操作人密级
Merge pull request !106 from wsm/feature/log_sec_level
This commit is contained in:
@@ -60,7 +60,12 @@ public class LogDTO implements Serializable {
|
|||||||
* 客户终端类型 pc:电脑端 app:手机端 h5:移动网页端
|
* 客户终端类型 pc:电脑端 app:手机端 h5:移动网页端
|
||||||
*/
|
*/
|
||||||
private String clientType;
|
private String clientType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 操作人密级(3非密,4一般,5重要)
|
||||||
|
*/
|
||||||
|
private Integer userSecurityLevel;
|
||||||
|
|
||||||
public LogDTO(){
|
public LogDTO(){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package org.jeecg.common.aspect;
|
|||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.alibaba.fastjson.serializer.PropertyFilter;
|
import com.alibaba.fastjson.serializer.PropertyFilter;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.shiro.SecurityUtils;
|
import org.apache.shiro.SecurityUtils;
|
||||||
import org.aspectj.lang.JoinPoint;
|
import org.aspectj.lang.JoinPoint;
|
||||||
import org.aspectj.lang.ProceedingJoinPoint;
|
import org.aspectj.lang.ProceedingJoinPoint;
|
||||||
@@ -39,6 +40,7 @@ import java.util.Date;
|
|||||||
* @email jeecgos@163.com
|
* @email jeecgos@163.com
|
||||||
* @Date 2018年1月14日
|
* @Date 2018年1月14日
|
||||||
*/
|
*/
|
||||||
|
@Slf4j
|
||||||
@Aspect
|
@Aspect
|
||||||
@Component
|
@Component
|
||||||
public class AutoLogAspect {
|
public class AutoLogAspect {
|
||||||
@@ -66,51 +68,55 @@ public class AutoLogAspect {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void saveSysLog(ProceedingJoinPoint joinPoint, long time, Object obj) {
|
private void saveSysLog(ProceedingJoinPoint joinPoint, long time, Object obj) {
|
||||||
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
|
try {
|
||||||
Method method = signature.getMethod();
|
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
|
||||||
|
Method method = signature.getMethod();
|
||||||
|
|
||||||
LogDTO dto = new LogDTO();
|
LogDTO dto = new LogDTO();
|
||||||
AutoLog syslog = method.getAnnotation(AutoLog.class);
|
AutoLog syslog = method.getAnnotation(AutoLog.class);
|
||||||
if(syslog != null){
|
if(syslog != null){
|
||||||
//update-begin-author:taoyan date:
|
//update-begin-author:taoyan date:
|
||||||
String content = syslog.value();
|
String content = syslog.value();
|
||||||
if(syslog.module()== ModuleType.ONLINE){
|
if(syslog.module()== ModuleType.ONLINE){
|
||||||
content = getOnlineLogContent(obj, content);
|
content = getOnlineLogContent(obj, content);
|
||||||
|
}
|
||||||
|
//注解上的描述,操作日志内容
|
||||||
|
dto.setLogType(syslog.logType());
|
||||||
|
dto.setLogContent(content);
|
||||||
}
|
}
|
||||||
//注解上的描述,操作日志内容
|
|
||||||
dto.setLogType(syslog.logType());
|
//请求的方法名
|
||||||
dto.setLogContent(content);
|
String className = joinPoint.getTarget().getClass().getName();
|
||||||
|
String methodName = signature.getName();
|
||||||
|
dto.setMethod(className + "." + methodName + "()");
|
||||||
|
|
||||||
|
|
||||||
|
//设置操作类型
|
||||||
|
if (CommonConstant.LOG_TYPE_2 == dto.getLogType()) {
|
||||||
|
dto.setOperateType(getOperateType(methodName, syslog.operateType()));
|
||||||
|
}
|
||||||
|
|
||||||
|
//获取request
|
||||||
|
HttpServletRequest request = SpringContextUtils.getHttpServletRequest();
|
||||||
|
//请求的参数
|
||||||
|
dto.setRequestParam(getReqestParams(request,joinPoint));
|
||||||
|
//设置IP地址
|
||||||
|
dto.setIp(IpUtils.getIpAddr(request));
|
||||||
|
//获取登录用户信息
|
||||||
|
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
||||||
|
if(sysUser!=null){
|
||||||
|
dto.setUserid(sysUser.getUsername());
|
||||||
|
dto.setUsername(sysUser.getRealname());
|
||||||
|
dto.setUserSecurityLevel(sysUser.getUserSecurityLevel());
|
||||||
|
}
|
||||||
|
//耗时
|
||||||
|
dto.setCostTime(time);
|
||||||
|
dto.setCreateTime(new Date());
|
||||||
|
//保存系统日志
|
||||||
|
baseCommonService.addLog(dto);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.warn("【系统日志-操作日志切面】记录操作日志异常,不影响业务执行, method: {}, error: {}", joinPoint.getSignature().toShortString(), e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
//请求的方法名
|
|
||||||
String className = joinPoint.getTarget().getClass().getName();
|
|
||||||
String methodName = signature.getName();
|
|
||||||
dto.setMethod(className + "." + methodName + "()");
|
|
||||||
|
|
||||||
|
|
||||||
//设置操作类型
|
|
||||||
if (CommonConstant.LOG_TYPE_2 == dto.getLogType()) {
|
|
||||||
dto.setOperateType(getOperateType(methodName, syslog.operateType()));
|
|
||||||
}
|
|
||||||
|
|
||||||
//获取request
|
|
||||||
HttpServletRequest request = SpringContextUtils.getHttpServletRequest();
|
|
||||||
//请求的参数
|
|
||||||
dto.setRequestParam(getReqestParams(request,joinPoint));
|
|
||||||
//设置IP地址
|
|
||||||
dto.setIp(IpUtils.getIpAddr(request));
|
|
||||||
//获取登录用户信息
|
|
||||||
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
|
||||||
if(sysUser!=null){
|
|
||||||
dto.setUserid(sysUser.getUsername());
|
|
||||||
dto.setUsername(sysUser.getRealname());
|
|
||||||
|
|
||||||
}
|
|
||||||
//耗时
|
|
||||||
dto.setCostTime(time);
|
|
||||||
dto.setCreateTime(new Date());
|
|
||||||
//保存系统日志
|
|
||||||
baseCommonService.addLog(dto);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+3
-2
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
<!-- 保存日志11 -->
|
<!-- 保存日志11 -->
|
||||||
<insert id="saveLog" parameterType="Object">
|
<insert id="saveLog" parameterType="Object">
|
||||||
insert into sys_log (id, log_type, log_content, method, operate_type, request_url, request_type, request_param, ip, userid, username, cost_time, create_time,create_by, tenant_id, client_type)
|
insert into sys_log (id, log_type, log_content, method, operate_type, request_url, request_type, request_param, ip, userid, username, cost_time, create_time,create_by, tenant_id, client_type, user_security_level)
|
||||||
values(
|
values(
|
||||||
#{dto.id,jdbcType=VARCHAR},
|
#{dto.id,jdbcType=VARCHAR},
|
||||||
#{dto.logType,jdbcType=INTEGER},
|
#{dto.logType,jdbcType=INTEGER},
|
||||||
@@ -21,7 +21,8 @@
|
|||||||
#{dto.createTime,jdbcType=TIMESTAMP},
|
#{dto.createTime,jdbcType=TIMESTAMP},
|
||||||
#{dto.createBy,jdbcType=VARCHAR},
|
#{dto.createBy,jdbcType=VARCHAR},
|
||||||
#{dto.tenantId,jdbcType=INTEGER},
|
#{dto.tenantId,jdbcType=INTEGER},
|
||||||
#{dto.clientType,jdbcType=VARCHAR}
|
#{dto.clientType,jdbcType=VARCHAR},
|
||||||
|
#{dto.userSecurityLevel,jdbcType=INTEGER}
|
||||||
)
|
)
|
||||||
</insert>
|
</insert>
|
||||||
|
|
||||||
|
|||||||
+1
@@ -82,6 +82,7 @@ public class BaseCommonServiceImpl implements BaseCommonService {
|
|||||||
if(user!=null){
|
if(user!=null){
|
||||||
sysLog.setUserid(user.getUsername());
|
sysLog.setUserid(user.getUsername());
|
||||||
sysLog.setUsername(user.getRealname());
|
sysLog.setUsername(user.getRealname());
|
||||||
|
sysLog.setUserSecurityLevel(user.getUserSecurityLevel());
|
||||||
}
|
}
|
||||||
sysLog.setCreateTime(new Date());
|
sysLog.setCreateTime(new Date());
|
||||||
//保存日志(异常捕获处理,防止数据太大存储失败,导致业务失败)JT-238
|
//保存日志(异常捕获处理,防止数据太大存储失败,导致业务失败)JT-238
|
||||||
|
|||||||
+5
@@ -120,4 +120,9 @@ public class SysLog implements Serializable {
|
|||||||
*/
|
*/
|
||||||
private Integer tenantId;
|
private Integer tenantId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 操作人密级(3非密,4一般,5重要)
|
||||||
|
*/
|
||||||
|
private Integer userSecurityLevel;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ YYYYMMDD_描述.sql
|
|||||||
|------|------|------|------|
|
|------|------|------|------|
|
||||||
| 2026-07-09 | DML | `20260709_新增督办状态字典.sql` | 新增 super_status 字典(未开始/督办中/已完成) |
|
| 2026-07-09 | DML | `20260709_新增督办状态字典.sql` | 新增 super_status 字典(未开始/督办中/已完成) |
|
||||||
| 2026-07-09 | DML | `20260709_新增反馈任务状态字典.sql` | 新增 feedback_status 字典(未开始/进行中/已完成) |
|
| 2026-07-09 | DML | `20260709_新增反馈任务状态字典.sql` | 新增 feedback_status 字典(未开始/进行中/已完成) |
|
||||||
|
| 2026-08-05 | DDL | `20260805_系统日志表新增操作人密级字段.sql` | sys_log 新增 user_security_level 列,记录操作人密级 |
|
||||||
|
|
||||||
## 使用方式
|
## 使用方式
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
-- 系统日志表新增操作人密级字段
|
||||||
|
-- 记录操作日志/登录日志时,带上操作人密级,取值与 sys_user.user_security_level 一致
|
||||||
|
-- 字典:user_security_level(3非密,4一般,5重要)
|
||||||
|
-- 变更日期:2026-08-05
|
||||||
|
ALTER TABLE `sys_log`
|
||||||
|
ADD COLUMN `user_security_level` tinyint(1) NULL DEFAULT NULL COMMENT '操作人密级(3非密,4一般,5重要)' AFTER `client_type`;
|
||||||
Reference in New Issue
Block a user