This commit is contained in:
caozehui
2025-03-24 15:43:20 +08:00
parent 0e1fb0e254
commit ebc52eb8ba
26 changed files with 126 additions and 194 deletions

View File

@@ -9,7 +9,6 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.njcn.gather.detection.pojo.dto.DevXiNumData;
import com.njcn.gather.detection.pojo.enums.SourceOperateCodeEnum;
import com.njcn.gather.detection.pojo.enums.SourceResponseCodeEnum;
import com.njcn.gather.detection.pojo.param.DevPhaseSequenceParam;
import com.njcn.gather.detection.pojo.param.PreDetectionParam;
import com.njcn.gather.detection.pojo.po.DevData;
import com.njcn.gather.detection.pojo.po.SourceCompareDev;
@@ -30,8 +29,8 @@ import com.njcn.gather.storage.pojo.po.AdHarmonicResult;
import com.njcn.gather.storage.pojo.po.AdNonHarmonicResult;
import com.njcn.gather.storage.service.AdHarmonicService;
import com.njcn.gather.storage.service.DetectionDataDealService;
import com.njcn.gather.system.config.pojo.po.SysTestConfig;
import com.njcn.gather.system.config.service.ISysTestConfigService;
import com.njcn.gather.system.cfg.pojo.po.SysTestConfig;
import com.njcn.gather.system.cfg.service.ISysTestConfigService;
import com.njcn.gather.system.dictionary.pojo.enums.DictDataEnum;
import com.njcn.gather.system.pojo.enums.DicDataEnum;
import com.njcn.gather.system.reg.service.ISysRegResService;

View File

@@ -32,8 +32,8 @@ import com.njcn.gather.device.service.IPqDevService;
import com.njcn.gather.monitor.pojo.po.PqMonitor;
import com.njcn.gather.monitor.service.IPqMonitorService;
import com.njcn.gather.storage.service.DetectionDataDealService;
import com.njcn.gather.system.config.pojo.po.SysTestConfig;
import com.njcn.gather.system.config.service.ISysTestConfigService;
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.pojo.po.DictType;
import com.njcn.gather.system.dictionary.service.IDictDataService;

View File

