From 9afc84245c90439a5625ca522f54e607a595917e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=A8=E6=9C=A8c?= <857448963@qq.com> Date: Wed, 29 Mar 2023 13:54:08 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/njcn/device/biz/utils/COverlimit.java | 3 ++ .../pq/mapper/RStatIntegrityDMapper.java | 11 ++++++ .../mapper/mapping/RStatIntegrityDMapper.xml | 15 ++++++++ .../mapping/TerminalOnlineRateDataMapper.xml | 2 +- .../impl/LineIntegrityDataServiceImpl.java | 9 +++-- .../TerminalOnlineRateDataServiceImpl.java | 36 +------------------ 6 files changed, 35 insertions(+), 41 deletions(-) create mode 100644 pqs-device/pq-device/pq-device-boot/src/main/java/com/njcn/device/pq/mapper/mapping/RStatIntegrityDMapper.xml diff --git a/pqs-device/common-device-biz/src/main/java/com/njcn/device/biz/utils/COverlimit.java b/pqs-device/common-device-biz/src/main/java/com/njcn/device/biz/utils/COverlimit.java index daf341de7..f015e81dd 100644 --- a/pqs-device/common-device-biz/src/main/java/com/njcn/device/biz/utils/COverlimit.java +++ b/pqs-device/common-device-biz/src/main/java/com/njcn/device/biz/utils/COverlimit.java @@ -227,6 +227,9 @@ public class COverlimit { case "515kV": uL = 535.0f; break; + case "800kV": + uL = 825.0f; + break; default: return 0.0f; } diff --git a/pqs-device/pq-device/pq-device-boot/src/main/java/com/njcn/device/pq/mapper/RStatIntegrityDMapper.java b/pqs-device/pq-device/pq-device-boot/src/main/java/com/njcn/device/pq/mapper/RStatIntegrityDMapper.java index adbe9b076..a995a23ae 100644 --- a/pqs-device/pq-device/pq-device-boot/src/main/java/com/njcn/device/pq/mapper/RStatIntegrityDMapper.java +++ b/pqs-device/pq-device/pq-device-boot/src/main/java/com/njcn/device/pq/mapper/RStatIntegrityDMapper.java @@ -2,7 +2,11 @@ package com.njcn.device.pq.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.njcn.device.pq.pojo.po.LineDataIntegrity; import com.njcn.device.pq.pojo.po.RStatIntegrityD; +import org.apache.ibatis.annotations.Param; + +import java.util.List; /** *

@@ -14,4 +18,11 @@ import com.njcn.device.pq.pojo.po.RStatIntegrityD; */ public interface RStatIntegrityDMapper extends BaseMapper { + + /** + * 获取监测点数据完整性 + * @author cdf + * @date 2023/3/29 + */ + List getLineIntegrityRate(@Param("lineIds")List lineIds,@Param("startTime")String startTime,@Param("endTime")String endTime); } diff --git a/pqs-device/pq-device/pq-device-boot/src/main/java/com/njcn/device/pq/mapper/mapping/RStatIntegrityDMapper.xml b/pqs-device/pq-device/pq-device-boot/src/main/java/com/njcn/device/pq/mapper/mapping/RStatIntegrityDMapper.xml new file mode 100644 index 000000000..e3c3e34b0 --- /dev/null +++ b/pqs-device/pq-device/pq-device-boot/src/main/java/com/njcn/device/pq/mapper/mapping/RStatIntegrityDMapper.xml @@ -0,0 +1,15 @@ + + + + + + diff --git a/pqs-device/pq-device/pq-device-boot/src/main/java/com/njcn/device/pq/mapper/mapping/TerminalOnlineRateDataMapper.xml b/pqs-device/pq-device/pq-device-boot/src/main/java/com/njcn/device/pq/mapper/mapping/TerminalOnlineRateDataMapper.xml index 27464a86d..f4407ce95 100644 --- a/pqs-device/pq-device/pq-device-boot/src/main/java/com/njcn/device/pq/mapper/mapping/TerminalOnlineRateDataMapper.xml +++ b/pqs-device/pq-device/pq-device-boot/src/main/java/com/njcn/device/pq/mapper/mapping/TerminalOnlineRateDataMapper.xml @@ -172,7 +172,7 @@ - select ts.* from ths_supervise ts where ts.name like CONCAT(CONCAT('%', #{param.searchValue}), '%') + select ts.* from ths_supervise ts where 1=1 AND DATE_FORMAT(ts.create_time, '%Y-%m-%d') >= DATE_FORMAT(#{param.searchBeginTime}, '%Y-%m-%d') diff --git a/pqs-prepare/prepare-boot/src/main/java/com/njcn/prepare/harmonic/service/mysql/Impl/line/ThsSuperviseServiceImpl.java b/pqs-prepare/prepare-boot/src/main/java/com/njcn/prepare/harmonic/service/mysql/Impl/line/ThsSuperviseServiceImpl.java index 2d066b2c7..d23253264 100644 --- a/pqs-prepare/prepare-boot/src/main/java/com/njcn/prepare/harmonic/service/mysql/Impl/line/ThsSuperviseServiceImpl.java +++ b/pqs-prepare/prepare-boot/src/main/java/com/njcn/prepare/harmonic/service/mysql/Impl/line/ThsSuperviseServiceImpl.java @@ -311,6 +311,17 @@ public class ThsSuperviseServiceImpl extends ServiceImpl> 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; + } + /** * 查询策略列表 diff --git a/pqs-prepare/prepare-boot/src/main/java/com/njcn/prepare/harmonic/service/mysql/line/ThsSuperviseService.java b/pqs-prepare/prepare-boot/src/main/java/com/njcn/prepare/harmonic/service/mysql/line/ThsSuperviseService.java index a90b0680b..35b60ef82 100644 --- a/pqs-prepare/prepare-boot/src/main/java/com/njcn/prepare/harmonic/service/mysql/line/ThsSuperviseService.java +++ b/pqs-prepare/prepare-boot/src/main/java/com/njcn/prepare/harmonic/service/mysql/line/ThsSuperviseService.java @@ -127,4 +127,11 @@ public interface ThsSuperviseService extends IService { * @param response */ void uploadSuperviseTicket(String id, String ticketType, MultipartFile[] files, HttpServletResponse response); + + /** + * 查询流程状态枚举列表 + * @return + */ + List> queryProgressValues(); + } diff --git a/pqs-process/process-api/src/main/java/com/njcn/process/enums/AlarmTypeEnum.java b/pqs-process/process-api/src/main/java/com/njcn/process/enums/AlarmTypeEnum.java new file mode 100644 index 000000000..eb6bf721d --- /dev/null +++ b/pqs-process/process-api/src/main/java/com/njcn/process/enums/AlarmTypeEnum.java @@ -0,0 +1,26 @@ +package com.njcn.process.enums; + +import lombok.Getter; + +@Getter +public enum AlarmTypeEnum { + EARLY_WARN(0, "电能质量技术预警单"), + REPORT_WARN(1, "电能质量技术告警单"); + private final Integer code; + + private final String message; + + AlarmTypeEnum(Integer code, String message) { + this.code = code; + this.message = message; + } + + public static AlarmTypeEnum getAlarmTypeEnumByCode(Integer code) { + for (AlarmTypeEnum alarmTypeEnum : AlarmTypeEnum.values()) { + if (alarmTypeEnum.getCode().equals(code)) { + return alarmTypeEnum; + } + } + return null; + } +} diff --git a/pqs-process/process-api/src/main/java/com/njcn/process/enums/AlertTypeEnum.java b/pqs-process/process-api/src/main/java/com/njcn/process/enums/AlertTypeEnum.java new file mode 100644 index 000000000..742979ebe --- /dev/null +++ b/pqs-process/process-api/src/main/java/com/njcn/process/enums/AlertTypeEnum.java @@ -0,0 +1,29 @@ +package com.njcn.process.enums; + +import lombok.Getter; + +@Getter +public enum AlertTypeEnum { + BLACK(0, "无预警"), + YELLOW(1, "一级预警"), + ORANGE(2, "二级预警"), + RED(3, "超时"); + + private final Integer code; + + private final String message; + + AlertTypeEnum(Integer code, String message) { + this.code = code; + this.message = message; + } + + public static AlertTypeEnum getAlertTypeEnumByCode(Integer code) { + for (AlertTypeEnum alertTypeEnum : AlertTypeEnum.values()) { + if (alertTypeEnum.getCode().equals(code)) { + return alertTypeEnum; + } + } + return null; + } +} diff --git a/pqs-process/process-api/src/main/java/com/njcn/process/enums/BigTypeEnum.java b/pqs-process/process-api/src/main/java/com/njcn/process/enums/BigTypeEnum.java new file mode 100644 index 000000000..62416c056 --- /dev/null +++ b/pqs-process/process-api/src/main/java/com/njcn/process/enums/BigTypeEnum.java @@ -0,0 +1,18 @@ +package com.njcn.process.enums; + +import lombok.Getter; + +@Getter +public enum BigTypeEnum { + COMMON(0, "通用策略"), + CUSTOM(1, "定制策略"); + + private final Integer code; + + private final String message; + + BigTypeEnum(Integer code, String message) { + this.code = code; + this.message = message; + } +} diff --git a/pqs-process/process-api/src/main/java/com/njcn/process/enums/GradeEnum.java b/pqs-process/process-api/src/main/java/com/njcn/process/enums/GradeEnum.java new file mode 100644 index 000000000..a5d1d376e --- /dev/null +++ b/pqs-process/process-api/src/main/java/com/njcn/process/enums/GradeEnum.java @@ -0,0 +1,19 @@ +package com.njcn.process.enums; + +import lombok.Getter; + +@Getter +public enum GradeEnum { + ONE_LEVEL(0, "一级"), + TWO_LEVEL(1, "二级"), + THREE_LEVEL(2, "三级"); + + private final Integer code; + + private final String message; + + GradeEnum(Integer code, String message) { + this.code = code; + this.message = message; + } +} diff --git a/pqs-process/process-api/src/main/java/com/njcn/process/enums/InitTypeEnum.java b/pqs-process/process-api/src/main/java/com/njcn/process/enums/InitTypeEnum.java new file mode 100644 index 000000000..c0d03e505 --- /dev/null +++ b/pqs-process/process-api/src/main/java/com/njcn/process/enums/InitTypeEnum.java @@ -0,0 +1,17 @@ +package com.njcn.process.enums; + +import lombok.Getter; + +@Getter +public enum InitTypeEnum { + AUTO(0, "自动"), + MANUAL(1, "手动"); + private final Integer code; + + private final String message; + + InitTypeEnum(Integer code, String message) { + this.code = code; + this.message = message; + } +} diff --git a/pqs-process/process-api/src/main/java/com/njcn/process/enums/InterferenceTypeEnum.java b/pqs-process/process-api/src/main/java/com/njcn/process/enums/InterferenceTypeEnum.java new file mode 100644 index 000000000..77e808e90 --- /dev/null +++ b/pqs-process/process-api/src/main/java/com/njcn/process/enums/InterferenceTypeEnum.java @@ -0,0 +1,38 @@ +package com.njcn.process.enums; + +import lombok.Getter; + +/** + * 干扰源类型枚举 + */ +@Getter +public enum InterferenceTypeEnum { + Electric_Load("Electric_Load", "电加热负荷"), + Electrolytic_Load("Electrolytic_Load", "电解负荷"), + Transportation_Hubs("Transportation_Hubs", "交通枢纽"), + Nonlinear_Loads("Nonlinear_Loads", "非线性负荷"), + Electrified_Railways("Electrified_Railways", "电气化铁路"), + Fre_Equipment("Fre_Equipment", "变频调速设备"), + Mill("Mill", "轧机"), + Medium_Furnace("Medium_Furnace", "中频炉"), + Precision_Mach("Precision_Mach", "精密加工"), + Com_Muni("Com_Muni", "商业/市政"), + AC_DC_Inverter("AC_DC_Inverter", "交直流逆变器"), + Shock_Loads("Shock_Loads", "冲击性负荷"), + Electric_Weld_Load("Electric_Weld_Load", "电焊负荷"), + dycs("dycs", "电压测试"), + dlcs("dlcs", "电流测试"), + Zlzz("Zlzz", "整流装置"), + Hospital("Hospital", "医院"), + Manufacturing("Manufacturing", "半导体制造"); + + private final String code; + + private final String message; + + InterferenceTypeEnum(String code, String message) { + this.code = code; + this.message = message; + } + +} diff --git a/pqs-process/process-api/src/main/java/com/njcn/process/enums/OperationEnum.java b/pqs-process/process-api/src/main/java/com/njcn/process/enums/OperationEnum.java new file mode 100644 index 000000000..f501d32bb --- /dev/null +++ b/pqs-process/process-api/src/main/java/com/njcn/process/enums/OperationEnum.java @@ -0,0 +1,18 @@ +package com.njcn.process.enums; + +import lombok.Getter; + +@Getter +public enum OperationEnum { + + AND(0, "与"), + OR(1, "或"); + private final Integer code; + + private final String message; + + OperationEnum(Integer code, String message) { + this.code = code; + this.message = message; + } +} diff --git a/pqs-process/process-api/src/main/java/com/njcn/process/enums/ProgressEnum.java b/pqs-process/process-api/src/main/java/com/njcn/process/enums/ProgressEnum.java new file mode 100644 index 000000000..8b980a29d --- /dev/null +++ b/pqs-process/process-api/src/main/java/com/njcn/process/enums/ProgressEnum.java @@ -0,0 +1,33 @@ +package com.njcn.process.enums; + +import lombok.Getter; + +@Getter +public enum ProgressEnum { + + 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; + + private final String message; + + ProgressEnum(Integer code, String message) { + this.code = code; + this.message = message; + } + + public static ProgressEnum getProgressEnumByCode(Integer code) { + for (ProgressEnum progressEnum : ProgressEnum.values()) { + if (progressEnum.getCode().equals(code)) { + return progressEnum; + } + } + return null; + } +} diff --git a/pqs-process/process-api/src/main/java/com/njcn/process/enums/SteadyIndicatorEnum.java b/pqs-process/process-api/src/main/java/com/njcn/process/enums/SteadyIndicatorEnum.java new file mode 100644 index 000000000..3c6c22822 --- /dev/null +++ b/pqs-process/process-api/src/main/java/com/njcn/process/enums/SteadyIndicatorEnum.java @@ -0,0 +1,38 @@ +package com.njcn.process.enums; + +import lombok.Getter; +import org.apache.commons.lang3.StringUtils; + +/** + * 指标参数类型枚举 + */ +@Getter +public enum SteadyIndicatorEnum { + + Negative_Voltage("Negative_Voltage", "负序电压不平衡度超标"), + Interhar_Voltage("Interhar_Voltage", "间谐波电压超标"), + Neg_Current("Neg_Current", "负序电流超标"), + Fre_Deviation("Fre_Deviation", "频率偏差超标"), + Voltage_Dev("Voltage_Dev", "电压偏差超标"), + Har_Current("Har_Current", "谐波电流超标"), + Voltage_Fluc("Voltage_Fluc", "电压波动与闪变超标"), + Har_Voltage("Har_Voltage", "谐波电压超标"); + + private final String code; + + private final String message; + + SteadyIndicatorEnum(String code, String message) { + this.code = code; + this.message = message; + } + + public static SteadyIndicatorEnum getSteadyIndicatorEnumByCode(String code) { + for (SteadyIndicatorEnum steadyIndicatorEnum : SteadyIndicatorEnum.values()) { + if (StringUtils.equals(code, steadyIndicatorEnum.getCode())) { + return steadyIndicatorEnum; + } + } + return null; + } +} diff --git a/pqs-process/process-api/src/main/java/com/njcn/process/enums/TicketTypeEnum.java b/pqs-process/process-api/src/main/java/com/njcn/process/enums/TicketTypeEnum.java new file mode 100644 index 000000000..abc748937 --- /dev/null +++ b/pqs-process/process-api/src/main/java/com/njcn/process/enums/TicketTypeEnum.java @@ -0,0 +1,34 @@ +package com.njcn.process.enums; + +import lombok.Getter; +import org.apache.commons.lang3.StringUtils; + +@Getter +public enum TicketTypeEnum { + + + ALARM_TICKET("alarm_ticket", "预/告警单"), + FEEDBACK("feedback", "反馈单"), + TEST_REPORT("test_report", "测试报告"), + REVISE_NOTICE("revise_notice", "整改通知单"), + REVISE_FEEDBACK("revise_feedback", "整改通知反馈单"); + + private final String code; + + private final String message; + + TicketTypeEnum(String code, String message) { + this.code = code; + this.message = message; + } + + public static TicketTypeEnum getTicketTypeEnumByCode(String code) { + for (TicketTypeEnum ticketTypeEnum : TicketTypeEnum.values()) { + if (StringUtils.equals(code, ticketTypeEnum.getCode())) { + return ticketTypeEnum; + } + } + return null; + } + +} diff --git a/pqs-process/process-api/src/main/java/com/njcn/process/enums/TypeEnum.java b/pqs-process/process-api/src/main/java/com/njcn/process/enums/TypeEnum.java new file mode 100644 index 000000000..2c835276d --- /dev/null +++ b/pqs-process/process-api/src/main/java/com/njcn/process/enums/TypeEnum.java @@ -0,0 +1,20 @@ +package com.njcn.process.enums; + +import lombok.Getter; + +@Getter +public enum TypeEnum { + MONITOR_TYPE(2, "监测点表类型"), + INTERFERENCE_TYPE(1, "指标类型"), + SOURCE_TYPE(0, "干扰源类型"); + + + private final Integer code; + + private final String message; + + TypeEnum(Integer code, String message) { + this.code = code; + this.message = message; + } +} diff --git a/pqs-process/process-api/src/main/java/com/njcn/process/pojo/po/ThsAlarmFormwork.java b/pqs-process/process-api/src/main/java/com/njcn/process/pojo/po/ThsAlarmFormwork.java new file mode 100644 index 000000000..c296e4d22 --- /dev/null +++ b/pqs-process/process-api/src/main/java/com/njcn/process/pojo/po/ThsAlarmFormwork.java @@ -0,0 +1,41 @@ +package com.njcn.process.pojo.po; + +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +/** + *

+ * + *

+ * + * @author lee + * @since 2023-03-29 + */ +@Data +@TableName("ths_alarm_formwork") +public class ThsAlarmFormwork { + + private static final long serialVersionUID = 1L; + + /** + * 主键id + */ + private String id; + + /** + * 类型(0:预警;1:告警) + */ + private Integer type; + + /** + * 单据类型(0:预/告警单模板;1:整改通知反馈单模板 + */ + private Integer formworkType; + + /** + * 模板路径 + */ + private String path; + + +} diff --git a/pqs-process/process-boot/pom.xml b/pqs-process/process-boot/pom.xml index ffa315673..878c50054 100644 --- a/pqs-process/process-boot/pom.xml +++ b/pqs-process/process-boot/pom.xml @@ -90,6 +90,12 @@ common-oss ${project.version} + + + com.baomidou + dynamic-datasource-spring-boot-starter + 3.5.1 + diff --git a/pqs-process/process-boot/src/main/java/com/njcn/process/controller/ThsSuperviseController.java b/pqs-process/process-boot/src/main/java/com/njcn/process/controller/ThsSuperviseController.java new file mode 100644 index 000000000..cdab990bc --- /dev/null +++ b/pqs-process/process-boot/src/main/java/com/njcn/process/controller/ThsSuperviseController.java @@ -0,0 +1,141 @@ +package com.njcn.process.controller; + + +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.njcn.common.pojo.enums.response.CommonResponseEnum; +import com.njcn.common.pojo.response.HttpResult; +import com.njcn.common.utils.HttpResultUtil; +import com.njcn.prepare.harmonic.pojo.dto.SuperviseDto; +import com.njcn.prepare.harmonic.pojo.param.SuperviseParam; +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.service.ThsOverRunLogService; +import com.njcn.process.service.ThsSuperviseService; +import com.njcn.web.controller.BaseController; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.annotation.Validated; +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; + +/** + *

+ * 前端控制器 + *

+ * + * @author lxp + * @since 2023-03-16 + */ +@Api(tags = "预警-告警技术监督") +@RestController +@RequestMapping("/thsSupervise") +public class ThsSuperviseController extends BaseController { + @Autowired + private ThsSuperviseService thsSuperviseService; + @Autowired + private ThsOverRunLogService thsOverRunLogService; + + @ApiOperation("预警/告警事务生成") + @ApiImplicitParam(name = "superviseParam", value = "创建技术监督参数", required = true) + @PostMapping("/initSupervise") + public HttpResult initSupervise(@RequestBody @Validated SuperviseParam superviseParam) { + return thsSuperviseService.initSupervise(superviseParam); + } + + @ApiOperation("保存技术监督监测点") + @ApiImplicitParam(name = "superviceRunLogVo", value = "技术监督监测点参数", required = true) + @PostMapping("/saveOverRunLog") + public HttpResult saveOverRunLog(@RequestBody SuperviceRunLogVo superviceRunLogVo) { + thsSuperviseService.saveOverRunLog(superviceRunLogVo); + String methodDescribe = getMethodDescribe("saveOverRunLog"); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe); + } + + @ApiOperation("技术监督详情") + @ApiImplicitParam(name = "supIndex", value = "技术监督id", required = true) + @PostMapping("/superviseDetail") + public HttpResult superviseDetail(@RequestParam String supIndex) { + SuperviceRunLogVo result = thsOverRunLogService.superviseDetail(supIndex); + String methodDescribe = getMethodDescribe("superviseDetail"); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe); + } + + @ApiOperation("删除技术监督") + @ApiImplicitParam(name = "superviseDto", value = "删除技术监督请求体", required = true) + @PostMapping("/deleteSupervise") + public HttpResult deleteSupervise(@RequestBody SuperviseDto superviseDto) { + return thsSuperviseService.deleteSupervise(superviseDto); + } + + @ApiOperation("查询技术监督列表") + @ApiImplicitParam(name = "superviseDto", value = "查询技术监督列表参数", required = true) + @PostMapping("/querySuperviseList") + public HttpResult> querySuperviseList(@RequestBody SuperviseDto superviseDto) { + Page pageResult = thsSuperviseService.querySuperviseList(superviseDto); + String methodDescribe = getMethodDescribe("querySuperviseList"); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, pageResult, methodDescribe); + } + + @ApiOperation("上传技术监督单据") + @PostMapping("/uploadSuperviseTicket") + public HttpResult uploadSuperviseTicket(@ApiParam(value = "文件", required = true) + @RequestPart(value = "files") MultipartFile[] files, + @ApiParam(name = "id", value = "越限监测点记录id", required = true) @RequestParam("id") String id, + @ApiParam(name = "supIndex", value = "技术监督id", required = true) @RequestParam("supIndex") String supIndex, + @ApiParam(name = "ticketType", value = "上传单据类型", required = true) @RequestParam("ticketType") String ticketType, + HttpServletResponse response) { + thsSuperviseService.uploadSuperviseTicket(id, supIndex, ticketType, files, response); + String methodDescribe = getMethodDescribe("uploadSuperviseTicket"); + 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); + + } + + @ApiOperation("上传单据模板") + @PostMapping("/uploadAlarmFormwork") + public HttpResult uploadAlarmFormwork(@ApiParam(value = "文件", required = true) + @RequestPart(value = "file") MultipartFile file, + @ApiParam(name = "type", value = "类型(0:预警;1:告警)", required = true) @RequestParam("type") Integer type, + @ApiParam(name = "formworkType", value = "0:预/告警单模板;1:整改通知反馈单模板", required = true) @RequestParam("formworkType") Integer formworkType, + HttpServletResponse response) { + thsSuperviseService.uploadAlarmFormwork(type, formworkType, file, response); + String methodDescribe = getMethodDescribe("uploadAlarmFormwork"); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe); + } + + @ApiOperation("下载单据模板") + @PostMapping("/dowloadAlarmFormwork") + public HttpResult dowloadAlarmFormwork(@ApiParam(name = "type", value = "类型(0:预警;1:告警)", required = true) @RequestParam("type") Integer type, + @ApiParam(name = "formworkType", value = "0:预/告警单模板;1:整改通知反馈单模板", required = true) @RequestParam("formworkType") Integer formworkType, + HttpServletResponse response) { + String httpPath = thsSuperviseService.dowloadAlarmFormwork(type, formworkType, response); + String methodDescribe = getMethodDescribe("uploadAlarmFormwork"); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, httpPath, methodDescribe); + } + + @ApiOperation("监督首页") + @ApiImplicitParam(name = "superviseDto", value = "查询技术监督列表参数", required = true) + @PostMapping("/superviseIndex") + public HttpResult> superviseIndex(@RequestBody SuperviseDto superviseDto) { + Page pageResult = thsSuperviseService.superviseIndex(superviseDto); + String methodDescribe = getMethodDescribe("superviseIndex"); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, pageResult, methodDescribe); + } +} + diff --git a/pqs-process/process-boot/src/main/java/com/njcn/process/mapper/LimitRateMapper.java b/pqs-process/process-boot/src/main/java/com/njcn/process/mapper/LimitRateMapper.java new file mode 100644 index 000000000..d26b5eeac --- /dev/null +++ b/pqs-process/process-boot/src/main/java/com/njcn/process/mapper/LimitRateMapper.java @@ -0,0 +1,20 @@ +package com.njcn.process.mapper; + +import com.baomidou.dynamic.datasource.annotation.DS; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.njcn.process.pojo.po.LimitRate; +import org.apache.ibatis.annotations.Mapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author lxp + * @since 2023-03-16 + */ +@DS("master") +@Mapper +public interface LimitRateMapper extends BaseMapper { + +} diff --git a/pqs-process/process-boot/src/main/java/com/njcn/process/mapper/PmsMonitorMapper.java b/pqs-process/process-boot/src/main/java/com/njcn/process/mapper/PmsMonitorMapper.java new file mode 100644 index 000000000..d865adab6 --- /dev/null +++ b/pqs-process/process-boot/src/main/java/com/njcn/process/mapper/PmsMonitorMapper.java @@ -0,0 +1,16 @@ +package com.njcn.process.mapper; + +import com.baomidou.dynamic.datasource.annotation.DS; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.njcn.device.pms.pojo.po.Monitor; +import org.apache.ibatis.annotations.Mapper; + +/** + * @author yzh + * @date 2022/10/17 + */ +@DS("master") +@Mapper +public interface PmsMonitorMapper extends BaseMapper { + +} diff --git a/pqs-process/process-boot/src/main/java/com/njcn/process/mapper/ThsAlarmFormworkMapper.java b/pqs-process/process-boot/src/main/java/com/njcn/process/mapper/ThsAlarmFormworkMapper.java new file mode 100644 index 000000000..d025f9981 --- /dev/null +++ b/pqs-process/process-boot/src/main/java/com/njcn/process/mapper/ThsAlarmFormworkMapper.java @@ -0,0 +1,18 @@ +package com.njcn.process.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.njcn.process.pojo.po.ThsAlarmFormwork; +import org.apache.ibatis.annotations.Mapper; + +/** + *

+ * Mapper 接口 + *

+ * + * @author lee + * @since 2023-03-29 + */ +@Mapper +public interface ThsAlarmFormworkMapper extends BaseMapper { + +} diff --git a/pqs-process/process-boot/src/main/java/com/njcn/process/mapper/ThsOverRunLogMapper.java b/pqs-process/process-boot/src/main/java/com/njcn/process/mapper/ThsOverRunLogMapper.java new file mode 100644 index 000000000..caa846bb7 --- /dev/null +++ b/pqs-process/process-boot/src/main/java/com/njcn/process/mapper/ThsOverRunLogMapper.java @@ -0,0 +1,20 @@ +package com.njcn.process.mapper; + +import com.baomidou.dynamic.datasource.annotation.DS; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.njcn.prepare.harmonic.pojo.po.ThsOverRunLog; +import org.apache.ibatis.annotations.Mapper; + +/** + *

+ * 告警/预警监测点列表 Mapper 接口 + *

+ * + * @author lxp + * @since 2023-03-16 + */ +@DS("process") +@Mapper +public interface ThsOverRunLogMapper extends BaseMapper { + +} diff --git a/pqs-process/process-boot/src/main/java/com/njcn/process/mapper/ThsSuperviseMapper.java b/pqs-process/process-boot/src/main/java/com/njcn/process/mapper/ThsSuperviseMapper.java new file mode 100644 index 000000000..7481c50b7 --- /dev/null +++ b/pqs-process/process-boot/src/main/java/com/njcn/process/mapper/ThsSuperviseMapper.java @@ -0,0 +1,30 @@ +package com.njcn.process.mapper; + +import com.baomidou.dynamic.datasource.annotation.DS; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.njcn.prepare.harmonic.pojo.dto.SuperviseDto; +import com.njcn.prepare.harmonic.pojo.po.ThsSupervise; +import com.njcn.prepare.harmonic.pojo.vo.SuperviseVo; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +/** + *

+ * Mapper 接口 + *

+ * + * @author lxp + * @since 2023-03-16 + */ +@DS("process") +@Mapper +public interface ThsSuperviseMapper extends BaseMapper { + /** + * 查询技术监督列表 + * + * @param superviseDto + * @return + */ + Page querySuperviseList(Page page, @Param("param") SuperviseDto superviseDto); +} diff --git a/pqs-process/process-boot/src/main/java/com/njcn/process/mapper/ThsWarnStrategyMapper.java b/pqs-process/process-boot/src/main/java/com/njcn/process/mapper/ThsWarnStrategyMapper.java index 3f0e63644..9686e2b7c 100644 --- a/pqs-process/process-boot/src/main/java/com/njcn/process/mapper/ThsWarnStrategyMapper.java +++ b/pqs-process/process-boot/src/main/java/com/njcn/process/mapper/ThsWarnStrategyMapper.java @@ -1,21 +1,24 @@ package com.njcn.process.mapper; +import com.baomidou.dynamic.datasource.annotation.DS; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.njcn.harmonic.pojo.vo.ThsStrategyVo; +import com.njcn.prepare.harmonic.pojo.param.SuperviseParam; import com.njcn.process.pojo.param.StrategyParam; import com.njcn.process.pojo.po.ThsWarnStrategy; -import com.baomidou.mybatisplus.core.mapper.BaseMapper; import org.apache.ibatis.annotations.Param; import java.util.List; /** *

- * Mapper 接口 + * Mapper 接口 *

* * @author wr * @since 2023-03-10 */ +@DS("process") public interface ThsWarnStrategyMapper extends BaseMapper { /*** @@ -47,10 +50,8 @@ public interface ThsWarnStrategyMapper extends BaseMapper { List getMonitorTagDetail(@Param("id") String id); /** - * 查询所有部门的策略列表 - * - * @return + * 查询策略的集合 */ - List selectStrategyList(); + List selectStrategyList(@Param("param") SuperviseParam superviseParam); } diff --git a/pqs-process/process-boot/src/main/java/com/njcn/process/mapper/mapping/ThsSuperviseMapper.xml b/pqs-process/process-boot/src/main/java/com/njcn/process/mapper/mapping/ThsSuperviseMapper.xml new file mode 100644 index 000000000..0dc9d7589 --- /dev/null +++ b/pqs-process/process-boot/src/main/java/com/njcn/process/mapper/mapping/ThsSuperviseMapper.xml @@ -0,0 +1,25 @@ + + + + + + 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)$"); + } +}