谐波模块:部分业务influxdb转mysql

This commit is contained in:
wurui
2023-04-06 14:28:50 +08:00
parent e45a3d6dab
commit a620ef6a77
38 changed files with 1537 additions and 440 deletions

View File

@@ -0,0 +1,30 @@
package com.njcn.harmonic.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.njcn.harmonic.pojo.po.PQSComAssesPO;
import com.njcn.harmonic.pojo.po.day.RStatComassesDPO;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* <p>
* 电能质量综合评估 Mapper 接口
* </p>
*
* @author wr
* @since 2023-03-31
*/
public interface RStatComassesDMapper extends BaseMapper<RStatComassesDPO> {
/**
* 统计综合评估平均值
* @param lineIndexes
* @param searchBeginTime
* @param searchEndTime
* @return
*/
List<PQSComAssesPO> getAvgCount(@Param("ids") List<String> lineIndexes,
@Param("statTime") String searchBeginTime,
@Param("endTime") String searchEndTime);
}

View File

@@ -0,0 +1,16 @@
package com.njcn.harmonic.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.njcn.harmonic.pojo.po.RStatDataVD;
/**
* <p>
* Mapper 接口
* </p>
*
* @author wr
* @since 2023-03-31
*/
public interface RStatDataVDMapper extends BaseMapper<RStatDataVD> {
}

View File

@@ -0,0 +1,23 @@
package com.njcn.harmonic.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.njcn.harmonic.pojo.po.day.RStatLimitRateDPO;
import com.njcn.harmonic.pojo.vo.RStatLimitRateDVO;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* <p>
* 合格率统计日表(越限次数) Mapper 接口
* </p>
*
* @author wr
* @since 2023-04-03
*/
public interface RStatLimitRateDMapper extends BaseMapper<RStatLimitRateDPO> {
List<RStatLimitRateDVO> getSumPassRate(@Param("ids") List<String> lineIndexes,
@Param("statTime") String searchBeginTime,
@Param("endTime") String searchEndTime);
}

View File

@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.njcn.harmonic.mapper.RStatComassesDMapper">
<select id="getAvgCount" resultType="com.njcn.harmonic.pojo.po.PQSComAssesPO">
SELECT
line_id,
AVG ( vu_dev1 ) AS vu_dev1,
AVG ( vu_dev2 ) AS vu_dev2,
AVG ( vu_dev3 ) AS vu_dev3,
AVG ( vu_dev4 ) AS vu_dev4,
AVG ( vu_dev5 ) AS vu_dev5,
AVG ( freq_dev1 ) AS freq_dev1,
AVG ( freq_dev2 ) AS freq_dev2,
AVG ( freq_dev3 ) AS freq_dev3,
AVG ( freq_dev4 ) AS freq_dev4,
AVG ( freq_dev5 ) AS freq_dev5,
AVG ( data_plt1 ) AS data_plt1,
AVG ( data_plt2 ) AS data_plt2,
AVG ( data_plt3 ) AS data_plt3,
AVG ( data_plt4 ) AS data_plt4,
AVG ( data_plt5 ) AS data_plt5,
AVG ( v_unbalance1 ) AS v_unbalance1,
AVG ( v_unbalance2 ) AS v_unbalance2,
AVG ( v_unbalance3 ) AS v_unbalance3,
AVG ( v_unbalance4 ) AS v_unbalance4,
AVG ( v_unbalance5 ) AS v_unbalance5,
AVG ( v_thd1 ) AS v_thd1,
AVG ( v_thd2 ) AS v_thd2,
AVG ( v_thd3 ) AS v_thd3,
AVG ( v_thd4 ) AS v_thd4,
AVG ( v_thd5 ) AS v_thd5,
AVG ( event1 ) AS event1,
AVG ( event2 ) AS event2,
AVG ( event3 ) AS event3,
AVG ( event4 ) AS event4,
AVG ( event5 ) AS event5
FROM
r_stat_comasses_d
<where>
<if test=" ids != null and ids.size > 0">
AND line_id IN
<foreach collection='ids' item='item' index="index" open='(' separator=',' close=')'>
#{item}
</foreach>
</if>
<if test=" statTime != null and statTime !=''">
AND time_id >= #{statTime}
</if>
<if test="endTime != null and endTime != ''">
AND time_id &lt;= #{endTime}
</if>
</where>
GROUP BY line_id
</select>
</mapper>

View File

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.njcn.harmonic.mapper.RStatDataVDMapper">
</mapper>

View File

@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.njcn.harmonic.mapper.RStatLimitRateDMapper">
<select id="getSumPassRate" resultType="com.njcn.harmonic.pojo.vo.RStatLimitRateDVO">
SELECT
SUM( all_time ) AS alltime,
SUM( freq_dev_overtime ) AS frequency,
SUM( ubalance_overtime ) AS uBalance,
SUM( i_neg_overtime ) AS iNeg,
SUM( iharm_13_overtime ) AS harmElec,
SUM( uharm_4_overtime ) AS harmVoltage,
SUM( flicker_overtime ) AS flicker,
SUM( flicker_all_time ) AS allFlicker,
SUM( voltage_dev_overtime ) AS voltageDeviation,
SUM( inuharm_9_overtime ) AS inUharm
FROM
r_stat_limit_rate_d
<where>
<if test=" ids != null and ids.size > 0">
AND my_index IN
<foreach collection='ids' item='item' index="index" open='(' separator=',' close=')'>
#{item}
</foreach>
</if>
<if test=" statTime != null and statTime !=''">
AND time_id >= #{statTime}
</if>
<if test="endTime != null and endTime != ''">
AND time_id &lt;= #{endTime}
</if>
</where>
</select>
</mapper>

View File