@@ -68,9 +68,6 @@ public class AdPlanParam {
@ApiModelProperty(value = "报告模板名称")
private String reportTemplateName;
@ApiModelProperty(value = "报告模板版本")
private String reportTemplateVersion;
/**
* 分页查询实体
*/

View File

@@ -108,9 +108,4 @@ public class AdPlanVO {
* 报告模板名称
*/
private String reportTemplateName;
/**
* 报告模板版本号
*/
private String reportTemplateVersion;
}

View File

@@ -41,8 +41,8 @@ import com.njcn.gather.source.service.IPqSourceService;
import com.njcn.gather.storage.pojo.param.StorageParam;
import com.njcn.gather.storage.service.AdHarmonicService;
import com.njcn.gather.storage.service.TableGenService;
import com.njcn.gather.system.config.pojo.po.SysTestConfig;
import com.njcn.gather.system.config.service.ISysTestConfigService;
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.pojo.po.DictTree;
import com.njcn.gather.system.dictionary.pojo.po.DictType;
@@ -107,8 +107,7 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
adPlanVO.setDatasourceIds(Arrays.asList(adPlan.getDatasourceId().split(StrUtil.COMMA)));
if (StrUtil.isNotBlank(adPlan.getReportTemplateId())) {
PqReport report = this.baseMapper.getPqReportById(adPlan.getReportTemplateId());
adPlanVO.setReportTemplateName(report.getName());
adPlanVO.setReportTemplateVersion(report.getVersion());
adPlanVO.setReportTemplateName(report.getName()+"_" + report.getVersion());
}
return adPlanVO;
}).collect(Collectors.toList());
@@ -149,7 +148,9 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
adPlan.setCode(this.generateCode());
if (param.getAssociateReport() == 1) {
String reportId = this.baseMapper.getReportIdByNameAndVersion(param.getReportTemplateName(), param.getReportTemplateVersion());
String reportTemplateName = param.getReportTemplateName();
String[] split = reportTemplateName.split("_");
String reportId = this.baseMapper.getReportIdByNameAndVersion(split[0], split[1]);
if (StrUtil.isNotBlank(reportId)) {
adPlan.setReportTemplateId(reportId);
}
@@ -180,7 +181,14 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
AdPlan plan2 = new AdPlan();
if (param.getAssociateReport() == 1) {
String reportId = this.baseMapper.getReportIdByNameAndVersion(param.getReportTemplateName(), param.getReportTemplateVersion());
String reportTemplateName = param.getReportTemplateName();
String[] split = reportTemplateName.split("_");
String reportId = this.baseMapper.getReportIdByNameAndVersion(split[0], split[1]);
if (plan1.getTestState() != CheckStateEnum.UNCHECKED.getValue()) {
if (!reportId.equals(plan1.getReportTemplateId())) {
throw new BusinessException(PlanResponseEnum.CANNOT_CHANGE_REPORT_WHEN_CHECKING);
}
}
if (StrUtil.isNotBlank(reportId)) {
plan2.setReportTemplateId(reportId);
}
@@ -196,15 +204,6 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
if (param.getAssociateReport() != plan1.getAssociateReport()) {
throw new BusinessException(PlanResponseEnum.CANNOT_CHANGE_REPORT_WHEN_CHECKING);
}
if (param.getAssociateReport() != plan1.getAssociateReport()) {
throw new BusinessException(PlanResponseEnum.CANNOT_CHANGE_REPORT_WHEN_CHECKING);
}
if (param.getAssociateReport() == 1) {
String reportId = this.baseMapper.getReportIdByNameAndVersion(param.getReportTemplateName(), param.getReportTemplateVersion());
if (!reportId.equals(plan1.getReportTemplateId())) {
throw new BusinessException(PlanResponseEnum.CANNOT_CHANGE_REPORT_WHEN_CHECKING);
}
}
}
BeanUtil.copyProperties(param, plan2);
@@ -352,7 +351,7 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
QueryWrapper<AdPlan> queryWrapper = new QueryWrapper<>();
if (ObjectUtil.isNotNull(queryParam)) {
queryWrapper.eq(StrUtil.isNotBlank(queryParam.getPattern()), "ad_plan.pattern", queryParam.getPattern())
.eq(StrUtil.isNotBlank(queryParam.getName()), "ad_plan.name", queryParam.getName())
.like(StrUtil.isNotBlank(queryParam.getName()), "ad_plan.name", queryParam.getName())
.eq(ObjectUtil.isNotNull(queryParam.getTestState()), "ad_plan.Test_State", queryParam.getTestState())
.eq(ObjectUtil.isNotNull(queryParam.getReportState()), "ad_plan.Report_State", queryParam.getReportState())
.eq(ObjectUtil.isNotNull(queryParam.getResult()), "ad_plan.result", queryParam.getResult());

View File

@@ -136,14 +136,4 @@ public class ReportController extends BaseController {
String methodDescribe = getMethodDescribe("listAllName");
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, pqReportService.listAllName(), methodDescribe);
}
@OperateInfo
@GetMapping("/listAllVersion")
@ApiOperation("根据名称查询指定报告模板的所有版本")
@ApiImplicitParam(name = "param", value = "查询参数", required = true)
public HttpResult<List<String>> listAllVersion(@RequestParam String name) {
String methodDescribe = getMethodDescribe("listAllVersion");
LogUtil.njcnDebug(log, "{},查询参数为:{}", methodDescribe, name);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, pqReportService.listAllVersion(name), methodDescribe);
}
}

View File

@@ -8,4 +8,6 @@ public interface ReportValidMessage {
String NAME_NOT_BLANK = "报告模板名称不能为空";
String VERSION_NOT_BLANK = "报告模板版本号不能为空";
String ENABLE_NOT_NULL = "报告模板的启用状态不能为空";
String NAME_PATTERN_NOT_MATCH = "报告模板名称格式不正确";
String VERSION_PATTERN_NOT_MATCH = "报告模板版本号格式不正确";
}

View File

