Commit 179edab1 authored by caotao's avatar caotao

优化曲线查询效率与查询sql

parent 386d197e
...@@ -488,16 +488,14 @@ public class MonitorFanIndicatorImpl implements IMonitorFanIndicator { ...@@ -488,16 +488,14 @@ public class MonitorFanIndicatorImpl implements IMonitorFanIndicator {
Map<String, Object> otherInfo = new HashMap<>(); Map<String, Object> otherInfo = new HashMap<>();
List<IndicatorData> activePowerList = new ArrayList<>(); List<IndicatorData> activePowerList = new ArrayList<>();
List<IndicatorData> otherList = new ArrayList<>(); List<IndicatorData> otherList = new ArrayList<>();
String startTime = DateUtil.today() + " 00:00:00";
String endTime = DateUtil.today() + " 23:59:59";
Double installedCapacity = commonServiceImpl.getStationCapactityByStationWerks(stationBasic.getStationNumber()); Double installedCapacity = commonServiceImpl.getStationCapactityByStationWerks(stationBasic.getStationNumber());
if ("FDZ".equals(stationBasic.getStationType())) { if ("FDZ".equals(stationBasic.getStationType())) {
activePowerList = indicatorDataMapper.selectDataByequipmentIndexNameAndtime(CommonConstans.xiazaoActivePowerPoint, startTime, endTime, stationBasic.getBoosterGatewayId()); activePowerList = indicatorDataMapper.selectDataByequipmentIndexNameAndtime(CommonConstans.xiazaoActivePowerPoint, stationBasic.getBoosterGatewayId());
otherList = indicatorDataMapper.selectDataByequipmentIndexNameAndtime(CommonConstans.xiazaoWindSpeedrPoint, startTime, endTime, stationBasic.getFanGatewayId()); otherList = indicatorDataMapper.selectDataByequipmentIndexNameAndtime(CommonConstans.xiazaoWindSpeedrPoint, stationBasic.getFanGatewayId());
groupMap = otherList.stream().collect(Collectors.groupingBy(IndicatorData::getCreatedTime, Collectors.averagingDouble(IndicatorData::getValueF))); groupMap = otherList.stream().collect(Collectors.groupingBy(IndicatorData::getCreatedTime, Collectors.averagingDouble(IndicatorData::getValueF)));
} else { } else {
activePowerList = indicatorDataMapper.selectDataByequipmentIndexNameAndtime(CommonConstans.taiheActivePowerPoint, startTime, endTime, stationBasic.getBoosterGatewayId()); activePowerList = indicatorDataMapper.selectDataByequipmentIndexNameAndtime(CommonConstans.taiheActivePowerPoint, stationBasic.getBoosterGatewayId());
otherList = indicatorDataMapper.selectDataByequipmentIndexNameAndtime(CommonConstans.taiheIrradiationPonit, startTime, endTime, stationBasic.getBoosterGatewayId()); otherList = indicatorDataMapper.selectDataByequipmentIndexNameAndtime(CommonConstans.taiheIrradiationPonit, stationBasic.getBoosterGatewayId());
} }
for (int i = 0; i < activePowerList.size(); i++) { for (int i = 0; i < activePowerList.size(); i++) {
IndicatorData indicatorData = activePowerList.get(i); IndicatorData indicatorData = activePowerList.get(i);
...@@ -555,14 +553,11 @@ public class MonitorFanIndicatorImpl implements IMonitorFanIndicator { ...@@ -555,14 +553,11 @@ public class MonitorFanIndicatorImpl implements IMonitorFanIndicator {
public Map<String, Object> getDetailsWindSpeed(String gatewayId, String name) { public Map<String, Object> getDetailsWindSpeed(String gatewayId, String name) {
Date currentDayStartTime = DateUtils.getCurrentDayStartTime(new Date());
Date currentDayEndTime = DateUtils.getCurrentDayEndTime(new Date());
String startTime = DateUtils.convertDateToString(currentDayStartTime, DateUtils.DATE_TIME_PATTERN);
String endTime = DateUtils.convertDateToString(currentDayEndTime, DateUtils.DATE_TIME_PATTERN);
List<IndicatorData> indicatorDataListWindSpeed = new ArrayList<>(); List<IndicatorData> indicatorDataListWindSpeed = new ArrayList<>();
List<IndicatorData> indicatorDataListActivePower = new ArrayList<>(); List<IndicatorData> indicatorDataListActivePower = new ArrayList<>();
indicatorDataListWindSpeed = indicatorDataMapper.selectDataByequipmentIndexNameAndtimeAndEquipmentNumber("瞬时风速", name, startTime, endTime, gatewayId); indicatorDataListWindSpeed = indicatorDataMapper.selectDataByequipmentIndexNameAndtimeAndEquipmentNumber("瞬时风速", name, gatewayId);
indicatorDataListActivePower = indicatorDataMapper.selectDataByequipmentIndexNameAndtimeAndEquipmentNumber("有功功率", name, startTime, endTime, gatewayId); indicatorDataListActivePower = indicatorDataMapper.selectDataByequipmentIndexNameAndtimeAndEquipmentNumber("有功功率", name, gatewayId);
List<String> windSpeeds = new ArrayList<>(); List<String> windSpeeds = new ArrayList<>();
List<String> activePowers = new ArrayList<>(); List<String> activePowers = new ArrayList<>();
List<String> axisData = new ArrayList<>(); List<String> axisData = new ArrayList<>();
...@@ -586,12 +581,8 @@ public class MonitorFanIndicatorImpl implements IMonitorFanIndicator { ...@@ -586,12 +581,8 @@ public class MonitorFanIndicatorImpl implements IMonitorFanIndicator {
public Map<String, Object> getDetailsWindSpeeds(String gatewayId, String name) { public Map<String, Object> getDetailsWindSpeeds(String gatewayId, String name) {
Date currentDayStartTime = DateUtils.getCurrentDayStartTime(new Date());
Date currentDayEndTime = DateUtils.getCurrentDayEndTime(new Date());
String startTime = DateUtils.convertDateToString(currentDayStartTime, DateUtils.DATE_TIME_PATTERN);
String endTime = DateUtils.convertDateToString(currentDayEndTime, DateUtils.DATE_TIME_PATTERN);
List<IndicatorData> indicatorDataListActivePowers = new ArrayList<>(); List<IndicatorData> indicatorDataListActivePowers = new ArrayList<>();
indicatorDataListActivePowers = indicatorDataMapper.selectDataByequipmentIndexNameAndtimeAndEquipmentNumber("有功功率", name, startTime, endTime, gatewayId); indicatorDataListActivePowers = indicatorDataMapper.selectDataByequipmentIndexNameAndtimeAndEquipmentNumber("有功功率", name, gatewayId);
List<String> axisData = new ArrayList<>(); List<String> axisData = new ArrayList<>();
List<String> activePowers = new ArrayList<>(); List<String> activePowers = new ArrayList<>();
for (int i = 0; i < indicatorDataListActivePowers.size(); i++) { for (int i = 0; i < indicatorDataListActivePowers.size(); i++) {
...@@ -1858,11 +1849,7 @@ public class MonitorFanIndicatorImpl implements IMonitorFanIndicator { ...@@ -1858,11 +1849,7 @@ public class MonitorFanIndicatorImpl implements IMonitorFanIndicator {
} }
public Map<String, Object> hlWindSpeeds(String gatewayId, String equipNum) { public Map<String, Object> hlWindSpeeds(String gatewayId, String equipNum) {
Date currentDayStartTime = DateUtils.getCurrentDayStartTime(new Date()); List<IndicatorData> originarPVs = indicatorDataMapper.selectDataByequipmentIndexNameAndtimeAndEquipmentNumberPv(equipNum, gatewayId);
Date currentDayEndTime = DateUtils.getCurrentDayEndTime(new Date());
String startTime = DateUtils.convertDateToString(currentDayStartTime, DateUtils.DATE_TIME_PATTERN);
String endTime = DateUtils.convertDateToString(currentDayEndTime, DateUtils.DATE_TIME_PATTERN);
List<IndicatorData> originarPVs = indicatorDataMapper.selectDataByequipmentIndexNameAndtimeAndEquipmentNumberPv(equipNum, startTime, endTime, gatewayId);
originarPVs.size(); originarPVs.size();
Map<String, Object> resultMap = new HashMap<>(); Map<String, Object> resultMap = new HashMap<>();
Map<String, List<IndicatorData>> data = originarPVs.stream().collect(Collectors.groupingBy(IndicatorData::getEquipmentIndexName, TreeMap::new, Collectors.toList())); Map<String, List<IndicatorData>> data = originarPVs.stream().collect(Collectors.groupingBy(IndicatorData::getEquipmentIndexName, TreeMap::new, Collectors.toList()));
...@@ -1907,7 +1894,7 @@ public class MonitorFanIndicatorImpl implements IMonitorFanIndicator { ...@@ -1907,7 +1894,7 @@ public class MonitorFanIndicatorImpl implements IMonitorFanIndicator {
} }
} }
List<Map<String, String>> maps = new ArrayList<>(); List<Map<String, String>> maps = new ArrayList<>();
List<String> nums = new ArrayList<>(); Set<String> nums = new HashSet<>();
//此处组装数据 每一个Map代表一个逆变器 //此处组装数据 每一个Map代表一个逆变器
for (ESEquipments esEquipments : listData1) { for (ESEquipments esEquipments : listData1) {
int num = Integer.parseInt(esEquipments.getEquipmentNumber().substring(0, 2)); int num = Integer.parseInt(esEquipments.getEquipmentNumber().substring(0, 2));
......
...@@ -706,7 +706,7 @@ public class MonitoringServiceImpl { ...@@ -706,7 +706,7 @@ public class MonitoringServiceImpl {
AtomicReference<Double> monthlyPower = new AtomicReference<>(0.0); AtomicReference<Double> monthlyPower = new AtomicReference<>(0.0);
//年发电量 //年发电量
AtomicReference<Double> annualPower = new AtomicReference<>(0.0); AtomicReference<Double> annualPower = new AtomicReference<>(0.0);
stationCacheInfoDtoList.forEach( stationCacheInfoDto->{ stationCacheInfoDtoList.forEach(stationCacheInfoDto -> {
if ("FDZ".equals(stationCacheInfoDto.getStationType())) { if ("FDZ".equals(stationCacheInfoDto.getStationType())) {
Map<String, List<String>> queryCondtion = new HashMap<>(); Map<String, List<String>> queryCondtion = new HashMap<>();
queryCondtion.put(CommonConstans.QueryStringEquipmentIndexName, Arrays.asList("日发电量", "月发电量", "年发电量")); queryCondtion.put(CommonConstans.QueryStringEquipmentIndexName, Arrays.asList("日发电量", "月发电量", "年发电量"));
...@@ -824,13 +824,13 @@ public class MonitoringServiceImpl { ...@@ -824,13 +824,13 @@ public class MonitoringServiceImpl {
List<ESEquipments> result = commonServiceImpl.getListDataByCondtions(queryCondtion, null, ESEquipments.class); List<ESEquipments> result = commonServiceImpl.getListDataByCondtions(queryCondtion, null, ESEquipments.class);
total.set(commonServiceImpl.getSumByEquipmentIndxName(result, finalIndicator)); total.set(commonServiceImpl.getSumByEquipmentIndxName(result, finalIndicator));
} }
stationCacheInfoDto.setAddress(String.format(CommonConstans.Twodecimalplaces, (total.get())*100/getPlanGenByStationIdAndMonth(stationCacheInfoDto.getStationId()))); stationCacheInfoDto.setAddress(String.format(CommonConstans.Twodecimalplaces, (total.get()) * 100 / getPlanGenByStationIdAndMonth(stationCacheInfoDto.getStationId())));
}); });
List<StationCacheInfoDto> sorted = stationCacheInfoDtoList.stream().sorted(Comparator.comparing(StationCacheInfoDto::getAddress, Comparator.comparingDouble(Double::parseDouble)).reversed()).collect(Collectors.toList()); List<StationCacheInfoDto> sorted = stationCacheInfoDtoList.stream().sorted(Comparator.comparing(StationCacheInfoDto::getAddress, Comparator.comparingDouble(Double::parseDouble)).reversed()).collect(Collectors.toList());
sorted.forEach(stationBasic -> { sorted.forEach(stationBasic -> {
HashMap<String, String> hashMap1 = new HashMap<>(); HashMap<String, String> hashMap1 = new HashMap<>();
hashMap1.put("stationName", stationBasic.getStationName()); hashMap1.put("stationName", stationBasic.getStationName());
hashMap1.put("value", stationBasic.getAddress()+"%"); hashMap1.put("value", stationBasic.getAddress() + "%");
hashMap1.put("value1", stationBasic.getAddress()); hashMap1.put("value1", stationBasic.getAddress());
mapList.add(hashMap1); mapList.add(hashMap1);
}); });
...@@ -1051,19 +1051,19 @@ public class MonitoringServiceImpl { ...@@ -1051,19 +1051,19 @@ public class MonitoringServiceImpl {
page2.setRecords(list2); page2.setRecords(list2);
Double totalAnnual = (powerOfAnnualFD + powerOfAnnualGF); Double totalAnnual = (powerOfAnnualFD + powerOfAnnualGF);
HashMap<String, String> stringHashMap13 = new HashMap<>(); HashMap<String, String> stringHashMap13 = new HashMap<>();
stringHashMap13.put("title1", String.format(CommonConstans.Twodecimalplaces, (totalAnnual * CommonConstans.carbonDioxide ))); stringHashMap13.put("title1", String.format(CommonConstans.Twodecimalplaces, (totalAnnual * CommonConstans.carbonDioxide)));
stringHashMap13.put("title2", "二氧化碳减排量(t)"); stringHashMap13.put("title2", "二氧化碳减排量(t)");
list3.add(stringHashMap13); list3.add(stringHashMap13);
HashMap<String, String> stringHashMap14 = new HashMap<>(); HashMap<String, String> stringHashMap14 = new HashMap<>();
stringHashMap14.put("title1", String.format(CommonConstans.Twodecimalplaces, (totalAnnual * CommonConstans.standardCoal ))); stringHashMap14.put("title1", String.format(CommonConstans.Twodecimalplaces, (totalAnnual * CommonConstans.standardCoal)));
stringHashMap14.put("title2", "节约标准煤(t)"); stringHashMap14.put("title2", "节约标准煤(t)");
list3.add(stringHashMap14); list3.add(stringHashMap14);
HashMap<String, String> stringHashMap15 = new HashMap<>(); HashMap<String, String> stringHashMap15 = new HashMap<>();
stringHashMap15.put("title1", String.format(CommonConstans.Twodecimalplaces, (totalAnnual * CommonConstans.toner ))); stringHashMap15.put("title1", String.format(CommonConstans.Twodecimalplaces, (totalAnnual * CommonConstans.toner)));
stringHashMap15.put("title2", "碳粉尘减排量(t)"); stringHashMap15.put("title2", "碳粉尘减排量(t)");
list3.add(stringHashMap15); list3.add(stringHashMap15);
HashMap<String, String> stringHashMap16 = new HashMap<>(); HashMap<String, String> stringHashMap16 = new HashMap<>();
stringHashMap16.put("title1", String.format(CommonConstans.Twodecimalplaces, (totalAnnual * CommonConstans.sulfurDioxide ))); stringHashMap16.put("title1", String.format(CommonConstans.Twodecimalplaces, (totalAnnual * CommonConstans.sulfurDioxide)));
stringHashMap16.put("title2", "二氧化硫减排量(t)"); stringHashMap16.put("title2", "二氧化硫减排量(t)");
list3.add(stringHashMap16); list3.add(stringHashMap16);
page3.setRecords(list3); page3.setRecords(list3);
...@@ -1162,10 +1162,11 @@ public class MonitoringServiceImpl { ...@@ -1162,10 +1162,11 @@ public class MonitoringServiceImpl {
HashMap<String, Object> result = new HashMap<>(); HashMap<String, Object> result = new HashMap<>();
List<HashMap<String, Object>> hashMapList = new ArrayList<>(); List<HashMap<String, Object>> hashMapList = new ArrayList<>();
List<IndicatorData> indicatorDataList = new ArrayList<>(); List<IndicatorData> indicatorDataList = new ArrayList<>();
Long day = DateUtil.between(DateUtil.parse(date), new Date(), DateUnit.DAY);
if (stationBasic.getStationType().equals("FDZ")) { if (stationBasic.getStationType().equals("FDZ")) {
indicatorDataList = indicatorDataMapper.selectDataByequipmentIndexNameAndtime("220kV夏雩线212线路测控装置PCS-9705TA有功功率一次值", date + " 00:00:00", date + " 23:59:59", stationBasic.getBoosterGatewayId()); indicatorDataList = indicatorDataMapper.selectDataByequipmentIndexNameAndtimeJp("220kV夏雩线212线路测控装置PCS-9705TA有功功率一次值", stationBasic.getBoosterGatewayId(), day);
} else { } else {
indicatorDataList = indicatorDataMapper.selectDataByequipmentIndexNameAndtime("南瑞光差保护_313P", date + " 00:00:00", date + " 23:59:59", stationBasic.getBoosterGatewayId()); indicatorDataList = indicatorDataMapper.selectDataByequipmentIndexNameAndtimeJp("南瑞光差保护_313P", stationBasic.getBoosterGatewayId(), day);
} }
//x轴数据 //x轴数据
List<String> xdata = new ArrayList<>(); List<String> xdata = new ArrayList<>();
...@@ -1314,7 +1315,7 @@ public class MonitoringServiceImpl { ...@@ -1314,7 +1315,7 @@ public class MonitoringServiceImpl {
queryCondtion1.put(CommonConstans.QueryStringGateWayId, Arrays.asList(stationBasic.getBoosterGatewayId())); queryCondtion1.put(CommonConstans.QueryStringGateWayId, Arrays.asList(stationBasic.getBoosterGatewayId()));
queryCondtion1.put(CommonConstans.QueryStringEquipmentIndexName, Arrays.asList("南瑞光差保护_313P")); queryCondtion1.put(CommonConstans.QueryStringEquipmentIndexName, Arrays.asList("南瑞光差保护_313P"));
List<ESEquipments> esEquipmentsList = commonServiceImpl.getListDataByCondtions(queryCondtion1, null, ESEquipments.class); List<ESEquipments> esEquipmentsList = commonServiceImpl.getListDataByCondtions(queryCondtion1, null, ESEquipments.class);
total.updateAndGet(v -> v + commonServiceImpl.getSumByEquipmentIndxName(esEquipmentsList, "南瑞光差保护_313P")*CommonConstans.kwToMv); total.updateAndGet(v -> v + commonServiceImpl.getSumByEquipmentIndxName(esEquipmentsList, "南瑞光差保护_313P") * CommonConstans.kwToMv);
} }
}); });
//有功功率换算 //有功功率换算
...@@ -1325,8 +1326,9 @@ public class MonitoringServiceImpl { ...@@ -1325,8 +1326,9 @@ public class MonitoringServiceImpl {
public Double keepFourdecimalPlaces(Double param) { public Double keepFourdecimalPlaces(Double param) {
return Double.valueOf(String.format("%.4f", param)); return Double.valueOf(String.format("%.4f", param));
} }
public Double getPlanGenByStationIdAndMonth(String stationId){
String [] dates = DateUtil.today().split("-"); public Double getPlanGenByStationIdAndMonth(String stationId) {
return stationPlanMapper.getPlanGenByStationIdAndMonth(stationId,dates[0], String.valueOf(Integer.valueOf(dates[1]))); String[] dates = DateUtil.today().split("-");
return stationPlanMapper.getPlanGenByStationIdAndMonth(stationId, dates[0], String.valueOf(Integer.valueOf(dates[1])));
} }
} }
...@@ -11,17 +11,15 @@ import java.util.List; ...@@ -11,17 +11,15 @@ import java.util.List;
@Repository @Repository
public interface IndicatorDataMapper extends BaseMapper<IndicatorData> { public interface IndicatorDataMapper extends BaseMapper<IndicatorData> {
@Select("select `value`, created_time, `value_f` as valueF from iot_data.indicator_data where equipment_index_name =#{equipmentIndexName} and equipment_number = #{equipmentNumber} and created_time >= #{startTime} and created_time <= #{endTime} and gateway_id =#{gatewayId}") @Select("select `value`, created_time, `value_f` as valueF from iot_data.indicator_data where equipment_index_name =#{equipmentIndexName} and equipment_number = #{equipmentNumber} and ts >= TODAY()-8h and gateway_id =#{gatewayId}")
List<IndicatorData> selectDataByequipmentIndexNameAndtimeAndEquipmentNumber(@Param("equipmentIndexName") String equipmentIndexName, @Param("equipmentNumber") String equipmentNumber, @Param("startTime") String startTime, @Param("endTime") String endTime, @Param("gatewayId") String gatewayId); List<IndicatorData> selectDataByequipmentIndexNameAndtimeAndEquipmentNumber(@Param("equipmentIndexName") String equipmentIndexName, @Param("equipmentNumber") String equipmentNumber, @Param("gatewayId") String gatewayId);
@Select("select `value`, created_time, `value_f` as valueF, equipment_index_name from iot_data.indicator_data where equipment_index_name like '%路电流%' and equipment_number = #{equipmentNumber} and created_time >= #{startTime} and created_time <= #{endTime} and gateway_id =#{gatewayId}") @Select("select `value`, created_time, `value_f` as valueF, equipment_index_name from iot_data.indicator_data where equipment_index_name like '%路电流%' and equipment_number = #{equipmentNumber} and ts >= TODAY()-8h and gateway_id =#{gatewayId}")
List<IndicatorData> selectDataByequipmentIndexNameAndtimeAndEquipmentNumberPv(@Param("equipmentNumber") String equipmentNumber, @Param("startTime") String startTime, @Param("endTime") String endTime, @Param("gatewayId") String gatewayId); List<IndicatorData> selectDataByequipmentIndexNameAndtimeAndEquipmentNumberPv(@Param("equipmentNumber") String equipmentNumber, @Param("gatewayId") String gatewayId);
@Select("select last(`value_f`) as `value_f`,created_time from iot_data.indicator_data where equipment_index_name =#{equipmentIndexName} and gateway_id=#{gatewayId} ") @Select("select `value`, created_time, `value_f` as valueF from iot_data.indicator_data where equipment_index_name =#{equipmentIndexName} and ts >=TODAY()-8h")
IndicatorData selectLastDataOfPower(@Param("equipmentIndexName") String equipmentIndexName, @Param("gatewayId") String gatewayId); List<IndicatorData> selectDataByequipmentIndexNameAndtime(@Param("equipmentIndexName") String equipmentIndexName, @Param("gatewayId") String gatewayId);
@Select("select last(`value_f`) as `value_f`,created_time from iot_data.indicator_data where equipment_index_name =#{equipmentIndexName} and gateway_id=#{gatewayId} and created_time <= #{endTime} ") @Select("select `value`, created_time, `value_f` as valueF from iot_data.indicator_data where equipment_index_name =#{equipmentIndexName} and ts >=TODAY()-#{day}d-8h")
IndicatorData selectLastDataOfPower(@Param("equipmentIndexName") String equipmentIndexName, @Param("gatewayId") String gatewayId,@Param("endTime") String endTime); List<IndicatorData> selectDataByequipmentIndexNameAndtimeJp(@Param("equipmentIndexName") String equipmentIndexName, @Param("gatewayId") String gatewayId,@Param("day") Long day);
@Select("select `value`, created_time, `value_f` as valueF from iot_data.indicator_data where equipment_index_name =#{equipmentIndexName} and created_time >= #{startTime} and created_time <= #{endTime} and gateway_id =#{gatewayId}")
List<IndicatorData> selectDataByequipmentIndexNameAndtime(@Param("equipmentIndexName") String equipmentIndexName, @Param("startTime") String startTime, @Param("endTime") String endTime, @Param("gatewayId") String gatewayId);
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment