This commit is contained in:
caozehui
2025-03-20 09:02:21 +08:00
parent 38cbb22eff
commit 051e7fe14a
24 changed files with 777 additions and 67 deletions

View File

@@ -1005,7 +1005,7 @@ public class SocketDevResponseService {
if (successComm.size() == FormalTestManager.monitorIdListComm.size()) { if (successComm.size() == FormalTestManager.monitorIdListComm.size()) {
System.out.println(sourceIssue.getType() + splitTag + sourceIssue.getIndex() + "当前测试小项读取数据已经全部结束。。。。。。。。。"); System.out.println(sourceIssue.getType() + splitTag + sourceIssue.getIndex() + "当前测试小项读取数据已经全部结束。。。。。。。。。");
//修改装置为监测中 //修改装置为监测中
adPlanService.updateTestState(param.getPlanId(), param.getDevIds()); // adPlanService.updateTestState(param.getPlanId(), param.getDevIds());
//开启线程进行入库原始数据操作 //开启线程进行入库原始数据操作
baseDataInsert(FormalTestManager.realDataXiList, sourceIssue, param, SocketManager.valueTypeMap); baseDataInsert(FormalTestManager.realDataXiList, sourceIssue, param, SocketManager.valueTypeMap);

View File

@@ -114,6 +114,9 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
throw new BusinessException(DevResponseEnum.SERIES_AND_DEVKEY_NOT_BLANK); throw new BusinessException(DevResponseEnum.SERIES_AND_DEVKEY_NOT_BLANK);
} }
} }
if("1".equals(sysTestConfigService.getCurrrentScene())){
pqDev.setManufacturer("8fa73802c9e1abab973adcbeb0d58567"); // 南京灿能字典项目对应的id
}
// 新增时默认设置 // 新增时默认设置
pqDev.setTimeCheckResult(TimeCheckResultEnum.UNKNOWN.getValue()); pqDev.setTimeCheckResult(TimeCheckResultEnum.UNKNOWN.getValue());
pqDev.setFactorCheckResult(FactorCheckResultEnum.UNKNOWN.getValue()); pqDev.setFactorCheckResult(FactorCheckResultEnum.UNKNOWN.getValue());

View File

@@ -2,6 +2,7 @@ package com.njcn.gather.plan.mapper;
import com.github.yulichang.base.MPJBaseMapper; import com.github.yulichang.base.MPJBaseMapper;
import com.njcn.gather.plan.pojo.po.AdPlan; import com.njcn.gather.plan.pojo.po.AdPlan;
import com.njcn.gather.report.pojo.po.PqReport;
/** /**
* @author caozehui * @author caozehui
@@ -9,5 +10,21 @@ import com.njcn.gather.plan.pojo.po.AdPlan;
*/ */
public interface AdPlanMapper extends MPJBaseMapper<AdPlan> { public interface AdPlanMapper extends MPJBaseMapper<AdPlan> {
/**
* 根据名称和版本获取报告id
*
* @param name
* @param version
* @return
*/
String getReportIdByNameAndVersion(String name, String version);
/**
* 根据id获取报告模板
*
* @param id
* @return
*/
PqReport getPqReportById(String id);
} }

View File

@@ -3,5 +3,19 @@
<mapper namespace="com.njcn.gather.plan.mapper.AdPlanMapper"> <mapper namespace="com.njcn.gather.plan.mapper.AdPlanMapper">
<select id="getReportIdByNameAndVersion" resultType="java.lang.String">
SELECT id
FROM pq_report
WHERE name = #{name}
AND version = #{version}
and enable !=0
</select>
<select id="getPqReportById" resultType="com.njcn.gather.report.pojo.po.PqReport">
SELECT *
FROM pq_report
WHERE id = #{id}
and enable !=0
</select>
</mapper> </mapper>

View File

