微调
This commit is contained in:
@@ -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.dto.DevXiNumData;
|
||||||
import com.njcn.gather.detection.pojo.enums.SourceOperateCodeEnum;
|
import com.njcn.gather.detection.pojo.enums.SourceOperateCodeEnum;
|
||||||
import com.njcn.gather.detection.pojo.enums.SourceResponseCodeEnum;
|
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.param.PreDetectionParam;
|
||||||
import com.njcn.gather.detection.pojo.po.DevData;
|
import com.njcn.gather.detection.pojo.po.DevData;
|
||||||
import com.njcn.gather.detection.pojo.po.SourceCompareDev;
|
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.pojo.po.AdNonHarmonicResult;
|
||||||
import com.njcn.gather.storage.service.AdHarmonicService;
|
import com.njcn.gather.storage.service.AdHarmonicService;
|
||||||
import com.njcn.gather.storage.service.DetectionDataDealService;
|
import com.njcn.gather.storage.service.DetectionDataDealService;
|
||||||
import com.njcn.gather.system.config.pojo.po.SysTestConfig;
|
import com.njcn.gather.system.cfg.pojo.po.SysTestConfig;
|
||||||
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.enums.DictDataEnum;
|
||||||
import com.njcn.gather.system.pojo.enums.DicDataEnum;
|
import com.njcn.gather.system.pojo.enums.DicDataEnum;
|
||||||
import com.njcn.gather.system.reg.service.ISysRegResService;
|
import com.njcn.gather.system.reg.service.ISysRegResService;
|
||||||
|
|||||||
@@ -32,8 +32,8 @@ import com.njcn.gather.device.service.IPqDevService;
|
|||||||
import com.njcn.gather.monitor.pojo.po.PqMonitor;
|
import com.njcn.gather.monitor.pojo.po.PqMonitor;
|
||||||
import com.njcn.gather.monitor.service.IPqMonitorService;
|
import com.njcn.gather.monitor.service.IPqMonitorService;
|
||||||
import com.njcn.gather.storage.service.DetectionDataDealService;
|
import com.njcn.gather.storage.service.DetectionDataDealService;
|
||||||
import com.njcn.gather.system.config.pojo.po.SysTestConfig;
|
import com.njcn.gather.system.cfg.pojo.po.SysTestConfig;
|
||||||
import com.njcn.gather.system.config.service.ISysTestConfigService;
|
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.DictData;
|
||||||
import com.njcn.gather.system.dictionary.pojo.po.DictType;
|
import com.njcn.gather.system.dictionary.pojo.po.DictType;
|
||||||
import com.njcn.gather.system.dictionary.service.IDictDataService;
|
import com.njcn.gather.system.dictionary.service.IDictDataService;
|
||||||
|
|||||||
@@ -68,9 +68,6 @@ public class AdPlanParam {
|
|||||||
@ApiModelProperty(value = "报告模板名称")
|
@ApiModelProperty(value = "报告模板名称")
|
||||||
private String reportTemplateName;
|
private String reportTemplateName;
|
||||||
|
|
||||||
@ApiModelProperty(value = "报告模板版本")
|
|
||||||
private String reportTemplateVersion;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分页查询实体
|
* 分页查询实体
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -108,9 +108,4 @@ public class AdPlanVO {
|
|||||||
* 报告模板名称
|
* 报告模板名称
|
||||||
*/
|
*/
|
||||||
private String reportTemplateName;
|
private String reportTemplateName;
|
||||||
|
|
||||||
/**
|
|
||||||
* 报告模板版本号
|
|
||||||
*/
|
|
||||||
private String reportTemplateVersion;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,8 +41,8 @@ import com.njcn.gather.source.service.IPqSourceService;
|
|||||||
import com.njcn.gather.storage.pojo.param.StorageParam;
|
import com.njcn.gather.storage.pojo.param.StorageParam;
|
||||||
import com.njcn.gather.storage.service.AdHarmonicService;
|
import com.njcn.gather.storage.service.AdHarmonicService;
|
||||||
import com.njcn.gather.storage.service.TableGenService;
|
import com.njcn.gather.storage.service.TableGenService;
|
||||||
import com.njcn.gather.system.config.pojo.po.SysTestConfig;
|
import com.njcn.gather.system.cfg.pojo.po.SysTestConfig;
|
||||||
import com.njcn.gather.system.config.service.ISysTestConfigService;
|
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.DictData;
|
||||||
import com.njcn.gather.system.dictionary.pojo.po.DictTree;
|
import com.njcn.gather.system.dictionary.pojo.po.DictTree;
|
||||||
import com.njcn.gather.system.dictionary.pojo.po.DictType;
|
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)));
|
adPlanVO.setDatasourceIds(Arrays.asList(adPlan.getDatasourceId().split(StrUtil.COMMA)));
|
||||||
if (StrUtil.isNotBlank(adPlan.getReportTemplateId())) {
|
if (StrUtil.isNotBlank(adPlan.getReportTemplateId())) {
|
||||||
PqReport report = this.baseMapper.getPqReportById(adPlan.getReportTemplateId());
|
PqReport report = this.baseMapper.getPqReportById(adPlan.getReportTemplateId());
|
||||||
adPlanVO.setReportTemplateName(report.getName());
|
adPlanVO.setReportTemplateName(report.getName()+"_" + report.getVersion());
|
||||||
adPlanVO.setReportTemplateVersion(report.getVersion());
|
|
||||||
}
|
}
|
||||||
return adPlanVO;
|
return adPlanVO;
|
||||||
}).collect(Collectors.toList());
|
}).collect(Collectors.toList());
|
||||||
@@ -149,7 +148,9 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
|
|||||||
adPlan.setCode(this.generateCode());
|
adPlan.setCode(this.generateCode());
|
||||||
|
|
||||||
if (param.getAssociateReport() == 1) {
|
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)) {
|
if (StrUtil.isNotBlank(reportId)) {
|
||||||
adPlan.setReportTemplateId(reportId);
|
adPlan.setReportTemplateId(reportId);
|
||||||
}
|
}
|
||||||
@@ -180,7 +181,14 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
|
|||||||
AdPlan plan2 = new AdPlan();
|
AdPlan plan2 = new AdPlan();
|
||||||
|
|
||||||
if (param.getAssociateReport() == 1) {
|
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)) {
|
if (StrUtil.isNotBlank(reportId)) {
|
||||||
plan2.setReportTemplateId(reportId);
|
plan2.setReportTemplateId(reportId);
|
||||||
}
|
}
|
||||||
@@ -196,15 +204,6 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
|
|||||||
if (param.getAssociateReport() != plan1.getAssociateReport()) {
|
if (param.getAssociateReport() != plan1.getAssociateReport()) {
|
||||||
throw new BusinessException(PlanResponseEnum.CANNOT_CHANGE_REPORT_WHEN_CHECKING);
|
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);
|
BeanUtil.copyProperties(param, plan2);
|
||||||
@@ -352,7 +351,7 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
|
|||||||
QueryWrapper<AdPlan> queryWrapper = new QueryWrapper<>();
|
QueryWrapper<AdPlan> queryWrapper = new QueryWrapper<>();
|
||||||
if (ObjectUtil.isNotNull(queryParam)) {
|
if (ObjectUtil.isNotNull(queryParam)) {
|
||||||
queryWrapper.eq(StrUtil.isNotBlank(queryParam.getPattern()), "ad_plan.pattern", queryParam.getPattern())
|
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.getTestState()), "ad_plan.Test_State", queryParam.getTestState())
|
||||||
.eq(ObjectUtil.isNotNull(queryParam.getReportState()), "ad_plan.Report_State", queryParam.getReportState())
|
.eq(ObjectUtil.isNotNull(queryParam.getReportState()), "ad_plan.Report_State", queryParam.getReportState())
|
||||||
.eq(ObjectUtil.isNotNull(queryParam.getResult()), "ad_plan.result", queryParam.getResult());
|
.eq(ObjectUtil.isNotNull(queryParam.getResult()), "ad_plan.result", queryParam.getResult());
|
||||||
|
|||||||
@@ -136,14 +136,4 @@ public class ReportController extends BaseController {
|
|||||||
String methodDescribe = getMethodDescribe("listAllName");
|
String methodDescribe = getMethodDescribe("listAllName");
|
||||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, pqReportService.listAllName(), methodDescribe);
|
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,4 +8,6 @@ public interface ReportValidMessage {
|
|||||||
String NAME_NOT_BLANK = "报告模板名称不能为空";
|
String NAME_NOT_BLANK = "报告模板名称不能为空";
|
||||||
String VERSION_NOT_BLANK = "报告模板版本号不能为空";
|
String VERSION_NOT_BLANK = "报告模板版本号不能为空";
|
||||||
String ENABLE_NOT_NULL = "报告模板的启用状态不能为空";
|
String ENABLE_NOT_NULL = "报告模板的启用状态不能为空";
|
||||||
|
String NAME_PATTERN_NOT_MATCH = "报告模板名称格式不正确";
|
||||||
|
String VERSION_PATTERN_NOT_MATCH = "报告模板版本号格式不正确";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.njcn.gather.report.pojo.param;
|
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.gather.report.pojo.constant.ReportValidMessage;
|
||||||
import com.njcn.web.pojo.param.BaseParam;
|
import com.njcn.web.pojo.param.BaseParam;
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
@@ -9,6 +10,7 @@ import org.springframework.web.multipart.MultipartFile;
|
|||||||
|
|
||||||
import javax.validation.constraints.NotBlank;
|
import javax.validation.constraints.NotBlank;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
|
import javax.validation.constraints.Pattern;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author caozehui
|
* @author caozehui
|
||||||
@@ -19,10 +21,12 @@ public class ReportParam {
|
|||||||
|
|
||||||
@ApiModelProperty(value = "报告模板名称", required = true)
|
@ApiModelProperty(value = "报告模板名称", required = true)
|
||||||
@NotBlank(message = ReportValidMessage.NAME_NOT_BLANK)
|
@NotBlank(message = ReportValidMessage.NAME_NOT_BLANK)
|
||||||
|
@Pattern(regexp = PatternRegex.REPORT_NAME_REGEX, message = ReportValidMessage.NAME_PATTERN_NOT_MATCH)
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@ApiModelProperty(value = "版本号", required = true)
|
@ApiModelProperty(value = "版本号", required = true)
|
||||||
@NotBlank(message = ReportValidMessage.VERSION_NOT_BLANK)
|
@NotBlank(message = ReportValidMessage.VERSION_NOT_BLANK)
|
||||||
|
@Pattern(regexp = PatternRegex.REPORT_VERSION_REGEX, message = ReportValidMessage.VERSION_PATTERN_NOT_MATCH)
|
||||||
private String version;
|
private String version;
|
||||||
|
|
||||||
@ApiModelProperty(value = "描述信息", required = true)
|
@ApiModelProperty(value = "描述信息", required = true)
|
||||||
|
|||||||
@@ -63,14 +63,6 @@ public interface IPqReportService extends IService<PqReport> {
|
|||||||
*/
|
*/
|
||||||
List<String> listAllName();
|
List<String> listAllName();
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据报告name查询改模板的所有版本号
|
|
||||||
*
|
|
||||||
* @param name
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
List<String> listAllVersion(String name);
|
|
||||||
|
|
||||||
void generateReport(DevReportParam devReportParam);
|
void generateReport(DevReportParam devReportParam);
|
||||||
|
|
||||||
void downloadReport(DevReportParam devReportParam, HttpServletResponse response);
|
void downloadReport(DevReportParam devReportParam, HttpServletResponse response);
|
||||||
|
|||||||
@@ -214,17 +214,10 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> listAllName() {
|
public List<String> listAllName() {
|
||||||
List<String> result = this.lambdaQuery()
|
List<PqReport> reportList = this.lambdaQuery()
|
||||||
.eq(PqReport::getState, DataStateEnum.ENABLE.getCode()).list().stream().map(PqReport::getName).distinct().collect(Collectors.toList());
|
.eq(PqReport::getState, DataStateEnum.ENABLE.getCode()).list();
|
||||||
return result;
|
List<String> collect = reportList.stream().map(pqReport -> pqReport.getName() + "_" + pqReport.getVersion()).collect(Collectors.toList());
|
||||||
}
|
return collect;
|
||||||
|
|
||||||
@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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -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.pojo.vo.RawDataVO;
|
||||||
import com.njcn.gather.storage.service.AdHarmonicService;
|
import com.njcn.gather.storage.service.AdHarmonicService;
|
||||||
import com.njcn.gather.storage.service.AdNonHarmonicService;
|
import com.njcn.gather.storage.service.AdNonHarmonicService;
|
||||||
import com.njcn.gather.system.config.pojo.po.SysTestConfig;
|
import com.njcn.gather.system.cfg.pojo.po.SysTestConfig;
|
||||||
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.enums.DictDataEnum;
|
||||||
import com.njcn.gather.system.dictionary.pojo.po.DictTree;
|
import com.njcn.gather.system.dictionary.pojo.po.DictTree;
|
||||||
import com.njcn.gather.system.dictionary.service.IDictTreeService;
|
import com.njcn.gather.system.dictionary.service.IDictTreeService;
|
||||||
|
|||||||
@@ -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.annotation.OperateInfo;
|
||||||
import com.njcn.common.pojo.constant.OperateType;
|
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.enums.response.CommonResponseEnum;
|
||||||
import com.njcn.common.pojo.response.HttpResult;
|
import com.njcn.common.pojo.response.HttpResult;
|
||||||
import com.njcn.common.utils.LogUtil;
|
import com.njcn.common.utils.LogUtil;
|
||||||
import com.njcn.gather.system.config.pojo.param.SysTestConfigParam;
|
import com.njcn.gather.system.cfg.pojo.param.SysTestConfigParam;
|
||||||
import com.njcn.gather.system.config.pojo.po.SysTestConfig;
|
import com.njcn.gather.system.cfg.pojo.po.SysTestConfig;
|
||||||
import com.njcn.gather.system.config.service.ISysTestConfigService;
|
import com.njcn.gather.system.cfg.service.ISysTestConfigService;
|
||||||
import com.njcn.web.controller.BaseController;
|
import com.njcn.web.controller.BaseController;
|
||||||
import com.njcn.web.utils.HttpResultUtil;
|
import com.njcn.web.utils.HttpResultUtil;
|
||||||
import io.swagger.annotations.Api;
|
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.github.yulichang.base.MPJBaseMapper;
|
||||||
import com.njcn.gather.system.config.pojo.po.SysTestConfig;
|
import com.njcn.gather.system.cfg.pojo.po.SysTestConfig;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author caozehui
|
* @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.common.pojo.constant.PatternRegex;
|
||||||
import com.njcn.gather.system.pojo.constant.SystemValidMessage;
|
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.TableField;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
@@ -7,7 +7,6 @@ import lombok.Data;
|
|||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.time.LocalDateTime;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author caozehui
|
* @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.baomidou.mybatisplus.extension.service.IService;
|
||||||
import com.njcn.gather.system.config.pojo.param.SysTestConfigParam;
|
import com.njcn.gather.system.cfg.pojo.param.SysTestConfigParam;
|
||||||
import com.njcn.gather.system.config.pojo.po.SysTestConfig;
|
import com.njcn.gather.system.cfg.pojo.po.SysTestConfig;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author caozehui
|
* @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 cn.hutool.core.util.ObjectUtil;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||||
import com.njcn.common.pojo.enums.common.DataStateEnum;
|
import com.njcn.common.pojo.enums.common.DataStateEnum;
|
||||||
import com.njcn.gather.system.config.mapper.SysTestConfigMapper;
|
import com.njcn.gather.system.cfg.mapper.SysTestConfigMapper;
|
||||||
import com.njcn.gather.system.config.pojo.param.SysTestConfigParam;
|
import com.njcn.gather.system.cfg.pojo.param.SysTestConfigParam;
|
||||||
import com.njcn.gather.system.config.pojo.po.SysTestConfig;
|
import com.njcn.gather.system.cfg.pojo.po.SysTestConfig;
|
||||||
import com.njcn.gather.system.config.service.ISysTestConfigService;
|
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.DictData;
|
||||||
import com.njcn.gather.system.dictionary.service.IDictDataService;
|
import com.njcn.gather.system.dictionary.service.IDictDataService;
|
||||||
import lombok.RequiredArgsConstructor;
|
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.ObjectUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.njcn.common.pojo.annotation.OperateInfo;
|
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.exception.BusinessException;
|
||||||
|
import com.njcn.common.pojo.response.HttpResult;
|
||||||
import com.njcn.db.mybatisplus.constant.UserConstant;
|
import com.njcn.db.mybatisplus.constant.UserConstant;
|
||||||
import com.njcn.gather.system.log.pojo.enums.LogLevelEnum;
|
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.LogOperationTypeEnum;
|
||||||
import com.njcn.gather.system.log.pojo.enums.LogResponseEnum;
|
import com.njcn.gather.system.log.pojo.enums.LogResponseEnum;
|
||||||
import com.njcn.gather.system.log.pojo.po.SysLogAudit;
|
import com.njcn.gather.system.log.pojo.po.SysLogAudit;
|
||||||
import com.njcn.gather.system.log.service.ISysLogAuditService;
|
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.pojo.po.SysUser;
|
||||||
import com.njcn.gather.user.user.service.ISysUserService;
|
import com.njcn.gather.user.user.service.ISysUserService;
|
||||||
import com.njcn.web.utils.RequestUtil;
|
import com.njcn.web.utils.RequestUtil;
|
||||||
@@ -28,6 +31,7 @@ import java.lang.reflect.Method;
|
|||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.BlockingQueue;
|
import java.util.concurrent.BlockingQueue;
|
||||||
import java.util.concurrent.LinkedBlockingDeque;
|
import java.util.concurrent.LinkedBlockingDeque;
|
||||||
@@ -45,10 +49,10 @@ public class LogAdvice implements ApplicationListener<ContextRefreshedEvent> {
|
|||||||
|
|
||||||
private final ISysLogAuditService sysLogAuditService;
|
private final ISysLogAuditService sysLogAuditService;
|
||||||
private final ISysUserService sysUserService;
|
private final ISysUserService sysUserService;
|
||||||
|
private final List<String> IGNORE_METHOD = new ArrayList<>(Arrays.asList("login"));
|
||||||
|
|
||||||
private BlockingQueue<SysLogAudit> logQueue = new LinkedBlockingDeque<>();
|
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.*.*(..)) && !execution(* com.njcn.gather..controller.AuthController.*(..))")
|
||||||
@Pointcut(value = "execution(* com.njcn.gather..controller.*.*(..))")
|
@Pointcut(value = "execution(* com.njcn.gather..controller.*.*(..))")
|
||||||
public void logPointcut() {
|
public void logPointcut() {
|
||||||
@@ -56,7 +60,16 @@ public class LogAdvice implements ApplicationListener<ContextRefreshedEvent> {
|
|||||||
|
|
||||||
@Around("logPointcut()")
|
@Around("logPointcut()")
|
||||||
public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
|
public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
|
||||||
|
String name = joinPoint.getSignature().getName();
|
||||||
String username = "";
|
String username = "";
|
||||||
|
// 因为刚开始登录时无法获取到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();
|
String userId = RequestUtil.getUserId();
|
||||||
if (StrUtil.isNotBlank(userId)) {
|
if (StrUtil.isNotBlank(userId)) {
|
||||||
SysUser user = sysUserService.getById(RequestUtil.getUserId());
|
SysUser user = sysUserService.getById(RequestUtil.getUserId());
|
||||||
@@ -64,12 +77,22 @@ public class LogAdvice implements ApplicationListener<ContextRefreshedEvent> {
|
|||||||
username = user.getName();
|
username = user.getName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Object result = null;
|
Object result = null;
|
||||||
try {
|
try {
|
||||||
sysLogAuditService.scheduleRemoveLog();
|
sysLogAuditService.scheduleRemoveLog();
|
||||||
result = joinPoint.proceed();
|
result = joinPoint.proceed();
|
||||||
|
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);
|
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) {
|
} catch (Throwable e) {
|
||||||
addLogToQueue(joinPoint, "".equals(username) ? UserConstant.UNKNOWN_USER_ID : username, LogOperationTypeEnum.OPERATE.getMsg(), 0, LogLevelEnum.ERROR.getCode(), 1);
|
addLogToQueue(joinPoint, "".equals(username) ? UserConstant.UNKNOWN_USER_ID : username, LogOperationTypeEnum.OPERATE.getMsg(), 0, LogLevelEnum.ERROR.getCode(), 1);
|
||||||
throw e;
|
throw e;
|
||||||
|
|||||||
@@ -29,22 +29,6 @@ public interface ISysLogAuditService extends IService<SysLogAudit> {
|
|||||||
*/
|
*/
|
||||||
void exportCSV(SysLogParam.QueryParam param);
|
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.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.njcn.gather.system.log.mapper.SysLogAuditMapper;
|
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.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.param.SysLogParam;
|
||||||
import com.njcn.gather.system.log.pojo.po.SysLogAudit;
|
import com.njcn.gather.system.log.pojo.po.SysLogAudit;
|
||||||
import com.njcn.gather.system.log.service.ISysLogAuditService;
|
import com.njcn.gather.system.log.service.ISysLogAuditService;
|
||||||
import com.njcn.gather.system.log.util.CSVUtil;
|
import com.njcn.gather.system.log.util.CSVUtil;
|
||||||
import com.njcn.web.factory.PageFactory;
|
import com.njcn.web.factory.PageFactory;
|
||||||
import com.njcn.web.utils.HttpServletUtil;
|
import com.njcn.web.utils.HttpServletUtil;
|
||||||
import com.njcn.web.utils.RequestUtil;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
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.XSSFSheet;
|
||||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.chart.CTPieSer;
|
import org.openxmlformats.schemas.drawingml.x2006.chart.CTPieSer;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
|
|
||||||
import javax.servlet.ServletOutputStream;
|
import javax.servlet.ServletOutputStream;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
@@ -34,7 +27,6 @@ import java.io.IOException;
|
|||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
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);
|
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
|
@Override
|
||||||
public Integer getMaxSort() {
|
public Integer getMaxSort() {
|
||||||
SysLogAudit log = this.lambdaQuery().orderByDesc(SysLogAudit::getSort).last("limit 1").one();
|
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.enums.common.DataStateEnum;
|
||||||
import com.njcn.common.pojo.exception.BusinessException;
|
import com.njcn.common.pojo.exception.BusinessException;
|
||||||
import com.njcn.common.utils.EncryptionUtil;
|
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.enums.DictDataEnum;
|
||||||
import com.njcn.gather.system.dictionary.pojo.po.DictData;
|
import com.njcn.gather.system.dictionary.pojo.po.DictData;
|
||||||
import com.njcn.gather.system.dictionary.service.IDictDataService;
|
import com.njcn.gather.system.dictionary.service.IDictDataService;
|
||||||
|
|||||||
@@ -44,9 +44,4 @@ public interface UserValidMessage {
|
|||||||
|
|
||||||
String LOGIN_FAILED = "登录失败,用户名或密码错误";
|
String LOGIN_FAILED = "登录失败,用户名或密码错误";
|
||||||
|
|
||||||
String TOKEN_VALID_ERROR = "非法的token";
|
|
||||||
|
|
||||||
String TOKEN_EXPIRED = "token已过期,请重新登录";
|
|
||||||
|
|
||||||
String ACCESS_TOKEN_EXPIRED = "access-token已过期";
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package com.njcn.gather.user.user.controller;
|
package com.njcn.gather.user.user.controller;
|
||||||
|
|
||||||
import cn.hutool.core.date.DateUnit;
|
import cn.hutool.core.date.DateUnit;
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.extra.spring.SpringUtil;
|
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.njcn.common.bean.CustomCacheUtil;
|
import com.njcn.common.bean.CustomCacheUtil;
|
||||||
import com.njcn.common.pojo.annotation.OperateInfo;
|
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||||
@@ -39,26 +39,8 @@ import java.util.Map;
|
|||||||
public class AuthController extends BaseController {
|
public class AuthController extends BaseController {
|
||||||
|
|
||||||
private final ISysUserService sysUserService;
|
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)
|
@OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.AUTHENTICATE)
|
||||||
@PostMapping("/login")
|
@PostMapping("/login")
|
||||||
@@ -67,7 +49,7 @@ public class AuthController extends BaseController {
|
|||||||
String methodDescribe = getMethodDescribe("login");
|
String methodDescribe = getMethodDescribe("login");
|
||||||
LogUtil.njcnDebug(log, "{},登录参数为:{}", methodDescribe, param);
|
LogUtil.njcnDebug(log, "{},登录参数为:{}", methodDescribe, param);
|
||||||
SysUser user = sysUserService.getUserByLoginNameAndPassword(param.getUsername(), param.getPassword());
|
SysUser user = sysUserService.getUserByLoginNameAndPassword(param.getUsername(), param.getPassword());
|
||||||
if (user == null) {
|
if (ObjectUtil.isNull(user)) {
|
||||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, UserValidMessage.LOGIN_FAILED);
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, UserValidMessage.LOGIN_FAILED);
|
||||||
} else {
|
} else {
|
||||||
String accessToken = JwtUtil.getAccessToken(user.getId());
|
String accessToken = JwtUtil.getAccessToken(user.getId());
|
||||||
@@ -81,10 +63,7 @@ public class AuthController extends BaseController {
|
|||||||
|
|
||||||
token.setUserInfo(map);
|
token.setUserInfo(map);
|
||||||
|
|
||||||
CustomCacheUtil customCacheUtil = SpringUtil.getBean(CustomCacheUtil.CACHE_NAME);
|
customCacheUtil.putWithExpireTime(accessToken, JSON.toJSONString(user), DateUnit.DAY.getMillis() * Integer.MAX_VALUE);
|
||||||
customCacheUtil.putWithExpireTime(accessToken, JSON.toJSONString(user), DateUnit.DAY.getMillis() * 2);
|
|
||||||
|
|
||||||
//sysLogAuditService.saveAuthLog(user.getName(), 1);
|
|
||||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, token, methodDescribe);
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, token, methodDescribe);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -97,13 +76,8 @@ public class AuthController extends BaseController {
|
|||||||
LogUtil.njcnDebug(log, "{},注销登录", methodDescribe);
|
LogUtil.njcnDebug(log, "{},注销登录", methodDescribe);
|
||||||
String accessToken = RequestUtil.getAccessToken();
|
String accessToken = RequestUtil.getAccessToken();
|
||||||
if (StrUtil.isNotBlank(accessToken)) {
|
if (StrUtil.isNotBlank(accessToken)) {
|
||||||
CustomCacheUtil customCacheUtil = SpringUtil.getBean(CustomCacheUtil.CACHE_NAME);
|
|
||||||
customCacheUtil.remove(accessToken);
|
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.SUCCESS, null, methodDescribe);
|
||||||
}
|
}
|
||||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
|
||||||
@@ -124,19 +98,15 @@ public class AuthController extends BaseController {
|
|||||||
SysUser user = sysUserService.getById(userId);
|
SysUser user = sysUserService.getById(userId);
|
||||||
String accessTokenNew = JwtUtil.getAccessToken(userId);
|
String accessTokenNew = JwtUtil.getAccessToken(userId);
|
||||||
|
|
||||||
String refreshTokenNew = JwtUtil.getRefreshToken(accessTokenNew);
|
//String refreshTokenNew = JwtUtil.getRefreshToken(accessTokenNew);
|
||||||
|
|
||||||
token.setAccessToken(accessTokenNew);
|
token.setAccessToken(accessTokenNew);
|
||||||
token.setRefreshToken(refreshTokenNew);
|
token.setRefreshToken(accessToken);
|
||||||
|
|
||||||
CustomCacheUtil customCacheUtil = SpringUtil.getBean(CustomCacheUtil.CACHE_NAME);
|
customCacheUtil.putWithExpireTime(accessTokenNew, JSON.toJSONString(user), DateUnit.DAY.getMillis() * Integer.MAX_VALUE);
|
||||||
customCacheUtil.remove(accessToken);
|
|
||||||
customCacheUtil.putWithExpireTime(accessTokenNew, JSON.toJSONString(user), DateUnit.DAY.getMillis() * 2);
|
|
||||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, token, methodDescribe);
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, token, methodDescribe);
|
||||||
} else {
|
} else {
|
||||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
package com.njcn.gather.user.user.filter;
|
package com.njcn.gather.user.user.filter;
|
||||||
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.njcn.common.pojo.constant.SecurityConstants;
|
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.common.utils.JwtUtil;
|
||||||
import com.njcn.gather.user.pojo.constant.UserValidMessage;
|
import com.njcn.web.utils.HttpResultUtil;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.core.Ordered;
|
import org.springframework.core.Ordered;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
@@ -35,16 +38,6 @@ public class AuthGlobalFilter implements Filter, Ordered {
|
|||||||
HttpServletRequest req = (HttpServletRequest) request;
|
HttpServletRequest req = (HttpServletRequest) request;
|
||||||
HttpServletResponse res = (HttpServletResponse) response;
|
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.setCharacterEncoding("UTF-8");
|
||||||
res.setContentType("application/json; charset=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 accessTokenStr = req.getHeader(SecurityConstants.AUTHORIZATION_KEY);
|
||||||
String isRefreshToken = req.getHeader(SecurityConstants.IS_REFRESH_TOKEN);
|
String isRefreshToken = req.getHeader(SecurityConstants.IS_REFRESH_TOKEN);
|
||||||
if (StrUtil.isBlank(accessTokenStr) || !accessTokenStr.startsWith(SecurityConstants.AUTHORIZATION_PREFIX)) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
String accessToken = accessTokenStr.substring(SecurityConstants.AUTHORIZATION_PREFIX.length());
|
String accessToken = accessTokenStr.substring(SecurityConstants.AUTHORIZATION_PREFIX.length());
|
||||||
try {
|
try {
|
||||||
if (StrUtil.isBlank(accessToken) || !JwtUtil.verifyToken(accessToken)) {
|
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)) {
|
} else if (JwtUtil.isExpired(accessToken)) {
|
||||||
if ("true".equals(isRefreshToken)) {
|
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 {
|
} 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 {
|
} else {
|
||||||
filterChain.doFilter(req, res);
|
filterChain.doFilter(req, res);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} 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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user