From 0e6b02a8769d41ff6a4a4206dd949ca193d8ffdd Mon Sep 17 00:00:00 2001 From: buaixuexideshitongxue <2936013465@qq.com> Date: Wed, 22 Apr 2026 17:03:43 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=A2=84=E8=AD=A6=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E9=87=8D=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../warning/WarningBusinessController.java | 82 +++ .../controller/warning/WarningController.java | 25 +- .../pojo/entity/report/ReportProject.java | 20 + .../pojo/entity/warning/WarningContent.java | 3 + .../pojo/enums/FlowWarningEnum.java | 4 + .../pojo/param/Report/FlowQueryParam.java | 2 + .../pojo/param/Warning/CompileQueryParam.java | 18 + .../request/warning/WarningAuditRequest.java | 33 ++ .../request/warning/WarningEndRequest.java | 31 +- .../request/warning/WarningSaveRequest.java | 42 ++ .../request/warning/WarningSubmitRequest.java | 36 ++ .../pojo/vo/warning/WarningBusinessVo.java | 27 + .../Warning/WarningBusinessService.java | 57 ++ .../impl/WarningBusinessServiceImpl.java | 542 ++++++++++++++++++ .../resources/mapper/ReportProjectMapper.xml | 53 +- 15 files changed, 931 insertions(+), 44 deletions(-) create mode 100644 src/main/java/com/biutag/supervision/controller/warning/WarningBusinessController.java create mode 100644 src/main/java/com/biutag/supervision/pojo/param/Warning/CompileQueryParam.java create mode 100644 src/main/java/com/biutag/supervision/pojo/request/warning/WarningAuditRequest.java create mode 100644 src/main/java/com/biutag/supervision/pojo/request/warning/WarningSaveRequest.java create mode 100644 src/main/java/com/biutag/supervision/pojo/request/warning/WarningSubmitRequest.java create mode 100644 src/main/java/com/biutag/supervision/pojo/vo/warning/WarningBusinessVo.java create mode 100644 src/main/java/com/biutag/supervision/service/Warning/WarningBusinessService.java create mode 100644 src/main/java/com/biutag/supervision/service/Warning/impl/WarningBusinessServiceImpl.java diff --git a/src/main/java/com/biutag/supervision/controller/warning/WarningBusinessController.java b/src/main/java/com/biutag/supervision/controller/warning/WarningBusinessController.java new file mode 100644 index 0000000..8fdecfd --- /dev/null +++ b/src/main/java/com/biutag/supervision/controller/warning/WarningBusinessController.java @@ -0,0 +1,82 @@ +package com.biutag.supervision.controller.warning; + +import com.biutag.supervision.pojo.Result; +import com.biutag.supervision.pojo.entity.report.ReportFlow; +import com.biutag.supervision.pojo.entity.report.ReportProject; +import com.biutag.supervision.pojo.param.Report.FlowQueryParam; +import com.biutag.supervision.pojo.param.Warning.CompileQueryParam; +import com.biutag.supervision.pojo.request.warning.*; +import com.biutag.supervision.pojo.vo.warning.WarningBusinessVo; +import com.biutag.supervision.service.Warning.WarningBusinessService; +import com.baomidou.mybatisplus.core.metadata.IPage; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +/** + * 预警业务控制器 + */ +@Tag(name = "预警业务") +@RestController +@RequestMapping("/warning/business") +@RequiredArgsConstructor +public class WarningBusinessController { + + private final WarningBusinessService businessService; + + @Operation(summary = "获取预警详情") + @GetMapping("/{reportId}") + public Result getDetail(@PathVariable String reportId) { + return Result.success(businessService.getDetail(reportId)); + } + + @Operation(summary = "保存预警内容") + @PostMapping("/save") + public Result save(@RequestBody WarningSaveRequest request) { + businessService.save(request); + return Result.success(); + } + + @Operation(summary = "提交给领导审批") + @PostMapping("/submit") + public Result submit(@RequestBody WarningSubmitRequest request) { + businessService.submit(request); + return Result.success(); + } + + @Operation(summary = "直接结束预警") + @PostMapping("/end") + public Result end(@RequestBody WarningEndRequest request) { + businessService.end(request); + return Result.success(); + } + + @Operation(summary = "领导审批-驳回") + @PostMapping("/audit/reject") + public Result auditReject(@RequestBody WarningAuditRequest request) { + businessService.auditReject(request); + return Result.success(); + } + + @Operation(summary = "领导审批-通过(带问题数据分发)") + @PostMapping("/audit/pass/distribute") + public Result auditPassDistribute(@RequestBody FlowQueryParam queryParam) { + businessService.auditPassWithDistribute(queryParam); + return Result.success(); + } + + @Operation(summary = "获取预警审批记录") + @GetMapping("/flow/{reportId}") + public Result> getFlowList(@PathVariable String reportId) { + return Result.success(businessService.getFlowList(reportId)); + } + + @Operation(summary = "预警项目列表(编译台账)") + @PostMapping("/compile/page") + public Result> compilePage(@RequestBody CompileQueryParam param) { + return Result.success(businessService.compilePage(param)); + } +} diff --git a/src/main/java/com/biutag/supervision/controller/warning/WarningController.java b/src/main/java/com/biutag/supervision/controller/warning/WarningController.java index 7ce80b0..54a290c 100644 --- a/src/main/java/com/biutag/supervision/controller/warning/WarningController.java +++ b/src/main/java/com/biutag/supervision/controller/warning/WarningController.java @@ -198,8 +198,8 @@ public class WarningController { private QueryWrapper buildWarningWrapper(WarningQueryParam queryParam, UserAuth user) { QueryWrapper wrapper = new QueryWrapper() .like(StrUtil.isNotBlank(queryParam.getReportName()), "p.report_name", queryParam.getReportName()) - .eq("f.report_link", "end") - .eq("f.approver_state", "end") +// .eq("f.report_link", "end") +// .eq("f.approver_state", "end") .eq(StrUtil.isNotBlank(queryParam.getWarningState()), "p.warning_state", queryParam.getWarningState()) .eq("p.node", FlowStateEnum.End.getLabel()) .eq("p.delete_flag", DeleteStatusEnum.NO.getCode()); @@ -245,17 +245,16 @@ public class WarningController { * 填充项目数据 */ private void fillProjectData(EntryWindowVo s) { - List list = recordService.list( - new LambdaQueryWrapper().eq(WarningRecord::getReportId, s.getId())); - - if (CollectionUtil.isNotEmpty(list)) { - // 是否已下发问题 - s.setStateData(list.stream().anyMatch(x -> "1".equals(x.getFlowState())) ? "1" : "0"); - // 预警问题数 - List ids = list.stream().map(WarningRecord::getId).toList(); - s.setWarningContent(contentService.count( - new LambdaQueryWrapper().in(WarningContent::getWarningId, ids).isNotNull(WarningContent::getRemark))); - } + // 是否已下发问题:根据 negativeId 判断 + s.setStateData(StrUtil.isNotBlank(s.getNegativeId()) ? "1" : "0"); + + // 预警问题数:有 remark 且 remark 不为空的内容条目数 + long contentCount = contentService.count( + new LambdaQueryWrapper() + .eq(WarningContent::getReportId, s.getId()) + .isNotNull(WarningContent::getRemark) + .ne(WarningContent::getRemark, "")); + s.setWarningContent(contentCount); // 格式化单位字符串 s.setAuditUnitStr(formatDepartStr(departService.getById(s.getAuditUnitId()))); diff --git a/src/main/java/com/biutag/supervision/pojo/entity/report/ReportProject.java b/src/main/java/com/biutag/supervision/pojo/entity/report/ReportProject.java index bb64d2f..12da9ca 100644 --- a/src/main/java/com/biutag/supervision/pojo/entity/report/ReportProject.java +++ b/src/main/java/com/biutag/supervision/pojo/entity/report/ReportProject.java @@ -161,10 +161,30 @@ public class ReportProject { @Schema(description = "预警状态") @TableField("warning_state") private String warningState; + + //预警监督人员 + @TableField("warning_supervision") + private String warningSupervision; + //预警监督人员ID + @TableField("warning_supervision_id") + private String warningSupervisionId; + //预警监督日期 + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @TableField("supervision_time") + private LocalDateTime supervisionTime; + + @TableField("negative_id") + private String negativeId; + //是否退窗 @TableField("is_recessed") private int isRecessed; + @Schema(description = "处理状态(非数据库字段)") + @TableField(exist = false) + private String processingStatus; + /** * @see AppConstants diff --git a/src/main/java/com/biutag/supervision/pojo/entity/warning/WarningContent.java b/src/main/java/com/biutag/supervision/pojo/entity/warning/WarningContent.java index 3e86ec7..57138f4 100644 --- a/src/main/java/com/biutag/supervision/pojo/entity/warning/WarningContent.java +++ b/src/main/java/com/biutag/supervision/pojo/entity/warning/WarningContent.java @@ -16,6 +16,9 @@ public class WarningContent { @TableField("warning_id") private String warningId; + @TableField("report_id") + private String reportId; + @TableField("genre") private String genre; diff --git a/src/main/java/com/biutag/supervision/pojo/enums/FlowWarningEnum.java b/src/main/java/com/biutag/supervision/pojo/enums/FlowWarningEnum.java index a537f9a..e737a5b 100644 --- a/src/main/java/com/biutag/supervision/pojo/enums/FlowWarningEnum.java +++ b/src/main/java/com/biutag/supervision/pojo/enums/FlowWarningEnum.java @@ -14,6 +14,10 @@ public enum FlowWarningEnum { inform("inform","报审单位签收"), + directend("directend", "直接结束"), + + toleader("toleader", "提交至领导"), + leader("leader","领导审核"), end("end","结束"); diff --git a/src/main/java/com/biutag/supervision/pojo/param/Report/FlowQueryParam.java b/src/main/java/com/biutag/supervision/pojo/param/Report/FlowQueryParam.java index f2b29b7..64ef74b 100644 --- a/src/main/java/com/biutag/supervision/pojo/param/Report/FlowQueryParam.java +++ b/src/main/java/com/biutag/supervision/pojo/param/Report/FlowQueryParam.java @@ -7,6 +7,8 @@ import lombok.extern.slf4j.Slf4j; @Data @Slf4j public class FlowQueryParam { + //流程ID + private String flowId; //是否通知报审人 private String isInform; //项目id diff --git a/src/main/java/com/biutag/supervision/pojo/param/Warning/CompileQueryParam.java b/src/main/java/com/biutag/supervision/pojo/param/Warning/CompileQueryParam.java new file mode 100644 index 0000000..d6b20a4 --- /dev/null +++ b/src/main/java/com/biutag/supervision/pojo/param/Warning/CompileQueryParam.java @@ -0,0 +1,18 @@ +package com.biutag.supervision.pojo.param.Warning; + +import com.biutag.supervision.pojo.param.BasePage; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.EqualsAndHashCode; + +@Data +@EqualsAndHashCode(callSuper = true) +@Schema(description = "编译台账查询参数") +public class CompileQueryParam extends BasePage { + + @Schema(description = "项目名称(模糊查询)") + private String name; + + @Schema(description = "处理状态:已修复/未修复") + private String processingStatus; +} diff --git a/src/main/java/com/biutag/supervision/pojo/request/warning/WarningAuditRequest.java b/src/main/java/com/biutag/supervision/pojo/request/warning/WarningAuditRequest.java new file mode 100644 index 0000000..7e36a65 --- /dev/null +++ b/src/main/java/com/biutag/supervision/pojo/request/warning/WarningAuditRequest.java @@ -0,0 +1,33 @@ +package com.biutag.supervision.pojo.request.warning; + +import cn.hutool.core.util.StrUtil; +import com.biutag.supervision.aop.ParamChecked; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +/** + * 预警审批请求 + */ +@Data +@Schema(description = "预警审批请求") +public class WarningAuditRequest implements ParamChecked { + + @Schema(description = "流程id") + private String flowId; + + @Schema(description = "项目id") + private String reportId; + + @Schema(description = "审批意见") + private String approverMessage; + + @Override + public void check() { + if (StrUtil.isBlank(flowId)) { + throw new IllegalArgumentException("流程id不能为空"); + } + if (StrUtil.isBlank(reportId)) { + throw new IllegalArgumentException("项目id不能为空"); + } + } +} diff --git a/src/main/java/com/biutag/supervision/pojo/request/warning/WarningEndRequest.java b/src/main/java/com/biutag/supervision/pojo/request/warning/WarningEndRequest.java index c7aa3a3..5015be4 100644 --- a/src/main/java/com/biutag/supervision/pojo/request/warning/WarningEndRequest.java +++ b/src/main/java/com/biutag/supervision/pojo/request/warning/WarningEndRequest.java @@ -3,41 +3,34 @@ package com.biutag.supervision.pojo.request.warning; import cn.hutool.core.util.StrUtil; import com.biutag.supervision.aop.ParamChecked; import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Getter; -import lombok.Setter; +import lombok.Data; + +import java.util.List; /** - * @ClassName WarningEndRequest - * @Description WarningEndRequest - * @Author shihao - * @Date 2025/12/24 11:40 + * 预警直接结束请求 + * 预警监督人员和预警监督时间由后端通过 UserContextHolder 自动获取 */ -@Getter -@Setter -@Schema(description = "预警结束请求") +@Data +@Schema(description = "预警直接结束请求") public class WarningEndRequest implements ParamChecked { @Schema(description = "项目id") private String reportId; - @Schema(description = "flowId") + @Schema(description = "流程id(驳回后重新提交时需要)") private String flowId; - //是否通知报审人 - private String isInform; + @Schema(description = "预警内容列表") + private List contents; //审批意见 private String message; - @Override public void check() { - if (StrUtil.isBlank(reportId)){ - throw new IllegalArgumentException("项目id不能为空"); + if (StrUtil.isBlank(reportId)) { + throw new IllegalArgumentException("项目id不能为空"); } - -// if (StrUtil.isBlank(flowId)){ -// throw new IllegalArgumentException("flowid不能为空"); -// } } } diff --git a/src/main/java/com/biutag/supervision/pojo/request/warning/WarningSaveRequest.java b/src/main/java/com/biutag/supervision/pojo/request/warning/WarningSaveRequest.java new file mode 100644 index 0000000..fb66003 --- /dev/null +++ b/src/main/java/com/biutag/supervision/pojo/request/warning/WarningSaveRequest.java @@ -0,0 +1,42 @@ +package com.biutag.supervision.pojo.request.warning; + +import cn.hutool.core.util.StrUtil; +import com.biutag.supervision.aop.ParamChecked; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.util.List; + +/** + * 预警保存请求 + */ +@Data +@Schema(description = "预警保存请求") +public class WarningSaveRequest implements ParamChecked { + + @Schema(description = "项目id") + private String reportId; + + @Schema(description = "预警内容列表") + private List contents; + + @Data + @Schema(description = "预警内容项") + public static class WarningContentItem { + @Schema(description = "类型") + private String type; + @Schema(description = "标题") + private String title; + @Schema(description = "内容") + private String content; + @Schema(description = "问题详情") + private String remark; + } + + @Override + public void check() { + if (StrUtil.isBlank(reportId)) { + throw new IllegalArgumentException("项目id不能为空"); + } + } +} diff --git a/src/main/java/com/biutag/supervision/pojo/request/warning/WarningSubmitRequest.java b/src/main/java/com/biutag/supervision/pojo/request/warning/WarningSubmitRequest.java new file mode 100644 index 0000000..3f31e12 --- /dev/null +++ b/src/main/java/com/biutag/supervision/pojo/request/warning/WarningSubmitRequest.java @@ -0,0 +1,36 @@ +package com.biutag.supervision.pojo.request.warning; + +import cn.hutool.core.util.StrUtil; +import com.biutag.supervision.aop.ParamChecked; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 预警提交请求(提交给领导) + * 预警监督人员和预警监督时间由后端通过 UserContextHolder 自动获取 + */ +@Data +@Schema(description = "预警提交请求") +public class WarningSubmitRequest implements ParamChecked { + + @Schema(description = "领导ID") + private String approverId; + + @Schema(description = "项目id") + private String reportId; + + @Schema(description = "领导名字") + private String approver; + + @Override + public void check() { + if (StrUtil.isBlank(approverId)) { + throw new IllegalArgumentException("领导ID不能为空"); + } + + if (StrUtil.isBlank(reportId)) { + throw new IllegalArgumentException("项目ID不能为空"); + } + } +} diff --git a/src/main/java/com/biutag/supervision/pojo/vo/warning/WarningBusinessVo.java b/src/main/java/com/biutag/supervision/pojo/vo/warning/WarningBusinessVo.java new file mode 100644 index 0000000..33055aa --- /dev/null +++ b/src/main/java/com/biutag/supervision/pojo/vo/warning/WarningBusinessVo.java @@ -0,0 +1,27 @@ +package com.biutag.supervision.pojo.vo.warning; + +import com.biutag.supervision.pojo.entity.report.ReportFlow; +import com.biutag.supervision.pojo.entity.report.ReportProject; +import com.biutag.supervision.pojo.entity.warning.WarningContent; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.util.List; + +/** + * 预警业务详情VO + */ +@Data +@Schema(description = "预警业务详情VO") +public class WarningBusinessVo { + + @Schema(description = "项目信息") + private ReportProject reportProject; + + @Schema(description = "预警内容列表") + private List contents; + + @Schema(description = "审批记录列表") + private List flowList; + +} diff --git a/src/main/java/com/biutag/supervision/service/Warning/WarningBusinessService.java b/src/main/java/com/biutag/supervision/service/Warning/WarningBusinessService.java new file mode 100644 index 0000000..9563162 --- /dev/null +++ b/src/main/java/com/biutag/supervision/service/Warning/WarningBusinessService.java @@ -0,0 +1,57 @@ +package com.biutag.supervision.service.Warning; + +import com.biutag.supervision.pojo.entity.report.ReportFlow; +import com.biutag.supervision.pojo.entity.report.ReportProject; +import com.biutag.supervision.pojo.param.Report.FlowQueryParam; +import com.biutag.supervision.pojo.param.Warning.CompileQueryParam; +import com.biutag.supervision.pojo.request.warning.*; +import com.biutag.supervision.pojo.vo.warning.WarningBusinessVo; +import com.baomidou.mybatisplus.core.metadata.IPage; + +import java.util.List; + +/** + * 预警业务服务接口 + */ +public interface WarningBusinessService { + + /** + * 获取预警详情 + */ + WarningBusinessVo getDetail(String reportId); + + /** + * 保存预警内容 + */ + void save(WarningSaveRequest request); + + /** + * 提交给领导审批 + */ + void submit(WarningSubmitRequest request); + + /** + * 直接结束预警 + */ + void end(WarningEndRequest request); + + /** + * 领导审批-驳回 + */ + void auditReject(WarningAuditRequest request); + + /** + * 领导审批-通过(带问题数据分发) + */ + void auditPassWithDistribute(FlowQueryParam queryParam); + + /** + * 获取预警审批记录 + */ + List getFlowList(String reportId); + + /** + * 预警项目列表(编译台账) + */ + IPage compilePage(CompileQueryParam param); +} diff --git a/src/main/java/com/biutag/supervision/service/Warning/impl/WarningBusinessServiceImpl.java b/src/main/java/com/biutag/supervision/service/Warning/impl/WarningBusinessServiceImpl.java new file mode 100644 index 0000000..6cdf1df --- /dev/null +++ b/src/main/java/com/biutag/supervision/service/Warning/impl/WarningBusinessServiceImpl.java @@ -0,0 +1,542 @@ +package com.biutag.supervision.service.Warning.impl; + +import cn.hutool.core.util.StrUtil; +import com.baomidou.dynamic.datasource.annotation.DSTransactional; +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.extension.plugins.pagination.Page; +import com.biutag.supervision.common.UserContextHolder; +import com.biutag.supervision.constants.enums.*; +import com.biutag.supervision.mapper.InformMessageMapper; +import com.biutag.supervision.mapper.Negative.NegativeMapper; +import com.biutag.supervision.mapper.Report.ReportFlowMapper; +import com.biutag.supervision.mapper.Report.ReportProjectMapper; +import com.biutag.supervision.mapper.Warning.WarningContentMapper; +import com.biutag.supervision.pojo.entity.InformMessage; +import com.biutag.supervision.pojo.entity.SupDepart; +import com.biutag.supervision.pojo.entity.negative.DataDataPetitionComplainDistribute; +import com.biutag.supervision.pojo.entity.negative.Negative; +import com.biutag.supervision.pojo.entity.report.ReportFlow; +import com.biutag.supervision.pojo.entity.report.ReportProject; +import com.biutag.supervision.pojo.entity.warning.WarningContent; +import com.biutag.supervision.pojo.entity.warning.WarningRecord; +import com.biutag.supervision.pojo.enums.FlowStateEnum; +import com.biutag.supervision.pojo.enums.FlowWarningEnum; +import com.biutag.supervision.pojo.model.UserAuth; +import com.biutag.supervision.pojo.model.negative.NegativeDto; +import com.biutag.supervision.pojo.param.Report.FlowQueryParam; +import com.biutag.supervision.pojo.param.Warning.CompileQueryParam; +import com.biutag.supervision.pojo.request.warning.*; +import com.biutag.supervision.pojo.vo.warning.WarningBusinessVo; +import com.biutag.supervision.service.Negative.NegativeService; +import com.biutag.supervision.service.Negative.NegativeThingFileService; +import com.biutag.supervision.service.Negative.NegativeWorkService; +import com.biutag.supervision.service.SupDepartService; +import com.biutag.supervision.service.SupDictDataTwoService; +import com.biutag.supervision.service.Warning.WarningBusinessService; +import com.biutag.supervision.service.Warning.WarningRecordService; +import com.baomidou.mybatisplus.core.metadata.IPage; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.text.SimpleDateFormat; +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * 预警业务服务实现 + */ +@Slf4j +@Service +@RequiredArgsConstructor +public class WarningBusinessServiceImpl implements WarningBusinessService { + + private final ReportProjectMapper projectMapper; + private final ReportFlowMapper flowMapper; + private final WarningContentMapper contentMapper; + private final InformMessageMapper informMessageMapper; + private final WarningRecordService warningRecordService; + private final ReportProjectMapper reportProjectMapper; + private final SupDepartService departService; + private final WarningContentMapper warningContentMapper; + private final NegativeService negativeService; + private final NegativeMapper negativeMapper; + + @Override + public WarningBusinessVo getDetail(String reportId) { + UserAuth user = UserContextHolder.getCurrentUser(); + WarningBusinessVo vo = new WarningBusinessVo(); + + // 查询项目信息 + ReportProject project = projectMapper.selectById(reportId); + vo.setReportProject(project); + + // 查询预警内容列表 + List contents = contentMapper.selectList( + new LambdaQueryWrapper() + .eq(WarningContent::getReportId, reportId) + .orderByAsc(WarningContent::getId) + ); + vo.setContents(contents); + + // 查询审批记录 + List flows = flowMapper.selectList( + new LambdaQueryWrapper() + .eq(ReportFlow::getReportId, reportId) + .eq(ReportFlow::getType, "warning") + .orderByAsc(ReportFlow::getAreportTime) + ); + vo.setFlowList(flows); + + + return vo; + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void save(WarningSaveRequest request) { + UserAuth user = UserContextHolder.getCurrentUser(); + + // 更新项目监督信息(由后端自动获取) + ReportProject project = new ReportProject(); + project.setId(request.getReportId()); + project.setWarningSupervisionId(user.getUserName()); + project.setWarningSupervision(user.getNickName()); + project.setSupervisionTime(LocalDateTime.now()); + projectMapper.updateById(project); + + // 保存预警内容 + saveWarningContents(request.getReportId(), request.getContents()); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void submit(WarningSubmitRequest request) { + UserAuth user = UserContextHolder.getCurrentUser(); + + // 1. 更新项目监督信息(由后端自动获取) + ReportProject project = new ReportProject(); + project.setId(request.getReportId()); + project.setWarningSupervisionId(user.getUserName()); + project.setWarningSupervision(user.getNickName()); + project.setSupervisionTime(LocalDateTime.now()); + project.setWarningState(WarningStateEnum.YTZ.getCode()); // 预警中 + projectMapper.updateById(project); + + // 2. 自动查找当前用户的有效 flow 并更新状态 + String currentFlowId = findCurrentUserValidFlowId(request.getReportId()); + if (currentFlowId != null) { + ReportFlow currentFlow = new ReportFlow(); + currentFlow.setId(currentFlowId); + currentFlow.setApproverState(FlowStateEnum.End.getLabel()); + currentFlow.setApproverTime(LocalDateTime.now()); + flowMapper.updateById(currentFlow); + } + + // 创建一条自己提交的记录 + ReportFlow selfFlow = new ReportFlow(); + selfFlow.setReportId(request.getReportId()); + selfFlow.setReportLink(FlowWarningEnum.toleader.getLabel()); + selfFlow.setReportCode(FlowWarningEnum.toleader.getValue()); + selfFlow.setAreportTime(LocalDateTime.now()); + selfFlow.setApproverState(FlowStateEnum.End.getLabel()); + selfFlow.setApprover(user.getNickName()); + selfFlow.setApproverId(user.getUserName()); + selfFlow.setType("warning"); + flowMapper.insert(selfFlow); + + // 3. 创建审批流程记录(提交给领导) + ReportFlow flow = new ReportFlow(); + flow.setReportId(request.getReportId()); + flow.setReportLink(FlowWarningEnum.leader.getLabel()); + flow.setReportCode(FlowWarningEnum.leader.getValue()); + flow.setAreportTime(LocalDateTime.now()); + flow.setApproverState(FlowStateEnum.Start.getLabel()); + flow.setApprover(request.getApprover()); + flow.setApproverId(request.getApproverId()); + flow.setType("warning"); + flowMapper.insert(flow); +// System.out.println(1/0); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void end(WarningEndRequest request) { + UserAuth user = UserContextHolder.getCurrentUser(); + + // 1. 更新项目状态(由后端自动获取预警监督人和时间) + ReportProject project = new ReportProject(); + project.setId(request.getReportId()); + project.setWarningSupervisionId(user.getUserName()); + project.setWarningSupervision(user.getNickName()); + project.setSupervisionTime(LocalDateTime.now()); + project.setWarningState(WarningStateEnum.YWJ.getCode()); + projectMapper.updateById(project); + + // 2. 保存预警内容 + saveWarningContents(request.getReportId(), request.getContents()); + + // 3. 自动查找当前用户的有效 flow 并结束 + String currentFlowId = findCurrentUserValidFlowId(request.getReportId()); + if (currentFlowId != null) { + ReportFlow currentFlow = new ReportFlow(); + currentFlow.setId(currentFlowId); + currentFlow.setApproverState(FlowStateEnum.End.getLabel()); + currentFlow.setApproverTime(LocalDateTime.now()); + flowMapper.updateById(currentFlow); + } + + // 4. 创建结束流程记录 + ReportFlow endFlow = new ReportFlow(); + endFlow.setReportId(request.getReportId()); + endFlow.setReportLink(FlowWarningEnum.directend.getLabel()); + endFlow.setReportCode(FlowWarningEnum.directend.getValue()); + endFlow.setAreportTime(LocalDateTime.now()); + endFlow.setApprover(user.getNickName()); + endFlow.setApproverId(user.getUserName()); + endFlow.setApproverTime(LocalDateTime.now()); + endFlow.setApproverState(FlowStateEnum.End.getLabel()); + endFlow.setType("warning"); + flowMapper.insert(endFlow); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void auditReject(WarningAuditRequest request) { + // 1. 更新当前流程状态为驳回 + ReportFlow currentFlow = new ReportFlow(); + currentFlow.setId(request.getFlowId()); + currentFlow.setApproverState(FlowStateEnum.Reject.getLabel()); + currentFlow.setApproverTime(LocalDateTime.now()); + currentFlow.setApproverMessage(request.getApproverMessage()); + flowMapper.updateById(currentFlow); + + + ReportProject reportProject = projectMapper.selectById(request.getReportId()); + reportProject.setWarningState(WarningStateEnum.WYJ.getCode()); + int i = projectMapper.updateById(reportProject); + if (i > 1) { + throw new RuntimeException("操作错误"); + } + + // 2. 创建新的流程记录给预警人 + ReportFlow newFlow = new ReportFlow(); + newFlow.setReportId(request.getReportId()); + newFlow.setReportLink(FlowWarningEnum.state.getLabel()); + newFlow.setReportCode(FlowWarningEnum.state.getValue()); + newFlow.setAreportTime(LocalDateTime.now()); + newFlow.setApprover(reportProject.getWarningSupervision()); + newFlow.setApproverId(reportProject.getWarningSupervisionId()); + newFlow.setApproverState(FlowStateEnum.Start.getLabel()); + newFlow.setType("warning"); + flowMapper.insert(newFlow); +// System.out.println(1/0); + } + + @Override + @DSTransactional(rollbackFor = Exception.class) + public void auditPassWithDistribute(FlowQueryParam queryParam) { + UserAuth user = UserContextHolder.getCurrentUser(); + String reportId = queryParam.getReportId(); + + // 0. 获取项目信息 + ReportProject project = projectMapper.selectById(reportId); + + // 0.1 通知报审人 + if ("1".equals(queryParam.getIsInform())) { + postInfoMessage(queryParam, project); + } + + // 1. 更新当前流程状态为通过 + if (StrUtil.isNotBlank(queryParam.getFlowId())) { + ReportFlow currentFlow = new ReportFlow(); + currentFlow.setId(queryParam.getFlowId()); + currentFlow.setApproverState(FlowStateEnum.End.getLabel()); + currentFlow.setApproverTime(LocalDateTime.now()); + currentFlow.setApproverMessage(queryParam.getMessage()); + currentFlow.setApprover(user.getNickName()); + currentFlow.setApproverId(user.getUserName()); + flowMapper.updateById(currentFlow); + } + + // 2. 生成问题数据 + if (queryParam.getData() != null) { + createNegativeDataForBusiness(reportId, queryParam.getData()); + } + + // 3. 更新项目状态为已预警监督 + projectMapper.update( + new LambdaUpdateWrapper() + .eq(ReportProject::getId, reportId) + .set(ReportProject::getWarningState, WarningStateEnum.YWJ.getCode()) + .set(ReportProject::getSupervisionTime, LocalDateTime.now()) + ); + + // 4. 创建结束流程记录 +// ReportFlow endFlow = new ReportFlow(); +// endFlow.setReportId(reportId); +// endFlow.setReportLink(FlowWarningEnum.end.getLabel()); +// endFlow.setReportCode(FlowWarningEnum.end.getValue()); +// endFlow.setAreportTime(LocalDateTime.now()); +// endFlow.setApprover(user.getNickName()); +// endFlow.setApproverId(user.getUserName()); +// endFlow.setApproverTime(LocalDateTime.now()); +// endFlow.setApproverMessage(queryParam.getMessage()); +// endFlow.setApproverState(FlowStateEnum.End.getLabel()); +// endFlow.setType("warning"); +// flowMapper.insert(endFlow); +// System.out.println(1/0); + } + + /** + * 发送通知(通知报审人) + */ + private void postInfoMessage(FlowQueryParam queryParam, ReportProject project) { + UserAuth user = UserContextHolder.getCurrentUser(); + // 获取预警记录信息 + WarningRecord record = warningRecordService.getOne( + new LambdaQueryWrapper() + .eq(WarningRecord::getReportId, project.getId()) + .orderByDesc(WarningRecord::getId) + .last("limit 1") + ); + + String node = record != null ? record.getNode() : FlowWarningEnum.end.getLabel(); + String recipient = project.getApplicant(); + String recipientId = project.getApplicantId(); + + InformMessage informMessage = new InformMessage(); + informMessage.setReportId(queryParam.getReportId()); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + String newDate = sdf.format(new Date()); + informMessage.setCrtTime(LocalDateTime.now()); + informMessage.setNode(FlowWarningEnum.contains(node)); + informMessage.setMessage(project.getReportName() + "项目于" + newDate + "下发至数字督察平台,意见【" + queryParam.getMessage()+ "】"); + informMessage.setCrtUserId(StrUtil.isNotBlank(queryParam.getApproverId()) ? queryParam.getApproverId() : user.getUserId()); + informMessage.setCrtUser(StrUtil.isNotBlank(queryParam.getApprover()) ? queryParam.getApprover() : user.getNickName()); + informMessage.setRecipient(recipient); + informMessage.setRecipientId(recipientId); + informMessage.setFlowState(FlowStateEnum.End.getLabel()); + informMessageMapper.insert(informMessage); + } + + @Override + public List getFlowList(String reportId) { + return flowMapper.selectList( + new LambdaQueryWrapper() + .eq(ReportFlow::getReportId, reportId) + .eq(ReportFlow::getType, "warning") + .orderByAsc(ReportFlow::getAreportTime) + ); + } + + @Override + public IPage compilePage(CompileQueryParam param) { + // 1. 查询所有有 negativeId 的 ReportProject,收集 negativeId + QueryWrapper idWrapper = new QueryWrapper<>(); + idWrapper.isNotNull("negative_id"); + List allNegativeIds = projectMapper.selectList(idWrapper).stream().map(ReportProject::getNegativeId).toList(); + + if (allNegativeIds.isEmpty()) { + return new Page<>(param.getCurrent(), param.getSize(), 0); + } + + // 2. 批量查询 Negative,获取所有状态 + LambdaQueryWrapper allNegativeWrapper = new LambdaQueryWrapper().in(Negative::getId, allNegativeIds); + List negatives = negativeMapper.selectList(allNegativeWrapper); + Map statusMap = negatives.stream().collect(Collectors.toMap(Negative::getId, Negative::getProcessingStatus)); + + List filteredNegativeIds = allNegativeIds; + if (StrUtil.isNotBlank(param.getProcessingStatus())) { + if ("已修复".equals(param.getProcessingStatus())){ + filteredNegativeIds = negatives.stream().filter(one -> "completed".equals(one.getProcessingStatus())).map(Negative::getId).toList(); + } + if ("未修复".equals(param.getProcessingStatus())){ + filteredNegativeIds = negatives.stream().filter(one -> !"completed".equals(one.getProcessingStatus())).map(Negative::getId).toList(); + } + } + if (filteredNegativeIds.isEmpty()) { + return new Page<>(param.getCurrent(), param.getSize(), 0); + } + // 4. 构建分页查询条件 + QueryWrapper wrapper = new QueryWrapper<>(); + if (StrUtil.isNotBlank(param.getName())) { + wrapper.like("report_name", param.getName()); + } + if (StrUtil.isNotBlank(param.getProcessingStatus())) { + wrapper.in("negative_id", filteredNegativeIds); + } else { + wrapper.in("negative_id", allNegativeIds); + } + wrapper.orderByDesc("supervision_time"); + + // 5. 分页查询 + IPage page = projectMapper.selectPage( + new Page<>(param.getCurrent(), param.getSize()), + wrapper + ); + + // 6. 内存关联 processingStatus + for (ReportProject record : page.getRecords()) { + String status = statusMap.get(record.getNegativeId()); + record.setProcessingStatus("completed".equals(status) ? "已修复" : "未修复"); + } + + return page; + } + + /** + * 查找当前用户待处理的预警流程ID + */ + private String findCurrentUserValidFlowId(String reportId) { + UserAuth user = UserContextHolder.getCurrentUser(); + List flows = flowMapper.selectList( + new LambdaQueryWrapper() + .eq(ReportFlow::getReportId, reportId) + .eq(ReportFlow::getType, "warning") + .eq(ReportFlow::getApproverId, user.getUserName()) + .eq(ReportFlow::getApproverState, FlowStateEnum.Start.getLabel()) + ); + return flows.isEmpty() ? null : flows.get(0).getId(); + } + + /** + * 保存预警内容 + */ + private void saveWarningContents(String reportId, List contents) { + if (contents == null || contents.isEmpty()) { + return; + } + + // 先删除旧的预警内容 + contentMapper.delete(new LambdaQueryWrapper().eq(WarningContent::getReportId, reportId)); + + // 保存新的预警内容 + List entities = new ArrayList<>(); + for (WarningSaveRequest.WarningContentItem item : contents) { + WarningContent content = new WarningContent(); + content.setReportId(reportId); + content.setType(item.getType()); + content.setTitle(item.getTitle()); + content.setContent(item.getContent()); + content.setRemark(item.getRemark()); + entities.add(content); + } + + if (!entities.isEmpty()) { + contentMapper.insert(entities.get(0)); + if (entities.size() > 1) { + for (int i = 1; i < entities.size(); i++) { + contentMapper.insert(entities.get(i)); + } + } + } + } + + + + + /** + * 业务预警通过时生成问题数据(不依赖 WarningRecord) + * 将所有 remark 合并成一条 negative + * + * @param reportId 项目ID + * @param data 业务数据(业务类别、涉嫌问题、警种、办理时限等) + */ + public void createNegativeDataForBusiness(String reportId, DataDataPetitionComplainDistribute data) { + // 1. 获取项目信息 + ReportProject project = reportProjectMapper.selectById(reportId); + if (project == null) { + throw new RuntimeException("项目不存在: " + reportId); + } + + // 2. 获取预警内容(过滤出有 remark 的) + List contents = warningContentMapper.selectList( + new LambdaQueryWrapper() + .eq(WarningContent::getReportId, reportId) + ); + + List filteredContents = contents.stream() + .filter(c -> StrUtil.isNotBlank(c.getRemark())) + .toList(); + + if (filteredContents.isEmpty()) { + log.warn("预警内容无有效数据,不生成问题: reportId={}", reportId); + return; + } + + // 3. 合并所有 remark 成一条 thingDesc + StringBuilder thingDescBuilder = new StringBuilder("项目名称: " + project.getReportName() +",存在问题:" ) ; + for (WarningContent content : filteredContents) { + thingDescBuilder.append(",").append(content.getRemark()); + } + thingDescBuilder.append(",请及时查收并在规定时限内完成整改。"); + + // 4. 只生成一条 negative + NegativeDto negativeDto = new NegativeDto(); + + // 时间相关 + negativeDto.setHappenTime(project.getSupervisionTime()); + negativeDto.setDiscoveryTime(project.getSupervisionTime()); + + // 问题来源 + negativeDto.setProblemSourcesCode("27"); + negativeDto.setProblemSources(ProblemSourcesEnum.get("27").getLabel()); + + // 业务数据(来自弹窗) + negativeDto.setBusinessTypeCode(data.getBusinessTypeCode()); + negativeDto.setPoliceType(data.getPoliceType()); + negativeDto.setInvolveProblem(data.getInvolveProblem()); + + // 问题描述(合并后的) + negativeDto.setThingDesc(thingDescBuilder.toString()); + + // 单位处理 + SupDepart depart = departService.getById(project.getProjectUnitId()); + if (depart == null) { + throw new RuntimeException("项目单位不存在: " + project.getProjectUnitId()); + } + if (DepartLevelEnum.SECOND.getValue().equals(depart.getLevel())) { + negativeDto.setDepartId(project.getProjectUnitId()); + } else if (DepartLevelEnum.THREE.getValue().equals(depart.getLevel())) { + if (DistributionFlowEnum.SECOND.getValue().equals(data.getDistributionFlow())) { + negativeDto.setDepartId(depart.getPid()); + } else { + negativeDto.setDepartId(depart.getId()); + } + } else { + throw new RuntimeException("指定办理单位 请选择二级或三级单位"); + } + + // 涉及单位 + negativeDto.setInvolveDepartId(project.getProjectUnitId()); + negativeDto.setInvolveDepartName(project.getProjectUnit()); + + // 审核级别 + negativeDto.setHostLevel(HostLevelEnums.SECOND.getValue()); + + // 流程配置 + negativeDto.setApprovalFlow(data.getApprovalFlow()); + negativeDto.setTimeLimit(data.getTimeLimit()); + negativeDto.setMaxSignDuration(data.getMaxSignDuration()); + negativeDto.setMaxHandleDuration(data.getMaxHandleDuration()); + negativeDto.setMaxExtensionDuration(data.getMaxExtensionDuration()); + + // 案号(使用项目ID) +// negativeDto.setCaseNumber(reportId); + negativeDto.setOriginId(reportId); + // 5. 保存问题数据(只保存一条) + Negative save = negativeService.save(negativeDto); + + // + project.setNegativeId(save.getId()); + projectMapper.updateById(project); + } +} diff --git a/src/main/resources/mapper/ReportProjectMapper.xml b/src/main/resources/mapper/ReportProjectMapper.xml index 1ffd318..0f0123e 100644 --- a/src/main/resources/mapper/ReportProjectMapper.xml +++ b/src/main/resources/mapper/ReportProjectMapper.xml @@ -4,6 +4,8 @@ "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> + + + +