@@ -1,6 +1,8 @@
package com.njcn.harmonic.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.njcn.device.pq.pojo.param.DeviceInfoParam;
import com.njcn.harmonic.pojo.po.day.RStatComassesDPO;
import com.njcn.harmonic.pojo.vo.ComAssessVO;
import java.util.List;
@@ -10,7 +12,7 @@ import java.util.List;
* @author: chenchao
* @date: 2022/04/21 10:21
*/
public interface ComAssessService {
public interface ComAssessService extends IService<RStatComassesDPO> {
/**
* 获取稳态综合评估分值

View File

@@ -0,0 +1,16 @@
package com.njcn.harmonic.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.njcn.harmonic.pojo.po.RStatDataVD;
/**
* <p>
* 服务类
* </p>
*
* @author wr
* @since 2023-03-31
*/
public interface IRStatDataVDService extends IService<RStatDataVD> {
}

View File

@@ -0,0 +1,16 @@
package com.njcn.harmonic.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.njcn.harmonic.pojo.po.day.RStatLimitRateDPO;
/**
* <p>
* 合格率统计日表(越限次数) 服务类
* </p>
*
* @author wr
* @since 2023-04-03
*/
public interface IRStatLimitRateDService extends IService<RStatLimitRateDPO> {
}

View File

@@ -1,8 +1,13 @@
package com.njcn.harmonic.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateUtil;
import com.njcn.device.pq.pojo.param.PulicTimeStatisParam;
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;
@@ -15,6 +20,7 @@ import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
@@ -30,6 +36,7 @@ public class AssesServiceImpl implements AssesService {
private final ComAssesUtil comAssesUtil;
private final RStatComassesDMapper rStatComassesDMapper;
@Override
public AssesVO getQualityAssessData(PulicTimeStatisParam pulicTimeStatisParam) {
AssesVO assesVO = new AssesVO();
@@ -48,54 +55,60 @@ public class AssesServiceImpl implements AssesService {
* 查询监测点的数据完整性
*/
private Float getCondition(String lineList, String startTime, String endTime) {
float synData;
if (!lineList.isEmpty()) {
//组装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 (");
//sql语句
stringBuilder.append(InfluxDBPublicParam.LINE_ID + "='").append(lineList).append("')");
stringBuilder.append(" group by " + InfluxDBPublicParam.LINE_ID).append(" ");
stringBuilder.append(InfluxDBPublicParam.TIME_ZONE);
String sql = "SELECT" +
" MEAN(freq_dev1) AS freq_dev1," +
" MEAN(freq_dev2) AS freq_dev2," +
" MEAN(freq_dev3) AS freq_dev3," +
" MEAN(freq_dev4) AS freq_dev4," +
" MEAN(freq_dev5) AS freq_dev5," +
" MEAN(vu_dev1) AS vu_dev1," +
" MEAN(vu_dev2) AS vu_dev2," +
" MEAN(vu_dev3) AS vu_dev3," +
" MEAN(vu_dev4) AS vu_dev4," +
" MEAN(vu_dev5) AS vu_dev5," +
" MEAN(data_plt1) AS data_plt1," +
" MEAN(data_plt2) AS data_plt2," +
" MEAN(data_plt3) AS data_plt3," +
" MEAN(data_plt4) AS data_plt4," +
" MEAN(data_plt5) AS data_plt5," +
" MEAN(v_unbalance1) AS v_unbalance1," +
" MEAN(v_unbalance2) AS v_unbalance2," +
" MEAN(v_unbalance3) AS v_unbalance3," +
" MEAN(v_unbalance4) AS v_unbalance4," +
" MEAN(v_unbalance5) AS v_unbalance5," +
" MEAN(v_thd1) AS v_thd1," +
" MEAN(v_thd2) AS v_thd2," +
" MEAN(v_thd3) AS v_thd3," +
" MEAN(v_thd4) AS v_thd4," +
" MEAN(v_thd5) AS v_thd5," +
" MEAN(event1) AS event1," +
" MEAN(event2) AS event2," +
" MEAN(event3) AS event3," +
" MEAN(event4) AS event4," +
" MEAN(event5) AS event5" +
" FROM" +
" pqs_comasses" +
" where " + stringBuilder.toString();
//结果集
QueryResult result = influxDbUtils.query(sql);
//处理结果集
InfluxDBResultMapper influxDBResultMapper = new InfluxDBResultMapper();
List<PqsComasses> communicateList = influxDBResultMapper.toPOJO(result, PqsComasses.class);
// //组装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 (");
// //sql语句
// stringBuilder.append(InfluxDBPublicParam.LINE_ID + "='").append(lineList).append("')");
// stringBuilder.append(" group by " + InfluxDBPublicParam.LINE_ID).append(" ");
// stringBuilder.append(InfluxDBPublicParam.TIME_ZONE);
// String sql = "SELECT" +
// " MEAN(freq_dev1) AS freq_dev1," +
// " MEAN(freq_dev2) AS freq_dev2," +
// " MEAN(freq_dev3) AS freq_dev3," +
// " MEAN(freq_dev4) AS freq_dev4," +
// " MEAN(freq_dev5) AS freq_dev5," +
// " MEAN(vu_dev1) AS vu_dev1," +
// " MEAN(vu_dev2) AS vu_dev2," +
// " MEAN(vu_dev3) AS vu_dev3," +
// " MEAN(vu_dev4) AS vu_dev4," +
// " MEAN(vu_dev5) AS vu_dev5," +
// " MEAN(data_plt1) AS data_plt1," +
// " MEAN(data_plt2) AS data_plt2," +
// " MEAN(data_plt3) AS data_plt3," +
// " MEAN(data_plt4) AS data_plt4," +
// " MEAN(data_plt5) AS data_plt5," +
// " MEAN(v_unbalance1) AS v_unbalance1," +
// " MEAN(v_unbalance2) AS v_unbalance2," +
// " MEAN(v_unbalance3) AS v_unbalance3," +
// " MEAN(v_unbalance4) AS v_unbalance4," +
// " MEAN(v_unbalance5) AS v_unbalance5," +
// " MEAN(v_thd1) AS v_thd1," +
// " MEAN(v_thd2) AS v_thd2," +
// " MEAN(v_thd3) AS v_thd3," +
// " MEAN(v_thd4) AS v_thd4," +
// " MEAN(v_thd5) AS v_thd5," +
// " MEAN(event1) AS event1," +
// " MEAN(event2) AS event2," +
// " MEAN(event3) AS event3," +
// " MEAN(event4) AS event4," +
// " MEAN(event5) AS event5" +
// " FROM" +
// " pqs_comasses" +
// " where " + stringBuilder.toString();
// //结果集
// QueryResult result = influxDbUtils.query(sql);
// //处理结果集
// InfluxDBResultMapper influxDBResultMapper = new InfluxDBResultMapper();
// List<PqsComasses> communicateList = influxDBResultMapper.toPOJO(result, PqsComasses.class);
List<PQSComAssesPO> avgCount = rStatComassesDMapper.getAvgCount(Arrays.asList(lineList),
DateUtil.beginOfDay(DateUtil.parse(startTime)).toString(),
DateUtil.beginOfDay(DateUtil.parse(endTime)).toString());
List<PqsComasses> communicateList = BeanUtil.copyToList(avgCount,PqsComasses.class);
if (!CollectionUtils.isEmpty(communicateList)) {
synData = comAssesUtil.getAllComAss(communicateList);
} else {

View File

@@ -1,10 +1,15 @@
package com.njcn.harmonic.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
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.harmonic.mapper.RStatComassesDMapper;
import com.njcn.harmonic.pojo.dto.ComAssessDTO;
import com.njcn.harmonic.pojo.po.PQSComAssesPO;
import com.njcn.harmonic.pojo.po.day.RStatComassesDPO;
import com.njcn.harmonic.pojo.vo.ComAssessVO;
import com.njcn.harmonic.service.ComAssessService;
import com.njcn.harmonic.utils.HarmonicComAssesUtil;
@@ -28,7 +33,7 @@ import java.util.stream.Collectors;
*/
@Service
@AllArgsConstructor
public class ComAssessServiceImpl implements ComAssessService {
public class ComAssessServiceImpl extends ServiceImpl<RStatComassesDMapper, RStatComassesDPO> implements ComAssessService {
private final GeneralDeviceInfoClient generalDeviceInfoClient;
@@ -52,13 +57,11 @@ public class ComAssessServiceImpl implements ComAssessService {
comAssessVO.setMonitors(lineIndexes.size());
if (!CollectionUtils.isEmpty(lineIndexes)) {
List<PQSComAssesPO> pqsComAssesPOS = getComAccessData(lineIndexes, comAccessParam.getSearchBeginTime(), comAccessParam.getSearchEndTime());
if (!CollectionUtils.isEmpty(pqsComAssesPOS)) {
setResults(pqsComAssesPOS,comAssessDTOS);
float allComAss = comAssesUtil.getAllComAss(comAssessDTOS);
String lv = getLevel(allComAss);
comAssessVO.setData(allComAss);
comAssessVO.setLevel(lv);
}
setResults(pqsComAssesPOS,comAssessDTOS);
float allComAss = comAssesUtil.getAllComAss(comAssessDTOS);
String lv = getLevel(allComAss);
comAssessVO.setData(allComAss);
comAssessVO.setLevel(lv);
}
List<ComAssessVO> children = new ArrayList<>();
List<ComAssessDTO> childrenDTOS = new ArrayList<>();
@@ -77,13 +80,11 @@ public class ComAssessServiceImpl implements ComAssessService {
assessVO.setMonitors(lines.size());
if (!CollectionUtils.isEmpty(lines)) {
List<PQSComAssesPO> pqsComAssesPOS = getComAccessData(lines, comAccessParam.getSearchBeginTime(), comAccessParam.getSearchEndTime());
if (!CollectionUtils.isEmpty(pqsComAssesPOS)) {
setResults(pqsComAssesPOS,childrenDTOS);
float allComAss = comAssesUtil.getAllComAss(childrenDTOS);
String lv = getLevel(allComAss);
assessVO.setData(allComAss);
assessVO.setLevel(lv);
}
setResults(pqsComAssesPOS,childrenDTOS);
float allComAss = comAssesUtil.getAllComAss(childrenDTOS);
String lv = getLevel(allComAss);
assessVO.setData(allComAss);
assessVO.setLevel(lv);
}
children.add(assessVO);
comAssessVO.setChildren(children);
@@ -139,15 +140,15 @@ public class ComAssessServiceImpl implements ComAssessService {
comAssessDTO.setVUnbalance4(vu4);
float vu5 = new BigDecimal(pqsComAssesPOS.get(i).getVUnbalance5()).setScale(4, BigDecimal.ROUND_HALF_UP).floatValue();
comAssessDTO.setVUnbalance5(vu5);
float vt1 = new BigDecimal(pqsComAssesPOS.get(i).getVTHD1()).setScale(4, BigDecimal.ROUND_HALF_UP).floatValue();
float vt1 = new BigDecimal(pqsComAssesPOS.get(i).getVThd1()).setScale(4, BigDecimal.ROUND_HALF_UP).floatValue();
comAssessDTO.setVTHD1(vt1);
float vt2 = new BigDecimal(pqsComAssesPOS.get(i).getVTHD2()).setScale(4, BigDecimal.ROUND_HALF_UP).floatValue();
float vt2 = new BigDecimal(pqsComAssesPOS.get(i).getVThd2()).setScale(4, BigDecimal.ROUND_HALF_UP).floatValue();
comAssessDTO.setVTHD2(vt2);
float vt3 = new BigDecimal(pqsComAssesPOS.get(i).getVTHD3()).setScale(4, BigDecimal.ROUND_HALF_UP).floatValue();
float vt3 = new BigDecimal(pqsComAssesPOS.get(i).getVThd3()).setScale(4, BigDecimal.ROUND_HALF_UP).floatValue();
comAssessDTO.setVTHD3(vt3);
float vt4 = new BigDecimal(pqsComAssesPOS.get(i).getVTHD4()).setScale(4, BigDecimal.ROUND_HALF_UP).floatValue();
float vt4 = new BigDecimal(pqsComAssesPOS.get(i).getVThd4()).setScale(4, BigDecimal.ROUND_HALF_UP).floatValue();
comAssessDTO.setVTHD4(vt4);
float vt5 = new BigDecimal(pqsComAssesPOS.get(i).getVTHD5()).setScale(4, BigDecimal.ROUND_HALF_UP).floatValue();
float vt5 = new BigDecimal(pqsComAssesPOS.get(i).getVThd5()).setScale(4, BigDecimal.ROUND_HALF_UP).floatValue();
comAssessDTO.setVTHD5(vt5);
float e1 = new BigDecimal(pqsComAssesPOS.get(i).getEvent1()).setScale(4, BigDecimal.ROUND_HALF_UP).floatValue();
comAssessDTO.setEvent1(e1);
@@ -190,27 +191,37 @@ public class ComAssessServiceImpl implements ComAssessService {
* @param searchEndTime
*/
private List<PQSComAssesPO> getComAccessData(List<String> lineIndexes, String searchBeginTime, String searchEndTime) {
//组装sql语句
StringBuilder builder = new StringBuilder();
builder.append("MEAN(vu_dev1)AS vu_dev1, MEAN(vu_dev2)AS vu_dev2, MEAN(vu_dev3)AS vu_dev3, MEAN(vu_dev4)AS vu_dev4, MEAN(vu_dev5)AS vu_dev5, MEAN(freq_dev1)AS freq_dev1, MEAN(freq_dev2)AS freq_dev2, MEAN(freq_dev3)AS freq_dev3, MEAN(freq_dev4)AS freq_dev4, MEAN(freq_dev5)AS freq_dev5, MEAN(data_plt1)AS data_plt1, MEAN(data_plt2)AS data_plt2, MEAN(data_plt3)AS data_plt3, MEAN(data_plt4)AS data_plt4, MEAN(data_plt5)AS data_plt5, MEAN(v_unbalance1)AS v_unbalance1, MEAN(v_unbalance2)AS v_unbalance2, MEAN(v_unbalance3)AS v_unbalance3, MEAN(v_unbalance4)AS v_unbalance4, MEAN(v_unbalance5)AS v_unbalance5, MEAN(v_thd1)AS v_thd1, MEAN(v_thd2)AS v_thd2, MEAN(v_thd3)AS v_thd3, MEAN(v_thd4)AS v_thd4, MEAN(v_thd5)AS v_thd5, MEAN(event1)AS event1, MEAN(event2)AS event2, MEAN(event3)AS event3, MEAN(event4)AS event4, MEAN(event5)AS event5");
StringBuffer string = new StringBuffer();
string.append(InfluxDBPublicParam.TIME + " >= '" + searchBeginTime + InfluxDBPublicParam.START_TIME + "' and " + InfluxDBPublicParam.TIME + " <= '" + searchEndTime + InfluxDBPublicParam.END_TIME + "' and ");
for (int i = 0; i < lineIndexes.size(); i++) {
if (lineIndexes.size() - i != 1) {
string.append(InfluxDBPublicParam.LINE_ID + "='").append(lineIndexes.get(i)).append("' or ");
} else {
string.append(InfluxDBPublicParam.LINE_ID + "='").append(lineIndexes.get(i)).append("' group by " + InfluxDBPublicParam.LINE_ID);
}
List<PQSComAssesPO> avgCount = this.baseMapper.getAvgCount(lineIndexes,
DateUtil.beginOfDay(DateUtil.parse(searchBeginTime)).toString(),
DateUtil.beginOfDay(DateUtil.parse(searchEndTime)).toString());
if(CollUtil.isNotEmpty(avgCount)){
return avgCount;
}
//sql语句
String sql = "SELECT "+ builder +" FROM "+InfluxDBPublicParam.PQS_COMASSES+" WHERE " + string + InfluxDBPublicParam.TIME_ZONE;
//结果集
System.out.println("--------------->>>>"+sql);
QueryResult result = influxDbUtils.query(sql);
//结果集映射到对象中
InfluxDBResultMapper resultMapper = new InfluxDBResultMapper();
List<PQSComAssesPO> pqsComAssesPOS = resultMapper.toPOJO(result, PQSComAssesPO.class);
return pqsComAssesPOS;
return new ArrayList<>();
// //组装sql语句
// StringBuilder builder = new StringBuilder();
// builder.append("MEAN(vu_dev1)AS vu_dev1, MEAN(vu_dev2)AS vu_dev2, MEAN(vu_dev3)AS vu_dev3, MEAN(vu_dev4)AS vu_dev4, MEAN(vu_dev5)AS vu_dev5, MEAN(freq_dev1)AS freq_dev1, MEAN(freq_dev2)AS freq_dev2, MEAN(freq_dev3)AS freq_dev3, MEAN(freq_dev4)AS freq_dev4, MEAN(freq_dev5)AS freq_dev5, MEAN(data_plt1)AS data_plt1, MEAN(data_plt2)AS data_plt2, MEAN(data_plt3)AS data_plt3, MEAN(data_plt4)AS data_plt4, MEAN(data_plt5)AS data_plt5, MEAN(v_unbalance1)AS v_unbalance1, MEAN(v_unbalance2)AS v_unbalance2, MEAN(v_unbalance3)AS v_unbalance3, MEAN(v_unbalance4)AS v_unbalance4, MEAN(v_unbalance5)AS v_unbalance5, MEAN(v_thd1)AS v_thd1, MEAN(v_thd2)AS v_thd2, MEAN(v_thd3)AS v_thd3, MEAN(v_thd4)AS v_thd4, MEAN(v_thd5)AS v_thd5, MEAN(event1)AS event1, MEAN(event2)AS event2, MEAN(event3)AS event3, MEAN(event4)AS event4, MEAN(event5)AS event5");
// StringBuffer string = new StringBuffer();
// string.append(InfluxDBPublicParam.TIME + " >= '" + searchBeginTime + InfluxDBPublicParam.START_TIME + "' and " + InfluxDBPublicParam.TIME + " <= '" + searchEndTime + InfluxDBPublicParam.END_TIME + "' and ");
// for (int i = 0; i < lineIndexes.size(); i++) {
// if (lineIndexes.size() - i != 1) {
// string.append(InfluxDBPublicParam.LINE_ID + "='").append(lineIndexes.get(i)).append("' or ");
// } else {
// string.append(InfluxDBPublicParam.LINE_ID + "='").append(lineIndexes.get(i)).append("' group by " + InfluxDBPublicParam.LINE_ID);
// }
// }
// //sql语句
// String sql = "SELECT "+ builder +" FROM "+InfluxDBPublicParam.PQS_COMASSES+" WHERE " + string + InfluxDBPublicParam.TIME_ZONE;
// //结果集
// System.out.println("--------------->>>>"+sql);
// QueryResult result = influxDbUtils.query(sql);
// //结果集映射到对象中
// InfluxDBResultMapper resultMapper = new InfluxDBResultMapper();
// List<PQSComAssesPO> pqsComAssesPOS = resultMapper.toPOJO(result, PQSComAssesPO.class);
// return pqsComAssesPOS;
}

View File

@@ -1,21 +1,23 @@
package com.njcn.harmonic.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.CharUtil;
import cn.hutool.core.util.StrUtil;
import com.njcn.common.config.GeneralInfo;
import com.njcn.device.pq.api.GeneralDeviceInfoClient;
import com.njcn.device.pq.api.LineFeignClient;
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.param.OnlineRateParam;
import com.njcn.device.pq.pojo.vo.RStatIntegrityVO;
import com.njcn.harmonic.mapper.IntegrityMapper;
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.param.InfluxDBPublicParam;
import com.njcn.influxdb.utils.InfluxDbUtils;
import com.njcn.poi.excel.ExcelUtil;
import com.njcn.poi.pojo.bo.BaseLineExcelBody;
@@ -25,7 +27,6 @@ import com.njcn.system.pojo.enums.StatisticsEnum;
import com.njcn.web.utils.RequestUtil;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.influxdb.dto.QueryResult;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
@@ -56,6 +57,8 @@ public class IntegrityServiceImpl implements IntegrityService {
private final GeneralInfo generalInfo;
private final LineFeignClient lineFeignClient;
@Override
public List<IntegrityVO> getIntegrityData(DeviceInfoParam.BusinessParam integrityParam) {
List<IntegrityVO> result = new ArrayList<>();
@@ -212,7 +215,7 @@ public class IntegrityServiceImpl implements IntegrityService {
log.error("文件路径" + targetDir);
log.error("文件名" + fileName);
File parentDir = new File(targetDir);
if(!parentDir.exists()){
if (!parentDir.exists()) {
parentDir.mkdirs();
}
File excel = new File(targetDir, fileName);
@@ -350,39 +353,58 @@ public class IntegrityServiceImpl implements IntegrityService {
*/
private List<PublicDTO> getCondition(List<String> lineList, String startTime, String endTime) {
List<PublicDTO> integrityList = new ArrayList<>();
//组装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 (");
for (int i = 0; i < lineList.size(); i++) {
if (lineList.size() - i != 1) {
stringBuilder.append(InfluxDBPublicParam.LINE_ID + "='").append(lineList.get(i)).append("' or ");
} else {
stringBuilder.append(InfluxDBPublicParam.LINE_ID + "='").append(lineList.get(i)).append("')");
}
}
//sql语句
String sql = "SELECT SUM(" + InfluxDBPublicParam.REAL + ")/SUM(" + InfluxDBPublicParam.DUE + ")*100 AS integrity FROM "+InfluxDBPublicParam.PQS_INTEGRITY+" WHERE " + stringBuilder + " group by " + InfluxDBPublicParam.LINE_ID + " tz('Asia/Shanghai')";
//结果集
QueryResult result = influxDbUtils.query(sql);
//处理结果集
List<QueryResult.Series> list = result.getResults().get(0).getSeries();
if (!CollectionUtils.isEmpty(list)) {
list.forEach(po -> {
OnlineRateParam param = new OnlineRateParam();
param.setIds(lineList);
param.setStartTime(DateUtil.beginOfDay(DateUtil.parse(startTime)).toString());
param.setEndTime(DateUtil.endOfDay(DateUtil.parse(endTime)).toString());
List<RStatIntegrityVO> data = lineFeignClient.getOnIntegrityByIds(param).getData();
if (!CollectionUtils.isEmpty(data)) {
data.forEach(po -> {
PublicDTO publicDTO = new PublicDTO();
List<List<Object>> valueList = po.getValues();
String index = po.getTags().get(InfluxDBPublicParam.LINE_ID);
if (!CollectionUtils.isEmpty(valueList)) {
for (List<Object> value : valueList) {
//数据完整性 保留四位小数
Double integrity = value.get(1) == null ? 3.14159 : BigDecimal.valueOf(Double.parseDouble(value.get(1).toString())).setScale(2, RoundingMode.HALF_UP).doubleValue();
publicDTO.setId(index);
publicDTO.setData((integrity > 100.00) ? 100.00 : integrity);
}
}
//数据完整性 保留四位小数
Double integrity = po.getIntegrityRate() == null ? 3.14159 : BigDecimal.valueOf(Double.parseDouble(po.getIntegrityRate().toString())).setScale(2, RoundingMode.HALF_UP).doubleValue();
publicDTO.setId(po.getLineIndex());
publicDTO.setData((integrity > 100.00) ? 100.00 : integrity);
integrityList.add(publicDTO);
});
}
return integrityList;
// //组装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 (");
// for (int i = 0; i < lineList.size(); i++) {
// if (lineList.size() - i != 1) {
// stringBuilder.append(InfluxDBPublicParam.LINE_ID + "='").append(lineList.get(i)).append("' or ");
// } else {
// stringBuilder.append(InfluxDBPublicParam.LINE_ID + "='").append(lineList.get(i)).append("')");
// }
// }
// //sql语句
// String sql = "SELECT SUM(" + InfluxDBPublicParam.REAL + ")/SUM(" + InfluxDBPublicParam.DUE + ")*100 AS integrity FROM "+InfluxDBPublicParam.PQS_INTEGRITY+" WHERE " + stringBuilder + " group by " + InfluxDBPublicParam.LINE_ID + " tz('Asia/Shanghai')";
// //结果集
// QueryResult result = influxDbUtils.query(sql);
// //处理结果集
// List<QueryResult.Series> list = result.getResults().get(0).getSeries();
// if (!CollectionUtils.isEmpty(list)) {
// list.forEach(po -> {
// PublicDTO publicDTO = new PublicDTO();
// List<List<Object>> valueList = po.getValues();
// String index = po.getTags().get(InfluxDBPublicParam.LINE_ID);
// if (!CollectionUtils.isEmpty(valueList)) {
// for (List<Object> value : valueList) {
// //数据完整性 保留四位小数
// Double integrity = value.get(1) == null ? 3.14159 : BigDecimal.valueOf(Double.parseDouble(value.get(1).toString())).setScale(2, RoundingMode.HALF_UP).doubleValue();
// publicDTO.setId(index);
// publicDTO.setData((integrity > 100.00) ? 100.00 : integrity);
// }
// }
// integrityList.add(publicDTO);
// });
// }
// return integrityList;
}
}

View File

@@ -1,10 +1,15 @@
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.njcn.common.config.GeneralInfo;
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;
@@ -144,39 +149,57 @@ public class OnlineRateDataServiceImpl implements OnlineRateDataService {
*/
private List<PublicDTO> getCondition(List<String> deviceIndexes, String startTime, String endTime) {
List<PublicDTO> publicDTOList = new ArrayList<>();
//组装sql语句
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(TIME + " >= '").append(startTime).append(START_TIME).append("' and ").append(TIME).append(" <= '").append(endTime).append(END_TIME).append("' and (");
for (int i = 0; i < deviceIndexes.size(); i++) {
if (deviceIndexes.size() - i != 1) {
stringBuilder.append(DEV_INDEX + "='").append(deviceIndexes.get(i)).append("' or ");
} else {
stringBuilder.append(DEV_INDEX + "='").append(deviceIndexes.get(i)).append("')");
}
}
//sql语句
String sql = "SELECT (SUM(" + ONLINE_MIN + ")/(SUM(" + OFFLINE_MIN + ")+SUM(" + ONLINE_MIN + ")))*100 AS onlineRate FROM "+PQS_ONLINERATE+" WHERE " + stringBuilder + " group by " + DEV_INDEX +" tz('Asia/Shanghai')";
//结果集
QueryResult result = influxDbUtils.query(sql);
//处理结果集
List<QueryResult.Series> list = result.getResults().get(0).getSeries();
if (!CollectionUtils.isEmpty(list)) {
list.forEach(po -> {
OnlineRateParam param=new OnlineRateParam();
param.setIds(deviceIndexes);
param.setStartTime( DateUtil.beginOfDay(DateUtil.parse(startTime)).toString());
param.setEndTime( DateUtil.endOfDay(DateUtil.parse(endTime)).toString());
List<RStatOnlinerateVO> data = generalDeviceInfoClient.getOnlineRateByDevIds(param).getData();
if (CollUtil.isNotEmpty(data)) {
data.forEach(po -> {
PublicDTO publicDTO = new PublicDTO();
List<List<Object>> valueList = po.getValues();
String index = po.getTags().get(DEV_INDEX);
if (!CollectionUtils.isEmpty(valueList)) {
for (List<Object> value : valueList) {
//终端在线率 保留两位小数
Double onlineRate = value.get(1) == null ? null : BigDecimal.valueOf(Double.parseDouble(value.get(1).toString())).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
publicDTO.setId(index);
publicDTO.setData(onlineRate);
}
}
//终端在线率 保留两位小数
Double onlineRate = po.getOnlineRate() == null ? null : BigDecimal.valueOf(Double.parseDouble(po.getOnlineRate().toString())).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
publicDTO.setId(po.getDevIndex());
publicDTO.setData(onlineRate);
publicDTOList.add(publicDTO);
});
}
return publicDTOList;
// //组装sql语句
// StringBuilder stringBuilder = new StringBuilder();
// stringBuilder.append(TIME + " >= '").append(startTime).append(START_TIME).append("' and ").append(TIME).append(" <= '").append(endTime).append(END_TIME).append("' and (");
// for (int i = 0; i < deviceIndexes.size(); i++) {
// if (deviceIndexes.size() - i != 1) {
// stringBuilder.append(DEV_INDEX + "='").append(deviceIndexes.get(i)).append("' or ");
// } else {
// stringBuilder.append(DEV_INDEX + "='").append(deviceIndexes.get(i)).append("')");
// }
// }
// //sql语句
// String sql = "SELECT (SUM(" + ONLINE_MIN + ")/(SUM(" + OFFLINE_MIN + ")+SUM(" + ONLINE_MIN + ")))*100 AS onlineRate FROM "+PQS_ONLINERATE+" WHERE " + stringBuilder + " group by " + DEV_INDEX +" tz('Asia/Shanghai')";
// //结果集
// QueryResult result = influxDbUtils.query(sql);
// //处理结果集
// List<QueryResult.Series> list = result.getResults().get(0).getSeries();
// if (!CollectionUtils.isEmpty(list)) {
// list.forEach(po -> {
// PublicDTO publicDTO = new PublicDTO();
// List<List<Object>> valueList = po.getValues();
// String index = po.getTags().get(DEV_INDEX);
// if (!CollectionUtils.isEmpty(valueList)) {
// for (List<Object> value : valueList) {
// //终端在线率 保留两位小数
// Double onlineRate = value.get(1) == null ? null : BigDecimal.valueOf(Double.parseDouble(value.get(1).toString())).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
// publicDTO.setId(index);
// publicDTO.setData(onlineRate);
// }
// }
// publicDTOList.add(publicDTO);
// });
// }
// return publicDTOList;
}

View File

@@ -0,0 +1,20 @@
package com.njcn.harmonic.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.njcn.harmonic.mapper.RStatDataVDMapper;
import com.njcn.harmonic.pojo.po.RStatDataVD;
import com.njcn.harmonic.service.IRStatDataVDService;
import org.springframework.stereotype.Service;
/**
* <p>
* 服务实现类
* </p>
*
* @author wr
* @since 2023-03-31
*/
@Service
public class RStatDataVDServiceImpl extends ServiceImpl<RStatDataVDMapper, RStatDataVD> implements IRStatDataVDService {
}

View File

@@ -0,0 +1,20 @@
package com.njcn.harmonic.service.impl;
import com.njcn.harmonic.mapper.RStatLimitRateDMapper;
import com.njcn.harmonic.pojo.po.day.RStatLimitRateDPO;
import com.njcn.harmonic.service.IRStatLimitRateDService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
/**
* <p>
* 合格率统计日表(越限次数) 服务实现类
* </p>
*
* @author wr
* @since 2023-04-03
*/
@Service
public class RStatLimitRateDServiceImpl extends ServiceImpl<RStatLimitRateDMapper, RStatLimitRateDPO> implements IRStatLimitRateDService {
}

View File

@@ -1,6 +1,11 @@
package com.njcn.harmonic.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.njcn.device.pq.pojo.param.PulicTimeStatisParam;
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;
@@ -15,6 +20,7 @@ import org.springframework.util.CollectionUtils;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
@@ -27,6 +33,7 @@ import java.util.List;
public class SteadyDataServiceImpl implements SteadyDataService {
private final InfluxDbUtils influxDbUtils;
private final RStatLimitRateDMapper rateDMapper;
@Override
public SteadyInfoData getSteadyData(PulicTimeStatisParam pulicTimeStatisParam) {
@@ -47,36 +54,11 @@ public class SteadyDataServiceImpl implements SteadyDataService {
SteadyDataVO steadyDataVO = new SteadyDataVO();
SteadyDataVO steadyData = new SteadyDataVO();
if (!lineList.isEmpty() || StringUtils.isNotBlank(lineList)) {
//组装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 (");
//sql语句
stringBuilder.append(InfluxDBPublicParam.LINE_ID + "='").append(lineList).append("') ");
stringBuilder.append(InfluxDBPublicParam.TIME_ZONE);
String sql = "SELECT" +
" SUM( all_time ) AS alltime," +
" SUM( freq_dev_overtime ) AS frequency," +
" SUM( ubalance_overtime ) AS uBalance," +
" SUM( i_neg_overtime ) AS iNeg," +
" SUM( iharm_13_overtime) AS harmElec," +
" SUM( uharm_4_overtime) AS harmVoltage," +
" SUM( flicker_overtime ) AS flicker," +
" SUM( flicker_all_time ) AS allFlicker," +
" SUM( voltage_dev_overtime ) AS voltageDeviation," +
" SUM( inuharm_9_overtime ) AS inUharm" +
" FROM" +
" limit_rate" +
" WHERE" +
" phasic_type = 'T'" +
" AND " + stringBuilder.toString();
//结果集
QueryResult result = influxDbUtils.query(sql);
//处理结果集
List<QueryResult.Series> list = result.getResults().get(0).getSeries();
if (!CollectionUtils.isEmpty(list)) {
List<List<Object>> valueList = list.get(0).getValues();
List<Object> value = valueList.get(0);
if (new Double(String.valueOf(value.get(1))).intValue() == 0 || new Double(String.valueOf(value.get(1))).intValue() < 0) {
List<RStatLimitRateDVO> list = rateDMapper.getSumPassRate(Arrays.asList(lineList),
DateUtil.beginOfDay(DateUtil.parse(startTime)).toString(),
DateUtil.beginOfDay(DateUtil.parse(endTime)).toString());
if (CollUtil.isNotEmpty(list)) {
if (ObjectUtil.isNull(list.get(0))) {
steadyDataVO.setVoltageDeviation(3.14159f);
steadyDataVO.setUBalance(3.14159f);
steadyDataVO.setFlicker(3.14159f);
@@ -96,16 +78,16 @@ public class SteadyDataServiceImpl implements SteadyDataService {
SteadyDataVO steadyDataList = getSteadyAcc(steadyData);
return getSteadyData(steadyDataList);
} else {
steadyDataVO.setAllTime(Float.parseFloat(value.get(1).toString()));
steadyDataVO.setFrequency(Float.parseFloat(value.get(2).toString()));
steadyDataVO.setUBalance(Float.parseFloat(value.get(3).toString()));
steadyDataVO.setINeg(Float.parseFloat(value.get(4).toString()));
steadyDataVO.setHarmElec(Float.parseFloat(value.get(5).toString()));
steadyDataVO.setHarmVoltage(Float.parseFloat(value.get(6).toString()));
steadyDataVO.setFlicker(Float.parseFloat(value.get(7).toString()));
steadyDataVO.setAllFlicker(Float.parseFloat(value.get(8).toString()));
steadyDataVO.setVoltageDeviation(Float.parseFloat(value.get(9).toString()));
steadyDataVO.setInUharm(Float.parseFloat(value.get(10).toString()));
steadyDataVO.setAllTime(Float.parseFloat(list.get(0).getAlltime().toString()));
steadyDataVO.setFrequency(Float.parseFloat(list.get(0).getFrequency().toString()));
steadyDataVO.setUBalance(Float.parseFloat(list.get(0).getUBalance().toString()));
steadyDataVO.setINeg(Float.parseFloat(list.get(0).getINeg().toString()));
steadyDataVO.setHarmElec(Float.parseFloat(list.get(0).getHarmElec().toString()));
steadyDataVO.setHarmVoltage(Float.parseFloat(list.get(0).getHarmVoltage().toString()));
steadyDataVO.setFlicker(Float.parseFloat(list.get(0).getFlicker().toString()));
steadyDataVO.setAllFlicker(Float.parseFloat(list.get(0).getAllFlicker().toString()));
steadyDataVO.setVoltageDeviation(Float.parseFloat(list.get(0).getVoltageDeviation().toString()));
steadyDataVO.setInUharm(Float.parseFloat(list.get(0).getInUharm().toString()));
}
} else {
//有监测点,但是无数据的处理

View File

@@ -1,18 +1,25 @@
package com.njcn.harmonic.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.njcn.device.pq.api.GeneralDeviceInfoClient;
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.harmonic.mapper.SteadyExceedRateMapper;
import com.njcn.harmonic.pojo.dto.SteadyQualifyDTO;
import com.njcn.harmonic.pojo.po.LimitRatePO;
import com.njcn.harmonic.pojo.po.day.RStatLimitRateDPO;
import com.njcn.harmonic.pojo.vo.SteadyExceedRateCensusVO;
import com.njcn.harmonic.pojo.vo.SteadyExceedRateVO;
import com.njcn.harmonic.service.IRStatLimitRateDService;
import com.njcn.harmonic.service.SteadyExceedRateService;
import com.njcn.influxdb.param.InfluxDBPublicParam;
import com.njcn.influxdb.utils.InfluxDbUtils;
@@ -44,6 +51,8 @@ public class SteadyExceedRateServiceImpl implements SteadyExceedRateService {
private final InfluxDbUtils influxDbUtils;
private final IRStatLimitRateDService rateDService;
@Override
public List<SteadyExceedRateVO> getSteadyExceedRateData(DeviceInfoParam.BusinessParam steadyExceedParam) {
List<SteadyExceedRateVO> steadyExceedRateVOS = new ArrayList<>();
@@ -410,44 +419,136 @@ public class SteadyExceedRateServiceImpl implements SteadyExceedRateService {
* @param endTime
*/
private List<LimitRatePO> getQualifiesRate(List<String> lineIndexes, String startTime, String endTime) {
List<LimitRatePO> limitRatePOS;
List<LimitRatePO> limitRatePOS = new ArrayList<>();
List<RStatLimitRateDPO> limitRates = rateDService.list(new LambdaQueryWrapper<RStatLimitRateDPO>()
.in(RStatLimitRateDPO::getLineId, lineIndexes)
.eq(RStatLimitRateDPO::getPhasicType,InfluxDBPublicParam.PHASIC_TYPET)
.ge(StrUtil.isNotBlank(startTime), RStatLimitRateDPO::getTime, DateUtil.beginOfDay(DateUtil.parse(startTime)))
.le(StrUtil.isNotBlank(endTime), RStatLimitRateDPO::getTime, DateUtil.endOfDay(DateUtil.parse(endTime)))
);
if(CollUtil.isNotEmpty(limitRates)){
limitRates.forEach(list ->{
LimitRatePO limitRatePO = new LimitRatePO();
limitRatePO.setDayStr(DateUtil.format(list.getTime(),"yyyy-MM-dd"));
limitRatePO.setMouthStr(DateUtil.format(list.getTime(),"yyyy-MM"));
limitRatePO.setTime(list.getTime().toInstant());
limitRatePO.setLineId(list.getLineId());
limitRatePO.setPhasicType(list.getPhasicType());
limitRatePO.setAllTime(list.getAllTime());
limitRatePO.setFlickerAllTime(list.getFlickerAllTime());
limitRatePO.setFlickerOverTime(list.getFlickerOvertime());
limitRatePO.setFreqDevOverTime(list.getFreqDevOvertime());
limitRatePO.setIHarm2OverTime(list.getIharm2Overtime());
limitRatePO.setIHarm3OverTime(list.getIharm3Overtime());
limitRatePO.setIHarm4OverTime(list.getIharm4Overtime());
limitRatePO.setIHarm5OverTime(list.getIharm5Overtime());
limitRatePO.setIHarm6OverTime(list.getIharm6Overtime());
limitRatePO.setIHarm7OverTime(list.getIharm7Overtime());
limitRatePO.setIHarm8OverTime(list.getIharm8Overtime());
limitRatePO.setIHarm9OverTime(list.getIharm9Overtime());
limitRatePO.setIHarm10OverTime(list.getIharm10Overtime());
limitRatePO.setIHarm11OverTime(list.getIharm11Overtime());
limitRatePO.setIHarm12OverTime(list.getIharm12Overtime());
limitRatePO.setIHarm13OverTime(list.getIharm13Overtime());
limitRatePO.setIHarm14OverTime(list.getIharm14Overtime());
limitRatePO.setIHarm15OverTime(list.getIharm15Overtime());
limitRatePO.setIHarm16OverTime(list.getIharm16Overtime());
limitRatePO.setIHarm17OverTime(list.getIharm17Overtime());
limitRatePO.setIHarm18OverTime(list.getIharm18Overtime());
limitRatePO.setIHarm19OverTime(list.getIharm19Overtime());
limitRatePO.setIHarm20OverTime(list.getIharm20Overtime());
limitRatePO.setIHarm21OverTime(list.getIharm21Overtime());
limitRatePO.setIHarm22OverTime(list.getIharm22Overtime());
limitRatePO.setIHarm23OverTime(list.getIharm23Overtime());
limitRatePO.setIHarm24OverTime(list.getIharm24Overtime());
limitRatePO.setIHarm25OverTime(list.getIharm25Overtime());
limitRatePO.setINegOverTime(list.getINegOvertime());
limitRatePO.setInUHARM1OverTime(list.getInuharm1Overtime());
limitRatePO.setInUHARM2OverTime(list.getInuharm2Overtime());
limitRatePO.setInUHARM3OverTime(list.getInuharm3Overtime());
limitRatePO.setInUHARM4OverTime(list.getInuharm4Overtime());
limitRatePO.setInUHARM5OverTime(list.getInuharm5Overtime());
limitRatePO.setInUHARM6OverTime(list.getInuharm6Overtime());
limitRatePO.setInUHARM7OverTime(list.getInuharm7Overtime());
limitRatePO.setInUHARM8OverTime(list.getInuharm8Overtime());
limitRatePO.setInUHARM9OverTime(list.getInuharm9Overtime());
limitRatePO.setInUHARM10OverTime(list.getInuharm10Overtime());
limitRatePO.setInUHARM11OverTime(list.getInuharm11Overtime());
limitRatePO.setInUHARM12OverTime(list.getInuharm12Overtime());
limitRatePO.setInUHARM13OverTime(list.getInuharm13Overtime());
limitRatePO.setInUHARM14OverTime(list.getInuharm14Overtime());
limitRatePO.setInUHARM15OverTime(list.getInuharm15Overtime());
limitRatePO.setInUHARM16OverTime(list.getInuharm16Overtime());
limitRatePO.setUAberranceOverTime(list.getUaberranceOvertime());
limitRatePO.setUBalanceOverTime(list.getUbalanceOvertime());
limitRatePO.setUHarm2OverTime(list.getUharm2Overtime());
limitRatePO.setUHarm3OverTime(list.getUharm3Overtime());
limitRatePO.setUHarm4OverTime(list.getUharm4Overtime());
limitRatePO.setUHarm5OverTime(list.getUharm5Overtime());
limitRatePO.setUHarm6OverTime(list.getUharm6Overtime());
limitRatePO.setUHarm7OverTime(list.getUharm7Overtime());
limitRatePO.setUHarm8OverTime(list.getUharm8Overtime());
limitRatePO.setUHarm9OverTime(list.getUharm9Overtime());
limitRatePO.setUHarm10OverTime(list.getUharm10Overtime());
limitRatePO.setUHarm11OverTime(list.getUharm11Overtime());
limitRatePO.setUHarm12OverTime(list.getUharm12Overtime());
limitRatePO.setUHarm13OverTime(list.getUharm13Overtime());
limitRatePO.setUHarm14OverTime(list.getUharm14Overtime());
limitRatePO.setUHarm15OverTime(list.getUharm15Overtime());
limitRatePO.setUHarm16OverTime(list.getUharm16Overtime());
limitRatePO.setUHarm17OverTime(list.getUharm17Overtime());
limitRatePO.setUHarm18OverTime(list.getUharm18Overtime());
limitRatePO.setUHarm19OverTime(list.getUharm19Overtime());
limitRatePO.setUHarm20OverTime(list.getUharm20Overtime());
limitRatePO.setUHarm21OverTime(list.getUharm21Overtime());
limitRatePO.setUHarm22OverTime(list.getUharm22Overtime());
limitRatePO.setUHarm23OverTime(list.getUharm23Overtime());
limitRatePO.setUHarm24OverTime(list.getUharm24Overtime());
limitRatePO.setUHarm25OverTime(list.getUharm25Overtime());
limitRatePO.setVoltageDevOverTime(list.getVoltageDevOvertime());
limitRatePOS.add(limitRatePO);
});
}
return limitRatePOS;
//组装sql语句
// StringBuilder string = new StringBuilder();
// string.append(Param.QualityFlag + "='1' and (" + Param.PHASIC_TYPE + "='" + Param.PHASIC_TYPEA + "' or " + Param.PHASIC_TYPE + "='" + Param.PHASIC_TYPEB + "' or " + Param.PHASIC_TYPE + "='" + Param.PHASIC_TYPEC + "') and "+ Param.VALUETYPE + "='AVG' and ");
StringBuilder timeId = new StringBuilder();
timeId.append(InfluxDBPublicParam.PHASIC_TYPE + "='" + InfluxDBPublicParam.PHASIC_TYPET + "' and " + InfluxDBPublicParam.TIME + " >= '" + startTime + InfluxDBPublicParam.START_TIME + "' and " + InfluxDBPublicParam.TIME + " <= '" + endTime + InfluxDBPublicParam.END_TIME + "' and ");
for (int i = 0; i < lineIndexes.size(); i++) {
if (lineIndexes.size() - i != 1) {
timeId.append(InfluxDBPublicParam.LINE_ID + "='").append(lineIndexes.get(i)).append("' or ");
} else {
timeId.append(InfluxDBPublicParam.LINE_ID + "='").append(lineIndexes.get(i)).append("' tz('Asia/Shanghai')");
}
}
//sql语句
String sql = "SELECT * FROM "+ InfluxDBPublicParam.LIMIT_RATE +" WHERE " + timeId;
//结果集
QueryResult result = influxDbUtils.query(sql);
// if (Objects.isNull(result.getResults().get(0).getSeries())) {
// throw new BusinessException(HarmonicResponseEnum.LIMIT_RATE_ERROR);
// }
//结果集映射到对象中
InfluxDBResultMapper resultMapper = new InfluxDBResultMapper();
limitRatePOS = resultMapper.toPOJO(result, LimitRatePO.class);
//将时间处理为年月日的字符串
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
DateTimeFormatter monthFormatter = DateTimeFormatter.ofPattern("yyyy-MM");
limitRatePOS.forEach(item->{
Instant instant = item.getTime();
ZoneId zoneId = ZoneId.systemDefault();
LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, zoneId);
String dateStr = dateTimeFormatter.format(localDateTime);
String monthStr = monthFormatter.format(localDateTime);
item.setDayStr(dateStr);
item.setMouthStr(monthStr);
});
return limitRatePOS;
// StringBuilder timeId = new StringBuilder();
// timeId.append(InfluxDBPublicParam.PHASIC_TYPE + "='" + InfluxDBPublicParam.PHASIC_TYPET + "' and " + InfluxDBPublicParam.TIME + " >= '" + startTime + InfluxDBPublicParam.START_TIME + "' and " + InfluxDBPublicParam.TIME + " <= '" + endTime + InfluxDBPublicParam.END_TIME + "' and ");
// for (int i = 0; i < lineIndexes.size(); i++) {
// if (lineIndexes.size() - i != 1) {
// timeId.append(InfluxDBPublicParam.LINE_ID + "='").append(lineIndexes.get(i)).append("' or ");
// } else {
// timeId.append(InfluxDBPublicParam.LINE_ID + "='").append(lineIndexes.get(i)).append("' tz('Asia/Shanghai')");
// }
// }
// //sql语句
// String sql = "SELECT * FROM "+ InfluxDBPublicParam.LIMIT_RATE +" WHERE " + timeId;
// //结果集
// QueryResult result = influxDbUtils.query(sql);
// // if (Objects.isNull(result.getResults().get(0).getSeries())) {
// // throw new BusinessException(HarmonicResponseEnum.LIMIT_RATE_ERROR);
// // }
// //结果集映射到对象中
// InfluxDBResultMapper resultMapper = new InfluxDBResultMapper();
// limitRatePOS = resultMapper.toPOJO(result, LimitRatePO.class);
// //将时间处理为年月日的字符串
// DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
// DateTimeFormatter monthFormatter = DateTimeFormatter.ofPattern("yyyy-MM");
// limitRatePOS.forEach(item->{
// Instant instant = item.getTime();
// ZoneId zoneId = ZoneId.systemDefault();
// LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, zoneId);
// String dateStr = dateTimeFormatter.format(localDateTime);
// String monthStr = monthFormatter.format(localDateTime);
// item.setDayStr(dateStr);
// item.setMouthStr(monthStr);
// });
//
//
// return limitRatePOS;
}
}

View File

@@ -1,7 +1,12 @@
package com.njcn.harmonic.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.njcn.device.pq.api.GeneralDeviceInfoClient;
import com.njcn.device.pq.enums.LineBaseEnum;
import com.njcn.device.pq.pojo.dto.GeneralDeviceDTO;
@@ -9,8 +14,10 @@ import com.njcn.device.pq.pojo.param.DeviceInfoParam;
import com.njcn.harmonic.mapper.SteadyQualifyMapper;
import com.njcn.harmonic.pojo.dto.SteadyQualifyDTO;
import com.njcn.harmonic.pojo.po.LimitRate;
import com.njcn.harmonic.pojo.po.day.RStatLimitRateDPO;
import com.njcn.harmonic.pojo.vo.SteadyQualifyCensusVO;
import com.njcn.harmonic.pojo.vo.SteadyQualifyVO;
import com.njcn.harmonic.service.IRStatLimitRateDService;
import com.njcn.harmonic.service.SteadyQualifyService;
import com.njcn.influxdb.param.InfluxDBPublicParam;
import com.njcn.influxdb.utils.InfluxDbUtils;
@@ -41,6 +48,8 @@ public class SteadyQualifyServiceImpl implements SteadyQualifyService {
private final InfluxDbUtils influxDbUtils;
private final IRStatLimitRateDService rateDService;
@Override
public List<SteadyQualifyVO> getSteadyQualifyData(DeviceInfoParam.BusinessParam steadyParam) {
List<SteadyQualifyVO> steadyQualifyList = new ArrayList<>();
@@ -407,107 +416,195 @@ public class SteadyQualifyServiceImpl implements SteadyQualifyService {
*/
private List<SteadyQualifyDTO> getQualifiesRate(List<String> lineIndexes, String startTime, String endTime) {
List<SteadyQualifyDTO> qualifyDTOList = new ArrayList<>();
//组装sql语句
StringBuilder timeId = new StringBuilder();
timeId.append(InfluxDBPublicParam.TIME + " >= '" + startTime + InfluxDBPublicParam.START_TIME + "' and " + InfluxDBPublicParam.TIME + " <= '" + endTime + InfluxDBPublicParam.END_TIME + "' and ");
for (int i = 0; i < lineIndexes.size(); i++) {
if (lineIndexes.size() - i != 1) {
timeId.append(InfluxDBPublicParam.LINE_ID + "='").append(lineIndexes.get(i)).append("' or ");
} else {
timeId.append(InfluxDBPublicParam.LINE_ID + "='").append(lineIndexes.get(i)).append("' tz('Asia/Shanghai')");
}
List<RStatLimitRateDPO> limitRates = rateDService.list(new LambdaQueryWrapper<RStatLimitRateDPO>()
.in(RStatLimitRateDPO::getLineId, lineIndexes)
.ge(StrUtil.isNotBlank(startTime), RStatLimitRateDPO::getTime, DateUtil.beginOfDay(DateUtil.parse(startTime)))
.le(StrUtil.isNotBlank(endTime), RStatLimitRateDPO::getTime, DateUtil.endOfDay(DateUtil.parse(endTime)))
);
if(CollUtil.isNotEmpty(limitRates)){
limitRates.forEach(list ->{
SteadyQualifyDTO steadyQualifyDTO = new SteadyQualifyDTO();
steadyQualifyDTO.setTime(DateUtil.format(list.getTime(),"yyyy-MM-dd HH:mm:ss.SSS"));
steadyQualifyDTO.setMYINDEX(list.getLineId());
steadyQualifyDTO.setPhasic_Type(list.getPhasicType());
steadyQualifyDTO.setAllTime(Double.parseDouble(list.getAllTime().toString()));
steadyQualifyDTO.setFlicker_AllTime(Double.parseDouble(list.getFlickerAllTime().toString()));
steadyQualifyDTO.setFlicker_OverTime(Double.parseDouble(list.getFlickerOvertime().toString()));
steadyQualifyDTO.setFreq_Dev_OverTime(Double.parseDouble(list.getFreqDevOvertime().toString()));
steadyQualifyDTO.setIHarm_2_OverTime(Double.parseDouble(list.getIharm2Overtime().toString()));
steadyQualifyDTO.setIHarm_3_OverTime(Double.parseDouble(list.getIharm3Overtime().toString()));
steadyQualifyDTO.setIHarm_4_OverTime(Double.parseDouble(list.getIharm4Overtime().toString()));
steadyQualifyDTO.setIHarm_5_OverTime(Double.parseDouble(list.getIharm5Overtime().toString()));
steadyQualifyDTO.setIHarm_6_OverTime(Double.parseDouble(list.getIharm6Overtime().toString()));
steadyQualifyDTO.setIHarm_7_OverTime(Double.parseDouble(list.getIharm7Overtime().toString()));
steadyQualifyDTO.setIHarm_8_OverTime(Double.parseDouble(list.getIharm8Overtime().toString()));
steadyQualifyDTO.setIHarm_9_OverTime(Double.parseDouble(list.getIharm9Overtime().toString()));
steadyQualifyDTO.setIHarm_10_OverTime(Double.parseDouble(list.getIharm10Overtime().toString()));
steadyQualifyDTO.setIHarm_11_OverTime(Double.parseDouble(list.getIharm11Overtime().toString()));
steadyQualifyDTO.setIHarm_12_OverTime(Double.parseDouble(list.getIharm12Overtime().toString()));
steadyQualifyDTO.setIHarm_13_OverTime(Double.parseDouble(list.getIharm13Overtime().toString()));
steadyQualifyDTO.setIHarm_14_OverTime(Double.parseDouble(list.getIharm14Overtime().toString()));
steadyQualifyDTO.setIHarm_15_OverTime(Double.parseDouble(list.getIharm15Overtime().toString()));
steadyQualifyDTO.setIHarm_16_OverTime(Double.parseDouble(list.getIharm16Overtime().toString()));
steadyQualifyDTO.setIHarm_17_OverTime(Double.parseDouble(list.getIharm17Overtime().toString()));
steadyQualifyDTO.setIHarm_18_OverTime(Double.parseDouble(list.getIharm18Overtime().toString()));
steadyQualifyDTO.setIHarm_19_OverTime(Double.parseDouble(list.getIharm19Overtime().toString()));
steadyQualifyDTO.setIHarm_20_OverTime(Double.parseDouble(list.getIharm20Overtime().toString()));
steadyQualifyDTO.setIHarm_21_OverTime(Double.parseDouble(list.getIharm21Overtime().toString()));
steadyQualifyDTO.setIHarm_22_OverTime(Double.parseDouble(list.getIharm22Overtime().toString()));
steadyQualifyDTO.setIHarm_23_OverTime(Double.parseDouble(list.getIharm23Overtime().toString()));
steadyQualifyDTO.setIHarm_24_OverTime(Double.parseDouble(list.getIharm24Overtime().toString()));
steadyQualifyDTO.setIHarm_25_OverTime(Double.parseDouble(list.getIharm25Overtime().toString()));
steadyQualifyDTO.setI_Neg_OverTime(Double.parseDouble(list.getINegOvertime().toString()));
steadyQualifyDTO.setInUHARM_1_OverTime(Double.parseDouble(list.getInuharm1Overtime().toString()));
steadyQualifyDTO.setInUHARM_2_OverTime(Double.parseDouble(list.getInuharm2Overtime().toString()));
steadyQualifyDTO.setInUHARM_3_OverTime(Double.parseDouble(list.getInuharm3Overtime().toString()));
steadyQualifyDTO.setInUHARM_4_OverTime(Double.parseDouble(list.getInuharm4Overtime().toString()));
steadyQualifyDTO.setInUHARM_5_OverTime(Double.parseDouble(list.getInuharm5Overtime().toString()));
steadyQualifyDTO.setInUHARM_6_OverTime(Double.parseDouble(list.getInuharm6Overtime().toString()));
steadyQualifyDTO.setInUHARM_7_OverTime(Double.parseDouble(list.getInuharm7Overtime().toString()));
steadyQualifyDTO.setInUHARM_8_OverTime(Double.parseDouble(list.getInuharm8Overtime().toString()));
steadyQualifyDTO.setInUHARM_9_OverTime(Double.parseDouble(list.getInuharm9Overtime().toString()));
steadyQualifyDTO.setInUHARM_10_OverTime(Double.parseDouble(list.getInuharm10Overtime().toString()));
steadyQualifyDTO.setInUHARM_11_OverTime(Double.parseDouble(list.getInuharm11Overtime().toString()));
steadyQualifyDTO.setInUHARM_12_OverTime(Double.parseDouble(list.getInuharm12Overtime().toString()));
steadyQualifyDTO.setInUHARM_13_OverTime(Double.parseDouble(list.getInuharm13Overtime().toString()));
steadyQualifyDTO.setInUHARM_14_OverTime(Double.parseDouble(list.getInuharm14Overtime().toString()));
steadyQualifyDTO.setInUHARM_15_OverTime(Double.parseDouble(list.getInuharm15Overtime().toString()));
steadyQualifyDTO.setInUHARM_16_OverTime(Double.parseDouble(list.getInuharm16Overtime().toString()));
steadyQualifyDTO.setUAberrance_OverTime(Double.parseDouble(list.getUaberranceOvertime().toString()));
steadyQualifyDTO.setUBalance_OverTime(Double.parseDouble(list.getUbalanceOvertime().toString()));
steadyQualifyDTO.setUHarm_2_OverTime(Double.parseDouble(list.getUharm2Overtime().toString()));
steadyQualifyDTO.setUHarm_3_OverTime(Double.parseDouble(list.getUharm3Overtime().toString()));
steadyQualifyDTO.setUHarm_4_OverTime(Double.parseDouble(list.getUharm4Overtime().toString()));
steadyQualifyDTO.setUHarm_5_OverTime(Double.parseDouble(list.getUharm5Overtime().toString()));
steadyQualifyDTO.setUHarm_6_OverTime(Double.parseDouble(list.getUharm6Overtime().toString()));
steadyQualifyDTO.setUHarm_7_OverTime(Double.parseDouble(list.getUharm7Overtime().toString()));
steadyQualifyDTO.setUHarm_8_OverTime(Double.parseDouble(list.getUharm8Overtime().toString()));
steadyQualifyDTO.setUHarm_9_OverTime(Double.parseDouble(list.getUharm9Overtime().toString()));
steadyQualifyDTO.setUHarm_10_OverTime(Double.parseDouble(list.getUharm10Overtime().toString()));
steadyQualifyDTO.setUHarm_11_OverTime(Double.parseDouble(list.getUharm11Overtime().toString()));
steadyQualifyDTO.setUHarm_12_OverTime(Double.parseDouble(list.getUharm12Overtime().toString()));
steadyQualifyDTO.setUHarm_13_OverTime(Double.parseDouble(list.getUharm13Overtime().toString()));
steadyQualifyDTO.setUHarm_14_OverTime(Double.parseDouble(list.getUharm14Overtime().toString()));
steadyQualifyDTO.setUHarm_15_OverTime(Double.parseDouble(list.getUharm15Overtime().toString()));
steadyQualifyDTO.setUHarm_16_OverTime(Double.parseDouble(list.getUharm16Overtime().toString()));
steadyQualifyDTO.setUHarm_17_OverTime(Double.parseDouble(list.getUharm17Overtime().toString()));
steadyQualifyDTO.setUHarm_18_OverTime(Double.parseDouble(list.getUharm18Overtime().toString()));
steadyQualifyDTO.setUHarm_19_OverTime(Double.parseDouble(list.getUharm19Overtime().toString()));
steadyQualifyDTO.setUHarm_20_OverTime(Double.parseDouble(list.getUharm20Overtime().toString()));
steadyQualifyDTO.setUHarm_21_OverTime(Double.parseDouble(list.getUharm21Overtime().toString()));
steadyQualifyDTO.setUHarm_22_OverTime(Double.parseDouble(list.getUharm22Overtime().toString()));
steadyQualifyDTO.setUHarm_23_OverTime(Double.parseDouble(list.getUharm23Overtime().toString()));
steadyQualifyDTO.setUHarm_24_OverTime(Double.parseDouble(list.getUharm24Overtime().toString()));
steadyQualifyDTO.setUHarm_25_OverTime(Double.parseDouble(list.getUharm25Overtime().toString()));
steadyQualifyDTO.setVoltage_Dev_OverTime(Double.parseDouble(list.getVoltageDevOvertime().toString()));
qualifyDTOList.add(steadyQualifyDTO);
});
}
//sql语句
String sql = "SELECT * FROM "+ InfluxDBPublicParam.LIMIT_RATE +" WHERE " + timeId;
//结果集
QueryResult result = influxDbUtils.query(sql);
//结果集映射到对象中
InfluxDBResultMapper influxDBResultMapper = new InfluxDBResultMapper();
List<LimitRate> limitRates = influxDBResultMapper.toPOJO(result, LimitRate.class);
limitRates.forEach(list ->{
SteadyQualifyDTO steadyQualifyDTO = new SteadyQualifyDTO();
LocalDateTime localDateTime = LocalDateTime.ofInstant(list.getTime(), ZoneId.systemDefault());
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS");
steadyQualifyDTO.setTime(dateTimeFormatter.format(localDateTime));
steadyQualifyDTO.setMYINDEX(list.getLineId());
steadyQualifyDTO.setPhasic_Type(list.getPhasicType());
steadyQualifyDTO.setAllTime(Double.parseDouble(list.getAllTime().toString()));
steadyQualifyDTO.setFlicker_AllTime(Double.parseDouble(list.getFlickerAllTime().toString()));
steadyQualifyDTO.setFlicker_OverTime(Double.parseDouble(list.getFlickerOverTime().toString()));
steadyQualifyDTO.setFreq_Dev_OverTime(Double.parseDouble(list.getFreqDevOverTime().toString()));
steadyQualifyDTO.setIHarm_2_OverTime(Double.parseDouble(list.getIHarm2OverTime().toString()));
steadyQualifyDTO.setIHarm_3_OverTime(Double.parseDouble(list.getIHarm3OverTime().toString()));
steadyQualifyDTO.setIHarm_4_OverTime(Double.parseDouble(list.getIHarm4OverTime().toString()));
steadyQualifyDTO.setIHarm_5_OverTime(Double.parseDouble(list.getIHarm5OverTime().toString()));
steadyQualifyDTO.setIHarm_6_OverTime(Double.parseDouble(list.getIHarm6OverTime().toString()));
steadyQualifyDTO.setIHarm_7_OverTime(Double.parseDouble(list.getIHarm7OverTime().toString()));
steadyQualifyDTO.setIHarm_8_OverTime(Double.parseDouble(list.getIHarm8OverTime().toString()));
steadyQualifyDTO.setIHarm_9_OverTime(Double.parseDouble(list.getIHarm9OverTime().toString()));
steadyQualifyDTO.setIHarm_10_OverTime(Double.parseDouble(list.getIHarm10OverTime().toString()));
steadyQualifyDTO.setIHarm_11_OverTime(Double.parseDouble(list.getIHarm11OverTime().toString()));
steadyQualifyDTO.setIHarm_12_OverTime(Double.parseDouble(list.getIHarm12OverTime().toString()));
steadyQualifyDTO.setIHarm_13_OverTime(Double.parseDouble(list.getIHarm13OverTime().toString()));
steadyQualifyDTO.setIHarm_14_OverTime(Double.parseDouble(list.getIHarm14OverTime().toString()));
steadyQualifyDTO.setIHarm_15_OverTime(Double.parseDouble(list.getIHarm15OverTime().toString()));
steadyQualifyDTO.setIHarm_16_OverTime(Double.parseDouble(list.getIHarm16OverTime().toString()));
steadyQualifyDTO.setIHarm_17_OverTime(Double.parseDouble(list.getIHarm17OverTime().toString()));
steadyQualifyDTO.setIHarm_18_OverTime(Double.parseDouble(list.getIHarm18OverTime().toString()));
steadyQualifyDTO.setIHarm_19_OverTime(Double.parseDouble(list.getIHarm19OverTime().toString()));
steadyQualifyDTO.setIHarm_20_OverTime(Double.parseDouble(list.getIHarm20OverTime().toString()));
steadyQualifyDTO.setIHarm_21_OverTime(Double.parseDouble(list.getIHarm21OverTime().toString()));
steadyQualifyDTO.setIHarm_22_OverTime(Double.parseDouble(list.getIHarm22OverTime().toString()));
steadyQualifyDTO.setIHarm_23_OverTime(Double.parseDouble(list.getIHarm23OverTime().toString()));
steadyQualifyDTO.setIHarm_24_OverTime(Double.parseDouble(list.getIHarm24OverTime().toString()));
steadyQualifyDTO.setIHarm_25_OverTime(Double.parseDouble(list.getIHarm25OverTime().toString()));
steadyQualifyDTO.setI_Neg_OverTime(Double.parseDouble(list.getINegOverTime().toString()));
steadyQualifyDTO.setInUHARM_1_OverTime(Double.parseDouble(list.getInuHarm1OverTime().toString()));
steadyQualifyDTO.setInUHARM_2_OverTime(Double.parseDouble(list.getInuHarm2OverTime().toString()));
steadyQualifyDTO.setInUHARM_3_OverTime(Double.parseDouble(list.getInuHarm3OverTime().toString()));
steadyQualifyDTO.setInUHARM_4_OverTime(Double.parseDouble(list.getInuHarm4OverTime().toString()));
steadyQualifyDTO.setInUHARM_5_OverTime(Double.parseDouble(list.getInuHarm5OverTime().toString()));
steadyQualifyDTO.setInUHARM_6_OverTime(Double.parseDouble(list.getInuHarm6OverTime().toString()));
steadyQualifyDTO.setInUHARM_7_OverTime(Double.parseDouble(list.getInuHarm7OverTime().toString()));
steadyQualifyDTO.setInUHARM_8_OverTime(Double.parseDouble(list.getInuHarm8OverTime().toString()));
steadyQualifyDTO.setInUHARM_9_OverTime(Double.parseDouble(list.getInuHarm9OverTime().toString()));
steadyQualifyDTO.setInUHARM_10_OverTime(Double.parseDouble(list.getInuHarm10OverTime().toString()));
steadyQualifyDTO.setInUHARM_11_OverTime(Double.parseDouble(list.getInuHarm11OverTime().toString()));
steadyQualifyDTO.setInUHARM_12_OverTime(Double.parseDouble(list.getInuHarm12OverTime().toString()));
steadyQualifyDTO.setInUHARM_13_OverTime(Double.parseDouble(list.getInuHarm13OverTime().toString()));
steadyQualifyDTO.setInUHARM_14_OverTime(Double.parseDouble(list.getInuHarm14OverTime().toString()));
steadyQualifyDTO.setInUHARM_15_OverTime(Double.parseDouble(list.getInuHarm15OverTime().toString()));
steadyQualifyDTO.setInUHARM_16_OverTime(Double.parseDouble(list.getInuHarm16OverTime().toString()));
steadyQualifyDTO.setUAberrance_OverTime(Double.parseDouble(list.getUAberranceOverTime().toString()));
steadyQualifyDTO.setUBalance_OverTime(Double.parseDouble(list.getUBalanceOverTime().toString()));
steadyQualifyDTO.setUHarm_2_OverTime(Double.parseDouble(list.getUHarm2OverTime().toString()));
steadyQualifyDTO.setUHarm_3_OverTime(Double.parseDouble(list.getUHarm3OverTime().toString()));
steadyQualifyDTO.setUHarm_4_OverTime(Double.parseDouble(list.getUHarm4OverTime().toString()));
steadyQualifyDTO.setUHarm_5_OverTime(Double.parseDouble(list.getUHarm5OverTime().toString()));
steadyQualifyDTO.setUHarm_6_OverTime(Double.parseDouble(list.getUHarm6OverTime().toString()));
steadyQualifyDTO.setUHarm_7_OverTime(Double.parseDouble(list.getUHarm7OverTime().toString()));
steadyQualifyDTO.setUHarm_8_OverTime(Double.parseDouble(list.getUHarm8OverTime().toString()));
steadyQualifyDTO.setUHarm_9_OverTime(Double.parseDouble(list.getUHarm9OverTime().toString()));
steadyQualifyDTO.setUHarm_10_OverTime(Double.parseDouble(list.getUHarm10OverTime().toString()));
steadyQualifyDTO.setUHarm_11_OverTime(Double.parseDouble(list.getUHarm11OverTime().toString()));
steadyQualifyDTO.setUHarm_12_OverTime(Double.parseDouble(list.getUHarm12OverTime().toString()));
steadyQualifyDTO.setUHarm_13_OverTime(Double.parseDouble(list.getUHarm13OverTime().toString()));
steadyQualifyDTO.setUHarm_14_OverTime(Double.parseDouble(list.getUHarm14OverTime().toString()));
steadyQualifyDTO.setUHarm_15_OverTime(Double.parseDouble(list.getUHarm15OverTime().toString()));
steadyQualifyDTO.setUHarm_16_OverTime(Double.parseDouble(list.getUHarm16OverTime().toString()));
steadyQualifyDTO.setUHarm_17_OverTime(Double.parseDouble(list.getUHarm17OverTime().toString()));
steadyQualifyDTO.setUHarm_18_OverTime(Double.parseDouble(list.getUHarm18OverTime().toString()));
steadyQualifyDTO.setUHarm_19_OverTime(Double.parseDouble(list.getUHarm19OverTime().toString()));
steadyQualifyDTO.setUHarm_20_OverTime(Double.parseDouble(list.getUHarm20OverTime().toString()));
steadyQualifyDTO.setUHarm_21_OverTime(Double.parseDouble(list.getUHarm21OverTime().toString()));
steadyQualifyDTO.setUHarm_22_OverTime(Double.parseDouble(list.getUHarm22OverTime().toString()));
steadyQualifyDTO.setUHarm_23_OverTime(Double.parseDouble(list.getUHarm23OverTime().toString()));
steadyQualifyDTO.setUHarm_24_OverTime(Double.parseDouble(list.getUHarm24OverTime().toString()));
steadyQualifyDTO.setUHarm_25_OverTime(Double.parseDouble(list.getUHarm25OverTime().toString()));
steadyQualifyDTO.setVoltage_Dev_OverTime(Double.parseDouble(list.getVoltageDevOverTime().toString()));
qualifyDTOList.add(steadyQualifyDTO);
});
return qualifyDTOList;
// //组装sql语句
// StringBuilder timeId = new StringBuilder();
// timeId.append(InfluxDBPublicParam.TIME + " >= '" + startTime + InfluxDBPublicParam.START_TIME + "' and " + InfluxDBPublicParam.TIME + " <= '" + endTime + InfluxDBPublicParam.END_TIME + "' and ");
// for (int i = 0; i < lineIndexes.size(); i++) {
// if (lineIndexes.size() - i != 1) {
// timeId.append(InfluxDBPublicParam.LINE_ID + "='").append(lineIndexes.get(i)).append("' or ");
// } else {
// timeId.append(InfluxDBPublicParam.LINE_ID + "='").append(lineIndexes.get(i)).append("' tz('Asia/Shanghai')");
// }
// }
// //sql语句
// String sql = "SELECT * FROM "+ InfluxDBPublicParam.LIMIT_RATE +" WHERE " + timeId;
// //结果集
// QueryResult result = influxDbUtils.query(sql);
// //结果集映射到对象中
// InfluxDBResultMapper influxDBResultMapper = new InfluxDBResultMapper();
// List<LimitRate> limitRates = influxDBResultMapper.toPOJO(result, LimitRate.class);
// limitRates.forEach(list ->{
// SteadyQualifyDTO steadyQualifyDTO = new SteadyQualifyDTO();
// LocalDateTime localDateTime = LocalDateTime.ofInstant(list.getTime(), ZoneId.systemDefault());
// DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS");
// steadyQualifyDTO.setTime(dateTimeFormatter.format(localDateTime));
// steadyQualifyDTO.setMYINDEX(list.getLineId());
// steadyQualifyDTO.setPhasic_Type(list.getPhasicType());
// steadyQualifyDTO.setAllTime(Double.parseDouble(list.getAllTime().toString()));
// steadyQualifyDTO.setFlicker_AllTime(Double.parseDouble(list.getFlickerAllTime().toString()));
// steadyQualifyDTO.setFlicker_OverTime(Double.parseDouble(list.getFlickerOverTime().toString()));
// steadyQualifyDTO.setFreq_Dev_OverTime(Double.parseDouble(list.getFreqDevOverTime().toString()));
// steadyQualifyDTO.setIHarm_2_OverTime(Double.parseDouble(list.getIHarm2OverTime().toString()));
// steadyQualifyDTO.setIHarm_3_OverTime(Double.parseDouble(list.getIHarm3OverTime().toString()));
// steadyQualifyDTO.setIHarm_4_OverTime(Double.parseDouble(list.getIHarm4OverTime().toString()));
// steadyQualifyDTO.setIHarm_5_OverTime(Double.parseDouble(list.getIHarm5OverTime().toString()));
// steadyQualifyDTO.setIHarm_6_OverTime(Double.parseDouble(list.getIHarm6OverTime().toString()));
// steadyQualifyDTO.setIHarm_7_OverTime(Double.parseDouble(list.getIHarm7OverTime().toString()));
// steadyQualifyDTO.setIHarm_8_OverTime(Double.parseDouble(list.getIHarm8OverTime().toString()));
// steadyQualifyDTO.setIHarm_9_OverTime(Double.parseDouble(list.getIHarm9OverTime().toString()));
// steadyQualifyDTO.setIHarm_10_OverTime(Double.parseDouble(list.getIHarm10OverTime().toString()));
// steadyQualifyDTO.setIHarm_11_OverTime(Double.parseDouble(list.getIHarm11OverTime().toString()));
// steadyQualifyDTO.setIHarm_12_OverTime(Double.parseDouble(list.getIHarm12OverTime().toString()));
// steadyQualifyDTO.setIHarm_13_OverTime(Double.parseDouble(list.getIHarm13OverTime().toString()));
// steadyQualifyDTO.setIHarm_14_OverTime(Double.parseDouble(list.getIHarm14OverTime().toString()));
// steadyQualifyDTO.setIHarm_15_OverTime(Double.parseDouble(list.getIHarm15OverTime().toString()));
// steadyQualifyDTO.setIHarm_16_OverTime(Double.parseDouble(list.getIHarm16OverTime().toString()));
// steadyQualifyDTO.setIHarm_17_OverTime(Double.parseDouble(list.getIHarm17OverTime().toString()));
// steadyQualifyDTO.setIHarm_18_OverTime(Double.parseDouble(list.getIHarm18OverTime().toString()));
// steadyQualifyDTO.setIHarm_19_OverTime(Double.parseDouble(list.getIHarm19OverTime().toString()));
// steadyQualifyDTO.setIHarm_20_OverTime(Double.parseDouble(list.getIHarm20OverTime().toString()));
// steadyQualifyDTO.setIHarm_21_OverTime(Double.parseDouble(list.getIHarm21OverTime().toString()));
// steadyQualifyDTO.setIHarm_22_OverTime(Double.parseDouble(list.getIHarm22OverTime().toString()));
// steadyQualifyDTO.setIHarm_23_OverTime(Double.parseDouble(list.getIHarm23OverTime().toString()));
// steadyQualifyDTO.setIHarm_24_OverTime(Double.parseDouble(list.getIHarm24OverTime().toString()));
// steadyQualifyDTO.setIHarm_25_OverTime(Double.parseDouble(list.getIHarm25OverTime().toString()));
// steadyQualifyDTO.setI_Neg_OverTime(Double.parseDouble(list.getINegOverTime().toString()));
// steadyQualifyDTO.setInUHARM_1_OverTime(Double.parseDouble(list.getInuHarm1OverTime().toString()));
// steadyQualifyDTO.setInUHARM_2_OverTime(Double.parseDouble(list.getInuHarm2OverTime().toString()));
// steadyQualifyDTO.setInUHARM_3_OverTime(Double.parseDouble(list.getInuHarm3OverTime().toString()));
// steadyQualifyDTO.setInUHARM_4_OverTime(Double.parseDouble(list.getInuHarm4OverTime().toString()));
// steadyQualifyDTO.setInUHARM_5_OverTime(Double.parseDouble(list.getInuHarm5OverTime().toString()));
// steadyQualifyDTO.setInUHARM_6_OverTime(Double.parseDouble(list.getInuHarm6OverTime().toString()));
// steadyQualifyDTO.setInUHARM_7_OverTime(Double.parseDouble(list.getInuHarm7OverTime().toString()));
// steadyQualifyDTO.setInUHARM_8_OverTime(Double.parseDouble(list.getInuHarm8OverTime().toString()));
// steadyQualifyDTO.setInUHARM_9_OverTime(Double.parseDouble(list.getInuHarm9OverTime().toString()));
// steadyQualifyDTO.setInUHARM_10_OverTime(Double.parseDouble(list.getInuHarm10OverTime().toString()));
// steadyQualifyDTO.setInUHARM_11_OverTime(Double.parseDouble(list.getInuHarm11OverTime().toString()));
// steadyQualifyDTO.setInUHARM_12_OverTime(Double.parseDouble(list.getInuHarm12OverTime().toString()));
// steadyQualifyDTO.setInUHARM_13_OverTime(Double.parseDouble(list.getInuHarm13OverTime().toString()));
// steadyQualifyDTO.setInUHARM_14_OverTime(Double.parseDouble(list.getInuHarm14OverTime().toString()));
// steadyQualifyDTO.setInUHARM_15_OverTime(Double.parseDouble(list.getInuHarm15OverTime().toString()));
// steadyQualifyDTO.setInUHARM_16_OverTime(Double.parseDouble(list.getInuHarm16OverTime().toString()));
// steadyQualifyDTO.setUAberrance_OverTime(Double.parseDouble(list.getUAberranceOverTime().toString()));
// steadyQualifyDTO.setUBalance_OverTime(Double.parseDouble(list.getUBalanceOverTime().toString()));
// steadyQualifyDTO.setUHarm_2_OverTime(Double.parseDouble(list.getUHarm2OverTime().toString()));
// steadyQualifyDTO.setUHarm_3_OverTime(Double.parseDouble(list.getUHarm3OverTime().toString()));
// steadyQualifyDTO.setUHarm_4_OverTime(Double.parseDouble(list.getUHarm4OverTime().toString()));
// steadyQualifyDTO.setUHarm_5_OverTime(Double.parseDouble(list.getUHarm5OverTime().toString()));
// steadyQualifyDTO.setUHarm_6_OverTime(Double.parseDouble(list.getUHarm6OverTime().toString()));
// steadyQualifyDTO.setUHarm_7_OverTime(Double.parseDouble(list.getUHarm7OverTime().toString()));
// steadyQualifyDTO.setUHarm_8_OverTime(Double.parseDouble(list.getUHarm8OverTime().toString()));
// steadyQualifyDTO.setUHarm_9_OverTime(Double.parseDouble(list.getUHarm9OverTime().toString()));
// steadyQualifyDTO.setUHarm_10_OverTime(Double.parseDouble(list.getUHarm10OverTime().toString()));
// steadyQualifyDTO.setUHarm_11_OverTime(Double.parseDouble(list.getUHarm11OverTime().toString()));
// steadyQualifyDTO.setUHarm_12_OverTime(Double.parseDouble(list.getUHarm12OverTime().toString()));
// steadyQualifyDTO.setUHarm_13_OverTime(Double.parseDouble(list.getUHarm13OverTime().toString()));
// steadyQualifyDTO.setUHarm_14_OverTime(Double.parseDouble(list.getUHarm14OverTime().toString()));
// steadyQualifyDTO.setUHarm_15_OverTime(Double.parseDouble(list.getUHarm15OverTime().toString()));
// steadyQualifyDTO.setUHarm_16_OverTime(Double.parseDouble(list.getUHarm16OverTime().toString()));
// steadyQualifyDTO.setUHarm_17_OverTime(Double.parseDouble(list.getUHarm17OverTime().toString()));
// steadyQualifyDTO.setUHarm_18_OverTime(Double.parseDouble(list.getUHarm18OverTime().toString()));
// steadyQualifyDTO.setUHarm_19_OverTime(Double.parseDouble(list.getUHarm19OverTime().toString()));
// steadyQualifyDTO.setUHarm_20_OverTime(Double.parseDouble(list.getUHarm20OverTime().toString()));
// steadyQualifyDTO.setUHarm_21_OverTime(Double.parseDouble(list.getUHarm21OverTime().toString()));
// steadyQualifyDTO.setUHarm_22_OverTime(Double.parseDouble(list.getUHarm22OverTime().toString()));
// steadyQualifyDTO.setUHarm_23_OverTime(Double.parseDouble(list.getUHarm23OverTime().toString()));
// steadyQualifyDTO.setUHarm_24_OverTime(Double.parseDouble(list.getUHarm24OverTime().toString()));
// steadyQualifyDTO.setUHarm_25_OverTime(Double.parseDouble(list.getUHarm25OverTime().toString()));
// steadyQualifyDTO.setVoltage_Dev_OverTime(Double.parseDouble(list.getVoltageDevOverTime().toString()));
// qualifyDTOList.add(steadyQualifyDTO);
// });
//
//
// return qualifyDTOList;
}

View File

@@ -1,5 +1,10 @@
package com.njcn.harmonic.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
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;
@@ -15,9 +20,11 @@ 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.influxdb.utils.InfluxDbUtils;
import lombok.AllArgsConstructor;
@@ -49,7 +56,7 @@ public class THDistortionServiceImpl implements THDistortionService {
private final RMpVThdMapper rMpVThdMapper;
private final LineFeignClient lineFeignClient;
private final IRStatDataVDService statDataVDService;
@Override
public List<THDistortionVO> getTHDistortionData(DeviceInfoParam.BusinessParam thDistortionParam) {
List<THDistortionVO> thDistortionVOS = new ArrayList<>();
@@ -70,10 +77,13 @@ public class THDistortionServiceImpl implements THDistortionService {
//查找畸变率
List<PublicDTO> condition = getCondition(lineIndexes, thDistortionParam.getSearchBeginTime(), thDistortionParam.getSearchEndTime());
thDistortionVO.setDistortion(condition.stream().mapToDouble(PublicDTO::getData).average().orElse(3.14159));
//组装父级数据树
List<THDistortionVO> treeList = getTreeData(lineIndexes, thDistortionParam);
thDistortionVO.setChildren(treeList);
if(CollUtil.isNotEmpty(condition)){
thDistortionVO.setDistortion(condition.stream().mapToDouble(PublicDTO::getData).average().orElse(3.14159));
//组装父级数据树
List<THDistortionVO> treeList = getTreeData(lineIndexes, thDistortionParam);
thDistortionVO.setChildren(treeList);
}
}
thDistortionVOS.add(thDistortionVO);
}
@@ -224,42 +234,70 @@ public class THDistortionServiceImpl implements THDistortionService {
*/
private List<PublicDTO> getCondition(List<String> lineIndexes, String startTime, String endTime) {
List<PublicDTO> publicDTOList = new ArrayList<>();
//组装sql语句
StringBuilder string = new StringBuilder();
string.append(Param.QualityFlag + "='1' and (" + Param.PHASIC_TYPE + "='" + Param.PHASIC_TYPEA + "' or " + Param.PHASIC_TYPE + "='" + Param.PHASIC_TYPEB + "' or " + Param.PHASIC_TYPE + "='" + Param.PHASIC_TYPEC + "') and "+ Param.VALUETYPE + "='AVG' and ");
StringBuilder timeId = new StringBuilder();
timeId.append(Param.TIME + " >= '" + startTime + Param.START_TIME + "' and " + Param.TIME + " <= '" + endTime + Param.END_TIME + "' and (");
for (int i = 0; i < lineIndexes.size(); i++) {
if (lineIndexes.size() - i != 1) {
timeId.append(Param.LINE_ID + "='").append(lineIndexes.get(i)).append("' or ");
} else {
timeId.append(Param.LINE_ID + "='").append(lineIndexes.get(i)).append("')");
List<String> phasicType=new ArrayList<>();
phasicType.add(Param.PHASIC_TYPEA);
phasicType.add(Param.PHASIC_TYPEB);
phasicType.add(Param.PHASIC_TYPEC);
//数据库查询
List<RStatDataVD> info = statDataVDService.list(new LambdaQueryWrapper<RStatDataVD>()
.in(RStatDataVD::getLineId, lineIndexes)
.ge(StrUtil.isNotBlank(startTime), RStatDataVD::getTime, DateUtil.beginOfDay(DateUtil.parse(startTime)))
.le(StrUtil.isNotBlank(endTime), RStatDataVD::getTime, DateUtil.endOfDay(DateUtil.parse(endTime)))
.eq(RStatDataVD::getQualityFlag, 1)
.in(RStatDataVD::getPhasicType, phasicType)
.eq(RStatDataVD::getValueType, Param.VALUE_TYPEAVG)
);
if (CollUtil.isNotEmpty(info)){
//根据id分组先乘以100.在取平均值,在四舍五入
Map<String, Double> vthdMap = info.stream().filter(x-> x.getVThd()!=null).collect(Collectors.groupingBy(RStatDataVD::getLineId,
Collectors.averagingDouble(x->x.getVThd().multiply(new BigDecimal(100)).setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue())));
PublicDTO publicDTO ;
for (Map.Entry<String, Double> entry : vthdMap.entrySet()) {
publicDTO = new PublicDTO();
publicDTO.setId(entry.getKey());
publicDTO.setData(entry.getValue());
publicDTOList.add(publicDTO);
}
}
// String a = "SELECT MEAN(V_THD) AS distortion FROM Data_V WHERE QualityFlag='1' and (phasic_type='A' or phasic_type='B' or phasic_type='C')and value_type='AVG' and time >= '2022-03-20 00:00:00' and time <= '2022-03-21 23:59:59' and (lineid ='1e3b8531483b2a8cbee6747f1f641cf9') group by lineid;";
//sql语句
String sql = "SELECT MEAN(" + Param.V_THD + ")*100 AS distortion FROM Data_V WHERE " + string + timeId + " group by " + Param.LINE_ID;
//结果集
QueryResult result = influxDbUtils.query(sql);
//处理结果集
List<QueryResult.Series> list = result.getResults().get(0).getSeries();
if (!CollectionUtils.isEmpty(list)){
list.forEach(po->{
PublicDTO publicDTO = new PublicDTO();
List<List<Object>> valueList = po.getValues();
String index = po.getTags().get(Param.LINE_ID);
if (!CollectionUtils.isEmpty(valueList)){
for (List<Object> value : valueList) {
//谐波畸变率 保留两位小数
Double distortion = value.get(1) == null ? null : BigDecimal.valueOf(Double.parseDouble(value.get(1).toString())).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
publicDTO.setId(index);
publicDTO.setData(distortion);
}
}
publicDTOList.add(publicDTO);
});
}
return publicDTOList;
//组装sql语句
// StringBuilder string = new StringBuilder();
// string.append(Param.QualityFlag + "='1' and (" + Param.PHASIC_TYPE + "='" + Param.PHASIC_TYPEA + "' or " + Param.PHASIC_TYPE + "='" + Param.PHASIC_TYPEB + "' or " + Param.PHASIC_TYPE + "='" + Param.PHASIC_TYPEC + "') and "+ Param.VALUETYPE + "='AVG' and ");
// StringBuilder timeId = new StringBuilder();
// timeId.append(Param.TIME + " >= '" + startTime + Param.START_TIME + "' and " + Param.TIME + " <= '" + endTime + Param.END_TIME + "' and (");
// for (int i = 0; i < lineIndexes.size(); i++) {
// if (lineIndexes.size() - i != 1) {
// timeId.append(Param.LINE_ID + "='").append(lineIndexes.get(i)).append("' or ");
// } else {
// timeId.append(Param.LINE_ID + "='").append(lineIndexes.get(i)).append("')");
// }
// }
// // String a = "SELECT MEAN(V_THD) AS distortion FROM Data_V WHERE QualityFlag='1' and (phasic_type='A' or phasic_type='B' or phasic_type='C')and value_type='AVG' and time >= '2022-03-20 00:00:00' and time <= '2022-03-21 23:59:59' and (lineid ='1e3b8531483b2a8cbee6747f1f641cf9') group by lineid;";
// //sql语句
// String sql = "SELECT MEAN(" + Param.V_THD + ")*100 AS distortion FROM Data_V WHERE " + string + timeId + " group by " + Param.LINE_ID;
// //结果集
// QueryResult result = influxDbUtils.query(sql);
// //处理结果集
// List<QueryResult.Series> list = result.getResults().get(0).getSeries();
// if (!CollectionUtils.isEmpty(list)){
// list.forEach(po->{
// PublicDTO publicDTO = new PublicDTO();
// List<List<Object>> valueList = po.getValues();
// String index = po.getTags().get(Param.LINE_ID);
// if (!CollectionUtils.isEmpty(valueList)){
// for (List<Object> value : valueList) {
// //谐波畸变率 保留两位小数
// Double distortion = value.get(1) == null ? null : BigDecimal.valueOf(Double.parseDouble(value.get(1).toString())).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
// publicDTO.setId(index);
// publicDTO.setData(distortion);
// }
// }
// publicDTOList.add(publicDTO);
// });
// }
// return publicDTOList;
}

View File

@@ -1,9 +1,14 @@
package com.njcn.harmonic.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import com.njcn.common.config.GeneralInfo;
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.TerminalDataMapper;
import com.njcn.harmonic.pojo.dto.PublicDTO;
import com.njcn.harmonic.pojo.vo.TerminalCensusVO;
@@ -207,39 +212,59 @@ public class TerminalServiceImpl implements TerminalService {
*/
private List<PublicDTO> getCondition(List<String> deviceIndexes, String startTime, String endTime) {
List<PublicDTO> publicDTOList = new ArrayList<>();
//组装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 (");
for (int i = 0; i < deviceIndexes.size(); i++) {
if (deviceIndexes.size() - i != 1) {
stringBuilder.append(InfluxDBPublicParam.DEV_INDEX + "='").append(deviceIndexes.get(i)).append("' or ");
} else {
stringBuilder.append(InfluxDBPublicParam.DEV_INDEX + "='").append(deviceIndexes.get(i)).append("')");
}
}
//sql语句
String sql = "SELECT (SUM(" + InfluxDBPublicParam.ONLINE_MIN + ")/(SUM(" + InfluxDBPublicParam.OFFLINE_MIN + ")+SUM(" + InfluxDBPublicParam.ONLINE_MIN + ")))*100 AS onlineRate FROM "+InfluxDBPublicParam.PQS_ONLINERATE+" WHERE " + stringBuilder + " group by " + InfluxDBPublicParam.DEV_INDEX + InfluxDBPublicParam.TIME_ZONE;
//结果集
QueryResult result = influxDbUtils.query(sql);
//处理结果集
List<QueryResult.Series> list = result.getResults().get(0).getSeries();
if (!CollectionUtils.isEmpty(list)) {
list.forEach(po -> {
OnlineRateParam param=new OnlineRateParam();
param.setIds(deviceIndexes);
param.setStartTime( DateUtil.beginOfDay(DateUtil.parse(startTime)).toString());
param.setEndTime( DateUtil.endOfDay(DateUtil.parse(endTime)).toString());
List<RStatOnlinerateVO> data = generalDeviceInfoClient.getOnlineRateByDevIds(param).getData();
if (CollUtil.isNotEmpty(data)) {
data.forEach(po -> {
PublicDTO publicDTO = new PublicDTO();
List<List<Object>> valueList = po.getValues();
String index = po.getTags().get(InfluxDBPublicParam.DEV_INDEX);
if (!CollectionUtils.isEmpty(valueList)) {
for (List<Object> value : valueList) {
//终端在线率 保留两位小数
Double onlineRate = value.get(1) == null ? null : BigDecimal.valueOf(Double.parseDouble(value.get(1).toString())).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
publicDTO.setId(index);
publicDTO.setData(onlineRate);
}
}
//终端在线率 保留两位小数
Double onlineRate = po.getOnlineRate() == null ? null : BigDecimal.valueOf(Double.parseDouble(po.getOnlineRate().toString())).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
publicDTO.setId(po.getDevIndex());
publicDTO.setData(onlineRate);
publicDTOList.add(publicDTO);
});
}
return publicDTOList;
// //组装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 (");
// for (int i = 0; i < deviceIndexes.size(); i++) {
// if (deviceIndexes.size() - i != 1) {
// stringBuilder.append(InfluxDBPublicParam.DEV_INDEX + "='").append(deviceIndexes.get(i)).append("' or ");
// } else {
// stringBuilder.append(InfluxDBPublicParam.DEV_INDEX + "='").append(deviceIndexes.get(i)).append("')");
// }
// }
// //sql语句
// String sql = "SELECT (SUM(" + InfluxDBPublicParam.ONLINE_MIN + ")/(SUM(" + InfluxDBPublicParam.OFFLINE_MIN + ")+SUM(" + InfluxDBPublicParam.ONLINE_MIN + ")))*100 AS onlineRate FROM "+InfluxDBPublicParam.PQS_ONLINERATE+" WHERE " + stringBuilder + " group by " + InfluxDBPublicParam.DEV_INDEX + InfluxDBPublicParam.TIME_ZONE;
// //结果集
// QueryResult result = influxDbUtils.query(sql);
// //处理结果集
// List<QueryResult.Series> list = result.getResults().get(0).getSeries();
// if (!CollectionUtils.isEmpty(list)) {
// list.forEach(po -> {
// PublicDTO publicDTO = new PublicDTO();
// List<List<Object>> valueList = po.getValues();
// String index = po.getTags().get(InfluxDBPublicParam.DEV_INDEX);
// if (!CollectionUtils.isEmpty(valueList)) {
// for (List<Object> value : valueList) {
// //终端在线率 保留两位小数
// Double onlineRate = value.get(1) == null ? null : BigDecimal.valueOf(Double.parseDouble(value.get(1).toString())).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
// publicDTO.setId(index);
// publicDTO.setData(onlineRate);
// }
// }
// publicDTOList.add(publicDTO);
// });
// }
// return publicDTOList;
}
/**