完成责任量化功能

This commit is contained in:
2023-07-26 11:20:12 +08:00
parent ae00d7671d
commit c3f8592160
104 changed files with 4709 additions and 1670 deletions

View File

@@ -5,6 +5,7 @@ import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.DependsOn;
/**
@@ -16,6 +17,7 @@ import org.springframework.cloud.openfeign.EnableFeignClients;
* @date 2021/12/27 11:38
*/
@Slf4j
@DependsOn("proxyMapperRegister")
@MapperScan("com.njcn.**.mapper")
@EnableFeignClients(basePackages = "com.njcn")
@SpringBootApplication(scanBasePackages = "com.njcn")

View File

@@ -8,12 +8,10 @@ import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.common.utils.LogUtil;
import com.njcn.device.pq.pojo.dto.PollutionLineDTO;
import com.njcn.harmonic.pojo.param.HarmonicPublicParam;
import com.njcn.harmonic.pojo.vo.*;
import com.njcn.harmonic.service.IAnalyzeService;
import com.njcn.harmonic.service.IHarmonicService;
import com.njcn.harmonic.service.IPollutionService;
import com.njcn.poi.util.PoiUtil;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
@@ -44,8 +42,6 @@ public class AnalyzeController extends BaseController {
private final IAnalyzeService IAnalyzeService;
private final IPollutionService pollutionService;
private final IHarmonicService harmonicService;

View File

@@ -6,11 +6,13 @@ import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.param.StatisticsBizBaseParam;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.harmonic.pojo.param.HistoryHarmParam;
import com.njcn.harmonic.pojo.param.HistoryParam;
import com.njcn.harmonic.pojo.param.NormHistoryParam;
import com.njcn.harmonic.pojo.vo.HistoryDataResultVO;
import com.njcn.harmonic.pojo.vo.StatHarmonicOrgVO;
import com.njcn.harmonic.service.HistoryResultService;
import com.njcn.influx.pojo.dto.HarmHistoryDataDTO;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
@@ -70,4 +72,14 @@ public class HistoryResultController extends BaseController {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/getHistoryHarmData")
@ApiOperation("获取谐波历史数据")
@ApiImplicitParam(name = "historyHarmParam", value = "谐波历史数据请求参数", required = true)
public HttpResult<HarmHistoryDataDTO> getHistoryHarmData(@RequestBody @Validated HistoryHarmParam historyHarmParam) {
String methodDescribe = getMethodDescribe("getHistoryHarmData");
HarmHistoryDataDTO harmHistoryDataDTO = historyResultService.getHistoryHarmData(historyHarmParam);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, harmHistoryDataDTO, methodDescribe);
}
}

View File

