Commit 31f39145 authored by tangwei's avatar tangwei

增加接口

parent 7ba4a966
...@@ -18,7 +18,7 @@ import java.util.Date; ...@@ -18,7 +18,7 @@ import java.util.Date;
*/ */
@Data @Data
@Accessors(chain = true) @Accessors(chain = true)
@Document(indexName = "jxiop_dailyPowerGeneration") @Document(indexName = "jxiop_day")
public class ESDailyPowerGeneration { public class ESDailyPowerGeneration {
@Id @Id
...@@ -41,6 +41,9 @@ public class ESDailyPowerGeneration { ...@@ -41,6 +41,9 @@ public class ESDailyPowerGeneration {
@Field(type = FieldType.Keyword ) @Field(type = FieldType.Keyword )
private String day;//时间标识 private String day;//时间标识
@Field(type = FieldType.Keyword )
private String moon;//月份标识
@Field(type = FieldType.Keyword) @Field(type = FieldType.Keyword)
private String gatewayId; private String gatewayId;
...@@ -55,7 +58,7 @@ public class ESDailyPowerGeneration { ...@@ -55,7 +58,7 @@ public class ESDailyPowerGeneration {
@Field(type = FieldType.Text, index = false) @Field(type = FieldType.Text, index = false)
private String address; private String address;
public ESDailyPowerGeneration(String id, String stationId, String stationName, String stationType, String belongProvince, String belongArea, String day, String gatewayId, Date createdTime, Double value, String equipmentIndexName, String equipmentNumber, String address) { public ESDailyPowerGeneration(String id, String stationId, String stationName, String stationType, String belongProvince, String belongArea, String day, String gatewayId, Date createdTime, Double value, String equipmentIndexName, String equipmentNumber, String address,String moon) {
this.id = id; this.id = id;
this.stationId = stationId; this.stationId = stationId;
this.stationName = stationName; this.stationName = stationName;
...@@ -69,6 +72,7 @@ public class ESDailyPowerGeneration { ...@@ -69,6 +72,7 @@ public class ESDailyPowerGeneration {
this.equipmentIndexName = equipmentIndexName; this.equipmentIndexName = equipmentIndexName;
this.equipmentNumber = equipmentNumber; this.equipmentNumber = equipmentNumber;
this.address = address; this.address = address;
this.moon=moon;
} }
public ESDailyPowerGeneration() { public ESDailyPowerGeneration() {
......
...@@ -17,7 +17,7 @@ import java.util.Date; ...@@ -17,7 +17,7 @@ import java.util.Date;
*/ */
@Data @Data
@Accessors(chain = true) @Accessors(chain = true)
@Document(indexName = "jxiop_moonPowerGeneration") @Document(indexName = "jxiop_moon")
public class ESMoonPowerGeneration { public class ESMoonPowerGeneration {
...@@ -42,6 +42,9 @@ public class ESMoonPowerGeneration { ...@@ -42,6 +42,9 @@ public class ESMoonPowerGeneration {
@Field(type = FieldType.Keyword ) @Field(type = FieldType.Keyword )
private String day;//时间标识 private String day;//时间标识
@Field(type = FieldType.Keyword )
private String year;//年份标识
@Field(type = FieldType.Keyword) @Field(type = FieldType.Keyword)
private String gatewayId; private String gatewayId;
@Field(type = FieldType.Date, format = DateFormat.basic_date_time, index = false) @Field(type = FieldType.Date, format = DateFormat.basic_date_time, index = false)
...@@ -55,7 +58,7 @@ public class ESMoonPowerGeneration { ...@@ -55,7 +58,7 @@ public class ESMoonPowerGeneration {
@Field(type = FieldType.Text, index = false) @Field(type = FieldType.Text, index = false)
private String address; private String address;
public ESMoonPowerGeneration(String id, String stationId, String stationName, String stationType, String belongProvince, String belongArea, String day, String gatewayId, Date createdTime, Double value, String equipmentIndexName, String equipmentNumber, String address) { public ESMoonPowerGeneration(String id, String stationId, String stationName, String stationType, String belongProvince, String belongArea, String day, String gatewayId, Date createdTime, Double value, String equipmentIndexName, String equipmentNumber, String address,String year) {
this.id = id; this.id = id;
this.stationId = stationId; this.stationId = stationId;
this.stationName = stationName; this.stationName = stationName;
...@@ -69,6 +72,7 @@ public class ESMoonPowerGeneration { ...@@ -69,6 +72,7 @@ public class ESMoonPowerGeneration {
this.equipmentIndexName = equipmentIndexName; this.equipmentIndexName = equipmentIndexName;
this.equipmentNumber = equipmentNumber; this.equipmentNumber = equipmentNumber;
this.address = address; this.address = address;
this.year=year;
} }
public ESMoonPowerGeneration() { public ESMoonPowerGeneration() {
......
...@@ -18,7 +18,7 @@ import java.util.Date; ...@@ -18,7 +18,7 @@ import java.util.Date;
@Data @Data
@Accessors(chain = true) @Accessors(chain = true)
@Document(indexName = "jxiop_yearPowerGeneration") @Document(indexName = "jxiop_year")
public class ESYearPowerGeneration { public class ESYearPowerGeneration {
@Id @Id
private String id; private String id;
......
...@@ -10,20 +10,22 @@ import com.yeejoin.amos.boot.module.jxiop.api.entity.MonitorFanIndicator; ...@@ -10,20 +10,22 @@ import com.yeejoin.amos.boot.module.jxiop.api.entity.MonitorFanIndicator;
import com.yeejoin.amos.boot.module.jxiop.api.entity.StationBasic; import com.yeejoin.amos.boot.module.jxiop.api.entity.StationBasic;
import com.yeejoin.amos.boot.module.jxiop.api.mapper.MonitorFanIndicatorMapper; import com.yeejoin.amos.boot.module.jxiop.api.mapper.MonitorFanIndicatorMapper;
import com.yeejoin.amos.boot.module.jxiop.api.mapper.StationBasicMapper; import com.yeejoin.amos.boot.module.jxiop.api.mapper.StationBasicMapper;
import com.yeejoin.amos.boot.module.jxiop.biz.ESDto.ESDailyPowerGeneration;
import com.yeejoin.amos.boot.module.jxiop.biz.ESDto.ESEquipments; import com.yeejoin.amos.boot.module.jxiop.biz.ESDto.ESEquipments;
import com.yeejoin.amos.boot.module.jxiop.biz.ESDto.ESMoonPowerGeneration;
import com.yeejoin.amos.boot.module.jxiop.biz.ESDto.ESYearPowerGeneration;
import com.yeejoin.amos.boot.module.jxiop.biz.dto.IndicatorsDto; import com.yeejoin.amos.boot.module.jxiop.biz.dto.IndicatorsDto;
import com.yeejoin.amos.boot.module.jxiop.biz.dto.QueryDto; import com.yeejoin.amos.boot.module.jxiop.biz.dto.QueryDto;
import com.yeejoin.amos.boot.module.jxiop.biz.dto.StationCacheInfoDto; import com.yeejoin.amos.boot.module.jxiop.biz.dto.StationCacheInfoDto;
import com.yeejoin.amos.boot.module.jxiop.biz.entity.Test; import com.yeejoin.amos.boot.module.jxiop.biz.entity.Test;
import com.yeejoin.amos.boot.module.jxiop.biz.repository.ESEquipmentsRepository; import com.yeejoin.amos.boot.module.jxiop.biz.repository.ESEquipmentsRepository;
import com.yeejoin.amos.boot.module.jxiop.biz.service.impl.CommonServiceImpl; import com.yeejoin.amos.boot.module.jxiop.biz.service.impl.*;
import com.yeejoin.amos.boot.module.jxiop.biz.service.impl.StationBasicServiceImpl;
import com.yeejoin.amos.boot.module.jxiop.biz.service.impl.TestServiceImpl;
import com.yeejoin.amos.boot.module.jxiop.biz.utils.InfluxDButils; import com.yeejoin.amos.boot.module.jxiop.biz.utils.InfluxDButils;
import com.yeejoin.amos.component.influxdb.InfluxDbConnection; import com.yeejoin.amos.component.influxdb.InfluxDbConnection;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang.StringUtils;
import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.client.RequestOptions; import org.elasticsearch.client.RequestOptions;
...@@ -44,6 +46,7 @@ import org.elasticsearch.search.aggregations.metrics.ParsedAvg; ...@@ -44,6 +46,7 @@ import org.elasticsearch.search.aggregations.metrics.ParsedAvg;
import org.elasticsearch.search.aggregations.metrics.ParsedSum; import org.elasticsearch.search.aggregations.metrics.ParsedSum;
import org.elasticsearch.search.aggregations.metrics.SumAggregationBuilder; import org.elasticsearch.search.aggregations.metrics.SumAggregationBuilder;
import org.elasticsearch.search.builder.SearchSourceBuilder; import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.search.sort.MinAndMax;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -65,6 +68,7 @@ import java.text.DecimalFormat; ...@@ -65,6 +68,7 @@ import java.text.DecimalFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
@RestController @RestController
...@@ -94,14 +98,28 @@ public class DemoController extends BaseController { ...@@ -94,14 +98,28 @@ public class DemoController extends BaseController {
@Autowired @Autowired
ESEquipmentsRepository equipmentsRepository; ESEquipmentsRepository equipmentsRepository;
@Autowired @Autowired
CommonServiceImpl commonServiceImpl; CommonServiceImpl commonServiceImpl; @Autowired
PowerGenerationImpl powerGenerationImpl;
@Autowired
LargeScreenImpl largeScreenImpl;
private final String ss= "瞬时风速"; private final String ss= "瞬时风速";
private final String zfs= "WTX-801_25_WTX-801_总辐射"; private final String zfs= "WTX-801_25_WTX-801_总辐射";
private final String zfslj= "WTX-801_25_WTX-801_总辐射累计"; private final String zfslj= "WTX-801_25_WTX-801_总辐射累计";
private final String dayvalue="日发电量";
private final String moonValue="月发电量";
private final String yearValue="年发电量";
private final String dayDateFormat="yyyy-MM-dd";
private final String moonDateFormat="yyyy-MM";
private final String yearDateFormat="yyyy";
private final String dayType="day";
private final String moonType="moon";
private final String yearType="year";
...@@ -480,10 +498,135 @@ public class DemoController extends BaseController { ...@@ -480,10 +498,135 @@ public class DemoController extends BaseController {
} }
return mapdta; return mapdta;
} }
@TycloudOperation(needAuth = false, ApiLevel = UserType.AGENCY)
@ApiOperation(value = "分组求和数")
@GetMapping("/test15")
public Map test15() {
Map<String,Double> map= largeScreenImpl.getqg();
return map;
}
@TycloudOperation(needAuth = false, ApiLevel = UserType.AGENCY)
@ApiOperation(value = "分组求和数")
@GetMapping("/test16")
public Map test16() {
//获取每个区域下所有风机网管
List<StationCacheInfoDto> listk =commonServiceImpl.getListStationCacheInfoDto();
Map<String, List<StationCacheInfoDto>> map = listk.stream().filter(v -> StringUtils.isNotEmpty(v.getBelongArea())).collect(Collectors.groupingBy(StationCacheInfoDto :: getBelongArea));
Map<String,Double> maps=null;
for(String key:map.keySet()){
List<String> value1=new ArrayList<>();
List<StationCacheInfoDto> list= map.get(key);
for (StationCacheInfoDto stationCacheInfoDto : list) {
value1.add(stationCacheInfoDto.getBoosterGatewayId());
value1.add(stationCacheInfoDto.getFanGatewayId());
}
maps= largeScreenImpl.getqy(value1);
break;
}
return maps;
}
@TycloudOperation(needAuth = false, ApiLevel = UserType.AGENCY)
@ApiOperation(value = "初始化升压站")
@GetMapping("/test17")
public ResponseModel<Integer> demoTest17() {
//数据说明 夏造风电、泰和光伏、夏造升压站、泰和升压站
String [] strings = {"1668801435891929089","1669524885619085313"};
// String [] strings = {"1669525017559306241"};
// Object o=this.monitorFanIndicatorImpl.getIndicatoralueAvage("1668801435891929089","60秒平均风速");
// System.out.println(o.toString());
int num=0;
for (int i = 0; i < strings.length; i++) {
QueryWrapper<MonitorFanIndicator> QueryWrapper = new QueryWrapper<>();
// 夏造风电
// QueryWrapper.eq("gateway", "1668801435891929089");
// 泰和光伏
QueryWrapper.eq("gateway", strings[i]);
long DATE = new Date().getTime();
System.out.println(DATE);
List<MonitorFanIndicator> list = monitorFanIndicatorregionMapper.selectList(QueryWrapper);
num=num+list.size();
List<ESEquipments> listit =new ArrayList<>();
for (MonitorFanIndicator monitorFanIndicator : list) {
Map<String, String> tag = new HashMap<>();
Map<String, Object> maps2 = new HashMap<>();
tag.put("address", monitorFanIndicator.getIndexAddress());
maps2.put("dataType", monitorFanIndicator.getDataType());
maps2.put("equipmentSpecificName", monitorFanIndicator.getFanCode());
tag.put("equipmentsIdx", monitorFanIndicator.getAddressGateway());
tag.put("gatewayId", monitorFanIndicator.getGateway());
maps2.put("isAlarm", monitorFanIndicator.getIsAlarm());
maps2.put("createdTime", "2023-07-05 18:30:26");
maps2.put("unit", monitorFanIndicator.getUnit());
maps2.put("value", "4");
maps2.put("traceId", "");
maps2.put("equipmentIndexName", monitorFanIndicator.getIndicator());
maps2.put("equipmentNumber", monitorFanIndicator.getEquipmentNumber());
maps2.put("frontModule", monitorFanIndicator.getFrontModule());
maps2.put("systemType", monitorFanIndicator.getSystemType());
maps2.put("pictureName", monitorFanIndicator.getPictureName());
//升压站的字段显示名称
maps2.put("displayName", monitorFanIndicator.getEquipmentNumber());
influxDbConnection.insert("test_" + monitorFanIndicator.getGateway(), tag, maps2);
}
}
return ResponseHelper.buildResponse(num);
}
@TycloudOperation(needAuth = false, ApiLevel = UserType.AGENCY)
@ApiOperation(value = "分组求和数")
@GetMapping("/test18")
public Map test18() {
List<StationCacheInfoDto> list = commonServiceImpl.getListStationCacheInfoDto();
//获取时间天字符串
String datyvalue= "2023-08-11";
elasticsearchTemplate.deleteIndex(ESDailyPowerGeneration.class);
elasticsearchTemplate.deleteIndex(ESMoonPowerGeneration.class);
elasticsearchTemplate.deleteIndex(ESYearPowerGeneration.class);
for (StationCacheInfoDto stationCacheInfoDto : list) {
if("FDZ".equals(stationCacheInfoDto.getStationType())){
//风机
powerGenerationImpl.addPowerGeneration( stationCacheInfoDto, stationCacheInfoDto.getFanGatewayId(), dayvalue, dayDateFormat, dayType,"FDZ",datyvalue);
powerGenerationImpl.addPowerGeneration( stationCacheInfoDto, stationCacheInfoDto.getFanGatewayId(), moonValue, moonDateFormat, moonType,"FDZ",datyvalue);
powerGenerationImpl.addPowerGeneration( stationCacheInfoDto, stationCacheInfoDto.getFanGatewayId(), yearValue, yearDateFormat, yearType,"FDZ",datyvalue);
}else{
//光伏
powerGenerationImpl.addPowerGeneration( stationCacheInfoDto, stationCacheInfoDto.getFanGatewayId(), dayvalue, dayDateFormat, dayType,"GFDZ",datyvalue);
powerGenerationImpl.addPowerGeneration( stationCacheInfoDto, stationCacheInfoDto.getFanGatewayId(), moonValue, moonDateFormat, moonType,"GFDZ",datyvalue);
powerGenerationImpl.addPowerGeneration( stationCacheInfoDto, stationCacheInfoDto.getFanGatewayId(), yearValue, yearDateFormat, yearType,"GFDZ",datyvalue);
}
}
return null;
}
} }
...@@ -2,6 +2,9 @@ package com.yeejoin.amos.boot.module.jxiop.biz.dto; ...@@ -2,6 +2,9 @@ package com.yeejoin.amos.boot.module.jxiop.biz.dto;
import lombok.Data; import lombok.Data;
import java.text.SimpleDateFormat;
import java.util.Date;
/** /**
* @description: * @description:
* @author: tw * @author: tw
...@@ -25,4 +28,5 @@ public class ColModel { ...@@ -25,4 +28,5 @@ public class ColModel {
this.type = type; this.type = type;
this.key = key; this.key = key;
} }
} }
package com.yeejoin.amos.boot.module.jxiop.biz.dto;
import lombok.Data;
/**
* @description:
* @author: tw
* @createDate: 2023/8/11
*/
@Data
public class TimeDate {
private String key;
private double value;
}
...@@ -10,7 +10,9 @@ import org.springframework.scheduling.annotation.EnableScheduling; ...@@ -10,7 +10,9 @@ import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import java.util.List; import java.util.List;
/** /**
...@@ -32,48 +34,86 @@ public class PowerGeneration { ...@@ -32,48 +34,86 @@ public class PowerGeneration {
private final String moonValue="月发电量"; private final String moonValue="月发电量";
private final String yearValue="年发电量"; private final String yearValue="年发电量";
private final String dayDateFormat="YYYY-MM-DD"; private final String dayDateFormat="yyyy-MM-dd";
private final String moonDateFormat="YYYY-MM"; private final String moonDateFormat="yyyy-MM";
private final String yearDateFormat="YYYY"; private final String yearDateFormat="yyyy";
private final String dayType="day"; private final String dayType="day";
private final String moonType="moon"; private final String moonType="moon";
private final String yearType="year"; private final String yearType="year";
//定时更新日发电量 //定时更新日发电量
// @Scheduled(cron = "${daily.power.generation.cron}") @Scheduled(cron = "${daily.power.generation.cron}")
public void addESDailyPowerGeneration(){ public void addESDailyPowerGeneration(){
List<StationCacheInfoDto> list =commonServiceImpl.getListStationCacheInfoDto(); List<StationCacheInfoDto> list =commonServiceImpl.getListStationCacheInfoDto();
//获取时间天字符串
SimpleDateFormat myFmt2=new SimpleDateFormat("yyyy-MM-dd");
Date now=new Date();
String daty= myFmt2.format(now);
for (StationCacheInfoDto stationCacheInfoDto : list) { for (StationCacheInfoDto stationCacheInfoDto : list) {
//风机
powerGenerationImpl.addPowerGeneration( stationCacheInfoDto, stationCacheInfoDto.getFanGatewayId(), dayvalue, dayDateFormat, dayType); if("FDZ".equals(stationCacheInfoDto.getStationType())){
//光伏
powerGenerationImpl.addPowerGeneration( stationCacheInfoDto, stationCacheInfoDto.getBoosterGatewayId(), dayvalue, dayDateFormat, dayType); //风机
powerGenerationImpl.addPowerGeneration( stationCacheInfoDto, stationCacheInfoDto.getFanGatewayId(), dayvalue, dayDateFormat, dayType,"FDZ",daty);
}else{
//光伏
powerGenerationImpl.addPowerGeneration( stationCacheInfoDto, stationCacheInfoDto.getFanGatewayId(), dayvalue, dayDateFormat, dayType,"GFDZ",daty);
}
} }
} }
//定时更新月发电量 //定时更新月发电量
// @Scheduled(cron = "${moon.power.generation.cron}") @Scheduled(cron = "${moon.power.generation.cron}")
public void addESMoonPowerGeneration(){ public void addESMoonPowerGeneration(){
List<StationCacheInfoDto> list =commonServiceImpl.getListStationCacheInfoDto(); List<StationCacheInfoDto> list =commonServiceImpl.getListStationCacheInfoDto();
//获取时间天字符串
SimpleDateFormat myFmt2=new SimpleDateFormat("yyyy-MM-dd");
Date now=new Date();
String daty= myFmt2.format(now);
for (StationCacheInfoDto stationCacheInfoDto : list) { for (StationCacheInfoDto stationCacheInfoDto : list) {
//风机 //风机
powerGenerationImpl.addPowerGeneration( stationCacheInfoDto, stationCacheInfoDto.getFanGatewayId(), moonValue, moonDateFormat, moonType); if("FDZ".equals(stationCacheInfoDto.getStationType())){
//光伏
powerGenerationImpl.addPowerGeneration( stationCacheInfoDto, stationCacheInfoDto.getBoosterGatewayId(), moonValue, moonDateFormat, moonType); //风机
powerGenerationImpl.addPowerGeneration( stationCacheInfoDto, stationCacheInfoDto.getFanGatewayId(), moonValue, moonDateFormat, moonType,"FDZ",daty);
}else{
//光伏
powerGenerationImpl.addPowerGeneration( stationCacheInfoDto, stationCacheInfoDto.getFanGatewayId(), moonValue, moonDateFormat, moonType,"GFDZ",daty);
}
} }
} }
//定时更新年发电量 //定时更新年发电量
//@Scheduled(cron = "${year.power.generation.cron}") @Scheduled(cron = "${year.power.generation.cron}")
public void addESYearPowerGeneration(){ public void addESYearPowerGeneration(){
List<StationCacheInfoDto> list =commonServiceImpl.getListStationCacheInfoDto(); List<StationCacheInfoDto> list =commonServiceImpl.getListStationCacheInfoDto();
//获取时间天字符串
SimpleDateFormat myFmt2=new SimpleDateFormat("yyyy-MM-dd");
Date now=new Date();
String daty= myFmt2.format(now);
for (StationCacheInfoDto stationCacheInfoDto : list) { for (StationCacheInfoDto stationCacheInfoDto : list) {
//风机 //风机
powerGenerationImpl.addPowerGeneration( stationCacheInfoDto, stationCacheInfoDto.getFanGatewayId(), yearValue, yearDateFormat, yearType); if("FDZ".equals(stationCacheInfoDto.getStationType())){
//光伏
powerGenerationImpl.addPowerGeneration( stationCacheInfoDto, stationCacheInfoDto.getBoosterGatewayId(), yearValue, yearDateFormat, yearType); //风机
powerGenerationImpl.addPowerGeneration( stationCacheInfoDto, stationCacheInfoDto.getFanGatewayId(), yearValue, yearDateFormat, yearType,"FDZ",daty);
}else{
//光伏
powerGenerationImpl.addPowerGeneration( stationCacheInfoDto, stationCacheInfoDto.getFanGatewayId(), yearValue, yearDateFormat, yearType,"GFDZ",daty);
}
} }
} }
......
package com.yeejoin.amos.boot.module.jxiop.biz.service.impl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Map;
/**
* @description:
* @author: tw
* @createDate: 2023/8/10
*/
@Service
public class IargeScreenImpl {
// @Autowired
// CommonServiceImpl commonServiceImpl;
//
// private final String ss= "瞬时风速";
// private final String zfs= "WTX-801_25_WTX-801_总辐射";
// private final String zfslj= "WTX-801_25_WTX-801_总辐射累计";
//
// private final String ss= "瞬时风速";
// private final String zfs= "WTX-801_25_WTX-801_总辐射";
// private final String zfslj= "WTX-801_25_WTX-801_总辐射累计";
//
//
//
// /**
// *
// * 全国
// *
// * */
// public Map<String,Object> getqg(){
//
//
//
//
//
//
// }
//
//
//
//
// /**
// *
// * 区域
// *
// * **/
//
// public Map<String,Object> getqy(){
//
//
// }
}
package com.yeejoin.amos.boot.module.jxiop.biz.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yeejoin.amos.boot.module.jxiop.api.entity.StationPlan;
import com.yeejoin.amos.boot.module.jxiop.api.mapper.StationPlanMapper;
import com.yeejoin.amos.boot.module.jxiop.biz.ESDto.ESEquipments;
import com.yeejoin.amos.boot.module.jxiop.biz.dto.TimeDate;
import org.elasticsearch.search.aggregations.Aggregation;
import org.elasticsearch.search.aggregations.Aggregations;
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
import org.elasticsearch.search.aggregations.metrics.ParsedAvg;
import org.elasticsearch.search.aggregations.metrics.ParsedSum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.time.LocalDate;
import java.util.*;
/**
* @description:
* @author: tw
* @createDate: 2023/8/10
*/
@Service
public class LargeScreenImpl {
@Autowired
CommonServiceImpl commonServiceImpl;
@Autowired
StationPlanMapper StationPlanMapper;
private final String SS = "瞬时风速";
private final String ZFS = "WTX-801_25_WTX-801_总辐射";
private final String ZFSLJ = "WTX-801_25_WTX-801_总辐射累计";
private final String RSD = "日发电量";
private final String YFD = "月发电量";
private final String NFD = "年发电量";
/**
* 全国
*/
public Map<String, Double> getqg() {
Map<String, Double> mapdta = new HashMap<>();
mapdta.put("SS", 0.0);
mapdta.put("ZFS", 0.0);
mapdta.put("ZFSLJ", 0.0);
mapdta.put("RSD", 0.0);
mapdta.put("YFD", 0.0);
mapdta.put("NFD", 0.0);
mapdta.put("YJHWC", 0.0);
mapdta.put("NJHWC", 0.0);
//平均数
List<String> value = new ArrayList<>();
value.add(SS);
value.add(ZFS);
value.add(ZFSLJ);
Map<String, List<String>> map = new HashMap<>();
map.put("equipmentIndexName.keyword", value);
List<? extends Terms.Bucket> lidate = commonServiceImpl.getgroupavg(map, "valueDouble", "equipmentIndexName.keyword", ESEquipments.class);
DecimalFormat format2 = new DecimalFormat("#.0000");
for (Terms.Bucket bucket : lidate) {
Aggregations aggregation = bucket.getAggregations();
List<Aggregation> listdata = Objects.nonNull(aggregation) ? aggregation.asList() : null;
for (Aggregation agg : listdata) {
ParsedAvg parsedAvg = (ParsedAvg) agg;
switch (bucket.getKeyAsString()) {
case SS:
mapdta.put("SS", Double.valueOf(format2.format(parsedAvg.getValue())));
break;
case ZFS:
mapdta.put("ZFS", Double.valueOf(format2.format(parsedAvg.getValue())));
break;
case ZFSLJ:
mapdta.put("ZFSLJ", Double.valueOf(format2.format(parsedAvg.getValue())));
break;
default:
break;
}
}
}
//总和
value.clear();
value.add(RSD);
value.add(YFD);
value.add(NFD);
List<? extends Terms.Bucket> lidatesum = commonServiceImpl.getgroupsum(map, "valueDouble", "equipmentIndexName.keyword", ESEquipments.class);
for (Terms.Bucket bucket : lidatesum) {
Aggregations aggregation = bucket.getAggregations();
List<Aggregation> listdata = Objects.nonNull(aggregation) ? aggregation.asList() : null;
for (Aggregation agg : listdata) {
ParsedSum parsedSum = (ParsedSum) agg;
switch (bucket.getKeyAsString()) {
case RSD:
mapdta.put("RSD", Double.valueOf(format2.format(parsedSum.getValue())));
break;
case YFD:
mapdta.put("YFD", Double.valueOf(format2.format(parsedSum.getValue())));
break;
case NFD:
mapdta.put("NFD", Double.valueOf(format2.format(parsedSum.getValue())));
break;
default:
break;
}
}
}
//计算月完成百分比
//当前月份 获取
LocalDate currentDate = LocalDate.now();
int month = currentDate.getMonthValue();
QueryWrapper<StationPlan> wrapper = new QueryWrapper<>();
wrapper.select("sum(value) as sum_value");
wrapper.eq("monthly", month);
List<Map<String, Object>> list = StationPlanMapper.selectMaps(wrapper);
Double sumValue = list != null && !list.isEmpty() ? (Double) list.get(0).get("sum_value") : 0;
//计算年完成百分比
Double ybfb = sumValue > 0 ? mapdta.get("YFD") / sumValue * 100 : 0;
ybfb = new BigDecimal(ybfb).setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue();
mapdta.put("YJHWC", ybfb);
QueryWrapper<StationPlan> wrapper1 = new QueryWrapper<>();
wrapper1.select("sum(value) as sum_value");
List<Map<String, Object>> list1 = StationPlanMapper.selectMaps(wrapper);
Double sumValuen = list1 != null && !list1.isEmpty() ? (Double) list1.get(0).get("sum_value") : 0;
Double ybfbn = sumValuen > 0 ? mapdta.get("NFD") / sumValue * 100 : 0;
ybfbn = new BigDecimal(ybfbn).setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue();
mapdta.put("NJHWC", ybfbn);
return mapdta;
}
/**
* 区域
**/
public Map<String, Double> getqy(List<String> gatewayId) {
Map<String, Double> mapdta = new HashMap<>();
mapdta.put("SS", 0.0);
mapdta.put("ZFS", 0.0);
mapdta.put("ZFSLJ", 0.0);
mapdta.put("RSD", 0.0);
mapdta.put("YFD", 0.0);
mapdta.put("NFD", 0.0);
mapdta.put("YJHWC", 0.0);
mapdta.put("NJHWC", 0.0);
//平均数
List<String> value = new ArrayList<>();
value.add(SS);
value.add(ZFS);
value.add(ZFSLJ);
Map<String, List<String>> map = new HashMap<>();
map.put("equipmentIndexName.keyword", value);
map.put("gatewayId.keyword", gatewayId);
List<? extends Terms.Bucket> lidate = commonServiceImpl.getgroupavg(map, "valueDouble", "equipmentIndexName.keyword", ESEquipments.class);
DecimalFormat format2 = new DecimalFormat("#.0000");
for (Terms.Bucket bucket : lidate) {
Aggregations aggregation = bucket.getAggregations();
List<Aggregation> listdata = Objects.nonNull(aggregation) ? aggregation.asList() : null;
for (Aggregation agg : listdata) {
ParsedAvg parsedAvg = (ParsedAvg) agg;
switch (bucket.getKeyAsString()) {
case SS:
mapdta.put("SS", Double.valueOf(format2.format(parsedAvg.getValue())));
break;
case ZFS:
mapdta.put("ZFS", Double.valueOf(format2.format(parsedAvg.getValue())));
break;
case ZFSLJ:
mapdta.put("ZFSLJ", Double.valueOf(format2.format(parsedAvg.getValue())));
break;
default:
break;
}
}
}
//总和
value.clear();
value.add(RSD);
value.add(YFD);
value.add(NFD);
List<? extends Terms.Bucket> lidatesum = commonServiceImpl.getgroupsum(map, "valueDouble", "equipmentIndexName.keyword", ESEquipments.class);
for (Terms.Bucket bucket : lidatesum) {
Aggregations aggregation = bucket.getAggregations();
List<Aggregation> listdata = Objects.nonNull(aggregation) ? aggregation.asList() : null;
for (Aggregation agg : listdata) {
ParsedSum parsedSum = (ParsedSum) agg;
switch (bucket.getKeyAsString()) {
case RSD:
mapdta.put("RSD", Double.valueOf(format2.format(parsedSum.getValue())));
break;
case YFD:
mapdta.put("YFD", Double.valueOf(format2.format(parsedSum.getValue())));
break;
case NFD:
mapdta.put("NFD", Double.valueOf(format2.format(parsedSum.getValue())));
break;
default:
break;
}
}
}
//计算月完成百分比
//当前月份 获取
LocalDate currentDate = LocalDate.now();
int month = currentDate.getMonthValue();
QueryWrapper<StationPlan> wrapper = new QueryWrapper<>();
wrapper.select("sum(value) as sum_value");
wrapper.eq("monthly", month);
List<Map<String, Object>> list = StationPlanMapper.selectMaps(wrapper);
Double sumValue = list != null && !list.isEmpty() ? (Double) list.get(0).get("sum_value") : 0;
//计算年完成百分比
Double ybfb = sumValue > 0 ? mapdta.get("YFD") / sumValue * 100 : 0;
ybfb = new BigDecimal(ybfb).setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue();
mapdta.put("YJHWC", ybfb);
QueryWrapper<StationPlan> wrapper1 = new QueryWrapper<>();
wrapper1.select("sum(value) as sum_value");
List<Map<String, Object>> list1 = StationPlanMapper.selectMaps(wrapper);
Double sumValuen = list1 != null && !list1.isEmpty() ? (Double) list1.get(0).get("sum_value") : 0;
Double ybfbn = sumValuen > 0 ? mapdta.get("NFD") / sumValue * 100 : 0;
ybfbn = new BigDecimal(ybfbn).setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue();
mapdta.put("NJHWC", ybfbn);
return mapdta;
}
//获取月日发电量
public List<TimeDate> gettimedate(){
return null;
}
}
\ No newline at end of file
...@@ -17,10 +17,7 @@ import org.springframework.scheduling.annotation.Async; ...@@ -17,10 +17,7 @@ import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.*;
import java.util.Date;
import java.util.List;
import java.util.Optional;
/** /**
* @description: * @description:
...@@ -43,24 +40,36 @@ public class PowerGenerationImpl { ...@@ -43,24 +40,36 @@ public class PowerGenerationImpl {
//获取指定指标,当天最后一条数据 //获取指定指标,当天最后一条数据
public List<IndexDto> getlast(String gatewayId, String value){ public List<IndexDto> getlast(String gatewayId, String value,String daty){
IndexDto indexDto=null; IndexDto indexDto=null;
//获取时间天字符串
SimpleDateFormat myFmt2=new SimpleDateFormat("yyyy-MM-dd"); String querySql = " SELECT * FROM test_%s WHERE equipmentIndexName='%s' and time >='%sT00:55:00Z' AND time < '%sT23:59:59Z' group by equipmentsIdx order by time desc LIMIT 1";
Date now=new Date();
String daty= myFmt2.format(now);
String querySql = " SELECT * FROM iot_data_%s WHERE equipmentIndexName='%s' and time >='%sT23:55:00Z' AND time < '%sT23:59:59Z' group by address order by time desc LIMIT 1";
querySql = String.format(querySql, gatewayId, value,daty,daty); querySql = String.format(querySql, gatewayId, value,daty,daty);
List<IndexDto> queryList = influxDButils.getListData(querySql,IndexDto.class); List<IndexDto> queryList = influxDButils.getListData(querySql,IndexDto.class);
return queryList; return queryList;
} }
public List<IndexDto> getlastgf(String gatewayId, String value,String daty){
IndexDto indexDto=null;
String querySql = " SELECT * FROM test_%s WHERE equipmentIndexName='%s' and equipmentSpecificName =~/.*逆变器.*/ and time >='%sT00:55:00Z' AND time < '%sT23:59:59Z' group by equipmentsIdx order by time desc LIMIT 1";
querySql = String.format(querySql, gatewayId, value,daty,daty);
List<IndexDto> queryList = influxDButils.getListData(querySql,IndexDto.class);
return queryList;
}
//更新es 数据 //更新es 数据
@Async("jxiopAsyncExecutor") //@Async("jxiopAsyncExecutor")
public void addPowerGeneration(StationCacheInfoDto stationCacheInfoDto,String gatewayId, String value, String dateFormat, String type){ public void addPowerGeneration(StationCacheInfoDto stationCacheInfoDto,String gatewayId, String value, String dateFormat, String type, String stationType,String datyvalue){
//获取指标值 //获取指标值
List<IndexDto> indexDto= this.getlast(gatewayId,value); List<IndexDto> indexDto=null;
if("FDZ".equals(stationType)){
indexDto= this.getlast(gatewayId,value, datyvalue);
}else{
indexDto= this.getlastgf(gatewayId,value,datyvalue);
}
SimpleDateFormat myFmt2=new SimpleDateFormat(dateFormat); SimpleDateFormat myFmt2=new SimpleDateFormat(dateFormat);
Date now=new Date(); Date now=new Date();
String daty= myFmt2.format(now); String daty= myFmt2.format(now);
...@@ -70,19 +79,21 @@ public class PowerGenerationImpl { ...@@ -70,19 +79,21 @@ public class PowerGenerationImpl {
//更新es //更新es
public void PowerGeneration(StationCacheInfoDto stationCacheInfoDto,List<IndexDto> indexDto,String daty,String type){ public void PowerGeneration(StationCacheInfoDto stationCacheInfoDto,List<IndexDto> indexDto,String daty,String type){
Calendar calendar = Calendar.getInstance();
int day = calendar.get(Calendar.DATE);
int month = calendar.get(Calendar.MONTH) + 1;
int year = calendar.get(Calendar.YEAR);
switch (type) { switch (type) {
case "day": case "day":
List<ESDailyPowerGeneration> listd= this.getESDailyPowerGeneration(stationCacheInfoDto,indexDto,type); List<ESDailyPowerGeneration> listd= this.getESDailyPowerGeneration(stationCacheInfoDto,indexDto,daty,String.valueOf(day),String.valueOf(month));
dailyPowerGenerationRepository.saveAll(listd); dailyPowerGenerationRepository.saveAll(listd);
break; break;
case "moon": case "moon":
List<ESMoonPowerGeneration> listm= this.getESMoonPowerGeneration(stationCacheInfoDto,indexDto,type); List<ESMoonPowerGeneration> listm= this.getESMoonPowerGeneration(stationCacheInfoDto,indexDto,daty,String.valueOf(month),String.valueOf(year));
moonPowerGenerationRepository.saveAll(listm); moonPowerGenerationRepository.saveAll(listm);
break; break;
case "year": case "year":
List<ESYearPowerGeneration> listy= this.getESYearPowerGeneration(stationCacheInfoDto,indexDto,type); List<ESYearPowerGeneration> listy= this.getESYearPowerGeneration(stationCacheInfoDto,indexDto,daty,String.valueOf(year));
yearPowerGenerationRepository.saveAll(listy); yearPowerGenerationRepository.saveAll(listy);
break; break;
default: default:
...@@ -93,7 +104,7 @@ public class PowerGenerationImpl { ...@@ -93,7 +104,7 @@ public class PowerGenerationImpl {
// 组装数据 // 组装数据
public List<ESDailyPowerGeneration> getESDailyPowerGeneration(StationCacheInfoDto stationCacheInfoDto,List<IndexDto> indexDto,String daty){ public List<ESDailyPowerGeneration> getESDailyPowerGeneration(StationCacheInfoDto stationCacheInfoDto,List<IndexDto> indexDto,String daty,String day,String month){
List<ESDailyPowerGeneration> list=new ArrayList<>(); List<ESDailyPowerGeneration> list=new ArrayList<>();
if(indexDto!=null&&!indexDto.isEmpty()){ if(indexDto!=null&&!indexDto.isEmpty()){
...@@ -105,20 +116,21 @@ public class PowerGenerationImpl { ...@@ -105,20 +116,21 @@ public class PowerGenerationImpl {
stationCacheInfoDto.getStationType(), stationCacheInfoDto.getStationType(),
stationCacheInfoDto.getBelongProvince(), stationCacheInfoDto.getBelongProvince(),
stationCacheInfoDto.getBelongArea(), stationCacheInfoDto.getBelongArea(),
daty, day,
dto.getGatewayId(), dto.getGatewayId(),
new Date(), new Date(),
dto.getValue()!=null?Double.valueOf(dto.getValue()):null, dto.getValue()!=null?Double.valueOf(dto.getValue()):null,
dto.getEquipmentIndexName(), dto.getEquipmentIndexName(),
dto.getEquipmentNumber(), dto.getEquipmentNumber(),
dto.getAddress() dto.getAddress(),
month
); );
list.add(dailyPowerGeneration); list.add(dailyPowerGeneration);
} }
} }
return list; return list;
} }
public List<ESMoonPowerGeneration> getESMoonPowerGeneration(StationCacheInfoDto stationCacheInfoDto,List<IndexDto> indexDto,String daty){ public List<ESMoonPowerGeneration> getESMoonPowerGeneration(StationCacheInfoDto stationCacheInfoDto,List<IndexDto> indexDto,String daty,String day,String year){
List<ESMoonPowerGeneration> list=new ArrayList<>(); List<ESMoonPowerGeneration> list=new ArrayList<>();
if(indexDto!=null&&!indexDto.isEmpty()){ if(indexDto!=null&&!indexDto.isEmpty()){
for (IndexDto dto : indexDto) { for (IndexDto dto : indexDto) {
...@@ -129,20 +141,21 @@ public class PowerGenerationImpl { ...@@ -129,20 +141,21 @@ public class PowerGenerationImpl {
stationCacheInfoDto.getStationType(), stationCacheInfoDto.getStationType(),
stationCacheInfoDto.getBelongProvince(), stationCacheInfoDto.getBelongProvince(),
stationCacheInfoDto.getBelongArea(), stationCacheInfoDto.getBelongArea(),
daty, day,
dto.getGatewayId(), dto.getGatewayId(),
new Date(), new Date(),
dto.getValue()!=null?Double.valueOf(dto.getValue()):null, dto.getValue()!=null?Double.valueOf(dto.getValue()):null,
dto.getEquipmentIndexName(), dto.getEquipmentIndexName(),
dto.getEquipmentNumber(), dto.getEquipmentNumber(),
dto.getAddress() dto.getAddress(),
year
); );
list.add(moonPowerGeneration); list.add(moonPowerGeneration);
} }
} }
return list; return list;
} }
public List<ESYearPowerGeneration> getESYearPowerGeneration(StationCacheInfoDto stationCacheInfoDto,List<IndexDto> indexDto,String daty){ public List<ESYearPowerGeneration> getESYearPowerGeneration(StationCacheInfoDto stationCacheInfoDto,List<IndexDto> indexDto,String daty,String day){
List<ESYearPowerGeneration> list=new ArrayList<>(); List<ESYearPowerGeneration> list=new ArrayList<>();
if(indexDto!=null&&!indexDto.isEmpty()){ if(indexDto!=null&&!indexDto.isEmpty()){
for (IndexDto dto : indexDto) { for (IndexDto dto : indexDto) {
...@@ -153,7 +166,7 @@ public class PowerGenerationImpl { ...@@ -153,7 +166,7 @@ public class PowerGenerationImpl {
stationCacheInfoDto.getStationType(), stationCacheInfoDto.getStationType(),
stationCacheInfoDto.getBelongProvince(), stationCacheInfoDto.getBelongProvince(),
stationCacheInfoDto.getBelongArea(), stationCacheInfoDto.getBelongArea(),
daty, day,
dto.getGatewayId(), dto.getGatewayId(),
new Date(), new Date(),
dto.getValue()!=null?Double.valueOf(dto.getValue()):null, dto.getValue()!=null?Double.valueOf(dto.getValue()):null,
......
...@@ -24,6 +24,7 @@ public class InfluxDButils { ...@@ -24,6 +24,7 @@ public class InfluxDButils {
InfluxDbConnection influxDbConnection; InfluxDbConnection influxDbConnection;
@Autowired @Autowired
InfluxdbUtil influxdbUtil; InfluxdbUtil influxdbUtil;
public <T> List<T> getListData(String sql, Class<T> clazz) { public <T> List<T> getListData(String sql, Class<T> clazz) {
List<T> list = new ArrayList<>(); List<T> list = new ArrayList<>();
try { try {
...@@ -102,4 +103,52 @@ public class InfluxDButils { ...@@ -102,4 +103,52 @@ public class InfluxDButils {
} }
return list; return list;
} }
public <T> List<T> getListDataGroup(String sql, Class<T> clazz) {
List<T> list = new ArrayList<>();
try {
QueryResult query = influxDbConnection.query(sql);
List<QueryResult.Result> queryResults = query.getResults();
for (QueryResult.Result result : queryResults) {
List<QueryResult.Series> series = result.getSeries();
if (series == null) {
continue;
}
for (QueryResult.Series serie : series) {
List<List<Object>> values = serie.getValues();
List<String> columns = serie.getColumns();
for (int i = 0; i < values.size(); ++i) {
T object = clazz.newInstance();
BeanWrapperImpl bean = new BeanWrapperImpl(object);
for (int j = 0; j < columns.size(); ++j) {
String k = columns.get(j);
Object v = values.get(i).get(j);
if ("time".equals(k)) {
continue;
} else {
bean.setPropertyValue(k, v);
}
}
list.add(object);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return list;
}
} }
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