Commit 65648c59 authored by tangwei's avatar tangwei

增加大屏接口

parent dcad5e76
package com.yeejoin.amos.boot.module.jxiop.biz.dto;
import lombok.Data;
import java.util.List;
import java.util.Map;
/**
* @description:
* @author: tw
* @createDate: 2023/8/14
*/
@Data
public class SeriesData {
private List<Map<String,Object>> seriesData;
private List<String> axisData;
}
......@@ -4,7 +4,9 @@ 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.SeriesData;
import com.yeejoin.amos.boot.module.jxiop.biz.dto.TimeDate;
import com.yeejoin.amos.boot.module.jxiop.biz.utils.DateUtil;
import org.elasticsearch.search.aggregations.Aggregation;
import org.elasticsearch.search.aggregations.Aggregations;
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
......@@ -14,6 +16,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.*;
......@@ -42,14 +45,14 @@ public class LargeScreenImpl {
*/
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);
mapdta.put("SS", 0d);
mapdta.put("ZFS", 0d);
mapdta.put("ZFSLJ", 0d);
mapdta.put("RSD", 0d);
mapdta.put("YFD", 0d);
mapdta.put("NFD", 0d);
mapdta.put("YJHWC", 0d);
mapdta.put("NJHWC", 0d);
//平均数
List<String> value = new ArrayList<>();
value.add(SS);
......@@ -139,17 +142,16 @@ public class LargeScreenImpl {
/**
* 区域
**/
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);
mapdta.put("SS", 0d);
mapdta.put("ZFS", 0d);
mapdta.put("ZFSLJ", 0d);
mapdta.put("RSD", 0d);
mapdta.put("YFD", 0d);
mapdta.put("NFD", 0d);
mapdta.put("YJHWC", 0d);
mapdta.put("NJHWC", 0d);
//平均数
List<String> value = new ArrayList<>();
value.add(SS);
......@@ -236,20 +238,203 @@ public class LargeScreenImpl {
}
//获取月日发电量
public List<TimeDate> gettimedate(){
//全国发电趋势
public SeriesData getSeriesDataqg(){
//获取今年当月 日发电趋势
List<Double> listjn= gettimedate( new Date());
//获取去年当月 日发电趋势
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.YEAR, -1);
Date oneYearAgoToday = calendar.getTime();
List<Double> listqn= gettimedate( oneYearAgoToday);
Map<String,Object> mapjn=new HashMap<>();
mapjn.put("data",listjn);
mapjn.put("name","当前值");
Map<String,Object> mapqn=new HashMap<>();
mapjn.put("data",listqn);
mapjn.put("name","同期值");
List<Map<String,Object>> list=new ArrayList<>();
list.add(mapjn);
list.add(mapqn);
SeriesData seriesData=new SeriesData();
seriesData.setSeriesData(list);
//获取日期
List<String> listdate= dayReportnq(new Date());
seriesData.setAxisData(listdate);
return seriesData;
}
//区域发电趋势
public SeriesData getSeriesDataqy( Date date,List<String> gatewayId){
//获取今年当月 日发电趋势
List<Double> listjn= gettimedateqy( new Date(),gatewayId);
//获取去年当月 日发电趋势
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.YEAR, -1);
Date oneYearAgoToday = calendar.getTime();
List<Double> listqn= gettimedateqy( oneYearAgoToday,gatewayId);
Map<String,Object> mapjn=new HashMap<>();
mapjn.put("data",listjn);
mapjn.put("name","当前值");
Map<String,Object> mapqn=new HashMap<>();
mapjn.put("data",listqn);
mapjn.put("name","同期值");
List<Map<String,Object>> list=new ArrayList<>();
list.add(mapjn);
list.add(mapqn);
SeriesData seriesData=new SeriesData();
seriesData.setSeriesData(list);
//获取日期
List<String> listdate= dayReportnq(new Date());
seriesData.setAxisData(listdate);
return seriesData;
}
//获取全国月日发电量
public List<Double> gettimedate( Date date){
SimpleDateFormat myFmt2=new SimpleDateFormat("yyyyMM");
String monthy= myFmt2.format(date);
List<Double> listdate= new ArrayList<>();
List<String> value=new ArrayList<>();
value.add(RSD);
Map<String,List<String>> map=new HashMap<>();
map.put("equipmentIndexName.keyword",value);
List<String> value1=new ArrayList<>();
value1.add(monthy);
map.put("moon.keyword",value1);
List<? extends Terms.Bucket> lidate= commonServiceImpl.getgroupsum(map,"value" ,"day.keyword",ESEquipments.class);
Map<String,Double> mapdta=new HashMap<>();
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) {
ParsedSum parsedSum =(ParsedSum)agg;
mapdta.put(bucket.getKeyAsString(), Double.valueOf(format2.format(parsedSum.getValue())));
}
}
//组装数据
List<String> list= dayReport(date);
for (String s : list) {
if(mapdta!=null&&mapdta.containsKey(s)){
listdate.add(mapdta.get(s));
}else{
listdate.add(0d);
}
}
return listdate;
return null;
}
//获取区域月日发电量
public List<Double> gettimedateqy( Date date,List<String> gatewayId){
SimpleDateFormat myFmt2=new SimpleDateFormat("yyyyMM");
String monthy= myFmt2.format(date);
List<Double> listdate= new ArrayList<>();
List<String> value=new ArrayList<>();
value.add(RSD);
Map<String,List<String>> map=new HashMap<>();
map.put("equipmentIndexName.keyword",value);
map.put("gatewayId.keyword", gatewayId);
List<String> value1=new ArrayList<>();
value1.add(monthy);
map.put("moon.keyword",value1);
List<? extends Terms.Bucket> lidate= commonServiceImpl.getgroupsum(map,"value" ,"day.keyword",ESEquipments.class);
Map<String,Double> mapdta=new HashMap<>();
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) {
ParsedSum parsedSum =(ParsedSum)agg;
mapdta.put(bucket.getKeyAsString(), Double.valueOf(format2.format(parsedSum.getValue())));
}
}
//组装数据
List<String> list= dayReport(date);
for (String s : list) {
if(mapdta!=null&&mapdta.containsKey(s)){
listdate.add(mapdta.get(s));
}else{
listdate.add(0d);
}
}
return listdate;
}
public List<String> dayReport(Date month) {
List<String> list=new ArrayList<>();
Calendar cal = Calendar.getInstance();
cal.setTime(month);//month 为指定月份任意日期
int year = cal.get(Calendar.YEAR);
int m = cal.get(Calendar.MONTH);
int dayNumOfMonth = DateUtil.getDaysByYearMonth(year, m);
cal.set(Calendar.DAY_OF_MONTH, 1);// 从一号开始
for (int i = 0; i < dayNumOfMonth; i++ ) {
list.add(String.valueOf(i+1));
}
return list;
}
public List<String> dayReportnq (Date month) {
List<String> list=new ArrayList<>();
Calendar cal = Calendar.getInstance();
cal.setTime(month);//month 为指定月份任意日期
int year = cal.get(Calendar.YEAR);
int m = cal.get(Calendar.MONTH);
int dayNumOfMonth = DateUtil.getDaysByYearMonth(year, m);
cal.set(Calendar.DAY_OF_MONTH, 1);// 从一号开始
for (int i = 0; i < dayNumOfMonth; i++ ) {
list.add(m+"-"+String.valueOf(i+1));
}
return list;
}
}
\ No newline at end of file
......@@ -83,13 +83,23 @@ public class PowerGenerationImpl {
int day = calendar.get(Calendar.DATE);
int month = calendar.get(Calendar.MONTH) + 1;
int year = calendar.get(Calendar.YEAR);
SimpleDateFormat myFmt2=new SimpleDateFormat("yyyyMM");
Date now=new Date();
String monthy= myFmt2.format(now);
SimpleDateFormat myFmty=new SimpleDateFormat("yyyy");
Date nowy=new Date();
String yeary= myFmty.format(nowy);
switch (type) {
case "day":
List<ESDailyPowerGeneration> listd= this.getESDailyPowerGeneration(stationCacheInfoDto,indexDto,daty,String.valueOf(day),String.valueOf(month));
List<ESDailyPowerGeneration> listd= this.getESDailyPowerGeneration(stationCacheInfoDto,indexDto,daty,String.valueOf(day),monthy);
dailyPowerGenerationRepository.saveAll(listd);
break;
case "moon":
List<ESMoonPowerGeneration> listm= this.getESMoonPowerGeneration(stationCacheInfoDto,indexDto,daty,String.valueOf(month),String.valueOf(year));
List<ESMoonPowerGeneration> listm= this.getESMoonPowerGeneration(stationCacheInfoDto,indexDto,daty,String.valueOf(month),yeary);
moonPowerGenerationRepository.saveAll(listm);
break;
case "year":
......
package com.yeejoin.amos.boot.module.jxiop.biz.utils;
import io.micrometer.core.instrument.util.TimeUtils;
import java.sql.Time;
import java.text.ParseException;
import java.text.ParsePosition;
......@@ -420,4 +422,19 @@ public static String cronTime(Date date){
}
public static int getDaysByYearMonth(int year, int month) {
Calendar a = Calendar.getInstance();
a.set(Calendar.YEAR, year);
a.set(Calendar.MONTH, month - 1);
a.set(Calendar.DATE, 1);
a.roll(Calendar.DATE, -1);
int maxDate = a.get(Calendar.DATE);
return maxDate;
}
}
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