@@ -1,5 +1,6 @@
package com.njcn.gather.report.pojo.param;
import com.njcn.common.pojo.constant.PatternRegex;
import com.njcn.gather.report.pojo.constant.ReportValidMessage;
import com.njcn.web.pojo.param.BaseParam;
import io.swagger.annotations.ApiModelProperty;
@@ -9,6 +10,7 @@ import org.springframework.web.multipart.MultipartFile;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
/**
* @author caozehui
@@ -19,10 +21,12 @@ public class ReportParam {
@ApiModelProperty(value = "报告模板名称", required = true)
@NotBlank(message = ReportValidMessage.NAME_NOT_BLANK)
@Pattern(regexp = PatternRegex.REPORT_NAME_REGEX, message = ReportValidMessage.NAME_PATTERN_NOT_MATCH)
private String name;
@ApiModelProperty(value = "版本号", required = true)
@NotBlank(message = ReportValidMessage.VERSION_NOT_BLANK)
@Pattern(regexp = PatternRegex.REPORT_VERSION_REGEX, message = ReportValidMessage.VERSION_PATTERN_NOT_MATCH)
private String version;
@ApiModelProperty(value = "描述信息", required = true)

View File

@@ -63,14 +63,6 @@ public interface IPqReportService extends IService<PqReport> {
*/
List<String> listAllName();
/**
* 根据报告name查询改模板的所有版本号
*
* @param name
* @return
*/
List<String> listAllVersion(String name);
void generateReport(DevReportParam devReportParam);
void downloadReport(DevReportParam devReportParam, HttpServletResponse response);

View File

@@ -214,17 +214,10 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
@Override
public List<String> listAllName() {
List<String> result = this.lambdaQuery()
.eq(PqReport::getState, DataStateEnum.ENABLE.getCode()).list().stream().map(PqReport::getName).distinct().collect(Collectors.toList());
return result;
}
@Override
public List<String> listAllVersion(String name) {
List<String> result = this.lambdaQuery().eq(PqReport::getName, name)
.eq(PqReport::getState, DataStateEnum.ENABLE.getCode())
.list().stream().map(PqReport::getVersion).collect(Collectors.toList());
return result;
List<PqReport> reportList = this.lambdaQuery()
.eq(PqReport::getState, DataStateEnum.ENABLE.getCode()).list();
List<String> collect = reportList.stream().map(pqReport -> pqReport.getName() + "_" + pqReport.getVersion()).collect(Collectors.toList());
return collect;
}
/**
@@ -1108,7 +1101,7 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
* @param enumByCode
* @return
*/
private XWPFTable generateTableBodyZJ(XWPFTable table,List<RawResultDataVO> rawResultDataVOS, DicDataEnum enumByCode) {
private XWPFTable generateTableBodyZJ(XWPFTable table, List<RawResultDataVO> rawResultDataVOS, DicDataEnum enumByCode) {
// 组装数据
getTableBodyDataZJ(rawResultDataVOS, enumByCode);
return table;

View File

@@ -41,8 +41,8 @@ import com.njcn.gather.storage.pojo.po.AdNonHarmonicResult;
import com.njcn.gather.storage.pojo.vo.RawDataVO;
import com.njcn.gather.storage.service.AdHarmonicService;
import com.njcn.gather.storage.service.AdNonHarmonicService;
import com.njcn.gather.system.config.pojo.po.SysTestConfig;
import com.njcn.gather.system.config.service.ISysTestConfigService;
import com.njcn.gather.system.cfg.pojo.po.SysTestConfig;
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.DictTree;
import com.njcn.gather.system.dictionary.service.IDictTreeService;

View File

@@ -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;

View File

@@ -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

View File

@@ -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;

View File

@@ -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

View File

@@ -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

View File

@@ -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;

View File

@@ -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;
}
}

View File

@@ -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;

View File

