From fc8d3ae26b96797e4c6a36100657a0013a3e6df0 Mon Sep 17 00:00:00 2001 From: cuizhibin Date: Tue, 22 Jul 2025 21:37:36 +0800 Subject: [PATCH] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E6=8A=A5=E5=91=8A=E7=94=9F?= =?UTF-8?q?=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/dite/znpt/config/ExtUtilConfig.java | 78 +++++++++++++++++++ .../java/com/dite/znpt/constant/Message.java | 2 + .../domain/entity/InspectionReportEntity.java | 4 + .../domain/vo/InspectionReportListReq.java | 3 + .../znpt/domain/vo/InspectionReportReq.java | 4 + .../enums/InspectionReportStatusEnum.java | 51 ++++++++++++ .../znpt/service/InspectionReportService.java | 18 +++++ .../impl/InspectionReportServiceImpl.java | 69 +++++++++++++++- .../mapper/InspectionReportMapper.xml | 3 + .../znpt/web/controller/CommonController.java | 6 ++ .../InspectionReportController.java | 7 ++ 11 files changed, 242 insertions(+), 3 deletions(-) create mode 100644 core/src/main/java/com/dite/znpt/config/ExtUtilConfig.java create mode 100644 core/src/main/java/com/dite/znpt/enums/InspectionReportStatusEnum.java diff --git a/core/src/main/java/com/dite/znpt/config/ExtUtilConfig.java b/core/src/main/java/com/dite/znpt/config/ExtUtilConfig.java new file mode 100644 index 0000000..bef6847 --- /dev/null +++ b/core/src/main/java/com/dite/znpt/config/ExtUtilConfig.java @@ -0,0 +1,78 @@ +package com.dite.znpt.config; + +import cn.hutool.core.io.FileUtil; +import cn.hutool.core.util.RuntimeUtil; +import com.dite.znpt.constant.Message; +import com.dite.znpt.exception.ServiceException; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +@Data +@Configuration +@ConfigurationProperties(prefix = "util") +public class ExtUtilConfig { + + @ApiModelProperty("图片预处理工具路径") + private String imagePreTreatmentPath; + @ApiModelProperty("报告生成工具路径") + private String reportGeneratorPath; + @ApiModelProperty("报告生成工具模板路径") + private String reportGeneratorTemplatePath; + + /** + * 参数 缩写 默认值 说明 + * --input-dir 无 必需 输入图片目录路径 + * --input-file 无 必需 输入的单图,默认输出到输入值同一目录 + * --output-dir 无 输入目录+"+调整" 输出目录路径 + * --gamma 无 180 阴影检测阈值 (0-255) + * --threshold 无 253 高光检测阈值 (0-255) + * --config-file 无 naming_config.json 命名规则配置文件路径 + * --no-auto-bright 无 禁用 RAW文件禁用自动亮度调整 + * --quiet 无 禁用 减少控制台输出 + * --encoder 无 vitl 深度模型编码器类型 (vits/vitb/vitl/vitg) + * --input-size 无 518 模型输入图像尺寸 + * @param inputFile + * @param outputDir + * @return + */ + public String imagePreTreatment(String inputFile, String outputDir) { + boolean directory = FileUtil.isDirectory(inputFile); + try { + Process exec = RuntimeUtil.exec(imagePreTreatmentPath, + directory ? "--input-dir" : "--input-file", inputFile, + "--output-dir", outputDir + ); + exec.waitFor(); + return RuntimeUtil.getResult(exec); + } catch (InterruptedException e) { + throw new ServiceException(Message.UTIL_EXEC_ERROR + e.getMessage()); + } + } + + /** + * 功能描述:报告生成器 + * --turbine_id 是 指定要生成报告的机组ID + * --output_dir 是 指定生成报告的输出目录 + * --template_dir 是 指定Word模板文件所在的目录 + * @param turbineId 机组id + * @param outputDir 输出dir + * @return {@link String } + * @author cuizhibin + * @date 2025/07/17 14:08 + **/ + public String reportGenerator(String turbineId, String outputDir) { + try { + Process exec = RuntimeUtil.exec(reportGeneratorPath, + "--turbine_id", turbineId, + "--output_dir", outputDir, + "--template_dir", reportGeneratorTemplatePath + ); + exec.waitFor(); + return RuntimeUtil.getResult(exec); + } catch (InterruptedException e) { + throw new ServiceException(Message.UTIL_EXEC_ERROR + e.getMessage()); + } + } +} diff --git a/core/src/main/java/com/dite/znpt/constant/Message.java b/core/src/main/java/com/dite/znpt/constant/Message.java index 974043f..ef93a73 100644 --- a/core/src/main/java/com/dite/znpt/constant/Message.java +++ b/core/src/main/java/com/dite/znpt/constant/Message.java @@ -70,4 +70,6 @@ public class Message implements Serializable { public static final String SUGGESTION_LEVEL_TYPE_FORBID_REPEAT = "存在缺陷级别为[{}]缺陷类型为[{}]的维修建议"; public static final String CHECK_SCHEME_ID_IS_NOT_EXIST = "检查方案id不存在"; public static final String INSPECTION_REPORT_ID_IS_NOT_EXIST = "检查报告id不存在"; + public static final String UTIL_EXEC_ERROR = "工具执行出错:"; + public static final String REPORT_GENERATOR_ERROR = "报告生成出错"; } diff --git a/core/src/main/java/com/dite/znpt/domain/entity/InspectionReportEntity.java b/core/src/main/java/com/dite/znpt/domain/entity/InspectionReportEntity.java index 0e47de4..f3dbd81 100644 --- a/core/src/main/java/com/dite/znpt/domain/entity/InspectionReportEntity.java +++ b/core/src/main/java/com/dite/znpt/domain/entity/InspectionReportEntity.java @@ -91,4 +91,8 @@ public class InspectionReportEntity extends AuditableEntity implements Serializa @ApiModelProperty("报告审核时间") @TableField("report_audit_time") private LocalDateTime reportAuditTime; + + @ApiModelProperty("报告状态") + @TableField("report_status") + private String reportStatus; } diff --git a/core/src/main/java/com/dite/znpt/domain/vo/InspectionReportListReq.java b/core/src/main/java/com/dite/znpt/domain/vo/InspectionReportListReq.java index 9daa4d3..3118874 100644 --- a/core/src/main/java/com/dite/znpt/domain/vo/InspectionReportListReq.java +++ b/core/src/main/java/com/dite/znpt/domain/vo/InspectionReportListReq.java @@ -36,5 +36,8 @@ public class InspectionReportListReq implements Serializable { @ApiModelProperty("委托单位") private String client; + @ApiModelProperty("报告状态") + private String reportStatus; + } diff --git a/core/src/main/java/com/dite/znpt/domain/vo/InspectionReportReq.java b/core/src/main/java/com/dite/znpt/domain/vo/InspectionReportReq.java index dd5ebe4..4cd1442 100644 --- a/core/src/main/java/com/dite/znpt/domain/vo/InspectionReportReq.java +++ b/core/src/main/java/com/dite/znpt/domain/vo/InspectionReportReq.java @@ -87,4 +87,8 @@ public class InspectionReportReq implements Serializable { @NotNull(message = "报告审核时间不能为空") @ApiModelProperty("报告审核时间") private LocalDate reportAuditTime; + + @NotBlank(message = "报告状态不能为空") + @ApiModelProperty("报告状态") + private String reportStatus; } diff --git a/core/src/main/java/com/dite/znpt/enums/InspectionReportStatusEnum.java b/core/src/main/java/com/dite/znpt/enums/InspectionReportStatusEnum.java new file mode 100644 index 0000000..f142941 --- /dev/null +++ b/core/src/main/java/com/dite/znpt/enums/InspectionReportStatusEnum.java @@ -0,0 +1,51 @@ +package com.dite.znpt.enums; + +import cn.hutool.json.JSONObject; +import lombok.Getter; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author Bear.G + * @date 2025/6/26/周四 10:49 + * @description + */ +@Getter +public enum InspectionReportStatusEnum { + + PENDING("PENDING","待审核"), + PUBLISH("PUBLISH","已发布"); + + private final String code; + private final String desc; + + InspectionReportStatusEnum(String code, String desc){ + this.code = code; + this.desc = desc; + } + + public static InspectionReportStatusEnum getByCode(String code){ + for (InspectionReportStatusEnum e : InspectionReportStatusEnum.values() ) { + if(e.code.equals(code)){ + return e; + } + } + return null; + } + + public static String getDescByCode(String code){ + InspectionReportStatusEnum e = getByCode(code); + return null == e ? null : e.desc; + } + + public static List listAll(){ + List list = new ArrayList<>(InspectionReportStatusEnum.values().length); + for (InspectionReportStatusEnum e : InspectionReportStatusEnum.values() ) { + JSONObject jsonObject = new JSONObject(); + jsonObject.set(e.code, e.desc); + list.add(jsonObject); + } + return list; + } +} diff --git a/core/src/main/java/com/dite/znpt/service/InspectionReportService.java b/core/src/main/java/com/dite/znpt/service/InspectionReportService.java index df8db79..72a54fe 100644 --- a/core/src/main/java/com/dite/znpt/service/InspectionReportService.java +++ b/core/src/main/java/com/dite/znpt/service/InspectionReportService.java @@ -20,4 +20,22 @@ public interface InspectionReportService extends IService implements InspectionReportService { @Resource @@ -44,6 +49,8 @@ public class InspectionReportServiceImpl extends ServiceImpl page(InspectionReportListReq req) { @@ -135,4 +142,60 @@ public class InspectionReportServiceImpl extends ServiceImpl list = FileUtil.listFileNames(outputDir); + if (CollUtil.isEmpty(list)) { + throw new ServiceException(Message.REPORT_GENERATOR_ERROR); + } + AttachInfoEntity attachInfo = new AttachInfoEntity(); + attachInfo.setBusinessId(turbineId); + attachInfo.setAttachPath(FilePathEnum.ATTACH.getFileDownPath(outputDir + list.get(0))); + attachInfo.setBusinessType(AttachBusinessTypeEnum.REPORT.getCode()); + attachInfoService.save(attachInfo); + + ProjectEntity project = projectService.getById(turbine.getProjectId()); + InspectionReportEntity inspectionReport = new InspectionReportEntity(); + inspectionReport.setTitle(project.getProjectName() + turbine.getTurbineName()); + inspectionReport.setProjectId(project.getProjectId()); + inspectionReport.setTurbineId(turbineId); + inspectionReport.setReportWriteTime(LocalDateTime.now()); + inspectionReport.setReportStatus(InspectionReportStatusEnum.PENDING.getCode()); + baseMapper.insert(inspectionReport); + } + + /** + * 功能描述:发布 + * + * @param reportId 报告id + * @author cuizhibin + * @date 2025/07/17 21:25 + **/ + @Override + public void publish(String reportId) { + InspectionReportEntity report = getById(reportId); + if (Objects.isNull(report)) { + throw new ServiceException(Message.REPORT_GENERATOR_ERROR); + } + report.setReportStatus(InspectionReportStatusEnum.PUBLISH.getCode()); + report.setReportAuditor(StpUtil.getLoginIdAsString()); + report.setReportAuditTime(LocalDateTime.now()); + baseMapper.updateById(report); + } } diff --git a/core/src/main/resources/mapper/InspectionReportMapper.xml b/core/src/main/resources/mapper/InspectionReportMapper.xml index 7af2305..388cdaa 100644 --- a/core/src/main/resources/mapper/InspectionReportMapper.xml +++ b/core/src/main/resources/mapper/InspectionReportMapper.xml @@ -28,6 +28,9 @@ AND p.client LIKE concat('%', #{req.client}, '%') + + and ir.report_status like concat ('%', #{req.reportStatus}, '%') + diff --git a/web/src/main/java/com/dite/znpt/web/controller/CommonController.java b/web/src/main/java/com/dite/znpt/web/controller/CommonController.java index 75f14fe..62a9c8a 100644 --- a/web/src/main/java/com/dite/znpt/web/controller/CommonController.java +++ b/web/src/main/java/com/dite/znpt/web/controller/CommonController.java @@ -163,5 +163,11 @@ public class CommonController { return Result.ok(CheckMethodEnum.listAll()); } + @ApiOperation(value = "查询报告状态", httpMethod = "GET") + @GetMapping("/list/report-status") + public Result listReportStatus(){ + return Result.ok(InspectionReportStatusEnum.listAll()); + } + } diff --git a/web/src/main/java/com/dite/znpt/web/controller/InspectionReportController.java b/web/src/main/java/com/dite/znpt/web/controller/InspectionReportController.java index d43883c..de4906f 100644 --- a/web/src/main/java/com/dite/znpt/web/controller/InspectionReportController.java +++ b/web/src/main/java/com/dite/znpt/web/controller/InspectionReportController.java @@ -67,4 +67,11 @@ public class InspectionReportController { inspectionReportService.removeById(reportId); return Result.ok(); } + + @ApiOperation(value = "发布项目机组报告", httpMethod = "POST") + @PutMapping("/publish/{reportId}") + public Result publish(@PathVariable String reportId) { + inspectionReportService.publish(reportId); + return Result.ok(); + } }