Commit b82fd2bc authored by chenzhao's avatar chenzhao

修改代码

parent c87f5901
......@@ -7,9 +7,9 @@ import lombok.Getter;
@AllArgsConstructor
public enum StationType {
FJC("风电场","FJC"),
JZGFC("集中光伏场","JZGFC"),
FBSGFC("分布式光伏场","FBSGFC");
FJC("风电场","FDZ"),
JZGFC("集中光伏场","JZSGFDZ"),
FBSGFC("分布式光伏场","FBSGFDZ");
......
......@@ -72,6 +72,9 @@ public class MonitorFanIdxController extends BaseController {
MonitorFanIndicatorImpl monitorFanIndicatorImpl;
@Autowired
CommonServiceImpl commonServiceImpl;
@Autowired
MonitorFanIndicatorImpl monitorFanIndicator;
@Autowired
......@@ -280,7 +283,8 @@ public class MonitorFanIdxController extends BaseController {
@TycloudOperation(needAuth = false, ApiLevel = UserType.AGENCY)
@ApiOperation(value = "概览-全站功率曲线")
@GetMapping("/overviewWindSpeed")
public ResponseModel<Map<String, Object>> getOverviewWindSpeed(@RequestParam(value = "stationId", required = false)String stationId,@RequestParam(value = "type", required = false)String type) {
public ResponseModel<Map<String, Object>> getOverviewWindSpeed(@RequestParam(value = "stationId", required = false)String stationId,@RequestParam(value = "type", required = false)String type
,@RequestParam(value = "areaCode", required = false)String areaCode) {
String gatewayId = "";
if (null != stationId){
StationBasic stationBasic = stationBasicMapper.selectById(stationId);
......@@ -735,11 +739,15 @@ public class MonitorFanIdxController extends BaseController {
public ResponseModel<Map<String,String>> getStatisticsInfo(@RequestParam(value = "equipmentIndexName", required = false) String equipmentIndexName,
@RequestParam(value = "stationId", required = false) String stationId,
@RequestParam(value = "stationType", required = false) String stationType) {
StationBasic stationBasic = stationBasicMapper.selectById(stationId);
String gatewayId = stationBasic.getFanGatewayId();
if (null != stationType){
gatewayId = stationBasic.getBoosterGatewayId();
}
String gatewayId = "";
if (null != stationId){
StationBasic stationBasic = stationBasicMapper.selectById(stationId);
gatewayId = stationBasic.getFanGatewayId();
if (null != stationType){
gatewayId = stationBasic.getBoosterGatewayId();
}
}
return ResponseHelper.buildResponse(monitorFanIndicator.getStatisticsInfo(gatewayId,equipmentIndexName ));
}
......@@ -923,8 +931,8 @@ public class MonitorFanIdxController extends BaseController {
for (StationType value : StationType.values()) {
Map<String, Object> map = new LinkedHashMap<>();
List<StationCacheInfoDto> dtos = listMap.get(value.getCode());
map.put("data",dtos.size());
map.put("title",dtos.stream().filter(obj -> !ObjectUtils.isEmpty(obj.getInstalledCapacity())).mapToDouble(l->Double.parseDouble(l.getInstalledCapacity())).sum());
map.put("data",dtos == null ? 0 :dtos.size());
map.put("title",dtos == null ? 0 :dtos.stream().filter(obj -> !ObjectUtils.isEmpty(obj.getInstalledCapacity())).mapToDouble(l->Double.parseDouble(l.getInstalledCapacity())).sum());
mapList.add(map);
}
......@@ -941,12 +949,18 @@ public class MonitorFanIdxController extends BaseController {
@TycloudOperation(needAuth = false, ApiLevel = UserType.AGENCY)
@ApiOperation(value = "社会贡献 ")
@GetMapping("/SocialContribution")
public ResponseModel<Page<SocialContributionDto> > socialContribution() {
public ResponseModel<Page<SocialContributionDto> > socialContribution(String areaCode ) {
List<String> value=new ArrayList<>();
value.add(NFDL);
Map<String,List<String>> map=new HashMap<>();
map.put("equipmentIndexName.keyword",value);
if (null != areaCode){
List<StationCacheInfoDto> listStationCacheInfoDto = commonServiceImpl.getListStationCacheInfoDto();
List<String> collect = listStationCacheInfoDto.stream().filter(e -> e.getBelongArea().equals(areaCode)).map(StationCacheInfoDto::getFanGatewayId).collect(Collectors.toList());
map.put("gateWayId",collect);
}
List<? extends Terms.Bucket> lidate= commonService.getgroupsum(map,"valueDouble" ,"equipmentIndexName.keyword", ESEquipments.class);
DecimalFormat format2 = new DecimalFormat("#.0000");
......@@ -973,19 +987,16 @@ public class MonitorFanIdxController extends BaseController {
BoolQueryBuilder boolMustAll = QueryBuilders.boolQuery();
//警情状态
BoolQueryBuilder qb0 = QueryBuilders.boolQuery();
List<QueryBuilder> should = boolMustAll.should();
String[] keys = new String[] {"日发电量","月发电量","年发电量"};
List<String> list = Arrays.asList(keys);
qb0.must((QueryBuilders.termsQuery("equipmentIndexName.keyword", list)));
boolMustAll.must(qb0);
BoolQueryBuilder qb1 = QueryBuilders.boolQuery();
qb1.must(QueryBuilders.matchQuery("gatewayId.keyword","1668801435891929089"));
boolMustAll.must(qb1);
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
boolQueryBuilder.must((QueryBuilders.termsQuery("equipmentIndexName.keyword", list))).must(QueryBuilders.matchQuery("gatewayId.keyword","1668801435891929089"));
should.add(boolQueryBuilder);
// 创建查询构造器
NativeSearchQueryBuilder queryBuilder = new NativeSearchQueryBuilder()
// 分页
.withPageable(PageRequest.of(current, size))
//过滤条件
.withQuery(boolMustAll);
......
......@@ -20,6 +20,7 @@ import org.elasticsearch.search.aggregations.Aggregations;
import org.elasticsearch.search.aggregations.bucket.terms.ParsedStringTerms;
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder;
import org.elasticsearch.search.aggregations.metrics.AvgAggregationBuilder;
import org.elasticsearch.search.aggregations.metrics.SumAggregationBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
......@@ -213,4 +214,40 @@ public class CommonServiceImpl {
return search.getSearchHits().size();
}
/*
*分组平均值
**/
public List<? extends Terms.Bucket> getgroupavg(Map<String,List<String>> value,String keyavg,String groupKey,Class clas){
List<? extends Terms.Bucket> listdata=null;
BoolQueryBuilder queryBuilder = QueryBuilders.boolQuery();
for(String key:value.keySet()){
List<String> va= value.get(key);
queryBuilder.must( QueryBuilders.termsQuery(key, va));
}
TermsAggregationBuilder tb1 = AggregationBuilders.terms("groupKey").field(groupKey);
AvgAggregationBuilder buyCountAvg = AggregationBuilders.avg("buyCountAvg").field(keyavg);
tb1.subAggregation(buyCountAvg); // 通过typeId字段分组统计总数
Query query = new NativeSearchQueryBuilder()
.withQuery(queryBuilder)
.addAggregation(tb1)
.withPageable(PageRequest.of(0, 1))
.build();
query.setTrackTotalHits(true);
SearchHits search = elasticsearchTemplate.search(query, ESEquipments.class);
if (search.hasAggregations()) {
Aggregations aggregations = search.getAggregations();
if (Objects.nonNull(aggregations)) {
List<Aggregation> list= aggregations.asList();
listdata= list!=null&&!list.isEmpty()?((ParsedStringTerms) list.get(0)).getBuckets():null;
}
}
return listdata;
}
}
package com.yeejoin.amos.boot.module.jxiop.biz.service.impl;
import com.alibaba.fastjson.JSON;
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.utils.DateUtil;
import org.eclipse.paho.client.mqttv3.MqttException;
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.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.typroject.tyboot.component.emq.EmqKeeper;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.*;
/**
* @description:
* @author: tw
* @createDate: 2023/8/10
*/
@Service
public class LargeScreenImpl {
@Autowired
CommonServiceImpl commonServiceImpl;
@Autowired
StationPlanMapper StationPlanMapper;
@Autowired
EmqKeeper emqKeeper;
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", 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);
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);
try {
emqKeeper.getMqttClient().publish("qg/yxzb", JSON.toJSONString(mapdta).getBytes(),0,false);
} catch (MqttException e) {
e.printStackTrace();
}
return mapdta;
}
/**
* 区域
**/
public Map<String, Double> getqy(List<String> gatewayId) {
Map<String, Double> mapdta = new HashMap<>();
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);
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);
try {
emqKeeper.getMqttClient().publish("topic", JSON.toJSONString(mapdta).getBytes(),0,false);
} catch (MqttException e) {
e.printStackTrace();
}
return mapdta;
}
//全国发电趋势
// @Scheduled(cron = "0/10 * * * * *")
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);
try {
emqKeeper.getMqttClient().publish("countryFd", JSON.toJSONString(seriesData).getBytes(),0,false);
} catch (MqttException e) {
e.printStackTrace();
}
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);
try {
emqKeeper.getMqttClient().publish("qy/yxzb", JSON.toJSONString(seriesData).getBytes(),0,false);
} catch (MqttException e) {
e.printStackTrace();
}
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);
}
}
try {
emqKeeper.getMqttClient().publish("topic", JSON.toJSONString(listdate).getBytes(),0,false);
} catch (MqttException e) {
e.printStackTrace();
}
return listdate;
}
//获取区域月日发电量
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);
}
}
try {
emqKeeper.getMqttClient().publish("topic", JSON.toJSONString(listdate).getBytes(),0,false);
} catch (MqttException e) {
e.printStackTrace();
}
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));
}
try {
emqKeeper.getMqttClient().publish("topic", JSON.toJSONString(list).getBytes(),0,false);
} catch (MqttException e) {
e.printStackTrace();
}
return list;
}
}
\ No newline at end of file
......@@ -540,9 +540,11 @@ public class MonitorFanIndicatorImpl implements IMonitorFanIndicator {
Map<String,Object> map1 = new HashMap<>();
Map<String,Object> map2 = new HashMap<>();
map1.put("data", values);
map2.put("data", valueList);
if (StringUtils.isNotEmpty(gatewayId)){
map2.put("data", valueList);
seriesData.add(map2);
}
seriesData.add(map1);
seriesData.add(map2);
map.put("seriesData", seriesData);
map.put("axisData",time);
......
......@@ -80,3 +80,7 @@ spring.elasticsearch.rest.connection-timeout=30000
spring.elasticsearch.rest.username=elastic
spring.elasticsearch.rest.password=123456
spring.elasticsearch.rest.read-timeout=30000
daily.power.generation.cron=*/30 * * * * ?
moon.power.generation.cron=*/30 * * * * ?
year.power.generation.cron=*/30 * * * * ?
\ No newline at end of file
......@@ -69,7 +69,7 @@ public class PowerGeneration {
}
//定时更新月发电量
@Scheduled(cron = "${moon.power.generation.cron}")
@Scheduled(cron = "${moon.power.generation.cron}")
public void addESMoonPowerGeneration(){
List<StationCacheInfoDto> list =commonServiceImpl.getListStationCacheInfoDto();
//获取时间天字符串
......
package com.yeejoin.amos.boot.module.jxiop.biz.service.impl;
import com.alibaba.fastjson.JSON;
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;
......@@ -7,6 +8,7 @@ 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.eclipse.paho.client.mqttv3.MqttException;
import org.elasticsearch.search.aggregations.Aggregation;
import org.elasticsearch.search.aggregations.Aggregations;
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
......@@ -14,6 +16,8 @@ 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 org.typroject.tyboot.component.emq.EmqKeeper;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
......@@ -31,6 +35,8 @@ public class LargeScreenImpl {
CommonServiceImpl commonServiceImpl;
@Autowired
StationPlanMapper StationPlanMapper;
@Autowired
EmqKeeper emqKeeper;
private final String SS = "瞬时风速";
private final String ZFS = "WTX-801_25_WTX-801_总辐射";
......@@ -134,6 +140,11 @@ public class LargeScreenImpl {
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);
try {
emqKeeper.getMqttClient().publish("topic", JSON.toJSONString(mapdta).getBytes(),0,false);
} catch (MqttException e) {
e.printStackTrace();
}
return mapdta;
}
......@@ -234,6 +245,11 @@ public class LargeScreenImpl {
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);
try {
emqKeeper.getMqttClient().publish("topic", JSON.toJSONString(mapdta).getBytes(),0,false);
} catch (MqttException e) {
e.printStackTrace();
}
return mapdta;
}
......@@ -267,6 +283,11 @@ public class LargeScreenImpl {
//获取日期
List<String> listdate= dayReportnq(new Date());
seriesData.setAxisData(listdate);
try {
emqKeeper.getMqttClient().publish("topic", JSON.toJSONString(seriesData).getBytes(),0,false);
} catch (MqttException e) {
e.printStackTrace();
}
return seriesData;
}
......@@ -298,6 +319,12 @@ public class LargeScreenImpl {
//获取日期
List<String> listdate= dayReportnq(new Date());
seriesData.setAxisData(listdate);
try {
emqKeeper.getMqttClient().publish("topic", JSON.toJSONString(seriesData).getBytes(),0,false);
} catch (MqttException e) {
e.printStackTrace();
}
return seriesData;
}
......@@ -341,6 +368,11 @@ public class LargeScreenImpl {
listdate.add(0d);
}
}
try {
emqKeeper.getMqttClient().publish("topic", JSON.toJSONString(listdate).getBytes(),0,false);
} catch (MqttException e) {
e.printStackTrace();
}
return listdate;
......@@ -387,6 +419,12 @@ public class LargeScreenImpl {
}
}
try {
emqKeeper.getMqttClient().publish("topic", JSON.toJSONString(listdate).getBytes(),0,false);
} catch (MqttException e) {
e.printStackTrace();
}
return listdate;
}
......@@ -433,8 +471,14 @@ public class LargeScreenImpl {
list.add(m+"-"+String.valueOf(i+1));
}
try {
emqKeeper.getMqttClient().publish("topic", JSON.toJSONString(list).getBytes(),0,false);
} catch (MqttException e) {
e.printStackTrace();
}
return list;
}
}
\ No newline at end of file
......@@ -43,7 +43,7 @@ public class PowerGenerationImpl {
public List<IndexDto> getlast(String gatewayId, String value,String daty){
IndexDto indexDto=null;
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";
String querySql = " SELECT * FROM iot_data_%s WHERE equipmentIndexName='%s' 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);
......@@ -51,7 +51,7 @@ public class PowerGenerationImpl {
}
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";
String querySql = " SELECT * FROM iot_data_%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);
......
......@@ -126,9 +126,9 @@ fan.statuts.stattuspath=upload/jxiop/device_status
pictureUrl=upload/jxiop/syz/
daily.power.generation.cron=* * */10 * * ?
moon.power.generation.cron=* * */10 * * ?
year.power.generation.cron=* * */10 * * ?
daily.power.generation.cron=0/30 * * * * ?
moon.power.generation.cron=0/30 * * * * ?
year.power.generation.cron=0/30 * * * * ?
......
......@@ -15,7 +15,7 @@
gatewayId = #{gatewayId}
</if>
<if test="gatewayId == null or gatewayId == ''">
equipmentNumber is not null
equipmentNumber is not null and equipmentIndexName is not null
</if>
</where>
GROUP BY batch_no ,equipmentIndexName;
......@@ -25,15 +25,29 @@
<select id="getStatisticsInfo" resultType="map">
SELECT
avg( VALUE ) AS mean,
( SELECT created_time FROM temporary_data WHERE gatewayId = #{gatewayId} and equipmentIndexName =#{equipmentIndexName} ORDER BY `value` LIMIT 1 ) AS minTime,
( SELECT created_time FROM temporary_data WHERE
equipmentIndexName =#{equipmentIndexName}
<if test="gatewayId != null and gatewayId != ''">
and gatewayId = #{gatewayId}
</if>
ORDER BY `value` LIMIT 1 ) AS minTime,
max( `value` ) AS max,
( SELECT created_time FROM temporary_data WHERE gatewayId = #{gatewayId} and equipmentIndexName =#{equipmentIndexName} ORDER BY `value` DESC LIMIT 1 ) AS maxTime,
( SELECT created_time FROM temporary_data WHERE
equipmentIndexName =#{equipmentIndexName}
<if test="gatewayId != null and gatewayId != ''">
and gatewayId = #{gatewayId}
</if> ORDER BY `value` DESC LIMIT 1 ) AS maxTime,
min( `value` ) AS min
FROM
`temporary_data`
WHERE
gatewayId = #{gatewayId} and equipmentIndexName =#{equipmentIndexName}
<where>
<if test="gatewayId != null and gatewayId != ''">
gatewayId = #{gatewayId} and equipmentIndexName =#{equipmentIndexName}
</if>
<if test="gatewayId == null or gatewayId == ''">
equipmentNumber is not null and equipmentIndexName is not null and equipmentIndexName =#{equipmentIndexName}
</if>
</where>
</select>
......
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