冀北污染值算法上传

This commit is contained in:
2025-03-12 13:41:15 +08:00
parent 7f6aa6f683
commit 295fddb935
23 changed files with 1242 additions and 5 deletions

View File

@@ -21,7 +21,7 @@ public class GenerateCode {
private static final String TARGET_DIR = "D://code"; 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 DB_URL = "jdbc:oracle:thin:@192.168.1.170:1521:pqsbase";
private static final String USERNAME = "root"; private static final String USERNAME = "root";
@@ -30,9 +30,9 @@ public class GenerateCode {
public static void main(String[] args) { public static void main(String[] args) {
List<Module> modules = Stream.of( List<Module> modules = Stream.of(
new Module("xy", "com.njcn.supervision", "survey", Stream.of( new Module("hongawen", "com.njcn.gather", "", Stream.of(
"app_version" "pq_dev_type"
).collect(Collectors.toList()), "supervision_") ).collect(Collectors.toList()), "pq_")
).collect(Collectors.toList()); ).collect(Collectors.toList());
generateJavaFile(modules); generateJavaFile(modules);
} }

View File

@@ -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.LineALLInfoDTO;
import com.njcn.device.biz.pojo.dto.LineDTO; import com.njcn.device.biz.pojo.dto.LineDTO;
import com.njcn.device.biz.pojo.dto.PollutionLineDTO; 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.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
@@ -36,6 +37,14 @@ public interface CommLineClient {
@GetMapping("/getLineDetail") @GetMapping("/getLineDetail")
HttpResult<LineDTO> getLineDetail(@RequestParam("id") String id); HttpResult<LineDTO> getLineDetail(@RequestParam("id") String id);
/**
* 获取污区值监测点相关信息
*
* @author hongawen
*/
@GetMapping("/getPollutionLineInfo")
HttpResult<List<PollutionLineInfoDTO>> getPollutionLineInfo(@RequestParam("id") List<String> id);
/*** /***
* 批量获取监测点信息 * 批量获取监测点信息
* @author hongawen * @author hongawen

View File

@@ -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.LineALLInfoDTO;
import com.njcn.device.biz.pojo.dto.LineDTO; import com.njcn.device.biz.pojo.dto.LineDTO;
import com.njcn.device.biz.pojo.dto.PollutionLineDTO; import com.njcn.device.biz.pojo.dto.PollutionLineDTO;
import com.njcn.device.biz.pojo.dto.PollutionLineInfoDTO;
import com.njcn.device.biz.utils.DeviceEnumUtil; import com.njcn.device.biz.utils.DeviceEnumUtil;
import feign.hystrix.FallbackFactory; import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@@ -39,6 +40,12 @@ public class CommLineClientFallbackFactory implements FallbackFactory<CommLineCl
throw new BusinessException(finalExceptionEnum); throw new BusinessException(finalExceptionEnum);
} }
@Override
public HttpResult<List<PollutionLineInfoDTO>> getPollutionLineInfo(List<String> id) {
log.error("{}异常,降级处理,异常为:{}", "获取污区值监测点相关信息", throwable.toString());
throw new BusinessException(finalExceptionEnum);
}
@Override @Override
public HttpResult<List<LineDTO>> getLineDetailBatch(List<String> ids) { public HttpResult<List<LineDTO>> getLineDetailBatch(List<String> ids) {
log.error("{}异常,降级处理,异常为:{}", "批量获取监测点信息", throwable.toString()); log.error("{}异常,降级处理,异常为:{}", "批量获取监测点信息", throwable.toString());

View File

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

View File

@@ -7,6 +7,7 @@ import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil; import com.njcn.common.utils.HttpResultUtil;
import com.njcn.device.biz.pojo.dto.LineDTO; import com.njcn.device.biz.pojo.dto.LineDTO;
import com.njcn.device.biz.pojo.dto.LineALLInfoDTO; 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.device.pq.service.LineService;
import com.njcn.web.controller.BaseController; import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
@@ -41,6 +42,15 @@ public class CommLineController extends BaseController {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe); return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
} }
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@GetMapping("/getPollutionLineInfo")
@ApiOperation("获取污区值监测点相关信息")
public HttpResult<List<PollutionLineInfoDTO>> getPollutionLineInfo(@RequestParam("id") List<String> id) {
String methodDescribe = getMethodDescribe("getPollutionLineInfo");
List<PollutionLineInfoDTO> result = lineService.getPollutionLineInfo(id);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON) @OperateInfo(info = LogEnum.BUSINESS_COMMON)
@GetMapping("/getLineAllDetail") @GetMapping("/getLineAllDetail")
@ApiOperation("获取监测点id取超标监测点信息") @ApiOperation("获取监测点id取超标监测点信息")

View File

@@ -3,6 +3,7 @@ package com.njcn.device.pq.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 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.po.Device;
import com.njcn.device.pq.pojo.vo.DevDetail; import com.njcn.device.pq.pojo.vo.DevDetail;
import com.njcn.device.pq.pojo.vo.LineInfluxDbOnlineVO; import com.njcn.device.pq.pojo.vo.LineInfluxDbOnlineVO;
@@ -85,4 +86,6 @@ public interface DeviceMapper extends BaseMapper<Device> {
List<DevDetail> selectDevByIds(@Param("ids") List<String> ids); List<DevDetail> selectDevByIds(@Param("ids") List<String> ids);
void updateDeviceRunFlag(@Param("id")String deviceId, @Param("runFlag")Integer status); void updateDeviceRunFlag(@Param("id")String deviceId, @Param("runFlag")Integer status);
List<PollutionLineInfoDTO> getPollutionDeviceInfo(@Param("id")List<String> devId);
} }

View File

@@ -340,4 +340,45 @@
bdName, bdName,
devName devName
</select> </select>
<select id="getPollutionDeviceInfo" resultType="com.njcn.device.biz.pojo.dto.PollutionLineInfoDTO">
SELECT
line.id lineId,
gdinfo.NAME AS gdName,
substation.NAME AS subStationName,
device.NAME AS devName,
deviceDetail.Com_Flag AS comFlag,
lineDetail.power_Flag AS powerFlag,
lineDetail.business_type AS businessType,
lineDetail.load_type AS loadtype,
lineDetail.obj_name AS objName,
lineDetail.power_substation_name AS powerSubstationName,
deviceDetail.manufacturer AS manufacturer,
deviceDetail.dev_Type AS devType,
deviceDetail.login_Time AS loginTime,
deviceDetail.id deviceId,
pv.scale lineVoltage,
lineDetail.monitor_id monitorId
FROM
pq_line line,
pq_line_detail lineDetail,
pq_line subv,
pq_line device,
pq_device deviceDetail,
pq_line substation,
pq_line gdinfo,
pq_voltage pv
WHERE line.id in
<foreach collection="id" close=")" item="item" open="(" separator=",">
#{item}
</foreach>
AND line.id = lineDetail.id
AND line.pid = subv.id
AND subv.pid = device.id
AND device.id = deviceDetail.id
AND device.pid = substation.id
AND substation.pid = gdinfo.id
AND subv.id = pv.id
</select>
</mapper> </mapper>

View File

@@ -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.LineDTO;
import com.njcn.device.biz.pojo.dto.LineALLInfoDTO; import com.njcn.device.biz.pojo.dto.LineALLInfoDTO;
import com.njcn.device.biz.pojo.dto.PollutionLineDTO; 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.PollutionParamDTO;
import com.njcn.device.pq.pojo.dto.PollutionSubstationDTO; import com.njcn.device.pq.pojo.dto.PollutionSubstationDTO;
import com.njcn.device.pq.pojo.param.*; import com.njcn.device.pq.pojo.param.*;
@@ -234,4 +235,10 @@ public interface LineService extends IService<Line> {
List<String> getLevelMonitorByDept(@RequestParam("level") String level, @RequestParam("deptId")String deptId); List<String> getLevelMonitorByDept(@RequestParam("level") String level, @RequestParam("deptId")String deptId);
/**
* 获取污区值监测点相关信息
* @author hongawen
*/
List<PollutionLineInfoDTO> getPollutionLineInfo(List<String> id);
} }

View File

@@ -19,6 +19,7 @@ import com.njcn.common.utils.PubUtils;
import com.njcn.device.biz.enums.DeviceResponseEnum; import com.njcn.device.biz.enums.DeviceResponseEnum;
import com.njcn.device.biz.pojo.dto.LineALLInfoDTO; import com.njcn.device.biz.pojo.dto.LineALLInfoDTO;
import com.njcn.device.biz.pojo.dto.LineDTO; 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.biz.pojo.po.Overlimit;
import com.njcn.device.pq.enums.LineBaseEnum; import com.njcn.device.pq.enums.LineBaseEnum;
import com.njcn.device.pq.mapper.*; import com.njcn.device.pq.mapper.*;
@@ -738,6 +739,39 @@ public class LineServiceImpl extends ServiceImpl<LineMapper, Line> implements Li
return result; return result;
} }
@Override
public List<PollutionLineInfoDTO> getPollutionLineInfo(List<String> lineId) {
List<PollutionLineInfoDTO> pollutionLineInfoDTOList;
// 获取终端信息
pollutionLineInfoDTOList = deviceMapper.getPollutionDeviceInfo(lineId);
List<DictData> manufacturerList = dicDataFeignClient.getDicDataByTypeCode(DicDataTypeEnum.DEV_MANUFACTURER.getCode()).getData();
List<DictData> devTypeList = dicDataFeignClient.getDicDataByTypeCode(DicDataTypeEnum.DEV_TYPE.getCode()).getData();
List<DictData> businessTypeList = dicDataFeignClient.getDicDataByTypeCode(DicDataTypeEnum.BUSINESS_TYPE.getCode()).getData();
List<DictData> loadTypeList = dicDataFeignClient.getDicDataByTypeCode(DicDataTypeEnum.INTERFERENCE_SOURCE_TYPE.getCode()).getData();
List<DictData> voltageList = dicDataFeignClient.getDicDataByTypeCode(DicDataTypeEnum.DEV_VOLTAGE_STAND.getCode()).getData();
for (PollutionLineInfoDTO pollutionLineInfoDTO : pollutionLineInfoDTOList) {
// 制造厂商
Optional<DictData> temp = manufacturerList.stream().filter(item -> item.getId().equals(pollutionLineInfoDTO.getManufacturer())).findAny();
pollutionLineInfoDTO.setManufacturer(temp.map(DictData::getName).orElse(null));
// 终端类型
Optional<DictData> temp1 = devTypeList.stream().filter(item -> item.getId().equals(pollutionLineInfoDTO.getDevType())).findAny();
pollutionLineInfoDTO.setDevType(temp1.map(DictData::getName).orElse(null));
// 行业类型
Optional<DictData> temp2 = businessTypeList.stream().filter(item -> item.getId().equals(pollutionLineInfoDTO.getBusinessType())).findAny();
pollutionLineInfoDTO.setBusinessType(temp2.map(DictData::getName).orElse(null));
// 干扰源类型
Optional<DictData> temp3 = loadTypeList.stream().filter(item -> item.getId().equals(pollutionLineInfoDTO.getLoadType())).findAny();
pollutionLineInfoDTO.setLoadType(temp3.map(DictData::getName).orElse(null));
// 电压等级
Optional<DictData> 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 @Override
public List<Overlimit> getOverLimitByList(PollutionParamDTO pollutionParamDTO) { public List<Overlimit> getOverLimitByList(PollutionParamDTO pollutionParamDTO) {
return overlimitMapper.selectBatchIds(pollutionParamDTO.getLineList()); return overlimitMapper.selectBatchIds(pollutionParamDTO.getLineList());

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -74,7 +74,6 @@ public interface InfluxdbPOConverter {
@Mapping(source = "v48", target = "harmonicVoltageContent48Max" ,numberFormat = "#.000") @Mapping(source = "v48", target = "harmonicVoltageContent48Max" ,numberFormat = "#.000")
@Mapping(source = "v49", target = "harmonicVoltageContent49Max" ,numberFormat = "#.000") @Mapping(source = "v49", target = "harmonicVoltageContent49Max" ,numberFormat = "#.000")
@Mapping(source = "v50", target = "harmonicVoltageContent50Max" ,numberFormat = "#.000") @Mapping(source = "v50", target = "harmonicVoltageContent50Max" ,numberFormat = "#.000")
public RMpHarmonicVRateReportD dataVPOTORMpHarmonicPReportDPOMax(DataHarmRateV dataVPO); public RMpHarmonicVRateReportD dataVPOTORMpHarmonicPReportDPOMax(DataHarmRateV dataVPO);
@Mapping(source = "v1", target = "fundamentalVoltageMin",numberFormat = "#.000") @Mapping(source = "v1", target = "fundamentalVoltageMin",numberFormat = "#.000")

View File

@@ -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;
/**
* <p>
* Mapper 接口
* </p>
*
* @author xuyang
* @since 2024-01-25
*/
public interface EventMapper {
List<EventCount> getEventCount(@Param("startTime") DateTime startTime, @Param("endTime")DateTime endTime);
List<IntegrityVO> getIntegrity(@Param("startTime") DateTime startTime, @Param("endTime")DateTime endTime);
List<IntegrityVO> getOnlineRate(@Param("startTime") DateTime startTime, @Param("endTime")DateTime endTime);
}

View File

@@ -0,0 +1,43 @@
<?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.prepare.harmonic.mapper.mysql.EventMapper">
<select id="getEventCount" resultType="com.njcn.event.pojo.dto.EventCount">
SELECT
measurement_point_id lineId,
SUM(CASE WHEN feature_amplitude &gt;= 0 AND feature_amplitude &lt; 0.1 THEN 1 ELSE 0 END) AS breakCounts,
SUM(CASE WHEN feature_amplitude &gt;= 0.1 AND feature_amplitude &lt; 0.9 THEN 1 ELSE 0 END) AS downCounts,
SUM(CASE WHEN feature_amplitude &gt;= 1.1 THEN 1 ELSE 0 END) AS upCounts
FROM
r_mp_event_detail
where start_time between #{startTime} and #{endTime}
GROUP BY measurement_point_id
</select>
<select id="getIntegrity" resultType="com.njcn.harmonic.pojo.vo.IntegrityVO">
SELECT
line_index id,
LEAST(ROUND(SUM(real_time) / SUM(due_time), 2) * 100,100) integrityData
FROM
`r_stat_integrity_d`
WHERE time_id between #{startTime} and #{endTime}
GROUP BY line_index
</select>
<select id="getOnlineRate" resultType="com.njcn.harmonic.pojo.vo.IntegrityVO">
SELECT
dev_index id,
LEAST(
ROUND(
SUM(online_min) / (SUM(online_min) + SUM(offline_min)),
2
) * 100,
100
) integrityData
FROM
`r_stat_onlinerate_d`
WHERE time_id between #{startTime} and #{endTime}
GROUP BY dev_index
</select>
</mapper>

View File

@@ -0,0 +1,6 @@
package com.njcn.prepare.harmonic.service.influxdb;
public interface IPollutionCalc {
void calcAllLineValue();
}

View File

@@ -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<String> lineIdList = commTerminalGeneralClient.getRunMonitorIds().getData();
// List<String> 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<EventCount> eventCounts = getEventCount(lineIdList, startDate, yesterdayDate);
Map<String, EventCount> eventMap = eventCounts.stream().collect(Collectors.toMap(EventCount::getLineId, pojo -> pojo));
// 获取所有监测点的元信息
List<PollutionLineInfoDTO> 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<IntegrityVO> integrityList = getIntegrity(startDate, yesterdayDate);
Map<String, IntegrityVO> integrityMap = integrityList.stream().collect(Collectors.toMap(IntegrityVO::getId, pojo -> pojo));
//获取装置在线率
List<IntegrityVO> onlineRateList = getOnlineRate(startDate, yesterdayDate);
Map<String, IntegrityVO> onlineRateMap = onlineRateList.stream().collect(Collectors.toMap(IntegrityVO::getId, pojo -> pojo));
List<LinePollution> 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<PollutionLineInfoDTO> 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<LinePollution> 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<LinePollution> loadTypeLineList = new ArrayList<>(linePollutionList);
/**
* 1、首先过滤重要变电站、一类变电站、跨省计量关点 todo...待优化
* 2、过滤后以监测对象分组统计数据有多个测点的需要出结果
*/
List<String> loadTypeSubStation = Stream.of("重要变电站", "一类变电站", "跨省计量关点").collect(Collectors.toList());
loadTypeLineList = loadTypeLineList.stream().filter(item -> !loadTypeSubStation.contains(item.getLoadType())).collect(Collectors.toList());
// 监测对象分组
Map<String, List<LinePollution>> loadTypeMap = loadTypeLineList.stream().collect(Collectors.groupingBy(LinePollution::getObjName));
List<ObjPollution> objPollutions = new ArrayList<>();
Set<String> objNameSet = loadTypeMap.keySet();
for (String objName : objNameSet) {
ObjPollution objPollution = new ObjPollution();
List<LinePollution> 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<LoadTypeLineItemPollution> 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<GdPollution> gdPollutionList = new ArrayList<>();
// 以供电公司分组
Map<String, List<LinePollution>> gdMap = linePollutionList.stream()
.collect(Collectors.groupingBy(LinePollution::getGdName));
// 同一供电公司以变电站分组
Set<String> gdNameSet = gdMap.keySet();
for (String gdName : gdNameSet) {
// 初始化gd实体
GdPollution gdPollution = new GdPollution();
gdPollution.setGdName(gdName);
List<LinePollution> gdLinePollution = gdMap.get(gdName);
// 以变电站分组
Map<String, List<LinePollution>> subMap = gdLinePollution.stream()
.collect(Collectors.groupingBy(LinePollution::getSubStationName));
Set<String> subNameMap = subMap.keySet();
List<SubstationPollution> substationPollutions = new ArrayList<>();
for (String subName : subNameMap) {
// 初始化变电站实体
SubstationPollution substationPollution = new SubstationPollution();
substationPollution.setSubStationName(subName);
List<LinePollution> subLinePollution = subMap.get(subName);
// 需要区分电网侧、非电网侧
Map<String, List<LinePollution>> powerFlagLinePollution = subLinePollution.stream().collect(Collectors.groupingBy(LinePollution::getPowerFlag));
List<PowerFlagPollution> powerFlagPollutionList = new ArrayList<>();
// 电网侧
List<LinePollution> temp = powerFlagLinePollution.get("电网侧");
PowerFlagPollution powerFlagPollution1 = new PowerFlagPollution();
powerFlagPollution1.setPowerFlag("电网侧");
List<LineItemPollution> 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<LinePollution> temp1 = powerFlagLinePollution.get("非电网侧");
PowerFlagPollution powerFlagPollution2 = new PowerFlagPollution();
powerFlagPollution2.setPowerFlag("非电网侧");
List<LineItemPollution> 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<SubstationPollution> 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<DataV> vthResultList = dataVMapper.getStatisticsByWraper(dataVQueryWrapper);
// 计算时间范围内指标越限百分比
// 总畸变率的限值
List<Double> 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<DataHarmRateV> 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<DataHarmRateV> dataHarmRateVList) {
List<Double> pollutionValue = new ArrayList<>();
// 2次
for (int i = 2; i < 51; i++) {
Float limitValue = getValueByFieldName(overlimit, "uharm" + i);
int finalI = i;
List<Double> 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<Double> valueList) {
double pollutionValue = 0;
// 没有限值的直接返回
if (Objects.isNull(limit) || limit == 0.0f) {
return pollutionValue;
}
// 计算每个数值的越限百分比MOP
List<Double> 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<EventCount> getEventCount(List<String> ids, String startDate, String endDate) {
DateTime startTime = DateUtil.beginOfDay(DateUtil.parse(startDate));
DateTime endTime = DateUtil.endOfDay(DateUtil.parse(endDate));
List<EventCount> eventCounts = eventMapper.getEventCount(startTime, endTime);
Map<String, EventCount> eventMap = eventCounts.stream().collect(Collectors.toMap(EventCount::getLineId, pojo -> pojo));
List<EventCount> 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<IntegrityVO> 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<IntegrityVO> getOnlineRate(String startDate, String endDate) {
DateTime startTime = DateUtil.beginOfDay(DateUtil.parse(startDate));
DateTime endTime = DateUtil.endOfDay(DateUtil.parse(endDate));
return eventMapper.getOnlineRate(startTime, endTime);
}
}

View File

@@ -89,6 +89,7 @@ public class RStatDevSignalDPOServiceImpl extends MppServiceImpl<RStatDevSignalD
} else { } else {
rStatDevSignal.setRunStatus("0"); rStatDevSignal.setRunStatus("0");
} }
rStatDevSignal.setUpdateTime(calculatedParam.getDataDate());
rStatDevSignalList.add(rStatDevSignal); rStatDevSignalList.add(rStatDevSignal);
}); });
if (CollectionUtil.isNotEmpty(rStatDevSignalList)){ if (CollectionUtil.isNotEmpty(rStatDevSignalList)){