diff --git a/pqs-common/common-autocode/src/main/java/com/njcn/autocode/utils/GenerateCode.java b/pqs-common/common-autocode/src/main/java/com/njcn/autocode/utils/GenerateCode.java index e8d8e97f6..284aa7d7d 100644 --- a/pqs-common/common-autocode/src/main/java/com/njcn/autocode/utils/GenerateCode.java +++ b/pqs-common/common-autocode/src/main/java/com/njcn/autocode/utils/GenerateCode.java @@ -21,7 +21,7 @@ public class GenerateCode { private static final String TARGET_DIR = "D://code"; - private static final String DB_URL = "jdbc:mysql://192.168.1.24:13306/pqsinfo_zl"; + private static final String DB_URL = "jdbc:mysql://192.168.1.24:13306/pqs9100"; // private static final String DB_URL = "jdbc:oracle:thin:@192.168.1.170:1521:pqsbase"; private static final String USERNAME = "root"; @@ -30,9 +30,9 @@ public class GenerateCode { public static void main(String[] args) { List modules = Stream.of( - new Module("xy", "com.njcn.supervision", "survey", Stream.of( - "app_version" - ).collect(Collectors.toList()), "supervision_") + new Module("hongawen", "com.njcn.gather", "", Stream.of( + "pq_dev_type" + ).collect(Collectors.toList()), "pq_") ).collect(Collectors.toList()); generateJavaFile(modules); } diff --git a/pqs-device/common-device-biz/src/main/java/com/njcn/device/biz/commApi/CommLineClient.java b/pqs-device/common-device-biz/src/main/java/com/njcn/device/biz/commApi/CommLineClient.java index 6ae392ca8..d060673d1 100644 --- a/pqs-device/common-device-biz/src/main/java/com/njcn/device/biz/commApi/CommLineClient.java +++ b/pqs-device/common-device-biz/src/main/java/com/njcn/device/biz/commApi/CommLineClient.java @@ -6,6 +6,7 @@ import com.njcn.device.biz.commApi.fallback.CommLineClientFallbackFactory; import com.njcn.device.biz.pojo.dto.LineALLInfoDTO; import com.njcn.device.biz.pojo.dto.LineDTO; import com.njcn.device.biz.pojo.dto.PollutionLineDTO; +import com.njcn.device.biz.pojo.dto.PollutionLineInfoDTO; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; @@ -36,6 +37,14 @@ public interface CommLineClient { @GetMapping("/getLineDetail") HttpResult getLineDetail(@RequestParam("id") String id); + /** + * 获取污区值监测点相关信息 + * + * @author hongawen + */ + @GetMapping("/getPollutionLineInfo") + HttpResult> getPollutionLineInfo(@RequestParam("id") List id); + /*** * 批量获取监测点信息 * @author hongawen diff --git a/pqs-device/common-device-biz/src/main/java/com/njcn/device/biz/commApi/fallback/CommLineClientFallbackFactory.java b/pqs-device/common-device-biz/src/main/java/com/njcn/device/biz/commApi/fallback/CommLineClientFallbackFactory.java index 9b829fe49..b2f652379 100644 --- a/pqs-device/common-device-biz/src/main/java/com/njcn/device/biz/commApi/fallback/CommLineClientFallbackFactory.java +++ b/pqs-device/common-device-biz/src/main/java/com/njcn/device/biz/commApi/fallback/CommLineClientFallbackFactory.java @@ -7,6 +7,7 @@ import com.njcn.device.biz.commApi.CommLineClient; import com.njcn.device.biz.pojo.dto.LineALLInfoDTO; import com.njcn.device.biz.pojo.dto.LineDTO; import com.njcn.device.biz.pojo.dto.PollutionLineDTO; +import com.njcn.device.biz.pojo.dto.PollutionLineInfoDTO; import com.njcn.device.biz.utils.DeviceEnumUtil; import feign.hystrix.FallbackFactory; import lombok.extern.slf4j.Slf4j; @@ -39,6 +40,12 @@ public class CommLineClientFallbackFactory implements FallbackFactory> getPollutionLineInfo(List id) { + log.error("{}异常,降级处理,异常为:{}", "获取污区值监测点相关信息", throwable.toString()); + throw new BusinessException(finalExceptionEnum); + } + @Override public HttpResult> getLineDetailBatch(List ids) { log.error("{}异常,降级处理,异常为:{}", "批量获取监测点信息", throwable.toString()); diff --git a/pqs-device/common-device-biz/src/main/java/com/njcn/device/biz/pojo/dto/PollutionLineInfoDTO.java b/pqs-device/common-device-biz/src/main/java/com/njcn/device/biz/pojo/dto/PollutionLineInfoDTO.java new file mode 100644 index 000000000..476519ad9 --- /dev/null +++ b/pqs-device/common-device-biz/src/main/java/com/njcn/device/biz/pojo/dto/PollutionLineInfoDTO.java @@ -0,0 +1,88 @@ +package com.njcn.device.biz.pojo.dto; + +import lombok.Data; + +@Data +public class PollutionLineInfoDTO { + + /** + * 供电公司名称 + */ + private String gdName; + + /** + * 所属变电站 + */ + private String subStationName; + + /** + * 终端名称 + */ + private String devName; + + /** + * 终端厂家 + */ + private String manufacturer; + + /** + * 终端型号 + */ + private String devType; + + /** + * 通讯状态 + */ + private Integer comFlag; + + /** + * 终端投运时间 + */ + private String loginTime; + + /** + * 位置,电网侧&非电网侧 + */ + private String powerFlag; + + /** + * 行业类型 + */ + private String businessType; + + /** + * 干扰源类型 + */ + private String loadType; + + /** + * 监测id + */ + private String lineId; + + /** + * 监测对象 + */ + private String objName; + + /** + * 变电站 + */ + private String powerSubstationName; + + /** + * 电压等级 + */ + private String lineVoltage; + + /** + * 装置id + */ + private String deviceId; + + /** + * 上送国网编号 + */ + private String monitorId; + +} diff --git a/pqs-device/pq-device/pq-device-boot/src/main/java/com/njcn/device/pq/controller/CommLineController.java b/pqs-device/pq-device/pq-device-boot/src/main/java/com/njcn/device/pq/controller/CommLineController.java index 76b086642..ab6f431ce 100644 --- a/pqs-device/pq-device/pq-device-boot/src/main/java/com/njcn/device/pq/controller/CommLineController.java +++ b/pqs-device/pq-device/pq-device-boot/src/main/java/com/njcn/device/pq/controller/CommLineController.java @@ -7,6 +7,7 @@ import com.njcn.common.pojo.response.HttpResult; import com.njcn.common.utils.HttpResultUtil; import com.njcn.device.biz.pojo.dto.LineDTO; import com.njcn.device.biz.pojo.dto.LineALLInfoDTO; +import com.njcn.device.biz.pojo.dto.PollutionLineInfoDTO; import com.njcn.device.pq.service.LineService; import com.njcn.web.controller.BaseController; import io.swagger.annotations.Api; @@ -41,6 +42,15 @@ public class CommLineController extends BaseController { return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe); } + @OperateInfo(info = LogEnum.BUSINESS_COMMON) + @GetMapping("/getPollutionLineInfo") + @ApiOperation("获取污区值监测点相关信息") + public HttpResult> getPollutionLineInfo(@RequestParam("id") List id) { + String methodDescribe = getMethodDescribe("getPollutionLineInfo"); + List result = lineService.getPollutionLineInfo(id); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe); + } + @OperateInfo(info = LogEnum.BUSINESS_COMMON) @GetMapping("/getLineAllDetail") @ApiOperation("获取监测点id取超标监测点信息") diff --git a/pqs-device/pq-device/pq-device-boot/src/main/java/com/njcn/device/pq/mapper/DeviceMapper.java b/pqs-device/pq-device/pq-device-boot/src/main/java/com/njcn/device/pq/mapper/DeviceMapper.java index d938ffef4..a451c2e14 100644 --- a/pqs-device/pq-device/pq-device-boot/src/main/java/com/njcn/device/pq/mapper/DeviceMapper.java +++ b/pqs-device/pq-device/pq-device-boot/src/main/java/com/njcn/device/pq/mapper/DeviceMapper.java @@ -3,6 +3,7 @@ package com.njcn.device.pq.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.njcn.device.biz.pojo.dto.PollutionLineInfoDTO; import com.njcn.device.pq.pojo.po.Device; import com.njcn.device.pq.pojo.vo.DevDetail; import com.njcn.device.pq.pojo.vo.LineInfluxDbOnlineVO; @@ -85,4 +86,6 @@ public interface DeviceMapper extends BaseMapper { List selectDevByIds(@Param("ids") List ids); void updateDeviceRunFlag(@Param("id")String deviceId, @Param("runFlag")Integer status); + + List getPollutionDeviceInfo(@Param("id")List devId); } diff --git a/pqs-device/pq-device/pq-device-boot/src/main/java/com/njcn/device/pq/mapper/mapping/DeviceMapper.xml b/pqs-device/pq-device/pq-device-boot/src/main/java/com/njcn/device/pq/mapper/mapping/DeviceMapper.xml index 8ab3002c6..6572c7615 100644 --- a/pqs-device/pq-device/pq-device-boot/src/main/java/com/njcn/device/pq/mapper/mapping/DeviceMapper.xml +++ b/pqs-device/pq-device/pq-device-boot/src/main/java/com/njcn/device/pq/mapper/mapping/DeviceMapper.xml @@ -340,4 +340,45 @@ bdName, devName + + + diff --git a/pqs-device/pq-device/pq-device-boot/src/main/java/com/njcn/device/pq/service/LineService.java b/pqs-device/pq-device/pq-device-boot/src/main/java/com/njcn/device/pq/service/LineService.java index 2c3c458b5..4f2d53975 100644 --- a/pqs-device/pq-device/pq-device-boot/src/main/java/com/njcn/device/pq/service/LineService.java +++ b/pqs-device/pq-device/pq-device-boot/src/main/java/com/njcn/device/pq/service/LineService.java @@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.extension.service.IService; import com.njcn.device.biz.pojo.dto.LineDTO; import com.njcn.device.biz.pojo.dto.LineALLInfoDTO; import com.njcn.device.biz.pojo.dto.PollutionLineDTO; +import com.njcn.device.biz.pojo.dto.PollutionLineInfoDTO; import com.njcn.device.pq.pojo.dto.PollutionParamDTO; import com.njcn.device.pq.pojo.dto.PollutionSubstationDTO; import com.njcn.device.pq.pojo.param.*; @@ -234,4 +235,10 @@ public interface LineService extends IService { List getLevelMonitorByDept(@RequestParam("level") String level, @RequestParam("deptId")String deptId); + /** + * 获取污区值监测点相关信息 + * @author hongawen + */ + List getPollutionLineInfo(List id); + } diff --git a/pqs-device/pq-device/pq-device-boot/src/main/java/com/njcn/device/pq/service/impl/LineServiceImpl.java b/pqs-device/pq-device/pq-device-boot/src/main/java/com/njcn/device/pq/service/impl/LineServiceImpl.java index 455303bc8..33cf3751b 100644 --- a/pqs-device/pq-device/pq-device-boot/src/main/java/com/njcn/device/pq/service/impl/LineServiceImpl.java +++ b/pqs-device/pq-device/pq-device-boot/src/main/java/com/njcn/device/pq/service/impl/LineServiceImpl.java @@ -19,6 +19,7 @@ import com.njcn.common.utils.PubUtils; import com.njcn.device.biz.enums.DeviceResponseEnum; import com.njcn.device.biz.pojo.dto.LineALLInfoDTO; import com.njcn.device.biz.pojo.dto.LineDTO; +import com.njcn.device.biz.pojo.dto.PollutionLineInfoDTO; import com.njcn.device.biz.pojo.po.Overlimit; import com.njcn.device.pq.enums.LineBaseEnum; import com.njcn.device.pq.mapper.*; @@ -738,6 +739,39 @@ public class LineServiceImpl extends ServiceImpl implements Li return result; } + @Override + public List getPollutionLineInfo(List lineId) { + List pollutionLineInfoDTOList; + // 获取终端信息 + pollutionLineInfoDTOList = deviceMapper.getPollutionDeviceInfo(lineId); + List manufacturerList = dicDataFeignClient.getDicDataByTypeCode(DicDataTypeEnum.DEV_MANUFACTURER.getCode()).getData(); + List devTypeList = dicDataFeignClient.getDicDataByTypeCode(DicDataTypeEnum.DEV_TYPE.getCode()).getData(); + List businessTypeList = dicDataFeignClient.getDicDataByTypeCode(DicDataTypeEnum.BUSINESS_TYPE.getCode()).getData(); + List loadTypeList = dicDataFeignClient.getDicDataByTypeCode(DicDataTypeEnum.INTERFERENCE_SOURCE_TYPE.getCode()).getData(); + List voltageList = dicDataFeignClient.getDicDataByTypeCode(DicDataTypeEnum.DEV_VOLTAGE_STAND.getCode()).getData(); + for (PollutionLineInfoDTO pollutionLineInfoDTO : pollutionLineInfoDTOList) { + // 制造厂商 + Optional temp = manufacturerList.stream().filter(item -> item.getId().equals(pollutionLineInfoDTO.getManufacturer())).findAny(); + pollutionLineInfoDTO.setManufacturer(temp.map(DictData::getName).orElse(null)); + // 终端类型 + Optional temp1 = devTypeList.stream().filter(item -> item.getId().equals(pollutionLineInfoDTO.getDevType())).findAny(); + pollutionLineInfoDTO.setDevType(temp1.map(DictData::getName).orElse(null)); + // 行业类型 + Optional temp2 = businessTypeList.stream().filter(item -> item.getId().equals(pollutionLineInfoDTO.getBusinessType())).findAny(); + pollutionLineInfoDTO.setBusinessType(temp2.map(DictData::getName).orElse(null)); + // 干扰源类型 + Optional temp3 = loadTypeList.stream().filter(item -> item.getId().equals(pollutionLineInfoDTO.getLoadType())).findAny(); + pollutionLineInfoDTO.setLoadType(temp3.map(DictData::getName).orElse(null)); + // 电压等级 + Optional temp4 = voltageList.stream().filter(item -> item.getId().equals(pollutionLineInfoDTO.getLineVoltage())).findAny(); + pollutionLineInfoDTO.setLineVoltage(temp4.map(DictData::getName).orElse(null)); + + // 电网侧 + pollutionLineInfoDTO.setPowerFlag(pollutionLineInfoDTO.getPowerFlag().equals("0") ? "电网侧" : "非电网侧"); + } + return pollutionLineInfoDTOList; + } + @Override public List getOverLimitByList(PollutionParamDTO pollutionParamDTO) { return overlimitMapper.selectBatchIds(pollutionParamDTO.getLineList()); diff --git a/pqs-event/event-api/src/main/java/com/njcn/event/pojo/dto/EventCount.java b/pqs-event/event-api/src/main/java/com/njcn/event/pojo/dto/EventCount.java new file mode 100644 index 000000000..263ce1b34 --- /dev/null +++ b/pqs-event/event-api/src/main/java/com/njcn/event/pojo/dto/EventCount.java @@ -0,0 +1,37 @@ +package com.njcn.event.pojo.dto; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class EventCount implements Serializable { + + private String lineId; + + /** + * 暂升次数 1.1~1.8 + * 10ms ~ 1min + */ + private int upCounts; + + /** + * 暂降次数 0.1~0.9 + * 10ms ~ 1min + */ + private int downCounts; + + /** + * 短时中断 0~0.1 + * 10ms ~ 1min + */ + private int breakCounts; + + public EventCount(String lineId) { + this.lineId = lineId; + } +} diff --git a/pqs-prepare/prepare-api/src/main/java/com/njcn/prepare/harmonic/pojo/bo/excel/GdPollution.java b/pqs-prepare/prepare-api/src/main/java/com/njcn/prepare/harmonic/pojo/bo/excel/GdPollution.java new file mode 100644 index 000000000..67d69f7d2 --- /dev/null +++ b/pqs-prepare/prepare-api/src/main/java/com/njcn/prepare/harmonic/pojo/bo/excel/GdPollution.java @@ -0,0 +1,27 @@ +package com.njcn.prepare.harmonic.pojo.bo.excel; + +import cn.afterturn.easypoi.excel.annotation.Excel; +import cn.afterturn.easypoi.excel.annotation.ExcelCollection; +import lombok.Data; + +import java.io.Serializable; +import java.util.List; + +@Data +public class GdPollution implements Serializable { + + /** + * 供电公司名称 + */ + @Excel(name = "供电公司", width = 30, needMerge = true) + private String gdName; + + + /** + * 变电站集合 + * name不要赋值 + */ + @ExcelCollection(name = "") + private List substationPollutionList; + +} diff --git a/pqs-prepare/prepare-api/src/main/java/com/njcn/prepare/harmonic/pojo/bo/excel/LineItemPollution.java b/pqs-prepare/prepare-api/src/main/java/com/njcn/prepare/harmonic/pojo/bo/excel/LineItemPollution.java new file mode 100644 index 000000000..02bfd2ac3 --- /dev/null +++ b/pqs-prepare/prepare-api/src/main/java/com/njcn/prepare/harmonic/pojo/bo/excel/LineItemPollution.java @@ -0,0 +1,80 @@ +package com.njcn.prepare.harmonic.pojo.bo.excel; + +import cn.afterturn.easypoi.excel.annotation.Excel; +import lombok.Data; + +import java.io.Serializable; + +@Data +public class LineItemPollution implements Serializable { + + + /** + * 终端名称 + */ + @Excel(name = "终端名称", width = 30, replace = "/_null") + private String devName; + + /** + * 终端厂家 + */ + @Excel(name = "终端厂家", width = 30, replace = "/_null") + private String manufacturer; + + /** + * 终端型号 + */ + @Excel(name = "终端型号", width = 30, replace = "/_null") + private String devType; + + /** + * 终端投运时间 + */ + @Excel(name = "投运时间", width = 30, replace = "/_null") + private String loginTime; + + /** + * 监测点名称 + */ + @Excel(name = "监测点名称", width = 30, replace = "/_null") + private String lineName; + + /** + * 统计间隔 + */ + @Excel(name = "统计间隔", width = 30, replace = "/_null") + private Integer interval; + + /** + * 谐波电压污染值 + */ + @Excel(name = "污染值", width = 20, replace = "/_null") + private String vHarmonicValue; + + /** + * 暂升次数 1.1~1.8 + * 10ms ~ 1min + */ + private int upCounts; + + /** + * 暂降次数 0.1~0.9 + * 10ms ~ 1min + */ + @Excel(name = "电压暂降(次)", width = 20) + private int downCounts; + + /** + * 短时中断 0~0.1 + * 10ms ~ 1min + */ + @Excel(name = "短时中断(次)", width = 20) + private int breakCounts; + + /** + * 备注 + */ + @Excel(name = "备注", width = 30, replace = "/_null") + private String remark; + +} diff --git a/pqs-prepare/prepare-api/src/main/java/com/njcn/prepare/harmonic/pojo/bo/excel/LinePollution.java b/pqs-prepare/prepare-api/src/main/java/com/njcn/prepare/harmonic/pojo/bo/excel/LinePollution.java new file mode 100644 index 000000000..63450dc8c --- /dev/null +++ b/pqs-prepare/prepare-api/src/main/java/com/njcn/prepare/harmonic/pojo/bo/excel/LinePollution.java @@ -0,0 +1,145 @@ +package com.njcn.prepare.harmonic.pojo.bo.excel; + +import cn.afterturn.easypoi.excel.annotation.Excel; +import lombok.Data; + +import java.io.Serializable; + +@Data +public class LinePollution implements Serializable { + + + /** + * 供电公司名称 + */ + @Excel(name = "供电公司", width = 30) + private String gdName; + + /** + * 所属变电站 + */ + @Excel(name = "变电站", width = 30) + private String subStationName; + + /** + * 终端名称 + */ + @Excel(name = "终端名称", width = 30) + private String devName; + + /** + * 终端厂家 + */ + @Excel(name = "终端厂家", width = 30) + private String manufacturer; + + /** + * 终端型号 + */ + @Excel(name = "终端型号", width = 30) + private String devType; + + /** + * 终端投运时间 + */ + @Excel(name = "投运时间", width = 30) + private String loginTime; + + /** + * 监测点索引 + */ + private String lineId; + + /** + * 监测点名称 + */ + @Excel(name = "监测点名称", width = 30) + private String lineName; + + /** + * 位置,电网侧&非电网侧 + */ + @Excel(name = "监测位置", width = 30) + private String powerFlag; + + /** + * 新增 + * 监测点电压等级 + */ + @Excel(name = "监测点电压等级", width = 30) + private String lineVoltage; + + /** + * 干扰源类型 + */ + @Excel(name = "干扰源类型", width = 30) + private String loadType; + + /** + * 监测对象 + */ + @Excel(name = "监测对象名称", width = 30) + private String objName; + + /** + * 统计间隔 + */ + @Excel(name = "统计间隔", width = 30) + private Integer interval; + + /** + * 新增 + * 在线率 + */ + @Excel(name = "在线率(%)", width = 30) + private Double onlineRate; + + /** + * 新增 + * 完整性 + */ + @Excel(name = "完整率(%)", width = 30) + private Double integrity; + + /** + * 谐波电压污染值 + */ + @Excel(name = "污染值", width = 20) + private String vHarmonicValue; + + /** + * 暂升次数 1.1~1.8 + * 10ms ~ 1min + */ + private int upCounts; + + /** + * 暂降次数 0.1~0.9 + * 10ms ~ 1min + */ + @Excel(name = "电压暂降(次)", width = 20) + private int downCounts; + + /** + * 短时中断 0~0.1 + * 10ms ~ 1min + */ + @Excel(name = "短时中断(次)", width = 20) + private int breakCounts; + + @Excel(name = "是否关联敏感用户", width = 30, replace = "/_null") + private String isMg; + + @Excel(name = "敏感及重要用户", width = 30,replace = "/_null") + private String importUser; + + @Excel(name = "一类监测点", width = 30,replace = "/_null") + private String monitorId; + +// /** +// * 备注 +// */ +// @Excel(name = "备注", width = 30, replace = "/_null") +// private String remark; + +} diff --git a/pqs-prepare/prepare-api/src/main/java/com/njcn/prepare/harmonic/pojo/bo/excel/LoadTypeLineItemPollution.java b/pqs-prepare/prepare-api/src/main/java/com/njcn/prepare/harmonic/pojo/bo/excel/LoadTypeLineItemPollution.java new file mode 100644 index 000000000..0ae7ae3b9 --- /dev/null +++ b/pqs-prepare/prepare-api/src/main/java/com/njcn/prepare/harmonic/pojo/bo/excel/LoadTypeLineItemPollution.java @@ -0,0 +1,85 @@ +package com.njcn.prepare.harmonic.pojo.bo.excel; + +import cn.afterturn.easypoi.excel.annotation.Excel; +import lombok.Data; + +import java.io.Serializable; + +@Data +public class LoadTypeLineItemPollution implements Serializable { + + /** + * 所属变电站 + */ + @Excel(name = "变电站", width = 30, needMerge = true) + private String subStationName; + + /** + * 终端名称 + */ + @Excel(name = "终端名称", width = 30, replace = "/_null") + private String devName; + + /** + * 终端厂家 + */ + @Excel(name = "终端厂家", width = 30, replace = "/_null") + private String manufacturer; + + /** + * 终端型号 + */ + @Excel(name = "终端型号", width = 30, replace = "/_null") + private String devType; + + /** + * 终端投运时间 + */ + @Excel(name = "投运时间", width = 30, replace = "/_null") + private String loginTime; + + /** + * 监测点名称 + */ + @Excel(name = "监测点名称", width = 30, replace = "/_null") + private String lineName; + + /** + * 统计间隔 + */ + @Excel(name = "统计间隔", width = 30, replace = "/_null") + private Integer interval; + + /** + * 谐波电压污染值 + */ + @Excel(name = "测点污染值", width = 20, replace = "/_null") + private String vHarmonicValue; + + /** + * 暂升次数 1.1~1.8 + * 10ms ~ 1min + */ + private int upCounts; + + /** + * 暂降次数 0.1~0.9 + * 10ms ~ 1min + */ + @Excel(name = "电压暂降(次)", width = 20) + private int downCounts; + + /** + * 短时中断 0~0.1 + * 10ms ~ 1min + */ + @Excel(name = "短时中断(次)", width = 20) + private int breakCounts; + + /** + * 备注 + */ + @Excel(name = "备注", width = 30, replace = "/_null") + private String remark; + +} diff --git a/pqs-prepare/prepare-api/src/main/java/com/njcn/prepare/harmonic/pojo/bo/excel/ObjPollution.java b/pqs-prepare/prepare-api/src/main/java/com/njcn/prepare/harmonic/pojo/bo/excel/ObjPollution.java new file mode 100644 index 000000000..00746cc78 --- /dev/null +++ b/pqs-prepare/prepare-api/src/main/java/com/njcn/prepare/harmonic/pojo/bo/excel/ObjPollution.java @@ -0,0 +1,44 @@ +package com.njcn.prepare.harmonic.pojo.bo.excel; + +import cn.afterturn.easypoi.excel.annotation.Excel; +import cn.afterturn.easypoi.excel.annotation.ExcelCollection; +import lombok.Data; + +import java.io.Serializable; +import java.util.List; + +@Data +public class ObjPollution implements Serializable { + + /** + * 对象名称 + */ + @Excel(name = "用户名称", width = 30, needMerge = true) + private String objName; + + /** + * 干扰源类型 + */ + @Excel(name = "干扰源类型", width = 30, needMerge = true) + private String loadType; + + /** + * 行业类型 + */ + @Excel(name = "行业类型", width = 30, needMerge = true) + private String businessType; + + /** + * 用户污染值 + */ + @Excel(name = "用户污染值", width = 30, needMerge = true) + private String objValue; + + + /** + * 下面监测点详细污染值 + */ + @ExcelCollection(name = "") + private List lineItemPollutionList; + +} diff --git a/pqs-prepare/prepare-api/src/main/java/com/njcn/prepare/harmonic/pojo/bo/excel/PowerFlagPollution.java b/pqs-prepare/prepare-api/src/main/java/com/njcn/prepare/harmonic/pojo/bo/excel/PowerFlagPollution.java new file mode 100644 index 000000000..f374ad6b3 --- /dev/null +++ b/pqs-prepare/prepare-api/src/main/java/com/njcn/prepare/harmonic/pojo/bo/excel/PowerFlagPollution.java @@ -0,0 +1,34 @@ +package com.njcn.prepare.harmonic.pojo.bo.excel; + +import cn.afterturn.easypoi.excel.annotation.Excel; +import cn.afterturn.easypoi.excel.annotation.ExcelCollection; +import lombok.Data; + +import java.io.Serializable; +import java.util.List; + +@Data +public class PowerFlagPollution implements Serializable { + + /** + * 监测位置 + */ + @Excel(name = "监测位置", width = 30, needMerge = true) + private String powerFlag; + + + /** + * 监测污染值 + */ + @Excel(name = "监测污染值", width = 30, needMerge = true, replace = "/_null") + private String powerValue; + + + /** + * 当前位置下,各测点的污染数据 + */ + @ExcelCollection(name = "") + private List lineItemPollutionList; + + +} diff --git a/pqs-prepare/prepare-api/src/main/java/com/njcn/prepare/harmonic/pojo/bo/excel/SubstationPollution.java b/pqs-prepare/prepare-api/src/main/java/com/njcn/prepare/harmonic/pojo/bo/excel/SubstationPollution.java new file mode 100644 index 000000000..b3b9ee9fe --- /dev/null +++ b/pqs-prepare/prepare-api/src/main/java/com/njcn/prepare/harmonic/pojo/bo/excel/SubstationPollution.java @@ -0,0 +1,34 @@ +package com.njcn.prepare.harmonic.pojo.bo.excel; + +import cn.afterturn.easypoi.excel.annotation.Excel; +import cn.afterturn.easypoi.excel.annotation.ExcelCollection; +import lombok.Data; + +import java.io.Serializable; +import java.util.List; + +@Data +public class SubstationPollution implements Serializable { + + + /** + * 所属变电站 + */ + @Excel(name = "变电站", width = 30, needMerge = true) + private String subStationName; + + /** + * 电站污染值 + */ + @Excel(name = "电站污染值", width = 30, needMerge = true) + private String subStationValue; + + + /** + * 电网侧&非电网侧 + * name不要赋值 + */ + @ExcelCollection(name = "") + private List powerFlagPollutionList; + +} diff --git a/pqs-prepare/prepare-boot/src/main/java/com/njcn/prepare/harmonic/constant/InfluxdbPOConverter.java b/pqs-prepare/prepare-boot/src/main/java/com/njcn/prepare/harmonic/constant/InfluxdbPOConverter.java index 83938e499..463dc0dd0 100644 --- a/pqs-prepare/prepare-boot/src/main/java/com/njcn/prepare/harmonic/constant/InfluxdbPOConverter.java +++ b/pqs-prepare/prepare-boot/src/main/java/com/njcn/prepare/harmonic/constant/InfluxdbPOConverter.java @@ -74,7 +74,6 @@ public interface InfluxdbPOConverter { @Mapping(source = "v48", target = "harmonicVoltageContent48Max" ,numberFormat = "#.000") @Mapping(source = "v49", target = "harmonicVoltageContent49Max" ,numberFormat = "#.000") @Mapping(source = "v50", target = "harmonicVoltageContent50Max" ,numberFormat = "#.000") - public RMpHarmonicVRateReportD dataVPOTORMpHarmonicPReportDPOMax(DataHarmRateV dataVPO); @Mapping(source = "v1", target = "fundamentalVoltageMin",numberFormat = "#.000") diff --git a/pqs-prepare/prepare-boot/src/main/java/com/njcn/prepare/harmonic/mapper/mysql/EventMapper.java b/pqs-prepare/prepare-boot/src/main/java/com/njcn/prepare/harmonic/mapper/mysql/EventMapper.java new file mode 100644 index 000000000..16c60af92 --- /dev/null +++ b/pqs-prepare/prepare-boot/src/main/java/com/njcn/prepare/harmonic/mapper/mysql/EventMapper.java @@ -0,0 +1,26 @@ +package com.njcn.prepare.harmonic.mapper.mysql; + +import cn.hutool.core.date.DateTime; +import com.njcn.event.pojo.dto.EventCount; +import com.njcn.harmonic.pojo.vo.IntegrityVO; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + *

+ * Mapper 接口 + *

+ * + * @author xuyang + * @since 2024-01-25 + */ +public interface EventMapper { + + List getEventCount(@Param("startTime") DateTime startTime, @Param("endTime")DateTime endTime); + + List getIntegrity(@Param("startTime") DateTime startTime, @Param("endTime")DateTime endTime); + + List getOnlineRate(@Param("startTime") DateTime startTime, @Param("endTime")DateTime endTime); + +} diff --git a/pqs-prepare/prepare-boot/src/main/java/com/njcn/prepare/harmonic/mapper/mysql/EventMapper.xml b/pqs-prepare/prepare-boot/src/main/java/com/njcn/prepare/harmonic/mapper/mysql/EventMapper.xml new file mode 100644 index 000000000..7fad810ae --- /dev/null +++ b/pqs-prepare/prepare-boot/src/main/java/com/njcn/prepare/harmonic/mapper/mysql/EventMapper.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/pqs-prepare/prepare-boot/src/main/java/com/njcn/prepare/harmonic/service/influxdb/IPollutionCalc.java b/pqs-prepare/prepare-boot/src/main/java/com/njcn/prepare/harmonic/service/influxdb/IPollutionCalc.java new file mode 100644 index 000000000..19a030402 --- /dev/null +++ b/pqs-prepare/prepare-boot/src/main/java/com/njcn/prepare/harmonic/service/influxdb/IPollutionCalc.java @@ -0,0 +1,6 @@ +package com.njcn.prepare.harmonic.service.influxdb; + +public interface IPollutionCalc { + + void calcAllLineValue(); +} diff --git a/pqs-prepare/prepare-boot/src/main/java/com/njcn/prepare/harmonic/service/influxdb/impl/PollutionCalcImpl.java b/pqs-prepare/prepare-boot/src/main/java/com/njcn/prepare/harmonic/service/influxdb/impl/PollutionCalcImpl.java new file mode 100644 index 000000000..d84b3abfc --- /dev/null +++ b/pqs-prepare/prepare-boot/src/main/java/com/njcn/prepare/harmonic/service/influxdb/impl/PollutionCalcImpl.java @@ -0,0 +1,477 @@ +package com.njcn.prepare.harmonic.service.influxdb.impl; + +import cn.afterturn.easypoi.excel.ExcelExportUtil; +import cn.afterturn.easypoi.excel.entity.ExportParams; +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.date.DateTime; +import cn.hutool.core.date.DateUtil; +import com.njcn.common.utils.HarmonicTimesUtil; +import com.njcn.common.utils.PubUtils; +import com.njcn.device.biz.commApi.CommLineClient; +import com.njcn.device.biz.commApi.CommTerminalGeneralClient; +import com.njcn.device.biz.pojo.dto.LineDevGetDTO; +import com.njcn.device.biz.pojo.dto.PollutionLineInfoDTO; +import com.njcn.device.biz.pojo.po.Overlimit; +import com.njcn.event.api.EventDetailFeignClient; +import com.njcn.event.pojo.dto.EventCount; +import com.njcn.harmonic.pojo.vo.IntegrityVO; +import com.njcn.influx.constant.InfluxDbSqlConstant; +import com.njcn.influx.imapper.DataHarmRateVMapper; +import com.njcn.influx.imapper.DataVMapper; +import com.njcn.influx.pojo.constant.InfluxDBTableConstant; +import com.njcn.influx.pojo.po.DataHarmRateV; +import com.njcn.influx.pojo.po.DataV; +import com.njcn.influx.query.InfluxQueryWrapper; +import com.njcn.prepare.harmonic.mapper.mysql.EventMapper; +import com.njcn.prepare.harmonic.pojo.bo.excel.*; +import com.njcn.prepare.harmonic.service.influxdb.IPollutionCalc; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.poi.ss.usermodel.Workbook; +import org.springframework.stereotype.Service; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.lang.reflect.Field; +import java.util.*; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +@Service +@RequiredArgsConstructor +@Slf4j +public class PollutionCalcImpl implements IPollutionCalc { + + private final CommTerminalGeneralClient commTerminalGeneralClient; + + private final CommLineClient commLineClient; + + private final DataVMapper dataVMapper; + + private final DataHarmRateVMapper dataHarmRateVMapper; + + private final EventDetailFeignClient eventDetailFeignClient; + + private final EventMapper eventMapper; + + /** + * 监测点污染值计算,谐波电压&谐波电流 + * 1、获取所有监测点; + * 2、根据指标获取对应的污染值,目前仅做谐波电压; + * 注:目前仅支持获取昨天的 + */ + @Override + public void calcAllLineValue() { +// LocalDate yesterday = LocalDate.now().minusDays(1); +// String yesterdayDate = LocalDateTimeUtil.format(LocalDateTimeUtil.beginOfDay(LocalDateTimeUtil.of(yesterday)), DatePattern.NORM_DATE_PATTERN); + + List lineIdList = commTerminalGeneralClient.getRunMonitorIds().getData(); + // List lineIdList = Stream.of("2886ec28f6ea8b0444ce18849f2e5736").collect(Collectors.toList()); + // 获取所有监测点的暂态数据 由于暂态事件较少,暂时查询最近30天的 +// LocalDate last30Day = LocalDate.now().minusDays(31); +// String startDate = LocalDateTimeUtil.format(LocalDateTimeUtil.beginOfDay(LocalDateTimeUtil.of(last30Day)), DatePattern.NORM_DATE_PATTERN); + String startDate = "2025-02-10"; + String yesterdayDate = "2025-03-10"; + + List eventCounts = getEventCount(lineIdList, startDate, yesterdayDate); + Map eventMap = eventCounts.stream().collect(Collectors.toMap(EventCount::getLineId, pojo -> pojo)); + // 获取所有监测点的元信息 + List lineInfoDTOList = commLineClient.getPollutionLineInfo(lineIdList).getData(); +// String beginDay = LocalDateTimeUtil.format(LocalDateTimeUtil.beginOfDay(LocalDateTimeUtil.of(yesterday)), DatePattern.NORM_DATETIME_PATTERN); +// String endDay = LocalDateTimeUtil.format(LocalDateTimeUtil.endOfDay(LocalDateTimeUtil.of(yesterday)), DatePattern.NORM_DATETIME_PATTERN); + String beginDay = "2025-02-10 00:00:00"; + String endDay = "2025-03-10 23:59:59"; + //获取监测点的数据完整性 + List integrityList = getIntegrity(startDate, yesterdayDate); + Map integrityMap = integrityList.stream().collect(Collectors.toMap(IntegrityVO::getId, pojo -> pojo)); + //获取装置在线率 + List onlineRateList = getOnlineRate(startDate, yesterdayDate); + Map onlineRateMap = onlineRateList.stream().collect(Collectors.toMap(IntegrityVO::getId, pojo -> pojo)); + List linePollutionList = new ArrayList<>(); + long startTime = System.currentTimeMillis(); + if (CollUtil.isNotEmpty(lineIdList)) { + System.out.println("总共" + lineIdList.size() + "个监测点参与污染值计算,开始执行"); + // 获取谐波电压数据&总畸变率&越限限值计算基础污染值 + for (int i = 0; i < lineIdList.size(); i++) { + String lineId = lineIdList.get(i); + LinePollution linePollution = new LinePollution(); + linePollution.setLineId(lineId); + //获取监测点数据完整性 + IntegrityVO vo = integrityMap.get(lineId); + linePollution.setIntegrity(Objects.isNull(vo) ? 0.0 : vo.getIntegrityData()); + //获取监测点限值 + Overlimit overlimit = commTerminalGeneralClient.getOverLimitData(lineId).getData(); + LineDevGetDTO lineDetailData = commTerminalGeneralClient.getMonitorDetail(lineId).getData(); + if (Objects.isNull(overlimit) || Objects.isNull(lineDetailData)) { + // 如果没有查到限值跳过,后期需要记录这种异常 + continue; + } + linePollution.setLineName(lineDetailData.getPointName()); + linePollution.setInterval(lineDetailData.getInterval()); + // 计算谐波电压的污染值 + linePollution.setVHarmonicValue(PubUtils.doubleRound(2, calcVAllPollutionValue(linePollution, overlimit, beginDay, endDay) * linePollution.getInterval()) + ""); + // 获取暂态数据 +// statisticsEvent(linePollution); + BeanUtil.copyProperties(eventMap.get(lineId), linePollution); + //获取该监测点其他元信息 + Optional any = lineInfoDTOList.stream().filter(item -> item.getLineId().equals(lineId)).findAny(); + if (any.isPresent()) { + PollutionLineInfoDTO data = any.get(); + BeanUtil.copyProperties(data, linePollution, true); +// if (data.getComFlag() == 0) { +// linePollution.setRemark("终端通讯状态为中断!"); +// } + IntegrityVO vo2 = onlineRateMap.get(data.getDeviceId()); + linePollution.setOnlineRate(Objects.isNull(vo2) ? 0.0 : vo2.getIntegrityData()); + } + linePollutionList.add(linePollution); + } + } + List finalLinePollutionList = new ArrayList<>(linePollutionList); + // 全部监测点计算完毕后根据污染值从大到小进行排序 + finalLinePollutionList.sort(Comparator.comparingDouble(o -> Double.parseDouble(o.getVHarmonicValue()))); + Collections.reverse(finalLinePollutionList); + + // 监测点的污染值计算完毕后,输出到指定目录。目前目录是写死的,待后期调整成配置可供用户选择下载。todo... + // 导出监测点污染值 + String folder = "c:\\njcn"; + File file = new File(folder); + if (!file.exists()) { + boolean mkdirs = file.mkdirs(); + if (!mkdirs) { + System.out.println("无法创建文件夹"); + return; + } + } + String fileName = folder + "\\监测点谐波电压污染值" + yesterdayDate + ".xlsx"; + ExportParams exportParams = new ExportParams(); + exportLinePollution(exportParams, LinePollution.class, finalLinePollutionList, fileName); + + // 处理干扰源用户的报告 + List loadTypeLineList = new ArrayList<>(linePollutionList); + /** + * 1、首先过滤:重要变电站、一类变电站、跨省计量关点 todo...待优化 + * 2、过滤后,以监测对象分组统计数据有多个测点的需要出结果 + */ + List loadTypeSubStation = Stream.of("重要变电站", "一类变电站", "跨省计量关点").collect(Collectors.toList()); + loadTypeLineList = loadTypeLineList.stream().filter(item -> !loadTypeSubStation.contains(item.getLoadType())).collect(Collectors.toList()); + // 监测对象分组 + Map> loadTypeMap = loadTypeLineList.stream().collect(Collectors.groupingBy(LinePollution::getObjName)); + List objPollutions = new ArrayList<>(); + Set objNameSet = loadTypeMap.keySet(); + for (String objName : objNameSet) { + ObjPollution objPollution = new ObjPollution(); + List linePollutions = loadTypeMap.get(objName); + objPollution.setObjName(linePollutions.get(0).getObjName()); + objPollution.setLoadType(linePollutions.get(0).getLoadType()); +// objPollution.setBusinessType(linePollutions.get(0).getBusinessType()); + // 求出平均污染值 + double objValue = linePollutions.stream() + .mapToDouble(o -> Double.parseDouble(o.getVHarmonicValue())) + .sum(); + objPollution.setObjValue(PubUtils.doubleRound(2, objValue) + ""); + + // 处理该监测对象下面监测点的信息 + List loadTypeLineItemPollutions = new ArrayList<>(); + for (LinePollution linePollution : linePollutions) { + LoadTypeLineItemPollution loadTypeLineItemPollution = new LoadTypeLineItemPollution(); + BeanUtil.copyProperties(linePollution, loadTypeLineItemPollution, true); + loadTypeLineItemPollutions.add(loadTypeLineItemPollution); + } + objPollution.setLineItemPollutionList(loadTypeLineItemPollutions); + objPollutions.add(objPollution); + } + fileName = folder + "\\用户谐波电压污染值" + yesterdayDate + ".xlsx"; + exportParams = new ExportParams(); + // 排序 + objPollutions.sort(Comparator.comparingDouble(o -> Double.parseDouble(o.getObjValue()))); + Collections.reverse(objPollutions); + exportLinePollution(exportParams, ObjPollution.class, objPollutions, fileName); + + // 整合变电站待导出的数据 + List gdPollutionList = new ArrayList<>(); + // 以供电公司分组 + Map> gdMap = linePollutionList.stream() + .collect(Collectors.groupingBy(LinePollution::getGdName)); + // 同一供电公司以变电站分组 + Set gdNameSet = gdMap.keySet(); + for (String gdName : gdNameSet) { + // 初始化gd实体 + GdPollution gdPollution = new GdPollution(); + gdPollution.setGdName(gdName); + List gdLinePollution = gdMap.get(gdName); + // 以变电站分组 + Map> subMap = gdLinePollution.stream() + .collect(Collectors.groupingBy(LinePollution::getSubStationName)); + Set subNameMap = subMap.keySet(); + List substationPollutions = new ArrayList<>(); + for (String subName : subNameMap) { + // 初始化变电站实体 + SubstationPollution substationPollution = new SubstationPollution(); + substationPollution.setSubStationName(subName); + List subLinePollution = subMap.get(subName); + // 需要区分电网侧、非电网侧 + Map> powerFlagLinePollution = subLinePollution.stream().collect(Collectors.groupingBy(LinePollution::getPowerFlag)); + + List powerFlagPollutionList = new ArrayList<>(); + // 电网侧 + List temp = powerFlagLinePollution.get("电网侧"); + PowerFlagPollution powerFlagPollution1 = new PowerFlagPollution(); + powerFlagPollution1.setPowerFlag("电网侧"); + List lineItemPollutionList1 = new ArrayList<>(); + if (CollUtil.isNotEmpty(temp)) { + // 计算电网侧下所有监测点平均污染值 + double subValue = temp.stream() + .mapToDouble(o -> Double.parseDouble(o.getVHarmonicValue())) + .average() + .orElse(0.0); + // 电网侧污染值 + powerFlagPollution1.setPowerValue(PubUtils.doubleRound(2, subValue) + ""); + // 设备信息 + for (LinePollution linePollution : temp) { + LineItemPollution lineItemPollution = new LineItemPollution(); + BeanUtil.copyProperties(linePollution, lineItemPollution, true); + lineItemPollutionList1.add(lineItemPollution); + } + } else { + // 仅有非电网侧时,电网侧赋予空置 + LineItemPollution lineItemPollution = new LineItemPollution(); + lineItemPollutionList1.add(lineItemPollution); + } + // 设备信息注入监测位置对象中 + powerFlagPollution1.setLineItemPollutionList(lineItemPollutionList1); + powerFlagPollutionList.add(powerFlagPollution1); + + + // 非电网侧 + List temp1 = powerFlagLinePollution.get("非电网侧"); + PowerFlagPollution powerFlagPollution2 = new PowerFlagPollution(); + powerFlagPollution2.setPowerFlag("非电网侧"); + List lineItemPollutionList2 = new ArrayList<>(); + if (CollUtil.isNotEmpty(temp1)) { + // 计算非电网侧下所有监测点平均污染值 + double subValue = temp1.stream() + .mapToDouble(o -> Double.parseDouble(o.getVHarmonicValue())) + .average() + .orElse(0.0); + powerFlagPollution2.setPowerValue(PubUtils.doubleRound(2, subValue) + ""); + for (LinePollution linePollution : temp1) { + LineItemPollution lineItemPollution = new LineItemPollution(); + BeanUtil.copyProperties(linePollution, lineItemPollution, true); + lineItemPollutionList2.add(lineItemPollution); + } + } else { + // 仅有非电网侧时,电网侧赋予空置 + LineItemPollution lineItemPollution = new LineItemPollution(); + lineItemPollutionList2.add(lineItemPollution); + } + // 设备信息注入监测位置对象中 + powerFlagPollution2.setLineItemPollutionList(lineItemPollutionList2); + powerFlagPollutionList.add(powerFlagPollution2); + + substationPollution.setPowerFlagPollutionList(powerFlagPollutionList); + // 如果电网侧有污染值,就作为变电站的污染值,否则就用非电网侧的污染值作为该变电站污染值 + if (Objects.nonNull(powerFlagPollution1.getPowerValue())) { + substationPollution.setSubStationValue(powerFlagPollution1.getPowerValue()); + } else { + substationPollution.setSubStationValue(powerFlagPollution2.getPowerValue()); + } + substationPollutions.add(substationPollution); + } + + // 针对这个供电公司下的变电站污染值排序 + substationPollutions.sort(Comparator.comparingDouble(o -> Double.parseDouble(o.getSubStationValue()))); + Collections.reverse(substationPollutions); +// List finalSubstation = substationPollutions.stream().sorted((Comparator.comparingDouble(SubstationPollution::getSubStationValue)) +// .reversed()) +// .collect(Collectors.toList()); + gdPollution.setSubstationPollutionList(substationPollutions); + gdPollutionList.add(gdPollution); + } + fileName = folder + "\\变电站谐波电压污染值" + yesterdayDate + ".xlsx"; + exportParams = new ExportParams(); + exportLinePollution(exportParams, GdPollution.class, gdPollutionList, fileName); + + long endTime = System.currentTimeMillis(); + long time = (endTime - startTime) / 1000; + System.out.println("程序执行完毕,总耗时:" + time + "秒"); + } + + + /** + * 输出下载文件 + * + * @param exportParams excel配置信息 + * @param pojoClass 映射对象 + * @param dataSet 数据集 + * @param fileName 文件名 + */ + private void exportLinePollution(ExportParams exportParams, Class pojoClass, Collection dataSet, String fileName) { + Workbook workbook = ExcelExportUtil.exportExcel(exportParams, pojoClass, dataSet); + File outFile = new File(fileName); + try (FileOutputStream fos = new FileOutputStream(outFile)) { + workbook.write(fos); + System.out.println("文档输出成功"); + } catch (IOException e) { + System.out.println("文档输出异常"); + } finally { + try { + workbook.close(); + } catch (IOException exception) { + System.out.println("关闭通道失败"); + } + } + } + + /** + * 计算谐波电压的污染值,包含了电压总畸变率和谐波电压2~25次 + * + * @param linePollution 监测点信息 + * @param overlimit 当前监测点限值 + */ + private double calcVAllPollutionValue(LinePollution linePollution, Overlimit overlimit, String startTime, String endTime) { + //最大值 + InfluxQueryWrapper dataVQueryWrapper = new InfluxQueryWrapper(DataV.class); + dataVQueryWrapper.eq(DataV::getLineId, linePollution.getLineId()) + .eq(DataV::getValueType, InfluxDbSqlConstant.CP95) + .ne(DataHarmRateV::getPhaseType, InfluxDBTableConstant.PHASE_TYPE_T) + .max(DataV::getVThd) + .groupBy("time(" + linePollution.getInterval() + "m)") + .between(DataV::getTime, startTime, endTime); + List vthResultList = dataVMapper.getStatisticsByWraper(dataVQueryWrapper); + // 计算时间范围内指标越限百分比 + // 总畸变率的限值 + List thdValueList = vthResultList.stream().map(DataV::getVThd).collect(Collectors.toList()); + double thdPollutionValue = calcPollutionValue(overlimit.getUbalance(), thdValueList); + // 谐波电压2~50次的数据获取并计算 + InfluxQueryWrapper harmRateVQueryWrapper = new InfluxQueryWrapper(DataHarmRateV.class); + harmRateVQueryWrapper.maxSamePrefixAndSuffix(InfluxDbSqlConstant.V, "", HarmonicTimesUtil.harmonicTimesList(2, 50, 1)); + harmRateVQueryWrapper.eq(DataHarmRateV::getLineId, linePollution.getLineId()) + .eq(DataHarmRateV::getValueType, InfluxDbSqlConstant.CP95) + .ne(DataHarmRateV::getPhaseType, InfluxDBTableConstant.PHASE_TYPE_T) + .groupBy("time(" + linePollution.getInterval() + "m)") + .between(DataHarmRateV::getTime, startTime, endTime); + List dataHarmRateVList = dataHarmRateVMapper.getStatisticsByWraper(harmRateVQueryWrapper); + double harmRateVPollutionValue = calcHarmRateVPollutionValue(overlimit, dataHarmRateVList); + return thdPollutionValue + harmRateVPollutionValue; + } + + /** + * 计算谐波电压2~50的越限污染值 + * + * @param overlimit 限值 + * @param dataHarmRateVList 2~50次的谐波电压值 + * @return 谐波电压污染值 + */ + private double calcHarmRateVPollutionValue(Overlimit overlimit, List dataHarmRateVList) { + List pollutionValue = new ArrayList<>(); + // 2次 + for (int i = 2; i < 51; i++) { + Float limitValue = getValueByFieldName(overlimit, "uharm" + i); + int finalI = i; + List valueList = dataHarmRateVList.stream().map(item -> { + Float valueByFieldName = getValueByFieldName(item, "v" + finalI); + if (Objects.isNull(valueByFieldName)) { + return 0.0; + } else { + return (double) valueByFieldName; + } + }).collect(Collectors.toList()); + pollutionValue.add(calcPollutionValue(limitValue, valueList)); + } + return pollutionValue.stream().mapToDouble(Double::doubleValue).sum(); + } + + /** + * 获取当前组数据的污染值 + * + * @param limit 限值 + * @param valueList 参考数据 + * @return 污染值 + */ + private double calcPollutionValue(Float limit, List valueList) { + double pollutionValue = 0; + // 没有限值的直接返回 + if (Objects.isNull(limit) || limit == 0.0f) { + return pollutionValue; + } + // 计算每个数值的越限百分比MOP + List overLimitPercentList = valueList.stream().map(value -> { + if (Objects.isNull(value)) { + return 0.0; + } + return value * 100 / limit; + }).collect(Collectors.toList()); + // 计算每个越限百分比对应的污染值,并求和返回 + if (CollUtil.isNotEmpty(overLimitPercentList)) { + pollutionValue = overLimitPercentList.stream().map(item -> { + double value = 0; + if (item >= 100.0 && item < 120.0) { + value = 0.1; + } else if (item >= 120.0 && item < 160.0) { + value = 0.2; + } else if (item >= 160.0 && item < 200.0) { + value = 0.3; + } else if (item >= 200.0) { + value = 0.4; + } + return value; + }).mapToDouble(Double::doubleValue).sum(); + } + return pollutionValue; + } + + /** + * 根据标记获取属性对应的值 + * + * @return 值 + */ + public static Float getValueByFieldName(Object obj, String fieldName) { + try { + Field field = obj.getClass().getDeclaredField(fieldName); + field.setAccessible(true); + Object val = field.get(obj); + if (Objects.isNull(val)) { + return null; + } + if (val instanceof Double) { + Double doubleValue = (Double) val; + return doubleValue.floatValue(); + } + return (float) field.get(obj); + } catch (NoSuchFieldException | IllegalAccessException e) { + return 0.0f; + } + } + + public List getEventCount(List ids, String startDate, String endDate) { + DateTime startTime = DateUtil.beginOfDay(DateUtil.parse(startDate)); + DateTime endTime = DateUtil.endOfDay(DateUtil.parse(endDate)); + List eventCounts = eventMapper.getEventCount(startTime, endTime); + Map eventMap = eventCounts.stream().collect(Collectors.toMap(EventCount::getLineId, pojo -> pojo)); + List eventCountList = new ArrayList<>(); + for (String id : ids) { + EventCount eventCountTemp = eventMap.get(id); + if (Objects.isNull(eventCountTemp)) { + eventCountTemp = new EventCount(id); + } + eventCountList.add(eventCountTemp); + } + return eventCountList; + } + + public List getIntegrity(String startDate, String endDate) { + DateTime startTime = DateUtil.beginOfDay(DateUtil.parse(startDate)); + DateTime endTime = DateUtil.endOfDay(DateUtil.parse(endDate)); + return eventMapper.getIntegrity(startTime, endTime); + } + + public List getOnlineRate(String startDate, String endDate) { + DateTime startTime = DateUtil.beginOfDay(DateUtil.parse(startDate)); + DateTime endTime = DateUtil.endOfDay(DateUtil.parse(endDate)); + return eventMapper.getOnlineRate(startTime, endTime); + } + +} diff --git a/pqs-prepare/prepare-boot/src/main/java/com/njcn/prepare/harmonic/service/mysql/Impl/device/RStatDevSignalDPOServiceImpl.java b/pqs-prepare/prepare-boot/src/main/java/com/njcn/prepare/harmonic/service/mysql/Impl/device/RStatDevSignalDPOServiceImpl.java index 4857d7c3f..9693e2d9f 100644 --- a/pqs-prepare/prepare-boot/src/main/java/com/njcn/prepare/harmonic/service/mysql/Impl/device/RStatDevSignalDPOServiceImpl.java +++ b/pqs-prepare/prepare-boot/src/main/java/com/njcn/prepare/harmonic/service/mysql/Impl/device/RStatDevSignalDPOServiceImpl.java @@ -89,6 +89,7 @@ public class RStatDevSignalDPOServiceImpl extends MppServiceImpl