微调
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
package com.njcn.gather.system.config.controller;
|
||||
package com.njcn.gather.system.cfg.controller;
|
||||
|
||||
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||
import com.njcn.common.pojo.constant.OperateType;
|
||||
@@ -6,9 +6,9 @@ import com.njcn.common.pojo.enums.common.LogEnum;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.common.utils.LogUtil;
|
||||
import com.njcn.gather.system.config.pojo.param.SysTestConfigParam;
|
||||
import com.njcn.gather.system.config.pojo.po.SysTestConfig;
|
||||
import com.njcn.gather.system.config.service.ISysTestConfigService;
|
||||
import com.njcn.gather.system.cfg.pojo.param.SysTestConfigParam;
|
||||
import com.njcn.gather.system.cfg.pojo.po.SysTestConfig;
|
||||
import com.njcn.gather.system.cfg.service.ISysTestConfigService;
|
||||
import com.njcn.web.controller.BaseController;
|
||||
import com.njcn.web.utils.HttpResultUtil;
|
||||
import io.swagger.annotations.Api;
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.njcn.gather.system.config.mapper;
|
||||
package com.njcn.gather.system.cfg.mapper;
|
||||
|
||||
import com.github.yulichang.base.MPJBaseMapper;
|
||||
import com.njcn.gather.system.config.pojo.po.SysTestConfig;
|
||||
import com.njcn.gather.system.cfg.pojo.po.SysTestConfig;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.njcn.gather.system.config.pojo.param;
|
||||
package com.njcn.gather.system.cfg.pojo.param;
|
||||
|
||||
import com.njcn.common.pojo.constant.PatternRegex;
|
||||
import com.njcn.gather.system.pojo.constant.SystemValidMessage;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.njcn.gather.system.config.pojo.po;
|
||||
package com.njcn.gather.system.cfg.pojo.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
@@ -7,7 +7,6 @@ import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.njcn.gather.system.config.service;
|
||||
package com.njcn.gather.system.cfg.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.njcn.gather.system.config.pojo.param.SysTestConfigParam;
|
||||
import com.njcn.gather.system.config.pojo.po.SysTestConfig;
|
||||
import com.njcn.gather.system.cfg.pojo.param.SysTestConfigParam;
|
||||
import com.njcn.gather.system.cfg.pojo.po.SysTestConfig;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
@@ -1,14 +1,14 @@
|
||||
package com.njcn.gather.system.config.service.impl;
|
||||
package com.njcn.gather.system.cfg.service.impl;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||
import com.njcn.common.pojo.enums.common.DataStateEnum;
|
||||
import com.njcn.gather.system.config.mapper.SysTestConfigMapper;
|
||||
import com.njcn.gather.system.config.pojo.param.SysTestConfigParam;
|
||||
import com.njcn.gather.system.config.pojo.po.SysTestConfig;
|
||||
import com.njcn.gather.system.config.service.ISysTestConfigService;
|
||||
import com.njcn.gather.system.cfg.mapper.SysTestConfigMapper;
|
||||
import com.njcn.gather.system.cfg.pojo.param.SysTestConfigParam;
|
||||
import com.njcn.gather.system.cfg.pojo.po.SysTestConfig;
|
||||
import com.njcn.gather.system.cfg.service.ISysTestConfigService;
|
||||
import com.njcn.gather.system.dictionary.pojo.po.DictData;
|
||||
import com.njcn.gather.system.dictionary.service.IDictDataService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.njcn.gather.system.config;
|
||||
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import com.njcn.common.bean.CustomCacheUtil;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2025-03-24
|
||||
*/
|
||||
@Configuration
|
||||
public class CustomCacheConfig {
|
||||
|
||||
/**
|
||||
* 将自定缓存工具类注入到spring容器中
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public CustomCacheUtil customCacheUtil() {
|
||||
CustomCacheUtil customCacheUtil = SpringUtil.getBean(CustomCacheUtil.CACHE_NAME);
|
||||
return customCacheUtil;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,13 +3,16 @@ package com.njcn.gather.system.log.aop;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.db.mybatisplus.constant.UserConstant;
|
||||
import com.njcn.gather.system.log.pojo.enums.LogLevelEnum;
|
||||
import com.njcn.gather.system.log.pojo.enums.LogOperationTypeEnum;
|
||||
import com.njcn.gather.system.log.pojo.enums.LogResponseEnum;
|
||||
import com.njcn.gather.system.log.pojo.po.SysLogAudit;
|
||||
import com.njcn.gather.system.log.service.ISysLogAuditService;
|
||||
import com.njcn.gather.user.user.pojo.param.SysUserParam;
|
||||
import com.njcn.gather.user.user.pojo.po.SysUser;
|
||||
import com.njcn.gather.user.user.service.ISysUserService;
|
||||
import com.njcn.web.utils.RequestUtil;
|
||||
@@ -28,6 +31,7 @@ import java.lang.reflect.Method;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.LinkedBlockingDeque;
|
||||
@@ -45,10 +49,10 @@ public class LogAdvice implements ApplicationListener<ContextRefreshedEvent> {
|
||||
|
||||
private final ISysLogAuditService sysLogAuditService;
|
||||
private final ISysUserService sysUserService;
|
||||
private final List<String> IGNORE_METHOD = new ArrayList<>(Arrays.asList("login"));
|
||||
|
||||
private BlockingQueue<SysLogAudit> logQueue = new LinkedBlockingDeque<>();
|
||||
|
||||
// @Pointcut(value = "execution(* com.njcn.gather..controller.*(..))")
|
||||
// @Pointcut(value = "execution(* com.njcn.gather..controller.*.*(..)) && !execution(* com.njcn.gather..controller.AuthController.*(..))")
|
||||
@Pointcut(value = "execution(* com.njcn.gather..controller.*.*(..))")
|
||||
public void logPointcut() {
|
||||
@@ -56,12 +60,22 @@ public class LogAdvice implements ApplicationListener<ContextRefreshedEvent> {
|
||||
|
||||
@Around("logPointcut()")
|
||||
public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
|
||||
String name = joinPoint.getSignature().getName();
|
||||
String username = "";
|
||||
String userId = RequestUtil.getUserId();
|
||||
if (StrUtil.isNotBlank(userId)) {
|
||||
SysUser user = sysUserService.getById(RequestUtil.getUserId());
|
||||
if (ObjectUtil.isNotNull(user)) {
|
||||
username = user.getName();
|
||||
// 因为刚开始登录时无法获取到token,针对login方法单独处理
|
||||
if (IGNORE_METHOD.contains(name)) {
|
||||
Object[] args = joinPoint.getArgs();
|
||||
Object arg = args[0];
|
||||
if (arg instanceof SysUserParam.LoginParam) {
|
||||
username = ((SysUserParam.LoginParam) arg).getUsername();
|
||||
}
|
||||
} else {
|
||||
String userId = RequestUtil.getUserId();
|
||||
if (StrUtil.isNotBlank(userId)) {
|
||||
SysUser user = sysUserService.getById(RequestUtil.getUserId());
|
||||
if (ObjectUtil.isNotNull(user)) {
|
||||
username = user.getName();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,7 +83,16 @@ public class LogAdvice implements ApplicationListener<ContextRefreshedEvent> {
|
||||
try {
|
||||
sysLogAuditService.scheduleRemoveLog();
|
||||
result = joinPoint.proceed();
|
||||
addLogToQueue(joinPoint, "".equals(username) ? UserConstant.UNKNOWN_USER_ID : username, LogOperationTypeEnum.OPERATE.getMsg(), 1, LogLevelEnum.INFO.getCode(), 0);
|
||||
if (result instanceof HttpResult) {
|
||||
HttpResult result1 = (HttpResult) result;
|
||||
if (CommonResponseEnum.SUCCESS.getCode().equals(result1.getCode())) {
|
||||
addLogToQueue(joinPoint, "".equals(username) ? UserConstant.UNKNOWN_USER_ID : username, LogOperationTypeEnum.OPERATE.getMsg(), 1, LogLevelEnum.INFO.getCode(), 0);
|
||||
} else {
|
||||
addLogToQueue(joinPoint, "".equals(username) ? UserConstant.UNKNOWN_USER_ID : username, LogOperationTypeEnum.OPERATE.getMsg(), 0, LogLevelEnum.INFO.getCode(), 0);
|
||||
}
|
||||
} else {
|
||||
addLogToQueue(joinPoint, "".equals(username) ? UserConstant.UNKNOWN_USER_ID : username, LogOperationTypeEnum.OPERATE.getMsg(), 1, LogLevelEnum.INFO.getCode(), 0);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
addLogToQueue(joinPoint, "".equals(username) ? UserConstant.UNKNOWN_USER_ID : username, LogOperationTypeEnum.OPERATE.getMsg(), 0, LogLevelEnum.ERROR.getCode(), 1);
|
||||
throw e;
|
||||
|
||||
@@ -29,22 +29,6 @@ public interface ISysLogAuditService extends IService<SysLogAudit> {
|
||||
*/
|
||||
void exportCSV(SysLogParam.QueryParam param);
|
||||
|
||||
/**
|
||||
* 添加审计日志
|
||||
*
|
||||
* @param sysLogParam
|
||||
* @return 成功返回true,失败返回false
|
||||
*/
|
||||
//boolean addSysLogAudit(SysLogParam sysLogParam);
|
||||
|
||||
/**
|
||||
* 保存登录、注销日志
|
||||
*
|
||||
* @param username 用户名
|
||||
* @param type 1登录,2注销
|
||||
*/
|
||||
void saveAuthLog(String username, Integer type);
|
||||
|
||||
/**
|
||||
* 获取最大的排序值
|
||||
*
|
||||
|
||||
@@ -8,25 +8,18 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.gather.system.log.mapper.SysLogAuditMapper;
|
||||
import com.njcn.gather.system.log.pojo.enums.LogLevelEnum;
|
||||
import com.njcn.gather.system.log.pojo.enums.LogOperationTypeEnum;
|
||||
import com.njcn.gather.system.log.pojo.param.SysLogParam;
|
||||
import com.njcn.gather.system.log.pojo.po.SysLogAudit;
|
||||
import com.njcn.gather.system.log.service.ISysLogAuditService;
|
||||
import com.njcn.gather.system.log.util.CSVUtil;
|
||||
import com.njcn.web.factory.PageFactory;
|
||||
import com.njcn.web.utils.HttpServletUtil;
|
||||
import com.njcn.web.utils.RequestUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.poi.ss.usermodel.ClientAnchor;
|
||||
import org.apache.poi.xddf.usermodel.chart.*;
|
||||
import org.apache.poi.xssf.usermodel.XSSFChart;
|
||||
import org.apache.poi.xssf.usermodel.XSSFDrawing;
|
||||
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.openxmlformats.schemas.drawingml.x2006.chart.CTPieSer;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
@@ -34,7 +27,6 @@ import java.io.IOException;
|
||||
import java.net.URLEncoder;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -93,32 +85,6 @@ public class SysLogAuditServiceImpl extends ServiceImpl<SysLogAuditMapper, SysLo
|
||||
CSVUtil.export("日志数据" + sdf.format(new Date()) + ".csv", titles, keys, data);
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public boolean addSysLogAudit(SysLogParam sysLogParam) {
|
||||
// SysLogAudit sysLogAudit = new SysLogAudit();
|
||||
// BeanUtils.copyProperties(sysLogParam, sysLogAudit);
|
||||
// return this.save(sysLogAudit);
|
||||
// }
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void saveAuthLog(String username, Integer type) {
|
||||
SysLogAudit sysLogAudit = new SysLogAudit();
|
||||
sysLogAudit.setOperateType(LogOperationTypeEnum.OPERATE.getMsg());
|
||||
sysLogAudit.setLevel(LogLevelEnum.INFO.getCode());
|
||||
sysLogAudit.setWarn(0);
|
||||
sysLogAudit.setIp(RequestUtil.getUserIp());
|
||||
String typeStr = (type == 1 ? "登录" : "注销");
|
||||
sysLogAudit.setResult(typeStr + "成功");
|
||||
String now = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
||||
sysLogAudit.setRemark(username + "用户:" + now + " " + typeStr + " 成功");
|
||||
|
||||
sysLogAudit.setSort(getMaxSort() + 1);
|
||||
sysLogAudit.setCreateBy(username);
|
||||
|
||||
this.save(sysLogAudit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getMaxSort() {
|
||||
SysLogAudit log = this.lambdaQuery().orderByDesc(SysLogAudit::getSort).last("limit 1").one();
|
||||
|
||||
@@ -8,7 +8,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.njcn.common.pojo.enums.common.DataStateEnum;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.common.utils.EncryptionUtil;
|
||||
import com.njcn.gather.system.config.service.ISysTestConfigService;
|
||||
import com.njcn.gather.system.cfg.service.ISysTestConfigService;
|
||||
import com.njcn.gather.system.dictionary.pojo.enums.DictDataEnum;
|
||||
import com.njcn.gather.system.dictionary.pojo.po.DictData;
|
||||
import com.njcn.gather.system.dictionary.service.IDictDataService;
|
||||
|
||||
Reference in New Issue
Block a user