diff --git a/pqs-prepare/prepare-api/src/main/java/com/njcn/prepare/harmonic/pojo/dto/SuperviseDto.java b/pqs-prepare/prepare-api/src/main/java/com/njcn/prepare/harmonic/pojo/dto/SuperviseDto.java index 9fa7f5e2e..40bd99655 100644 --- a/pqs-prepare/prepare-api/src/main/java/com/njcn/prepare/harmonic/pojo/dto/SuperviseDto.java +++ b/pqs-prepare/prepare-api/src/main/java/com/njcn/prepare/harmonic/pojo/dto/SuperviseDto.java @@ -8,6 +8,12 @@ import java.util.List; @Data public class SuperviseDto extends BaseParam { - @ApiModelProperty("删除的技术监督id集合") + @ApiModelProperty(value = "删除的技术监督id集合", required = true) private List deleteIds; + @ApiModelProperty(value = "事务类型(0:预警;1:告警)") + private Integer type; + @ApiModelProperty(value = "进度(0:开始;1:预/告警单下发;2:反馈单上传;3:现场测试;4:整改通知单下发:5:整改通知反馈单;6:完结)") + private Integer progress; + + } diff --git a/pqs-prepare/prepare-api/src/main/java/com/njcn/prepare/harmonic/pojo/dto/ThsOverRunLogDto.java b/pqs-prepare/prepare-api/src/main/java/com/njcn/prepare/harmonic/pojo/dto/ThsOverRunLogDto.java new file mode 100644 index 000000000..77411f535 --- /dev/null +++ b/pqs-prepare/prepare-api/src/main/java/com/njcn/prepare/harmonic/pojo/dto/ThsOverRunLogDto.java @@ -0,0 +1,92 @@ +package com.njcn.prepare.harmonic.pojo.dto; + +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; + +import java.util.Date; + +@Data +public class ThsOverRunLogDto { + + private static final long serialVersionUID = 1L; + + /** + * 主键id + */ + @ApiModelProperty(name = "id", value = "主键", required = true) + private String id; + + /** + * 监测点ID + */ + @ApiModelProperty(name = "lineIndex", value = "监测点ID") + private String lineIndex; + @ApiModelProperty(name = "lineIndexName", value = "监测点名称") + private String lineIndexName; + + /** + * 名称(变电站_监测点_日期_id) + */ + @ApiModelProperty(name = "name", value = "名称", required = true) + private String name; + + /** + * 技术监督Guid + */ + @ApiModelProperty(name = "supIndex", value = "技术监督Guid", required = true) + private String supIndex; + + /** + * 描述 + */ + @ApiModelProperty(name = "description", value = "描述") + private String description; + + /** + * 预/告警单 + */ + @ApiModelProperty(name = "alarmTicket", value = "预/告警单") + private String alarmTicket; + + /** + * 反馈单 + */ + @ApiModelProperty(name = "feedback", value = "反馈单") + private String feedback; + + /** + * 测试报告 + */ + @ApiModelProperty(name = "testReport", value = "测试报告") + private String testReport; + + /** + * 整改通知单 + */ + @ApiModelProperty(name = "reviseNotice", value = "整改通知单") + private String reviseNotice; + + /** + * 整改通知反馈单 + */ + @ApiModelProperty(name = "reviseFeedback", value = "整改通知反馈单") + private String reviseFeedback; + /** + * 越限时间(yyyy-MM-dd) + */ + @ApiModelProperty(name = "updateTime", value = "越限时间", required = true) + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private Date updateTime; + /** + * 创建时间 + */ + @ApiModelProperty(name = "createTime", value = "创建时间") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private Date createTime; + @ApiModelProperty(name = "companyName", value = "供电公司") + private String companyName; +} diff --git a/pqs-prepare/prepare-api/src/main/java/com/njcn/prepare/harmonic/pojo/param/SuperviseParam.java b/pqs-prepare/prepare-api/src/main/java/com/njcn/prepare/harmonic/pojo/param/SuperviseParam.java index 4750d97a1..92b57e2bf 100644 --- a/pqs-prepare/prepare-api/src/main/java/com/njcn/prepare/harmonic/pojo/param/SuperviseParam.java +++ b/pqs-prepare/prepare-api/src/main/java/com/njcn/prepare/harmonic/pojo/param/SuperviseParam.java @@ -26,4 +26,6 @@ public class SuperviseParam { private String description; @ApiModelProperty(name = "thsSupervise", value = "技术监督参数") private ThsSupervise thsSupervise; + @ApiModelProperty(name = "type", value = "类型(0:预警;1:告警)") + private Integer type; } diff --git a/pqs-prepare/prepare-api/src/main/java/com/njcn/prepare/harmonic/pojo/po/ThsOverRunLog.java b/pqs-prepare/prepare-api/src/main/java/com/njcn/prepare/harmonic/pojo/po/ThsOverRunLog.java index 141a0d7b1..7e3c9ce91 100644 --- a/pqs-prepare/prepare-api/src/main/java/com/njcn/prepare/harmonic/pojo/po/ThsOverRunLog.java +++ b/pqs-prepare/prepare-api/src/main/java/com/njcn/prepare/harmonic/pojo/po/ThsOverRunLog.java @@ -1,5 +1,6 @@ package com.njcn.prepare.harmonic.pojo.po; +import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.annotations.ApiModelProperty; @@ -95,6 +96,15 @@ public class ThsOverRunLog { @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") private Date createTime; + @ApiModelProperty(name = "companyName", value = "供电公司") + @TableField(exist = false) + private String companyName; + @ApiModelProperty(name = "lineIndexName", value = "监测点名称") + @TableField(exist = false) + private String lineIndexName; + @ApiModelProperty(name = "fileName", value = "文件名") + @TableField(exist = false) + private String fileName; } diff --git a/pqs-prepare/prepare-api/src/main/java/com/njcn/prepare/harmonic/pojo/vo/SuperviceRunLogVo.java b/pqs-prepare/prepare-api/src/main/java/com/njcn/prepare/harmonic/pojo/vo/SuperviceRunLogVo.java index b65e22d70..18fbad0a5 100644 --- a/pqs-prepare/prepare-api/src/main/java/com/njcn/prepare/harmonic/pojo/vo/SuperviceRunLogVo.java +++ b/pqs-prepare/prepare-api/src/main/java/com/njcn/prepare/harmonic/pojo/vo/SuperviceRunLogVo.java @@ -17,4 +17,5 @@ public class SuperviceRunLogVo { private ThsSupervise thsSupervise; @ApiModelProperty(name = "overRunLog", value = "监测点集合", required = true) private List overRunLog; + } diff --git a/pqs-prepare/prepare-api/src/main/java/com/njcn/prepare/harmonic/pojo/vo/SuperviseVo.java b/pqs-prepare/prepare-api/src/main/java/com/njcn/prepare/harmonic/pojo/vo/SuperviseVo.java index 8f23b2935..57f6520d6 100644 --- a/pqs-prepare/prepare-api/src/main/java/com/njcn/prepare/harmonic/pojo/vo/SuperviseVo.java +++ b/pqs-prepare/prepare-api/src/main/java/com/njcn/prepare/harmonic/pojo/vo/SuperviseVo.java @@ -111,4 +111,11 @@ public class SuperviseVo { */ @ApiModelProperty(name = "haveReviseFeedback", value = "是否已经上传 整改通知反馈单") private boolean haveReviseFeedback; + @ApiModelProperty(name = "companyName", value = "部门名称") + private String companyName; + @ApiModelProperty(name = "alertType", value = "预警类型:0 无预警,1 一级预警 2 二级预警 3 超时") + private Integer alertType; + @ApiModelProperty(name = "progressTime", value = "进行时间(天)") + private Integer progressTime; + } diff --git a/pqs-prepare/prepare-api/src/main/java/com/njcn/prepare/harmonic/pojo/vo/ThsSuperviseVo.java b/pqs-prepare/prepare-api/src/main/java/com/njcn/prepare/harmonic/pojo/vo/ThsSuperviseVo.java new file mode 100644 index 000000000..48009a6c6 --- /dev/null +++ b/pqs-prepare/prepare-api/src/main/java/com/njcn/prepare/harmonic/pojo/vo/ThsSuperviseVo.java @@ -0,0 +1,26 @@ +package com.njcn.prepare.harmonic.pojo.vo; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.List; + +@Data +public class ThsSuperviseVo { + @ApiModelProperty(name = "superviseVoList", value = "技术监督列表") + private List superviseVoList; + @ApiModelProperty(name = "progressTime", value = "开始数量") + private Integer startNum; + @ApiModelProperty(name = "alarmTicketIssueNum", value = "预/告警单下发数量") + private Integer alarmTicketIssueNum; + @ApiModelProperty(name = "feedbackUploadNum", value = "预/告警单反馈数量") + private Integer feedbackUploadNum; + @ApiModelProperty(name = "testReportNum", value = "现场测试数量") + private Integer testReportNum; + @ApiModelProperty(name = "reviseNoticeIssueNum", value = "整改通知单下发数量") + private Integer reviseNoticeIssueNum; + @ApiModelProperty(name = "reviseFeedbackNum", value = "整改通知单反馈数量") + private Integer reviseFeedbackNum; + @ApiModelProperty(name = "endNum", value = "完结数量") + private Integer endNum; +} diff --git a/pqs-prepare/prepare-boot/src/main/java/com/njcn/prepare/enums/ProgressEnum.java b/pqs-prepare/prepare-boot/src/main/java/com/njcn/prepare/enums/ProgressEnum.java index 6d28992a9..9cd757988 100644 --- a/pqs-prepare/prepare-boot/src/main/java/com/njcn/prepare/enums/ProgressEnum.java +++ b/pqs-prepare/prepare-boot/src/main/java/com/njcn/prepare/enums/ProgressEnum.java @@ -5,7 +5,13 @@ import lombok.Getter; @Getter public enum ProgressEnum { - START(0, "开始"); + START(0, "开始"), + ALARM_TICKET_ISSUE(1, "预/告警单下发"), + FEEDBACK_UPLOAD(2, "反馈单上传"), + TEST_REPORT(3, "现场测试"), + REVISE_NOTICE_ISSUE(4, "整改通知单下发"), + REVISE_FEEDBACK(5, "整改通知单反馈"), + END(6, "完结"); private final Integer code; diff --git a/pqs-prepare/prepare-boot/src/main/java/com/njcn/prepare/harmonic/controller/line/ThsSuperviseController.java b/pqs-prepare/prepare-boot/src/main/java/com/njcn/prepare/harmonic/controller/line/ThsSuperviseController.java index 028d8df0e..9e43c4d2e 100644 --- a/pqs-prepare/prepare-boot/src/main/java/com/njcn/prepare/harmonic/controller/line/ThsSuperviseController.java +++ b/pqs-prepare/prepare-boot/src/main/java/com/njcn/prepare/harmonic/controller/line/ThsSuperviseController.java @@ -22,6 +22,8 @@ import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletResponse; +import java.util.List; +import java.util.Map; /** *

@@ -93,5 +95,14 @@ public class ThsSuperviseController extends BaseController { return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe); } + + @ApiOperation("查询流程状态列表") + @PostMapping("/queryProgressValues") + public HttpResult queryProgressValues() { + List> values = thsSuperviseService.queryProgressValues(); + String methodDescribe = getMethodDescribe("queryProgressValues"); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, values, methodDescribe); + + } } diff --git a/pqs-prepare/prepare-boot/src/main/java/com/njcn/prepare/harmonic/mapper/mysql/line/mapping/ThsSuperviseMapper.xml b/pqs-prepare/prepare-boot/src/main/java/com/njcn/prepare/harmonic/mapper/mysql/line/mapping/ThsSuperviseMapper.xml index 5af886dad..1286ca613 100644 --- a/pqs-prepare/prepare-boot/src/main/java/com/njcn/prepare/harmonic/mapper/mysql/line/mapping/ThsSuperviseMapper.xml +++ b/pqs-prepare/prepare-boot/src/main/java/com/njcn/prepare/harmonic/mapper/mysql/line/mapping/ThsSuperviseMapper.xml @@ -4,7 +4,7 @@ + select ts.* from ths_supervise ts where 1=1 + + AND ts.name like CONCAT(CONCAT('%', #{param.searchValue}), '%') + + + AND DATE_FORMAT(ts.create_time, '%Y-%m-%d') >= DATE_FORMAT(#{param.searchBeginTime}, '%Y-%m-%d') + + + AND DATE_FORMAT(ts.create_time, '%Y-%m-%d') <= DATE_FORMAT(#{param.searchEndTime}, '%Y-%m-%d') + + + AND ts.progress=#{param.searchState} + + + AND ts.type=#{param.type} + + order by ts.create_time desc + + diff --git a/pqs-process/process-boot/src/main/java/com/njcn/process/mapper/mapping/ThsWarnStrategyMapper.xml b/pqs-process/process-boot/src/main/java/com/njcn/process/mapper/mapping/ThsWarnStrategyMapper.xml index bc33f9af7..ff55b8c4e 100644 --- a/pqs-process/process-boot/src/main/java/com/njcn/process/mapper/mapping/ThsWarnStrategyMapper.xml +++ b/pqs-process/process-boot/src/main/java/com/njcn/process/mapper/mapping/ThsWarnStrategyMapper.xml @@ -4,23 +4,23 @@ - - - - - - - - - - + + + + + + + + + + - - - - + + + + - + SELECT + ts.Id AS id, + ts.NAME AS NAME, + ts.Grade AS grade, + ts.Operation AS operation FROM - ths_warn_strategy ts + ths_warn_strategy ts WHERE - id = #{id} + id = #{id} - - select tws.id, tws.name, tws.grade, tws.operation, tws.type, + Monitor_Id as monitorId, tda.dept_Id as deptId from ths_warn_strategy tws - left join ths_dept_alarm tda on + INNER join ths_dept_alarm tda on tws.Id = tda.Alarm_Id - where - tws.State = 1 and tws.Grade in(0,2) + + + + tws.State = 1 and tws.Grade in(0,2) + + + tws.State = 1 and tws.Grade in(1,2) + + + + and tda.Dept_Id=#{param.deptId} + + + and tda.type=#{param.type} + + + and tws.Big_Type=1 + diff --git a/pqs-process/process-boot/src/main/java/com/njcn/process/service/ThsOverRunLogService.java b/pqs-process/process-boot/src/main/java/com/njcn/process/service/ThsOverRunLogService.java new file mode 100644 index 000000000..20d28c99e --- /dev/null +++ b/pqs-process/process-boot/src/main/java/com/njcn/process/service/ThsOverRunLogService.java @@ -0,0 +1,41 @@ +package com.njcn.process.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.njcn.common.pojo.response.HttpResult; +import com.njcn.prepare.harmonic.pojo.param.SuperviseParam; +import com.njcn.prepare.harmonic.pojo.po.ThsOverRunLog; +import com.njcn.prepare.harmonic.pojo.vo.SuperviceRunLogVo; + +/** + *

+ * 告警/预警监测点列表 服务类 + *

+ * + * @author lxp + * @since 2023-03-16 + */ +public interface ThsOverRunLogService extends IService { + + /** + * 保存技术监督监测点 + * + * @param superviseParam + * @return + */ + void saveOverRunLog(SuperviseParam superviseParam); + + /** + * 查询技术监督监测点集合 + * + * @param supIndex + * @return + */ + SuperviceRunLogVo superviseDetail(String supIndex); + + /** + * 更新技术监督 + * + * @param superviseParam + */ + HttpResult updateSupervise(SuperviseParam superviseParam); +} diff --git a/pqs-process/process-boot/src/main/java/com/njcn/process/service/ThsSuperviseService.java b/pqs-process/process-boot/src/main/java/com/njcn/process/service/ThsSuperviseService.java new file mode 100644 index 000000000..063e692f3 --- /dev/null +++ b/pqs-process/process-boot/src/main/java/com/njcn/process/service/ThsSuperviseService.java @@ -0,0 +1,166 @@ +package com.njcn.process.service; + +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.IService; +import com.njcn.common.pojo.response.HttpResult; +import com.njcn.device.pms.pojo.po.Monitor; +import com.njcn.harmonic.pojo.vo.SourceSteadyIndicator; +import com.njcn.harmonic.pojo.vo.ThsStrategyVo; +import com.njcn.prepare.harmonic.pojo.dto.SuperviseDto; +import com.njcn.prepare.harmonic.pojo.param.SuperviseParam; +import com.njcn.prepare.harmonic.pojo.po.ThsOverRunLog; +import com.njcn.prepare.harmonic.pojo.po.ThsSupervise; +import com.njcn.prepare.harmonic.pojo.vo.SuperviceRunLogVo; +import com.njcn.prepare.harmonic.pojo.vo.SuperviseVo; +import com.njcn.prepare.harmonic.pojo.vo.ThsSuperviseVo; +import com.njcn.process.enums.TypeEnum; +import com.njcn.process.pojo.po.LimitRate; +import com.njcn.process.pojo.po.ThsWarnStrategyAss; +import com.njcn.user.pojo.po.Dept; +import org.springframework.web.multipart.MultipartFile; + +import javax.servlet.http.HttpServletResponse; +import java.util.List; +import java.util.Map; + +/** + *

+ * 服务类 + *

+ * + * @author lxp + * @since 2023-03-16 + */ +public interface ThsSuperviseService extends IService { + /** + * 初始化技术监督 + */ + HttpResult initSupervise(SuperviseParam superviseParam); + + /** + * 查新策略集合 + * + * @param superviseParam + * @return + */ + List selectStrategyList(SuperviseParam superviseParam); + + /** + * 查询LimitTarget数据 + * + * @param monitorId + */ + LimitRate queryLimitTargetData(String monitorId); + + /** + * 生成监督数据 + * + * @param limitBoolMap + */ + void buildData(SourceSteadyIndicator steady, Map limitBoolMap, Monitor monitor, LimitRate limitRate, Integer initType, ThsSupervise thsSupervise, List thsOverRunLogs); + + /** + * 查询策略绑定的干扰源列表或指标参数列表 + * + * @param id + * @param typeEnum + * @return + */ + List queryWarnStrategyAss(String id, TypeEnum typeEnum); + + /** + * 生成监督数据 + * + * @param steady + * @param monitor + * @return + */ + void buildSuperviseData(SourceSteadyIndicator steady, Monitor monitor, LimitRate limitRate, Map limitBoolMap, Integer initType, ThsSupervise thsSupervise, List thsOverRunLogs); + + /** + * 生成 告警/预警监测点列表 数据 + * + * @param steady + * @param thsSupervise + * @param monitor + */ + void buildOverRunLog(SourceSteadyIndicator steady, ThsSupervise thsSupervise, Monitor monitor, LimitRate limitRate, Map limitBoolMap, Integer initType, List thsOverRunLogs); + + + void deleteTodayData(String depId, Integer initType); + + /** + * 生成技术监督数据 + * + * @param thsSupervise + * @param overRunLogList + */ + void creatData(Dept dept, ThsSupervise thsSupervise, List overRunLogList); + + /** + * 保存技术监督数据 + * + * @param superviceRunLogVo + */ + void saveOverRunLog(SuperviceRunLogVo superviceRunLogVo); + + /** + * 查询技术监督列表 + * + * @param superviseDto + */ + Page querySuperviseList(SuperviseDto superviseDto); + + /** + * 删除技术监督 + * + * @param superviseDto + * @return + */ + HttpResult deleteSupervise(SuperviseDto superviseDto); + + /** + * 上传技术监督单据 + * + * @param id + * @param ticketType + * @param files + * @param response + */ + void uploadSuperviseTicket(String id, String supIndex, String ticketType, MultipartFile[] files, HttpServletResponse response); + + /** + * 查询流程状态枚举列表 + * + * @return + */ + List> queryProgressValues(); + + /** + * 上传单据模板 + * + * @param type + * @param formworkType + * @param file + * @param response + */ + void uploadAlarmFormwork(Integer type, Integer formworkType, MultipartFile file, HttpServletResponse response); + + /** + * 下载单据模板 + * + * @param type + * @param formworkType + * @param response + * @return + */ + String dowloadAlarmFormwork(Integer type, Integer formworkType, HttpServletResponse response); + + /** + * 技术监督首页 + * + * @param superviseDto + * @return + */ + Page superviseIndex(SuperviseDto superviseDto); +} diff --git a/pqs-process/process-boot/src/main/java/com/njcn/process/service/impl/ThsOverRunLogServiceImpl.java b/pqs-process/process-boot/src/main/java/com/njcn/process/service/impl/ThsOverRunLogServiceImpl.java new file mode 100644 index 000000000..cc1bdd3f8 --- /dev/null +++ b/pqs-process/process-boot/src/main/java/com/njcn/process/service/impl/ThsOverRunLogServiceImpl.java @@ -0,0 +1,92 @@ +package com.njcn.process.service.impl; + +import cn.hutool.core.collection.CollectionUtil; +import com.baomidou.dynamic.datasource.annotation.DS; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.njcn.common.pojo.enums.response.CommonResponseEnum; +import com.njcn.common.pojo.response.HttpResult; +import com.njcn.common.utils.HttpResultUtil; +import com.njcn.oss.utils.FileStorageUtil; +import com.njcn.prepare.harmonic.pojo.param.SuperviseParam; +import com.njcn.prepare.harmonic.pojo.po.ThsOverRunLog; +import com.njcn.prepare.harmonic.pojo.po.ThsSupervise; +import com.njcn.prepare.harmonic.pojo.vo.SuperviceRunLogVo; +import com.njcn.process.mapper.ThsOverRunLogMapper; +import com.njcn.process.mapper.ThsSuperviseMapper; +import com.njcn.process.service.ThsOverRunLogService; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; +import java.util.stream.Collectors; + +/** + *

+ * 告警/预警监测点列表 服务实现类 + *

+ * + * @author lxp + * @since 2023-03-16 + */ +@Service +@Slf4j +@DS("process") +public class ThsOverRunLogServiceImpl extends ServiceImpl implements ThsOverRunLogService { + @Autowired + private ThsOverRunLogMapper thsOverRunLogMapper; + @Autowired + private ThsSuperviseMapper thsSuperviseMapper; + @Autowired + private FileStorageUtil fileStorageUtil; + + @Override + @Transactional(rollbackFor = Exception.class) + public void saveOverRunLog(SuperviseParam superviseParam) { + this.saveBatch(superviseParam.getOverRunLog()); + } + + @Override + public SuperviceRunLogVo superviseDetail(String supIndex) { + ThsSupervise thsSupervise = thsSuperviseMapper.selectOne(new LambdaQueryWrapper().eq(ThsSupervise::getSupIndex, supIndex)); + List thsOverRunLogs = thsOverRunLogMapper.selectList(new LambdaQueryWrapper().eq(ThsOverRunLog::getSupIndex, supIndex)); + if (CollectionUtil.isNotEmpty(thsOverRunLogs)) { + thsOverRunLogs.forEach(item -> { + if (StringUtils.isNotBlank(item.getAlarmTicket())) { + item.setAlarmTicket(fileStorageUtil.getFileUrl(item.getAlarmTicket())); + } + if (StringUtils.isNotBlank(item.getFeedback())) { + item.setFeedback(fileStorageUtil.getFileUrl(item.getFeedback())); + } + if (StringUtils.isNotBlank(item.getTestReport())) { + item.setTestReport(fileStorageUtil.getFileUrl(item.getTestReport())); + } + if (StringUtils.isNotBlank(item.getReviseNotice())) { + item.setReviseNotice(fileStorageUtil.getFileUrl(item.getReviseNotice())); + } + if (StringUtils.isNotBlank(item.getReviseFeedback())) { + item.setReviseFeedback(fileStorageUtil.getFileUrl(item.getReviseFeedback())); + } + + }); + } + return SuperviceRunLogVo.builder().overRunLog(thsOverRunLogs).thsSupervise(thsSupervise).build(); + } + + @Override + public HttpResult updateSupervise(SuperviseParam superviseParam) { + List overRunLog = superviseParam.getOverRunLog(); + if (CollectionUtil.isEmpty(overRunLog)) { + HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, "监测点不能为空", null); + } + List thsOverRunLogs = thsOverRunLogMapper.selectList(new LambdaQueryWrapper().eq(ThsOverRunLog::getSupIndex, superviseParam.getSupIndex())); + List saveIds = superviseParam.getOverRunLog().stream().map(ThsOverRunLog::getId).collect(Collectors.toList()); + List allIds = thsOverRunLogs.stream().map(ThsOverRunLog::getId).collect(Collectors.toList()); + allIds.removeAll(saveIds); + thsOverRunLogMapper.delete(new LambdaQueryWrapper().in(ThsOverRunLog::getId, allIds)); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, null); + } +} diff --git a/pqs-process/process-boot/src/main/java/com/njcn/process/service/impl/ThsSuperviseServiceImpl.java b/pqs-process/process-boot/src/main/java/com/njcn/process/service/impl/ThsSuperviseServiceImpl.java new file mode 100644 index 000000000..ca79a36a2 --- /dev/null +++ b/pqs-process/process-boot/src/main/java/com/njcn/process/service/impl/ThsSuperviseServiceImpl.java @@ -0,0 +1,739 @@ +package com.njcn.process.service.impl; + +import cn.hutool.core.collection.CollectionUtil; +import cn.hutool.core.date.DateUnit; +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.IdUtil; +import com.baomidou.dynamic.datasource.annotation.DS; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.njcn.common.pojo.enums.response.CommonResponseEnum; +import com.njcn.common.pojo.exception.BusinessException; +import com.njcn.common.pojo.response.HttpResult; +import com.njcn.common.utils.HttpResultUtil; +import com.njcn.device.pms.api.PmsGeneralDeviceInfoClient; +import com.njcn.device.pms.pojo.po.Monitor; +import com.njcn.harmonic.pojo.vo.SourceSteadyIndicator; +import com.njcn.harmonic.pojo.vo.ThsStrategyVo; +import com.njcn.oss.constant.OssPath; +import com.njcn.oss.utils.FileStorageUtil; +import com.njcn.prepare.harmonic.pojo.dto.SuperviseDto; +import com.njcn.prepare.harmonic.pojo.param.SuperviseParam; +import com.njcn.prepare.harmonic.pojo.po.ThsOverRunLog; +import com.njcn.prepare.harmonic.pojo.po.ThsSupervise; +import com.njcn.prepare.harmonic.pojo.vo.SuperviceRunLogVo; +import com.njcn.prepare.harmonic.pojo.vo.SuperviseVo; +import com.njcn.prepare.harmonic.pojo.vo.ThsSuperviseVo; +import com.njcn.process.annotaion.HarCurrent; +import com.njcn.process.annotaion.HarVoltage; +import com.njcn.process.annotaion.InterharVoltage; +import com.njcn.process.enums.*; +import com.njcn.process.mapper.*; +import com.njcn.process.pojo.po.LimitRate; +import com.njcn.process.pojo.po.ThsAlarmFormwork; +import com.njcn.process.pojo.po.ThsWarnStrategyAss; +import com.njcn.process.service.ThsSuperviseService; +import com.njcn.process.utils.ReadPatientExcelUtil; +import com.njcn.system.api.DicDataFeignClient; +import com.njcn.system.pojo.po.DictData; +import com.njcn.user.api.DeptFeignClient; +import com.njcn.user.pojo.po.Dept; +import com.njcn.web.factory.PageFactory; +import com.njcn.web.utils.RequestUtil; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections.map.HashedMap; +import org.apache.commons.lang.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.multipart.MultipartFile; + +import javax.servlet.http.HttpServletResponse; +import java.lang.reflect.Field; +import java.util.*; +import java.util.stream.Collectors; + +/** + *

+ * 服务实现类 + *

+ * + * @author lxp + * @since 2023-03-16 + */ +@Service +@Slf4j +public class ThsSuperviseServiceImpl extends ServiceImpl implements ThsSuperviseService { + + @Autowired + private PmsGeneralDeviceInfoClient pmsGeneralDeviceInfoClient; + + @Autowired + private ThsWarnStrategyMapper thsWarnStrategyMapper; + @Autowired + private ThsWarnStrategyAssMapper thsWarnStrategyAssMapper; + @Autowired + private PmsMonitorMapper pmsMonitorMapper; + @Autowired + private LimitRateMapper limitRateMapper; + @Autowired + private DicDataFeignClient dicDataFeignClient; + @Autowired + private ThsSuperviseMapper thsSuperviseMapper; + @Autowired + private ThsOverRunLogMapper thsOverRunLogMapper; + @Autowired + private DeptFeignClient deptFeignClient; + @Autowired + private FileStorageUtil fileStorageUtil; + @Autowired + private ThsAlarmFormworkMapper thsAlarmFormworkMapper; + private static final String DESCRIPTION = "description"; + + @Override + public HttpResult initSupervise(SuperviseParam superviseParam) { + SuperviceRunLogVo superviceRunLogVo = new SuperviceRunLogVo(); + List overRunLogList = new ArrayList<>(); + if (InitTypeEnum.MANUAL.getCode().equals(superviseParam.getInitType()) && StringUtils.isBlank(superviseParam.getDeptId())) { + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.INVALID_PARAMETER, null, ""); + } + List thsStrategyList = this.selectStrategyList(superviseParam); + //按部门进行分组 + if (CollectionUtil.isNotEmpty(thsStrategyList)) { + Map> deptMap = thsStrategyList.stream().collect(Collectors.groupingBy(ThsStrategyVo::getDeptId)); + for (Map.Entry> entry : deptMap.entrySet()) { + String depId = entry.getKey(); + ThsSupervise thsSupervise = new ThsSupervise(); + List deptList = entry.getValue(); + List oneLevel = deptList.stream().filter(r -> !GradeEnum.THREE_LEVEL.getCode().equals(r.getGrade())).collect(Collectors.toList());//一级或二级策略集合 + List oneSourceSteadyIndicatorList = new ArrayList<>(); + if (CollectionUtil.isNotEmpty(oneLevel)) { + for (ThsStrategyVo oneStrategyVo : oneLevel) { + List oneInterferenceSourceAsses = this.queryWarnStrategyAss(oneStrategyVo.getId(), TypeEnum.SOURCE_TYPE);//干扰源列表 + List oneSteadyIndicatorAsses = this.queryWarnStrategyAss(oneStrategyVo.getId(), TypeEnum.INTERFERENCE_TYPE);//干扰源列表 + List oneSteadyIndicatorAssesIds = oneSteadyIndicatorAsses.stream().map(ThsWarnStrategyAss::getAssId).collect(Collectors.toList()); + //封装每一种干扰源和对应的指标 + for (ThsWarnStrategyAss oneWarnStrategyAss : oneInterferenceSourceAsses) { + SourceSteadyIndicator build = SourceSteadyIndicator.builder().id(oneStrategyVo.getId()).operation(oneStrategyVo.getOperation()) + .interferenceSource(oneWarnStrategyAss.getAssId()) + .steadyIndicator(oneSteadyIndicatorAssesIds) + .deptId(oneStrategyVo.getDeptId()) + .type(oneStrategyVo.getType()) + .monitorId(oneStrategyVo.getMonitorId()) + .build(); + oneSourceSteadyIndicatorList.add(build); + } + } + } + List threeLevel = deptList.stream().filter(r -> GradeEnum.THREE_LEVEL.getCode().equals(r.getGrade())).collect(Collectors.toList());//三级策略集合 + if (CollectionUtil.isNotEmpty(threeLevel)) { + for (ThsStrategyVo threeStrategyVo : threeLevel) { + Iterator iterator = oneSourceSteadyIndicatorList.iterator(); + while (iterator.hasNext()) { + SourceSteadyIndicator sourceSteady = iterator.next(); + if (sourceSteady.getType().equals(threeStrategyVo.getType())) { + if (StringUtils.equals(threeStrategyVo.getMonitorId(), sourceSteady.getMonitorId())) { + List interferenceSourceAsses = this.queryWarnStrategyAss(threeStrategyVo.getId(), TypeEnum.SOURCE_TYPE); + //干扰源类型id + List threeInterferenceSourceIds = interferenceSourceAsses.stream().map(ThsWarnStrategyAss::getAssId).collect(Collectors.toList()); + List threeSteadyIndicatorAsses = this.queryWarnStrategyAss(threeStrategyVo.getId(), TypeEnum.INTERFERENCE_TYPE); + //指标类型id + List steadyIndicatorIds = threeSteadyIndicatorAsses.stream().map(ThsWarnStrategyAss::getAssId).collect(Collectors.toList()); + for (String threeInterferenceSourceId : threeInterferenceSourceIds) { + if (OperationEnum.AND.getCode().equals(threeStrategyVo.getOperation())) {//处理三级策略的与 + if (OperationEnum.AND.getCode().equals(sourceSteady.getOperation())) { + if (StringUtils.equals(threeInterferenceSourceId, sourceSteady.getInterferenceSource()) && + steadyIndicatorIds.containsAll(sourceSteady.getSteadyIndicator())) { + iterator.remove(); + } + } + } else {//处理三级策略的或 + if (StringUtils.equals(threeInterferenceSourceId, sourceSteady.getInterferenceSource())) { + if (steadyIndicatorIds.containsAll(sourceSteady.getSteadyIndicator())) { + iterator.remove(); + } else { + List steadyIndicator = sourceSteady.getSteadyIndicator(); + steadyIndicator.removeAll(steadyIndicatorIds); + } + } + } + } + } + } + } + } + } + if (CollectionUtil.isNotEmpty(oneSourceSteadyIndicatorList)) { + oneSourceSteadyIndicatorList.forEach(steady -> { + Monitor monitor = pmsMonitorMapper.selectById(steady.getMonitorId()); + if (monitor != null) { + if (StringUtils.equals(monitor.getMonitorTag(), steady.getInterferenceSource())) {//匹配该监测点属于的干扰源类型 + //查询该监测点的检测数据 + LimitRate limitRate = this.queryLimitTargetData(monitor.getId()); + //判断指标是否超标 + Map limitBoolMap = this.verifyLimit(limitRate, steady); + //构建监督数据 + this.buildData(steady, limitBoolMap, monitor, limitRate, superviseParam.getInitType(), thsSupervise, overRunLogList); + + } + } + }); + //生成技术监督数据 + HttpResult deptById = deptFeignClient.getDeptById(depId); + Dept dept = deptById.getData(); + if (InitTypeEnum.AUTO.getCode().equals(superviseParam.getInitType())) { + this.creatData(dept, thsSupervise, overRunLogList); + } else { + this.buildSuperviseName(thsSupervise, overRunLogList, dept); + superviceRunLogVo.setOverRunLog(overRunLogList); + superviceRunLogVo.setThsSupervise(thsSupervise); + } + } + } + } + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, superviceRunLogVo, ""); + } + + /** + * 构建技术监督名称 + * + * @param thsSupervise + * @param overRunLogList + * @param dept + */ + private void buildSuperviseName(ThsSupervise thsSupervise, List overRunLogList, Dept dept) { + if (CollectionUtil.isNotEmpty(overRunLogList)) { + thsSupervise.setDescription(overRunLogList.get(0).getDescription()); + String str = Arrays.asList(overRunLogList.get(0).getDescription().split(",")).get(0); + String overItem = str.substring(0, str.indexOf("次") - 1); + thsSupervise.setName(DateUtil.today() + dept.getName() + overRunLogList.get(0).getName() + "等" + overRunLogList.size() + "个监测点" + overItem); + } + } + + //生成技术监督数据 + @DS("process") + @Transactional(rollbackFor = Exception.class) + @Override + public void creatData(Dept dept, ThsSupervise thsSupervise, List overRunLogList) { + if (CollectionUtil.isNotEmpty(overRunLogList)) { + thsSupervise.setDescription(overRunLogList.get(0).getDescription()); + String str = Arrays.asList(overRunLogList.get(0).getDescription().split(",")).get(0); + String overItem = str.substring(0, str.indexOf("次") - 1); + thsSupervise.setName(DateUtil.today() + dept.getName() + overRunLogList.get(0).getName() + "等" + overRunLogList.size() + "个监测点" + overItem); + thsSuperviseMapper.insert(thsSupervise); + for (ThsOverRunLog thsOverRunLog : overRunLogList) { + thsOverRunLogMapper.insert(thsOverRunLog); + } + } + } + + @Override + @DS("process") + @Transactional(rollbackFor = Exception.class) + public void saveOverRunLog(SuperviceRunLogVo superviceRunLogVo) { + if (CollectionUtil.isNotEmpty(superviceRunLogVo.getOverRunLog())) { + ThsSupervise thsSupervise = superviceRunLogVo.getThsSupervise(); + HttpResult deptById = deptFeignClient.getDeptById(thsSupervise.getDeptId()); + Dept dept = deptById.getData(); + Date date = new Date(); + thsSupervise.setCreateTime(date); + thsSupervise.setCreateUser(RequestUtil.getUsername()); + thsSupervise.setModifyUser(RequestUtil.getUsername()); + thsSupervise.setModifyTime(date); + thsSupervise.setSupIndex(IdUtil.simpleUUID()); + this.buildSuperviseName(thsSupervise, superviceRunLogVo.getOverRunLog(), dept); + this.thsSuperviseMapper.insert(thsSupervise); + for (ThsOverRunLog thsOverRunLog : superviceRunLogVo.getOverRunLog()) { + thsOverRunLog.setCreateTime(date); + thsOverRunLog.setSupIndex(thsSupervise.getSupIndex()); + this.thsOverRunLogMapper.insert(thsOverRunLog); + } + } + } + + @Override + public Page querySuperviseList(SuperviseDto superviseDto) { + Integer pageNum = PageFactory.getPageNum(superviseDto); + Integer pageSize = PageFactory.getPageSize(superviseDto); + Page superviseVoPage = new Page<>(pageNum, pageSize); + Page page = thsSuperviseMapper.querySuperviseList(superviseVoPage, superviseDto); + List pageRecords = page.getRecords(); + if (CollectionUtil.isNotEmpty(pageRecords)) { + for (SuperviseVo superviseVo : pageRecords) { + superviseVo.setCompanyName(deptFeignClient.getDeptById(superviseVo.getDeptId()).getData().getName()); + List thsOverRunLogs = thsOverRunLogMapper.selectList(new LambdaQueryWrapper().eq(ThsOverRunLog::getSupIndex, superviseVo.getSupIndex())); + if (CollectionUtil.isNotEmpty(thsOverRunLogs)) { + List alarmTickets = thsOverRunLogs.stream().map(ThsOverRunLog::getAlarmTicket).collect(Collectors.toList()); + if (CollectionUtil.isNotEmpty(alarmTickets)) { + superviseVo.setHaveAlarmticket(true); + } + List feedbacks = thsOverRunLogs.stream().map(ThsOverRunLog::getFeedback).collect(Collectors.toList()); + if (CollectionUtil.isNotEmpty(feedbacks)) { + superviseVo.setHaveFeedback(true); + } + List testReports = thsOverRunLogs.stream().map(ThsOverRunLog::getTestReport).collect(Collectors.toList()); + if (CollectionUtil.isNotEmpty(testReports)) { + superviseVo.setHaveTestReport(true); + } + List reviseNotices = thsOverRunLogs.stream().map(ThsOverRunLog::getReviseNotice).collect(Collectors.toList()); + if (CollectionUtil.isNotEmpty(reviseNotices)) { + superviseVo.setHaveReviseNotice(true); + } + List reviseFeedbacks = thsOverRunLogs.stream().map(ThsOverRunLog::getReviseFeedback).collect(Collectors.toList()); + if (CollectionUtil.isNotEmpty(reviseFeedbacks)) { + superviseVo.setHaveReviseFeedback(true); + } + } + } + } + page.setRecords(pageRecords); + return page; + } + + @Override + public HttpResult deleteSupervise(SuperviseDto superviseDto) { + if (CollectionUtil.isNotEmpty(superviseDto.getDeleteIds())) { + superviseDto.getDeleteIds().forEach(id -> { + thsOverRunLogMapper.delete(new LambdaQueryWrapper().eq(ThsOverRunLog::getSupIndex, id)); + thsSuperviseMapper.deleteById(id); + }); + } + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, null); + } + + @Override + public void uploadSuperviseTicket(String id, String supIndex, String ticketType, MultipartFile[] files, HttpServletResponse response) { + ThsSupervise thsSupervise = thsSuperviseMapper.selectOne(new LambdaQueryWrapper().eq(ThsSupervise::getSupIndex, supIndex).last("limit 1")); + ThsOverRunLog thsOverRunLog = thsOverRunLogMapper.selectById(id); + thsSupervise.setSupIndex(thsOverRunLog.getSupIndex()); + thsOverRunLog.setId(id); + if (files != null && files.length == 1) { + String path = fileStorageUtil.uploadMultipart(files[0], OssPath.ELECTRICITY_QUALITY); + this.updateSuperviesData(path, thsOverRunLog, ticketType); + } else { + List thsOverRunLogs = thsOverRunLogMapper.selectList(new LambdaQueryWrapper().eq(ThsOverRunLog::getSupIndex, supIndex)); + this.batchUploadFile(thsSupervise, thsOverRunLogs, files, ticketType); + } + } + + /** + * 批量上传文件 + * + * @param thsSupervise + * @param thsOverRunLogs + * @param files + * @param ticketType + */ + private void batchUploadFile(ThsSupervise thsSupervise, List thsOverRunLogs, MultipartFile[] files, String ticketType) { + if (files != null && files.length > 1) { + List excelData = new ArrayList<>(); + for (int i = 0; i < files.length; i++) { + String originalFilename = files[i].getOriginalFilename(); + String fileType = originalFilename.substring(originalFilename.lastIndexOf(".")); + if (".xls".equalsIgnoreCase(fileType) || ".xlsx".equalsIgnoreCase(fileType)) { + excelData = ReadPatientExcelUtil.getExcelInfo(files[i]); + } + } + if (CollectionUtil.isEmpty(excelData)) { + throw new BusinessException("没有Excel文件,或Excel文件无数据!"); + } + for (ThsOverRunLog thsOverRunLogDto : excelData) { + for (ThsOverRunLog thsOverRunLog : thsOverRunLogs) { + if (StringUtils.equals(thsOverRunLog.getLineIndexName(), thsOverRunLogDto.getLineIndexName()) && + StringUtils.equals(thsOverRunLog.getName(), thsOverRunLogDto.getName())) { + for (int i = 0; i < files.length; i++) { + String originalFilename = files[i].getOriginalFilename(); + String filename = originalFilename.substring(0, originalFilename.lastIndexOf(".")); + if (StringUtils.equals(filename, thsOverRunLogDto.getLineIndexName())) { + this.uploadFile(files[i], ticketType, thsOverRunLog); + } + } + } + } + } + } + } + + private void uploadFile(MultipartFile file, String ticketType, ThsOverRunLog thsOverRunLog) { + String path = fileStorageUtil.uploadMultipart(file, OssPath.ELECTRICITY_QUALITY); + this.updateSuperviesData(path, thsOverRunLog, ticketType); + } + + private void updateSuperviesData(String path, ThsOverRunLog thsOverRunLog, String ticketType) { + TicketTypeEnum ticketTypeEnum = TicketTypeEnum.getTicketTypeEnumByCode(ticketType); + if (ticketTypeEnum == null) { + throw new BusinessException("上传单据参数类型错误!"); + } + switch (ticketTypeEnum) { + case ALARM_TICKET: + thsOverRunLog.setAlarmTicket(path); + break; + case FEEDBACK: + thsOverRunLog.setFeedback(path); + break; + case TEST_REPORT: + thsOverRunLog.setTestReport(path); + break; + case REVISE_NOTICE: + thsOverRunLog.setTestReport(path); + break; + case REVISE_FEEDBACK: + thsOverRunLog.setReviseFeedback(path); + break; + } + thsOverRunLogMapper.updateById(thsOverRunLog); + } + + + @Override + public List> queryProgressValues() { + List> list = new ArrayList<>(); + Arrays.asList(ProgressEnum.values()).forEach(value -> { + Map progress = new HashMap<>(); + progress.put(value.getCode(), value.getMessage()); + list.add(progress); + }); + return list; + } + + @Override + public void uploadAlarmFormwork(Integer type, Integer formworkType, MultipartFile file, HttpServletResponse response) { + thsAlarmFormworkMapper.delete(new LambdaQueryWrapper().eq(ThsAlarmFormwork::getFormworkType, formworkType) + .eq(ThsAlarmFormwork::getType, type)); + String path = fileStorageUtil.uploadMultipart(file, OssPath.ELECTRICITY_QUALITY); + ThsAlarmFormwork alarmFormwork = new ThsAlarmFormwork(); + alarmFormwork.setId(IdUtil.simpleUUID()); + alarmFormwork.setType(type); + alarmFormwork.setFormworkType(formworkType); + alarmFormwork.setPath(path); + thsAlarmFormworkMapper.insert(alarmFormwork); + } + + @Override + public String dowloadAlarmFormwork(Integer type, Integer formworkType, HttpServletResponse response) { + ThsAlarmFormwork thsAlarmFormwork = thsAlarmFormworkMapper.selectOne(new LambdaQueryWrapper().eq(ThsAlarmFormwork::getFormworkType, formworkType) + .eq(ThsAlarmFormwork::getType, type).last("limit 1")); + return fileStorageUtil.getFileUrl(thsAlarmFormwork.getPath()); + } + + @Override + public Page superviseIndex(SuperviseDto superviseDto) { + Integer pageNum = PageFactory.getPageNum(superviseDto); + Integer pageSize = PageFactory.getPageSize(superviseDto); + Page superviseVoPage = new Page<>(pageNum, pageSize); + Page page = thsSuperviseMapper.querySuperviseList(superviseVoPage, superviseDto); + List pageRecords = page.getRecords(); + Page thsSuperviseVoPage = new Page<>(pageNum, pageSize); + thsSuperviseVoPage.setTotal(superviseVoPage.getTotal()); + ThsSuperviseVo thsSuperviseVo = new ThsSuperviseVo(); + if (CollectionUtil.isNotEmpty(pageRecords)) { + for (SuperviseVo superviseVo : pageRecords) { + superviseVo.setCompanyName(deptFeignClient.getDeptById(superviseVo.getDeptId()).getData().getName()); + //处理预警类型 + Date modifyTime = superviseVo.getModifyTime(); + Long progressTime = DateUtil.between(modifyTime, new Date(), DateUnit.DAY); + superviseVo.setProgressTime(progressTime.intValue()); + switch (ProgressEnum.getProgressEnumByCode(superviseVo.getProgress())) { + case START: + case ALARM_TICKET_ISSUE: + if (progressTime >= 1) { + superviseVo.setAlertType(AlertTypeEnum.RED.getCode()); + } else { + superviseVo.setAlertType(AlertTypeEnum.BLACK.getCode()); + } + break; + default: + if (progressTime >= 10) { + superviseVo.setAlertType(AlertTypeEnum.RED.getCode()); + } else if (progressTime >= 8) { + superviseVo.setAlertType(AlertTypeEnum.ORANGE.getCode()); + } else if (progressTime >= 5) { + superviseVo.setAlertType(AlertTypeEnum.YELLOW.getCode()); + } + break; + } + } + thsSuperviseVo.setSuperviseVoList(pageRecords); + //分组处理每种流程状态的数量 + Map> map = pageRecords.stream().collect(Collectors.groupingBy(SuperviseVo::getProgress)); + for (Map.Entry> entry : map.entrySet()) { + Integer code = entry.getKey(); + switch (ProgressEnum.getProgressEnumByCode(code)) { + case START: + thsSuperviseVo.setStartNum(entry.getValue().size()); + break; + case ALARM_TICKET_ISSUE: + thsSuperviseVo.setAlarmTicketIssueNum(entry.getValue().size()); + break; + case FEEDBACK_UPLOAD: + thsSuperviseVo.setFeedbackUploadNum(entry.getValue().size()); + break; + case TEST_REPORT: + thsSuperviseVo.setTestReportNum(entry.getValue().size()); + break; + case REVISE_NOTICE_ISSUE: + thsSuperviseVo.setReviseFeedbackNum(entry.getValue().size()); + break; + case REVISE_FEEDBACK: + thsSuperviseVo.setReviseFeedbackNum(entry.getValue().size()); + break; + case END: + thsSuperviseVo.setEndNum(entry.getValue().size()); + break; + } + } + + } + thsSuperviseVoPage.setRecords(Collections.singletonList(thsSuperviseVo)); + return thsSuperviseVoPage; + } + + + /** + * 查询策略列表 + * + * @param superviseParam + * @return + */ + @DS("process") + @Override + public List selectStrategyList(SuperviseParam superviseParam) { + return thsWarnStrategyMapper.selectStrategyList(superviseParam); + } + + /** + * 查询策略绑定的干扰源列表或指标参数列表 + * + * @param warnId + * @param typeEnum + * @return + */ + @DS("process") + @Override + public List queryWarnStrategyAss(String warnId, TypeEnum typeEnum) { + return thsWarnStrategyAssMapper.selectList(new LambdaQueryWrapper() + .eq(ThsWarnStrategyAss::getWarnId, warnId) + .eq(ThsWarnStrategyAss::getType, typeEnum.getCode())); + } + + /** + * 生成监督数据 + * + * @param limitBoolMap + */ + @Override + public void buildData(SourceSteadyIndicator steady, Map limitBoolMap, Monitor monitor, LimitRate limitRate, Integer initType, ThsSupervise thsSupervise, List thsOverRunLogs) { + if (CollectionUtil.isNotEmpty(limitBoolMap)) { + if (OperationEnum.AND.getCode().equals(steady.getOperation())) { + for (Map.Entry entry : limitBoolMap.entrySet()) { + if (entry.getValue() instanceof Boolean && !(boolean) entry.getValue()) { + return; + } + } + //构建监督数据 + this.buildSuperviseData(steady, monitor, limitRate, limitBoolMap, initType, thsSupervise, thsOverRunLogs); + //构建告警/预警监测点列表数据 + this.buildOverRunLog(steady, thsSupervise, monitor, limitRate, limitBoolMap, initType, thsOverRunLogs); + return; + } + if (OperationEnum.OR.getCode().equals(steady.getOperation())) { + for (Map.Entry entry : limitBoolMap.entrySet()) { + if (entry.getValue() instanceof Boolean && (boolean) entry.getValue()) { + //生成监督数据 + this.buildSuperviseData(steady, monitor, limitRate, limitBoolMap, initType, thsSupervise, thsOverRunLogs); + //生成告警/预警监测点数据 + this.buildOverRunLog(steady, thsSupervise, monitor, limitRate, limitBoolMap, initType, thsOverRunLogs); + return; + } + } + } + } + } + + + @Override + public void buildSuperviseData(SourceSteadyIndicator steady, Monitor monitor, LimitRate limitRate, Map limitBoolMap, Integer initType, ThsSupervise thsSupervise, List thsOverRunLogs) { + if (thsSupervise != null && StringUtils.isBlank(thsSupervise.getSupIndex())) { + thsSupervise.setSupIndex(IdUtil.simpleUUID()); + thsSupervise.setDeptId(steady.getDeptId()); + thsSupervise.setCreateTime(new Date()); + thsSupervise.setType(steady.getType()); + thsSupervise.setCreateUser(RequestUtil.getUsername()); + thsSupervise.setProgress(ProgressEnum.START.getCode()); + thsSupervise.setCreateType(initType); + } + } + + + @Override + public void buildOverRunLog(SourceSteadyIndicator steady, ThsSupervise thsSupervise, Monitor monitor, LimitRate limitRate, Map limitBoolMap, Integer initType, List thsOverRunLogs) { + ThsOverRunLog thsOverRunLog = new ThsOverRunLog(); + thsOverRunLog.setId(IdUtil.simpleUUID()); + thsOverRunLog.setSupIndex(thsSupervise.getSupIndex()); + thsOverRunLog.setLineIndex(monitor.getId()); + thsOverRunLog.setName(monitor.getPowerrName()); + thsOverRunLog.setUpdateTime(limitRate.getCreatTime()); + thsOverRunLog.setCreateTime(new Date()); + thsOverRunLog.setCompanyName(monitor.getOrgName()); + thsOverRunLog.setLineIndexName(monitor.getName()); + List descriptionList = (List) limitBoolMap.get(DESCRIPTION); + thsOverRunLog.setDescription(StringUtils.join(descriptionList, ",")); + + thsOverRunLogs.add(thsOverRunLog); + } + + + @Override + @DS("pms") + public LimitRate queryLimitTargetData(String monitorId) { + LimitRate limitRate = limitRateMapper.selectOne(new LambdaQueryWrapper().eq(LimitRate::getLineId, monitorId) + .between(LimitRate::getCreatTime, + DateUtil.beginOfDay(DateUtil.offsetDay(new Date(), -1)), + DateUtil.endOfDay(DateUtil.offsetDay(new Date(), -1))).last("limit 1")); + return limitRate; + } + + + /** + * 重复执行删除旧数据 + * + * @param depId + */ + @Override + @DS("process") + public void deleteTodayData(String depId, Integer initType) { + ThsSupervise thsSupervise = thsSuperviseMapper.selectOne(new LambdaQueryWrapper().eq(ThsSupervise::getDeptId, depId) + .eq(ThsSupervise::getCreateType, initType) + .between(ThsSupervise::getCreateTime, + DateUtil.beginOfDay(new Date()), + DateUtil.endOfDay(new Date())).last("limit 1")); + if (thsSupervise != null) { + thsOverRunLogMapper.delete(new LambdaQueryWrapper().eq(ThsOverRunLog::getSupIndex, thsSupervise.getSupIndex())); + thsSuperviseMapper.delete(new LambdaQueryWrapper().eq(ThsSupervise::getSupIndex, thsSupervise.getSupIndex())); + } + } + + /** + * 判断监测数据是否超标 + * + * @param limitRate + * @param steady + */ + private Map verifyLimit(LimitRate limitRate, SourceSteadyIndicator steady) { + if (limitRate != null) { + List steadyIndicator = steady.getSteadyIndicator(); + Map limitBoolMap = new HashedMap(); + List descriptionList = new ArrayList<>(); + steadyIndicator.forEach(id -> { + HttpResult dicDataById = dicDataFeignClient.getDicDataById(id); + if (CommonResponseEnum.SUCCESS.getCode().equals(dicDataById.getCode()) && dicDataById.getData() != null) { + SteadyIndicatorEnum steadyIndicatorEnum = SteadyIndicatorEnum.getSteadyIndicatorEnumByCode(dicDataById.getData().getCode()); + if (null != steadyIndicatorEnum) { + switch (steadyIndicatorEnum) { + case Negative_Voltage://负序电压不平衡度 + if (limitRate.getUbalanceOvertime() > 0) { + limitBoolMap.put(SteadyIndicatorEnum.Negative_Voltage.getCode(), true); + descriptionList.add(SteadyIndicatorEnum.Negative_Voltage.getMessage().concat(limitRate.getUbalanceOvertime() + "次")); + } else { + limitBoolMap.put(SteadyIndicatorEnum.Negative_Voltage.getCode(), false); + } + break; + case Interhar_Voltage://间谐波电压 + Integer interharVoltageOvertime = this.maxOverTime(limitRate, InterharVoltage.class); + if (interharVoltageOvertime > 0) { + limitBoolMap.put(SteadyIndicatorEnum.Interhar_Voltage.getCode(), true); + descriptionList.add(SteadyIndicatorEnum.Interhar_Voltage.getMessage().concat(interharVoltageOvertime + "次")); + } else { + limitBoolMap.put(SteadyIndicatorEnum.Interhar_Voltage.getCode(), false); + } + break; + case Neg_Current://负序电流 + if (limitRate.getINegOvertime() > 0) { + limitBoolMap.put(SteadyIndicatorEnum.Neg_Current.getCode(), true); + descriptionList.add(SteadyIndicatorEnum.Neg_Current.getMessage().concat(limitRate.getINegOvertime() + "次")); + } else { + limitBoolMap.put(SteadyIndicatorEnum.Neg_Current.getCode(), false); + } + break; + case Fre_Deviation://频率偏差 + if (limitRate.getFreqDevOvertime() > 0) { + limitBoolMap.put(SteadyIndicatorEnum.Fre_Deviation.getCode(), true); + descriptionList.add(SteadyIndicatorEnum.Fre_Deviation.getMessage().concat(limitRate.getFreqDevOvertime() + "次")); + } else { + limitBoolMap.put(SteadyIndicatorEnum.Fre_Deviation.getCode(), false); + } + break; + case Voltage_Dev://电压偏差 + if (limitRate.getVoltageDevOvertime() > 0) { + limitBoolMap.put(SteadyIndicatorEnum.Voltage_Dev.getCode(), true); + descriptionList.add(SteadyIndicatorEnum.Voltage_Dev.getMessage().concat(limitRate.getVoltageDevOvertime() + "次")); + } else { + limitBoolMap.put(SteadyIndicatorEnum.Voltage_Dev.getCode(), false); + } + break; + case Har_Current://谐波电流 + Integer harCurrentOvertime = this.maxOverTime(limitRate, HarCurrent.class); + if (harCurrentOvertime > 0) { + limitBoolMap.put(SteadyIndicatorEnum.Har_Current.getCode(), true); + descriptionList.add(SteadyIndicatorEnum.Har_Current.getMessage().concat(harCurrentOvertime + "次")); + } else { + limitBoolMap.put(SteadyIndicatorEnum.Har_Current.getCode(), false); + } + break; + case Voltage_Fluc://电压波动与闪变 + if (limitRate.getFlickerOvertime() > 0) { + limitBoolMap.put(SteadyIndicatorEnum.Voltage_Fluc.getCode(), true); + descriptionList.add(SteadyIndicatorEnum.Voltage_Fluc.getMessage().concat(limitRate.getFlickerOvertime() + "次")); + } else { + limitBoolMap.put(SteadyIndicatorEnum.Voltage_Fluc.getCode(), false); + } + break; + case Har_Voltage://谐波电压 + Integer harVoltageOvertime = this.maxOverTime(limitRate, HarVoltage.class); + if (harVoltageOvertime > 0) { + limitBoolMap.put(SteadyIndicatorEnum.Har_Voltage.getCode(), true); + descriptionList.add(SteadyIndicatorEnum.Har_Voltage.getMessage().concat(harVoltageOvertime + "次")); + } else { + limitBoolMap.put(SteadyIndicatorEnum.Har_Voltage.getCode(), false); + } + break; + } + } + } + }); + limitBoolMap.put(DESCRIPTION, descriptionList); + return limitBoolMap; + } + return null; + } + + /*** + * 获取越限最大值 + * @param object + * @param annotation + * @return + */ + private Integer maxOverTime(Object object, Class annotation) { + Integer maxValue = 0; + try { + Class objClass = object.getClass(); + Field[] fields = objClass.getDeclaredFields(); + for (Field field : fields) { + field.setAccessible(true); + boolean isAnon = field.isAnnotationPresent(annotation); + if (isAnon) { + Object objValue = field.get(object); + if (objValue instanceof Integer) { + if ((Integer) objValue > maxValue) { + maxValue = (Integer) objValue; + } + } + } + } + } catch (Exception e) { + log.error("获取越限最大值异常:{}", e.toString()); + } + return maxValue; + } +} diff --git a/pqs-process/process-boot/src/main/java/com/njcn/process/utils/ReadPatientExcelUtil.java b/pqs-process/process-boot/src/main/java/com/njcn/process/utils/ReadPatientExcelUtil.java new file mode 100644 index 000000000..99630eb61 --- /dev/null +++ b/pqs-process/process-boot/src/main/java/com/njcn/process/utils/ReadPatientExcelUtil.java @@ -0,0 +1,164 @@ +package com.njcn.process.utils; + +import com.njcn.prepare.harmonic.pojo.po.ThsOverRunLog; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.ss.usermodel.*; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; +import org.springframework.web.multipart.MultipartFile; + +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; + + +/** + * @author lee + * @version 1.0 + */ +public class ReadPatientExcelUtil { + //总行数 + private static int totalRows = 0; + //总条数 + private static int totalCells = 0; + //错误信息接收器 + private static String errorMsg; + + /** + * 读EXCEL文件,获取信息集合 + * + * @return + */ + public static List getExcelInfo(MultipartFile mFile) { + String fileName = mFile.getOriginalFilename();//获取文件名 + try { + if (!validateExcel(fileName)) {// 验证文件名是否合格 + return null; + } + boolean isExcel2003 = true;// 根据文件名判断文件是2003版本还是2007版本 + if (isExcel2007(fileName)) { + isExcel2003 = false; + } + List userList = createExcel(mFile.getInputStream(), isExcel2003); + return userList; + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + /** + * 根据excel里面的内容读取客户信息 + * + * @param is 输入流 + * @param isExcel2003 excel是2003还是2007版本 + * @return + * @throws IOException + */ + public static List createExcel(InputStream is, boolean isExcel2003) { + try { + Workbook wb = null; + if (isExcel2003) {// 当excel是2003时,创建excel2003 + wb = new HSSFWorkbook(is); + } else {// 当excel是2007时,创建excel2007 + wb = new XSSFWorkbook(is); + } + List thsOverRunLogList = readExcelValue(wb);// 读取Excel里面客户的信息 + return thsOverRunLogList; + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } + + /** + * 读取Excel里面客户的信息 + * + * @param wb + * @return + */ + private static List readExcelValue(Workbook wb) { + //默认会跳过第一行标题 + // 得到第一个shell + Sheet sheet = wb.getSheetAt(0); + // 得到Excel的行数 + totalRows = sheet.getPhysicalNumberOfRows(); + // 得到Excel的列数(前提是有行数) + if (totalRows > 1 && sheet.getRow(1) != null) { + totalCells = sheet.getRow(1).getPhysicalNumberOfCells(); + } + List thsOverRunLogList = new ArrayList(); + // 循环Excel行数 + for (int r = 1; r < totalRows; r++) { + Row row = sheet.getRow(r); + if (row == null) { + continue; + } + ThsOverRunLog ThsOverRunLog = new ThsOverRunLog(); + // 循环Excel的列 + for (int c = 0; c < totalCells; c++) { + Cell cell = row.getCell(c); + if (null != cell) { + if (c == 0) { //第一列 + //如果是纯数字,将单元格类型转为String + if (cell.getCellTypeEnum() == CellType.NUMERIC) { + cell.setCellType(CellType.STRING); + } + ThsOverRunLog.setCompanyName(cell.getStringCellValue());//将单元格数据赋值给ThsOverRunLog + } else if (c == 1) { + if (cell.getCellTypeEnum() == CellType.NUMERIC) { + cell.setCellType(CellType.STRING); + } + ThsOverRunLog.setName(cell.getStringCellValue()); + } else if (c == 2) { + if (cell.getCellTypeEnum() == CellType.NUMERIC) { + cell.setCellType(CellType.STRING); + } + String stringCellValue = cell.getStringCellValue(); + ThsOverRunLog.setLineIndexName(stringCellValue); + } else if (c == 3) { + if (cell.getCellTypeEnum() == CellType.NUMERIC) { + cell.setCellType(CellType.STRING); + } + String stringCellValue = cell.getStringCellValue(); + ThsOverRunLog.setDescription(stringCellValue); + } else if (c == 4) { + if (cell.getCellTypeEnum() == CellType.NUMERIC) { + cell.setCellType(CellType.STRING); + } + String stringCellValue = cell.getStringCellValue(); + ThsOverRunLog.setFileName(stringCellValue); + } + } + } + //将excel解析出来的数据赋值给对象添加到list中 + // 添加到list + thsOverRunLogList.add(ThsOverRunLog); + } + return thsOverRunLogList; + } + + /** + * 验证EXCEL文件 + * + * @param filePath + * @return + */ + public static boolean validateExcel(String filePath) { + if (filePath == null || !(isExcel2003(filePath) || isExcel2007(filePath))) { + errorMsg = "文件名不是excel格式"; + return false; + } + return true; + } + + // @描述:是否是2003的excel,返回true是2003 + public static boolean isExcel2003(String filePath) { + return filePath.matches("^.+\\.(?i)(xls)$"); + } + + //@描述:是否是2007的excel,返回true是2007 + public static boolean isExcel2007(String filePath) { + return filePath.matches("^.+\\.(?i)(xlsx)$"); + } +}