代码调整,bug修改
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -12,6 +12,10 @@ import java.time.format.DateTimeFormatter;
|
||||
@Slf4j
|
||||
@Component
|
||||
@AllArgsConstructor
|
||||
/**
|
||||
* 终端装置异常告警每日统计
|
||||
* @date 2023/4/18
|
||||
*/
|
||||
public class DeviceAbnormalStatisticsJob {
|
||||
private final DeviceAbnormalFeignClient deviceAbnormalFeignClient;
|
||||
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
package com.njcn.executor.handler;
|
||||
|
||||
import com.njcn.prepare.harmonic.api.line.DistortionRateFeignClient;
|
||||
import com.njcn.prepare.harmonic.pojo.param.LineParam;
|
||||
import com.xxl.job.core.handler.annotation.XxlJob;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Date;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@AllArgsConstructor
|
||||
public class DistortionRateJob {
|
||||
private final DistortionRateFeignClient distortionRateFeignClient;
|
||||
|
||||
@XxlJob("DistortionRateJob")
|
||||
public void DistortionRateJob () {
|
||||
log.info("===================DistortionRateJob Start===================");
|
||||
LineParam lineParam = new LineParam();
|
||||
lineParam.setDataDate(LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
|
||||
log.info(lineParam.toString());
|
||||
distortionRateFeignClient.distortionRate(lineParam);
|
||||
log.info("===================DistortionRateJob End=====================");
|
||||
}
|
||||
}
|
||||
@@ -1,592 +0,0 @@
|
||||
/*
|
||||
package com.njcn.executor.handler;
|
||||
|
||||
import com.njcn.device.pq.api.LineFeignClient;
|
||||
import com.njcn.device.pq.pojo.po.Overlimit;
|
||||
import com.njcn.executor.pojo.dto.PollutionDTO;
|
||||
import com.njcn.executor.pojo.vo.*;
|
||||
import com.njcn.harmonic.pojo.dto.PublicDTO;
|
||||
import com.njcn.influxdb.config.InfluxDbConfig;
|
||||
import com.njcn.influxdb.utils.InfluxDbUtils;
|
||||
import com.xxl.job.core.handler.annotation.XxlJob;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.influxdb.InfluxDB;
|
||||
import org.influxdb.dto.BatchPoints;
|
||||
import org.influxdb.dto.Point;
|
||||
import org.influxdb.dto.QueryResult;
|
||||
import org.influxdb.impl.InfluxDBResultMapper;
|
||||
import org.influxdb.querybuilder.SelectQueryImpl;
|
||||
import org.influxdb.querybuilder.WhereNested;
|
||||
import org.influxdb.querybuilder.WhereQueryImpl;
|
||||
import org.influxdb.querybuilder.clauses.Clause;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.BinaryOperator;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
*/
|
||||
/**
|
||||
* @author xuy
|
||||
* @version 1.0.0
|
||||
* @date 2022年04月07日 09:54
|
||||
*//*
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@AllArgsConstructor
|
||||
public class PollutionJob {
|
||||
|
||||
private final InfluxDbConfig influxDbConfig;
|
||||
|
||||
private final InfluxDbUtils influxDbUtils;
|
||||
|
||||
private final LineFeignClient lineFeignClient;
|
||||
|
||||
*/
|
||||
/**
|
||||
* 监测点污染指标
|
||||
*//*
|
||||
|
||||
@XxlJob("pollutionJobHandler")
|
||||
public void pollutionJobHandler() {
|
||||
List<PublicDTO> list = new ArrayList<>();
|
||||
//谐波电压
|
||||
List<PublicDTO> uaberranceList = new ArrayList<>();
|
||||
//谐波电流
|
||||
List<PublicDTO> iHarmList = new ArrayList<>();
|
||||
//频率偏差
|
||||
List<PublicDTO> freqList = new ArrayList<>();
|
||||
//电压偏差
|
||||
List<PublicDTO> devList = new ArrayList<>();
|
||||
//三相电压不平衡度
|
||||
List<PublicDTO> uBalanceList = new ArrayList<>();
|
||||
//负序电流
|
||||
List<PublicDTO> iNegList = new ArrayList<>();
|
||||
//间谐波电压含有率
|
||||
List<PublicDTO> iNuharmList = new ArrayList<>();
|
||||
//长时电压闪变
|
||||
List<PublicDTO> flickerList = new ArrayList<>();
|
||||
List<String> lineList = getAllLinesLimitData().stream().map(Overlimit::getId).collect(Collectors.toList());
|
||||
List<PollutionDTO> pollutionList = new ArrayList<>();
|
||||
lineList.forEach(item->{
|
||||
PollutionDTO pollutionDTO = new PollutionDTO();
|
||||
pollutionDTO.setId(item);
|
||||
pollutionList.add(pollutionDTO);
|
||||
});
|
||||
//谐波电压污染数值
|
||||
Map<String, Optional<PublicDTO>> map1 = getDistortionData();
|
||||
for (String key : map1.keySet()) {
|
||||
list.add(map1.get(key).get());
|
||||
}
|
||||
Map<String, Optional<PublicDTO>> map2 = getContentData();
|
||||
for (String key : map2.keySet()) {
|
||||
list.add(map2.get(key).get());
|
||||
}
|
||||
Comparator<PublicDTO> comparator = Comparator.comparing(PublicDTO::getData);
|
||||
Map<String, Optional<PublicDTO>> result = list.stream().collect(Collectors.groupingBy(PublicDTO::getId,Collectors.reducing(BinaryOperator.maxBy(comparator))));
|
||||
for (String key : result.keySet()) {
|
||||
uaberranceList.add(result.get(key).get());
|
||||
}
|
||||
//谐波电流污染数值
|
||||
Map<String, Optional<PublicDTO>> map3 = getIharm();
|
||||
for (String key : map3.keySet()) {
|
||||
iHarmList.add(map3.get(key).get());
|
||||
}
|
||||
//频率偏差污染数值
|
||||
Map<String, Optional<PublicDTO>> map4 = getFreq();
|
||||
for (String key : map4.keySet()) {
|
||||
freqList.add(map4.get(key).get());
|
||||
}
|
||||
//电压偏差
|
||||
Map<String, Optional<PublicDTO>> map5 = getDev();
|
||||
for (String key : map5.keySet()) {
|
||||
devList.add(map5.get(key).get());
|
||||
}
|
||||
//三相电压不平衡度
|
||||
Map<String, Optional<PublicDTO>> map6 = getUbalance();
|
||||
for (String key : map6.keySet()) {
|
||||
uBalanceList.add(map6.get(key).get());
|
||||
}
|
||||
//负序电流
|
||||
Map<String, Optional<PublicDTO>> map7 = getIneg();
|
||||
for (String key : map7.keySet()) {
|
||||
iNegList.add(map7.get(key).get());
|
||||
}
|
||||
//间谐波电压含有率
|
||||
Map<String, Optional<PublicDTO>> map8 = getInuharm();
|
||||
for (String key : map8.keySet()) {
|
||||
iNuharmList.add(map8.get(key).get());
|
||||
}
|
||||
//长时电压闪变
|
||||
Map<String, Optional<PublicDTO>> map9 = getFlicker();
|
||||
for (String key : map9.keySet()) {
|
||||
flickerList.add(map9.get(key).get());
|
||||
}
|
||||
//组装数据
|
||||
for (PollutionDTO item1 : pollutionList) {
|
||||
for (PublicDTO item2 : uaberranceList) {
|
||||
if (Objects.equals(item1.getId(),item2.getId())){
|
||||
item1.setData5(BigDecimal.valueOf(item2.getData()).setScale(4, RoundingMode.HALF_UP).doubleValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
for (PollutionDTO item1 : pollutionList) {
|
||||
for (PublicDTO item2 : iHarmList) {
|
||||
if (Objects.equals(item1.getId(),item2.getId())){
|
||||
item1.setData6(BigDecimal.valueOf(item2.getData()).setScale(4, RoundingMode.HALF_UP).doubleValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
for (PollutionDTO item1 : pollutionList) {
|
||||
for (PublicDTO item2 : freqList) {
|
||||
if (Objects.equals(item1.getId(),item2.getId())){
|
||||
item1.setData1(BigDecimal.valueOf(item2.getData()).setScale(4, RoundingMode.HALF_UP).doubleValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
for (PollutionDTO item1 : pollutionList) {
|
||||
for (PublicDTO item2 : devList) {
|
||||
if (Objects.equals(item1.getId(),item2.getId())){
|
||||
item1.setData2(BigDecimal.valueOf(item2.getData()).setScale(4, RoundingMode.HALF_UP).doubleValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
for (PollutionDTO item1 : pollutionList) {
|
||||
for (PublicDTO item2 : uBalanceList) {
|
||||
if (Objects.equals(item1.getId(),item2.getId())){
|
||||
item1.setData3(BigDecimal.valueOf(item2.getData()).setScale(4, RoundingMode.HALF_UP).doubleValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
for (PollutionDTO item1 : pollutionList) {
|
||||
for (PublicDTO item2 : iNegList) {
|
||||
if (Objects.equals(item1.getId(),item2.getId())){
|
||||
item1.setData4(BigDecimal.valueOf(item2.getData()).setScale(4, RoundingMode.HALF_UP).doubleValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
for (PollutionDTO item1 : pollutionList) {
|
||||
for (PublicDTO item2 : iNuharmList) {
|
||||
if (Objects.equals(item1.getId(),item2.getId())){
|
||||
item1.setData7(BigDecimal.valueOf(item2.getData()).setScale(4, RoundingMode.HALF_UP).doubleValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
for (PollutionDTO item1 : pollutionList) {
|
||||
for (PublicDTO item2 : flickerList) {
|
||||
if (Objects.equals(item1.getId(),item2.getId())){
|
||||
item1.setData8(BigDecimal.valueOf(item2.getData()).setScale(4, RoundingMode.HALF_UP).doubleValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
//将处理好的数据存入influxDB表中
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH)-1, 0, 0, 0);
|
||||
calendar.set(Calendar.MILLISECOND,0);
|
||||
createMeasurement(pollutionList,calendar.getTimeInMillis());
|
||||
}
|
||||
|
||||
|
||||
*/
|
||||
/**
|
||||
* 获取限值表中的所有监测点信息
|
||||
*//*
|
||||
|
||||
private List<Overlimit> getAllLinesLimitData() {
|
||||
return lineFeignClient.getAllLineOverLimit("harmonic-boot","").getData();
|
||||
}
|
||||
|
||||
private void whereAndNested(List<Clause> clauses, WhereQueryImpl<SelectQueryImpl> whereQuery) {
|
||||
WhereNested<WhereQueryImpl<SelectQueryImpl>> andNested = whereQuery.andNested();
|
||||
for (Clause clause : clauses) {
|
||||
andNested.or(clause);
|
||||
}
|
||||
andNested.close();
|
||||
}
|
||||
|
||||
*/
|
||||
/**
|
||||
* 谐波电压 -> 电压总谐波畸变率
|
||||
* 各监测点最新的A、B、C三相数据
|
||||
* 按照监测点分组,每个监测点取最大
|
||||
*//*
|
||||
|
||||
private Map<String, Optional<PublicDTO>> getDistortionData(){
|
||||
String sql = "SELECT * FROM day_v where value_type = 'CP95' and (phasic_type = 'A' or phasic_type = 'B' or phasic_type = 'C') group by line_id order by time desc limit 3 tz('Asia/Shanghai')";
|
||||
QueryResult sqlResult = influxDbUtils.query(sql);
|
||||
InfluxDBResultMapper resultMapper = new InfluxDBResultMapper();
|
||||
List<Double> data;
|
||||
PublicDTO publicDTO;
|
||||
List<PublicDTO> lineData = new ArrayList<>();
|
||||
List<DayV> list = resultMapper.toPOJO(sqlResult, DayV.class);
|
||||
List<Overlimit> overLimitList = getAllLinesLimitData();
|
||||
for (DayV item1 : list) {
|
||||
for (Overlimit item2 : overLimitList) {
|
||||
if (Objects.equals(item1.getLineId(),item2.getId())){
|
||||
double vUnbalance = item1.getVUnbalance()/item2.getUaberrance();
|
||||
data = Stream.of(vUnbalance).collect(Collectors.toList());
|
||||
double result = data.stream().max(Comparator.comparing(Double::doubleValue)).get();
|
||||
publicDTO = new PublicDTO();
|
||||
publicDTO.setId(item1.getLineId());
|
||||
publicDTO.setData(result);
|
||||
lineData.add(publicDTO);
|
||||
}
|
||||
}
|
||||
}
|
||||
Comparator<PublicDTO> comparator = Comparator.comparing(PublicDTO::getData);
|
||||
return lineData.stream().collect(Collectors.groupingBy(PublicDTO::getId,Collectors.reducing(BinaryOperator.maxBy(comparator))));
|
||||
}
|
||||
|
||||
*/
|
||||
/**
|
||||
* 谐波电压 -> 各次谐波电压含有率(2~25次)
|
||||
* 各监测点最新的A、B、C三相数据
|
||||
*//*
|
||||
|
||||
private Map<String, Optional<PublicDTO>> getContentData(){
|
||||
String sql = "SELECT * FROM day_harmrate_v where value_type = 'CP95' and (phasic_type = 'A' or phasic_type = 'B' or phasic_type = 'C') group by line_id order by time desc limit 3 tz('Asia/Shanghai')";
|
||||
QueryResult sqlResult = influxDbUtils.query(sql);
|
||||
InfluxDBResultMapper resultMapper = new InfluxDBResultMapper();
|
||||
List<Double> data;
|
||||
PublicDTO publicDTO;
|
||||
List<PublicDTO> lineData = new ArrayList<>();
|
||||
List<DayHarmrateV> list = resultMapper.toPOJO(sqlResult, DayHarmrateV.class);
|
||||
List<Overlimit> overLimitList = getAllLinesLimitData();
|
||||
for (DayHarmrateV dayHarmrateV : list) {
|
||||
for (Overlimit overlimit : overLimitList) {
|
||||
if (Objects.equals(dayHarmrateV.getLineId(),overlimit.getId())){
|
||||
double v2 = dayHarmrateV.getV2()/overlimit.getUharm2();
|
||||
double v3 = dayHarmrateV.getV3()/overlimit.getUharm3();
|
||||
double v4 = dayHarmrateV.getV4()/overlimit.getUharm4();
|
||||
double v5 = dayHarmrateV.getV5()/overlimit.getUharm5();
|
||||
double v6 = dayHarmrateV.getV6()/overlimit.getUharm6();
|
||||
double v7 = dayHarmrateV.getV7()/overlimit.getUharm7();
|
||||
double v8 = dayHarmrateV.getV8()/overlimit.getUharm8();
|
||||
double v9 = dayHarmrateV.getV9()/overlimit.getUharm9();
|
||||
double v10 = dayHarmrateV.getV10()/overlimit.getUharm10();
|
||||
double v11 = dayHarmrateV.getV11()/overlimit.getUharm11();
|
||||
double v12 = dayHarmrateV.getV12()/overlimit.getUharm12();
|
||||
double v13 = dayHarmrateV.getV13()/overlimit.getUharm13();
|
||||
double v14 = dayHarmrateV.getV14()/overlimit.getUharm14();
|
||||
double v15 = dayHarmrateV.getV15()/overlimit.getUharm15();
|
||||
double v16 = dayHarmrateV.getV16()/overlimit.getUharm16();
|
||||
double v17 = dayHarmrateV.getV17()/overlimit.getUharm17();
|
||||
double v18 = dayHarmrateV.getV18()/overlimit.getUharm18();
|
||||
double v19 = dayHarmrateV.getV19()/overlimit.getUharm19();
|
||||
double v20 = dayHarmrateV.getV20()/overlimit.getUharm20();
|
||||
double v21 = dayHarmrateV.getV21()/overlimit.getUharm21();
|
||||
double v22 = dayHarmrateV.getV22()/overlimit.getUharm22();
|
||||
double v23 = dayHarmrateV.getV23()/overlimit.getUharm23();
|
||||
double v24 = dayHarmrateV.getV24()/overlimit.getUharm24();
|
||||
double v25 = dayHarmrateV.getV25()/overlimit.getUharm25();
|
||||
data = Stream.of(v2,v3,v4,v5,v6,v7,v8,v9,v10,v11,v12,v13,v14,v15,v16,v17,v18,v19,v20,v21,v22,v23,v24,v25).collect(Collectors.toList());
|
||||
double result = data.stream().max(Comparator.comparing(Double::doubleValue)).get();
|
||||
publicDTO = new PublicDTO();
|
||||
publicDTO.setId(dayHarmrateV.getLineId());
|
||||
publicDTO.setData(result);
|
||||
lineData.add(publicDTO);
|
||||
}
|
||||
}
|
||||
}
|
||||
Comparator<PublicDTO> comparator = Comparator.comparing(PublicDTO::getData);
|
||||
return lineData.stream().collect(Collectors.groupingBy(PublicDTO::getId,Collectors.reducing(BinaryOperator.maxBy(comparator))));
|
||||
}
|
||||
|
||||
*/
|
||||
/**
|
||||
* 谐波电流 -> 各次谐波电流(2~25次)
|
||||
* 各监测点最新的A、B、C三相数据
|
||||
*//*
|
||||
|
||||
private Map<String, Optional<PublicDTO>> getIharm(){
|
||||
String sql = "SELECT * FROM day_i where value_type = 'CP95' and (phasic_type = 'A' or phasic_type = 'B' or phasic_type = 'C') group by line_id order by time desc limit 3 tz('Asia/Shanghai')";
|
||||
QueryResult sqlResult = influxDbUtils.query(sql);
|
||||
InfluxDBResultMapper resultMapper = new InfluxDBResultMapper();
|
||||
List<Double> data;
|
||||
PublicDTO publicDTO;
|
||||
List<PublicDTO> lineData = new ArrayList<>();
|
||||
List<DayI> list = resultMapper.toPOJO(sqlResult, DayI.class);
|
||||
List<Overlimit> overLimitList = getAllLinesLimitData();
|
||||
for (DayI dayI : list) {
|
||||
for (Overlimit overlimit : overLimitList) {
|
||||
if (Objects.equals(dayI.getLineId(),overlimit.getId())){
|
||||
double v2 = dayI.getI2()/overlimit.getIharm2();
|
||||
double v3 = dayI.getI3()/overlimit.getIharm3();
|
||||
double v4 = dayI.getI4()/overlimit.getIharm4();
|
||||
double v5 = dayI.getI5()/overlimit.getIharm5();
|
||||
double v6 = dayI.getI6()/overlimit.getIharm6();
|
||||
double v7 = dayI.getI7()/overlimit.getIharm7();
|
||||
double v8 = dayI.getI8()/overlimit.getIharm8();
|
||||
double v9 = dayI.getI9()/overlimit.getIharm9();
|
||||
double v10 = dayI.getI10()/overlimit.getIharm10();
|
||||
double v11 = dayI.getI11()/overlimit.getIharm11();
|
||||
double v12 = dayI.getI12()/overlimit.getIharm12();
|
||||
double v13 = dayI.getI13()/overlimit.getIharm13();
|
||||
double v14 = dayI.getI14()/overlimit.getIharm14();
|
||||
double v15 = dayI.getI15()/overlimit.getIharm15();
|
||||
double v16 = dayI.getI16()/overlimit.getIharm16();
|
||||
double v17 = dayI.getI17()/overlimit.getIharm17();
|
||||
double v18 = dayI.getI18()/overlimit.getIharm18();
|
||||
double v19 = dayI.getI19()/overlimit.getIharm19();
|
||||
double v20 = dayI.getI20()/overlimit.getIharm20();
|
||||
double v21 = dayI.getI21()/overlimit.getIharm21();
|
||||
double v22 = dayI.getI22()/overlimit.getIharm22();
|
||||
double v23 = dayI.getI23()/overlimit.getIharm23();
|
||||
double v24 = dayI.getI24()/overlimit.getIharm24();
|
||||
double v25 = dayI.getI25()/overlimit.getIharm25();
|
||||
data = Stream.of(v2,v3,v4,v5,v6,v7,v8,v9,v10,v11,v12,v13,v14,v15,v16,v17,v18,v19,v20,v21,v22,v23,v24,v25).collect(Collectors.toList());
|
||||
double result = data.stream().max(Comparator.comparing(Double::doubleValue)).get();
|
||||
publicDTO = new PublicDTO();
|
||||
publicDTO.setId(dayI.getLineId());
|
||||
publicDTO.setData(result);
|
||||
lineData.add(publicDTO);
|
||||
}
|
||||
}
|
||||
}
|
||||
Comparator<PublicDTO> comparator = Comparator.comparing(PublicDTO::getData);
|
||||
return lineData.stream().collect(Collectors.groupingBy(PublicDTO::getId,Collectors.reducing(BinaryOperator.maxBy(comparator))));
|
||||
}
|
||||
|
||||
*/
|
||||
/**
|
||||
* 频率偏差 -> 绝对值
|
||||
* 各监测点最新的T相数据
|
||||
*//*
|
||||
|
||||
private Map<String, Optional<PublicDTO>> getFreq(){
|
||||
String sql = "SELECT line_id,abs(freq_dev) AS freq_dev FROM day_v where phasic_type = 'T' and (value_type = 'MIN' or value_type = 'MAX') group by line_id order by time desc limit 2 tz('Asia/Shanghai')";
|
||||
QueryResult sqlResult = influxDbUtils.query(sql);
|
||||
InfluxDBResultMapper resultMapper = new InfluxDBResultMapper();
|
||||
List<Double> data;
|
||||
PublicDTO publicDTO;
|
||||
List<PublicDTO> lineData = new ArrayList<>();
|
||||
List<DayV> list = resultMapper.toPOJO(sqlResult, DayV.class);
|
||||
List<Overlimit> overLimitList = getAllLinesLimitData();
|
||||
for (DayV dayV : list) {
|
||||
for (Overlimit overlimit : overLimitList) {
|
||||
if (Objects.equals(dayV.getLineId(),overlimit.getId())){
|
||||
double freqDev = dayV.getFreqDev()/overlimit.getFreqDev();
|
||||
data = Stream.of(freqDev).collect(Collectors.toList());
|
||||
double result = data.stream().max(Comparator.comparing(Double::doubleValue)).get();
|
||||
publicDTO = new PublicDTO();
|
||||
publicDTO.setId(dayV.getLineId());
|
||||
publicDTO.setData(result);
|
||||
lineData.add(publicDTO);
|
||||
}
|
||||
}
|
||||
}
|
||||
Comparator<PublicDTO> comparator = Comparator.comparing(PublicDTO::getData);
|
||||
return lineData.stream().collect(Collectors.groupingBy(PublicDTO::getId,Collectors.reducing(BinaryOperator.maxBy(comparator))));
|
||||
}
|
||||
|
||||
*/
|
||||
/**
|
||||
* 电压偏差 -> 绝对值
|
||||
* 各监测点最新的A、B、C三相数据
|
||||
*//*
|
||||
|
||||
private Map<String, Optional<PublicDTO>> getDev(){
|
||||
String sql = "SELECT line_id,vu_dev,vl_dev,value_type FROM day_v where (phasic_type = 'A' or phasic_type = 'B' or phasic_type = 'C') and (value_type = 'MIN' or value_type = 'MAX') group by line_id order by time desc limit 6 tz('Asia/Shanghai')";
|
||||
QueryResult sqlResult = influxDbUtils.query(sql);
|
||||
InfluxDBResultMapper resultMapper = new InfluxDBResultMapper();
|
||||
List<Double> data;
|
||||
PublicDTO publicDTO;
|
||||
List<PublicDTO> lineData = new ArrayList<>();
|
||||
List<DayV> list = resultMapper.toPOJO(sqlResult, DayV.class);
|
||||
List<Overlimit> overLimitList = getAllLinesLimitData();
|
||||
for (DayV dayV : list) {
|
||||
for (Overlimit overlimit : overLimitList) {
|
||||
if (Objects.equals(dayV.getLineId(),overlimit.getId())){
|
||||
double vlDev = Math.abs(dayV.getVlDev()/overlimit.getUvoltageDev());
|
||||
double vuDev = Math.abs(dayV.getVuDev()/overlimit.getVoltageDev());
|
||||
data = Stream.of(vuDev,vlDev).collect(Collectors.toList());
|
||||
double result = data.stream().max(Comparator.comparing(Double::doubleValue)).get();
|
||||
publicDTO = new PublicDTO();
|
||||
publicDTO.setId(dayV.getLineId());
|
||||
publicDTO.setData(result);
|
||||
lineData.add(publicDTO);
|
||||
}
|
||||
}
|
||||
}
|
||||
Comparator<PublicDTO> comparator = Comparator.comparing(PublicDTO::getData);
|
||||
return lineData.stream().collect(Collectors.groupingBy(PublicDTO::getId,Collectors.reducing(BinaryOperator.maxBy(comparator))));
|
||||
}
|
||||
|
||||
*/
|
||||
/**
|
||||
* 三相电压不平衡度
|
||||
* 各监测点最新的T相数据
|
||||
*//*
|
||||
|
||||
private Map<String, Optional<PublicDTO>> getUbalance(){
|
||||
String sql = "SELECT line_id,v_unbalance,value_type FROM day_v where phasic_type = 'T' and (value_type = 'CP95' or value_type = 'MAX') group by line_id order by time desc limit 2 tz('Asia/Shanghai')";
|
||||
QueryResult sqlResult = influxDbUtils.query(sql);
|
||||
InfluxDBResultMapper resultMapper = new InfluxDBResultMapper();
|
||||
List<Double> data;
|
||||
PublicDTO publicDTO;
|
||||
List<PublicDTO> lineData = new ArrayList<>();
|
||||
List<DayV> list = resultMapper.toPOJO(sqlResult, DayV.class);
|
||||
List<Overlimit> overLimitList = getAllLinesLimitData();
|
||||
for (DayV dayV : list) {
|
||||
for (Overlimit overlimit : overLimitList) {
|
||||
if (Objects.equals(dayV.getLineId(),overlimit.getId())){
|
||||
double vUnbalance = Math.abs(dayV.getVUnbalance()/overlimit.getUbalance());
|
||||
data = Stream.of(vUnbalance).collect(Collectors.toList());
|
||||
double result = data.stream().max(Comparator.comparing(Double::doubleValue)).get();
|
||||
publicDTO = new PublicDTO();
|
||||
publicDTO.setId(dayV.getLineId());
|
||||
publicDTO.setData(result);
|
||||
lineData.add(publicDTO);
|
||||
}
|
||||
}
|
||||
}
|
||||
Comparator<PublicDTO> comparator = Comparator.comparing(PublicDTO::getData);
|
||||
return lineData.stream().collect(Collectors.groupingBy(PublicDTO::getId,Collectors.reducing(BinaryOperator.maxBy(comparator))));
|
||||
}
|
||||
|
||||
*/
|
||||
/**
|
||||
* 负序电流
|
||||
* 各监测点最新的T相数据
|
||||
*//*
|
||||
|
||||
private Map<String, Optional<PublicDTO>> getIneg(){
|
||||
String sql = "SELECT line_id,i_neg,value_type FROM day_i where phasic_type = 'T' and (value_type = 'CP95' or value_type = 'MAX') group by line_id order by time desc limit 2 tz('Asia/Shanghai')";
|
||||
QueryResult sqlResult = influxDbUtils.query(sql);
|
||||
InfluxDBResultMapper resultMapper = new InfluxDBResultMapper();
|
||||
List<Double> data;
|
||||
PublicDTO publicDTO;
|
||||
List<PublicDTO> lineData = new ArrayList<>();
|
||||
List<DayI> list = resultMapper.toPOJO(sqlResult, DayI.class);
|
||||
List<Overlimit> overLimitList = getAllLinesLimitData();
|
||||
for (DayI dayI : list) {
|
||||
for (Overlimit overlimit : overLimitList) {
|
||||
if (Objects.equals(dayI.getLineId(),overlimit.getId())){
|
||||
double iNeg = Math.abs(dayI.getINeg()/overlimit.getINeg());
|
||||
data = Stream.of(iNeg).collect(Collectors.toList());
|
||||
double result = data.stream().max(Comparator.comparing(Double::doubleValue)).get();
|
||||
publicDTO = new PublicDTO();
|
||||
publicDTO.setId(dayI.getLineId());
|
||||
publicDTO.setData(result);
|
||||
lineData.add(publicDTO);
|
||||
}
|
||||
}
|
||||
}
|
||||
Comparator<PublicDTO> comparator = Comparator.comparing(PublicDTO::getData);
|
||||
return lineData.stream().collect(Collectors.groupingBy(PublicDTO::getId,Collectors.reducing(BinaryOperator.maxBy(comparator))));
|
||||
}
|
||||
|
||||
*/
|
||||
/**
|
||||
* 间谐波电压含有率
|
||||
* 各监测点最新的A、B、C三相数据
|
||||
*//*
|
||||
|
||||
private Map<String, Optional<PublicDTO>> getInuharm(){
|
||||
String sql = "SELECT * FROM day_inharm_v where (phasic_type = 'A' or phasic_type = 'B' or phasic_type = 'C') and value_type = 'CP95' group by line_id order by time desc limit 3 tz('Asia/Shanghai')";
|
||||
QueryResult sqlResult = influxDbUtils.query(sql);
|
||||
InfluxDBResultMapper resultMapper = new InfluxDBResultMapper();
|
||||
List<Double> data;
|
||||
PublicDTO publicDTO;
|
||||
List<PublicDTO> lineData = new ArrayList<>();
|
||||
List<DayInharmV> list = resultMapper.toPOJO(sqlResult, DayInharmV.class);
|
||||
List<Overlimit> overLimitList = getAllLinesLimitData();
|
||||
for (DayInharmV dayInharmV : list) {
|
||||
for (Overlimit overlimit : overLimitList) {
|
||||
if (Objects.equals(dayInharmV.getLineId(),overlimit.getId())){
|
||||
double v1 = Math.abs(dayInharmV.getV1()/overlimit.getInuharm1());
|
||||
double v2 = Math.abs(dayInharmV.getV2()/overlimit.getInuharm2());
|
||||
double v3 = Math.abs(dayInharmV.getV3()/overlimit.getInuharm3());
|
||||
double v4 = Math.abs(dayInharmV.getV4()/overlimit.getInuharm4());
|
||||
double v5 = Math.abs(dayInharmV.getV5()/overlimit.getInuharm5());
|
||||
double v6 = Math.abs(dayInharmV.getV6()/overlimit.getInuharm6());
|
||||
double v7 = Math.abs(dayInharmV.getV7()/overlimit.getInuharm7());
|
||||
double v8 = Math.abs(dayInharmV.getV8()/overlimit.getInuharm8());
|
||||
double v9 = Math.abs(dayInharmV.getV9()/overlimit.getInuharm9());
|
||||
double v10 = Math.abs(dayInharmV.getV10()/overlimit.getInuharm10());
|
||||
double v11 = Math.abs(dayInharmV.getV11()/overlimit.getInuharm11());
|
||||
double v12 = Math.abs(dayInharmV.getV12()/overlimit.getInuharm12());
|
||||
double v13 = Math.abs(dayInharmV.getV13()/overlimit.getInuharm13());
|
||||
double v14 = Math.abs(dayInharmV.getV14()/overlimit.getInuharm14());
|
||||
double v15 = Math.abs(dayInharmV.getV15()/overlimit.getInuharm15());
|
||||
double v16 = Math.abs(dayInharmV.getV16()/overlimit.getInuharm16());
|
||||
data = Stream.of(v1,v2,v3,v4,v5,v6,v7,v8,v9,v10,v11,v12,v13,v14,v15,v16).collect(Collectors.toList());
|
||||
double result = data.stream().max(Comparator.comparing(Double::doubleValue)).get();
|
||||
publicDTO = new PublicDTO();
|
||||
publicDTO.setId(dayInharmV.getLineId());
|
||||
publicDTO.setData(result);
|
||||
lineData.add(publicDTO);
|
||||
}
|
||||
}
|
||||
}
|
||||
Comparator<PublicDTO> comparator = Comparator.comparing(PublicDTO::getData);
|
||||
return lineData.stream().collect(Collectors.groupingBy(PublicDTO::getId,Collectors.reducing(BinaryOperator.maxBy(comparator))));
|
||||
}
|
||||
|
||||
*/
|
||||
/**
|
||||
* 长时电压闪变
|
||||
* 各监测点最新的A、B、C三相数据
|
||||
*//*
|
||||
|
||||
private Map<String, Optional<PublicDTO>> getFlicker(){
|
||||
String sql = "SELECT * FROM day_plt where (phasic_type = 'A' or phasic_type = 'B' or phasic_type = 'C') and value_type = 'CP95' group by line_id order by time desc limit 3 tz('Asia/Shanghai')";
|
||||
QueryResult sqlResult = influxDbUtils.query(sql);
|
||||
InfluxDBResultMapper resultMapper = new InfluxDBResultMapper();
|
||||
List<Double> data;
|
||||
PublicDTO publicDTO;
|
||||
List<PublicDTO> lineData = new ArrayList<>();
|
||||
List<DayPlt> list = resultMapper.toPOJO(sqlResult, DayPlt.class);
|
||||
List<Overlimit> overLimitList = getAllLinesLimitData();
|
||||
for (DayPlt dayPlt : list) {
|
||||
for (Overlimit overlimit : overLimitList) {
|
||||
if (Objects.equals(dayPlt.getLineId(),overlimit.getId())){
|
||||
double plt = Math.abs(dayPlt.getPlt()/overlimit.getFlicker());
|
||||
data = Stream.of(plt).collect(Collectors.toList());
|
||||
double result = data.stream().max(Comparator.comparing(Double::doubleValue)).get();
|
||||
publicDTO = new PublicDTO();
|
||||
publicDTO.setId(dayPlt.getLineId());
|
||||
publicDTO.setData(result);
|
||||
lineData.add(publicDTO);
|
||||
}
|
||||
}
|
||||
}
|
||||
Comparator<PublicDTO> comparator = Comparator.comparing(PublicDTO::getData);
|
||||
return lineData.stream().collect(Collectors.groupingBy(PublicDTO::getId,Collectors.reducing(BinaryOperator.maxBy(comparator))));
|
||||
}
|
||||
|
||||
|
||||
*/
|
||||
/**
|
||||
* 生成谐波污区图污染指标表
|
||||
*//*
|
||||
|
||||
private void createMeasurement(List<PollutionDTO> list, long time){
|
||||
List<String> records = new ArrayList<String>();
|
||||
list.forEach(item->{
|
||||
Map<String, String> tags = new HashMap<>();
|
||||
Map<String, Object> fields = new HashMap<>();
|
||||
tags.put("line_id",item.getId());
|
||||
fields.put("freq",item.getData1());
|
||||
fields.put("freq_dev",item.getData2());
|
||||
fields.put("unbalance",item.getData3());
|
||||
fields.put("ineg",item.getData4());
|
||||
fields.put("harmonic_v",item.getData5());
|
||||
fields.put("harmonic_i",item.getData6());
|
||||
fields.put("inuharm",item.getData7());
|
||||
fields.put("flicker",item.getData8());
|
||||
Point point = influxDbUtils.pointBuilder("harmonic_pollution", time, TimeUnit.MILLISECONDS,tags, fields);
|
||||
BatchPoints batchPoints = BatchPoints.database(influxDbConfig.getDatabase()).tag("line_id", item.getId()).retentionPolicy("").consistency(InfluxDB.ConsistencyLevel.ALL).build();
|
||||
batchPoints.point(point);
|
||||
records.add(batchPoints.lineProtocol());
|
||||
});
|
||||
influxDbUtils.batchInsert(influxDbConfig.getDatabase(),"", InfluxDB.ConsistencyLevel.ALL, records);
|
||||
}
|
||||
}
|
||||
*/
|
||||
@@ -1,191 +0,0 @@
|
||||
/*
|
||||
package com.njcn.executor.handler;
|
||||
|
||||
import com.njcn.common.pojo.constant.PatternRegex;
|
||||
import com.njcn.device.pq.api.LineFeignClient;
|
||||
import com.njcn.device.pq.pojo.po.LineDetail;
|
||||
import com.njcn.executor.pojo.vo.*;
|
||||
import com.njcn.influxdb.config.InfluxDbConfig;
|
||||
import com.njcn.influxdb.param.InfluxDBPublicParam;
|
||||
import com.njcn.influxdb.utils.InfluxDbUtils;
|
||||
import com.xxl.job.core.context.XxlJobHelper;
|
||||
import com.xxl.job.core.handler.annotation.XxlJob;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.influxdb.InfluxDB;
|
||||
import org.influxdb.dto.BatchPoints;
|
||||
import org.influxdb.dto.Point;
|
||||
import org.influxdb.dto.QueryResult;
|
||||
import org.influxdb.impl.InfluxDBResultMapper;
|
||||
import org.influxdb.querybuilder.SelectQueryImpl;
|
||||
import org.influxdb.querybuilder.WhereNested;
|
||||
import org.influxdb.querybuilder.WhereQueryImpl;
|
||||
import org.influxdb.querybuilder.clauses.Clause;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.Instant;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.njcn.influxdb.param.InfluxDBPublicParam.*;
|
||||
import static com.njcn.influxdb.param.InfluxDBPublicParam.LINE_ID;
|
||||
import static org.influxdb.querybuilder.BuiltQuery.QueryBuilder.*;
|
||||
import static org.influxdb.querybuilder.BuiltQuery.QueryBuilder.eq;
|
||||
|
||||
*/
|
||||
/**
|
||||
* 类的介绍:
|
||||
*
|
||||
* @author xuyang
|
||||
* @version 1.0.0
|
||||
* @createTime 2022/7/8 13:44
|
||||
*//*
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@AllArgsConstructor
|
||||
public class PqsIntegrityJob {
|
||||
|
||||
private final InfluxDbUtils influxDbUtils;
|
||||
|
||||
private final InfluxDbConfig influxDbConfig;
|
||||
|
||||
private final LineFeignClient lineFeignClient;
|
||||
|
||||
@XxlJob("pqsIntegrityJobHandler")
|
||||
public void pqsIntegrityJobHandler() throws ParseException {
|
||||
List<PqsIntegrity> result = new ArrayList<>();
|
||||
List<String> paramList = new ArrayList<>(),lineList = new ArrayList<>();
|
||||
List<DataV> dataList = new ArrayList<>();
|
||||
String command = XxlJobHelper.getJobParam();
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH)-1, 0, 0, 0);
|
||||
calendar.set(Calendar.MILLISECOND, 0);
|
||||
Calendar calendar2 = Calendar.getInstance();
|
||||
calendar2.set(calendar2.get(Calendar.YEAR), calendar2.get(Calendar.MONTH), calendar2.get(Calendar.DAY_OF_MONTH)-1, 23, 59, 59);
|
||||
calendar2.set(Calendar.MILLISECOND, 0);
|
||||
String startTime = format.format(calendar.getTime());
|
||||
String endTime = format.format(calendar2.getTime());
|
||||
if (!StringUtils.isEmpty(command)){
|
||||
paramList = Arrays.asList(command.split(","));
|
||||
startTime = paramList.get(0);
|
||||
endTime = paramList.get(1);
|
||||
lineList = paramList.subList(2,paramList.size());
|
||||
boolean s1 = Pattern.matches(PatternRegex.TIME_FORMAT,startTime);
|
||||
boolean e1 = Pattern.matches(PatternRegex.TIME_FORMAT,endTime);
|
||||
if (!s1 || !e1){
|
||||
log.error("补招时间格式错误");
|
||||
return;
|
||||
} else {
|
||||
startTime = startTime + START_TIME;
|
||||
endTime = endTime + END_TIME;
|
||||
}
|
||||
}
|
||||
List<LineDetail> lineDetail = lineFeignClient.getLineDetail(lineList).getData();
|
||||
if (!CollectionUtils.isEmpty(lineDetail)){
|
||||
//获取dataV表中监测点的数据数量
|
||||
lineList = lineDetail.stream().map(LineDetail::getId).collect(Collectors.toList());
|
||||
long diff,diffDays,a,b = 0;
|
||||
Date d1 = format.parse(startTime);
|
||||
Date d2 = format.parse(endTime);
|
||||
diff = d2.getTime() - d1.getTime();
|
||||
diffDays = diff / (24 * 60 * 60 * 1000-1000);
|
||||
int days = (int) diffDays;
|
||||
for (int i = 1; i <= days; i++) {
|
||||
a = d1.getTime() + (long)(i-1)*(24 * 60 * 60) * 1000;
|
||||
b = d1.getTime() + (long)i*(24 * 60 * 60) * 1000-1000;
|
||||
startTime = format.format(a);
|
||||
endTime = format.format(b);
|
||||
dataList = getDataV(lineList,startTime,endTime);
|
||||
for (LineDetail detail : lineDetail) {
|
||||
PqsIntegrity pqsIntegrity = new PqsIntegrity();
|
||||
pqsIntegrity.setTime(Instant.ofEpochMilli(a));
|
||||
pqsIntegrity.setLineId(detail.getId());
|
||||
pqsIntegrity.setDue(DAY_MINUTE/detail.getTimeInterval());
|
||||
if (!CollectionUtils.isEmpty(dataList)){
|
||||
Map<String,List<DataV>> lineMap = dataList.stream().collect(Collectors.groupingBy(DataV::getLineId));
|
||||
List<DataV> l1 = lineMap.get(detail.getId());
|
||||
if (!CollectionUtils.isEmpty(l1)){
|
||||
Map<Instant,List<DataV>> timeMap = l1.stream().collect(Collectors.groupingBy(DataV::getTime));
|
||||
pqsIntegrity.setReal(timeMap.size());
|
||||
}
|
||||
}
|
||||
result.add(pqsIntegrity);
|
||||
}
|
||||
}
|
||||
}
|
||||
insertData(result);
|
||||
}
|
||||
|
||||
|
||||
*/
|
||||
/**
|
||||
* 获取dataV数据
|
||||
* @param list 监测点集合
|
||||
* @return dataV数据
|
||||
*//*
|
||||
|
||||
private List<DataV> getDataV(List<String> list, String startTime, String endTime){
|
||||
SelectQueryImpl selectQuery = select().from(influxDbConfig.getDatabase(), DATA_V);
|
||||
WhereQueryImpl<SelectQueryImpl> where = selectQuery.where();
|
||||
whereAndNested(list, where);
|
||||
where.and(gte(TIME, startTime)).and(lte(TIME, endTime));
|
||||
where.tz(TZ);
|
||||
QueryResult queryResult = influxDbUtils.query(selectQuery.getCommand());
|
||||
InfluxDBResultMapper resultMapper = new InfluxDBResultMapper();
|
||||
return resultMapper.toPOJO(queryResult, DataV.class);
|
||||
}
|
||||
|
||||
*/
|
||||
/**
|
||||
* 拼接监测点条件
|
||||
* @param list 监测点集合
|
||||
* @param whereQuery WhereQueryImpl
|
||||
*//*
|
||||
|
||||
private void whereAndNested(List<String> list, WhereQueryImpl<SelectQueryImpl> whereQuery) {
|
||||
List<Clause> clauses = new ArrayList<>();
|
||||
list.forEach(item->{
|
||||
Clause clause = eq(LINE_ID, item);
|
||||
clauses.add(clause);
|
||||
});
|
||||
WhereNested<WhereQueryImpl<SelectQueryImpl>> andNested = whereQuery.andNested();
|
||||
for (Clause clause : clauses) {
|
||||
andNested.or(clause);
|
||||
}
|
||||
andNested.close();
|
||||
}
|
||||
|
||||
*/
|
||||
/**
|
||||
* 功能描述:插入pqs_integrity表数据
|
||||
* @author xy
|
||||
* @param list 数据集合
|
||||
* @date 2022/5/12 8:55
|
||||
*//*
|
||||
|
||||
private void insertData(List<PqsIntegrity> list){
|
||||
List<String> records = new ArrayList<>();
|
||||
list.forEach(item->{
|
||||
Map<String, String> tags = new HashMap<>();
|
||||
Map<String, Object> fields = new HashMap<>();
|
||||
tags.put(LINE_ID,item.getLineId());
|
||||
fields.put(DUE,item.getDue());
|
||||
fields.put(REAL,item.getReal());
|
||||
Point point = influxDbUtils.pointBuilder(PQS_INTEGRITY, item.getTime().toEpochMilli(), TimeUnit.MILLISECONDS, tags, fields);
|
||||
BatchPoints batchPoints = BatchPoints.database(influxDbConfig.getDatabase()).tag(LINE_ID, item.getLineId()).retentionPolicy("").consistency(InfluxDB.ConsistencyLevel.ALL).build();
|
||||
batchPoints.point(point);
|
||||
records.add(batchPoints.lineProtocol());
|
||||
});
|
||||
influxDbUtils.batchInsert(influxDbConfig.getDatabase(),"", InfluxDB.ConsistencyLevel.ALL, records);
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
@@ -1,294 +0,0 @@
|
||||
/*
|
||||
package com.njcn.executor.handler;
|
||||
|
||||
import com.njcn.common.pojo.constant.PatternRegex;
|
||||
import com.njcn.device.pq.api.LineFeignClient;
|
||||
import com.njcn.energy.pojo.constant.ModelState;
|
||||
import com.njcn.executor.pojo.vo.PqsCommunicate;
|
||||
import com.njcn.executor.pojo.vo.PqsOnlineRate;
|
||||
import com.njcn.influxdb.config.InfluxDbConfig;
|
||||
import com.njcn.influxdb.utils.InfluxDbUtils;
|
||||
import com.xxl.job.core.context.XxlJobHelper;
|
||||
import com.xxl.job.core.handler.annotation.XxlJob;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.influxdb.InfluxDB;
|
||||
import org.influxdb.dto.BatchPoints;
|
||||
import org.influxdb.dto.Point;
|
||||
import org.influxdb.dto.QueryResult;
|
||||
import org.influxdb.impl.InfluxDBResultMapper;
|
||||
import org.influxdb.querybuilder.SelectQueryImpl;
|
||||
import org.influxdb.querybuilder.WhereNested;
|
||||
import org.influxdb.querybuilder.WhereQueryImpl;
|
||||
import org.influxdb.querybuilder.clauses.Clause;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.njcn.influxdb.param.InfluxDBPublicParam.*;
|
||||
import static org.influxdb.querybuilder.BuiltQuery.QueryBuilder.*;
|
||||
|
||||
*/
|
||||
/**
|
||||
* 类的介绍:
|
||||
*
|
||||
* @author xuyang
|
||||
* @version 1.0.0
|
||||
* @createTime 2022/7/8 13:43
|
||||
*//*
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@AllArgsConstructor
|
||||
public class PqsOnlineRateJob {
|
||||
|
||||
private final InfluxDbUtils influxDbUtils;
|
||||
|
||||
private final InfluxDbConfig influxDbConfig;
|
||||
|
||||
private final LineFeignClient lineFeignClient;
|
||||
|
||||
@XxlJob("pqsOnlineRateJobHandler")
|
||||
public void pqsOnlineRateJobHandler() throws ParseException {
|
||||
List<PqsOnlineRate> result = new ArrayList<>();
|
||||
List<String> paramList = new ArrayList<>(),deviceList = new ArrayList<>();
|
||||
String command = XxlJobHelper.getJobParam();
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH)-1, 0, 0, 0);
|
||||
calendar.set(Calendar.MILLISECOND, 0);
|
||||
Calendar calendar2 = Calendar.getInstance();
|
||||
calendar2.set(calendar2.get(Calendar.YEAR), calendar2.get(Calendar.MONTH), calendar2.get(Calendar.DAY_OF_MONTH)-1, 23, 59, 59);
|
||||
calendar2.set(Calendar.MILLISECOND, 0);
|
||||
String startTime = format.format(calendar.getTime());
|
||||
String endTime = format.format(calendar2.getTime());
|
||||
if (!StringUtils.isEmpty(command)){
|
||||
paramList = Arrays.asList(command.split(","));
|
||||
startTime = paramList.get(0);
|
||||
endTime = paramList.get(1);
|
||||
deviceList = paramList.subList(2,paramList.size());
|
||||
boolean s1 = Pattern.matches(PatternRegex.TIME_FORMAT,startTime);
|
||||
boolean e1 = Pattern.matches(PatternRegex.TIME_FORMAT,endTime);
|
||||
if (!s1 || !e1){
|
||||
log.error("补招时间格式错误");
|
||||
return;
|
||||
} else {
|
||||
startTime = startTime + START_TIME;
|
||||
endTime = endTime + END_TIME;
|
||||
}
|
||||
}
|
||||
if (CollectionUtils.isEmpty(deviceList)){
|
||||
deviceList = lineFeignClient.getDeviceList().getData();
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(deviceList)){
|
||||
long diff,diffDays,a,b = 0;
|
||||
List<PqsCommunicate> l1 = new ArrayList<>(),l2 = new ArrayList<>();
|
||||
Date d1 = format.parse(startTime);
|
||||
Date d2 = format.parse(endTime);
|
||||
diff = d2.getTime() - d1.getTime();
|
||||
diffDays = diff / (24 * 60 * 60 * 1000-1000);
|
||||
int days = (int) diffDays;
|
||||
for (int i = 1; i <= days; i++) {
|
||||
a = d1.getTime() + (long)(i-1)*(24 * 60 * 60) * 1000;
|
||||
b = d1.getTime() + (long)i*(24 * 60 * 60) * 1000-1000;
|
||||
startTime = format.format(a);
|
||||
endTime = format.format(b);
|
||||
//获取装置的最新的一条数据
|
||||
List<PqsCommunicate> latestList = getData(deviceList);
|
||||
if (!CollectionUtils.isEmpty(latestList)){
|
||||
for (PqsCommunicate item : latestList) {
|
||||
if (item.getTime().toEpochMilli() < a){
|
||||
l1.add(item);
|
||||
} else if (a <= item.getTime().toEpochMilli() && item.getTime().toEpochMilli() < b){
|
||||
l2.add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(l1)){
|
||||
for (PqsCommunicate item : l1) {
|
||||
PqsOnlineRate onlineRate = new PqsOnlineRate();
|
||||
if (Objects.equals(item.getType(), ModelState.offline)){
|
||||
onlineRate.setOfflineMin(DAY_MINUTE);
|
||||
onlineRate.setOnlineMin(0);
|
||||
onlineRate.setOnlineRate(0.0);
|
||||
} else {
|
||||
onlineRate.setOfflineMin(0);
|
||||
onlineRate.setOnlineMin(DAY_MINUTE);
|
||||
onlineRate.setOnlineRate(100.0);
|
||||
}
|
||||
onlineRate.setTime(Instant.ofEpochMilli(a));
|
||||
onlineRate.setDevId(item.getDevId());
|
||||
result.add(onlineRate);
|
||||
}
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(l2)){
|
||||
List<String> devList = l2.stream().map(PqsCommunicate::getDevId).collect(Collectors.toList());
|
||||
List<PqsCommunicate> list = getPqsCommunicate(devList,startTime,endTime);
|
||||
//根据装置的id进行分组
|
||||
Map<String,List<PqsCommunicate>> groupMap = list.stream().collect(Collectors.groupingBy(PqsCommunicate::getDevId));
|
||||
try {
|
||||
if (!CollectionUtils.isEmpty(groupMap)){
|
||||
for (String key : groupMap.keySet()) {
|
||||
int offTime = 0;
|
||||
int onTime = 0;
|
||||
PqsOnlineRate onlineRate = new PqsOnlineRate();
|
||||
List<PqsCommunicate> infoList = groupMap.get(key);
|
||||
if (infoList.size() > 1){
|
||||
//获取最早一条记录
|
||||
PqsCommunicate first = infoList.stream().min(Comparator.comparing(PqsCommunicate::getTime)).get();
|
||||
//将上线和下线分组
|
||||
Map<Integer,List<PqsCommunicate>> typeMap = infoList.stream().collect(Collectors.groupingBy(PqsCommunicate::getType));
|
||||
List<PqsCommunicate> off = typeMap.get(0);
|
||||
List<PqsCommunicate> on = typeMap.get(1);
|
||||
if (first.getType() == 0){
|
||||
if (off.size() == on.size()){
|
||||
for (int j = 0; j < off.size(); j++) {
|
||||
offTime = offTime + (int) (on.get(j).getTime().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli() + 1000L - off.get(j).getTime().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli()) / (1000*60);
|
||||
}
|
||||
} else {
|
||||
for (int j = 0; j < off.size(); j++) {
|
||||
if (j == off.size() - 1){
|
||||
offTime = offTime + (int) (format.parse(endTime).getTime() + 1000L - off.get(j).getTime().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli()) / (1000*60);
|
||||
} else {
|
||||
offTime = offTime + (int) (on.get(j).getTime().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli() + 1000L - off.get(j).getTime().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli()) / (1000*60);
|
||||
}
|
||||
}
|
||||
}
|
||||
onTime = DAY_MINUTE-offTime;
|
||||
} else {
|
||||
if (off.size() == on.size()){
|
||||
for (int j = 0; j < on.size(); j++) {
|
||||
onTime = onTime + (int) (off.get(j).getTime().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli() + 1000L - on.get(j).getTime().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli()) / (1000*60);
|
||||
}
|
||||
} else {
|
||||
for (int j = 0; j < on.size(); j++) {
|
||||
if (j == on.size() - 1){
|
||||
onTime = onTime + (int) (format.parse(endTime).getTime() + 1000L - on.get(j).getTime().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli()) / (1000*60);
|
||||
} else {
|
||||
onTime = onTime + (int) (off.get(j).getTime().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli() + 1000L - on.get(j).getTime().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli()) / (1000*60);
|
||||
}
|
||||
}
|
||||
}
|
||||
offTime = DAY_MINUTE-onTime;
|
||||
}
|
||||
} else {
|
||||
LocalDateTime updateTime = LocalDateTime.ofInstant(infoList.get(0).getTime(), ZoneId.systemDefault());
|
||||
if (Objects.equals(infoList.get(0).getType(),0)) {
|
||||
onTime = 0;
|
||||
offTime = (int) (format.parse(endTime).getTime() + 1000L - updateTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli()) / (1000*60);
|
||||
} else {
|
||||
offTime = 0;
|
||||
onTime = (int) (format.parse(endTime).getTime() + 1000L - updateTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli()) / (1000*60);
|
||||
}
|
||||
}
|
||||
onlineRate.setDevId(infoList.get(0).getDevId());
|
||||
onlineRate.setOnlineMin(onTime);
|
||||
onlineRate.setOfflineMin(offTime);
|
||||
onlineRate.setOnlineRate(Double.parseDouble(String.format("%.2f",onTime*1.0/DAY_MINUTE*100)));
|
||||
onlineRate.setTime(Instant.ofEpochMilli(a));
|
||||
result.add(onlineRate);
|
||||
}
|
||||
}
|
||||
} catch (ParseException e) {
|
||||
e.getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
insertData(result);
|
||||
}
|
||||
|
||||
*/
|
||||
/**
|
||||
* 获取pqs_communicate数据
|
||||
* @param list 装置集合
|
||||
* @param startTime 开始时间
|
||||
* @param endTime 结束时间
|
||||
* @return pqs_communicate数据
|
||||
*//*
|
||||
|
||||
private List<PqsCommunicate> getPqsCommunicate(List<String> list, String startTime, String endTime){
|
||||
SelectQueryImpl selectQuery = select().from(influxDbConfig.getDatabase(), PQS_COMMUNICATE);
|
||||
WhereQueryImpl<SelectQueryImpl> where = selectQuery.where();
|
||||
whereAndNested(list, where);
|
||||
where.and(gte(TIME, startTime)).and(lte(TIME, endTime));
|
||||
where.tz(TZ);
|
||||
QueryResult queryResult = influxDbUtils.query(selectQuery.getCommand());
|
||||
InfluxDBResultMapper resultMapper = new InfluxDBResultMapper();
|
||||
return resultMapper.toPOJO(queryResult, PqsCommunicate.class);
|
||||
}
|
||||
|
||||
*/
|
||||
/**
|
||||
* 拼接装置条件
|
||||
* @param list 装置集合
|
||||
* @param whereQuery WhereQueryImpl
|
||||
*//*
|
||||
|
||||
private void whereAndNested(List<String> list, WhereQueryImpl<SelectQueryImpl> whereQuery) {
|
||||
List<Clause> clauses = new ArrayList<>();
|
||||
list.forEach(item->{
|
||||
Clause clause = eq(DEV_ID, item);
|
||||
clauses.add(clause);
|
||||
});
|
||||
WhereNested<WhereQueryImpl<SelectQueryImpl>> andNested = whereQuery.andNested();
|
||||
for (Clause clause : clauses) {
|
||||
andNested.or(clause);
|
||||
}
|
||||
andNested.close();
|
||||
}
|
||||
|
||||
*/
|
||||
/**
|
||||
* 获取pqs_communicate数据最新一条数据
|
||||
* @param list 装置id集合
|
||||
* @return pqs_communicate数据
|
||||
*//*
|
||||
|
||||
private List<PqsCommunicate> getData(List<String> list){
|
||||
SelectQueryImpl selectQuery = select().from(influxDbConfig.getDatabase(), PQS_COMMUNICATE);
|
||||
WhereQueryImpl<SelectQueryImpl> where = selectQuery.where();
|
||||
whereAndNested(list, where);
|
||||
where.groupBy(DEV_ID).orderBy(desc()).limit(1);
|
||||
where.tz(TZ);
|
||||
QueryResult queryResult = influxDbUtils.query(selectQuery.getCommand());
|
||||
InfluxDBResultMapper resultMapper = new InfluxDBResultMapper();
|
||||
return resultMapper.toPOJO(queryResult, PqsCommunicate.class);
|
||||
}
|
||||
|
||||
*/
|
||||
/**
|
||||
* 功能描述:插入pqs_integrity表数据
|
||||
* @author xy
|
||||
* @param list 数据集合
|
||||
* @date 2022/5/12 8:55
|
||||
*//*
|
||||
|
||||
private void insertData(List<PqsOnlineRate> list){
|
||||
List<String> records = new ArrayList<>();
|
||||
list.forEach(item->{
|
||||
Map<String, String> tags = new HashMap<>();
|
||||
Map<String, Object> fields = new HashMap<>();
|
||||
tags.put(DEV_ID,item.getDevId());
|
||||
fields.put(ONLINE_MIN,item.getOnlineMin());
|
||||
fields.put(OFFLINE_MIN,item.getOfflineMin());
|
||||
fields.put(ONLINE_RATE,item.getOnlineRate());
|
||||
Point point = influxDbUtils.pointBuilder(PQS_ONLINERATE, item.getTime().toEpochMilli(), TimeUnit.MILLISECONDS, tags, fields);
|
||||
BatchPoints batchPoints = BatchPoints.database(influxDbConfig.getDatabase()).tag(DEV_ID, item.getDevId()).retentionPolicy("").consistency(InfluxDB.ConsistencyLevel.ALL).build();
|
||||
batchPoints.point(point);
|
||||
records.add(batchPoints.lineProtocol());
|
||||
});
|
||||
influxDbUtils.batchInsert(influxDbConfig.getDatabase(),"", InfluxDB.ConsistencyLevel.ALL, records);
|
||||
}
|
||||
}
|
||||
*/
|
||||
Reference in New Issue
Block a user