@@ -12,7 +12,6 @@ import com.njcn.harmonic.pojo.param.HarmonicPublicParam;
import com.njcn.harmonic.pojo.param.PollutionSubstationQuryParam;
import com.njcn.harmonic.pojo.vo.PollutionSubstationVO;
import com.njcn.harmonic.pojo.vo.PollutionVO;
import com.njcn.harmonic.service.IPollutionService;
import com.njcn.harmonic.service.PollutionSubstationService;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
@@ -46,8 +45,6 @@ public class PollutionSubstationController extends BaseController {
private final PollutionSubstationService pollutionSubstationService;
private final IPollutionService pollutionService;
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/getPollutionSubstationData")

View File

@@ -0,0 +1,26 @@
package com.njcn.harmonic.pojo;
import com.njcn.influx.pojo.bo.HarmonicHistoryData;
import lombok.Data;
import org.influxdb.dto.QueryResult;
import java.io.Serializable;
import java.util.List;
/**
* @author denghuajun
* @date 2022/3/15
* 存值
*/
@Data
public class QueryResultLimitVO implements Serializable {
private QueryResult queryResult;
private List<HarmonicHistoryData> harmonicHistoryDataList;
private Float topLimit;
private Float lowerLimit;
private String lineName;
private String targetName;
private List<String> phaiscType;
private List<String> unit;
private Integer harmNum;
}

View File

@@ -1,10 +1,12 @@
package com.njcn.harmonic.service;
import com.njcn.common.pojo.param.StatisticsBizBaseParam;
import com.njcn.harmonic.pojo.param.HistoryHarmParam;
import com.njcn.harmonic.pojo.param.HistoryParam;
import com.njcn.harmonic.pojo.param.NormHistoryParam;
import com.njcn.harmonic.pojo.vo.HistoryDataResultVO;
import com.njcn.harmonic.pojo.vo.StatHarmonicOrgVO;
import com.njcn.influx.pojo.dto.HarmHistoryDataDTO;
import java.util.List;
@@ -36,4 +38,13 @@ public interface HistoryResultService {
* @return 结果
*/
List<StatHarmonicOrgVO> getHarmonicProportion(StatisticsBizBaseParam statisticsBizBaseParam);
/***
* 按次、监测点获取指定历史谐波数据
* @author hongawen
* @date 2023/7/19 9:56
* @param historyHarmParam 请求历史谐波数据参数
* @return HarmHistoryDataDTO
*/
HarmHistoryDataDTO getHistoryHarmData(HistoryHarmParam historyHarmParam);
}

View File

@@ -1,53 +0,0 @@
package com.njcn.harmonic.service;
import com.njcn.device.pq.pojo.dto.PollutionLineDTO;
import com.njcn.device.pq.pojo.dto.PollutionSubstationDTO;
import com.njcn.harmonic.pojo.param.HarmonicPublicParam;
import com.njcn.harmonic.pojo.vo.PollutionVO;
import java.util.List;
/**
* @author 徐扬
*/
public interface IPollutionService {
/**
* 功能描述: 获取部门变电站关系
*
* @param param
* @return java.util.List<java.lang.Object>
* @author xy
* @date 2022/2/21 16:48
*/
// List<PollutionVO> getDeptSubstationRelations(HarmonicPublicParam param);
/**
* 功能描述: 根据部门获取变电站详情
*
* @param param 部门参数
* @return java.util.List<com.njcn.harmonic.pojo.vo.PollutionVO>
* @author xy
* @date 2022/2/21 20:51
*/
//List<PollutionSubstationDTO> getSubstationInfoById(HarmonicPublicParam param);
/**
* 功能描述: 根据变电站获取监测点详情
* @param param
* @return java.util.List<com.njcn.harmonic.pojo.vo.PollutionVO>
* @author xy
* @date 2022/2/21 20:51
*/
// List<PollutionLineDTO> getLineInfoById(HarmonicPublicParam param);
/**
* 功能描述:获取排名前10的监测点
* @param param
*
* @return java.util.List<com.njcn.harmonic.pojo.vo.LoadTypeVO>
* @author xy
* @date 2022/2/22 10:04
*/
// List<PollutionLineDTO> getLineRank(HarmonicPublicParam param);
}

View File

@@ -56,15 +56,6 @@ public interface PollutionSubstationService extends IService<RStatPollutionSubst
*/
List<PollutionLineDTO> getLineInfoById(HarmonicPublicParam param);
/***
* 获取前十监测点排名
* @author wr
* @date 2023-03-03 16:21
* @param param
* @return List<PollutionLineDTO>
*/
List<PollutionLineDTO> getLineRank(HarmonicPublicParam param);
List<PollutionLineDTO> getLineRankTop10(HarmonicPublicParam param);

View File

@@ -36,7 +36,6 @@ import com.njcn.harmonic.pojo.vo.OverAreaLimitVO;
import com.njcn.harmonic.pojo.vo.OverAreaVO;
import com.njcn.harmonic.pojo.vo.WarningSubstationVO;
import com.njcn.harmonic.service.IAnalyzeService;
import com.njcn.influxdb.utils.InfluxDbUtils;
import com.njcn.poi.excel.ExcelUtil;
import com.njcn.system.api.DicDataFeignClient;
import com.njcn.system.enums.DicDataEnum;
@@ -76,8 +75,6 @@ public class AnalyzeServiceImpl implements IAnalyzeService {
private final HarmonicServiceImpl harmonicService;
private final InfluxDbUtils influxDbUtils;
private final LineFeignClient lineFeignClient;
private final RStatLimitRateDMapper rateDMapper;
@@ -371,147 +368,6 @@ public class AnalyzeServiceImpl implements IAnalyzeService {
return page;
}
return page;
// if (!CollectionUtils.isEmpty(lineList)){
// page.setTotal(lineList.size());
// int pages = (int)Math.ceil(lineList.size()*1.0/param.getPageSize());
// page.setPages(pages);
// List<List<String>> pageList = Lists.partition(lineList,param.getPageSize());
// List<String> temList = pageList.get(param.getPageNum()-1);
// List<LimitTarget> limitTargetList = getOverDays(temList,param.getSearchBeginTime(),param.getSearchEndTime());
// Map<String,List<LimitTarget>> map = limitTargetList.stream().collect(Collectors.groupingBy(LimitTarget::getLineId));
// PollutionParamDTO pollutionParamDTO = new PollutionParamDTO();
// pollutionParamDTO.setLineList(temList);
// List<OverLimitLineDTO> overLimitLineList = lineFeignClient.getOverLimitLineInfo(pollutionParamDTO).getData();
// overLimitLineList.forEach(item->{
// int overDay=0,freqOverDay=0,volDevOverDay=0,threeUnbalance=0,flickerOverDay=0,negativeOverDay=0,harmVolOverDay=0,volDisOverDay=0,volContainOverDay=0,harmCurOverDay=0,intHarmOverDay=0;
// int overVolThreeTimes=0,overVolFiveTimes=0,overVolSevenTimes=0,overVolElevenTimes=0,overVolThirteenTimes=0,overVolTwentyThreeTimes=0,overVolTwentyFiveTimes=0,overVolOtherTimes=0;
// int overCurThreeTimes=0,overCurFiveTimes=0,overCurSevenTimes=0,overCurElevenTimes=0,overCurThirteenTimes=0,overCurTwentyThreeTimes=0,overCurTwentyFiveTimes=0,overCurOtherTimes=0;
// MonitorOverLimitVO monitorOverLimitVO = new MonitorOverLimitVO();
// BeanUtil.copyProperties(item,monitorOverLimitVO);
// List<LimitTarget> l1 = map.get(item.getId());
// if (!CollectionUtils.isEmpty(l1)) {
// for (LimitTarget item2 : l1) {
// if (item2.getFreqDevOverTime()+item2.getVoltageDevOverTime()+item2.getUBalanceOverTime()+item2.getFlickerOverTime()+item2.getINegOverTime()+item2.getUAberranceOverTime()+item2.getUHarmAllOverTime()+item2.getIHarmAllOverTime()+item2.getInuharmAllOverTime() > 0){
// overDay++;
// }
// if (item2.getFreqDevOverTime()>0){
// freqOverDay++;
// }
// if (item2.getVoltageDevOverTime()>0){
// volDevOverDay++;
// }
// if (item2.getUBalanceOverTime()>0){
// threeUnbalance++;
// }
// if (item2.getFlickerOverTime()>0){
// flickerOverDay++;
// }
// if (item2.getINegOverTime()>0){
// negativeOverDay++;
// }
// if (item2.getUAberranceOverTime()+item2.getUHarmAllOverTime()>0){
// harmVolOverDay++;
// }
// if (item2.getUAberranceOverTime()>0){
// volDisOverDay++;
// }
// if (item2.getUHarmAllOverTime()>0){
// volContainOverDay++;
// }
// if (item2.getIHarmAllOverTime()>0){
// harmCurOverDay++;
// }
// if (item2.getInuharmAllOverTime()>0){
// intHarmOverDay++;
// }
// if (item2.getUHarm3OverTime()>0){
// overVolThreeTimes++;
// }
// if (item2.getUHarm5OverTime()>0){
// overVolFiveTimes++;
// }
// if (item2.getUHarm7OverTime()>0){
// overVolSevenTimes++;
// }
// if (item2.getUHarm11OverTime()>0){
// overVolElevenTimes++;
// }
// if (item2.getUHarm13OverTime()>0){
// overVolThirteenTimes++;
// }
// if (item2.getUHarm23OverTime()>0){
// overVolTwentyThreeTimes++;
// }
// if (item2.getUHarm25OverTime()>0){
// overVolTwentyFiveTimes++;
// }
// if (item2.getUHarmAllOverTime()>0){
// overVolOtherTimes++;
// }
// if (item2.getIHarm3OverTime()>0){
// overCurThreeTimes++;
// }
// if (item2.getIHarm5OverTime()>0){
// overCurFiveTimes++;
// }
// if (item2.getIHarm7OverTime()>0){
// overCurSevenTimes++;
// }
// if (item2.getIHarm11OverTime()>0){
// overCurElevenTimes++;
// }
// if (item2.getIHarm13OverTime()>0){
// overCurThirteenTimes++;
// }
// if (item2.getIHarm23OverTime()>0){
// overCurTwentyThreeTimes++;
// }
// if (item2.getIHarm25OverTime()>0){
// overCurTwentyFiveTimes++;
// }
// if (item2.getIHarmAllOverTime()>0){
// overCurOtherTimes++;
// }
// }
// }
// monitorOverLimitVO.setOverDay(overDay);
// monitorOverLimitVO.setFreqOverDay(freqOverDay);
// monitorOverLimitVO.setVolDevOverDay(volDevOverDay);
// monitorOverLimitVO.setThreeUnbalance(threeUnbalance);
// monitorOverLimitVO.setFlickerOverDay(flickerOverDay);
// monitorOverLimitVO.setNegativeOverDay(negativeOverDay);
// monitorOverLimitVO.setHarmVolOverDay(harmVolOverDay);
// monitorOverLimitVO.setVolDisOverDay(volDisOverDay);
// monitorOverLimitVO.setVolContainOverDay(volContainOverDay);
// monitorOverLimitVO.setHarmCurOverDay(harmCurOverDay);
// monitorOverLimitVO.setIntHarmOverDay(intHarmOverDay);
// monitorOverLimitVO.setOverVolThreeTimes(overVolThreeTimes);
// monitorOverLimitVO.setOverVolFiveTimes(overVolFiveTimes);
// monitorOverLimitVO.setOverVolSevenTimes(overVolSevenTimes);
// monitorOverLimitVO.setOverVolElevenTimes(overVolElevenTimes);
// monitorOverLimitVO.setOverVolThirteenTimes(overVolThirteenTimes);
// monitorOverLimitVO.setOverVolTwentyThreeTimes(overVolTwentyThreeTimes);
// monitorOverLimitVO.setOverVolTwentyFiveTimes(overVolTwentyFiveTimes);
// monitorOverLimitVO.setOverVolOtherTimes(overVolOtherTimes);
// monitorOverLimitVO.setOverCurThreeTimes(overCurThreeTimes);
// monitorOverLimitVO.setOverCurFiveTimes(overCurFiveTimes);
// monitorOverLimitVO.setOverCurSevenTimes(overCurSevenTimes);
// monitorOverLimitVO.setOverCurElevenTimes(overCurElevenTimes);
// monitorOverLimitVO.setOverCurThirteenTimes(overCurThirteenTimes);
// monitorOverLimitVO.setOverCurTwentyThreeTimes(overCurTwentyThreeTimes);
// monitorOverLimitVO.setOverCurTwentyFiveTimes(overCurTwentyFiveTimes);
// monitorOverLimitVO.setOverCurOtherTimes(overCurOtherTimes);
// result.add(monitorOverLimitVO);
// });
// }
// if (!CollectionUtils.isEmpty(result)){
// List<MonitorOverLimitVO> recordList = new ArrayList<>();
// //默认 根据在线监测点个数 倒叙排序
// recordList = result.stream().sorted(Comparator.comparing(MonitorOverLimitVO::getOverDay).reversed()).collect(Collectors.toList());
// page.setRecords(recordList);
// return page;
// }
// return page;
}
private boolean filterNotQualifiedHarmVolData(RStatLimitTargetDPO t) {
@@ -781,64 +637,4 @@ public class AnalyzeServiceImpl implements IAnalyzeService {
condMap.put(DicDataEnum.VOLTAGE_RISE.getCode(), dictMap.get(DicDataEnum.VOLTAGE_RISE.getCode())); //电压暂升
return eventDetailFeignClient.getEventDetailCount(condMap).getData();
}
public List<LimitTarget> getOverDays(List<String> list, String startTime, String endTime) {
StringBuilder stringBuilder = new StringBuilder();
StringBuilder stringBuilder1 = new StringBuilder();
stringBuilder.append(Param.TIME + " >= '").append(startTime).append("' and ").append(Param.TIME).append(" <= '").append(endTime).append("' and (");
for (int i = 0; i < list.size(); i++) {
if (list.size() - i != 1) {
stringBuilder.append(Param.LINE_ID + "='").append(list.get(i)).append("' or ");
} else {
stringBuilder.append(Param.LINE_ID + "='").append(list.get(i)).append("')");
}
}
stringBuilder.append(" group by line_id tz('Asia/Shanghai')");
stringBuilder1.append("freq_dev_overtime AS freq_dev_overtime,voltage_dev_overtime AS voltage_dev_overtime,ubalance_overtime AS ubalance_overtime,flicker_overtime AS flicker_overtime,i_neg_overtime AS i_neg_overtime,uaberrance_overtime AS uaberrance_overtime,");
for (int i = 2; i <= 25; i++) {
if (i == 25) {
stringBuilder1.append("uharm_").append(i).append("_overtime AS uharm_all_overtime,");
} else {
stringBuilder1.append("uharm_").append(i).append("_overtime+");
}
}
for (int i = 2; i <= 25; i++) {
if (i == 25) {
stringBuilder1.append("iharm_").append(i).append("_overtime AS iharm_all_overtime,");
} else {
stringBuilder1.append("iharm_").append(i).append("_overtime+");
}
}
for (int i = 1; i <= 16; i++) {
if (i == 16) {
stringBuilder1.append("inuharm_").append(i).append("_overtime AS inuharm_all_overtime,");
} else {
stringBuilder1.append("inuharm_").append(i).append("_overtime+");
}
}
stringBuilder1.append("uharm_3_overtime,uharm_5_overtime,uharm_7_overtime,uharm_11_overtime,uharm_13_overtime,uharm_23_overtime,uharm_25_overtime,");
for (int i = 2; i <= 25; i++) {
if (i != 3 && i != 5 && i != 7 && i != 11 && i != 13 && i != 23 && i != 25) {
if (i == 24) {
stringBuilder1.append("uharm_").append(i).append("_overtime AS uOtherTimes,");
} else {
stringBuilder1.append("uharm_").append(i).append("_overtime+");
}
}
}
stringBuilder1.append("iharm_3_overtime,iharm_5_overtime,iharm_7_overtime,iharm_11_overtime,iharm_13_overtime,iharm_23_overtime,iharm_25_overtime,");
for (int i = 2; i <= 25; i++) {
if (i != 3 && i != 5 && i != 7 && i != 11 && i != 13 && i != 23 && i != 25) {
if (i == 24) {
stringBuilder1.append("iharm_").append(i).append("_overtime AS iOtherTimes");
} else {
stringBuilder1.append("iharm_").append(i).append("_overtime+");
}
}
}
String sql = "select " + stringBuilder1 + " from limit_target where " + stringBuilder;
QueryResult sqlResult = influxDbUtils.query(sql);
InfluxDBResultMapper resultMapper = new InfluxDBResultMapper();
return resultMapper.toPOJO(sqlResult, LimitTarget.class);
}
}

View File

@@ -7,15 +7,10 @@ import com.njcn.harmonic.mapper.RStatComassesDMapper;
import com.njcn.harmonic.pojo.po.PQSComAssesPO;
import com.njcn.harmonic.pojo.vo.AssesVO;
import com.njcn.harmonic.service.AssesService;
import com.njcn.harmonic.service.ComAssessService;
import com.njcn.influxdb.param.InfluxDBPublicParam;
import com.njcn.influxdb.utils.InfluxDbUtils;
import com.njcn.web.utils.ComAssesUtil;
import com.njcn.web.utils.PqsComasses;
import lombok.AllArgsConstructor;
import org.apache.commons.lang.StringUtils;
import org.influxdb.dto.QueryResult;
import org.influxdb.impl.InfluxDBResultMapper;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
@@ -32,7 +27,6 @@ import java.util.List;
@AllArgsConstructor
public class AssesServiceImpl implements AssesService {
private final InfluxDbUtils influxDbUtils;
private final ComAssesUtil comAssesUtil;
@@ -51,12 +45,9 @@ public class AssesServiceImpl implements AssesService {
}
/**
* influxDB相关操作
* 查询监测点的数据完整性
*/
private Float getCondition(String lineList, String startTime, String endTime) {
float synData;
if (!lineList.isEmpty()) {
List<PQSComAssesPO> avgCount = rStatComassesDMapper.getAvgCount(Arrays.asList(lineList),

View File

@@ -3,7 +3,6 @@ package com.njcn.harmonic.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.text.StrPool;
import cn.hutool.core.util.CharsetUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.*;
@@ -20,6 +19,10 @@ import com.njcn.harmonic.mapper.ExcelRptTempMapper;
import com.njcn.harmonic.pojo.dto.ReportTemplateDTO;
import com.njcn.harmonic.pojo.param.ReportSearchParam;
import com.njcn.harmonic.pojo.param.ReportTemplateParam;
import com.njcn.influx.constant.InfluxDbSqlConstant;
import com.njcn.influx.pojo.constant.InfluxDBTableConstant;
import com.njcn.influx.pojo.dto.StatisticalDataDTO;
import com.njcn.influx.service.CommonService;
import com.njcn.system.pojo.po.EleEpdPqd;
import com.njcn.harmonic.pojo.po.ExcelRpt;
import com.njcn.harmonic.pojo.po.ExcelRptTemp;
@@ -28,34 +31,22 @@ import com.njcn.harmonic.pojo.vo.ReportTemplateVO;
import com.njcn.harmonic.pojo.vo.ReportTreeVO;
import com.njcn.harmonic.pojo.vo.SysDeptTempVO;
import com.njcn.harmonic.service.CustomReportService;
import com.njcn.influxdb.param.InfluxDBSqlConstant;
import com.njcn.influxdb.param.InfluxDBTableConstant;
import com.njcn.influxdb.utils.InfluxDbUtils;
import com.njcn.oss.constant.OssPath;
import com.njcn.oss.enums.OssResponseEnum;
import com.njcn.oss.utils.FileStorageUtil;
import com.njcn.system.api.DicDataFeignClient;
import com.njcn.user.api.DeptFeignClient;
import com.njcn.user.pojo.dto.DeptDTO;
import com.njcn.web.utils.WebUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.tomcat.util.http.fileupload.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.influxdb.dto.QueryResult;
import org.springframework.beans.BeanUtils;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
@@ -83,16 +74,12 @@ public class CustomReportServiceImpl implements CustomReportService {
private final EleEpdMapper eleEpdMapper;
private final InfluxDbUtils influxDbUtils;
private final DicDataFeignClient dicDataFeignClient;
private final DeptTempMapper deptTempMapper;
private final GeneralInfo generalInfo;
private final FileStorageUtil fileStorageUtil;
private final CommonService commonService;
@Override
public boolean addCustomReportTemplate(ReportTemplateParam reportTemplateParam) {
@@ -406,7 +393,6 @@ public class CustomReportServiceImpl implements CustomReportService {
reportTemplateDTO.setStatMethod(vItem[1].toUpperCase());
reportTemplateDTO.setClassId(vItem[2]);
}
reportTemplateDTOList.add(reportTemplateDTO);
}
}
@@ -421,15 +407,15 @@ public class CustomReportServiceImpl implements CustomReportService {
if (CollUtil.isNotEmpty(reportTemplateDTOList)) {
//开始组织sql
reportTemplateDTOList.stream().forEach(data -> {
StringBuilder sql = new StringBuilder(InfluxDBSqlConstant.SELECT);
if (InfluxDBTableConstant.MAX.equalsIgnoreCase(data.getStatMethod())) {
assSql(data, sql, endList, InfluxDBSqlConstant.MAX, reportSearchParam);
} else if (InfluxDBTableConstant.MIN.equalsIgnoreCase(data.getStatMethod())) {
assSql(data, sql, endList, InfluxDBSqlConstant.MIN, reportSearchParam);
} else if (InfluxDBTableConstant.AVG.equalsIgnoreCase(data.getStatMethod())) {
assSql(data, sql, endList, InfluxDBSqlConstant.AVG, reportSearchParam);
} else if (InfluxDBTableConstant.CP95.equalsIgnoreCase(data.getStatMethod())) {
assSql(data, sql, endList, InfluxDBSqlConstant.CP95, reportSearchParam);
StringBuilder sql = new StringBuilder(InfluxDbSqlConstant.SELECT);
if (InfluxDbSqlConstant.MAX.equalsIgnoreCase(data.getStatMethod())) {
assSql(data, sql, endList, InfluxDbSqlConstant.MAX, reportSearchParam);
} else if (InfluxDbSqlConstant.MIN.equalsIgnoreCase(data.getStatMethod())) {
assSql(data, sql, endList, InfluxDbSqlConstant.MIN, reportSearchParam);
} else if (InfluxDbSqlConstant.AVG.equalsIgnoreCase(data.getStatMethod())) {
assSql(data, sql, endList, InfluxDbSqlConstant.AVG, reportSearchParam);
} else if (InfluxDbSqlConstant.CP95.equalsIgnoreCase(data.getStatMethod())) {
assSql(data, sql, endList, InfluxDbSqlConstant.CP95, reportSearchParam);
}
});
}
@@ -492,93 +478,68 @@ public class CustomReportServiceImpl implements CustomReportService {
//sql拼接示例select MAX(IHA2) as IHA2 from power_quality_data where Phase = 'A' and LineId='1324564568' and Stat_Method='max' tz('Asia/Shanghai')
//cp95函数特殊处理 PERCENTILE(field_key, N)
if (InfluxDBSqlConstant.CP95.equals(method)) {
if (InfluxDbSqlConstant.CP95.equals(method)) {
sql.append(method)
.append(InfluxDBSqlConstant.LBK)
.append(InfluxDbSqlConstant.LBK)
.append(data.getTemplateName())
.append(InfluxDBSqlConstant.NUM_95)
.append(InfluxDBSqlConstant.RBK)
.append(InfluxDBSqlConstant.AS_VALUE);
.append(InfluxDbSqlConstant.NUM_95)
.append(InfluxDbSqlConstant.RBK)
.append(InfluxDbSqlConstant.AS_VALUE);
} else {
sql.append(method)
.append(InfluxDBSqlConstant.LBK)
.append(InfluxDbSqlConstant.LBK)
.append(data.getTemplateName())
.append(InfluxDBSqlConstant.RBK)
.append(InfluxDBSqlConstant.AS_VALUE);
.append(InfluxDbSqlConstant.RBK)
.append(InfluxDbSqlConstant.AS_VALUE);
}
sql.append(InfluxDBSqlConstant.FROM)
sql.append(InfluxDbSqlConstant.FROM)
.append(data.getClassId())
.append(InfluxDBSqlConstant.WHERE)
.append(InfluxDbSqlConstant.WHERE)
.append(InfluxDBTableConstant.LINE_ID)
.append(InfluxDBSqlConstant.EQ)
.append(InfluxDBSqlConstant.QM)
.append(InfluxDbSqlConstant.EQ)
.append(InfluxDbSqlConstant.QM)
.append(reportSearchParam.getLineId())
.append(InfluxDBSqlConstant.QM);
.append(InfluxDbSqlConstant.QM);
//相别特殊处理
if (!InfluxDBTableConstant.NO_PHASE.equals(data.getPhase())) {
sql.append(InfluxDBSqlConstant.AND)
sql.append(InfluxDbSqlConstant.AND)
.append(InfluxDBTableConstant.PHASIC_TYPE)
.append(InfluxDBSqlConstant.EQ)
.append(InfluxDBSqlConstant.QM)
.append(InfluxDbSqlConstant.EQ)
.append(InfluxDbSqlConstant.QM)
.append(data.getPhase())
.append(InfluxDBSqlConstant.QM);
.append(InfluxDbSqlConstant.QM);
}
//data_flicker、data_fluc、data_plt 无 value_type
if (!InfluxDBTableConstant.DATA_FLICKER.equals(data.getClassId()) && !InfluxDBTableConstant.DATA_FLUC.equals(data.getClassId()) && !InfluxDBTableConstant.DATA_PLT.equals(data.getClassId())) {
sql.append(InfluxDBSqlConstant.AND)
sql.append(InfluxDbSqlConstant.AND)
.append(InfluxDBTableConstant.VALUE_TYPE)
.append(InfluxDBSqlConstant.EQ)
.append(InfluxDBSqlConstant.QM)
.append(InfluxDbSqlConstant.EQ)
.append(InfluxDbSqlConstant.QM)
.append(data.getStatMethod())
.append(InfluxDBSqlConstant.QM);
.append(InfluxDbSqlConstant.QM);
}
//频率和频率偏差仅统计T相
if(data.getTemplateName().equals("freq_dev") || data.getTemplateName().equals("freq")){
sql.append(InfluxDBSqlConstant.AND)
sql.append(InfluxDbSqlConstant.AND)
.append(InfluxDBTableConstant.PHASIC_TYPE)
.append(InfluxDBSqlConstant.EQ)
.append(InfluxDbSqlConstant.EQ)
.append(InfluxDBTableConstant.PHASE_TYPE_T);
}
//时间范围处理
sql
.append(InfluxDBSqlConstant.AND)
.append(InfluxDBSqlConstant.TIME).append(InfluxDBSqlConstant.GE).append(InfluxDBSqlConstant.QM).append(reportSearchParam.getStartTime()).append(InfluxDBSqlConstant.START_TIME).append(InfluxDBSqlConstant.QM)
.append(InfluxDBSqlConstant.AND)
.append(InfluxDBSqlConstant.TIME).append(InfluxDBSqlConstant.LT).append(InfluxDBSqlConstant.QM).append(reportSearchParam.getEndTime()).append(InfluxDBSqlConstant.END_TIME).append(InfluxDBSqlConstant.QM);
.append(InfluxDbSqlConstant.AND)
.append(InfluxDbSqlConstant.TIME).append(InfluxDbSqlConstant.GE).append(InfluxDbSqlConstant.QM).append(reportSearchParam.getStartTime()).append(InfluxDbSqlConstant.START_TIME).append(InfluxDbSqlConstant.QM)
.append(InfluxDbSqlConstant.AND)
.append(InfluxDbSqlConstant.TIME).append(InfluxDbSqlConstant.LT).append(InfluxDbSqlConstant.QM).append(reportSearchParam.getEndTime()).append(InfluxDbSqlConstant.END_TIME).append(InfluxDbSqlConstant.QM);
sql.append(InfluxDBSqlConstant.TZ);
if(data.getClassId().equals(InfluxDBTableConstant.DATA_PLT)){
System.out.println(sql);
}
sql.append(InfluxDbSqlConstant.TZ);
//根据不同的库表赋值
QueryResult queryResult = influxDbUtils.query(String.valueOf(sql));
//剖析influx数据填入value
List<QueryResult.Result> results = queryResult.getResults();
if (results.size() != 0) {
QueryResult.Result result = results.get(0);
if (result.getSeries() != null) {
List<QueryResult.Series> seriess = result.getSeries();
if (seriess.size() != 0) {
QueryResult.Series series = seriess.get(0);
List<String> columns = series.getColumns();
List<List<Object>> values = series.getValues();
for (List<Object> columnValue : values) {
for (int i = 0; i < columnValue.size(); i++) {
if (columns.get(i).equals("value")) {
data.setValue(String.format("%.3f", columnValue.get(i)));
}
}
}
}
}
}
StatisticalDataDTO statisticalDataDTO = commonService.selectBySql(sql);
data.setValue(String.format("%.3f",statisticalDataDTO.getValue()));
endList.add(data);
}

View File

@@ -1,5 +1,7 @@
package com.njcn.harmonic.service.impl;
import cn.hutool.core.util.StrUtil;
import com.njcn.common.utils.HarmonicTimesUtil;
import com.njcn.common.utils.PubUtils;
import com.njcn.device.pq.api.LineFeignClient;
import com.njcn.device.biz.pojo.po.Overlimit;
@@ -7,7 +9,12 @@ import com.njcn.harmonic.constant.Param;
import com.njcn.harmonic.pojo.param.HarmInHarmParam;
import com.njcn.harmonic.pojo.vo.HarmInHarmVO;
import com.njcn.harmonic.service.HarmInHarmService;
import com.njcn.influxdb.utils.InfluxDbUtils;
import com.njcn.influx.pojo.constant.InfluxDBTableConstant;
import com.njcn.influx.pojo.po.DataHarmRateV;
import com.njcn.influx.pojo.po.DataI;
import com.njcn.influx.query.InfluxQueryWrapper;
import com.njcn.influx.service.DataHarmRateVService;
import com.njcn.influx.service.IDataIService;
import lombok.AllArgsConstructor;
import org.influxdb.dto.QueryResult;
import org.springframework.stereotype.Service;
@@ -15,6 +22,7 @@ import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
/**
* 类的介绍
@@ -29,7 +37,10 @@ public class HarmInHarmServiceImpl implements HarmInHarmService {
private final LineFeignClient lineFeignClient;
private final InfluxDbUtils influxDbUtils;
private final DataHarmRateVService dataHarmRateVService;
private final IDataIService dataIService;
@Override
public HarmInHarmVO getHarmInHarmData(HarmInHarmParam harmInHarmParam) {
@@ -64,47 +75,35 @@ public class HarmInHarmServiceImpl implements HarmInHarmService {
*/
private List<Float> getCondition(String startTime, String endTime, String lineId, Integer harmState) {
List<Float> floatList = new ArrayList<>();
QueryResult queryResult;
if (!lineId.isEmpty()) {
//组装sql语句
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(Param.TIME + " >= '").append(startTime).append(Param.START_TIME).append("' and ").append(Param.TIME).append(" <= '").append(endTime).append(Param.END_TIME).append("' and (");
//sql语句
stringBuilder.append(Param.LINE_ID + "='").append(lineId).append("')");
stringBuilder.append(" and ").append(Param.VALUETYPE + "='").append("CP95").append("'");
String sql = "";
if (StrUtil.isNotBlank(lineId)) {
if (harmState == 0) {
sql = "SELECT MEAN(v_2) as V2, MEAN(v_3) as V3, MEAN(v_4) as V4, MEAN(v_5) as V5, MEAN(v_6) as V6, MEAN(v_7) as V7," +
" MEAN(v_8) as V8, MEAN(v_9) as V9, MEAN(v_10) as V10, MEAN(v_11) as V11, MEAN(v_12) as V12, MEAN(v_13) as V13," +
" MEAN(v_14) as V14, MEAN(v_15) as V15, MEAN(v_16) as V16, MEAN(v_17) as V17, MEAN(v_18) as V18," +
" MEAN(v_19) as V19, MEAN(v_20) as V20, MEAN(v_21) as V21," +
" MEAN(v_22) as V22, MEAN(v_23) as V23, MEAN(v_24) as V24, MEAN(v_25) as V25, MEAN(v_26) as V25, MEAN(v_27) as V27, MEAN(v_28) as V28," +
" MEAN(v_29) as V29, MEAN(v_30) as V30, MEAN(v_31) as V31, MEAN(v_32) as V32, MEAN(v_33) as V33, MEAN(v_34) as V34, MEAN(v_35) as V35," +
" MEAN(v_36) as V36, MEAN(v_37) as V37, MEAN(v_38) as V38, MEAN(v_39) as V39, MEAN(v_40) as V40, MEAN(v_41) as V41, MEAN(v_42) as V42," +
" MEAN(v_43) as V43, MEAN(v_44) as V44, MEAN(v_45) as V45, MEAN(v_46) as V46, MEAN(v_47) as V47, MEAN(v_48) as V48, MEAN(v_49) as V49," +
" MEAN(v_50) as V50 FROM data_harmrate_v WHERE " + stringBuilder.toString() + " and phasic_type !='T' order by time asc tz('Asia/Shanghai');";
InfluxQueryWrapper influxQueryWrapper = new InfluxQueryWrapper(DataHarmRateV.class);
influxQueryWrapper.meanSamePrefixAndSuffix("v_","", HarmonicTimesUtil.harmonicTimesList(2,50,1))
.between(DataHarmRateV::getTime,startTime,endTime)
.eq(DataHarmRateV::getLineId,lineId)
.eq(DataHarmRateV::getValueType, InfluxDBTableConstant.CP95)
.ne(DataHarmRateV::getPhaseType,InfluxDBTableConstant.PHASE_TYPE_T);
DataHarmRateV dataHarmRateV = dataHarmRateVService.getMeanAllTimesData(influxQueryWrapper);
if(Objects.nonNull(dataHarmRateV)){
for (int i = 2; i < 51; i++) {
floatList.add(PubUtils.getValueByMethod(dataHarmRateV, "getV", i));
}
}
} else {
sql = "SELECT MEAN(i_2) as I2, MEAN(i_3) as I3, MEAN(i_4) as I4, MEAN(i_5) as I5, MEAN(i_6) as I6, MEAN(i_7) as I7," +
" MEAN(i_8) as I8, MEAN(i_9) as I9, MEAN(i_10) as I10, MEAN(i_11) as I11, MEAN(i_12) as I12, MEAN(i_13) as I13," +
" MEAN(i_14) as I14, MEAN(i_15) as I15, MEAN(i_16) as I16, MEAN(i_17) as I17, MEAN(i_18) as I18," +
" MEAN(i_19) as I19, MEAN(i_20) as I20, MEAN(i_21) as I21," +
" MEAN(i_22) as I22, MEAN(i_23) as I23, MEAN(i_24) as I24, MEAN(i_25) as I25, MEAN(i_26) as I25, MEAN(i_27) as I27, MEAN(i_28) as I28," +
" MEAN(i_29) as I29, MEAN(i_30) as I30, MEAN(i_31) as I31, MEAN(i_32) as I32, MEAN(i_33) as I33, MEAN(i_34) as I34, MEAN(i_35) as I35," +
" MEAN(i_36) as I36, MEAN(i_37) as I37, MEAN(i_38) as I38, MEAN(i_39) as I39, MEAN(i_40) as I40, MEAN(i_41) as I41, MEAN(i_42) as I42," +
" MEAN(i_43) as I43, MEAN(i_44) as I44, MEAN(i_45) as I45, MEAN(i_46) as I46, MEAN(i_47) as I47, MEAN(i_48) as I48, MEAN(i_49) as I49," +
" MEAN(i_50) as I50 FROM data_i WHERE " + stringBuilder.toString() + " and phasic_type !='T' order by time asc tz('Asia/Shanghai');";
}
queryResult = influxDbUtils.query(sql);
if (queryResult.getResults().get(0).getSeries() != null) {
List<Object> resultList = queryResult.getResults().get(0).getSeries().get(0).getValues().get(0);
if (resultList.size() != 0) {
for (int i = 1; i < resultList.size(); i++) {
floatList.add(BigDecimal.valueOf(Float.parseFloat(resultList.get(i).toString())).setScale(4, BigDecimal.ROUND_HALF_UP).floatValue());
InfluxQueryWrapper influxQueryWrapper = new InfluxQueryWrapper(DataI.class);
influxQueryWrapper.meanSamePrefixAndSuffix("i_","", HarmonicTimesUtil.harmonicTimesList(2,50,1))
.between(DataHarmRateV::getTime,startTime,endTime)
.eq(DataHarmRateV::getLineId,lineId)
.eq(DataHarmRateV::getValueType, InfluxDBTableConstant.CP95)
.ne(DataHarmRateV::getPhaseType,InfluxDBTableConstant.PHASE_TYPE_T);
DataI dataI = dataIService.getMeanAllTimesData(influxQueryWrapper);
if(Objects.nonNull(dataI)){
for (int i = 2; i < 51; i++) {
floatList.add(PubUtils.getValueByMethod(dataI, "getI", i));
}
}
}
}
return floatList;
}
}

View File

@@ -25,7 +25,6 @@ import com.njcn.harmonic.pojo.vo.HarmonicLineVO;
import com.njcn.harmonic.pojo.vo.HarmonicSubstationVO;
import com.njcn.harmonic.pojo.vo.PollutionVO;
import com.njcn.harmonic.service.IHarmonicService;
import com.njcn.influxdb.utils.InfluxDbUtils;
import com.njcn.system.enums.DicDataEnum;
import com.njcn.web.utils.RequestUtil;
import lombok.AllArgsConstructor;

View File

@@ -1,8 +1,12 @@
package com.njcn.harmonic.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.njcn.common.pojo.constant.BizParamConstant;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.common.pojo.param.StatisticsBizBaseParam;
import com.njcn.common.utils.PubUtils;
import com.njcn.device.pq.api.LineFeignClient;
@@ -10,46 +14,55 @@ import com.njcn.device.biz.pojo.po.Overlimit;
import com.njcn.device.pq.pojo.vo.LineDetailDataVO;
import com.njcn.event.api.EventDetailFeignClient;
import com.njcn.event.pojo.po.EventDetail;
import com.njcn.harmonic.constant.Param;
import com.njcn.harmonic.enums.HarmonicResponseEnum;
import com.njcn.harmonic.mapper.StatHarmonicOrgDMapper;
import com.njcn.harmonic.mapper.StatHarmonicOrgMMapper;
import com.njcn.harmonic.mapper.StatHarmonicOrgQMapper;
import com.njcn.harmonic.mapper.StatHarmonicOrgYMapper;
import com.njcn.harmonic.pojo.QueryResultLimitVO;
import com.njcn.harmonic.pojo.param.HistoryHarmParam;
import com.njcn.harmonic.pojo.param.HistoryParam;
import com.njcn.harmonic.pojo.param.NormHistoryParam;
import com.njcn.harmonic.pojo.vo.EventDetailVO;
import com.njcn.harmonic.pojo.vo.HistoryDataResultVO;
import com.njcn.harmonic.pojo.vo.QueryResultLimitVO;
import com.njcn.harmonic.pojo.vo.StatHarmonicOrgVO;
import com.njcn.harmonic.service.HistoryResultService;
import com.njcn.influxdb.param.InfluxDBPublicParam;
import com.njcn.influxdb.utils.InfluxDbUtils;
import com.njcn.influx.imapper.CommonMapper;
import com.njcn.influx.imapper.DataHarmRateVMapper;
import com.njcn.influx.imapper.IDataIMapper;
import com.njcn.influx.pojo.bo.HarmonicHistoryData;
import com.njcn.influx.pojo.constant.InfluxDBTableConstant;
import com.njcn.influx.pojo.dto.HarmData;
import com.njcn.influx.pojo.dto.HarmHistoryDataDTO;
import com.njcn.influx.pojo.po.DataHarmRateV;
import com.njcn.influx.pojo.po.DataI;
import com.njcn.influx.query.InfluxQueryWrapper;
import com.njcn.user.api.DeptFeignClient;
import com.njcn.user.pojo.dto.DeptDTO;
import com.njcn.web.utils.WebUtil;
import lombok.AllArgsConstructor;
import lombok.SneakyThrows;
import org.influxdb.dto.QueryResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.math.BigDecimal;
import java.text.DateFormat;
import java.math.RoundingMode;
import java.text.SimpleDateFormat;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* @author denghuajun
* @date 2022/3/14
*/
@Slf4j
@Service
@AllArgsConstructor
public class HistoryResultServiceImpl implements HistoryResultService {
private final InfluxDbUtils influxDbUtils;
private final LineFeignClient lineFeignClient;
private final EventDetailFeignClient eventDetailFeignClient;
@@ -64,6 +77,13 @@ public class HistoryResultServiceImpl implements HistoryResultService {
private final StatHarmonicOrgDMapper statHarmonicOrgDMapper;
private final CommonMapper commonMapper;
private final IDataIMapper dataIMapper;
private final DataHarmRateVMapper dataHarmRateVMapper;
@Override
public List<HistoryDataResultVO> getHistoryResult(HistoryParam historyParam) {
List<HistoryDataResultVO> historyDataResultVOList = new ArrayList<>();
@@ -123,31 +143,32 @@ public class HistoryResultServiceImpl implements HistoryResultService {
private HistoryDataResultVO getCondition(String startTime, String endTime, String lineId, String contion, Integer number, Integer valueType, Integer ptType) {
HistoryDataResultVO historyDataResultVO = new HistoryDataResultVO();
QueryResultLimitVO queryResultLimitVO = getQueryResult(startTime, endTime, lineId, contion, number, valueType, ptType);
QueryResult queryResult = queryResultLimitVO.getQueryResult();
List<HarmonicHistoryData> harmonicHistoryDataList = queryResultLimitVO.getHarmonicHistoryDataList();
BeanUtil.copyProperties(queryResultLimitVO, historyDataResultVO);
List<QueryResult.Series> list = queryResult.getResults().get(0).getSeries();
//时间轴
List<Date> time = new ArrayList<>();
List<Float> aValue = new ArrayList<>();
//A相值
List<Float> aValue;
//B相值
List<Float> bValue = new ArrayList<>();
//C相值
List<Float> cValue = new ArrayList<>();
//针对统计相别为T时存放的数据
List<Float> fValue = new ArrayList<>();
List<List<Object>> objectListData = new ArrayList<>();
if (!CollectionUtils.isEmpty(list)) {
if (list.size() == 1) {
List<List<Object>> listData = queryResult.getResults().get(0).getSeries().get(0).getValues();
for (int i = 0; i < listData.size(); i++) {
List<Object> objectList = listData.get(i);
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX");
TimeZone tx = TimeZone.getTimeZone("Asia/Shanghai");
formatter.setTimeZone(tx);
Date d = formatter.parse(objectList.get(0).toString());
time.add(d);
fValue.add(BigDecimal.valueOf(Float.parseFloat(objectList.get(1).toString())).setScale(4, BigDecimal.ROUND_HALF_UP).floatValue());
if (CollectionUtil.isNotEmpty(harmonicHistoryDataList)) {
//相别统计为T时业务数据处理
if (StrUtil.isBlank(harmonicHistoryDataList.get(0).getPhasicType()) || harmonicHistoryDataList.get(0).getPhasicType().equalsIgnoreCase("t")) {
for (HarmonicHistoryData harmonicHistoryData : harmonicHistoryDataList) {
time.add(new Date(harmonicHistoryData.getTime().toEpochMilli()));
fValue.add(BigDecimal.valueOf(harmonicHistoryData.getAValue()).setScale(4, RoundingMode.HALF_UP).floatValue());
//返回结果有多个值,需要额外处理下
if (Integer.parseInt(contion) == 14) {
bValue.add(BigDecimal.valueOf(Float.parseFloat(objectList.get(2).toString())).setScale(4, BigDecimal.ROUND_HALF_UP).floatValue());
cValue.add(BigDecimal.valueOf(Float.parseFloat(objectList.get(3).toString())).setScale(4, BigDecimal.ROUND_HALF_UP).floatValue());
bValue.add(BigDecimal.valueOf(harmonicHistoryData.getBValue()).setScale(4, RoundingMode.HALF_UP).floatValue());
cValue.add(BigDecimal.valueOf(harmonicHistoryData.getCValue()).setScale(4, RoundingMode.HALF_UP).floatValue());
}
}
//组装二维数组
for (int i = 0; i < time.size(); i++) {
List<Object> objects = new ArrayList<>();
objects.add(time.get(i));
@@ -163,28 +184,33 @@ public class HistoryResultServiceImpl implements HistoryResultService {
historyDataResultVO.setMinValue(Collections.min(fValue));
historyDataResultVO.setMaxValue(Collections.max(fValue));
historyDataResultVO.setValue(objectListData);
} else {
for (int i = 0; i < list.size(); i++) {
List<List<Object>> values = list.get(i).getValues();
for (int j = 0; j < values.size(); j++) {
List<Object> objectList = values.get(j);
if (i == 0) {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX");
TimeZone tx = TimeZone.getTimeZone("Asia/Shanghai");
formatter.setTimeZone(tx);
Date d = formatter.parse(objectList.get(0).toString());
time.add(d);
aValue.add(BigDecimal.valueOf(Float.parseFloat(objectList.get(1).toString())).setScale(4, BigDecimal.ROUND_HALF_UP).floatValue());
} else if (i == 1) {
bValue.add(BigDecimal.valueOf(Float.parseFloat(objectList.get(1).toString())).setScale(4, BigDecimal.ROUND_HALF_UP).floatValue());
} else {
cValue.add(BigDecimal.valueOf(Float.parseFloat(objectList.get(1).toString())).setScale(4, BigDecimal.ROUND_HALF_UP).floatValue());
}
}
}
//按相别分为3组
List<HarmonicHistoryData> aList = harmonicHistoryDataList.stream()
.filter(temp -> temp.getPhasicType().equalsIgnoreCase(InfluxDBTableConstant.PHASE_TYPE_A))
.collect(Collectors.toList());
List<HarmonicHistoryData> bList = harmonicHistoryDataList.stream()
.filter(temp -> temp.getPhasicType().equalsIgnoreCase(InfluxDBTableConstant.PHASE_TYPE_B))
.collect(Collectors.toList());
List<HarmonicHistoryData> cList = harmonicHistoryDataList.stream()
.filter(temp -> temp.getPhasicType().equalsIgnoreCase(InfluxDBTableConstant.PHASE_TYPE_C))
.collect(Collectors.toList());
time = aList.stream()
.map(temp -> new Date(temp.getTime().toEpochMilli()))
.collect(Collectors.toList());
aValue = aList.stream()
.map(temp -> BigDecimal.valueOf(temp.getAValue()).setScale(4, RoundingMode.HALF_UP).floatValue())
.collect(Collectors.toList());
bValue = bList.stream()
.map(temp -> BigDecimal.valueOf(temp.getAValue()).setScale(4, RoundingMode.HALF_UP).floatValue())
.collect(Collectors.toList());
cValue = cList.stream()
.map(temp -> BigDecimal.valueOf(temp.getAValue()).setScale(4, RoundingMode.HALF_UP).floatValue())
.collect(Collectors.toList());
//组装二维数组
for (int i = 0; i < time.size(); i++) {
List<Object> objects = new ArrayList<>();
//指定
objects.add(time.get(i));
objects.add(aValue.get(i));
objects.add(bValue.get(i));
@@ -198,7 +224,7 @@ public class HistoryResultServiceImpl implements HistoryResultService {
Float bValueMax = Collections.max(bValue);
Float cValueMax = Collections.max(cValue);
historyDataResultVO.setMinValue((aValueMin < bValueMin) ? ((aValueMin < cValueMin) ? aValueMin : cValueMin) : ((bValueMin < cValueMin) ? bValueMin : cValueMin));
historyDataResultVO.setMaxValue(aValueMax > bValueMax ? (aValueMax > cValueMax ? aValueMax : bValueMax) : (bValueMax > cValueMax ? bValueMax : cValueMax ));
historyDataResultVO.setMaxValue(aValueMax > bValueMax ? (aValueMax > cValueMax ? aValueMax : bValueMax) : (bValueMax > cValueMax ? bValueMax : cValueMax));
historyDataResultVO.setTopLimit(queryResultLimitVO.getTopLimit());
historyDataResultVO.setLowerLimit(queryResultLimitVO.getLowerLimit());
historyDataResultVO.setValue(objectListData);
@@ -212,7 +238,6 @@ public class HistoryResultServiceImpl implements HistoryResultService {
private QueryResultLimitVO getQueryResult(String startTime, String endTime, String lineList, String contion, Integer number, Integer valueType, Integer ptType) {
QueryResultLimitVO queryResultLimitVO = new QueryResultLimitVO();
QueryResult queryResult;
if (!lineList.isEmpty()) {
Float topLimit = 0f;
Float lowerLimit = 0f;
@@ -222,9 +247,9 @@ public class HistoryResultServiceImpl implements HistoryResultService {
LineDetailDataVO lineDetailDataVO = lineFeignClient.getLineDetailData(lineList).getData();
//组装sql语句
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(InfluxDBPublicParam.TIME + " >= '").append(startTime).append(InfluxDBPublicParam.START_TIME).append("' and ").append(InfluxDBPublicParam.TIME).append(" <= '").append(endTime).append(InfluxDBPublicParam.END_TIME).append("' and (");
stringBuilder.append(InfluxDBTableConstant.TIME + " >= '").append(startTime).append(InfluxDBTableConstant.START_TIME).append("' and ").append(InfluxDBTableConstant.TIME).append(" <= '").append(endTime).append(InfluxDBTableConstant.END_TIME).append("' and (");
//sql语句
stringBuilder.append(InfluxDBPublicParam.LINE_ID + "='").append(lineList).append("')");
stringBuilder.append(InfluxDBTableConstant.LINE_ID + "='").append(lineList).append("')");
String valueTypeName = "";
switch (valueType) {
case 1:
@@ -243,7 +268,7 @@ public class HistoryResultServiceImpl implements HistoryResultService {
break;
}
if (!Integer.valueOf(contion).equals(60) && !Integer.valueOf(contion).equals(61) && !Integer.valueOf(contion).equals(62)) {
stringBuilder.append(" and ").append(InfluxDBPublicParam.VALUETYPE + "='").append(valueTypeName).append("'");
stringBuilder.append(" and ").append(InfluxDBTableConstant.VALUE_TYPE + "='").append(valueTypeName).append("'");
}
String sql = "";
List<String> phasicType = new ArrayList<>();
@@ -252,7 +277,7 @@ public class HistoryResultServiceImpl implements HistoryResultService {
switch (Integer.parseInt(contion)) {
case 10:
//相电压有效值
sql = "SELECT time as time, rms as aValue FROM data_v WHERE " + stringBuilder.toString() +
sql = "SELECT time as time, rms as aValue ," + InfluxDBTableConstant.PHASIC_TYPE + " FROM data_v WHERE " + stringBuilder +
" and (phasic_type ='A' or phasic_type ='B' or phasic_type ='C') group by phasic_type order by time asc tz('Asia/Shanghai');";
phasicType.add("A相");
phasicType.add("B相");
@@ -262,7 +287,7 @@ public class HistoryResultServiceImpl implements HistoryResultService {
break;
case 11:
//线电压有效值
sql = "SELECT time as time, rms_lvr as aValue FROM data_v WHERE " + stringBuilder.toString() +
sql = "SELECT time as time, rms_lvr as aValue ," + InfluxDBTableConstant.PHASIC_TYPE + " FROM data_v WHERE " + stringBuilder +
" and (phasic_type ='A' or phasic_type ='B' or phasic_type ='C') group by phasic_type order by time asc tz('Asia/Shanghai');";
phasicType.add("AB相");
phasicType.add("BC相");
@@ -272,7 +297,7 @@ public class HistoryResultServiceImpl implements HistoryResultService {
break;
case 12:
//电压偏差
sql = "SELECT time as time, vu_dev as aValue FROM data_v WHERE " + stringBuilder.toString() +
sql = "SELECT time as time, vu_dev as aValue ," + InfluxDBTableConstant.PHASIC_TYPE + " FROM data_v WHERE " + stringBuilder +
" and (phasic_type ='A' or phasic_type ='B' or phasic_type ='C') group by phasic_type order by time asc tz('Asia/Shanghai');";
topLimit = overlimit.getVoltageDev();
lowerLimit = overlimit.getUvoltageDev();
@@ -290,7 +315,7 @@ public class HistoryResultServiceImpl implements HistoryResultService {
break;
case 13:
//三相电压不平衡度
sql = "SELECT time as time, v_unbalance as aValue FROM data_v WHERE " + stringBuilder.toString() +
sql = "SELECT time as time, v_unbalance as aValue ," + InfluxDBTableConstant.PHASIC_TYPE + " FROM data_v WHERE " + stringBuilder +
" and phasic_type ='T' order by time asc tz('Asia/Shanghai');";
topLimit = overlimit.getUbalance();
phasicType.add("三相电压不平衡度");
@@ -299,7 +324,7 @@ public class HistoryResultServiceImpl implements HistoryResultService {
break;
case 14:
//电压不平衡
sql = "SELECT time as time, v_zero as aValue, v_pos as bValue, v_neg as cValue FROM data_v WHERE " + stringBuilder.toString() +
sql = "SELECT time as time, v_zero as aValue, v_pos as bValue, v_neg as cValue ," + InfluxDBTableConstant.PHASIC_TYPE + "FROM data_v WHERE " + stringBuilder +
" and (phasic_type ='T') group by phasic_type order by time asc tz('Asia/Shanghai');";
phasicType.add("零序电压");
phasicType.add("正序电压");
@@ -311,7 +336,7 @@ public class HistoryResultServiceImpl implements HistoryResultService {
break;
case 15:
//电压总谐波畸变率
sql = "SELECT time as time, v_thd as aValue FROM data_v WHERE " + stringBuilder.toString() +
sql = "SELECT time as time, v_thd as aValue ," + InfluxDBTableConstant.PHASIC_TYPE + " FROM data_v WHERE " + stringBuilder +
" and (phasic_type ='A' or phasic_type ='B' or phasic_type ='C') group by phasic_type order by time asc tz('Asia/Shanghai');";
topLimit = overlimit.getUaberrance();
if (ptType == 0) {
@@ -328,7 +353,7 @@ public class HistoryResultServiceImpl implements HistoryResultService {
break;
case 20:
//电流有效值
sql = "SELECT time as time, rms as aValue FROM data_i WHERE " + stringBuilder.toString() +
sql = "SELECT time as time, rms as aValue ," + InfluxDBTableConstant.PHASIC_TYPE + " FROM data_i WHERE " + stringBuilder +
" and (phasic_type ='A' or phasic_type ='B' or phasic_type ='C') group by phasic_type order by time asc tz('Asia/Shanghai');";
phasicType.add("A相");
phasicType.add("B相");
@@ -338,7 +363,7 @@ public class HistoryResultServiceImpl implements HistoryResultService {
break;
case 21:
//电流总畸变率
sql = "SELECT time as time, i_thd as aValue FROM data_i WHERE " + stringBuilder.toString() +
sql = "SELECT time as time, i_thd as aValue ," + InfluxDBTableConstant.PHASIC_TYPE + " FROM data_i WHERE " + stringBuilder +
" and (phasic_type ='A' or phasic_type ='B' or phasic_type ='C') group by phasic_type order by time asc tz('Asia/Shanghai');";
phasicType.add("A相");
phasicType.add("B相");
@@ -348,7 +373,7 @@ public class HistoryResultServiceImpl implements HistoryResultService {
break;
case 22:
//负序电流
sql = "SELECT time as time, i_neg as aValue FROM data_i WHERE " + stringBuilder.toString() +
sql = "SELECT time as time, i_neg as aValue ," + InfluxDBTableConstant.PHASIC_TYPE + " FROM data_i WHERE " + stringBuilder +
" and (phasic_type ='A' or phasic_type ='B' or phasic_type ='C') group by phasic_type order by time asc tz('Asia/Shanghai');";
topLimit = overlimit.getINeg();
phasicType.add("负序电流");
@@ -357,7 +382,7 @@ public class HistoryResultServiceImpl implements HistoryResultService {
break;
case 30:
//频率 V9暂时代表Freq
sql = "SELECT time as time, freq as aValue FROM data_v WHERE " + stringBuilder.toString() +
sql = "SELECT time as time, freq as aValue ," + InfluxDBTableConstant.PHASIC_TYPE + " FROM data_v WHERE " + stringBuilder +
" and phasic_type ='T' order by time asc tz('Asia/Shanghai');";
topLimit = 50 + overlimit.getFreqDev();
lowerLimit = 50 - overlimit.getFreqDev();
@@ -368,10 +393,10 @@ public class HistoryResultServiceImpl implements HistoryResultService {
case 40:
//谐波电压含有率
if (number == 1) {
sql = "SELECT time as time, v as aValue FROM data_harmrate_v WHERE " + stringBuilder.toString() +
sql = "SELECT time as time, v as aValue ," + InfluxDBTableConstant.PHASIC_TYPE + " FROM data_harmrate_v WHERE " + stringBuilder +
" and (phasic_type ='A' or phasic_type ='B' or phasic_type ='C') group by phasic_type order by time asc tz('Asia/Shanghai');";
} else {
sql = "SELECT time as time, v_" + number + " as aValue FROM data_harmrate_v WHERE " + stringBuilder.toString() +
sql = "SELECT time as time, v_" + number + " as aValue ," + InfluxDBTableConstant.PHASIC_TYPE + " FROM data_harmrate_v WHERE " + stringBuilder +
" and (phasic_type ='A' or phasic_type ='B' or phasic_type ='C') group by phasic_type order by time asc tz('Asia/Shanghai');";
if (number < 26) {
topLimit = PubUtils.getValueByMethod(overlimit, "getUharm", number);
@@ -392,10 +417,10 @@ public class HistoryResultServiceImpl implements HistoryResultService {
case 41:
//谐波电流含有率
if (number == 1) {
sql = "SELECT time as time, i as aValue FROM data_harmrate_i WHERE " + stringBuilder.toString() +
sql = "SELECT time as time, i as aValue ," + InfluxDBTableConstant.PHASIC_TYPE + " FROM data_harmrate_i WHERE " + stringBuilder +
" and (phasic_type ='A' or phasic_type ='B' or phasic_type ='C') group by phasic_type order by time asc tz('Asia/Shanghai');";
} else {
sql = "SELECT time as time, i_" + number + " as aValue FROM data_harmrate_i WHERE " + stringBuilder.toString() +
sql = "SELECT time as time, i_" + number + " as aValue ," + InfluxDBTableConstant.PHASIC_TYPE + " FROM data_harmrate_i WHERE " + stringBuilder +
" and (phasic_type ='A' or phasic_type ='B' or phasic_type ='C') group by phasic_type order by time asc tz('Asia/Shanghai');";
}
phasicType.add("A相");
@@ -407,10 +432,10 @@ public class HistoryResultServiceImpl implements HistoryResultService {
case 42:
//谐波电压幅值
if (number == 1) {
sql = "SELECT time as time, v as aValue FROM data_v WHERE " + stringBuilder.toString() +
sql = "SELECT time as time, v as aValue ," + InfluxDBTableConstant.PHASIC_TYPE + " FROM data_v WHERE " + stringBuilder +
" and (phasic_type ='A' or phasic_type ='B' or phasic_type ='C') group by phasic_type order by time asc tz('Asia/Shanghai');";
} else {
sql = "SELECT time as time, v_" + number + " as aValue FROM data_v WHERE " + stringBuilder.toString() +
sql = "SELECT time as time, v_" + number + " as aValue ," + InfluxDBTableConstant.PHASIC_TYPE + " FROM data_v WHERE " + stringBuilder +
" and (phasic_type ='A' or phasic_type ='B' or phasic_type ='C') group by phasic_type order by time asc tz('Asia/Shanghai');";
}
if (ptType == 0) {
@@ -432,10 +457,10 @@ public class HistoryResultServiceImpl implements HistoryResultService {
case 43:
//谐波电流幅值
if (number == 1) {
sql = "SELECT time as time, i as aValue FROM data_i WHERE " + stringBuilder.toString() +
sql = "SELECT time as time, i as aValue ," + InfluxDBTableConstant.PHASIC_TYPE + " FROM data_i WHERE " + stringBuilder +
" and (phasic_type ='A' or phasic_type ='B' or phasic_type ='C') group by phasic_type order by time asc tz('Asia/Shanghai');";
} else {
sql = "SELECT time as time, i_" + number + " as aValue FROM data_i WHERE " + stringBuilder.toString() +
sql = "SELECT time as time, i_" + number + " as aValue ," + InfluxDBTableConstant.PHASIC_TYPE + " FROM data_i WHERE " + stringBuilder +
" and (phasic_type ='A' or phasic_type ='B' or phasic_type ='C') group by phasic_type order by time asc tz('Asia/Shanghai');";
if (number < 26) {
topLimit = PubUtils.getValueByMethod(overlimit, "getIharm", number);
@@ -450,10 +475,10 @@ public class HistoryResultServiceImpl implements HistoryResultService {
case 44:
//谐波电压相角
if (number == 1) {
sql = "SELECT time as time, v as aValue FROM data_harmphasic_v WHERE " + stringBuilder.toString() +
sql = "SELECT time as time, v as aValue ," + InfluxDBTableConstant.PHASIC_TYPE + " FROM data_harmphasic_v WHERE " + stringBuilder +
" and (phasic_type ='A' or phasic_type ='B' or phasic_type ='C') group by phasic_type order by time asc tz('Asia/Shanghai');";
} else {
sql = "SELECT time as time, v_" + number + " as aValue FROM data_harmphasic_v WHERE " + stringBuilder.toString() +
sql = "SELECT time as time, v_" + number + " as aValue ," + InfluxDBTableConstant.PHASIC_TYPE + " FROM data_harmphasic_v WHERE " + stringBuilder +
" and (phasic_type ='A' or phasic_type ='B' or phasic_type ='C') group by phasic_type order by time asc tz('Asia/Shanghai');";
}
if (ptType == 0) {
@@ -471,10 +496,10 @@ public class HistoryResultServiceImpl implements HistoryResultService {
case 45:
//谐波电流相角
if (number == 1) {
sql = "SELECT time as time, i as aValue FROM data_harmphasic_i WHERE " + stringBuilder.toString() +
sql = "SELECT time as time, i as aValue ," + InfluxDBTableConstant.PHASIC_TYPE + " FROM data_harmphasic_i WHERE " + stringBuilder +
" and (phasic_type ='A' or phasic_type ='B' or phasic_type ='C') group by phasic_type order by time asc tz('Asia/Shanghai');";
} else {
sql = "SELECT time as time, i_" + number + " as aValue FROM data_harmphasic_i WHERE " + stringBuilder.toString() +
sql = "SELECT time as time, i_" + number + " as aValue ," + InfluxDBTableConstant.PHASIC_TYPE + " FROM data_harmphasic_i WHERE " + stringBuilder +
" and (phasic_type ='A' or phasic_type ='B' or phasic_type ='C') group by phasic_type order by time asc tz('Asia/Shanghai');";
}
phasicType.add("A相");
@@ -485,7 +510,7 @@ public class HistoryResultServiceImpl implements HistoryResultService {
break;
case 46:
//间谐波电压含有率
sql = "SELECT time as time, v_" + number + " as aValue FROM data_inharmrate_v WHERE " + stringBuilder.toString() +
sql = "SELECT time as time, v_" + number + " as aValue ," + InfluxDBTableConstant.PHASIC_TYPE + " FROM data_inharmrate_v WHERE " + stringBuilder +
" and (phasic_type ='A' or phasic_type ='B' or phasic_type ='C') group by phasic_type order by time asc tz('Asia/Shanghai');";
topLimit = PubUtils.getValueByMethod(overlimit, "getInuharm", number);
if (ptType == 0) {
@@ -502,7 +527,7 @@ public class HistoryResultServiceImpl implements HistoryResultService {
break;
case 47:
//间谐波电流含有率
sql = "SELECT time as time, i_" + number + " as aValue FROM data_inharmrate_i WHERE " + stringBuilder.toString() +
sql = "SELECT time as time, i_" + number + " as aValue ," + InfluxDBTableConstant.PHASIC_TYPE + " FROM data_inharmrate_i WHERE " + stringBuilder +
" and (phasic_type ='A' or phasic_type ='B' or phasic_type ='C') group by phasic_type order by time asc tz('Asia/Shanghai');";
phasicType.add("A相");
phasicType.add("B相");
@@ -512,7 +537,7 @@ public class HistoryResultServiceImpl implements HistoryResultService {
break;
case 48:
//间谐波电压幅值
sql = "SELECT time as time, v_" + number + " as aValue FROM data_inharm_v WHERE " + stringBuilder.toString() +
sql = "SELECT time as time, v_" + number + " as aValue ," + InfluxDBTableConstant.PHASIC_TYPE + " FROM data_inharm_v WHERE " + stringBuilder +
" and (phasic_type ='A' or phasic_type ='B' or phasic_type ='C') group by phasic_type order by time asc tz('Asia/Shanghai');";
targetName = "间谐波电压幅值";
if (ptType == 0) {
@@ -528,7 +553,7 @@ public class HistoryResultServiceImpl implements HistoryResultService {
break;
case 49:
//间谐波电流幅值
sql = "SELECT time as time, i_" + number + " as aValue FROM data_inharm_i WHERE " + stringBuilder.toString() +
sql = "SELECT time as time, i_" + number + " as aValue ," + InfluxDBTableConstant.PHASIC_TYPE + " FROM data_inharm_i WHERE " + stringBuilder +
" and (phasic_type ='A' or phasic_type ='B' or phasic_type ='C') group by phasic_type order by time asc tz('Asia/Shanghai');";
phasicType.add("A相");
phasicType.add("B相");
@@ -538,7 +563,7 @@ public class HistoryResultServiceImpl implements HistoryResultService {
break;
case 50:
//谐波有功功率
sql = "SELECT time as time, p_" + number + " as aValue FROM data_harmpower_p WHERE " + stringBuilder.toString() +
sql = "SELECT time as time, p_" + number + " as aValue ," + InfluxDBTableConstant.PHASIC_TYPE + " FROM data_harmpower_p WHERE " + stringBuilder +
" and (phasic_type ='A' or phasic_type ='B' or phasic_type ='C') group by phasic_type order by time asc tz('Asia/Shanghai');";
phasicType.add("A相");
phasicType.add("B相");
@@ -552,7 +577,7 @@ public class HistoryResultServiceImpl implements HistoryResultService {
break;
case 51:
//谐波无功功率
sql = "SELECT time as time, q_" + number + " as aValue FROM data_harmpower_q WHERE " + stringBuilder.toString() +
sql = "SELECT time as time, q_" + number + " as aValue ," + InfluxDBTableConstant.PHASIC_TYPE + " FROM data_harmpower_q WHERE " + stringBuilder +
" and (phasic_type ='A' or phasic_type ='B' or phasic_type ='C') group by phasic_type order by time asc tz('Asia/Shanghai');";
phasicType.add("A相");
phasicType.add("B相");
@@ -566,7 +591,7 @@ public class HistoryResultServiceImpl implements HistoryResultService {
break;
case 52:
//谐波视在功率
sql = "SELECT time as time, s_" + number + " as aValue FROM data_harmpower_s WHERE " + stringBuilder.toString() +
sql = "SELECT time as time, s_" + number + " as aValue ," + InfluxDBTableConstant.PHASIC_TYPE + " FROM data_harmpower_s WHERE " + stringBuilder +
" and (phasic_type ='A' or phasic_type ='B' or phasic_type ='C') group by phasic_type order by time asc tz('Asia/Shanghai');";
phasicType.add("A相");
phasicType.add("B相");
@@ -580,7 +605,7 @@ public class HistoryResultServiceImpl implements HistoryResultService {
break;
case 53:
//三相有功功率
sql = "SELECT time as time, p as aValue FROM data_harmpower_p WHERE " + stringBuilder.toString() +
sql = "SELECT time as time, p as aValue ," + InfluxDBTableConstant.PHASIC_TYPE + " FROM data_harmpower_p WHERE " + stringBuilder +
" and (phasic_type ='A' or phasic_type ='B' or phasic_type ='C') group by phasic_type order by time asc tz('Asia/Shanghai');";
phasicType.add("A相");
phasicType.add("B相");
@@ -590,7 +615,7 @@ public class HistoryResultServiceImpl implements HistoryResultService {
break;
case 54:
//三相无功功率
sql = "SELECT time as time, q as aValue FROM data_harmpower_q WHERE " + stringBuilder.toString() +
sql = "SELECT time as time, q as aValue ," + InfluxDBTableConstant.PHASIC_TYPE + " FROM data_harmpower_q WHERE " + stringBuilder +
" and (phasic_type ='A' or phasic_type ='B' or phasic_type ='C') group by phasic_type order by time asc tz('Asia/Shanghai');";
phasicType.add("A相");
phasicType.add("B相");
@@ -600,7 +625,7 @@ public class HistoryResultServiceImpl implements HistoryResultService {
break;
case 55:
//三相视在功率
sql = "SELECT time as time, s as aValue FROM data_harmpower_s WHERE " + stringBuilder.toString() +
sql = "SELECT time as time, s as aValue ," + InfluxDBTableConstant.PHASIC_TYPE + " FROM data_harmpower_s WHERE " + stringBuilder +
" and (phasic_type ='A' or phasic_type ='B' or phasic_type ='C') group by phasic_type order by time asc tz('Asia/Shanghai');";
phasicType.add("A相");
phasicType.add("B相");
@@ -610,7 +635,7 @@ public class HistoryResultServiceImpl implements HistoryResultService {
break;
case 56:
//三相总有功功率
sql = "SELECT time as time, p as aValue FROM data_harmpower_p WHERE " + stringBuilder.toString() +
sql = "SELECT time as time, p as aValue ," + InfluxDBTableConstant.PHASIC_TYPE + " FROM data_harmpower_p WHERE " + stringBuilder +
" and phasic_type ='T' order by time asc tz('Asia/Shanghai');";
phasicType.add("三相总有功功率");
unit.add("kW");
@@ -618,7 +643,7 @@ public class HistoryResultServiceImpl implements HistoryResultService {
break;
case 57:
//三相总无功功率
sql = "SELECT time as time, q as aValue FROM data_harmpower_q WHERE " + stringBuilder.toString() +
sql = "SELECT time as time, q as aValue ," + InfluxDBTableConstant.PHASIC_TYPE + " FROM data_harmpower_q WHERE " + stringBuilder +
" and phasic_type ='T' order by time asc tz('Asia/Shanghai');";
phasicType.add("三相总无功功率");
unit.add("kVar");
@@ -626,7 +651,7 @@ public class HistoryResultServiceImpl implements HistoryResultService {
break;
case 58:
//三相总视在功率
sql = "SELECT time as time, s as aValue FROM data_harmpower_s WHERE " + stringBuilder.toString() +
sql = "SELECT time as time, s as aValue ," + InfluxDBTableConstant.PHASIC_TYPE + " FROM data_harmpower_s WHERE " + stringBuilder +
" and phasic_type ='T' order by time asc tz('Asia/Shanghai');";
phasicType.add("三相总视在功率");
unit.add("kVA");
@@ -634,7 +659,7 @@ public class HistoryResultServiceImpl implements HistoryResultService {
break;
case 59:
//视在功率因数
sql = "SELECT time as time, pf as aValue FROM data_harmpower_p WHERE " + stringBuilder.toString() +
sql = "SELECT time as time, pf as aValue ," + InfluxDBTableConstant.PHASIC_TYPE + " FROM data_harmpower_p WHERE " + stringBuilder +
" and (phasic_type ='A' or phasic_type ='B' or phasic_type ='C') group by phasic_type order by time asc tz('Asia/Shanghai');";
phasicType.add("A相");
phasicType.add("B相");
@@ -643,7 +668,7 @@ public class HistoryResultServiceImpl implements HistoryResultService {
break;
case 591:
//位移功率因数
sql = "SELECT time as time, df as aValue FROM data_harmpower_p WHERE " + stringBuilder.toString() +
sql = "SELECT time as time, df as aValue ," + InfluxDBTableConstant.PHASIC_TYPE + " FROM data_harmpower_p WHERE " + stringBuilder +
" and (phasic_type ='A' or phasic_type ='B' or phasic_type ='C') group by phasic_type order by time asc tz('Asia/Shanghai');";
phasicType.add("A相");
phasicType.add("B相");
@@ -652,21 +677,21 @@ public class HistoryResultServiceImpl implements HistoryResultService {
break;
case 592:
//总视在功率因数
sql = "SELECT time as time, pf as aValue FROM data_harmpower_p WHERE " + stringBuilder.toString() +
sql = "SELECT time as time, pf as aValue ," + InfluxDBTableConstant.PHASIC_TYPE + " FROM data_harmpower_p WHERE " + stringBuilder +
" and phasic_type ='T' order by time asc tz('Asia/Shanghai');";
phasicType.add("总视在功率因数");
targetName = "总视在功率因数";
break;
case 593:
//总位移功率因数
sql = "SELECT time as time, df as aValue FROM data_harmpower_p WHERE " + stringBuilder.toString() +
sql = "SELECT time as time, df as aValue ," + InfluxDBTableConstant.PHASIC_TYPE + " FROM data_harmpower_p WHERE " + stringBuilder +
" and phasic_type ='T' order by time asc tz('Asia/Shanghai');";
phasicType.add("总位移功率因数");
targetName = "总位移功率因数";
break;
case 61:
//长时闪变
sql = "SELECT time as time, plt as aValue FROM data_plt WHERE " + stringBuilder.toString() +
sql = "SELECT time as time, plt as aValue ," + InfluxDBTableConstant.PHASIC_TYPE + " FROM data_plt WHERE " + stringBuilder +
" and (phasic_type ='A' or phasic_type ='B' or phasic_type ='C') group by phasic_type order by time asc tz('Asia/Shanghai');";
if (ptType == 0) {
phasicType.add("A相");
@@ -682,7 +707,7 @@ public class HistoryResultServiceImpl implements HistoryResultService {
break;
case 60:
//短时闪变
sql = "SELECT time as time, pst as aValue FROM data_flicker WHERE " + stringBuilder.toString() +
sql = "SELECT time as time, pst as aValue ," + InfluxDBTableConstant.PHASIC_TYPE + " FROM data_flicker WHERE " + stringBuilder +
" and (phasic_type ='A' or phasic_type ='B' or phasic_type ='C') group by phasic_type order by time asc tz('Asia/Shanghai');";
topLimit = overlimit.getFlicker();
if (ptType == 0) {
@@ -698,7 +723,7 @@ public class HistoryResultServiceImpl implements HistoryResultService {
break;
case 62:
//电压波动
sql = "SELECT time as time, fluc as aValue FROM data_fluc WHERE " + stringBuilder.toString() +
sql = "SELECT time as time, fluc as aValue ," + InfluxDBTableConstant.PHASIC_TYPE + " FROM data_fluc WHERE " + stringBuilder +
" and (phasic_type ='A' or phasic_type ='B' or phasic_type ='C') group by phasic_type order by time asc tz('Asia/Shanghai');";
if (ptType == 0) {
phasicType.add("A相");
@@ -714,8 +739,12 @@ public class HistoryResultServiceImpl implements HistoryResultService {
default:
break;
}
queryResult = influxDbUtils.query(sql);
queryResultLimitVO.setQueryResult(queryResult);
//大致有3种类型
//1、一次查询返回3条记录分别为A/B/C三相的结果
//2、一次查询返回一条记录以T相为条件返回某3个指标值
//3、一次查询返回一条记录以T相为条件返回某1个指标值
List<HarmonicHistoryData> harmonicHistoryData = commonMapper.getHistoryResult(sql);
queryResultLimitVO.setHarmonicHistoryDataList(harmonicHistoryData);
queryResultLimitVO.setTopLimit(topLimit);
queryResultLimitVO.setLowerLimit(lowerLimit);
queryResultLimitVO.setPhaiscType(phasicType);
@@ -733,7 +762,6 @@ public class HistoryResultServiceImpl implements HistoryResultService {
private QueryResultLimitVO getQueryNormDataResult(NormHistoryParam normHistoryParam) {
QueryResultLimitVO queryResultLimitVO = new QueryResultLimitVO();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
QueryResult queryResult = null;
if (!normHistoryParam.getLineId().isEmpty()) {
Float topLimit = 0f;
Float lowerLimit = 0f;
@@ -747,9 +775,9 @@ public class HistoryResultServiceImpl implements HistoryResultService {
LineDetailDataVO lineDetailDataVO = lineFeignClient.getLineDetailData(lineList).getData();
//组装sql语句
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(Param.TIME + " >= '").append(startTime).append("' and ").append(Param.TIME).append(" <= '").append(endTime).append("' and (");
stringBuilder.append(InfluxDBTableConstant.TIME + " >= '").append(startTime).append("' and ").append(InfluxDBTableConstant.TIME).append(" <= '").append(endTime).append("' and (");
//sql语句
stringBuilder.append(Param.LINE_ID + "='").append(lineList).append("')");
stringBuilder.append(InfluxDBTableConstant.LINE_ID + "='").append(lineList).append("')");
String valueTypeName = "";
String phasicType = "";
switch (valueType) {
@@ -768,15 +796,15 @@ public class HistoryResultServiceImpl implements HistoryResultService {
default:
break;
}
if ("A".equals(normHistoryParam.getPhaseType()) || "AB".equals(normHistoryParam.getPhaseType())) {
if ("A".equalsIgnoreCase(normHistoryParam.getPhaseType()) || "AB".equalsIgnoreCase(normHistoryParam.getPhaseType())) {
phasicType = "A";
} else if ("B".equals(normHistoryParam.getPhaseType()) || "BC".equals(normHistoryParam.getPhaseType())) {
} else if ("B".equalsIgnoreCase(normHistoryParam.getPhaseType()) || "BC".equalsIgnoreCase(normHistoryParam.getPhaseType())) {
phasicType = "B";
} else if ("C".equals(normHistoryParam.getPhaseType()) || "CA".equals(normHistoryParam.getPhaseType())) {
} else if ("C".equalsIgnoreCase(normHistoryParam.getPhaseType()) || "CA".equalsIgnoreCase(normHistoryParam.getPhaseType())) {
phasicType = "C";
}
if (Integer.parseInt(normHistoryParam.getTargetCode()) != 60 || Integer.parseInt(normHistoryParam.getTargetCode()) != 61 || Integer.parseInt(normHistoryParam.getTargetCode()) != 62) {
stringBuilder.append(" and ").append(Param.VALUETYPE + "='").append(valueTypeName).append("'");
stringBuilder.append(" and ").append(InfluxDBTableConstant.VALUE_TYPE + "='").append(valueTypeName).append("'");
}
stringBuilder.append(" and ").append("phasic_type ='").append(phasicType).append("'");
String sql = "";
@@ -786,7 +814,7 @@ public class HistoryResultServiceImpl implements HistoryResultService {
switch (Integer.parseInt(normHistoryParam.getTargetCode())) {
case 12:
//电压偏差
sql = "SELECT time as time, vu_dev as aValue FROM data_v WHERE " + stringBuilder.toString() +
sql = "SELECT time as time, vu_dev as aValue FROM data_v WHERE " + stringBuilder +
" order by time asc tz('Asia/Shanghai');";
topLimit = overlimit.getVoltageDev();
lowerLimit = overlimit.getUvoltageDev();
@@ -795,7 +823,7 @@ public class HistoryResultServiceImpl implements HistoryResultService {
break;
case 13:
//三相电压不平衡度
sql = "SELECT time as time, v_unbalance as aValue FROM data_v WHERE " + stringBuilder.toString() +
sql = "SELECT time as time, v_unbalance as aValue FROM data_v WHERE " + stringBuilder +
" order by time asc tz('Asia/Shanghai');";
topLimit = overlimit.getUbalance();
unit.add("%");
@@ -803,7 +831,7 @@ public class HistoryResultServiceImpl implements HistoryResultService {
break;
case 15:
//电压总谐波畸变率
sql = "SELECT time as time, v_thd as aValue FROM data_v WHERE " + stringBuilder.toString() +
sql = "SELECT time as time, v_thd as aValue FROM data_v WHERE " + stringBuilder +
" order by time asc tz('Asia/Shanghai');";
topLimit = overlimit.getUaberrance();
unit.add("%");
@@ -811,7 +839,7 @@ public class HistoryResultServiceImpl implements HistoryResultService {
break;
case 22:
//负序电流
sql = "SELECT time as time, i_neg as aValue FROM data_i WHERE " + stringBuilder.toString() +
sql = "SELECT time as time, i_neg as aValue FROM data_i WHERE " + stringBuilder +
" order by time asc tz('Asia/Shanghai');";
topLimit = overlimit.getINeg();
unit.add("A");
@@ -819,8 +847,8 @@ public class HistoryResultServiceImpl implements HistoryResultService {
break;
case 30:
//频率 V9暂时代表Freq
sql = "SELECT time as time, freq as aValue FROM data_v WHERE " + stringBuilder.toString() +
" and phasic_type ='T' order by time asc tz('Asia/Shanghai');";
sql = "SELECT time as time, freq as aValue FROM data_v WHERE " + stringBuilder +
" order by time asc tz('Asia/Shanghai');";
topLimit = 50 + overlimit.getFreqDev();
lowerLimit = 50 - overlimit.getFreqDev();
unit.add("Hz");
@@ -828,23 +856,23 @@ public class HistoryResultServiceImpl implements HistoryResultService {
break;
case 40:
//谐波电压含有率
sql = "SELECT time as time, v_" + number + " as aValue FROM data_harmrate_v WHERE " + stringBuilder.toString() +
" and (phasic_type ='A' or phasic_type ='B' or phasic_type ='C') group by phasic_type order by time asc tz('Asia/Shanghai');";
sql = "SELECT time as time, v_" + number + " as aValue FROM data_harmrate_v WHERE " + stringBuilder +
" order by time asc tz('Asia/Shanghai');";
topLimit = PubUtils.getValueByMethod(overlimit, "getUharm", number);
unit.add("%");
targetName = "谐波电压含有率";
break;
case 41:
//谐波电流含有率
sql = "SELECT time as time, i_" + number + " as aValue FROM data_harmrate_i WHERE " + stringBuilder.toString() +
" and (phasic_type ='A' or phasic_type ='B' or phasic_type ='C') group by phasic_type order by time asc tz('Asia/Shanghai');";
sql = "SELECT time as time, i_" + number + " as aValue FROM data_harmrate_i WHERE " + stringBuilder +
" order by time asc tz('Asia/Shanghai');";
unit.add("%");
targetName = "谐波电流含有率";
break;
case 43:
//谐波电流幅值
sql = "SELECT time as time, i_" + number + " as aValue FROM data_i WHERE " + stringBuilder.toString() +
" and (phasic_type ='A' or phasic_type ='B' or phasic_type ='C') group by phasic_type order by time asc tz('Asia/Shanghai');";
sql = "SELECT time as time, i_" + number + " as aValue FROM data_i WHERE " + stringBuilder +
" order by time asc tz('Asia/Shanghai');";
topLimit = PubUtils.getValueByMethod(overlimit, "getIharm", number);
unit.add("A");
targetName = "谐波电流幅值";
@@ -852,24 +880,24 @@ public class HistoryResultServiceImpl implements HistoryResultService {
case 46:
//间谐波电压含有率
sql = "SELECT time as time, v_" + number + " as aValue FROM data_inharmrate_v WHERE " + stringBuilder.toString() +
" and (phasic_type ='A' or phasic_type ='B' or phasic_type ='C') group by phasic_type order by time asc tz('Asia/Shanghai');";
sql = "SELECT time as time, v_" + number + " as aValue FROM data_inharmrate_v WHERE " + stringBuilder +
" order by time asc tz('Asia/Shanghai');";
topLimit = PubUtils.getValueByMethod(overlimit, "getInuharm", number);
unit.add("%");
targetName = "间谐波电压含有率";
break;
case 61:
//长时闪变
sql = "SELECT time as time, plt as aValue FROM data_plt WHERE " + stringBuilder.toString() +
" and (phasic_type ='A' or phasic_type ='B' or phasic_type ='C') group by phasic_type order by time asc tz('Asia/Shanghai');";
sql = "SELECT time as time, plt as aValue FROM data_plt WHERE " + stringBuilder +
" order by time asc tz('Asia/Shanghai');";
targetName = "长时闪变";
topLimit = overlimit.getFlicker();
break;
default:
break;
}
queryResult = influxDbUtils.query(sql);
queryResultLimitVO.setQueryResult(queryResult);
List<HarmonicHistoryData> harmonicHistoryData = commonMapper.getHistoryResult(sql);
queryResultLimitVO.setHarmonicHistoryDataList(harmonicHistoryData);
queryResultLimitVO.setTopLimit(topLimit);
queryResultLimitVO.setLowerLimit(lowerLimit);
queryResultLimitVO.setPhaiscType(Collections.singletonList(phasicType));
@@ -891,22 +919,16 @@ public class HistoryResultServiceImpl implements HistoryResultService {
private HistoryDataResultVO getNormCondition(NormHistoryParam normHistoryParam) {
HistoryDataResultVO historyDataResultVO = new HistoryDataResultVO();
QueryResultLimitVO queryResultLimitVO = getQueryNormDataResult(normHistoryParam);
QueryResult queryResult = queryResultLimitVO.getQueryResult();
BeanUtil.copyProperties(queryResultLimitVO, historyDataResultVO);
List<QueryResult.Series> list = queryResult.getResults().get(0).getSeries();
//获取查询返回的结果集
List<HarmonicHistoryData> harmonicHistoryDataList = queryResultLimitVO.getHarmonicHistoryDataList();
List<Date> time = new ArrayList<>();
List<Float> fValue = new ArrayList<>();
List<List<Object>> objectListData = new ArrayList<>();
if (!CollectionUtils.isEmpty(list)) {
List<List<Object>> listData = queryResult.getResults().get(0).getSeries().get(0).getValues();
for (int i = 0; i < listData.size(); i++) {
List<Object> objectList = listData.get(i);
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX");
TimeZone tx = TimeZone.getTimeZone("Asia/Kolkata");
formatter.setTimeZone(tx);
Date d = formatter.parse(objectList.get(0).toString());
time.add(d);
fValue.add(BigDecimal.valueOf(Float.parseFloat(objectList.get(1).toString())).setScale(4, BigDecimal.ROUND_HALF_UP).floatValue());
if (CollectionUtil.isNotEmpty(harmonicHistoryDataList)) {
for (HarmonicHistoryData harmonicHistoryData : harmonicHistoryDataList) {
time.add(new Date(harmonicHistoryData.getTime().toEpochMilli()));
fValue.add(BigDecimal.valueOf(harmonicHistoryData.getAValue()).setScale(4, BigDecimal.ROUND_HALF_UP).floatValue());
}
for (int i = 0; i < time.size(); i++) {
List<Object> objects = new ArrayList<>();
@@ -961,6 +983,103 @@ public class HistoryResultServiceImpl implements HistoryResultService {
return statHarmonicOrgVOS;
}
@Override
public HarmHistoryDataDTO getHistoryHarmData(HistoryHarmParam historyHarmParam) {
List<HarmData> historyData;
float overLimit;
Overlimit overlimit = lineFeignClient.getOverLimitData(historyHarmParam.getLineId()).getData();
//判断是电流还是电压谐波
if (historyHarmParam.getType() == 0) {
historyData = getIHistoryData(historyHarmParam);
overLimit = PubUtils.getValueByMethod(overlimit, "getIharm", historyHarmParam.getTime());
} else {
historyData = getVHistoryData(historyHarmParam);
overLimit = PubUtils.getValueByMethod(overlimit, "getUharm", historyHarmParam.getTime());
}
return new HarmHistoryDataDTO(historyData, overLimit);
}
/***
* 获取指定次数 监测点的历史谐波电流数据
* @author hongawen
* @date 2023/7/19 10:03
*/
private List<HarmData> getIHistoryData(HistoryHarmParam historyHarmParam) {
LineDetailDataVO lineDetailData = lineFeignClient.getLineDetailData(historyHarmParam.getLineId()).getData();
List<HarmData> historyData;
InfluxQueryWrapper influxQueryWrapper = new InfluxQueryWrapper(DataI.class, HarmData.class);
influxQueryWrapper
.select(DataI::getTime)
.max("i_" + historyHarmParam.getTime(), "value")
.between(DataI::getTime, historyHarmParam.getSearchBeginTime().concat(" 00:00:00"), historyHarmParam.getSearchEndTime().concat(" 23:59:59"))
.eq(DataI::getLineId, historyHarmParam.getLineId())
.or(DataI::getPhaseType, Stream.of(InfluxDBTableConstant.PHASE_TYPE_A, InfluxDBTableConstant.PHASE_TYPE_B, InfluxDBTableConstant.PHASE_TYPE_C).collect(Collectors.toList()))
//以时间分组时,需要加上时间间隔,比如此处需要加上监测点的采样间隔
.groupBy("time(" + lineDetailData.getTimeInterval() + "m)")
.timeAsc();
historyData = dataIMapper.getIHistoryData(influxQueryWrapper);
if (CollectionUtils.isEmpty(historyData)) {
//如果数据为空,则提示给用户暂无数据
throw new BusinessException(HarmonicResponseEnum.NO_DATA);
}
//最新两条数据的间隔与监测点查出的间隔做对比,返回一个合理的间隔
int lineInterval = getInterval(lineDetailData.getTimeInterval(), PubUtils.instantToDate(historyData.get(historyData.size() - 1).getTime()), PubUtils.instantToDate(historyData.get(historyData.size() - 2).getTime()));
historyData = dealHistoryData(historyData, lineInterval);
if (CollectionUtils.isEmpty(historyData)) {
//如果数据为空,则提示给用户暂无数据
throw new BusinessException(HarmonicResponseEnum.NO_DATA);
}
//根据时间天数,获取理论上多少次用采数据
List<String> dateStr = PubUtils.getTimes(DateUtil.beginOfDay(DateUtil.parse(historyHarmParam.getSearchBeginTime())), DateUtil.endOfDay(DateUtil.parse(historyHarmParam.getSearchEndTime())));
int dueTimes = dateStr.size() * 1440 / lineInterval;
int realTimes = historyData.size();
if (dueTimes != realTimes) {
//期待值与实际值不等,则提示用户时间范围内谐波数据完整性不足
throw new BusinessException(HarmonicResponseEnum.INSUFFICIENCY_OF_INTEGRITY);
}
return historyData.stream().sorted(Comparator.comparing(HarmData::getTime)).collect(Collectors.toList());
}
/**
* 获取谐波电压的数据
* <p>
* 因历史谐波表data_harmrate_v
*/
private List<HarmData> getVHistoryData(HistoryHarmParam historyHarmParam) {
LineDetailDataVO lineDetailData = lineFeignClient.getLineDetailData(historyHarmParam.getLineId()).getData();
List<HarmData> historyData;
InfluxQueryWrapper influxQueryWrapper = new InfluxQueryWrapper(DataHarmRateV.class, HarmData.class);
influxQueryWrapper
.select(DataHarmRateV::getTime)
.max("v_" + historyHarmParam.getTime(), "value")
.between(DataHarmRateV::getTime, historyHarmParam.getSearchBeginTime().concat(" 00:00:00"), historyHarmParam.getSearchEndTime().concat(" 23:59:59"))
.eq(DataHarmRateV::getLineId, historyHarmParam.getLineId())
.or(DataHarmRateV::getPhaseType, Stream.of(InfluxDBTableConstant.PHASE_TYPE_A, InfluxDBTableConstant.PHASE_TYPE_B, InfluxDBTableConstant.PHASE_TYPE_C).collect(Collectors.toList()))
.groupBy("time(" + lineDetailData.getTimeInterval() + "m)")
.timeAsc();
historyData = dataHarmRateVMapper.getHarmRateVHistoryData(influxQueryWrapper);
if (CollectionUtils.isEmpty(historyData)) {
//如果数据为空,则提示给用户暂无数据
throw new BusinessException(HarmonicResponseEnum.NO_DATA);
}
int lineInterval = getInterval(lineDetailData.getTimeInterval(), PubUtils.instantToDate(historyData.get(historyData.size() - 1).getTime()), PubUtils.instantToDate(historyData.get(historyData.size() - 2).getTime()));
//最新两条数据的间隔与监测点查出的间隔做对比,返回一个合理的间隔
historyData = dealHistoryData(historyData, lineInterval);
if (CollectionUtils.isEmpty(historyData)) {
//如果数据为空,则提示给用户暂无数据
throw new BusinessException(HarmonicResponseEnum.NO_DATA);
}
//根据时间天数,获取理论上多少次用采数据
List<String> dateStr = PubUtils.getTimes(DateUtil.beginOfDay(DateUtil.parse(historyHarmParam.getSearchBeginTime())), DateUtil.endOfDay(DateUtil.parse(historyHarmParam.getSearchEndTime())));
int dueTimes = dateStr.size() * 1440 / lineInterval;
int realTimes = historyData.size();
if (dueTimes != realTimes) {
//期待值与实际值不等,则提示用户时间范围内谐波数据完整性不足
throw new BusinessException(HarmonicResponseEnum.INSUFFICIENCY_OF_INTEGRITY);
}
return historyData.stream().sorted(Comparator.comparing(HarmData::getTime)).collect(Collectors.toList());
}
/**
* 使用流对象的方法插入数据
*/
@@ -981,6 +1100,149 @@ public class HistoryResultServiceImpl implements HistoryResultService {
return list;
}
/**
* 根据库中查询的数据,进行数据补齐操作
*
* @param beforeDeal 库中实际的历史谐波数据
*/
private List<HarmData> dealHistoryData(List<HarmData> beforeDeal, int lineInterval) {
List<HarmData> result = new ArrayList<>();
try {
if (CollectionUtils.isEmpty(beforeDeal)) {
return result;
} else {
//先将查询数据按日进行收集
Map<String/*yyyy-MM-dd的时间格式*/, Map<Date, HarmData>/*当前天的所有谐波数据*/> dayHistoryDatas = new HashMap<>();
for (HarmData harmData : beforeDeal) {
Date time = PubUtils.instantToDate(harmData.getTime());
String date = DateUtil.format(time, DatePattern.NORM_DATE_PATTERN);
if (dayHistoryDatas.containsKey(date)) {
Map<Date, HarmData> harmDataMap = dayHistoryDatas.get(date);
harmDataMap.put(PubUtils.getSecondsAsZero(PubUtils.instantToDate(harmData.getTime())), harmData);
dayHistoryDatas.put(date, harmDataMap);
} else {
Map<Date, HarmData> harmDataMap = new HashMap<>();
harmDataMap.put(PubUtils.getSecondsAsZero(PubUtils.instantToDate(harmData.getTime())), harmData);
dayHistoryDatas.put(date, harmDataMap);
}
}
//将数据按日期处理后,开始进行完整性判断,满足完整性则进行补齐,否则返回空数据
Set<String> days = dayHistoryDatas.keySet();
for (String day : days) {
//获取出当天的历史谐波数据
Map<Date, HarmData> harmDataMap = dayHistoryDatas.get(day);
if (CollectionUtils.isEmpty(harmDataMap)) {
continue;
}
int dueTimes = 1440 / lineInterval;
int realTimes = harmDataMap.size();
double integrity = (double) realTimes / (double) dueTimes;
if (integrity < 0.9 || integrity >= 1.0) {
//完整性不足,则返回原数据
Set<Date> dates = harmDataMap.keySet();
for (Date time : dates) {
result.add(harmDataMap.get(time));
}
} else if (integrity < 1.0) {
//进行数据补齐,数据补齐需要根据监测点测量间隔,最好是MAP格式 map的key是yyyy-MM-dd HH:mm
List<HarmData> afterDeal = new ArrayList<>();
String timeTemp = day + " 00:00:00";
Date date = DateUtil.parse(timeTemp, DatePattern.NORM_DATETIME_PATTERN);
for (int i = 0; i < dueTimes; i++) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.MINUTE, lineInterval * i);
HarmData temp = harmDataMap.get(calendar.getTime());
if (temp != null && temp.getValue() != null) {
afterDeal.add(temp);
} else {
//递归找到前面的值
Float preValue = getPreHarmValue(date, calendar.getTime(), harmDataMap, lineInterval);
//递归找到后面的值
Float appendValue = getAppendHarmValue(date, calendar.getTime(), harmDataMap, lineInterval);
HarmData harmData = new HarmData();
harmData.setTime(PubUtils.dateToInstant(calendar.getTime()));
//还需要判断前值和后值为空的情况
if (null == preValue && null == appendValue) {
harmData.setValue(0.0f);
} else if (null == preValue) {
harmData.setValue(appendValue);
} else if (null == appendValue) {
harmData.setValue(preValue);
} else {
harmData.setValue((preValue + appendValue) / 2);
}
afterDeal.add(harmData);
}
}
result.addAll(afterDeal);
}
}
}
} catch (Exception e) {
log.error("开始处理历史电压谐波数据失败,失败原因:{}", e.toString());
throw new BusinessException(HarmonicResponseEnum.INSUFFICIENCY_OF_INTEGRITY);
}
return result;
}
/**
* 递归找前值 谐波数据
*
* @param date 起始时间
* @param time 当前事件
* @param beforeDeal 处理前的数据
*/
private Float getPreHarmValue(Date date, Date time, Map<Date, HarmData> beforeDeal, int interval) {
Float result;
if (date.getTime() >= time.getTime()) {
return null;
} else {
Calendar calendar = Calendar.getInstance();
calendar.setTime(time);
interval = -interval;
calendar.add(Calendar.MINUTE, interval);
HarmData temp = beforeDeal.get(calendar.getTime());
if (temp == null || temp.getValue() == null) {
result = getPreHarmValue(date, calendar.getTime(), beforeDeal, Math.abs(interval));
} else {
result = temp.getValue();
}
}
return result;
}
/**
* 递归找后置 谐波数据
*
* @param date 起始时间
* @param time 截止时间
*/
private Float getAppendHarmValue(Date date, Date time, Map<Date, HarmData> beforeDeal, int interval) {
Float result;
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.DAY_OF_MONTH, 1);
calendar.add(Calendar.MINUTE, -interval);
if (calendar.getTimeInMillis() <= time.getTime()) {
return null;
} else {
Calendar calendar1 = Calendar.getInstance();
calendar1.setTime(time);
calendar1.add(Calendar.MINUTE, interval);
HarmData temp = beforeDeal.get(calendar1.getTime());
if (temp == null || temp.getValue() == null) {
result = getAppendHarmValue(date, calendar1.getTime(), beforeDeal, interval);
} else {
result = temp.getValue();
}
}
return result;
}
// /**
// * 获取季度时间段
// * @param date
@@ -1037,4 +1299,26 @@ public class HistoryResultServiceImpl implements HistoryResultService {
// return result;
// }
/**
* 获取合理的测量间隔
*/
private int getInterval(int lineInterval, Date lastOne, Date lastTwo) {
int interval = 0;
Calendar one = Calendar.getInstance();
one.setTime(lastOne);
Calendar two = Calendar.getInstance();
two.setTime(lastTwo);
long oneTime = lastOne.getTime();
long twoTime = lastTwo.getTime();
long intvalTime = oneTime - twoTime;
long databaseInterval = lineInterval * 60 * 1000;
if (oneTime < twoTime || intvalTime >= databaseInterval) {
interval = lineInterval;
}
if (intvalTime < databaseInterval) {
interval = (int) (intvalTime / (1000 * 60));
}
return interval;
}
}

View File

@@ -21,7 +21,6 @@ import com.njcn.harmonic.pojo.dto.PublicDTO;
import com.njcn.harmonic.pojo.vo.IntegrityIconVO;
import com.njcn.harmonic.pojo.vo.IntegrityVO;
import com.njcn.harmonic.service.IntegrityService;
import com.njcn.influxdb.utils.InfluxDbUtils;
import com.njcn.poi.excel.ExcelUtil;
import com.njcn.poi.pojo.bo.BaseLineExcelBody;
import com.njcn.poi.pojo.bo.BaseLineProExcelBody;
@@ -54,8 +53,6 @@ public class IntegrityServiceImpl implements IntegrityService {
private final IntegrityMapper integrityMapper;
private final InfluxDbUtils influxDbUtils;
private final GeneralDeviceInfoClient generalDeviceInfoClient;
private final GeneralInfo generalInfo;

View File

@@ -8,16 +8,13 @@ import com.njcn.device.pq.api.GeneralDeviceInfoClient;
import com.njcn.device.pq.pojo.dto.GeneralDeviceDTO;
import com.njcn.device.pq.pojo.param.DeviceInfoParam;
import com.njcn.device.pq.pojo.param.OnlineRateParam;
import com.njcn.device.pq.pojo.po.OnlineRate;
import com.njcn.device.pq.pojo.vo.RStatOnlinerateVO;
import com.njcn.harmonic.mapper.OnlineRateDataMapper;
import com.njcn.harmonic.pojo.dto.PublicDTO;
import com.njcn.harmonic.pojo.vo.OnlineRateCensusVO;
import com.njcn.harmonic.pojo.vo.OnlineRateVO;
import com.njcn.harmonic.service.OnlineRateDataService;
import com.njcn.influxdb.utils.InfluxDbUtils;
import lombok.AllArgsConstructor;
import org.influxdb.dto.QueryResult;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
@@ -27,7 +24,6 @@ import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import static com.njcn.influxdb.param.InfluxDBPublicParam.*;
/**
* 类的介绍:

View File

@@ -8,7 +8,6 @@ import com.njcn.device.pq.api.LineFeignClient;
import com.njcn.device.pq.pojo.dto.GeneralDeviceDTO;
import com.njcn.device.pq.pojo.dto.OverLimitLineDTO;
import com.njcn.device.pq.pojo.dto.PollutionParamDTO;
import com.njcn.device.pq.pojo.dto.WarningSubstationDTO;
import com.njcn.harmonic.constant.Param;
import com.njcn.harmonic.enums.HarmonicResponseEnum;
import com.njcn.harmonic.pojo.photoVO.WarningAreaVO;
@@ -18,7 +17,7 @@ import com.njcn.harmonic.pojo.po.LimitRate;
import com.njcn.harmonic.pojo.po.LimitTarget;
import com.njcn.harmonic.pojo.vo.OverAreaVO;
import com.njcn.harmonic.service.PhotovoltaicService;
import com.njcn.influxdb.utils.InfluxDbUtils;
import com.njcn.influx.imapper.CommonMapper;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.influxdb.dto.QueryResult;
@@ -45,89 +44,89 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService {
private final GeneralDeviceInfoClient generalDeviceInfoClient;
private final InfluxDbUtils influxDbUtils;
private final LineFeignClient lineFeignClient;
private final CommonMapper commonMapper;
@Override
@SuppressWarnings("unchecked")
public Page<WarningAreaVO> areaWarningManage(OverAreaVO param) {
List<String> line = new ArrayList<>();
Map<String,List<LimitRate>> map = new HashMap<>();
Map<String,List<EventDetail>> map2 = new HashMap<>();
Map<String, List<LimitRate>> map = new HashMap<>();
Map<String, List<EventDetail>> map2 = new HashMap<>();
Page<WarningAreaVO> page = new Page<>();
List<WarningAreaVO> list = new ArrayList<>();
page.setSize(param.getPageSize());
page.setCurrent(param.getPageNum());
List<GeneralDeviceDTO> subList = generalDeviceInfoClient.getPracticalRunDeviceInfo(param).getData();
if (!CollectionUtils.isEmpty(subList)){
if (!CollectionUtils.isEmpty(subList)) {
page.setTotal(subList.size());
int pages = (int)Math.ceil(subList.size()*1.0/param.getPageSize());
int pages = (int) Math.ceil(subList.size() * 1.0 / param.getPageSize());
page.setPages(pages);
List<List<GeneralDeviceDTO>> pageList = Lists.partition(subList,param.getPageSize());
List<GeneralDeviceDTO> temList = pageList.get(param.getPageNum()-1);
temList.forEach(item->{
List<List<GeneralDeviceDTO>> pageList = Lists.partition(subList, param.getPageSize());
List<GeneralDeviceDTO> temList = pageList.get(param.getPageNum() - 1);
temList.forEach(item -> {
line.addAll(item.getLineIndexes());
});
if (!CollectionUtils.isEmpty(line)){
List<LimitRate> limitRateList = (List<LimitRate>)getAllData(line,param.getSearchBeginTime(),param.getSearchEndTime(), Param.LIMIT_RATE);
if (!CollectionUtils.isEmpty(limitRateList)){
if (!CollectionUtils.isEmpty(line)) {
List<LimitRate> limitRateList = (List<LimitRate>) getAllData(line, param.getSearchBeginTime(), param.getSearchEndTime(), Param.LIMIT_RATE);
if (!CollectionUtils.isEmpty(limitRateList)) {
map = limitRateList.stream().collect(Collectors.groupingBy(LimitRate::getLineId));
}
List<EventDetail> eventDetailList = getEventDetail(line,param.getSearchBeginTime(),param.getSearchEndTime());
if (!CollectionUtils.isEmpty(eventDetailList)){
List<EventDetail> eventDetailList = getEventDetail(line, param.getSearchBeginTime(), param.getSearchEndTime());
if (!CollectionUtils.isEmpty(eventDetailList)) {
map2 = eventDetailList.stream().collect(Collectors.groupingBy(EventDetail::getLineId));
}
}
if (!CollectionUtils.isEmpty(temList)){
if (!CollectionUtils.isEmpty(temList)) {
for (GeneralDeviceDTO item : temList) {
int onlineMonitorCount = 0,alertMonitorCount = 0,alertCount = 0,freqCount = 0,voltageCount = 0,ubalanceCount = 0,flickerCount = 0,iNegCount = 0,uharmCount = 0,iharmCount = 0,inuharmCount = 0;
int freqCounts = 0,voltageCounts = 0,uharmCounts = 0,iharmCounts = 0,ubalanceCounts = 0,flickerCounts = 0,inuharmCounts = 0,iNegCounts = 0;
int eventUp = 0,eventDown = 0,eventInterrupt = 0,eventUps = 0,eventDowns = 0,eventInterrupts = 0;
int onlineMonitorCount = 0, alertMonitorCount = 0, alertCount = 0, freqCount = 0, voltageCount = 0, ubalanceCount = 0, flickerCount = 0, iNegCount = 0, uharmCount = 0, iharmCount = 0, inuharmCount = 0;
int freqCounts = 0, voltageCounts = 0, uharmCounts = 0, iharmCounts = 0, ubalanceCounts = 0, flickerCounts = 0, inuharmCounts = 0, iNegCounts = 0;
int eventUp = 0, eventDown = 0, eventInterrupt = 0, eventUps = 0, eventDowns = 0, eventInterrupts = 0;
WarningAreaVO warningAreaVO = new WarningAreaVO();
//单位id
warningAreaVO.setId(item.getIndex());
//单位名称
warningAreaVO.setName(item.getName());
if (!CollectionUtils.isEmpty(item.getLineIndexes())){
if (!CollectionUtils.isEmpty(item.getLineIndexes())) {
for (String item2 : item.getLineIndexes()) {
//谐波统计
if (!CollectionUtils.isEmpty(map.get(item2))){
if (!CollectionUtils.isEmpty(map.get(item2))) {
LimitRate limitRate = map.get(item2).get(0);
if (!Objects.isNull(limitRate)){
if (!Objects.isNull(limitRate)) {
onlineMonitorCount++;
if (limitRate.getFreqDevOverTime() > 0 || limitRate.getVoltageDevOverTime() > 0 || limitRate.getUBalanceOverTime() > 0 || limitRate.getFlickerOverTime() > 0 || limitRate.getINegOverTime() > 0 || limitRate.getUHarm2OverTime() > 0 || limitRate.getIHarm2OverTime() > 0 || limitRate.getInuHarm1OverTime() > 0){
if (limitRate.getFreqDevOverTime() > 0 || limitRate.getVoltageDevOverTime() > 0 || limitRate.getUBalanceOverTime() > 0 || limitRate.getFlickerOverTime() > 0 || limitRate.getINegOverTime() > 0 || limitRate.getUHarm2OverTime() > 0 || limitRate.getIHarm2OverTime() > 0 || limitRate.getInuHarm1OverTime() > 0) {
alertMonitorCount++;
}
if (limitRate.getFreqDevOverTime() > 0){
if (limitRate.getFreqDevOverTime() > 0) {
freqCount++;
freqCounts = freqCounts + limitRate.getFreqDevOverTime();
}
if (limitRate.getVoltageDevOverTime() > 0){
if (limitRate.getVoltageDevOverTime() > 0) {
voltageCount++;
voltageCounts = voltageCounts + limitRate.getVoltageDevOverTime();
}
if (limitRate.getUHarm2OverTime() > 0){
if (limitRate.getUHarm2OverTime() > 0) {
uharmCount++;
uharmCounts = uharmCounts + limitRate.getUHarm2OverTime();
}
if (limitRate.getIHarm2OverTime() > 0){
if (limitRate.getIHarm2OverTime() > 0) {
iharmCount++;
iharmCounts = iharmCounts + limitRate.getIHarm2OverTime();
}
if (limitRate.getUBalanceOverTime() > 0){
if (limitRate.getUBalanceOverTime() > 0) {
ubalanceCount++;
ubalanceCounts = ubalanceCounts + limitRate.getUBalanceOverTime();
}
if (limitRate.getFlickerOverTime() > 0){
if (limitRate.getFlickerOverTime() > 0) {
flickerCount++;
flickerCounts = flickerCounts + limitRate.getFlickerOverTime();
}
if (limitRate.getInuHarm1OverTime() > 0){
if (limitRate.getInuHarm1OverTime() > 0) {
inuharmCount++;
inuharmCounts = inuharmCounts + limitRate.getInuHarm1OverTime();
}
if (limitRate.getINegOverTime() > 0){
if (limitRate.getINegOverTime() > 0) {
iNegCount++;
iNegCounts = iNegCounts + limitRate.getINegOverTime();
}
@@ -138,68 +137,68 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService {
}
}
//暂降统计
if (!CollectionUtils.isEmpty(map2.get(item2))){
if (!CollectionUtils.isEmpty(map2.get(item2))) {
List<EventDetail> eventDetailList = map2.get(item2);
if (!CollectionUtils.isEmpty(eventDetailList)){
if (!CollectionUtils.isEmpty(eventDetailList)) {
for (EventDetail item3 : eventDetailList) {
if (item3.getWaveType() == 1){
if (item3.getWaveType() == 1) {
eventDowns++;
} else if (item3.getWaveType() == 2){
} else if (item3.getWaveType() == 2) {
eventUps++;
} else if (item3.getWaveType() == 3){
} else if (item3.getWaveType() == 3) {
eventInterrupts++;
}
}
}
}
if (eventDowns > 0){
if (eventDowns > 0) {
eventDown++;
}
if (eventUps > 0){
if (eventUps > 0) {
eventUp++;
}
if (eventInterrupts > 0){
if (eventInterrupts > 0) {
eventInterrupt++;
}
}
}
//在线监测点数量(个)
warningAreaVO.setOnlineMonitorCounts(onlineMonitorCount);
if (onlineMonitorCount != 0){
if (onlineMonitorCount != 0) {
//告警监测点数量(个)
warningAreaVO.setAlertMonitorCounts(alertMonitorCount);
//告警次数
warningAreaVO.setAlertCounts(alertCount);
//告警频次(次/点)
warningAreaVO.setAlertAlarmFrequency(alertMonitorCount==0?0: BigDecimal.valueOf(alertCount*1.0/alertMonitorCount).setScale(2, RoundingMode.HALF_UP).doubleValue());
warningAreaVO.setAlertAlarmFrequency(alertMonitorCount == 0 ? 0 : BigDecimal.valueOf(alertCount * 1.0 / alertMonitorCount).setScale(2, RoundingMode.HALF_UP).doubleValue());
//频率偏差
warningAreaVO.setFrequencyDeviation(freqCount==0?0:BigDecimal.valueOf(freqCounts*1.0/freqCount).setScale(2, RoundingMode.HALF_UP).doubleValue());
warningAreaVO.setFrequencyDeviation(freqCount == 0 ? 0 : BigDecimal.valueOf(freqCounts * 1.0 / freqCount).setScale(2, RoundingMode.HALF_UP).doubleValue());
//电压偏差
warningAreaVO.setVoltageDeviation(voltageCount==0?0:BigDecimal.valueOf(voltageCounts*1.0/voltageCount).setScale(2, RoundingMode.HALF_UP).doubleValue());
warningAreaVO.setVoltageDeviation(voltageCount == 0 ? 0 : BigDecimal.valueOf(voltageCounts * 1.0 / voltageCount).setScale(2, RoundingMode.HALF_UP).doubleValue());
//谐波电压
warningAreaVO.setHarmonicVoltage(uharmCount==0?0:BigDecimal.valueOf(uharmCounts*1.0/uharmCount).setScale(2, RoundingMode.HALF_UP).doubleValue());
warningAreaVO.setHarmonicVoltage(uharmCount == 0 ? 0 : BigDecimal.valueOf(uharmCounts * 1.0 / uharmCount).setScale(2, RoundingMode.HALF_UP).doubleValue());
//谐波电流
warningAreaVO.setHarmonicCurrent(iharmCount==0?0:BigDecimal.valueOf(iharmCounts*1.0/iharmCount).setScale(2, RoundingMode.HALF_UP).doubleValue());
warningAreaVO.setHarmonicCurrent(iharmCount == 0 ? 0 : BigDecimal.valueOf(iharmCounts * 1.0 / iharmCount).setScale(2, RoundingMode.HALF_UP).doubleValue());
//三相电压不平衡
warningAreaVO.setThreePhaseVoltageUnbalance(ubalanceCount==0?0:BigDecimal.valueOf(ubalanceCounts*1.0/ubalanceCount).setScale(2, RoundingMode.HALF_UP).doubleValue());
warningAreaVO.setThreePhaseVoltageUnbalance(ubalanceCount == 0 ? 0 : BigDecimal.valueOf(ubalanceCounts * 1.0 / ubalanceCount).setScale(2, RoundingMode.HALF_UP).doubleValue());
//闪变
warningAreaVO.setFlicker(flickerCount==0?0:BigDecimal.valueOf(flickerCounts*1.0/flickerCount).setScale(2, RoundingMode.HALF_UP).doubleValue());
warningAreaVO.setFlicker(flickerCount == 0 ? 0 : BigDecimal.valueOf(flickerCounts * 1.0 / flickerCount).setScale(2, RoundingMode.HALF_UP).doubleValue());
//间谐波电压
warningAreaVO.setInterHarmonic(inuharmCount==0?0:BigDecimal.valueOf(inuharmCounts*1.0/inuharmCount).setScale(2, RoundingMode.HALF_UP).doubleValue());
warningAreaVO.setInterHarmonic(inuharmCount == 0 ? 0 : BigDecimal.valueOf(inuharmCounts * 1.0 / inuharmCount).setScale(2, RoundingMode.HALF_UP).doubleValue());
//负序电流
warningAreaVO.setNegative(iNegCount==0?0:BigDecimal.valueOf(iNegCounts*1.0/iNegCount).setScale(2, RoundingMode.HALF_UP).doubleValue());
warningAreaVO.setNegative(iNegCount == 0 ? 0 : BigDecimal.valueOf(iNegCounts * 1.0 / iNegCount).setScale(2, RoundingMode.HALF_UP).doubleValue());
//电压暂降
warningAreaVO.setVoltageDip(eventDown==0?0:BigDecimal.valueOf(eventDowns*1.0/eventDown).setScale(2, RoundingMode.HALF_UP).doubleValue());
warningAreaVO.setVoltageDip(eventDown == 0 ? 0 : BigDecimal.valueOf(eventDowns * 1.0 / eventDown).setScale(2, RoundingMode.HALF_UP).doubleValue());
//电压暂升
warningAreaVO.setVoltageSwell(eventUp==0?0:BigDecimal.valueOf(eventUps*1.0/eventUp).setScale(2, RoundingMode.HALF_UP).doubleValue());
warningAreaVO.setVoltageSwell(eventUp == 0 ? 0 : BigDecimal.valueOf(eventUps * 1.0 / eventUp).setScale(2, RoundingMode.HALF_UP).doubleValue());
//短时中断
warningAreaVO.setShortInterruption(eventInterrupt==0?0:BigDecimal.valueOf(eventInterrupts*1.0/eventInterrupt).setScale(2, RoundingMode.HALF_UP).doubleValue());
warningAreaVO.setShortInterruption(eventInterrupt == 0 ? 0 : BigDecimal.valueOf(eventInterrupts * 1.0 / eventInterrupt).setScale(2, RoundingMode.HALF_UP).doubleValue());
}
list.add(warningAreaVO);
}
}
}
if (!CollectionUtils.isEmpty(list)){
if (!CollectionUtils.isEmpty(list)) {
List<WarningAreaVO> recordList = new ArrayList<>();
//默认 在线监测点数量 倒叙排序
recordList = list.stream().sorted(Comparator.comparing(WarningAreaVO::getOnlineMonitorCounts).reversed().thenComparing(WarningAreaVO::getName)).collect(Collectors.toList());
@@ -212,84 +211,84 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService {
@Override
@SuppressWarnings("unchecked")
public Page<WarningMonitorVO> monitorWarningManage(OverAreaVO param) {
List<String> line = new ArrayList<>(),temList = new ArrayList<>();
Map<String,List<LimitRate>> map = new HashMap<>();
Map<String,List<EventDetail>> map2 = new HashMap<>();
List<String> line = new ArrayList<>(), temList = new ArrayList<>();
Map<String, List<LimitRate>> map = new HashMap<>();
Map<String, List<EventDetail>> map2 = new HashMap<>();
Page<WarningMonitorVO> page = new Page<>();
List<WarningMonitorVO> list = new ArrayList<>();
page.setSize(param.getPageSize());
page.setCurrent(param.getPageNum());
List<GeneralDeviceDTO> areaList = generalDeviceInfoClient.getPracticalRunDeviceInfo(param).getData();
if (!CollectionUtils.isEmpty(areaList)){
areaList.forEach(item->{
if (!CollectionUtils.isEmpty(areaList)) {
areaList.forEach(item -> {
line.addAll(item.getLineIndexes());
});
if (!CollectionUtils.isEmpty(line)){
if (!CollectionUtils.isEmpty(line)) {
page.setTotal(line.size());
int pages = (int)Math.ceil(line.size()*1.0/param.getPageSize());
int pages = (int) Math.ceil(line.size() * 1.0 / param.getPageSize());
page.setPages(pages);
List<List<String>> pageList = Lists.partition(line,param.getPageSize());
temList = pageList.get(param.getPageNum()-1);
List<List<String>> pageList = Lists.partition(line, param.getPageSize());
temList = pageList.get(param.getPageNum() - 1);
}
if (!CollectionUtils.isEmpty(temList)){
List<LimitRate> limitRateList = (List<LimitRate>)getAllData(temList,param.getSearchBeginTime(),param.getSearchEndTime(), Param.LIMIT_RATE);
if (!CollectionUtils.isEmpty(limitRateList)){
if (!CollectionUtils.isEmpty(temList)) {
List<LimitRate> limitRateList = (List<LimitRate>) getAllData(temList, param.getSearchBeginTime(), param.getSearchEndTime(), Param.LIMIT_RATE);
if (!CollectionUtils.isEmpty(limitRateList)) {
map = limitRateList.stream().collect(Collectors.groupingBy(LimitRate::getLineId));
}
List<EventDetail> eventDetailList = getEventDetail(temList,param.getSearchBeginTime(),param.getSearchEndTime());
if (!CollectionUtils.isEmpty(eventDetailList)){
List<EventDetail> eventDetailList = getEventDetail(temList, param.getSearchBeginTime(), param.getSearchEndTime());
if (!CollectionUtils.isEmpty(eventDetailList)) {
map2 = eventDetailList.stream().collect(Collectors.groupingBy(EventDetail::getLineId));
}
PollutionParamDTO pollutionParamDTO = new PollutionParamDTO();
pollutionParamDTO.setLineList(temList);
List<OverLimitLineDTO> overLimitLineList = lineFeignClient.getOverLimitLineInfo(pollutionParamDTO).getData();
for (OverLimitLineDTO pojo:overLimitLineList) {
for (OverLimitLineDTO pojo : overLimitLineList) {
String item = pojo.getId();
String name = pojo.getLineName();
int alertMonitorCount = 0,alertCount = 0,freqCount = 0,voltageCount = 0,ubalanceCount = 0,flickerCount = 0,iNegCount = 0,uharmCount = 0,iharmCount = 0,inuharmCount = 0;
int freqCounts = 0,voltageCounts = 0,uharmCounts = 0,iharmCounts = 0,ubalanceCounts = 0,flickerCounts = 0,inuharmCounts = 0,iNegCounts = 0;
int eventUp = 0,eventDown = 0,eventInterrupt = 0,eventUps = 0,eventDowns = 0,eventInterrupts = 0;
int alertMonitorCount = 0, alertCount = 0, freqCount = 0, voltageCount = 0, ubalanceCount = 0, flickerCount = 0, iNegCount = 0, uharmCount = 0, iharmCount = 0, inuharmCount = 0;
int freqCounts = 0, voltageCounts = 0, uharmCounts = 0, iharmCounts = 0, ubalanceCounts = 0, flickerCounts = 0, inuharmCounts = 0, iNegCounts = 0;
int eventUp = 0, eventDown = 0, eventInterrupt = 0, eventUps = 0, eventDowns = 0, eventInterrupts = 0;
WarningMonitorVO warningMonitorVO = new WarningMonitorVO();
//监测点id
warningMonitorVO.setId(item);
//监测点名称
warningMonitorVO.setName(name);
//谐波统计
if (!CollectionUtils.isEmpty(map.get(item))){
if (!CollectionUtils.isEmpty(map.get(item))) {
LimitRate limitRate = map.get(item).get(0);
if (!Objects.isNull(limitRate)){
if (limitRate.getFreqDevOverTime() > 0 || limitRate.getVoltageDevOverTime() > 0 || limitRate.getUBalanceOverTime() > 0 || limitRate.getFlickerOverTime() > 0 || limitRate.getINegOverTime() > 0 || limitRate.getUHarm2OverTime() > 0 || limitRate.getIHarm2OverTime() > 0 || limitRate.getInuHarm1OverTime() > 0){
if (!Objects.isNull(limitRate)) {
if (limitRate.getFreqDevOverTime() > 0 || limitRate.getVoltageDevOverTime() > 0 || limitRate.getUBalanceOverTime() > 0 || limitRate.getFlickerOverTime() > 0 || limitRate.getINegOverTime() > 0 || limitRate.getUHarm2OverTime() > 0 || limitRate.getIHarm2OverTime() > 0 || limitRate.getInuHarm1OverTime() > 0) {
alertMonitorCount++;
}
if (limitRate.getFreqDevOverTime() > 0){
if (limitRate.getFreqDevOverTime() > 0) {
freqCount++;
freqCounts = freqCounts + limitRate.getFreqDevOverTime();
}
if (limitRate.getVoltageDevOverTime() > 0){
if (limitRate.getVoltageDevOverTime() > 0) {
voltageCount++;
voltageCounts = voltageCounts + limitRate.getVoltageDevOverTime();
}
if (limitRate.getUHarm2OverTime() > 0){
if (limitRate.getUHarm2OverTime() > 0) {
uharmCount++;
uharmCounts = uharmCounts + limitRate.getUHarm2OverTime();
}
if (limitRate.getIHarm2OverTime() > 0){
if (limitRate.getIHarm2OverTime() > 0) {
iharmCount++;
iharmCounts = iharmCounts + limitRate.getIHarm2OverTime();
}
if (limitRate.getUBalanceOverTime() > 0){
if (limitRate.getUBalanceOverTime() > 0) {
ubalanceCount++;
ubalanceCounts = ubalanceCounts + limitRate.getUBalanceOverTime();
}
if (limitRate.getFlickerOverTime() > 0){
if (limitRate.getFlickerOverTime() > 0) {
flickerCount++;
flickerCounts = flickerCounts + limitRate.getFlickerOverTime();
}
if (limitRate.getInuHarm1OverTime() > 0){
if (limitRate.getInuHarm1OverTime() > 0) {
inuharmCount++;
inuharmCounts = inuharmCounts + limitRate.getInuHarm1OverTime();
}
if (limitRate.getINegOverTime() > 0){
if (limitRate.getINegOverTime() > 0) {
iNegCount++;
iNegCounts = iNegCounts + limitRate.getINegOverTime();
}
@@ -300,59 +299,59 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService {
}
}
//暂降统计
if (!CollectionUtils.isEmpty(map2.get(item))){
if (!CollectionUtils.isEmpty(map2.get(item))) {
List<EventDetail> eventDetailList2 = map2.get(item);
if (!CollectionUtils.isEmpty(eventDetailList2)){
if (!CollectionUtils.isEmpty(eventDetailList2)) {
for (EventDetail item3 : eventDetailList2) {
if (item3.getWaveType() == 1){
if (item3.getWaveType() == 1) {
eventDowns++;
} else if (item3.getWaveType() == 2){
} else if (item3.getWaveType() == 2) {
eventUps++;
} else if (item3.getWaveType() == 3){
} else if (item3.getWaveType() == 3) {
eventInterrupts++;
}
}
}
}
if (eventDowns > 0){
if (eventDowns > 0) {
eventDown++;
}
if (eventUps > 0){
if (eventUps > 0) {
eventUp++;
}
if (eventInterrupts > 0){
if (eventInterrupts > 0) {
eventInterrupt++;
}
//告警次数
warningMonitorVO.setAlertCounts(alertCount);
//告警频次(次/点)
warningMonitorVO.setAlertAlarmFrequency(alertMonitorCount==0?0: BigDecimal.valueOf(alertCount*1.0/alertMonitorCount).setScale(2, RoundingMode.HALF_UP).doubleValue());
warningMonitorVO.setAlertAlarmFrequency(alertMonitorCount == 0 ? 0 : BigDecimal.valueOf(alertCount * 1.0 / alertMonitorCount).setScale(2, RoundingMode.HALF_UP).doubleValue());
//频率偏差
warningMonitorVO.setFrequencyDeviation(freqCount==0?0:BigDecimal.valueOf(freqCounts*1.0/freqCount).setScale(2, RoundingMode.HALF_UP).doubleValue());
warningMonitorVO.setFrequencyDeviation(freqCount == 0 ? 0 : BigDecimal.valueOf(freqCounts * 1.0 / freqCount).setScale(2, RoundingMode.HALF_UP).doubleValue());
//电压偏差
warningMonitorVO.setVoltageDeviation(voltageCount==0?0:BigDecimal.valueOf(voltageCounts*1.0/voltageCount).setScale(2, RoundingMode.HALF_UP).doubleValue());
warningMonitorVO.setVoltageDeviation(voltageCount == 0 ? 0 : BigDecimal.valueOf(voltageCounts * 1.0 / voltageCount).setScale(2, RoundingMode.HALF_UP).doubleValue());
//谐波电压
warningMonitorVO.setHarmonicVoltage(uharmCount==0?0:BigDecimal.valueOf(uharmCounts*1.0/uharmCount).setScale(2, RoundingMode.HALF_UP).doubleValue());
warningMonitorVO.setHarmonicVoltage(uharmCount == 0 ? 0 : BigDecimal.valueOf(uharmCounts * 1.0 / uharmCount).setScale(2, RoundingMode.HALF_UP).doubleValue());
//谐波电流
warningMonitorVO.setHarmonicCurrent(iharmCount==0?0:BigDecimal.valueOf(iharmCounts*1.0/iharmCount).setScale(2, RoundingMode.HALF_UP).doubleValue());
warningMonitorVO.setHarmonicCurrent(iharmCount == 0 ? 0 : BigDecimal.valueOf(iharmCounts * 1.0 / iharmCount).setScale(2, RoundingMode.HALF_UP).doubleValue());
//三相电压不平衡
warningMonitorVO.setThreePhaseVoltageUnbalance(ubalanceCount==0?0:BigDecimal.valueOf(ubalanceCounts*1.0/ubalanceCount).setScale(2, RoundingMode.HALF_UP).doubleValue());
warningMonitorVO.setThreePhaseVoltageUnbalance(ubalanceCount == 0 ? 0 : BigDecimal.valueOf(ubalanceCounts * 1.0 / ubalanceCount).setScale(2, RoundingMode.HALF_UP).doubleValue());
//闪变
warningMonitorVO.setFlicker(flickerCount==0?0:BigDecimal.valueOf(flickerCounts*1.0/flickerCount).setScale(2, RoundingMode.HALF_UP).doubleValue());
warningMonitorVO.setFlicker(flickerCount == 0 ? 0 : BigDecimal.valueOf(flickerCounts * 1.0 / flickerCount).setScale(2, RoundingMode.HALF_UP).doubleValue());
//间谐波电压
warningMonitorVO.setInterHarmonic(inuharmCount==0?0:BigDecimal.valueOf(inuharmCounts*1.0/inuharmCount).setScale(2, RoundingMode.HALF_UP).doubleValue());
warningMonitorVO.setInterHarmonic(inuharmCount == 0 ? 0 : BigDecimal.valueOf(inuharmCounts * 1.0 / inuharmCount).setScale(2, RoundingMode.HALF_UP).doubleValue());
//负序电流
warningMonitorVO.setNegative(iNegCount==0?0:BigDecimal.valueOf(iNegCounts*1.0/iNegCount).setScale(2, RoundingMode.HALF_UP).doubleValue());
warningMonitorVO.setNegative(iNegCount == 0 ? 0 : BigDecimal.valueOf(iNegCounts * 1.0 / iNegCount).setScale(2, RoundingMode.HALF_UP).doubleValue());
//电压暂降
warningMonitorVO.setVoltageDip(eventDown==0?0:BigDecimal.valueOf(eventDowns*1.0/eventDown).setScale(2, RoundingMode.HALF_UP).doubleValue());
warningMonitorVO.setVoltageDip(eventDown == 0 ? 0 : BigDecimal.valueOf(eventDowns * 1.0 / eventDown).setScale(2, RoundingMode.HALF_UP).doubleValue());
//电压暂升
warningMonitorVO.setVoltageSwell(eventUp==0?0:BigDecimal.valueOf(eventUps*1.0/eventUp).setScale(2, RoundingMode.HALF_UP).doubleValue());
warningMonitorVO.setVoltageSwell(eventUp == 0 ? 0 : BigDecimal.valueOf(eventUps * 1.0 / eventUp).setScale(2, RoundingMode.HALF_UP).doubleValue());
//短时中断
warningMonitorVO.setShortInterruption(eventInterrupt==0?0:BigDecimal.valueOf(eventInterrupts*1.0/eventInterrupt).setScale(2, RoundingMode.HALF_UP).doubleValue());
warningMonitorVO.setShortInterruption(eventInterrupt == 0 ? 0 : BigDecimal.valueOf(eventInterrupts * 1.0 / eventInterrupt).setScale(2, RoundingMode.HALF_UP).doubleValue());
list.add(warningMonitorVO);
}
}
if (!CollectionUtils.isEmpty(list)){
if (!CollectionUtils.isEmpty(list)) {
List<WarningMonitorVO> recordList = new ArrayList<>();
//默认 监测点告警次数 倒叙排序
recordList = list.stream().sorted(Comparator.comparing(WarningMonitorVO::getAlertCounts).reversed()).collect(Collectors.toList());
@@ -366,18 +365,19 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService {
/**
* 功能描述: 处理区域在线监测点数、超标监测点数
*
* @param list 集合
* @return
* @author xy
* @date 2022/2/25 15:05
*/
private List<?> getAllData(List<String> list, String startTime, String endTime, String databaseName){
private List<?> getAllData(List<String> list, String startTime, String endTime, String databaseName) {
List<?> result = new ArrayList<>();
StringBuilder stringBuilder = new StringBuilder();
StringBuilder stringBuilder1 = new StringBuilder();
stringBuilder.append(Param.TIME + " >= '").append(startTime).append("' and ").append(Param.TIME).append(" <= '").append(endTime).append("' and (");
for (int i=0;i<list.size();i++){
if (list.size() - i != 1){
for (int i = 0; i < list.size(); i++) {
if (list.size() - i != 1) {
stringBuilder.append(Param.LINE_ID + "='").append(list.get(i)).append("' or ");
} else {
stringBuilder.append(Param.LINE_ID + "='").append(list.get(i)).append("')");
@@ -387,35 +387,33 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService {
stringBuilder1.append("sum(freq_dev_overtime) AS freq_dev_overtime,sum(voltage_dev_overtime) AS voltage_dev_overtime,sum(ubalance_overtime) AS ubalance_overtime,sum(flicker_overtime) AS flicker_overtime,sum(i_neg_overtime) AS i_neg_overtime,");
stringBuilder1.append("sum(uaberrance_overtime)+");
for (int i = 2; i <= 25; i++) {
if (i==25){
if (i == 25) {
stringBuilder1.append("sum(uharm_").append(i).append("_overtime) AS ").append("uharm_2").append("_overtime,");
} else {
stringBuilder1.append("sum(uharm_").append(i).append("_overtime)+");
}
}
for (int i = 2; i <= 25; i++) {
if (i==25){
if (i == 25) {
stringBuilder1.append("sum(iharm_").append(i).append("_overtime) AS ").append("iharm_2").append("_overtime,");
} else {
stringBuilder1.append("sum(iharm_").append(i).append("_overtime)+");
}
}
for (int i = 1; i <= 16; i++) {
if (i==16){
if (i == 16) {
stringBuilder1.append("sum(inuharm_").append(i).append("_overtime) AS ").append("inuharm_1").append("_overtime");
} else {
stringBuilder1.append("sum(inuharm_").append(i).append("_overtime)+");
}
}
String sql = "select "+stringBuilder1+" from "+databaseName+" where " + stringBuilder;
QueryResult sqlResult = influxDbUtils.query(sql);
InfluxDBResultMapper resultMapper = new InfluxDBResultMapper();
String sql = "select " + stringBuilder1 + " from " + databaseName + " where " + stringBuilder;
switch (databaseName) {
case Param.LIMIT_TARGET:
result = resultMapper.toPOJO(sqlResult, LimitTarget.class);
result = commonMapper.selectLimitTargetBySql(sql);
break;
case Param.LIMIT_RATE:
result = resultMapper.toPOJO(sqlResult,LimitRate.class);
result = commonMapper.selectLimitTargetBySql(sql);
break;
default:
break;
@@ -423,11 +421,11 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService {
return result;
}
public List<EventDetail> getEventDetail(List<String> list, String startTime, String endTime){
public List<EventDetail> getEventDetail(List<String> list, String startTime, String endTime) {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(Param.TIME + " >= '").append(startTime).append("' and ").append(Param.TIME).append(" <= '").append(endTime).append("' and (");
for (int i=0;i<list.size();i++){
if (list.size() - i != 1){
for (int i = 0; i < list.size(); i++) {
if (list.size() - i != 1) {
stringBuilder.append(Param.LINE_ID + "='").append(list.get(i)).append("' or ");
} else {
stringBuilder.append(Param.LINE_ID + "='").append(list.get(i)).append("')");
@@ -435,9 +433,9 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService {
}
stringBuilder.append(" group by line_id tz('Asia/Shanghai')");
String sql = "select * from pqs_eventdetail where " + stringBuilder;
QueryResult sqlResult = influxDbUtils.query(sql);
// QueryResult sqlResult = influxDbUtils.query(sql);
InfluxDBResultMapper resultMapper = new InfluxDBResultMapper();
return resultMapper.toPOJO(sqlResult, EventDetail.class);
return null;
}
}

View File

@@ -1,261 +0,0 @@
package com.njcn.harmonic.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import com.njcn.common.config.GeneralInfo;
import com.njcn.common.pojo.dto.SimpleDTO;
import com.njcn.device.pms.api.MonitorClient;
import com.njcn.device.pms.api.PmsGeneralDeviceInfoClient;
import com.njcn.device.pms.api.PmsGeneratrixClient;
import com.njcn.device.pms.api.StatationStatClient;
import com.njcn.device.pms.pojo.dto.PmsGeneralDeviceDTO;
import com.njcn.device.pms.pojo.dto.PmsStatationStatInfoDTO;
import com.njcn.device.pms.pojo.param.PmsDeviceInfoParam;
import com.njcn.device.pms.pojo.param.PmsStatationStatInfoParam;
import com.njcn.device.pms.pojo.po.Monitor;
import com.njcn.device.pq.api.GeneralDeviceInfoClient;
import com.njcn.device.pq.api.LineFeignClient;
import com.njcn.device.pq.pojo.dto.GeneralDeviceDTO;
import com.njcn.device.pq.pojo.dto.PollutionLineDTO;
import com.njcn.device.pq.pojo.dto.PollutionParamDTO;
import com.njcn.device.pq.pojo.dto.PollutionSubstationDTO;
import com.njcn.harmonic.constant.Param;
import com.njcn.harmonic.pojo.dto.PublicDTO;
import com.njcn.harmonic.pojo.param.HarmonicPublicParam;
import com.njcn.harmonic.pojo.vo.PollMonitorVO;
import com.njcn.harmonic.pojo.vo.PollutionVO;
import com.njcn.harmonic.service.IPollutionService;
import com.njcn.influxdb.utils.InfluxDbUtils;
import com.njcn.system.enums.DicDataEnum;
import com.njcn.web.utils.RequestUtil;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.influxdb.dto.QueryResult;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
/**
* 类的介绍:
*
* @author xuyang
* @version 1.0.0
* @createTime 2022/2/21 16:43
*/
@Service
@AllArgsConstructor
public class PollutionServiceImpl implements IPollutionService {
private final GeneralDeviceInfoClient generalDeviceInfoClient;
private final PmsGeneralDeviceInfoClient pmsGeneralDeviceInfoClient;
private final StatationStatClient statationStatClient;
private final MonitorClient monitorClient;
private final InfluxDbUtils influxDbUtils = new InfluxDbUtils("admin", "njcnpqs", "http://192.168.1.18:8086", "pqsbase", ""); ;
private final GeneralInfo generalInfo;
private final LineFeignClient lineFeignClient;
/* @Override
public List<PollutionVO> getDeptSubstationRelations(HarmonicPublicParam harmonicPublicParam) {
//用于区分是pms 还是 pq
List<PollutionVO> list = new ArrayList<>();
List<String> lineList = new ArrayList<>();
List<PollutionLineDTO> lineInfo = new ArrayList<>();
PollutionParamDTO paramDTO = new PollutionParamDTO();
harmonicPublicParam.setServerName(generalInfo.getMicroServiceName());
if (StringUtils.isBlank(RequestUtil.getDeptIndex())) {
return list;
}
List<GeneralDeviceDTO> deviceList = generalDeviceInfoClient.getPracticalRunDeviceInfo(harmonicPublicParam).getData();
deviceList.forEach(dept -> {
lineList.addAll(dept.getLineIndexes());
});
if (!CollectionUtils.isEmpty(lineList)) {
paramDTO.setLineList(lineList);
lineInfo = lineFeignClient.getLineInfo(paramDTO).getData();
List<PublicDTO> lineData = getLineDate(lineList, harmonicPublicParam.getSearchBeginTime(), harmonicPublicParam.getSearchEndTime(), harmonicPublicParam.getStatisticalType().getCode());
if (!CollectionUtils.isEmpty(lineData)) {
lineInfo.stream().map(list1 -> lineData.stream().filter(list2 -> Objects.equals(list1.getId(), list2.getId())).findAny().map(m -> {
list1.setData(m.getData());
return list1;
})).collect(Collectors.toList());
}
}
Map<String, List<PollutionLineDTO>> map = lineInfo.stream().collect(Collectors.groupingBy(PollutionLineDTO::getSubstationId));
deviceList.forEach(dept -> {
List<PollutionVO> childrenList = new ArrayList<>();
PollutionVO pollutionVO = new PollutionVO();
pollutionVO.setId(dept.getIndex());
pollutionVO.setName(dept.getName());
if (!CollectionUtils.isEmpty(dept.getSubIndexes())) {
dept.getSubIndexes().forEach(sub -> {
List<PollutionLineDTO> l1 = map.get(sub);
PollutionVO children = new PollutionVO();
children.setId(sub);
children.setPid(dept.getIndex());
children.setName(l1.get(0).getSubstation());
children.setData(l1.stream().max(Comparator.comparing(PollutionLineDTO::getData)).get().getData());
childrenList.add(children);
});
}
if (!CollectionUtils.isEmpty(childrenList)) {
pollutionVO.setChildren(childrenList.stream().sorted(Comparator.comparing(PollutionVO::getData).reversed()).collect(Collectors.toList()));
pollutionVO.setData(childrenList.stream().max(Comparator.comparing(PollutionVO::getData)).get().getData());
}
list.add(pollutionVO);
});
if (!CollectionUtils.isEmpty(list)) {
return list.stream().sorted(Comparator.comparing(PollutionVO::getData).reversed().thenComparing(PollutionVO::getName)).collect(Collectors.toList());
}
return list;
}
@Override
public List<PollutionSubstationDTO> getSubstationInfoById(HarmonicPublicParam deptParam) {
List<PollutionSubstationDTO> list = new ArrayList<>();
deptParam.setServerName(generalInfo.getMicroServiceName());
List<GeneralDeviceDTO> sub = generalDeviceInfoClient.getPracticalRunDeviceInfoAsSubstation(deptParam).getData();
sub.forEach(item -> {
PollutionSubstationDTO pollutionSubstationDTO = lineFeignClient.getSubstationInfo(item.getIndex()).getData();
if (!CollectionUtils.isEmpty(item.getLineIndexes())) {
List<PublicDTO> lineData = getLineDate(item.getLineIndexes(), deptParam.getSearchBeginTime(), deptParam.getSearchEndTime(), deptParam.getStatisticalType().getCode());
if (!CollectionUtils.isEmpty(lineData)) {
pollutionSubstationDTO.setData(lineData.stream().max(Comparator.comparing(PublicDTO::getData)).get().getData());
}
}
list.add(pollutionSubstationDTO);
});
if (!CollectionUtils.isEmpty(list)) {
return list.stream().sorted(Comparator.comparing(PollutionSubstationDTO::getData).reversed().thenComparing(PollutionSubstationDTO::getName)).collect(Collectors.toList());
}
return list;
}
@Override
public List<PollutionLineDTO> getLineInfoById(HarmonicPublicParam harmonicPublicParam) {
harmonicPublicParam.setServerName(generalInfo.getMicroServiceName());
List<PollutionLineDTO> list = new ArrayList<>();
List<String> line = new ArrayList<>();
PollutionParamDTO paramDTO = new PollutionParamDTO();
if (StringUtils.isBlank(RequestUtil.getDeptIndex())) {
return list;
}
List<GeneralDeviceDTO> sub = generalDeviceInfoClient.getPracticalRunDeviceInfoAsSubstation(harmonicPublicParam).getData();
sub.forEach(item -> {
if (Objects.equals(harmonicPublicParam.getId(), item.getIndex())) {
if (!CollectionUtils.isEmpty(item.getLineIndexes())) {
line.addAll(item.getLineIndexes());
}
}
});
if (!CollectionUtils.isEmpty(line)) {
paramDTO.setLineList(line);
list = lineFeignClient.getLineInfo(paramDTO).getData();
List<PublicDTO> lineData = getLineDate(line, harmonicPublicParam.getSearchBeginTime(), harmonicPublicParam.getSearchEndTime(), harmonicPublicParam.getStatisticalType().getCode());
if (!CollectionUtils.isEmpty(lineData)) {
list.stream().map(list1 -> lineData.stream().filter(list2 -> Objects.equals(list1.getId(), list2.getId())).findAny().map(m -> {
list1.setData(m.getData());
return list1;
})).collect(Collectors.toList());
}
} else {
return list;
}
return list.stream().sorted(Comparator.comparing(PollutionLineDTO::getData).reversed().thenComparing(PollutionLineDTO::getName)).collect(Collectors.toList());
}
*/
/* @Override
public List<PollutionLineDTO> getLineRank(HarmonicPublicParam harmonicPublicParam) {
harmonicPublicParam.setServerName(generalInfo.getMicroServiceName());
List<PollutionLineDTO> list = new ArrayList<>();
List<String> lineList = new ArrayList<>();
PollutionParamDTO paramDTO = new PollutionParamDTO();
if (StringUtils.isBlank(RequestUtil.getDeptIndex())) {
return list;
}
List<GeneralDeviceDTO> deviceList = generalDeviceInfoClient.getPracticalRunDeviceInfo(harmonicPublicParam).getData();
deviceList.forEach(item -> {
if (!CollectionUtils.isEmpty(item.getLineIndexes())) {
lineList.addAll(item.getLineIndexes());
}
});
if (!CollectionUtils.isEmpty(lineList)) {
paramDTO.setLineList(lineList);
list = lineFeignClient.getLineInfo(paramDTO).getData();
List<PublicDTO> result = getLineDate(lineList, harmonicPublicParam.getSearchBeginTime(), harmonicPublicParam.getSearchEndTime(), harmonicPublicParam.getStatisticalType().getCode());
if (!CollectionUtils.isEmpty(result)) {
list.stream().map(list1 -> result.stream().filter(list2 -> Objects.equals(list1.getId(), list2.getId())).findAny().map(m -> {
list1.setData(m.getData());
return list1;
})).collect(Collectors.toList());
}
}
list.sort((item1, item2) -> item2.getData().compareTo(item1.getData()));
if (list.size() > Param.UP_LIMIT) {
return list.subList(Param.DOWN_LIMIT, Param.UP_LIMIT);
}
return list;
}*/
/**
* 功能描述:根据监测点id查询influxDB污染指数
*
* @param line 监测点集合
* startTime 开始时间
* endTime 结束时间
* type 指标参数
* @return
* @author xy
* @date 2022/2/21 20:08
*/
private List<PublicDTO> getLineDate(List<String> line, String startTime, String endTime, String type) {
List<PublicDTO> result = new ArrayList<>();
String quota = "";
if (Objects.equals(type, DicDataEnum.XBDY_ENUM.getCode())) {
quota = "harmonic_v";
} else if (Objects.equals(type, DicDataEnum.XBDL_ENUM.getCode())) {
quota = "harmonic_i";
}
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(Param.TIME).append(" >= '").append(startTime).append(Param.START_TIME).append("' and ").append(Param.TIME).append(" <= '").append(endTime).append(Param.END_TIME).append("' and (");
for (int i = 0; i < line.size(); i++) {
if (line.size() - i != 1) {
stringBuilder.append(Param.LINE_ID).append("='").append(line.get(i)).append("' or ");
} else {
stringBuilder.append(Param.LINE_ID).append("='").append(line.get(i)).append("')");
}
}
stringBuilder.append(" group by line_id order by time desc limit 1 tz('Asia/Shanghai')");
String sql = "SELECT line_id," + quota + " FROM harmonic_pollution where " + stringBuilder;
QueryResult sqlResult = influxDbUtils.query(sql);
List<QueryResult.Series> list = sqlResult.getResults().get(0).getSeries();
if (!CollectionUtils.isEmpty(list)) {
list.forEach(po -> {
String index = po.getTags().get(Param.LINE_ID);
List<List<Object>> valueList = po.getValues();
if (!CollectionUtils.isEmpty(valueList)) {
for (List<Object> value : valueList) {
PublicDTO publicDTO = new PublicDTO();
Double data = value.get(2) == null ? 0.0 : BigDecimal.valueOf(Double.parseDouble(value.get(2).toString())).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
publicDTO.setId(index);
publicDTO.setData(data);
result.add(publicDTO);
}
}
});
}
return result;
}
}

View File

@@ -30,15 +30,12 @@ import com.njcn.harmonic.pojo.po.*;
import com.njcn.harmonic.pojo.vo.PollutionSubstationVO;
import com.njcn.harmonic.pojo.vo.PollutionVO;
import com.njcn.harmonic.service.PollutionSubstationService;
import com.njcn.influxdb.utils.InfluxDbUtils;
import com.njcn.system.enums.DicDataEnum;
import com.njcn.user.api.DeptFeignClient;
import com.njcn.user.pojo.po.Dept;
import com.njcn.web.utils.RequestUtil;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.influxdb.dto.QueryResult;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
@@ -91,7 +88,6 @@ public class PollutionSubstationServiceImpl extends ServiceImpl<RStatPollutionSu
private final RMpPollutionDPOMapper rMpPollutionDPOMapper;
private final InfluxDbUtils influxDbUtils = new InfluxDbUtils("admin", "njcnpqs", "http://192.168.1.18:8086", "pqsbase", ""); ;
/**
* @param pollutionSubstationQuryParam
* @Description: getPollutionSubstationData
@@ -578,99 +574,6 @@ public class PollutionSubstationServiceImpl extends ServiceImpl<RStatPollutionSu
return list.stream().sorted(Comparator.comparing(PollutionLineDTO::getData).reversed().thenComparing(PollutionLineDTO::getName)).collect(Collectors.toList());
}
@Override
public List<PollutionLineDTO> getLineRank(HarmonicPublicParam param) {
List<PollutionLineDTO> list= new ArrayList<>();
String pollutionType = param.getStatisticalType ( ).getId ();
String searchBeginTime = "";
if(Objects.equals (param.getReportFlag (),BizParamConstant.STAT_BIZ_YEAR) ){
searchBeginTime = param.getSearchBeginTime ( ).substring (0, 4)+"%";
}else if(Objects.equals (param.getReportFlag (),BizParamConstant.STAT_BIZ_MONTH)){
searchBeginTime = param.getSearchBeginTime ( ).substring (0, 7)+"%";
}else if(Objects.equals (param.getReportFlag (),BizParamConstant.STAT_BIZ_DAY)) {
searchBeginTime = param.getSearchBeginTime ( ).substring (0, 10)+"%";
}
if(param.getType()==0) {
param.setServerName(generalInfo.getMicroServiceName());
List<String> lineList = new ArrayList<>();
PollutionParamDTO paramDTO = new PollutionParamDTO();
if (StringUtils.isBlank(RequestUtil.getDeptIndex())) {
return list;
}
List<GeneralDeviceDTO> deviceList = generalDeviceInfoClient.getPracticalRunDeviceInfo(param).getData();
deviceList.forEach(item -> {
if (!CollectionUtils.isEmpty(item.getLineIndexes())) {
lineList.addAll(item.getLineIndexes());
}
});
if (!CollectionUtils.isEmpty(lineList)) {
paramDTO.setLineList(lineList);
list = lineFeignClient.getLineInfo(paramDTO).getData();
List<PublicDTO> result = getLineDate(lineList, param.getSearchBeginTime(), param.getSearchEndTime(), param.getStatisticalType().getCode());
if (!CollectionUtils.isEmpty(result)) {
list.stream().map(list1 -> result.stream().filter(list2 -> Objects.equals(list1.getId(), list2.getId())).findAny().map(m -> {
list1.setData(m.getData());
return list1;
})).collect(Collectors.toList());
}
}
list.sort((item1, item2) -> item2.getData().compareTo(item1.getData()));
if (list.size() > Param.UP_LIMIT) {
return list.subList(Param.DOWN_LIMIT, Param.UP_LIMIT);
}
return list;
}
PmsDeviceInfoParam pmsDeviceInfoParam = new PmsDeviceInfoParam();
pmsDeviceInfoParam.setDeptIndex(param.getDeptIndex());
//获取统计类型
pmsDeviceInfoParam.setStatisticalType(param.getStatisticalType());
//获取主网台账信息
List<PmsGeneralDeviceDTO> deviceList = pmsGeneralDeviceInfoClient.getPmsDeviceInfoWithInOrg(pmsDeviceInfoParam).getData();
List<String> monitorIdList=new ArrayList<>();
deviceList.forEach(dept -> {
monitorIdList.addAll(dept.getMonitorIdList());
});
if(CollectionUtil.isNotEmpty(monitorIdList)){
//获取监测点数据
List<RMpPollutionDPO> lineData = rMpPollutionDPOMapper.selectMaxList ( monitorIdList,pollutionType,searchBeginTime);
if(CollectionUtil.isEmpty(lineData)){
return list;
}
//获取主网监测点信息
List<Monitor> data = monitorClient.getMonitorList(monitorIdList).getData();
Map<String, Monitor> monitorMap = data.stream().collect(Collectors.toMap(Monitor::getId, Function.identity(), (key1, kye2) -> key1));
lineData.sort((item1, item2) -> item2.getValue().compareTo(item1.getValue()));
if (lineData.size() > Param.UP_LIMIT) {
lineData = lineData.subList(Param.DOWN_LIMIT, Param.UP_LIMIT);
}
PollutionLineDTO dto;
for (RMpPollutionDPO lineDatum : lineData) {
if(monitorMap.containsKey(lineDatum.getLineId())){
Monitor monitor = monitorMap.get(lineDatum.getLineId());
dto=new PollutionLineDTO();
dto.setId(monitor.getId());
dto.setName(monitor.getName());
dto.setPowerCompany(monitor.getOrgName());
dto.setSubstation(monitor.getPowerrId());
dto.setSubstationId(monitor.getPowerrName());
dto.setBusBar(monitor.getLineName());
dto.setData(lineDatum.getValue());
list.add(dto);
}
}
}
return list;
}
@Override
public List<PollutionLineDTO> getLineRankTop10 (HarmonicPublicParam param) {
@@ -752,53 +655,4 @@ public class PollutionSubstationServiceImpl extends ServiceImpl<RStatPollutionSu
return list;
}
/**
* 功能描述:根据监测点id查询influxDB污染指数
*
* @param line 监测点集合
* startTime 开始时间
* endTime 结束时间
* type 指标参数
* @return
* @author xy
* @date 2022/2/21 20:08
*/
private List<PublicDTO> getLineDate(List<String> line, String startTime, String endTime, String type) {
List<PublicDTO> result = new ArrayList<>();
String quota = "";
if (Objects.equals(type, DicDataEnum.V_HARMONIC.getCode())) {
quota = ",harmonic_v";
} else if (Objects.equals(type, DicDataEnum.I_ALL.getCode())) {
quota = ",harmonic_i";
}
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(Param.TIME).append(" >= '").append(startTime).append(Param.START_TIME).append("' and ").append(Param.TIME).append(" <= '").append(endTime).append(Param.END_TIME).append("' and (");
for (int i = 0; i < line.size(); i++) {
if (line.size() - i != 1) {
stringBuilder.append(Param.LINE_ID).append("='").append(line.get(i)).append("' or ");
} else {
stringBuilder.append(Param.LINE_ID).append("='").append(line.get(i)).append("')");
}
}
stringBuilder.append(" group by line_id order by time desc limit 1 tz('Asia/Shanghai')");
String sql = "SELECT line_id" + quota + " FROM harmonic_pollution where " + stringBuilder;
QueryResult sqlResult = influxDbUtils.query(sql);
List<QueryResult.Series> list = sqlResult.getResults().get(0).getSeries();
if (!CollectionUtils.isEmpty(list)) {
list.forEach(po -> {
String index = po.getTags().get(Param.LINE_ID);
List<List<Object>> valueList = po.getValues();
if (!CollectionUtils.isEmpty(valueList)) {
for (List<Object> value : valueList) {
PublicDTO publicDTO = new PublicDTO();
Double data = value.get(2) == null ? 0.0 : BigDecimal.valueOf(Double.parseDouble(value.get(2).toString())).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
publicDTO.setId(index);
publicDTO.setData(data);
result.add(publicDTO);
}
}
});
}
return result;
}
}

View File

@@ -8,14 +8,10 @@ import com.njcn.harmonic.mapper.RStatLimitRateDMapper;
import com.njcn.harmonic.pojo.vo.RStatLimitRateDVO;
import com.njcn.harmonic.pojo.vo.SteadyInfoData;
import com.njcn.harmonic.service.SteadyDataService;
import com.njcn.influxdb.param.InfluxDBPublicParam;
import com.njcn.influxdb.utils.InfluxDbUtils;
import com.njcn.web.pojo.vo.SteadyDataVO;
import lombok.AllArgsConstructor;
import org.apache.commons.lang.StringUtils;
import org.influxdb.dto.QueryResult;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.math.BigDecimal;
import java.text.DecimalFormat;
@@ -32,7 +28,6 @@ import java.util.List;
@AllArgsConstructor
public class SteadyDataServiceImpl implements SteadyDataService {
private final InfluxDbUtils influxDbUtils;
private final RStatLimitRateDMapper rateDMapper;
@Override

View File

@@ -23,8 +23,7 @@ import com.njcn.harmonic.pojo.vo.SteadyExceedRateVO;
import com.njcn.harmonic.service.IRStatLimitRateDService;
import com.njcn.harmonic.service.SteadyExceedRateService;
import com.njcn.harmonic.utils.PubUtils;
import com.njcn.influxdb.param.InfluxDBPublicParam;
import com.njcn.influxdb.utils.InfluxDbUtils;
import com.njcn.influx.pojo.constant.InfluxDBTableConstant;
import lombok.AllArgsConstructor;
import lombok.SneakyThrows;
import org.springframework.stereotype.Service;
@@ -47,8 +46,6 @@ public class SteadyExceedRateServiceImpl implements SteadyExceedRateService {
private final SteadyExceedRateMapper steadyExceedRateMapper;
private final InfluxDbUtils influxDbUtils;
private final IRStatLimitRateDService rateDService;
private final RStatLimitRateDMapper rateDMapper;
@@ -472,7 +469,7 @@ public class SteadyExceedRateServiceImpl implements SteadyExceedRateService {
List<LimitRatePO> limitRatePOS = new ArrayList<>();
List<RStatLimitRateDPO> limitRates = rateDService.list(new LambdaQueryWrapper<RStatLimitRateDPO>()
.in(RStatLimitRateDPO::getLineId, lineIndexes)
.eq(RStatLimitRateDPO::getPhasicType,InfluxDBPublicParam.PHASIC_TYPET)
.eq(RStatLimitRateDPO::getPhasicType, InfluxDBTableConstant.PHASE_TYPE_T)
.ge(StrUtil.isNotBlank(startTime), RStatLimitRateDPO::getTime, DateUtil.beginOfDay(DateUtil.parse(startTime)))
.le(StrUtil.isNotBlank(endTime), RStatLimitRateDPO::getTime, DateUtil.endOfDay(DateUtil.parse(endTime)))
);

View File

@@ -3,7 +3,6 @@ package com.njcn.harmonic.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.njcn.common.config.GeneralInfo;
import com.njcn.common.pojo.dto.SimpleDTO;
@@ -14,19 +13,16 @@ import com.njcn.device.pq.enums.LineBaseEnum;
import com.njcn.device.pq.pojo.dto.GeneralDeviceDTO;
import com.njcn.device.pq.pojo.param.DeviceInfoParam;
import com.njcn.device.pq.pojo.vo.LineDetailDataVO;
import com.njcn.harmonic.constant.Param;
import com.njcn.harmonic.mapper.RMpVThdMapper;
import com.njcn.harmonic.mapper.THDistortionMapper;
import com.njcn.harmonic.pojo.dto.PublicDTO;
import com.njcn.harmonic.pojo.po.RMpVThd;
import com.njcn.harmonic.pojo.po.RStatDataVD;
import com.njcn.harmonic.pojo.vo.RMpVThdVO;
import com.njcn.harmonic.pojo.vo.THDistortionCensusVO;
import com.njcn.harmonic.pojo.vo.THDistortionVO;
import com.njcn.harmonic.service.IRStatDataVDService;
import com.njcn.harmonic.service.THDistortionService;
import com.njcn.harmonic.utils.PubUtils;
import com.njcn.influxdb.utils.InfluxDbUtils;
import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

View File

@@ -14,7 +14,6 @@ import com.njcn.harmonic.pojo.vo.TerminalCensusVO;
import com.njcn.harmonic.pojo.vo.TerminalVO;
import com.njcn.harmonic.service.TerminalService;
import com.njcn.harmonic.utils.PubUtils;
import com.njcn.influxdb.utils.InfluxDbUtils;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
@@ -41,8 +40,6 @@ public class TerminalServiceImpl implements TerminalService {
private final TerminalDataMapper terminalDataMapper;
private final InfluxDbUtils influxDbUtils;
@Override
public List<TerminalVO> getTerminalData(DeviceInfoParam.BusinessParam terminalParam) {
List<TerminalVO> terminalList = new ArrayList<>();

View File

@@ -38,6 +38,8 @@ spring:
multipart:
max-file-size: 100MB
max-request-size: 100MB
jackson:
time-zone: GMT+8
#项目日志的配置