新增预警/告警事务首页以及技术监督管理接口

This commit is contained in:
Lee
2023-03-29 18:04:03 +08:00
parent 0a5573804c
commit 92f10b85f7
39 changed files with 2060 additions and 48 deletions

View File

@@ -8,6 +8,12 @@ import java.util.List;
@Data @Data
public class SuperviseDto extends BaseParam { public class SuperviseDto extends BaseParam {
@ApiModelProperty("删除的技术监督id集合") @ApiModelProperty(value = "删除的技术监督id集合", required = true)
private List<String> deleteIds; private List<String> deleteIds;
@ApiModelProperty(value = "事务类型0预警1告警")
private Integer type;
@ApiModelProperty(value = "进度0开始1预/告警单下发2反馈单上传3现场测试4整改通知单下发:5整改通知反馈单6完结")
private Integer progress;
} }

View File

@@ -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;
}

View File

@@ -26,4 +26,6 @@ public class SuperviseParam {
private String description; private String description;
@ApiModelProperty(name = "thsSupervise", value = "技术监督参数") @ApiModelProperty(name = "thsSupervise", value = "技术监督参数")
private ThsSupervise thsSupervise; private ThsSupervise thsSupervise;
@ApiModelProperty(name = "type", value = "类型0预警1告警")
private Integer type;
} }

View File

@@ -1,5 +1,6 @@
package com.njcn.prepare.harmonic.pojo.po; package com.njcn.prepare.harmonic.pojo.po;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
@@ -95,6 +96,15 @@ public class ThsOverRunLog {
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date createTime; 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;
} }

View File

@@ -17,4 +17,5 @@ public class SuperviceRunLogVo {
private ThsSupervise thsSupervise; private ThsSupervise thsSupervise;
@ApiModelProperty(name = "overRunLog", value = "监测点集合", required = true) @ApiModelProperty(name = "overRunLog", value = "监测点集合", required = true)
private List<ThsOverRunLog> overRunLog; private List<ThsOverRunLog> overRunLog;
} }

View File

@@ -111,4 +111,11 @@ public class SuperviseVo {
*/ */
@ApiModelProperty(name = "haveReviseFeedback", value = "是否已经上传 整改通知反馈单") @ApiModelProperty(name = "haveReviseFeedback", value = "是否已经上传 整改通知反馈单")
private boolean haveReviseFeedback; 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;
} }

View File

@@ -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<SuperviseVo> 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;
}

View File