@@ -13,7 +13,8 @@ public enum PlanResponseEnum {
SCRIPT_RELATE_DICT_NOT_EXIST("A003016","脚本关联的字典不存在"), SCRIPT_RELATE_DICT_NOT_EXIST("A003016","脚本关联的字典不存在"),
NOT_CHECKED_PLAN_CANNOT_ANALYSE("A003017","只有检测状态为检测完成的计划才能进行统计分析" ), NOT_CHECKED_PLAN_CANNOT_ANALYSE("A003017","只有检测状态为检测完成的计划才能进行统计分析" ),
CANNOT_CHANGE_SCRIPT_WHEN_CHECKING("A003018","只有检测状态为未检时,才能修改检测脚本" ), CANNOT_CHANGE_SCRIPT_WHEN_CHECKING("A003018","只有检测状态为未检时,才能修改检测脚本" ),
CANNOT_CHANGE_ERROR_SYS_WHEN_CHECKING("A003019","只有检测状态为未检时,才能修改误差体系" ); CANNOT_CHANGE_ERROR_SYS_WHEN_CHECKING("A003019","只有检测状态为未检时,才能修改误差体系" ),
CANNOT_CHANGE_REPORT_WHEN_CHECKING("A003020","只有检测状态为未检时,才能修改绑定报告模板");
private final String message; private final String message;
private final String code; private final String code;

View File

@@ -4,6 +4,7 @@ import com.njcn.common.pojo.constant.PatternRegex;
import com.njcn.gather.device.pojo.constant.DevValidMessage; import com.njcn.gather.device.pojo.constant.DevValidMessage;
import com.njcn.web.pojo.param.BaseParam; import com.njcn.web.pojo.param.BaseParam;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import io.swagger.models.auth.In;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
@@ -60,6 +61,15 @@ public class AdPlanParam {
@NotNull(message = DevValidMessage.PQ_DEV_IDS_NOT_NULL) @NotNull(message = DevValidMessage.PQ_DEV_IDS_NOT_NULL)
private List<String> devIds; private List<String> devIds;
@ApiModelProperty(value = "是否关联报告")
private Integer associateReport;
@ApiModelProperty(value = "报告模板名称")
private String reportName;
@ApiModelProperty(value = "报告模板版本")
private String reportVersion;
/** /**
* 分页查询实体 * 分页查询实体
*/ */

View File

@@ -78,6 +78,16 @@ public class AdPlan extends BaseEntity implements Serializable {
*/ */
private Integer code; private Integer code;
/**
* 是否关联报告0-不关联 1-关联
*/
private Integer associateReport;
/**
* 报告模板ID关联PQ_Report表
*/
private String reportTemplateId;
/** /**
* 状态0-删除 1-正常 * 状态0-删除 1-正常
*/ */

View File

@@ -1,5 +1,6 @@
package com.njcn.gather.plan.pojo.vo; package com.njcn.gather.plan.pojo.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
@@ -97,4 +98,19 @@ public class AdPlanVO {
* 创建时间 * 创建时间
*/ */
private String createTime; private String createTime;
/**
* 是否关联报告0-不关联 1-关联
*/
private Integer associateReport;
/**
* 报告模板名称
*/
private String reportTemplateName;
/**
* 报告模板版本号
*/
private String reportTemplateVersion;
} }

View File

@@ -32,15 +32,14 @@ import com.njcn.gather.plan.pojo.vo.AdPlanExcel;
import com.njcn.gather.plan.pojo.vo.AdPlanVO; import com.njcn.gather.plan.pojo.vo.AdPlanVO;
import com.njcn.gather.plan.service.IAdPlanService; import com.njcn.gather.plan.service.IAdPlanService;
import com.njcn.gather.plan.service.IAdPlanSourceService; import com.njcn.gather.plan.service.IAdPlanSourceService;
import com.njcn.gather.report.pojo.po.PqReport;
import com.njcn.gather.script.pojo.po.PqScriptDtls; import com.njcn.gather.script.pojo.po.PqScriptDtls;
import com.njcn.gather.script.service.IPqScriptDtlsService; import com.njcn.gather.script.service.IPqScriptDtlsService;
import com.njcn.gather.script.service.IPqScriptService; import com.njcn.gather.script.service.IPqScriptService;
import com.njcn.gather.source.pojo.po.PqSource; import com.njcn.gather.source.pojo.po.PqSource;
import com.njcn.gather.source.service.IPqSourceService; import com.njcn.gather.source.service.IPqSourceService;
import com.njcn.gather.storage.mapper.DetectionDataDealMapper;
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.AdNonHarmonicService;
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.config.pojo.po.SysTestConfig;
import com.njcn.gather.system.config.service.ISysTestConfigService; import com.njcn.gather.system.config.service.ISysTestConfigService;
@@ -106,6 +105,11 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
BeanUtil.copyProperties(adPlan, adPlanVO); BeanUtil.copyProperties(adPlan, adPlanVO);
adPlanVO.setCreateTime(adPlanVO.getCreateTime().replace("T", " ")); adPlanVO.setCreateTime(adPlanVO.getCreateTime().replace("T", " "));
adPlanVO.setDatasourceIds(Arrays.asList(adPlan.getDatasourceId().split(StrUtil.COMMA))); 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());
}
return adPlanVO; return adPlanVO;
}).collect(Collectors.toList()); }).collect(Collectors.toList());
adPlanVOList.forEach(adPlanVO -> { adPlanVOList.forEach(adPlanVO -> {
@@ -144,6 +148,13 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
adPlan.setResult(CheckResultEnum.UNCHECKED.getValue()); adPlan.setResult(CheckResultEnum.UNCHECKED.getValue());
adPlan.setCode(this.generateCode()); adPlan.setCode(this.generateCode());
if (param.getAssociateReport() == 1) {
String reportId = this.baseMapper.getReportIdByNameAndVersion(param.getReportName(), param.getReportVersion());
if (StrUtil.isNotBlank(reportId)) {
adPlan.setReportTemplateId(reportId);
}
}
// 新增检测计划、检测源关联 // 新增检测计划、检测源关联
adPlanSourceService.addAdPlanSource(planId, param.getSourceIds()); adPlanSourceService.addAdPlanSource(planId, param.getSourceIds());
if (ObjectUtil.isNotEmpty(param.getDevIds())) { if (ObjectUtil.isNotEmpty(param.getDevIds())) {
@@ -167,6 +178,14 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
this.checkRepeat(param, true); this.checkRepeat(param, true);
AdPlan plan1 = this.getById(param.getId()); AdPlan plan1 = this.getById(param.getId());
AdPlan plan2 = new AdPlan(); AdPlan plan2 = new AdPlan();
if (param.getAssociateReport() == 1) {
String reportId = this.baseMapper.getReportIdByNameAndVersion(param.getReportName(), param.getReportVersion());
if (StrUtil.isNotBlank(reportId)) {
plan2.setReportTemplateId(reportId);
}
}
if (plan1.getTestState() != CheckStateEnum.UNCHECKED.getValue()) { if (plan1.getTestState() != CheckStateEnum.UNCHECKED.getValue()) {
if (!plan1.getScriptId().equals(param.getScriptId())) { if (!plan1.getScriptId().equals(param.getScriptId())) {
throw new BusinessException(PlanResponseEnum.CANNOT_CHANGE_SCRIPT_WHEN_CHECKING); throw new BusinessException(PlanResponseEnum.CANNOT_CHANGE_SCRIPT_WHEN_CHECKING);

View File

@@ -1,11 +1,15 @@
package com.njcn.gather.report.controller; package com.njcn.gather.report.controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
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.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.report.pojo.DevReportParam; import com.njcn.gather.report.pojo.DevReportParam;
import com.njcn.gather.report.service.IReportService; import com.njcn.gather.report.pojo.param.ReportParam;
import com.njcn.gather.report.pojo.vo.PqReportVO;
import com.njcn.gather.report.service.IPqReportService;
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;
@@ -16,6 +20,8 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;
/** /**
@@ -30,7 +36,7 @@ import javax.servlet.http.HttpServletResponse;
@RequiredArgsConstructor @RequiredArgsConstructor
public class ReportController extends BaseController { public class ReportController extends BaseController {
private final IReportService reportService; private final IPqReportService pqReportService;
/** /**
* 此方法临时的,给楼下使用,实际需要优化 * 此方法临时的,给楼下使用,实际需要优化
@@ -44,7 +50,7 @@ public class ReportController extends BaseController {
public HttpResult<Object> generateReport(@RequestBody DevReportParam devReportParam) { public HttpResult<Object> generateReport(@RequestBody DevReportParam devReportParam) {
String methodDescribe = getMethodDescribe("generateReport"); String methodDescribe = getMethodDescribe("generateReport");
LogUtil.njcnDebug(log, "{},终端参数为:{}", methodDescribe, devReportParam); LogUtil.njcnDebug(log, "{},终端参数为:{}", methodDescribe, devReportParam);
reportService.generateReport(devReportParam); pqReportService.generateReport(devReportParam);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe); return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
} }
@@ -58,9 +64,87 @@ public class ReportController extends BaseController {
public void downloadReport(@RequestBody DevReportParam devReportParam, HttpServletResponse response) { public void downloadReport(@RequestBody DevReportParam devReportParam, HttpServletResponse response) {
String methodDescribe = getMethodDescribe("downloadReport"); String methodDescribe = getMethodDescribe("downloadReport");
LogUtil.njcnDebug(log, "{},终端参数为:{}", methodDescribe, devReportParam); LogUtil.njcnDebug(log, "{},终端参数为:{}", methodDescribe, devReportParam);
reportService.downloadReport(devReportParam,response); pqReportService.downloadReport(devReportParam, response);
} }
@OperateInfo
@PostMapping("/list")
@ApiOperation("分页查询报告模板")
@ApiImplicitParam(name = "param", value = "查询参数", required = true)
public HttpResult<Page<PqReportVO>> list(@RequestBody ReportParam.QueryParam queryParam) {
String methodDescribe = getMethodDescribe("list");
LogUtil.njcnDebug(log, "{},查询参数为:{}", methodDescribe, queryParam);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, pqReportService.list(queryParam), methodDescribe);
}
@OperateInfo
@GetMapping("/getById")
@ApiOperation("查询报告模板详情")
@ApiImplicitParam(name = "param", value = "查询参数", required = true)
public HttpResult<PqReportVO> getById(@RequestParam("id") String id) {
String methodDescribe = getMethodDescribe("getById");
LogUtil.njcnDebug(log, "{},查询参数为:{}", methodDescribe, id);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, pqReportService.getById(id), methodDescribe);
}
@OperateInfo(operateType = OperateType.ADD)
@PostMapping("/add")
@ApiOperation("新增报告模板")
@ApiImplicitParam(name = "param", value = "报告模板参数", required = true)
public HttpResult<Object> add(ReportParam reportParam) {
String methodDescribe = getMethodDescribe("add");
LogUtil.njcnDebug(log, "{},新增参数为:{}", methodDescribe, reportParam);
boolean result = pqReportService.add(reportParam);
if (result) {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
}
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
}
@OperateInfo(operateType = OperateType.UPDATE)
@PostMapping("/update")
@ApiOperation("更新报告模板")
@ApiImplicitParam(name = "param", value = "报告模板参数", required = true)
public HttpResult<Object> update(ReportParam.UpdateParam reportParam) {
String methodDescribe = getMethodDescribe("update");
LogUtil.njcnDebug(log, "{},修改参数为:{}", methodDescribe, reportParam);
boolean result = pqReportService.update(reportParam);
if (result) {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
}
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
}
@OperateInfo(operateType = OperateType.DELETE)
@PostMapping("/delete")
@ApiOperation("删除报告模板")
@ApiImplicitParam(name = "param", value = "报告模板参数", required = true)
public HttpResult<Object> delete(@RequestBody List<String> ids) {
String methodDescribe = getMethodDescribe("delete");
LogUtil.njcnDebug(log, "{},删除参数为:{}", methodDescribe, ids);
boolean result = pqReportService.delete(ids);
if (result) {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
}
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
}
@OperateInfo
@GetMapping("/listAllName")
@ApiOperation("查询所有报告模板名称")
@ApiImplicitParam(name = "param", value = "查询参数", required = true)
public HttpResult<List<String>> listAllName() {
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

@@ -0,0 +1,13 @@
package com.njcn.gather.report.mapper;
import com.github.yulichang.base.MPJBaseMapper;
import com.njcn.gather.report.pojo.po.PqReport;
/**
* @author makejava
* @date 2025-03-19
*/
public interface PqReportMapper extends MPJBaseMapper<PqReport> {
}

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.njcn.gather.report.mapper.PqReportMapper">
</mapper>

View File

@@ -0,0 +1,22 @@
package com.njcn.gather.report.pojo.enums;
import lombok.Getter;
/**
* @author caozehui
* @data 2025-03-20
*/
@Getter
public enum ReportEnableEnum {
DELETE(0, "删除"),
ENABLE(1, "启用"),
DISABLE(2, "禁用");
private int code;
private String desc;
ReportEnableEnum(int code, String desc) {
this.code = code;
this.desc = desc;
}
}

View File

@@ -0,0 +1,23 @@
package com.njcn.gather.report.pojo.enums;
import lombok.Getter;
/**
* @author caozehui
* @data 2025-03-19
*/
@Getter
public enum ReportResponseEnum {
FILE_UPLOAD_FAILED("A012001", "文件上传失败"),
FILE_SUFFIX_ERROR("A012002", "文件后缀错误,请上传.docx文件"),
REPORT_REPEATED("A012003", "已存在相同版本、相同名称的报告");
private String code;
private String message;
ReportResponseEnum(String code, String message) {
this.code = code;
this.message = message;
}
}

View File

@@ -0,0 +1,47 @@
package com.njcn.gather.report.pojo.param;
import com.njcn.web.pojo.param.BaseParam;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.web.multipart.MultipartFile;
/**
* @author caozehui
* @data 2025-03-19
*/
@Data
public class ReportParam {
@ApiModelProperty(value = "报告模板名称", required = true)
private String name;
@ApiModelProperty(value = "版本号", required = true)
private String version;
@ApiModelProperty(value = "描述信息", required = true)
private String description;
@ApiModelProperty(value = "基础模板文件", required = true)
private MultipartFile baseFile;
@ApiModelProperty(value = "检测项模版文件", required = true)
private MultipartFile detailFile;
@Data
@EqualsAndHashCode(callSuper = true)
public static class QueryParam extends BaseParam {
@ApiModelProperty(value = "报告模板名称", required = true)
private String name;
@ApiModelProperty(value = "版本号", required = true)
private String version;
}
@Data
@EqualsAndHashCode(callSuper = true)
public static class UpdateParam extends ReportParam {
@ApiModelProperty(value = "id", required = true)
private String id;
}
}

View File

@@ -0,0 +1,55 @@
package com.njcn.gather.report.pojo.po;
import com.baomidou.mybatisplus.annotation.TableName;
import com.njcn.db.mybatisplus.bo.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serializable;
import java.time.LocalDateTime;
/**
* @author makejava
* @date 2025-03-19
*/
@Data
@EqualsAndHashCode(callSuper = true)
@TableName("pq_report")
public class PqReport extends BaseEntity implements Serializable {
private static final long serialVersionUID = 582972970946593407L;
/**
* 报告模板id
*/
private String id;
/**
* 报告模板名称
*/
private String name;
/**
* 版本号
*/
private String version;
/**
* 基础模板文件路径
*/
private String basePath;
/**
* 检测项模版文件路径
*/
private String detailPath;
/**
* 描述信息
*/
private String description;
/**
* 状态0-删除 1-激活 2-未激活
*/
private Integer enable;
}

View File

@@ -0,0 +1,53 @@
package com.njcn.gather.report.pojo.vo;
import lombok.Data;
/**
* @author caozehui
* @data 2025-03-19
*/
@Data
public class PqReportVO {
/**
* 报告模板id
*/
private String id;
/**
* 报告模板名称
*/
private String name;
/**
* 版本号
*/
private String version;
/**
* 基础模板文件路径
*/
private FileVO baseFileVO;
/**
* 检测项模版文件路径
*/
private FileVO detailFileVO;
/**
* 描述信息
*/
private String desc;
/**
* 状态0-删除 1-激活 2-未激活
*/
private Integer enable;
@Data
public static class FileVO{
private String fileName;
private String url;
}
}

View File

@@ -0,0 +1,86 @@
package com.njcn.gather.report.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.njcn.gather.report.pojo.DevReportParam;
import com.njcn.gather.report.pojo.param.ReportParam;
import com.njcn.gather.report.pojo.po.PqReport;
import com.njcn.gather.report.pojo.vo.PqReportVO;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;
/**
* @author makejava
* @date 2025-03-19
*/
public interface IPqReportService extends IService<PqReport> {
/**
* 分页查询报告列表
*
* @param queryParam
* @return
*/
Page<PqReportVO> list(ReportParam.QueryParam queryParam);
/**
* 根据id查询报告详情
*
* @param id
* @return
*/
PqReportVO getById(String id);
/**
* 新增报告
*
* @param reportParam
* @return
*/
boolean add(ReportParam reportParam);
/**
* 修改报告
*
* @param reportParam
* @return
*/
boolean update(ReportParam.UpdateParam reportParam);
/**
* 批量删除报告
*
* @param ids
* @return
*/
boolean delete(List<String> ids);
/**
* 查询所有报告名称
*
* @return key为报告idvalue为报告名称
*/
List<String> listAllName();
/**
* 根据报告name查询改模板的所有版本号
*
* @param name
* @return
*/
List<String> listAllVersion(String name);
/**
* 根据报告名称和版本号查询报告
*
* @param name
* @param version
* @return
*/
PqReport getReportByNameAndVersion(String name, String version);
void generateReport(DevReportParam devReportParam);
void downloadReport(DevReportParam devReportParam, HttpServletResponse response);
}

View File

@@ -1,16 +0,0 @@
package com.njcn.gather.report.service;
import com.njcn.gather.report.pojo.DevReportParam;
import javax.servlet.http.HttpServletResponse;
/**
* @author hongawen
* @version 1.0
* @data 2025/1/9 20:59
*/
public interface IReportService {
void generateReport(DevReportParam devReportParam);
void downloadReport(DevReportParam devReportParam, HttpServletResponse response);
}

View File

@@ -4,9 +4,14 @@ import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DatePattern; import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import cn.hutool.core.text.StrPool; import cn.hutool.core.text.StrPool;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
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.gather.detection.pojo.vo.DetectionData; import com.njcn.gather.detection.pojo.vo.DetectionData;
@@ -16,8 +21,14 @@ import com.njcn.gather.device.service.IPqDevService;
import com.njcn.gather.plan.pojo.enums.PlanReportStateEnum; import com.njcn.gather.plan.pojo.enums.PlanReportStateEnum;
import com.njcn.gather.plan.pojo.po.AdPlan; import com.njcn.gather.plan.pojo.po.AdPlan;
import com.njcn.gather.plan.service.IAdPlanService; import com.njcn.gather.plan.service.IAdPlanService;
import com.njcn.gather.report.mapper.PqReportMapper;
import com.njcn.gather.report.pojo.DevReportParam; import com.njcn.gather.report.pojo.DevReportParam;
import com.njcn.gather.report.service.IReportService; import com.njcn.gather.report.pojo.enums.ReportEnableEnum;
import com.njcn.gather.report.pojo.enums.ReportResponseEnum;
import com.njcn.gather.report.pojo.param.ReportParam;
import com.njcn.gather.report.pojo.po.PqReport;
import com.njcn.gather.report.pojo.vo.PqReportVO;
import com.njcn.gather.report.service.IPqReportService;
import com.njcn.gather.report.utils.WordUtil; import com.njcn.gather.report.utils.WordUtil;
import com.njcn.gather.script.pojo.po.PqScriptCheckData; import com.njcn.gather.script.pojo.po.PqScriptCheckData;
import com.njcn.gather.script.pojo.po.PqScriptDtls; import com.njcn.gather.script.pojo.po.PqScriptDtls;
@@ -32,31 +43,39 @@ 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 com.njcn.gather.type.pojo.po.DevType; import com.njcn.gather.type.pojo.po.DevType;
import com.njcn.gather.type.service.IDevTypeService; import com.njcn.gather.type.service.IDevTypeService;
import com.njcn.web.factory.PageFactory;
import com.njcn.web.utils.RequestUtil; 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.xwpf.usermodel.XWPFDocument; import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.*; import java.io.*;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode; import java.math.RoundingMode;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
/** /**
* @author hongawen * @author makejava
* @version 1.0 * @date 2025-03-19
* @data 2025/1/9 21:00
*/ */
@Slf4j @Slf4j
@Service @Service
@RequiredArgsConstructor @RequiredArgsConstructor
public class ReportServiceImpl implements IReportService { public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> implements IPqReportService {
@Value("${report.template:D:\\template\\}")
@Value("${report.template:D:\\template}")
private String templatePath; private String templatePath;
@Value("${report.reportDir:D:\\report}") @Value("${report.reportDir:D:\\report}")
@@ -78,6 +97,205 @@ public class ReportServiceImpl implements IReportService {
private final IDevTypeService devTypeService; private final IDevTypeService devTypeService;
@Override
public Page<PqReportVO> list(ReportParam.QueryParam queryParam) {
QueryWrapper<PqReport> wrapper = new QueryWrapper<>();
wrapper.like(StrUtil.isNotBlank(queryParam.getName()), "name", queryParam.getName())
.eq(StrUtil.isNotBlank(queryParam.getVersion()), "version", queryParam.getVersion())
.ne("enable", ReportEnableEnum.DELETE.getCode());
Page<PqReport> page1 = this.page(new Page<>(PageFactory.getPageNum(queryParam), PageFactory.getPageSize(queryParam)), wrapper);
List<PqReportVO> pqReportVOList = page1.getRecords().stream().map(pqReport -> {
PqReportVO pqReportVO = new PqReportVO();
BeanUtils.copyProperties(pqReport, pqReportVO);
PqReportVO.FileVO baseFileVo = new PqReportVO.FileVO();
baseFileVo.setFileName(pqReport.getBasePath().substring(pqReport.getBasePath().lastIndexOf(File.separator) + 1));
baseFileVo.setUrl(pqReport.getBasePath());
pqReportVO.setBaseFileVO(baseFileVo);
PqReportVO.FileVO detailFileVo = new PqReportVO.FileVO();
detailFileVo.setFileName(pqReport.getBasePath().substring(pqReport.getBasePath().lastIndexOf(File.separator) + 1));
detailFileVo.setUrl(pqReport.getBasePath());
pqReportVO.setDetailFileVO(detailFileVo);
return pqReportVO;
}).collect(Collectors.toList());
Page<PqReportVO> page2 = new Page<>(PageFactory.getPageNum(queryParam), PageFactory.getPageSize(queryParam));
page2.setTotal(page1.getTotal());
page2.setOrders(page1.orders());
page2.setPages(page1.getPages());
page2.setRecords(pqReportVOList);
return page2;
}
@Override
public PqReportVO getById(String id) {
PqReport pqReport = this.baseMapper.selectById(id);
PqReportVO pqReportVO = new PqReportVO();
BeanUtils.copyProperties(pqReport, pqReportVO);
PqReportVO.FileVO baseFileVo = new PqReportVO.FileVO();
baseFileVo.setFileName(pqReport.getBasePath().substring(pqReport.getBasePath().lastIndexOf(File.separator) + 1));
baseFileVo.setUrl(pqReport.getBasePath());
pqReportVO.setBaseFileVO(baseFileVo);
PqReportVO.FileVO detailFileVo = new PqReportVO.FileVO();
detailFileVo.setFileName(pqReport.getDetailPath().substring(pqReport.getDetailPath().lastIndexOf(File.separator) + 1));
detailFileVo.setUrl(pqReport.getDetailPath());
pqReportVO.setDetailFileVO(detailFileVo);
return pqReportVO;
}
@Override
@Transactional(rollbackFor = Exception.class)
public boolean add(ReportParam reportParam) {
this.checkRepeat(reportParam, false);
PqReport pqReport = new PqReport();
BeanUtils.copyProperties(reportParam, pqReport);
pqReport.setEnable(ReportEnableEnum.DISABLE.getCode());
// 上传文件
this.uploadFile(reportParam, pqReport);
return this.save(pqReport);
}
@Override
public boolean update(ReportParam.UpdateParam reportParam) {
this.checkRepeat(reportParam, true);
this.deleteFile(Collections.singletonList(reportParam.getId()));
PqReport pqReport = new PqReport();
BeanUtils.copyProperties(reportParam, pqReport);
// 上传文件
this.uploadFile(reportParam, pqReport);
return this.updateById(pqReport);
}
@Override
public boolean delete(List<String> ids) {
// 删除对应的文件
this.deleteFile(ids);
boolean result = this.lambdaUpdate().in(CollectionUtil.isNotEmpty(ids), PqReport::getId, ids)
.ne(PqReport::getEnable, ReportEnableEnum.DELETE.getCode())
.set(PqReport::getEnable, ReportEnableEnum.DELETE.getCode())
.update();
return result;
}
@Override
public List<String> listAllName() {
List<String> result = this.lambdaQuery()
.ne(PqReport::getEnable, ReportEnableEnum.DELETE.getCode()).list().stream().map(PqReport::getName).collect(Collectors.toList());
return result;
}
@Override
public List<String> listAllVersion(String name) {
List<String> result = this.lambdaQuery().eq(PqReport::getName, name)
.ne(PqReport::getEnable, ReportEnableEnum.DELETE.getCode())
.list().stream().map(PqReport::getVersion).collect(Collectors.toList());
return result;
}
@Override
public PqReport getReportByNameAndVersion(String name, String version) {
PqReport one = this.lambdaQuery().eq(PqReport::getName, name).eq(PqReport::getVersion, version)
.ne(PqReport::getEnable, ReportEnableEnum.DELETE.getCode())
.last("LIMIT 1").one();
return one;
}
/**
* 上传文件并设置pqReport的basePath和detailPath属性
*
* @param reportParam
* @param pqReport
*/
private void uploadFile(ReportParam reportParam, PqReport pqReport) {
String uploadDir = templatePath + File.separator + reportParam.getName() + File.separator + reportParam.getVersion() + File.separator;
//校验文件后缀
MultipartFile baseFile = reportParam.getBaseFile();
MultipartFile detailFile = reportParam.getDetailFile();
String baseOriginalFilename = baseFile.getOriginalFilename();
String baseFileName = baseOriginalFilename.substring(0, baseOriginalFilename.lastIndexOf("."));
String baseSuffix = baseOriginalFilename.substring(baseOriginalFilename.lastIndexOf(".") + 1);
String detailOriginalFilename = detailFile.getOriginalFilename();
String detailFileName = detailOriginalFilename.substring(0, detailOriginalFilename.lastIndexOf("."));
String detailSuffix = detailOriginalFilename.substring(detailOriginalFilename.lastIndexOf(".") + 1);
if (!"docx".equals(baseSuffix) || !"docx".equals(detailSuffix)) {
throw new BusinessException(ReportResponseEnum.FILE_SUFFIX_ERROR);
}
pqReport.setBasePath(uploadDir + baseFileName + "_" + pqReport.getVersion() + ".docx");
pqReport.setDetailPath(uploadDir + detailFileName + "_" + pqReport.getVersion() + ".docx");
try {
// 创建上传目录如果不存在
Path uploadPath = Paths.get(uploadDir);
if (!Files.exists(uploadPath)) {
Files.createDirectories(uploadPath);
}
//清空目录下的文件
File[] files = uploadPath.toFile().listFiles();
if (ArrayUtil.isNotEmpty(files)) {
for (int i = 0; i < files.length; i++) {
files[i].delete();
}
}
// 保存文件
byte[] baseBytes = baseFile.getBytes();
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(pqReport.getBasePath()));
bufferedOutputStream.write(baseBytes);
bufferedOutputStream.flush();
bufferedOutputStream.close();
byte[] detailBytes = detailFile.getBytes();
bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(pqReport.getDetailPath()));
bufferedOutputStream.write(detailBytes);
bufferedOutputStream.flush();
bufferedOutputStream.close();
} catch (IOException e) {
e.printStackTrace();
throw new BusinessException(ReportResponseEnum.FILE_UPLOAD_FAILED);
}
}
/**
* 根据id删除已有的文件
* @param ids
*/
private void deleteFile(List<String> ids) {
List<PqReport> pqReports = this.listByIds(ids);
for (PqReport pqReport : pqReports) {
String uploadDir = templatePath + File.separator + pqReport.getName() + File.separator + pqReport.getVersion() + File.separator;
Path uploadPath = Paths.get(uploadDir);
if (Files.exists(uploadPath)) {
//清空目录下的文件
File file1 = uploadPath.toFile();
File[] fileArr1 = file1.listFiles();
if (ArrayUtil.isNotEmpty(fileArr1)) {
for (int i = 0; i < fileArr1.length; i++) {
fileArr1[i].delete();
}
}
file1.delete();
String dir = templatePath + File.separator + pqReport.getName() + File.separator;
Path dirPath = Paths.get(dir);
File dirFile = dirPath.toFile();
File[] fileArr2 = dirFile.listFiles();
if (ArrayUtil.isEmpty(fileArr2)) {
dirFile.delete();
}
}
}
}
@Override @Override
public void generateReport(DevReportParam devReportParam) { public void generateReport(DevReportParam devReportParam) {
@@ -181,7 +399,6 @@ public class ReportServiceImpl implements IReportService {
} }
/** /**
* 处理基础模版中的信息非数据页报告 * 处理基础模版中的信息非数据页报告
* *
@@ -586,5 +803,25 @@ public class ReportServiceImpl implements IReportService {
} }
} }
/**
* 检查模板文件是否重复
*
* @param reportParam 报告模板参数
* @param isExcludeSelf 是否排除自己
*/
private void checkRepeat(ReportParam reportParam, boolean isExcludeSelf) {
QueryWrapper<PqReport> wrapper = new QueryWrapper();
wrapper.eq("name", reportParam.getName())
.eq("version", reportParam.getVersion())
.ne("enable", DataStateEnum.DELETED.getCode());
if (isExcludeSelf) {
if (reportParam instanceof ReportParam.UpdateParam) {
wrapper.ne("id", ((ReportParam.UpdateParam) reportParam).getId());
}
}
int count = this.count(wrapper);
if (count > 0) {
throw new BusinessException(ReportResponseEnum.REPORT_REPEATED);
}
}
} }

View File

@@ -75,6 +75,6 @@ log:
homeDir: D:\logs homeDir: D:\logs
commonLevel: info commonLevel: info
report: report:
template: D:\\template template: D:\template
reportDir: D:\\report reportDir: D:\report

View File

@@ -92,21 +92,28 @@ public class DictTreeServiceImpl extends ServiceImpl<DictTreeMapper, DictTree> i
@Override @Override
@Transactional(rollbackFor = {Exception.class}) @Transactional(rollbackFor = {Exception.class})
public boolean updateDictTree(DictTreeParam.UpdateParam param) { public boolean updateDictTree(DictTreeParam.UpdateParam param) {
DictTree dictTree = this.getById(param.getId());
if("975f63baeb6f653c54fca226a9ae36ca".equals(param.getId()) || dictTree.getPids().contains("975f63baeb6f653c54fca226a9ae36ca")){
throw new BusinessException(SystemResponseEnum.CAN_NOT_UPDATE_USED_DICT);
}
checkRepeat(param, true); checkRepeat(param, true);
boolean result; DictTree copyDictTree = new DictTree();
DictTree dictTree = new DictTree(); BeanUtils.copyProperties(param, copyDictTree);
BeanUtils.copyProperties(param, dictTree);
result = this.updateById(dictTree);
// if (result) { // if (result) {
// refreshDictTreeCache(); // refreshDictTreeCache();
// } // }
return result; return this.updateById(copyDictTree);
} }
@Override @Override
@Transactional(rollbackFor = {Exception.class}) @Transactional(rollbackFor = {Exception.class})
public boolean deleteDictTree(String id) { public boolean deleteDictTree(String id) {
boolean result = false; boolean result = false;
DictTree dictTree = this.getById(id);
if("975f63baeb6f653c54fca226a9ae36ca".equals(id) || dictTree.getPids().contains("975f63baeb6f653c54fca226a9ae36ca")){
throw new BusinessException(SystemResponseEnum.CAN_NOT_DELETE_USED_DICT);
}
List<DictTree> childrenList = this.lambdaQuery().eq(DictTree::getState, DictConst.ENABLE).eq(DictTree::getPid, id).list(); List<DictTree> childrenList = this.lambdaQuery().eq(DictTree::getState, DictConst.ENABLE).eq(DictTree::getPid, id).list();
if (CollectionUtils.isEmpty(childrenList)) { if (CollectionUtils.isEmpty(childrenList)) {
result = this.lambdaUpdate().set(DictTree::getState, DictConst.DELETE).in(DictTree::getId, id).update(); result = this.lambdaUpdate().set(DictTree::getState, DictConst.DELETE).in(DictTree::getId, id).update();

View File

@@ -48,8 +48,8 @@ public class LogAdvice implements ApplicationListener<ContextRefreshedEvent> {
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.*(..))")
@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.*(..))")
public void logPointcut() { public void logPointcut() {
} }

View File

@@ -65,7 +65,9 @@ public enum SystemResponseEnum {
DELETE_DATA("A0303", "导入旧日志文件异常:删除数据失败"), DELETE_DATA("A0303", "导入旧日志文件异常:删除数据失败"),
MULTIPLE_CLICKS_LOG_FILE_WRITER("A0304", "当前文件备份数据未结束,请勿多次点击"), MULTIPLE_CLICKS_LOG_FILE_WRITER("A0304", "当前文件备份数据未结束,请勿多次点击"),
MULTIPLE_CLICKS_RECOVER_LOG_FILE("A0303", "当前文件恢复数据未结束,请勿多次点击"), MULTIPLE_CLICKS_RECOVER_LOG_FILE("A0303", "当前文件恢复数据未结束,请勿多次点击"),
CODE_REPEAT("A0305","该层级下已存在相同的编码" ); CODE_REPEAT("A0305", "该层级下已存在相同的编码"),
CAN_NOT_DELETE_USED_DICT("A0306", "该字典在使用中,不能删除"),
CAN_NOT_UPDATE_USED_DICT("A0307", "该字典在使用中,不能修改");
private final String code; private final String code;