Commit c1df5573 authored by caotao's avatar caotao

功率曲线全国、片区功率曲线开发

parent dba2135f
package com.yeejoin.amos.boot.module.jxiop.biz.config;
import com.alibaba.druid.pool.DruidDataSource;
import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import javax.sql.DataSource;
/**
* 从数据源配置
* 若需要配置更多数据源 , 直接在yml中添加数据源配置再增加相应的新的数据源配置类即可
*/
@Configuration
@MapperScan(basePackages = "com.yeejoin.amos.boot.module.jxiop.biz.tdanalysismapper", sqlSessionFactoryRef = "taosAnalysisSqlSessionFactory")
public class TdEngineAnalysisConfig {
private Logger logger = LoggerFactory.getLogger(TdEngineAnalysisConfig.class);
// 精确到 cluster 目录,以便跟其他数据源隔离
private static final String MAPPER_LOCATION = "classpath*:mapper/tdengineanalysis/*.xml";
@Value("${spring.db4.datasource.url}")
private String dbUrl;
@Value("${spring.db4.datasource.username}")
private String username;
@Value("${spring.db4.datasource.password}")
private String password;
@Value("${spring.db4.datasource.driver-class-name}")
private String driverClassName;
@Bean(name = "taosAnalysisDataSource") //声明其为Bean实例
public DataSource clusterDataSource() {
DruidDataSource datasource = new DruidDataSource();
datasource.setUrl(this.dbUrl);
datasource.setUsername(username);
datasource.setPassword(password);
datasource.setDriverClassName(driverClassName);
return datasource;
}
@Bean(name = "taosAnalysisTransactionManager")
public DataSourceTransactionManager clusterTransactionManager() {
return new DataSourceTransactionManager(clusterDataSource());
}
@Bean(name = "taosAnalysisSqlSessionFactory")
public SqlSessionFactory clusterSqlSessionFactory(@Qualifier("taosDataSource") DataSource culsterDataSource)
throws Exception {
final MybatisSqlSessionFactoryBean sessionFactory = new MybatisSqlSessionFactoryBean();
sessionFactory.setDataSource(culsterDataSource);
sessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver()
.getResources(TdEngineAnalysisConfig.MAPPER_LOCATION));
sessionFactory.setTypeAliasesPackage("com.yeejoin.amos.boot.module.jxiop.biz.entity");
//mybatis 数据库字段与实体类属性驼峰映射配置
sessionFactory.getObject().getConfiguration().setMapUnderscoreToCamelCase(true);
return sessionFactory.getObject();
}
}
...@@ -130,9 +130,9 @@ public class CommonConstans { ...@@ -130,9 +130,9 @@ public class CommonConstans {
public static final String YEAR_GEN_ATTAINMENT_RATE = "年计划完成率"; public static final String YEAR_GEN_ATTAINMENT_RATE = "年计划完成率";
//年利用小时数 //年利用小时数
public static final String YEAR_GEN_HOURS = "年利用小时数"; public static final String YEAR_GEN_HOURS = "年利用小时数";
public static final String WIND_SPEED_THIRTY_SECONDS = "30秒平均风速"; public static final String WIND_SPEED_THIRTY_SECONDS = "30秒平均风速";
public static final String TOTAL_RADIATION = "辐照度"; public static final String TOTAL_RADIATION = "辐照度";
public static final String TOTAL_RADIATION_SUM = "累计辐照度"; public static final String TOTAL_RADIATION_SUM = "累计辐照度";
public static final String ACTIVE_POWER = "有功功率"; public static final String ACTIVE_POWER = "有功功率";
......
...@@ -2,6 +2,7 @@ package com.yeejoin.amos.boot.module.jxiop.biz.entity; ...@@ -2,6 +2,7 @@ package com.yeejoin.amos.boot.module.jxiop.biz.entity;
import lombok.Data; import lombok.Data;
import java.io.PipedReader;
import java.util.Date; import java.util.Date;
@Data @Data
...@@ -23,7 +24,7 @@ public class IndicatorData { ...@@ -23,7 +24,7 @@ public class IndicatorData {
private String unit; private String unit;
private String value; private String value="0";
private Float valueF ; private Float valueF ;
...@@ -35,4 +36,11 @@ public class IndicatorData { ...@@ -35,4 +36,11 @@ public class IndicatorData {
private String displayName; private String displayName;
private String xtime; private String xtime;
private String pointSeq;
private String pointAddress;
private String pointLocation;
private String pointType;
private String pointName;
private String dasTime;
} }
...@@ -89,7 +89,6 @@ public interface MonitorService { ...@@ -89,7 +89,6 @@ public interface MonitorService {
IPage<Map> getStationOverViewFanByStationId( String stationId); IPage<Map> getStationOverViewFanByStationId( String stationId);
/** /**
* @Descritpion 根据入参动态获取全国发电量数据 * @Descritpion 根据入参动态获取全国发电量数据
* @param stationId
* @return * @return
*/ */
Map<String,Object> gettimedateyfd( ); Map<String,Object> gettimedateyfd( );
...@@ -109,5 +108,15 @@ public interface MonitorService { ...@@ -109,5 +108,15 @@ public interface MonitorService {
*/ */
ResultsData getElectricQuantityList(int current, int size, StationBasic stationBasic); ResultsData getElectricQuantityList(int current, int size, StationBasic stationBasic);
/**
* @Description 动态获取电量表计数据
*/
void getTotalData(); void getTotalData();
/**
* @Description 获取全国功率曲线
* @return
*/
Map<String, Object> getDetailsWindSpeedAlldataqg();
} }
...@@ -19,8 +19,10 @@ import com.yeejoin.amos.boot.module.jxiop.api.util.HttpRequestUtil; ...@@ -19,8 +19,10 @@ import com.yeejoin.amos.boot.module.jxiop.api.util.HttpRequestUtil;
import com.yeejoin.amos.boot.module.jxiop.biz.ESDto.ESMoonPowerGeneration; import com.yeejoin.amos.boot.module.jxiop.biz.ESDto.ESMoonPowerGeneration;
import com.yeejoin.amos.boot.module.jxiop.biz.constants.CommonConstans; import com.yeejoin.amos.boot.module.jxiop.biz.constants.CommonConstans;
import com.yeejoin.amos.boot.module.jxiop.biz.dto.*; import com.yeejoin.amos.boot.module.jxiop.biz.dto.*;
import com.yeejoin.amos.boot.module.jxiop.biz.entity.IndicatorData;
import com.yeejoin.amos.boot.module.jxiop.biz.service.CoreCommonService; import com.yeejoin.amos.boot.module.jxiop.biz.service.CoreCommonService;
import com.yeejoin.amos.boot.module.jxiop.biz.service.MonitorService; import com.yeejoin.amos.boot.module.jxiop.biz.service.MonitorService;
import com.yeejoin.amos.boot.module.jxiop.biz.tdanalysismapper.IndicatorDataNewMapper;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.eclipse.paho.client.mqttv3.MqttException; import org.eclipse.paho.client.mqttv3.MqttException;
...@@ -43,6 +45,7 @@ import java.text.DecimalFormat; ...@@ -43,6 +45,7 @@ import java.text.DecimalFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.*; import java.util.*;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static com.alibaba.fastjson.JSON.parseArray; import static com.alibaba.fastjson.JSON.parseArray;
...@@ -57,6 +60,7 @@ public class MonitorServiceImpl implements MonitorService { ...@@ -57,6 +60,7 @@ public class MonitorServiceImpl implements MonitorService {
private final HttpRequestUtil httpRequestUtil; private final HttpRequestUtil httpRequestUtil;
private final CoreCommonService coreCommonService; private final CoreCommonService coreCommonService;
private final StationElectricityMeterMapper stationElectricityMeterMapper; private final StationElectricityMeterMapper stationElectricityMeterMapper;
private final IndicatorDataNewMapper indicatorDataNewMapper;
@Value("classpath:/json/overview.json") @Value("classpath:/json/overview.json")
private Resource overview; private Resource overview;
@Value("classpath:/json/overviewGF.json") @Value("classpath:/json/overviewGF.json")
...@@ -893,4 +897,109 @@ public class MonitorServiceImpl implements MonitorService { ...@@ -893,4 +897,109 @@ public class MonitorServiceImpl implements MonitorService {
} }
} }
public Map<String, Object> getDetailsWindSpeedAlldataqg() {
List<StationCacheInfoDto> stationCacheInfoDtos = getListStationCacheInfoDto();
AtomicReference<Double> installedCapacity = new AtomicReference<>(0.0);
stationCacheInfoDtos.forEach( stationCacheInfoDto-> {
installedCapacity.updateAndGet(v -> v + Double.parseDouble(stationCacheInfoDto.getInstalledCapacity()));
});
Map<String, Object> map = new HashMap<>();
List<String> values = new ArrayList<>();
List<String> time = new ArrayList<>();
Map<String, Object> activePowerInfo = new HashMap<>();
List<IndicatorData> activePowerList = new ArrayList<>();
activePowerList = indicatorDataNewMapper.selectDataByequipmentIndexNameAndtimeqgNew(CommonConstans.ACTIVE_POWER);
Map<String,List<IndicatorData>> stringObjectMap =activePowerList.stream().collect(Collectors.groupingBy(IndicatorData::getDasTime));
stringObjectMap.keySet().stream().forEach(dasTime -> {
time.add(dasTime.split(":")[1]);
Double vl= stringObjectMap.get(dasTime).stream().mapToDouble(IndicatorData::getValueF).sum();
values.add(String.format(CommonConstans.Twodecimalplaces, vl));
});
String max = String.format(CommonConstans.Twodecimalplaces, values.stream().mapToDouble(Double::parseDouble).max().getAsDouble());
String min = String.format(CommonConstans.Twodecimalplaces, values.stream().mapToDouble(Double::parseDouble).min().getAsDouble());
String mean = String.format(CommonConstans.Twodecimalplaces, values.stream().mapToDouble(Double::parseDouble).average().getAsDouble());
activePowerInfo.put("mean", mean);
activePowerInfo.put("max", max);
activePowerInfo.put("min", min);
activePowerInfo.put("maxTime", time.get(values.lastIndexOf(max)));
activePowerInfo.put("minTime", time.get(values.lastIndexOf(min)));
activePowerInfo.put("load", String.format(CommonConstans.Twodecimalplaces, Double.valueOf(values.get(values.size() - 1)) / installedCapacity.get()));
List<Map<String, Object>> seriesData = new ArrayList<>();
Map<String, Object> map3 = new HashMap<>();
Map<String, Object> map1 = new HashMap<>();
Map<String, Object> map2 = new HashMap<>();
map1.put("data", values);
seriesData.add(map1);
map.put("seriesData", seriesData);
map.put("axisData", time);
System.out.println(JSON.toJSONString(map));
try {
emqKeeper.getMqttClient().publish( "all_Power_table", JSON.toJSON(map).toString().getBytes("UTF-8"), 1, true);
emqKeeper.getMqttClient().publish("all_Power_info", JSON.toJSON(activePowerInfo).toString().getBytes("UTF-8"), 1, true);
} catch (Exception exception) {
exception.printStackTrace();
}
return map;
}
public Map<String, Object> getDetailsWindqy(String s ) {
List<StationCacheInfoDto> stationCacheInfoDtos = getListStationCacheInfoDto();
AtomicReference<Double> installedCapacity = new AtomicReference<>(0.0);
stationCacheInfoDtos = stationCacheInfoDtos.stream().filter(stationCacheInfoDto -> stationCacheInfoDto.getBelongArea().equals(s)).collect(Collectors.toList());
stationCacheInfoDtos.forEach(stationCacheInfoDto -> {
installedCapacity.updateAndGet(v -> v + Double.parseDouble(stationCacheInfoDto.getInstalledCapacity()));
});
Map<String, Object> map = new HashMap<>();
List<String> values = new ArrayList<>();
List<String> fanGateWayIds = stationCacheInfoDtos.stream().filter(stationCacheInfoDto -> stationCacheInfoDto.getFanGatewayId()!=null).map(StationCacheInfoDto::getFanGatewayId).collect(Collectors.toList());
List<String> boostGateWayIds = stationCacheInfoDtos.stream().filter(stationCacheInfoDto -> stationCacheInfoDto.getBoosterGatewayId()!=null).map(StationCacheInfoDto::getBoosterGatewayId).collect(Collectors.toList());
fanGateWayIds.addAll(boostGateWayIds);
String gatewayIds =Optional.ofNullable(fanGateWayIds).orElse(new ArrayList<>()).stream().distinct().collect(Collectors.joining(","));
List<String> time = new ArrayList<>();
Map<String, Object> activePowerInfo = new HashMap<>();
List<IndicatorData> activePowerList = new ArrayList<>();
activePowerList = indicatorDataNewMapper.selectDataByequipmentIndexNameAndtimeqgNew(CommonConstans.ACTIVE_POWER,gatewayIds);
Map<String,List<IndicatorData>> stringObjectMap =activePowerList.stream().collect(Collectors.groupingBy(IndicatorData::getDasTime));
stringObjectMap.keySet().stream().forEach(dasTime -> {
time.add(dasTime.split(":")[1]);
Double vl= stringObjectMap.get(dasTime).stream().mapToDouble(IndicatorData::getValueF).sum();
values.add(String.format(CommonConstans.Twodecimalplaces, vl));
});
String max = String.format(CommonConstans.Twodecimalplaces, values.stream().mapToDouble(Double::parseDouble).max().getAsDouble());
String min = String.format(CommonConstans.Twodecimalplaces, values.stream().mapToDouble(Double::parseDouble).min().getAsDouble());
String mean = String.format(CommonConstans.Twodecimalplaces, values.stream().mapToDouble(Double::parseDouble).average().getAsDouble());
activePowerInfo.put("mean", mean);
activePowerInfo.put("max", max);
activePowerInfo.put("min", min);
activePowerInfo.put("maxTime", time.get(values.lastIndexOf(max)));
activePowerInfo.put("minTime", time.get(values.lastIndexOf(min)));
activePowerInfo.put("load", String.format(CommonConstans.Twodecimalplaces, Double.valueOf(values.get(values.size() - 1)) / installedCapacity.get()));
List<Map<String, Object>> seriesData = new ArrayList<>();
Map<String, Object> map3 = new HashMap<>();
Map<String, Object> map1 = new HashMap<>();
Map<String, Object> map2 = new HashMap<>();
map1.put("data", values);
seriesData.add(map1);
map.put("seriesData", seriesData);
map.put("axisData", time);
try {
emqKeeper.getMqttClient().publish( s+"_Power_table", JSON.toJSON(map).toString().getBytes("UTF-8"), 1, true);
emqKeeper.getMqttClient().publish(s+"_Power_info", JSON.toJSON(activePowerInfo).toString().getBytes("UTF-8"), 1, true);
} catch (Exception exception) {
exception.printStackTrace();
}
return map;
}
} }
package com.yeejoin.amos.boot.module.jxiop.biz.service.impl;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
public class Test {
public static class A{
String name1;
String name2;
public String getName1() {
return name1;
}
public void setName1(String name1) {
this.name1 = name1;
}
public String getName2() {
return name2;
}
public void setName2(String name2) {
this.name2 = name2;
}
public A() {
}
public A(String name1, String name2) {
this.name1 = name1;
this.name2 = name2;
}
}
public static void main(String[] args) {
List<A> list = new ArrayList<>();
list.add(new A("1","2"));
list.add(new A("3",null));
list.add(new A(null,"4"));
list.add(new A());
String names = list.stream().map(a ->{
if(a.getName1()!=null&&a.getName2()!=null){
return a.getName1()+","+a.getName2();
}
if(a.getName1()!=null){
return a.getName1();
}
if(a.getName2()!=null){
return a.getName2();
}
return "";
}).collect(Collectors.joining(","));
names.replace("null","");
// System.out.printf(names);
}
}
package com.yeejoin.amos.boot.module.jxiop.biz.tdanalysismapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yeejoin.amos.boot.module.jxiop.biz.entity.IndicatorData;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface IndicatorDataNewMapper extends BaseMapper<IndicatorData> {
@Select("select LAST(address)address,LAST(gateway_id)gatewayId,LAST(data_type)dataType,LAST(equipment_index_name)equipmentIndexName,LAST(`value_f`)valueF,LAST(equipment_number)equipmentNumber,LAST(created_time)createdTime from iot_data.indicator_data where equipment_index_name =#{equipmentIndexName} and gateway_id =#{gatewayId} and ts >=#{startTime} and ts <=#{endTime} group by address ")
List<IndicatorData> selectlastfd(@Param("equipmentIndexName") String equipmentIndexName,@Param("gatewayId") String gatewayId,@Param("startTime") String startTime, @Param("endTime") String endTime);
@Select("select LAST(address)address,LAST(gateway_id)gatewayId,LAST(data_type)dataType,LAST(equipment_index_name)equipmentIndexName,LAST(`value_f`)valueF,LAST(equipment_number)equipmentNumber,LAST(created_time)createdTime from iot_data.indicator_data where equipment_index_name =#{equipmentIndexName} and gateway_id =#{gatewayId} and ts >=#{startTime} and ts <=#{endTime} group by address ")
List<IndicatorData> selectlastgf(@Param("equipmentIndexName") String equipmentIndexName,@Param("gatewayId") String gatewayId,@Param("startTime") String startTime, @Param("endTime") String endTime);
@Select("select created_time createdTime, `value_f` as valueF from iot_data.indicator_data where equipment_index_name =#{equipmentIndexName} and ts >= #{startTime} and ts <= #{endTime} and gateway_id =#{gatewayId}")
List<IndicatorData> selectDataByequipmentIndexNameAndtime(@Param("equipmentIndexName") String equipmentIndexName, @Param("startTime") String startTime, @Param("endTime") String endTime, @Param("gatewayId") String gatewayId);
@Select("select sum(valueFs) valueF,xtime from (select SUBSTR(`created_time`, 11,6) xtime, `value_f` as valueFs from iot_data.indicator_data where equipment_index_name =#{equipmentIndexName} and ts >= #{startTime} and ts <= #{endTime} and gateway_id in (#{gatewayId})) group by xtime order by xtime ")
List<IndicatorData> selectDataByequipmentIndexNameAndtimeqg(@Param("equipmentIndexName") String equipmentIndexName, @Param("startTime") String startTime, @Param("endTime") String endTime, @Param("gatewayId") String gatewayId);
@Select("select `value`, created_time, `value_f` as valueF from iot_data.indicator_data where point_name =#{pointName} and ts >= TODAY()-8h")
List<IndicatorData> selectDataByequipmentIndexNameAndtimeqgNew(@Param("equipmentIndexName") String pointName);
@Select("select `value`, created_time, `value_f` as valueF from iot_data.indicator_data where point_name =#{pointName} and ts >= TODAY()-8h and gateway_id in (#{gatewayId}))")
List<IndicatorData> selectDataByequipmentIndexNameAndtimeqgNew(@Param("equipmentIndexName") String pointName,@Param("gatewayId") String 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 >= #{startTime} and ts <= #{endTime} 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);
@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 >= #{startTime} and ts <= #{endTime} and gateway_id =#{gatewayId}")
List<IndicatorData> selectDataByequipmentIndexNameAndtimeAndEquipmentNumberPv(@Param("equipmentNumber") String equipmentNumber, @Param("startTime") String startTime, @Param("endTime") String endTime, @Param("gatewayId") String gatewayId);
}
...@@ -11,13 +11,16 @@ spring.db2.datasource.url=jdbc:mysql://139.9.173.44:3306/jxiop_sync_data?allowMu ...@@ -11,13 +11,16 @@ spring.db2.datasource.url=jdbc:mysql://139.9.173.44:3306/jxiop_sync_data?allowMu
spring.db2.datasource.username=root spring.db2.datasource.username=root
spring.db2.datasource.password=Yeejoin@2020 spring.db2.datasource.password=Yeejoin@2020
spring.db2.datasource.driver-class-name: com.mysql.cj.jdbc.Driver spring.db2.datasource.driver-class-name: com.mysql.cj.jdbc.Driver
##db3
spring.db3.datasource.url=jdbc:TAOS-RS://139.9.170.47:6041/iot_data?user=root&password=taosdata&timezone=GMT%2b8&allowMultiQueries=true spring.db3.datasource.url=jdbc:TAOS-RS://139.9.170.47:6041/iot_data?user=root&password=taosdata&timezone=GMT%2b8&allowMultiQueries=true
spring.db3.datasource.username=root spring.db3.datasource.username=root
spring.db3.datasource.password=taosdata spring.db3.datasource.password=taosdata
spring.db3.datasource.driver-class-name: com.taosdata.jdbc.rs.RestfulDriver spring.db3.datasource.driver-class-name: com.taosdata.jdbc.rs.RestfulDriver
##db4
spring.db4.datasource.url=jdbc:TAOS-RS://139.9.170.47:6041/iot_data?user=root&password=taosdata&timezone=GMT%2b8&allowMultiQueries=true
spring.db4.datasource.username=root
spring.db4.datasource.password=taosdata
spring.db4.datasource.driver-class-name: com.taosdata.jdbc.rs.RestfulDriver
## eureka properties: ## eureka properties:
eureka.instance.hostname=172.16.10.220 eureka.instance.hostname=172.16.10.220
......
...@@ -16,6 +16,7 @@ public class IndicatorData { ...@@ -16,6 +16,7 @@ public class IndicatorData {
private Date createdTime; private Date createdTime;
private String gatewayId; private String gatewayId;
private String dataType; private String dataType;
private String dasTime;
private String pointSeq; private String pointSeq;
private String pointAddress; private String pointAddress;
private String pointLocation; private String pointLocation;
......
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