@@ -5,7 +5,13 @@ import lombok.Getter;
@Getter @Getter
public enum ProgressEnum { 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; private final Integer code;

View File

@@ -22,6 +22,8 @@ import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;
/** /**
* <p> * <p>
@@ -93,5 +95,14 @@ public class ThsSuperviseController extends BaseController {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe); return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
} }
@ApiOperation("查询流程状态列表")
@PostMapping("/queryProgressValues")
public HttpResult queryProgressValues() {
List<Map<Integer, String>> values = thsSuperviseService.queryProgressValues();
String methodDescribe = getMethodDescribe("queryProgressValues");
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, values, methodDescribe);
}
} }

View File

@@ -4,7 +4,7 @@
<!--查询技术监督列表--> <!--查询技术监督列表-->
<select id="querySuperviseList" parameterType="com.njcn.prepare.harmonic.pojo.dto.SuperviseDto" <select id="querySuperviseList" parameterType="com.njcn.prepare.harmonic.pojo.dto.SuperviseDto"
resultType="com.njcn.prepare.harmonic.pojo.vo.SuperviseVo"> resultType="com.njcn.prepare.harmonic.pojo.vo.SuperviseVo">
select ts.* from ths_supervise ts where ts.name like CONCAT(CONCAT('%', #{param.searchValue}), '%') select ts.* from ths_supervise ts where 1=1
<if test="param.searchBeginTime != null and param.searchBeginTime != ''"> <if test="param.searchBeginTime != null and param.searchBeginTime != ''">
AND DATE_FORMAT(ts.create_time, '%Y-%m-%d') &gt;= DATE_FORMAT(#{param.searchBeginTime}, '%Y-%m-%d') AND DATE_FORMAT(ts.create_time, '%Y-%m-%d') &gt;= DATE_FORMAT(#{param.searchBeginTime}, '%Y-%m-%d')
</if> </if>

View File

@@ -311,6 +311,17 @@ public class ThsSuperviseServiceImpl extends ServiceImpl<ThsSuperviseMapper, Ths
} }
} }
@Override
public List<Map<Integer, String>> queryProgressValues() {
List<Map<Integer, String>> list = new ArrayList<>();
Arrays.asList(ProgressEnum.values()).forEach(value -> {
Map<Integer, String> progress = new HashMap<>();
progress.put(value.getCode(), value.getMessage());
list.add(progress);
});
return list;
}
/** /**
* 查询策略列表 * 查询策略列表

View File

@@ -127,4 +127,11 @@ public interface ThsSuperviseService extends IService<ThsSupervise> {
* @param response * @param response
*/ */
void uploadSuperviseTicket(String id, String ticketType, MultipartFile[] files, HttpServletResponse response); void uploadSuperviseTicket(String id, String ticketType, MultipartFile[] files, HttpServletResponse response);
/**
* 查询流程状态枚举列表
* @return
*/
List<Map<Integer, String>> queryProgressValues();
} }

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -0,0 +1,41 @@
package com.njcn.process.pojo.po;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
/**
* <p>
*
* </p>
*
* @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;
}

View File

@@ -90,6 +90,12 @@
<artifactId>common-oss</artifactId> <artifactId>common-oss</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<!-- 多数据源切换当数据源为oracle时需要使用 -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>dynamic-datasource-spring-boot-starter</artifactId>
<version>3.5.1</version>
</dependency>
</dependencies> </dependencies>
<build> <build>

View File

@@ -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;
/**
* <p>
* 前端控制器
* </p>
*
* @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<SuperviceRunLogVo> 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<Page<SuperviseVo>> querySuperviseList(@RequestBody SuperviseDto superviseDto) {
Page<SuperviseVo> 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<Map<Integer, String>> 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<Page<ThsSuperviseVo>> superviseIndex(@RequestBody SuperviseDto superviseDto) {
Page<ThsSuperviseVo> pageResult = thsSuperviseService.superviseIndex(superviseDto);
String methodDescribe = getMethodDescribe("superviseIndex");
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, pageResult, methodDescribe);
}
}

View File

@@ -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;
/**
* <p>
* Mapper 接口
* </p>
*
* @author lxp
* @since 2023-03-16
*/
@DS("master")
@Mapper
public interface LimitRateMapper extends BaseMapper<LimitRate> {
}

View File

@@ -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<Monitor> {
}

View File

@@ -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;
/**
* <p>
* Mapper 接口
* </p>
*
* @author lee
* @since 2023-03-29
*/
@Mapper
public interface ThsAlarmFormworkMapper extends BaseMapper<ThsAlarmFormwork> {
}

View File

@@ -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;
/**
* <p>
* 告警/预警监测点列表 Mapper 接口
* </p>
*
* @author lxp
* @since 2023-03-16
*/
@DS("process")
@Mapper
public interface ThsOverRunLogMapper extends BaseMapper<ThsOverRunLog> {
}

View File

@@ -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;
/**
* <p>
* Mapper 接口
* </p>
*
* @author lxp
* @since 2023-03-16
*/
@DS("process")
@Mapper
public interface ThsSuperviseMapper extends BaseMapper<ThsSupervise> {
/**
* 查询技术监督列表
*
* @param superviseDto
* @return
*/
Page<SuperviseVo> querySuperviseList(Page<SuperviseVo> page, @Param("param") SuperviseDto superviseDto);
}

View File

@@ -1,9 +1,11 @@
package com.njcn.process.mapper; 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.harmonic.pojo.vo.ThsStrategyVo;
import com.njcn.prepare.harmonic.pojo.param.SuperviseParam;
import com.njcn.process.pojo.param.StrategyParam; import com.njcn.process.pojo.param.StrategyParam;
import com.njcn.process.pojo.po.ThsWarnStrategy; import com.njcn.process.pojo.po.ThsWarnStrategy;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import java.util.List; import java.util.List;
@@ -16,6 +18,7 @@ import java.util.List;
* @author wr * @author wr
* @since 2023-03-10 * @since 2023-03-10
*/ */
@DS("process")
public interface ThsWarnStrategyMapper extends BaseMapper<ThsWarnStrategy> { public interface ThsWarnStrategyMapper extends BaseMapper<ThsWarnStrategy> {
/*** /***
@@ -47,10 +50,8 @@ public interface ThsWarnStrategyMapper extends BaseMapper<ThsWarnStrategy> {
List<String> getMonitorTagDetail(@Param("id") String id); List<String> getMonitorTagDetail(@Param("id") String id);
/** /**
* 查询所有部门的策略列表 * 查询策略的集合
*
* @return
*/ */
List<ThsStrategyVo> selectStrategyList(); List<ThsStrategyVo> selectStrategyList(@Param("param") SuperviseParam superviseParam);
} }

View File

@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.njcn.process.mapper.ThsSuperviseMapper">
<!--查询技术监督列表-->
<select id="querySuperviseList" parameterType="com.njcn.prepare.harmonic.pojo.dto.SuperviseDto"
resultType="com.njcn.prepare.harmonic.pojo.vo.SuperviseVo">
select ts.* from ths_supervise ts where 1=1
<if test="param.searchValue != null and param.searchValue != ''">
AND ts.name like CONCAT(CONCAT('%', #{param.searchValue}), '%')
</if>
<if test="param.searchBeginTime != null and param.searchBeginTime != ''">
AND DATE_FORMAT(ts.create_time, '%Y-%m-%d') &gt;= DATE_FORMAT(#{param.searchBeginTime}, '%Y-%m-%d')
</if>
<if test="param.searchEndTime != null and param.searchEndTime != ''">
AND DATE_FORMAT(ts.create_time, '%Y-%m-%d') &lt;= DATE_FORMAT(#{param.searchEndTime}, '%Y-%m-%d')
</if>
<if test="param.searchState != null">
AND ts.progress=#{param.searchState}
</if>
<if test="param.type != null">
AND ts.type=#{param.type}
</if>
order by ts.create_time desc
</select>
</mapper>

View File

@@ -4,23 +4,23 @@
<!-- 通用查询映射结果 --> <!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="com.njcn.process.pojo.po.ThsWarnStrategy"> <resultMap id="BaseResultMap" type="com.njcn.process.pojo.po.ThsWarnStrategy">
<id column="Id" property="id" /> <id column="Id" property="id"/>
<result column="Create_Time" property="createTime" /> <result column="Create_Time" property="createTime"/>
<result column="Update_TIme" property="updateTime" /> <result column="Update_TIme" property="updateTime"/>
<result column="Name" property="name" /> <result column="Name" property="name"/>
<result column="Grade" property="grade" /> <result column="Grade" property="grade"/>
<result column="Operation" property="operation" /> <result column="Operation" property="operation"/>
<result column="type" property="type" /> <result column="type" property="type"/>
<result column="State" property="state" /> <result column="State" property="state"/>
<result column="Create_By" property="createBy" /> <result column="Create_By" property="createBy"/>
<result column="Update_By" property="updateBy" /> <result column="Update_By" property="updateBy"/>
</resultMap> </resultMap>
<resultMap id="StrategyResultMap" type="com.njcn.process.pojo.param.StrategyParam$StrategyUpdateParam"> <resultMap id="StrategyResultMap" type="com.njcn.process.pojo.param.StrategyParam$StrategyUpdateParam">
<id column="Id" property="id" /> <id column="Id" property="id"/>
<result column="Name" property="name" /> <result column="Name" property="name"/>
<result column="Grade" property="grade" /> <result column="Grade" property="grade"/>
<result column="Operation" property="operation" /> <result column="Operation" property="operation"/>
<collection <collection
property="monitorTag" property="monitorTag"
column="{id = id}" column="{id = id}"
@@ -51,21 +51,44 @@
WHERE WHERE
Warn_Id = #{id} and ts.Type=1 Warn_Id = #{id} and ts.Type=1
</select> </select>
<!--查询所有部门的策略列表--> <!--查询策略的集合-->
<select id="selectStrategyList" resultType="com.njcn.harmonic.pojo.vo.ThsStrategyVo"> <select id="selectStrategyList" parameterType="com.njcn.prepare.harmonic.pojo.param.SuperviseParam"
resultType="com.njcn.harmonic.pojo.vo.ThsStrategyVo">
select select
tws.id, tws.id,
tws.name, tws.name,
tws.grade, tws.grade,
tws.operation, tws.operation,
tws.type, tws.type,
Monitor_Id as monitorId,
tda.dept_Id as deptId tda.dept_Id as deptId
from from
ths_warn_strategy tws ths_warn_strategy tws
left join ths_dept_alarm tda on INNER join ths_dept_alarm tda on
tws.Id = tda.Alarm_Id tws.Id = tda.Alarm_Id
where <where>
<choose>
<when test="param.initType==0">
tws.State = 1 and tws.Grade in(0,2) tws.State = 1 and tws.Grade in(0,2)
</when>
<when test="param.initType==1">
tws.State = 1 and tws.Grade in(1,2)
</when>
</choose>
<if test="param.deptId !=null and param.deptId !=''">
and tda.Dept_Id=#{param.deptId}
</if>
<if test="param.type !=null">
and tda.type=#{param.type}
</if>
<!-- <if test="param != null and param.overRunLog != null and param.overRunLog.size > 0">
AND tda.Monitor_Id IN
<foreach collection='param.overRunLog' item='item' index="index" open='(' separator=',' close=')'>
#{item.lineIndex}
</foreach>
</if>-->
and tws.Big_Type=1
</where>
</select> </select>
<select id="getMonitorTagDetail" resultType="java.lang.String"> <select id="getMonitorTagDetail" resultType="java.lang.String">

View File

@@ -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;
/**
* <p>
* 告警/预警监测点列表 服务类
* </p>
*
* @author lxp
* @since 2023-03-16
*/
public interface ThsOverRunLogService extends IService<ThsOverRunLog> {
/**
* 保存技术监督监测点
*
* @param superviseParam
* @return
*/
void saveOverRunLog(SuperviseParam superviseParam);
/**
* 查询技术监督监测点集合
*
* @param supIndex
* @return
*/
SuperviceRunLogVo superviseDetail(String supIndex);
/**
* 更新技术监督
*
* @param superviseParam
*/
HttpResult updateSupervise(SuperviseParam superviseParam);
}

View File

@@ -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;
/**
* <p>
* 服务类
* </p>
*
* @author lxp
* @since 2023-03-16
*/
public interface ThsSuperviseService extends IService<ThsSupervise> {
/**
* 初始化技术监督
*/
HttpResult<SuperviceRunLogVo> initSupervise(SuperviseParam superviseParam);
/**
* 查新策略集合
*
* @param superviseParam
* @return
*/
List<ThsStrategyVo> selectStrategyList(SuperviseParam superviseParam);
/**
* 查询LimitTarget数据
*
* @param monitorId
*/
LimitRate queryLimitTargetData(String monitorId);
/**
* 生成监督数据
*
* @param limitBoolMap
*/
void buildData(SourceSteadyIndicator steady, Map<String, Object> limitBoolMap, Monitor monitor, LimitRate limitRate, Integer initType, ThsSupervise thsSupervise, List<ThsOverRunLog> thsOverRunLogs);
/**
* 查询策略绑定的干扰源列表或指标参数列表
*
* @param id
* @param typeEnum
* @return
*/
List<ThsWarnStrategyAss> queryWarnStrategyAss(String id, TypeEnum typeEnum);
/**
* 生成监督数据
*
* @param steady
* @param monitor
* @return
*/
void buildSuperviseData(SourceSteadyIndicator steady, Monitor monitor, LimitRate limitRate, Map<String, Object> limitBoolMap, Integer initType, ThsSupervise thsSupervise, List<ThsOverRunLog> thsOverRunLogs);
/**
* 生成 告警/预警监测点列表 数据
*
* @param steady
* @param thsSupervise
* @param monitor
*/
void buildOverRunLog(SourceSteadyIndicator steady, ThsSupervise thsSupervise, Monitor monitor, LimitRate limitRate, Map<String, Object> limitBoolMap, Integer initType, List<ThsOverRunLog> thsOverRunLogs);
void deleteTodayData(String depId, Integer initType);
/**
* 生成技术监督数据
*
* @param thsSupervise
* @param overRunLogList
*/
void creatData(Dept dept, ThsSupervise thsSupervise, List<ThsOverRunLog> overRunLogList);
/**
* 保存技术监督数据
*
* @param superviceRunLogVo
*/
void saveOverRunLog(SuperviceRunLogVo superviceRunLogVo);
/**
* 查询技术监督列表
*
* @param superviseDto
*/
Page<SuperviseVo> 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<Map<Integer, String>> 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<ThsSuperviseVo> superviseIndex(SuperviseDto superviseDto);
}

View File

@@ -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;
/**
* <p>
* 告警/预警监测点列表 服务实现类
* </p>
*
* @author lxp
* @since 2023-03-16
*/
@Service
@Slf4j
@DS("process")
public class ThsOverRunLogServiceImpl extends ServiceImpl<ThsOverRunLogMapper, ThsOverRunLog> 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<ThsSupervise>().eq(ThsSupervise::getSupIndex, supIndex));
List<ThsOverRunLog> thsOverRunLogs = thsOverRunLogMapper.selectList(new LambdaQueryWrapper<ThsOverRunLog>().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<ThsOverRunLog> overRunLog = superviseParam.getOverRunLog();
if (CollectionUtil.isEmpty(overRunLog)) {
HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, "监测点不能为空", null);
}
List<ThsOverRunLog> thsOverRunLogs = thsOverRunLogMapper.selectList(new LambdaQueryWrapper<ThsOverRunLog>().eq(ThsOverRunLog::getSupIndex, superviseParam.getSupIndex()));
List<String> saveIds = superviseParam.getOverRunLog().stream().map(ThsOverRunLog::getId).collect(Collectors.toList());
List<String> allIds = thsOverRunLogs.stream().map(ThsOverRunLog::getId).collect(Collectors.toList());
allIds.removeAll(saveIds);
thsOverRunLogMapper.delete(new LambdaQueryWrapper<ThsOverRunLog>().in(ThsOverRunLog::getId, allIds));
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, null);
}
}