@@ -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);
/**
* 获取最大的排序值
*

View File

@@ -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();

View File

@@ -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;

View File

@@ -44,9 +44,4 @@ public interface UserValidMessage {
String LOGIN_FAILED = "登录失败,用户名或密码错误";
String TOKEN_VALID_ERROR = "非法的token";
String TOKEN_EXPIRED = "token已过期请重新登录";
String ACCESS_TOKEN_EXPIRED = "access-token已过期";
}

View File

@@ -1,8 +1,8 @@
package com.njcn.gather.user.user.controller;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.spring.SpringUtil;
import com.alibaba.fastjson.JSON;
import com.njcn.common.bean.CustomCacheUtil;
import com.njcn.common.pojo.annotation.OperateInfo;
@@ -39,26 +39,8 @@ import java.util.Map;
public class AuthController extends BaseController {
private final ISysUserService sysUserService;
private final CustomCacheUtil customCacheUtil;
// @RequestMapping("/login")
// public HttpResult<Token> login() {
// Token token = new Token();
// token.setAccessToken("bqddxxwqmfncffacvbpkuxvwvqrhln");
// HttpResult<Token> result = new HttpResult<>();
// result.setMessage("成功");
// result.setCode("A0000");
// result.setData(token);
// return result;
// }
//
// @RequestMapping("/logout")
// public HttpResult<String> logout() {
// HttpResult<String> result = new HttpResult<>();
// result.setMessage("成功");
// result.setCode("A0000");
// result.setData("退出成功");
// return result;
// }
@OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.AUTHENTICATE)
@PostMapping("/login")
@@ -67,7 +49,7 @@ public class AuthController extends BaseController {
String methodDescribe = getMethodDescribe("login");
LogUtil.njcnDebug(log, "{},登录参数为:{}", methodDescribe, param);
SysUser user = sysUserService.getUserByLoginNameAndPassword(param.getUsername(), param.getPassword());
if (user == null) {
if (ObjectUtil.isNull(user)) {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, UserValidMessage.LOGIN_FAILED);
} else {
String accessToken = JwtUtil.getAccessToken(user.getId());
@@ -81,10 +63,7 @@ public class AuthController extends BaseController {
token.setUserInfo(map);
CustomCacheUtil customCacheUtil = SpringUtil.getBean(CustomCacheUtil.CACHE_NAME);
customCacheUtil.putWithExpireTime(accessToken, JSON.toJSONString(user), DateUnit.DAY.getMillis() * 2);
//sysLogAuditService.saveAuthLog(user.getName(), 1);
customCacheUtil.putWithExpireTime(accessToken, JSON.toJSONString(user), DateUnit.DAY.getMillis() * Integer.MAX_VALUE);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, token, methodDescribe);
}
}
@@ -97,13 +76,8 @@ public class AuthController extends BaseController {
LogUtil.njcnDebug(log, "{},注销登录", methodDescribe);
String accessToken = RequestUtil.getAccessToken();
if (StrUtil.isNotBlank(accessToken)) {
CustomCacheUtil customCacheUtil = SpringUtil.getBean(CustomCacheUtil.CACHE_NAME);
customCacheUtil.remove(accessToken);
Map<String, Object> map = JwtUtil.parseToken(accessToken);
SysUser user = sysUserService.getById((String) map.get(SecurityConstants.USER_ID));
//sysLogAuditService.saveAuthLog(user.getName(), 2);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
}
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
@@ -124,19 +98,15 @@ public class AuthController extends BaseController {
SysUser user = sysUserService.getById(userId);
String accessTokenNew = JwtUtil.getAccessToken(userId);
String refreshTokenNew = JwtUtil.getRefreshToken(accessTokenNew);
//String refreshTokenNew = JwtUtil.getRefreshToken(accessTokenNew);
token.setAccessToken(accessTokenNew);
token.setRefreshToken(refreshTokenNew);
token.setRefreshToken(accessToken);
CustomCacheUtil customCacheUtil = SpringUtil.getBean(CustomCacheUtil.CACHE_NAME);
customCacheUtil.remove(accessToken);
customCacheUtil.putWithExpireTime(accessTokenNew, JSON.toJSONString(user), DateUnit.DAY.getMillis() * 2);
customCacheUtil.putWithExpireTime(accessTokenNew, JSON.toJSONString(user), DateUnit.DAY.getMillis() * Integer.MAX_VALUE);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, token, methodDescribe);
} else {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
}
}
}

View File

@@ -1,9 +1,12 @@
package com.njcn.gather.user.user.filter;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.njcn.common.pojo.constant.SecurityConstants;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.JwtUtil;
import com.njcn.gather.user.pojo.constant.UserValidMessage;
import com.njcn.web.utils.HttpResultUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.Ordered;
import org.springframework.stereotype.Component;
@@ -35,16 +38,6 @@ public class AuthGlobalFilter implements Filter, Ordered {
HttpServletRequest req = (HttpServletRequest) request;
HttpServletResponse res = (HttpServletResponse) response;
//设置允许跨域的配置
// 这里填写允许进行跨域的主机ip正式上线时可以动态配置具体允许的域名和IP
//rep.setHeader("Access-Control-Allow-Origin", "*");
// 允许的访问方法
//rep.setHeader("Access-Control-Allow-Methods", "POST, GET, PUT, OPTIONS, DELETE, PATCH");
// Access-Control-Max-Age 用于 CORS 相关配置的缓存
//rep.setHeader("Access-Control-Max-Age", "3600");
//rep.setHeader("Access-Control-Allow-Headers", "token,Origin, X-Requested-With, Content-Type, Accept");
res.setCharacterEncoding("UTF-8");
res.setContentType("application/json; charset=utf-8");
@@ -55,24 +48,29 @@ public class AuthGlobalFilter implements Filter, Ordered {
String accessTokenStr = req.getHeader(SecurityConstants.AUTHORIZATION_KEY);
String isRefreshToken = req.getHeader(SecurityConstants.IS_REFRESH_TOKEN);
if (StrUtil.isBlank(accessTokenStr) || !accessTokenStr.startsWith(SecurityConstants.AUTHORIZATION_PREFIX)) {
res.getWriter().write("{\"code\": 4001, \"message\":\"" + UserValidMessage.TOKEN_VALID_ERROR + "\"}"); //前端重定向到登录页面
HttpResult httpResult = new HttpResult<>(CommonResponseEnum.PARSE_TOKEN_ERROR.getCode(), CommonResponseEnum.PARSE_TOKEN_ERROR.getMessage());
res.getWriter().write(JSON.toJSONString(httpResult)); //前端重定向到登录页面
return;
}
String accessToken = accessTokenStr.substring(SecurityConstants.AUTHORIZATION_PREFIX.length());
try {
if (StrUtil.isBlank(accessToken) || !JwtUtil.verifyToken(accessToken)) {
res.getWriter().write("{\"code\": 4001, \"message\":\"" + UserValidMessage.TOKEN_VALID_ERROR + "\"}"); //前端重定向到登录页面
HttpResult httpResult = new HttpResult<>(CommonResponseEnum.PARSE_TOKEN_ERROR.getCode(), CommonResponseEnum.PARSE_TOKEN_ERROR.getMessage());
res.getWriter().write(JSON.toJSONString(httpResult));
} else if (JwtUtil.isExpired(accessToken)) {
if ("true".equals(isRefreshToken)) {
res.getWriter().write("{\"code\": 4001, \"message\":\"" + UserValidMessage.TOKEN_EXPIRED + "\"}"); //前端重定向到登录页面
HttpResult httpResult = new HttpResult<>(CommonResponseEnum.PARSE_TOKEN_ERROR.getCode(), CommonResponseEnum.PARSE_TOKEN_ERROR.getMessage());
res.getWriter().write(JSON.toJSONString(httpResult));
} else {
res.getWriter().write("{\"code\": 401, \"message\":\"" + UserValidMessage.ACCESS_TOKEN_EXPIRED + "\"}"); //前端发起refreshToken请求
HttpResult httpResult = new HttpResult<>(CommonResponseEnum.TOKEN_EXPIRE_JWT.getCode(), CommonResponseEnum.TOKEN_EXPIRE_JWT.getMessage());
res.getWriter().write(JSON.toJSONString(httpResult));
}
} else {
filterChain.doFilter(req, res);
}
} catch (Exception e) {
res.getWriter().write("{\"code\": 4001, \"message\":\"" + UserValidMessage.TOKEN_VALID_ERROR + "\"}");
HttpResult httpResult = new HttpResult<>(CommonResponseEnum.PARSE_TOKEN_ERROR.getCode(), CommonResponseEnum.PARSE_TOKEN_ERROR.getMessage());
res.getWriter().write(JSON.toJSONString(httpResult));
}
}
}