View File

@@ -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;
/**
* <p>
* 服务实现类
* </p>
*
* @author lxp
* @since 2023-03-16
*/
@Service
@Slf4j
public class ThsSuperviseServiceImpl extends ServiceImpl<ThsSuperviseMapper, ThsSupervise> 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<SuperviceRunLogVo> initSupervise(SuperviseParam superviseParam) {
SuperviceRunLogVo superviceRunLogVo = new SuperviceRunLogVo();
List<ThsOverRunLog> overRunLogList = new ArrayList<>();
if (InitTypeEnum.MANUAL.getCode().equals(superviseParam.getInitType()) && StringUtils.isBlank(superviseParam.getDeptId())) {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.INVALID_PARAMETER, null, "");
}
List<ThsStrategyVo> thsStrategyList = this.selectStrategyList(superviseParam);
//按部门进行分组
if (CollectionUtil.isNotEmpty(thsStrategyList)) {
Map<String, List<ThsStrategyVo>> deptMap = thsStrategyList.stream().collect(Collectors.groupingBy(ThsStrategyVo::getDeptId));
for (Map.Entry<String, List<ThsStrategyVo>> entry : deptMap.entrySet()) {
String depId = entry.getKey();
ThsSupervise thsSupervise = new ThsSupervise();
List<ThsStrategyVo> deptList = entry.getValue();
List<ThsStrategyVo> oneLevel = deptList.stream().filter(r -> !GradeEnum.THREE_LEVEL.getCode().equals(r.getGrade())).collect(Collectors.toList());//一级或二级策略集合
List<SourceSteadyIndicator> oneSourceSteadyIndicatorList = new ArrayList<>();
if (CollectionUtil.isNotEmpty(oneLevel)) {
for (ThsStrategyVo oneStrategyVo : oneLevel) {
List<ThsWarnStrategyAss> oneInterferenceSourceAsses = this.queryWarnStrategyAss(oneStrategyVo.getId(), TypeEnum.SOURCE_TYPE);//干扰源列表
List<ThsWarnStrategyAss> oneSteadyIndicatorAsses = this.queryWarnStrategyAss(oneStrategyVo.getId(), TypeEnum.INTERFERENCE_TYPE);//干扰源列表
List<String> 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<ThsStrategyVo> threeLevel = deptList.stream().filter(r -> GradeEnum.THREE_LEVEL.getCode().equals(r.getGrade())).collect(Collectors.toList());//三级策略集合
if (CollectionUtil.isNotEmpty(threeLevel)) {
for (ThsStrategyVo threeStrategyVo : threeLevel) {
Iterator<SourceSteadyIndicator> iterator = oneSourceSteadyIndicatorList.iterator();
while (iterator.hasNext()) {
SourceSteadyIndicator sourceSteady = iterator.next();
if (sourceSteady.getType().equals(threeStrategyVo.getType())) {
if (StringUtils.equals(threeStrategyVo.getMonitorId(), sourceSteady.getMonitorId())) {
List<ThsWarnStrategyAss> interferenceSourceAsses = this.queryWarnStrategyAss(threeStrategyVo.getId(), TypeEnum.SOURCE_TYPE);
//干扰源类型id
List<String> threeInterferenceSourceIds = interferenceSourceAsses.stream().map(ThsWarnStrategyAss::getAssId).collect(Collectors.toList());
List<ThsWarnStrategyAss> threeSteadyIndicatorAsses = this.queryWarnStrategyAss(threeStrategyVo.getId(), TypeEnum.INTERFERENCE_TYPE);
//指标类型id
List<String> 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<String> 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<String, Object> limitBoolMap = this.verifyLimit(limitRate, steady);
//构建监督数据
this.buildData(steady, limitBoolMap, monitor, limitRate, superviseParam.getInitType(), thsSupervise, overRunLogList);
}
}
});
//生成技术监督数据
HttpResult<Dept> 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<ThsOverRunLog> 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<ThsOverRunLog> 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<Dept> 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<SuperviseVo> querySuperviseList(SuperviseDto superviseDto) {
Integer pageNum = PageFactory.getPageNum(superviseDto);
Integer pageSize = PageFactory.getPageSize(superviseDto);
Page<SuperviseVo> superviseVoPage = new Page<>(pageNum, pageSize);
Page<SuperviseVo> page = thsSuperviseMapper.querySuperviseList(superviseVoPage, superviseDto);
List<SuperviseVo> pageRecords = page.getRecords();
if (CollectionUtil.isNotEmpty(pageRecords)) {
for (SuperviseVo superviseVo : pageRecords) {
superviseVo.setCompanyName(deptFeignClient.getDeptById(superviseVo.getDeptId()).getData().getName());
List<ThsOverRunLog> thsOverRunLogs = thsOverRunLogMapper.selectList(new LambdaQueryWrapper<ThsOverRunLog>().eq(ThsOverRunLog::getSupIndex, superviseVo.getSupIndex()));
if (CollectionUtil.isNotEmpty(thsOverRunLogs)) {
List<String> alarmTickets = thsOverRunLogs.stream().map(ThsOverRunLog::getAlarmTicket).collect(Collectors.toList());
if (CollectionUtil.isNotEmpty(alarmTickets)) {
superviseVo.setHaveAlarmticket(true);
}
List<String> feedbacks = thsOverRunLogs.stream().map(ThsOverRunLog::getFeedback).collect(Collectors.toList());
if (CollectionUtil.isNotEmpty(feedbacks)) {
superviseVo.setHaveFeedback(true);
}
List<String> testReports = thsOverRunLogs.stream().map(ThsOverRunLog::getTestReport).collect(Collectors.toList());
if (CollectionUtil.isNotEmpty(testReports)) {
superviseVo.setHaveTestReport(true);
}
List<String> reviseNotices = thsOverRunLogs.stream().map(ThsOverRunLog::getReviseNotice).collect(Collectors.toList());
if (CollectionUtil.isNotEmpty(reviseNotices)) {
superviseVo.setHaveReviseNotice(true);
}
List<String> 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<ThsOverRunLog>().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<ThsSupervise>().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<ThsOverRunLog> thsOverRunLogs = thsOverRunLogMapper.selectList(new LambdaQueryWrapper<ThsOverRunLog>().eq(ThsOverRunLog::getSupIndex, supIndex));
this.batchUploadFile(thsSupervise, thsOverRunLogs, files, ticketType);
}
}
/**
* 批量上传文件
*
* @param thsSupervise
* @param thsOverRunLogs
* @param files
* @param ticketType
*/
private void batchUploadFile(ThsSupervise thsSupervise, List<ThsOverRunLog> thsOverRunLogs, MultipartFile[] files, String ticketType) {
if (files != null && files.length > 1) {
List<ThsOverRunLog> 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<Map<Integer, String>> queryProgressValues() {
List<Map<Integer, String>> list = new ArrayList<>();
Arrays.asList(ProgressEnum.values()).forEach(value -> {
Map<Integer, String> 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<ThsAlarmFormwork>().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<ThsAlarmFormwork>().eq(ThsAlarmFormwork::getFormworkType, formworkType)
.eq(ThsAlarmFormwork::getType, type).last("limit 1"));
return fileStorageUtil.getFileUrl(thsAlarmFormwork.getPath());
}
@Override
public Page<ThsSuperviseVo> superviseIndex(SuperviseDto superviseDto) {
Integer pageNum = PageFactory.getPageNum(superviseDto);
Integer pageSize = PageFactory.getPageSize(superviseDto);
Page<SuperviseVo> superviseVoPage = new Page<>(pageNum, pageSize);
Page<SuperviseVo> page = thsSuperviseMapper.querySuperviseList(superviseVoPage, superviseDto);
List<SuperviseVo> pageRecords = page.getRecords();
Page<ThsSuperviseVo> 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<Integer, List<SuperviseVo>> map = pageRecords.stream().collect(Collectors.groupingBy(SuperviseVo::getProgress));
for (Map.Entry<Integer, List<SuperviseVo>> 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<ThsStrategyVo> selectStrategyList(SuperviseParam superviseParam) {
return thsWarnStrategyMapper.selectStrategyList(superviseParam);
}
/**
* 查询策略绑定的干扰源列表或指标参数列表
*
* @param warnId
* @param typeEnum
* @return
*/
@DS("process")
@Override
public List<ThsWarnStrategyAss> queryWarnStrategyAss(String warnId, TypeEnum typeEnum) {
return thsWarnStrategyAssMapper.selectList(new LambdaQueryWrapper<ThsWarnStrategyAss>()
.eq(ThsWarnStrategyAss::getWarnId, warnId)
.eq(ThsWarnStrategyAss::getType, typeEnum.getCode()));
}
/**
* 生成监督数据
*
* @param limitBoolMap
*/
@Override
public void buildData(SourceSteadyIndicator steady, Map<String, Object> limitBoolMap, Monitor monitor, LimitRate limitRate, Integer initType, ThsSupervise thsSupervise, List<ThsOverRunLog> thsOverRunLogs) {
if (CollectionUtil.isNotEmpty(limitBoolMap)) {
if (OperationEnum.AND.getCode().equals(steady.getOperation())) {
for (Map.Entry<String, Object> 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<String, Object> 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<String, Object> limitBoolMap, Integer initType, ThsSupervise thsSupervise, List<ThsOverRunLog> 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<String, Object> limitBoolMap, Integer initType, List<ThsOverRunLog> 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<String> 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<LimitRate>().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<ThsSupervise>().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<ThsOverRunLog>().eq(ThsOverRunLog::getSupIndex, thsSupervise.getSupIndex()));
thsSuperviseMapper.delete(new LambdaQueryWrapper<ThsSupervise>().eq(ThsSupervise::getSupIndex, thsSupervise.getSupIndex()));
}
}
/**
* 判断监测数据是否超标
*
* @param limitRate
* @param steady
*/
private Map<String, Object> verifyLimit(LimitRate limitRate, SourceSteadyIndicator steady) {
if (limitRate != null) {
List<String> steadyIndicator = steady.getSteadyIndicator();
Map<String, Object> limitBoolMap = new HashedMap();
List<String> descriptionList = new ArrayList<>();
steadyIndicator.forEach(id -> {
HttpResult<DictData> 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;
}
}

View File

@@ -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<ThsOverRunLog> getExcelInfo(MultipartFile mFile) {
String fileName = mFile.getOriginalFilename();//获取文件名
try {
if (!validateExcel(fileName)) {// 验证文件名是否合格
return null;
}
boolean isExcel2003 = true;// 根据文件名判断文件是2003版本还是2007版本
if (isExcel2007(fileName)) {
isExcel2003 = false;
}
List<ThsOverRunLog> 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<ThsOverRunLog> 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<ThsOverRunLog> thsOverRunLogList = readExcelValue(wb);// 读取Excel里面客户的信息
return thsOverRunLogList;
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
/**
* 读取Excel里面客户的信息
*
* @param wb
* @return
*/
private static List<ThsOverRunLog> 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<ThsOverRunLog> thsOverRunLogList = new ArrayList<ThsOverRunLog>();
// 循环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)$");
}
}