Commit f937b12d authored by caotao's avatar caotao

运行监盘将查询influxdb迁移到查询es

parent df5f5cdb
......@@ -77,4 +77,17 @@ public class CommonConstans {
}
};
//es EquipIndexName 查绚关键字
public static final String QueryStringEquipmentIndexName = "equipmentIndexName.keyword";
//es gatewayId 查绚关键字
public static final String QueryStringGateWayId = "gatewayId.keyword";
public static final String QueryStringFrontMoudle = "frontModule";
public static final String QueryStringSystemType = "systemType";
public static final String QueryStringEquipmentNumber = "equipmentNumber";
public static final String QueryStringValue = "value";
public static final String QueryStringDataType = "dataType";
public static final String QueryStringDisplayName = "displayName";
public static final String QueryStringIsAlarm = "isAlarm";
public static final String Twodecimalplaces= "%.2f";
public static final String Fourdecimalplaces = "%.4f";
}
......@@ -101,13 +101,13 @@ public class DemoController extends BaseController {
ESEquipmentsRepository equipmentsRepository;
@Autowired
CommonServiceImpl commonServiceImpl;
@Autowired
PowerGenerationImpl powerGenerationImpl;
// @Autowired
// PowerGenerationImpl powerGenerationImpl;
@Autowired
StationCacheDataInit stationCacheDataInit;
@Autowired
LargeScreenImpl largeScreenImpl;
// @Autowired
// LargeScreenImpl largeScreenImpl;
private final String ss= "瞬时风速";
private final String zfs= "WTX-801_25_WTX-801_总辐射";
private final String zfslj= "WTX-801_25_WTX-801_总辐射累计";
......@@ -513,43 +513,43 @@ public class DemoController extends BaseController {
}
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("/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 = "初始化inlfuxdb-new")
......@@ -607,40 +607,46 @@ public class DemoController extends BaseController {
@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);
}
}
// @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;
// }
return null;
@TycloudOperation(needAuth = false, ApiLevel = UserType.AGENCY)
@ApiOperation(value = "es获取数据")
@GetMapping("/test19")
public void test19() {
Map<String,List<String>> queryConditon = new HashMap<>();
queryConditon.put("equipmentIndexName.keyword",Arrays.asList("日发电量","月发电量","年发电量"));
commonServiceImpl.getListDataByCondtions(queryConditon,null,ESEquipments.class);
}
}
......@@ -13,6 +13,7 @@ import com.yeejoin.amos.boot.module.jxiop.api.dto.TreeDto;
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.StationBasicMapper;
import com.yeejoin.amos.boot.module.jxiop.biz.ESDto.ESEquipments;
import com.yeejoin.amos.boot.module.jxiop.biz.constants.CommonConstans;
import com.yeejoin.amos.boot.module.jxiop.biz.dto.DeaviationRateDto;
import com.yeejoin.amos.boot.module.jxiop.biz.dto.ResultsData;
......@@ -78,12 +79,12 @@ public class MonitorFanIdxController extends BaseController {
@TycloudOperation(needAuth = false, ApiLevel = UserType.AGENCY)
@ApiOperation(value = "根据设备编号、场站id、前段展示模块、系统类型查询表数据")
@GetMapping("/getFanIdxInfoByPage")
public ResponseModel<IPage<IndexDto>> getFanIdxInfoByPage(@RequestParam(value = "equipNum", required = false) String equipNum,
@RequestParam(value = "stationId", required = false) String stationId,
@RequestParam(value = "frontModule", required = false) String frontModule,
@RequestParam(value = "systemType", required = false) String systemType,
@RequestParam(value = "current", required = false) int current,
@RequestParam(value = "size", required = false) int size) {
public ResponseModel<IPage<ESEquipments>> getFanIdxInfoByPage(@RequestParam(value = "equipNum", required = false) String equipNum,
@RequestParam(value = "stationId", required = false) String stationId,
@RequestParam(value = "frontModule", required = false) String frontModule,
@RequestParam(value = "systemType", required = false) String systemType,
@RequestParam(value = "current", required = false) int current,
@RequestParam(value = "size", required = false) int size) {
return ResponseHelper.buildResponse(monitorFanIndicator.getFanIdxInfoByPage(equipNum, stationId, frontModule, current, size, systemType));
}
......@@ -98,12 +99,12 @@ public class MonitorFanIdxController extends BaseController {
@TycloudOperation(needAuth = false, ApiLevel = UserType.AGENCY)
@ApiOperation(value = "风机布置图 - 风机状态列表")
@GetMapping("/getFanStatusList")
public ResponseModel<IPage<IndexDto>> getFanStatusList(@RequestParam(value = "stationId", required = false) String stationId,
public ResponseModel<IPage<ESEquipments>> getFanStatusList(@RequestParam(value = "stationId", required = false) String stationId,
@RequestParam(value = "current", required = false) int current,
@RequestParam(value = "size", required = false) int size) {
List<IndexDto> fanStatusList = monitorFanIndicator.getFanStatusList(stationId);
Page<IndexDto> page = new Page<>(current, size);
List<IndexDto> collect = fanStatusList.stream()
List<ESEquipments> fanStatusList = monitorFanIndicator.getFanStatusList(stationId);
Page<ESEquipments> page = new Page<>(current, size);
List<ESEquipments> collect = fanStatusList.stream()
.skip((long) (current - 1) * size)
.limit(size)
.collect(Collectors.toList());
......@@ -116,21 +117,21 @@ public class MonitorFanIdxController extends BaseController {
@ApiOperation(value = "风机布置图 - 风机状态图片")
@GetMapping("/getFanStatusListImage")
public ResponseModel<IPage<HashMap<String,String>>> getFanStatusListImages(@RequestParam(value = "stationId", required = false) String stationId){
List<IndexDto> fanStatusList = monitorFanIndicator.getFanStatusList(stationId);
List<IndexDto> collect = fanStatusList.stream()
List<ESEquipments> fanStatusList = monitorFanIndicator.getFanStatusList(stationId);
List<ESEquipments> collect = fanStatusList.stream()
.limit(999)
.collect(Collectors.toList());
IPage<HashMap<String,String>> page = new Page<>();
HashMap<String,String> hashMap = new HashMap<>();
List<IndexDto> indexDtoList = collect.stream().sorted(Comparator.comparing(IndexDto::getEquipmentNumber)).collect(Collectors.toList());
List<ESEquipments> indexDtoList = collect.stream().sorted(Comparator.comparing(ESEquipments::getEquipmentNumber)).collect(Collectors.toList());
//获取拼音首字母
String prefix =commonService.getFanDevicePrefix(stationId);
for (int i = 1; i <= indexDtoList.size(); i++) {
IndexDto indexDto = indexDtoList.get(i-1);
hashMap.put("url"+i,fanStatusImagePathPrefix+"/"+"风机-"+indexDto.getState()+".gif");
hashMap.put("name"+i,prefix+indexDto.getEquipmentNumber());
ESEquipments ESEquipments = indexDtoList.get(i-1);
hashMap.put("url"+i,fanStatusImagePathPrefix+"/"+"风机-"+ESEquipments.getAddress()+".gif");
hashMap.put("name"+i,prefix+ESEquipments.getEquipmentNumber());
//用于参数传递
hashMap.put("name"+i+'d',indexDto.getEquipmentNumber());
hashMap.put("name"+i+'d',ESEquipments.getEquipmentNumber());
}
page.setTotal(10);
page.setSize(10);
......@@ -820,76 +821,4 @@ public class MonitorFanIdxController extends BaseController {
Page<Map<String, Object>> result = monitorFanIndicator.nbqStatus(stationBasic.getFanGatewayId());
return ResponseHelper.buildResponse(result);
}
@ApiOperation(value = "电站排名")
@Scheduled(cron = "0/10 * * * * ? ")
@GetMapping("/stationRanking")
public ResponseModel stationRanking() {
LambdaQueryWrapper<StationBasic> wrapper = new LambdaQueryWrapper<>();
List<StationBasic> stationBasics = stationBasicMapper.selectList(wrapper);
List< Map<String,Object>> datDataFJ = new ArrayList<>();
List< Map<String,Object>> monthDataFJ = new ArrayList<>();
List< Map<String,Object>> yearDataFJ = new ArrayList<>();
List< Map<String,Object>> datDataGF = new ArrayList<>();
List< Map<String,Object>> monthDataGF = new ArrayList<>();
List< Map<String,Object>> yearDataGF = new ArrayList<>();
for (StationBasic stationBasic : stationBasics) {
String gatewayId = stationBasic.getFanGatewayId();
String querySql = null;
String name = stationBasic.getStationName();
if (stationBasic.getStationType().equals("FDZ")){
Map<String, Object> map = monitorFanIndicator.generatingCapacity(gatewayId,querySql);
Map<String, Object> dayMap = new HashMap<>();
Map<String, Object> monthMap = new HashMap<>();
Map<String, Object> yearMap = new HashMap<>();
dayMap.put("name",name);
dayMap.put("value",map.get("日发电量") == null?0:String.format("%.4f",map.get("日发电量")));
monthMap.put("name",name);
monthMap.put("value",map.get("月发电量") == null?0:String.format("%.4f",map.get("月发电量")));
yearMap.put("name",name);
yearMap.put("value",map.get("年发电量") == null?0:String.format("%.4f",map.get("年发电量")));
datDataFJ.add(dayMap);
monthDataFJ.add(monthMap);
yearDataFJ.add(yearMap);
} else {
querySql = " and frontModule = '逆变器'";
Map<String, Object> map = monitorFanIndicator.generatingCapacity(gatewayId,querySql);
Map<String, Object> dayMap = new HashMap<>();
Map<String, Object> monthMap = new HashMap<>();
Map<String, Object> yearMap = new HashMap<>();
dayMap.put("name",name);
dayMap.put("value",map.get("日发电量") == null?0:String.format("%.4f",map.get("日发电量")));
monthMap.put("name",name);
monthMap.put("value",map.get("月发电量") == null?0:String.format("%.4f",map.get("月发电量")));
yearMap.put("name",name);
yearMap.put("value",map.get("年发电量") == null?0:String.format("%.4f",map.get("年发电量")));
datDataGF.add(dayMap);
monthDataGF.add(monthMap);
yearDataGF.add(yearMap);
}
}
monitorFanIndicator.sendMqttByRanking(datDataFJ, GeneratingCapacity.DAY.getCode(),"fjpm");
monitorFanIndicator.sendMqttByRanking(monthDataFJ,GeneratingCapacity.MONTH.getCode(),"fjpm");
monitorFanIndicator.sendMqttByRanking(yearDataFJ,GeneratingCapacity.YEAR.getCode(),"fjpm");
monitorFanIndicator.sendMqttByRanking(datDataGF,GeneratingCapacity.YEAR.getCode(),"gfpm");
monitorFanIndicator.sendMqttByRanking(monthDataGF,GeneratingCapacity.YEAR.getCode(),"gfpm");
monitorFanIndicator.sendMqttByRanking(yearDataGF,GeneratingCapacity.YEAR.getCode(),"gfpm");
return CommonResponseUtil.success();
}
@TycloudOperation(needAuth = false, ApiLevel = UserType.AGENCY)
@ApiOperation(value = "实时告警")
@GetMapping("/getEventByEquipIndex")
public ResponseModel<ResultsData> getEventByEquipIndex(@RequestParam(value = "current") int current,
@RequestParam(value = "size") int size,
@RequestParam(value = "stationId") String stationId,
@RequestParam(value = "equipIndex") String equipIndex,
@RequestParam(value = "frontModule") String frontModule) {
StationBasic stationBasic = stationBasicMapper.selectById(stationId);
String gatewayId = stationBasic.getFanGatewayId();
ResultsData resultsData = equipAlarmEventService.getEventByEquipIndex(gatewayId, current, size, equipIndex, frontModule);
return ResponseHelper.buildResponse(resultsData);
}
}
package com.yeejoin.amos.boot.module.jxiop.biz.scheduled;
import com.yeejoin.amos.boot.module.jxiop.biz.ESDto.ESDailyPowerGeneration;
import com.yeejoin.amos.boot.module.jxiop.biz.ESDto.ESMoonPowerGeneration;
import com.yeejoin.amos.boot.module.jxiop.biz.dto.StationCacheInfoDto;
import com.yeejoin.amos.boot.module.jxiop.biz.service.impl.CommonServiceImpl;
import com.yeejoin.amos.boot.module.jxiop.biz.service.impl.PowerGenerationImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
* @description:
* @author: tw
* @createDate: 2023/8/9
*/
@Component
@EnableScheduling
public class PowerGeneration {
@Autowired
PowerGenerationImpl powerGenerationImpl;
@Autowired
CommonServiceImpl commonServiceImpl;
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";
//定时更新日发电量
@Scheduled(cron = "${daily.power.generation.cron}")
public void addESDailyPowerGeneration(){
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) {
if("FDZ".equals(stationCacheInfoDto.getStationType())){
//风机
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}")
public void addESMoonPowerGeneration(){
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) {
//风机
if("FDZ".equals(stationCacheInfoDto.getStationType())){
//风机
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}")
public void addESYearPowerGeneration(){
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) {
//风机
if("FDZ".equals(stationCacheInfoDto.getStationType())){
//风机
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.scheduled;
//
//import com.yeejoin.amos.boot.module.jxiop.biz.ESDto.ESDailyPowerGeneration;
//import com.yeejoin.amos.boot.module.jxiop.biz.ESDto.ESMoonPowerGeneration;
//import com.yeejoin.amos.boot.module.jxiop.biz.dto.StationCacheInfoDto;
//import com.yeejoin.amos.boot.module.jxiop.biz.service.impl.CommonServiceImpl;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.scheduling.annotation.EnableScheduling;
//import org.springframework.scheduling.annotation.Scheduled;
//import org.springframework.stereotype.Component;
//
//import java.text.SimpleDateFormat;
//import java.util.ArrayList;
//import java.util.Date;
//import java.util.List;
//
///**
// * @description:
// * @author: tw
// * @createDate: 2023/8/9
// */
//
//@Component
//@EnableScheduling
//public class PowerGeneration {
//
//// @Autowired
//// PowerGenerationImpl powerGenerationImpl;
// @Autowired
// CommonServiceImpl commonServiceImpl;
//
// 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";
//
// //定时更新日发电量
// @Scheduled(cron = "${daily.power.generation.cron}")
// public void addESDailyPowerGeneration(){
// 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) {
//
// if("FDZ".equals(stationCacheInfoDto.getStationType())){
//
// //风机
// 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}")
// public void addESMoonPowerGeneration(){
// 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) {
// //风机
// if("FDZ".equals(stationCacheInfoDto.getStationType())){
//
// //风机
// 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}")
// public void addESYearPowerGeneration(){
// 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) {
// //风机
// if("FDZ".equals(stationCacheInfoDto.getStationType())){
//
// //风机
// powerGenerationImpl.addPowerGeneration( stationCacheInfoDto, stationCacheInfoDto.getFanGatewayId(), yearValue, yearDateFormat, yearType,"FDZ",daty);
//
// }else{
//
// //光伏
// powerGenerationImpl.addPowerGeneration( stationCacheInfoDto, stationCacheInfoDto.getFanGatewayId(), yearValue, yearDateFormat, yearType,"GFDZ",daty);
//
// }
//
// }
// }
//
//
//
//}
......@@ -9,7 +9,6 @@ import com.yeejoin.amos.boot.module.jxiop.api.entity.StationBasic;
import com.yeejoin.amos.boot.module.jxiop.api.mapper.MapRegionMapper;
import com.yeejoin.amos.boot.module.jxiop.api.mapper.RegionMapper;
import com.yeejoin.amos.boot.module.jxiop.api.mapper.StationBasicMapper;
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.constants.CommonConstans;
import com.yeejoin.amos.boot.module.jxiop.biz.dto.QueryDto;
......@@ -31,6 +30,7 @@ import org.elasticsearch.search.aggregations.metrics.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.data.elasticsearch.core.SearchHit;
import org.springframework.data.elasticsearch.core.SearchHits;
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
import org.springframework.data.elasticsearch.core.query.Query;
......@@ -39,6 +39,7 @@ import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import javax.annotation.Resource;
import javax.sql.rowset.serial.SerialJavaObject;
import java.util.*;
import java.util.stream.Collectors;
......@@ -49,12 +50,11 @@ public class CommonServiceImpl {
InfluxdbUtil influxdbUtil;
@Autowired
SjglZsjZsbtzMapper sjglZsjZsbtzMapper;
@Autowired
private ElasticsearchRestTemplate elasticsearchTemplate;
@Autowired
ESEquipmentsRepository equipmentsRepository;
@Autowired
private ElasticsearchRestTemplate elasticsearchTemplate;
@Autowired
private StationCacheDataInit stationCacheDataInit;
@Autowired
......@@ -190,11 +190,11 @@ public class CommonServiceImpl {
}
/**
* @deprecated 获取场站的设备总数
* @param queryDto
* @param keysum
* @param clas
* @return
* @deprecated 获取场站的设备总数
*/
public Integer getCount(List<QueryDto> queryDto, String keysum, Class clas) {
BoolQueryBuilder queryBuilder = QueryBuilders.boolQuery();
......@@ -274,8 +274,7 @@ public class CommonServiceImpl {
}
/**
*
* @param mapList 查询出来的influxdb数据
* @param mapList 查询出来的influxdb数据
* @param indicator 指标名称
* @return 该指标的求和数据
*/
......@@ -283,7 +282,7 @@ public class CommonServiceImpl {
Double totalvalue = 0.0000;
try {
totalvalue = mapList.stream().filter(stringObjectMap -> stringObjectMap.get("equipmentIndexName").toString().contains(indicator) && !ObjectUtils.isEmpty(stringObjectMap.get("value"))).mapToDouble(l -> Double.parseDouble((String) l.get("value"))).sum();
}catch (Exception e){
} catch (Exception e) {
return totalvalue;
}
return Double.valueOf(String.format("%.4f", totalvalue));
......@@ -298,7 +297,7 @@ public class CommonServiceImpl {
Double avageValue = 0.00;
try {
avageValue = mapList.stream().filter(stringObjectMap -> stringObjectMap.get("equipmentIndexName").toString().contains(indicator) && !ObjectUtils.isEmpty(stringObjectMap.get("value"))).mapToDouble(l -> Double.parseDouble((String) l.get("value"))).sum();
}catch (Exception exception){
} catch (Exception exception) {
return avageValue;
}
return Double.valueOf(String.format("%.2f", avageValue));
......@@ -306,6 +305,7 @@ public class CommonServiceImpl {
/**
* 根据场站Number获取装机容量
*
* @param WERKS
* @return
*/
......@@ -314,9 +314,9 @@ public class CommonServiceImpl {
}
/**
* @deprecated 根据发电量获取社会贡献
* @param totalSocialContribution
* @return
* @deprecated 根据发电量获取社会贡献
*/
public Page<SocialContributionDto> getSocialContributionDtoList(Double totalSocialContribution) {
......@@ -362,8 +362,8 @@ public class CommonServiceImpl {
}
/**
* @return 缓存的场站信息
* @deprecated 获取缓存场站信息数据
* @return 缓存的场站信息
*/
public List<StationCacheInfoDto> getListStationCacheInfoDto() {
List<StationCacheInfoDto> stationCacheInfoDtoList = redisTemplate.opsForList().range("station_info_cache", 0, -1);
......@@ -378,23 +378,23 @@ public class CommonServiceImpl {
stationCacheInfoDto.setStationId(stationBasic.getSequenceNbr().toString());
stationCacheInfoDto.setStationName(stationBasic.getStationName());
stationCacheInfoDto.setStationType(stationBasic.getStationType());
stationCacheInfoDto.setBelongProvince(regionList.stream().filter(region -> region.getRegionCode().toString().equals(stationBasic.getBelongArea().replace("[","").split(",")[0])).map(region -> region.getRegionName()).collect(Collectors.toList()).get(0));
stationCacheInfoDto.setBelongArea(mapRegionList.stream().filter(mapRegion -> mapRegion.getProvince().contains(stationCacheInfoDto.getBelongProvince().substring(0,2))||mapRegion.getProvince().contains(stationCacheInfoDto.getBelongProvince().substring(0,3))).map(mapRegion -> mapRegion.getName()).collect(Collectors.toList()).get(0));
stationCacheInfoDto.setAreaCode(mapRegionList.stream().filter(mapRegion -> mapRegion.getProvince().contains(stationCacheInfoDto.getBelongProvince().substring(0,2))||mapRegion.getProvince().contains(stationCacheInfoDto.getBelongProvince().substring(0,3))).map(mapRegion -> mapRegion.getAreaCode()).collect(Collectors.toList()).get(0));
stationCacheInfoDto.setInstalledCapacity(String.format("%.2f",sjglZsjZsbtzMapper.getStationCapactityByStationWerks(stationBasic.getStationNumber())));
stationCacheInfoDto.setBelongProvince(regionList.stream().filter(region -> region.getRegionCode().toString().equals(stationBasic.getBelongArea().replace("[", "").split(",")[0])).map(region -> region.getRegionName()).collect(Collectors.toList()).get(0));
stationCacheInfoDto.setBelongArea(mapRegionList.stream().filter(mapRegion -> mapRegion.getProvince().contains(stationCacheInfoDto.getBelongProvince().substring(0, 2)) || mapRegion.getProvince().contains(stationCacheInfoDto.getBelongProvince().substring(0, 3))).map(mapRegion -> mapRegion.getName()).collect(Collectors.toList()).get(0));
stationCacheInfoDto.setAreaCode(mapRegionList.stream().filter(mapRegion -> mapRegion.getProvince().contains(stationCacheInfoDto.getBelongProvince().substring(0, 2)) || mapRegion.getProvince().contains(stationCacheInfoDto.getBelongProvince().substring(0, 3))).map(mapRegion -> mapRegion.getAreaCode()).collect(Collectors.toList()).get(0));
stationCacheInfoDto.setInstalledCapacity(String.format("%.2f", sjglZsjZsbtzMapper.getStationCapactityByStationWerks(stationBasic.getStationNumber())));
List<QueryDto> queryDtoList = new ArrayList<>();
queryDtoList.add(new QueryDto("gatewayId",stationBasic.getFanGatewayId()));
queryDtoList.add(new QueryDto("equipmentIndexName.keyword","有功功率"));
if(!stationBasic.getStationType().equals("FDZ")){
queryDtoList.add(new QueryDto("frontModule","逆变器"));
queryDtoList.add(new QueryDto("gatewayId", stationBasic.getFanGatewayId()));
queryDtoList.add(new QueryDto("equipmentIndexName.keyword", "有功功率"));
if (!stationBasic.getStationType().equals("FDZ")) {
queryDtoList.add(new QueryDto("frontModule", "逆变器"));
}
stationCacheInfoDto.setEquipmentNumbers(this.getCount(queryDtoList,"equipmentNumber.Keyword", ESEquipments.class).toString());
stationCacheInfoDto.setEquipmentNumbers(this.getCount(queryDtoList, "equipmentNumber.Keyword", ESEquipments.class).toString());
stationCacheInfoDto.setFanGatewayId(stationBasic.getFanGatewayId());
stationCacheInfoDto.setBoosterGatewayId(stationBasic.getBoosterGatewayId());
stationCacheInfoDtos.add(stationCacheInfoDto);
});
redisTemplate.opsForList().leftPushAll("station_info_cache",stationCacheInfoDtos);
return stationCacheInfoDtos;
redisTemplate.opsForList().leftPushAll("station_info_cache", stationCacheInfoDtos);
return stationCacheInfoDtos;
} catch (Exception e) {
throw new RuntimeException(e);
}
......@@ -403,9 +403,9 @@ public class CommonServiceImpl {
}
/**
* @deprecated 根据场站id获取缓存数据中的场站对象
* @param stationId 场站id
* @return 缓存的场站对象
* @deprecated 根据场站id获取缓存数据中的场站对象
*/
public StationCacheInfoDto getStationCacheInfoDtoByStationId(String stationId) {
StationCacheInfoDto stationCacheInfoDto = this.getListStationCacheInfoDto().stream().filter(stationCacheInfoDto1 -> stationCacheInfoDto1.getStationId().equals(stationId)).collect(Collectors.toList()).get(0);
......@@ -413,9 +413,9 @@ public class CommonServiceImpl {
}
/**
* @deprecated 根据场站id获取场站的首字母缩写
* @param stationid 场站id
* @return 返回该场站的名称拼音缩写
* @deprecated 根据场站id获取场站的首字母缩写
*/
public String getFanDevicePrefix(String stationid) {
StationBasic stationBasic = stationBasicMapper.selectById(stationid);
......@@ -423,15 +423,94 @@ public class CommonServiceImpl {
}
/**
* @deprecated 将查询条件进行组装
* @param searchCondtionMap 需要查询的数据的 条件map
* @param searchCondtionMap 需要查询的数据的 条件map
* @return List<QueryDto> QueryDtolist 用于给传值
* @deprecated 将查询条件进行组装
*/
public List<QueryDto> getQueryDtoList(Map<String,String> searchCondtionMap){
public List<QueryDto> getQueryDtoList(Map<String, String> searchCondtionMap) {
List<QueryDto> result = new ArrayList<>();
searchCondtionMap.keySet().forEach(s -> {
result.add(new QueryDto(s,searchCondtionMap.get(s)));
result.add(new QueryDto(s, searchCondtionMap.get(s)));
});
return result;
}
/**
* 根据查询条件获取列表信息
*
* @param mustQuerCondtion
* @param shouldQuerCondtion
* @param tClass
* @param <T>
* @return
*/
public <T> List<T> getListDataByCondtions(Map<String, List<String>> mustQuerCondtion, Map<String, String> shouldQuerCondtion, Class<T> tClass) {
BoolQueryBuilder queryBuilder = QueryBuilders.boolQuery();
if (!ObjectUtils.isEmpty(mustQuerCondtion)) {
for (String key : mustQuerCondtion.keySet()) {
List<String> va = mustQuerCondtion.get(key);
queryBuilder.must(QueryBuilders.termsQuery(key, va));
}
}
if (!ObjectUtils.isEmpty(shouldQuerCondtion)) {
for (String key : shouldQuerCondtion.keySet()) {
queryBuilder.should(QueryBuilders.wildcardQuery(key, shouldQuerCondtion.get(key)));
}
}
Query query = new NativeSearchQueryBuilder()
.withQuery(queryBuilder)
.build();
query.setTrackTotalHits(true);
SearchHits search = elasticsearchTemplate.search(query, tClass);
if (search.hasSearchHits()) {
List<SearchHit<T>> searchHitList = search.getSearchHits();
List<T> list = searchHitList.stream().map(hit -> hit.getContent()).collect(Collectors.toList());
return list;
}
return null;
}
public <T> List<T> getListDataByCondtions(Map<String, List<String>> mustQuerCondtion, Map<String, String> shouldQuerCondtion, Map<String, String> notMustQuerCondtion, Class<T> tClass) {
BoolQueryBuilder queryBuilder = QueryBuilders.boolQuery();
if (!ObjectUtils.isEmpty(mustQuerCondtion)) {
for (String key : mustQuerCondtion.keySet()) {
List<String> va = mustQuerCondtion.get(key);
queryBuilder.must(QueryBuilders.termsQuery(key, va));
}
}
if (!ObjectUtils.isEmpty(shouldQuerCondtion)) {
for (String key : shouldQuerCondtion.keySet()) {
queryBuilder.should(QueryBuilders.wildcardQuery(key, shouldQuerCondtion.get(key)));
}
}
if (!ObjectUtils.isEmpty(notMustQuerCondtion)) {
for (String key : notMustQuerCondtion.keySet()) {
queryBuilder.mustNot(QueryBuilders.termsQuery(key, notMustQuerCondtion.get(key)));
}
}
Query query = new NativeSearchQueryBuilder()
.withQuery(queryBuilder)
.build();
query.setTrackTotalHits(true);
SearchHits search = elasticsearchTemplate.search(query, tClass);
if (search.hasSearchHits()) {
List<SearchHit<T>> searchHitList = search.getSearchHits();
List<T> list = searchHitList.stream().map(hit -> hit.getContent()).collect(Collectors.toList());
return list;
}
return null;
}
public Double getAvagerByEquipmentIndxName(List<ESEquipments> equipments, String indexName) {
Double result = 0.00;
result = equipments.stream().filter(esEquipments -> esEquipments.getEquipmentIndexName().equals(indexName)).mapToDouble(ESEquipments::getValueDouble).average().getAsDouble();
return result;
}
public Double getSumByEquipmentIndxName(List<ESEquipments> equipments, String indexName) {
Double result = 0.00;
result = equipments.stream().filter(esEquipments -> esEquipments.getEquipmentIndexName().equals(indexName)).mapToDouble(ESEquipments::getValueDouble).sum();
return result;
}
}
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.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;
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;
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("topic", 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;
}
//全国发电趋势
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("topic", 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("topic", 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
//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.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;
//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;
//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("topic", 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;
//
// }
//
//
//
// //全国发电趋势
//
// 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("topic", 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("topic", 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
package com.yeejoin.amos.boot.module.jxiop.biz.service.impl;
import com.google.common.collect.Lists;
import com.yeejoin.amos.boot.module.jxiop.api.dto.IndexDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* @description:
* @author: tw
* @createDate: 2023/7/4
*/
@Component
public class MonitorFanIndicatorAsync {
@Autowired
MonitorFanIndicatorImpl monitorFanIndicatorImpl;
@Value("${station.section}")
private int stationSection;
@Value("${station.isok}")
private boolean isok;
@Async("jxiopAsyncExecutor")
public void UpdateMonitorFanIndicator(List<IndexDto> list){
monitorFanIndicatorImpl.UpdateMonitorFanIndicator(list);
}
}
//package com.yeejoin.amos.boot.module.jxiop.biz.service.impl;
//
//import com.google.common.collect.Lists;
//import com.yeejoin.amos.boot.module.jxiop.api.dto.IndexDto;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.scheduling.annotation.Async;
//import org.springframework.stereotype.Component;
//
//import java.util.List;
//
///**
// * @description:
// * @author: tw
// * @createDate: 2023/7/4
// */
//@Component
//public class MonitorFanIndicatorAsync {
// @Autowired
// MonitorFanIndicatorImpl monitorFanIndicatorImpl;
// @Value("${station.section}")
// private int stationSection;
// @Value("${station.isok}")
// private boolean isok;
//
//
// @Async("jxiopAsyncExecutor")
// public void UpdateMonitorFanIndicator(List<IndexDto> list){
// monitorFanIndicatorImpl.UpdateMonitorFanIndicator(list);
// }
//
//
//}
......@@ -11,6 +11,7 @@ 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.RegionMapper;
import com.yeejoin.amos.boot.module.jxiop.api.mapper.StationBasicMapper;
import com.yeejoin.amos.boot.module.jxiop.biz.ESDto.ESEquipments;
import com.yeejoin.amos.boot.module.jxiop.biz.constants.CommonConstans;
import com.yeejoin.amos.boot.module.jxiop.biz.dto.IndicatorsDto;
import com.yeejoin.amos.boot.module.jxiop.biz.dto.SocialContributionDto;
......@@ -90,9 +91,19 @@ public class MonitoringServiceIMQTTmpl {
List<StationBasic> stationBasicList = stationBasicMapper.selectList(new QueryWrapper<StationBasic>().isNotNull("fan_gateway_id"));
stationBasicList.forEach(stationBasic -> {
if ("FDZ".equals(stationBasic.getStationType())) {
Map<String, List<String>> queryCondtion = new HashMap<>();
queryCondtion.put(CommonConstans.QueryStringEquipmentIndexName, Arrays.asList( "日发电量", "月发电量", "年发电量"));
queryCondtion.put(CommonConstans.QueryStringGateWayId, Arrays.asList(stationBasic.getFanGatewayId()));
totalSocialContribution.updateAndGet(v -> v + commonServiceImpl.getTotalByIndicatior(stationBasic.getFanGatewayId(), "年发电量"));
} else {
totalSocialContribution.updateAndGet(v -> v + commonServiceImpl.getTotalByIndicatior(stationBasic.getFanGatewayId(), "年发电量") * CommonConstans.pvGenPoweActor);
Map<String, List<String>> queryCondtion = new HashMap<>();
queryCondtion.put(CommonConstans.QueryStringEquipmentIndexName, Arrays.asList( "日发电量", "月发电量", "年发电量"));
queryCondtion.put(CommonConstans.QueryStringGateWayId, Arrays.asList(stationBasic.getFanGatewayId()));
Map<String, String> shouldQueryCondtion = new HashMap<>();
shouldQueryCondtion.put("frontModule", "逆变器");
List<ESEquipments> result = commonServiceImpl.getListDataByCondtions(queryCondtion, shouldQueryCondtion, ESEquipments.class);
totalSocialContribution.updateAndGet(v -> v + commonServiceImpl.getSumByEquipmentIndxName(result, "年发电量") * CommonConstans.pvGenPoweActor);
}
});
Page<SocialContributionDto> socialContributionDtoPage = commonService.getSocialContributionDtoList(totalSocialContribution.get());
......@@ -124,13 +135,23 @@ public class MonitoringServiceIMQTTmpl {
String completionRatio = "23.11";
stationBasicList.forEach(stationBasic -> {
if ("FDZ".equals(stationBasic.getStationType())) {
dailyPower.updateAndGet(v -> v + commonServiceImpl.getTotalByIndicatior(stationBasic.getFanGatewayId(), "日发电量"));
monthlyPower.updateAndGet(v -> v + commonServiceImpl.getTotalByIndicatior(stationBasic.getFanGatewayId(), "月发电量"));
annualPower.updateAndGet(v -> v + commonServiceImpl.getTotalByIndicatior(stationBasic.getFanGatewayId(), "年发电量"));
Map<String, List<String>> queryCondtion = new HashMap<>();
queryCondtion.put(CommonConstans.QueryStringEquipmentIndexName, Arrays.asList("有功功率", "日发电量", "月发电量", "年发电量"));
queryCondtion.put(CommonConstans.QueryStringGateWayId, Arrays.asList(stationBasic.getFanGatewayId()));
List<ESEquipments> result = commonServiceImpl.getListDataByCondtions(queryCondtion, null, ESEquipments.class);
dailyPower.updateAndGet(v -> v + commonServiceImpl.getSumByEquipmentIndxName(result, "日发电量"));
monthlyPower.updateAndGet(v -> v + commonServiceImpl.getSumByEquipmentIndxName(result, "月发电量"));
annualPower.updateAndGet(v -> v + commonServiceImpl.getSumByEquipmentIndxName(result, "年发电量"));
} else {
dailyPower.updateAndGet(v -> v + commonServiceImpl.getTotalByIndicatior(stationBasic.getFanGatewayId(), "日发电量")*CommonConstans.pvGenPoweActor);
monthlyPower.updateAndGet(v -> v + commonServiceImpl.getTotalByIndicatior(stationBasic.getFanGatewayId(), "月发电量")*CommonConstans.pvGenPoweActor);
annualPower.updateAndGet(v -> v + commonServiceImpl.getTotalByIndicatior(stationBasic.getFanGatewayId(), "年发电量")*CommonConstans.pvGenPoweActor);
Map<String, List<String>> queryCondtion = new HashMap<>();
queryCondtion.put(CommonConstans.QueryStringEquipmentIndexName, Arrays.asList( "日发电量", "月发电量", "年发电量"));
queryCondtion.put(CommonConstans.QueryStringGateWayId, Arrays.asList(stationBasic.getFanGatewayId()));
Map<String, String> shouldQueryCondtion = new HashMap<>();
shouldQueryCondtion.put("frontModule", "逆变器");
List<ESEquipments> result = commonServiceImpl.getListDataByCondtions(queryCondtion, shouldQueryCondtion, ESEquipments.class);
dailyPower.updateAndGet(v -> v + commonServiceImpl.getSumByEquipmentIndxName(result, "日发电量")*CommonConstans.pvGenPoweActor);
monthlyPower.updateAndGet(v -> v + commonServiceImpl.getSumByEquipmentIndxName(result, "月发电量")*CommonConstans.pvGenPoweActor);
annualPower.updateAndGet(v -> v + commonServiceImpl.getSumByEquipmentIndxName(result, "年发电量")*CommonConstans.pvGenPoweActor);
}
});
SocialContributionDto dailyPowerdto = new SocialContributionDto();
......@@ -299,7 +320,7 @@ public class MonitoringServiceIMQTTmpl {
Integer size = 99;
List<StationBasic> stationBasicList = stationBasicMapper.selectList(new QueryWrapper<StationBasic>().isNotNull("sequence_nbr").eq("station_type", "FDZ"));
stationBasicList.forEach(stationBasic -> {
List<IndexDto> fanStatusList = monitorFanIndicator.getFanStatusList(String.valueOf(stationBasic.getSequenceNbr()));
List<ESEquipments> fanStatusList = monitorFanIndicator.getFanStatusList(String.valueOf(stationBasic.getSequenceNbr()));
fanStatusList.forEach(indexDto -> {
String stationBasicId = String.valueOf(stationBasic.getSequenceNbr());
String equipmentNumber = indexDto.getEquipmentNumber();
......@@ -313,22 +334,22 @@ public class MonitoringServiceIMQTTmpl {
String powerFrequency = monitorFanIndicator.getFanDataByType(stationBasicId, equipmentNumber, "实时监控表计", "电网频率");
String hubSpeed = monitorFanIndicator.getFanDataByType(stationBasicId, equipmentNumber, "实时监控表计", "轮毂转速");
HashMap<String, List<String>> realTimeTemperatureResult = monitorFanIndicator.getRealTimeTemperature(equipmentNumber, stationBasicId, "实时监控表计");
IPage<IndexDto> realTimedata = monitorFanIndicator.getFanIdxInfoByPage(equipmentNumber, stationBasicId, "实时运行数据", current, size, "");
IPage<ESEquipments> realTimedata = monitorFanIndicator.getFanIdxInfoByPage(equipmentNumber, stationBasicId, "实时运行数据", current, size, "");
Map<String, Object> windSpeedOfFan = monitorFanIndicator.getDetailsWindSpeed(stationBasic.getFanGatewayId(), equipmentNumber);
//发电机系统
IPage<IndexDto> fdjSystem = monitorFanIndicator.getFanIdxInfoByPage(equipmentNumber, stationBasicId, "实时运行数据", current, size, "发电机系统");
IPage<ESEquipments> fdjSystem = monitorFanIndicator.getFanIdxInfoByPage(equipmentNumber, stationBasicId, "实时运行数据", current, size, "发电机系统");
List<Map<String, Object>> fdjSystemStatus = monitorFanIndicator.getStatusMonitoring(stationBasic.getFanGatewayId(), equipmentNumber, "发电机系统");
//机舱与塔筒系统
IPage<IndexDto> jcyttSystem = monitorFanIndicator.getFanIdxInfoByPage(equipmentNumber, stationBasicId, "实时运行数据", current, size, "机舱与塔筒系统");
IPage<ESEquipments> jcyttSystem = monitorFanIndicator.getFanIdxInfoByPage(equipmentNumber, stationBasicId, "实时运行数据", current, size, "机舱与塔筒系统");
List<Map<String, Object>> jcyttSystemStatus = monitorFanIndicator.getStatusMonitoring(stationBasic.getFanGatewayId(), equipmentNumber, "机舱与塔筒系统");
//偏航与液压系统
IPage<IndexDto> phyyySystem = monitorFanIndicator.getFanIdxInfoByPage(equipmentNumber, stationBasicId, "实时运行数据", current, size, "偏航与液压系统");
IPage<ESEquipments> phyyySystem = monitorFanIndicator.getFanIdxInfoByPage(equipmentNumber, stationBasicId, "实时运行数据", current, size, "偏航与液压系统");
List<Map<String, Object>> phyyySystemStatus = monitorFanIndicator.getStatusMonitoring(stationBasic.getFanGatewayId(), equipmentNumber, "偏航与液压系统");
//变流与主控系统
IPage<IndexDto> blyzkSystem = monitorFanIndicator.getFanIdxInfoByPage(equipmentNumber, stationBasicId, "实时运行数据", current, size, "变流与主控系统");
IPage<ESEquipments> blyzkSystem = monitorFanIndicator.getFanIdxInfoByPage(equipmentNumber, stationBasicId, "实时运行数据", current, size, "变流与主控系统");
List<Map<String, Object>> blyzkSystemStatus = monitorFanIndicator.getStatusMonitoring(stationBasic.getFanGatewayId(), equipmentNumber, "变流与主控系统");
//变流与主控系统
IPage<IndexDto> ylSystem = monitorFanIndicator.getFanIdxInfoByPage(equipmentNumber, stationBasicId, "实时运行数据", current, size, "叶轮系统");
IPage<ESEquipments> ylSystem = monitorFanIndicator.getFanIdxInfoByPage(equipmentNumber, stationBasicId, "实时运行数据", current, size, "叶轮系统");
List<Map<String, Object>> ylSystemStatus = monitorFanIndicator.getStatusMonitoring(stationBasic.getFanGatewayId(), equipmentNumber, "叶轮系统");
try {
//{stationBasicId}_{equipmentNumber}_fanBasicInfo_topic
......
......@@ -86,102 +86,9 @@ public class MonitoringServiceImpl {
return ObjectUtils.isEmpty(installCapacity) ? 0.00 : installCapacity;
}
/**
* 根据省份名称查询电站详情
*
* @param provinceName
* @return
*/
// public List<RegionNationWideDto> getNationWideInfo(String provinceName, String type) {
// List<RegionNationWideDto> regionNationWideDtoList = new ArrayList<>();
// List<StationBasic> stationBasicList = stationBasicMapper.selectList(new QueryWrapper<StationBasic>().isNotNull("belong_area").isNotNull("fan_gateway_id"));
// List<Region> regionList = this.regionMapper.selectList(new QueryWrapper<Region>().eq("level", 1));
// List<StationBasic> list = new ArrayList<>();
// //如果 provinceName 为空则表示当前为全国地图 否则则为省份地图
//// if (ObjectUtils.isEmpty(provinceName) || provinceName.equals("")) {
// if ((!ObjectUtils.isEmpty(type) && type.equals("gis")) && (ObjectUtils.isEmpty(provinceName) || provinceName.equals(""))) {
// for (int i = 0; i < regionList.size(); i++) {
// RegionNationWideDto regionNationWideDto = new RegionNationWideDto();
// AtomicReference<Double> guangfuMW = new AtomicReference<>(0.0);
// AtomicReference<Double> fengdianMW = new AtomicReference<>(0.0);
// AtomicReference<Integer> guangfu = new AtomicReference<>(0);
// AtomicReference<Integer> fengdian = new AtomicReference<>(0);
// Region region = regionList.get(i);
// list = stationBasicList.stream().filter(stationBasic -> stationBasic.getBelongArea().contains(String.valueOf(region.getRegionCode()))).collect(Collectors.toList());
// list.forEach(stationBasic -> {
// if (!ObjectUtils.isEmpty(stationBasic.getFanGatewayId()) && !ObjectUtils.isEmpty(stationBasic.getStationNumber())) {
// regionNationWideDto.setJsJoin(true);
// }
// if (stationBasic.getStationType().equals("FDZ")) {
// fengdianMW.set(getStationCaPACITYL(stationBasic.getStationNumber()));
// fengdian.getAndSet(fengdian.get() + 1);
// } else {
// guangfuMW.set(getStationCaPACITYL(stationBasic.getStationNumber()));
// guangfu.getAndSet(guangfu.get() + 1);
// }
// });
// regionNationWideDto.setFengdian(fengdian.toString());
// regionNationWideDto.setGuangfu(guangfu.toString());
// regionNationWideDto.setGuangfuMW("0");
// regionNationWideDto.setFengdianMV("0");
// if (!ObjectUtils.isEmpty(guangfuMW.get())) {
// regionNationWideDto.setGuangfuMW(String.format("%.2f", guangfuMW.get()));
// }
// if (!ObjectUtils.isEmpty(fengdianMW.get())) {
// regionNationWideDto.setFengdianMV(String.format("%.2f", fengdianMW.get()));
// }
// regionNationWideDto.setName(region.getRegionName());
// regionNationWideDtoList.add(regionNationWideDto);
// }
// } else {
// if (!ObjectUtils.isEmpty(provinceName) && provinceName.contains("%")) {
// try {
// provinceName = URLDecoder.decode(provinceName, "UTF-8");
// } catch (Exception e) {
//
// }
// }
// String finalProvinceName = provinceName;
// if (!ObjectUtils.isEmpty(type) && type.equals("station")) {
// list = stationBasicList;
// } else {
// Region region = regionList.stream().filter(region1 -> region1.getRegionName().equals(finalProvinceName)).collect(Collectors.toList()).get(0);
// list = stationBasicList.stream().filter(stationBasic -> stationBasic.getBelongArea().contains(String.valueOf(region.getRegionCode())) && stationBasic.getFanGatewayId() != null).collect(Collectors.toList());
// }
// List<StationCoordinate> stationCoordinateList = stationCoordinateMapper.selectList(new QueryWrapper<StationCoordinate>().isNotNull("station_id").eq("is_main_coordinate", 0));
// for (int i = 0; i < list.size(); i++) {
// HashMap<String, Double> hashMap = new HashMap<>();
// StationBasic stationBasic = list.get(i);
// RegionNationWideDto regionNationWideDto = new RegionNationWideDto();
// regionNationWideDto.setStaitionId(String.valueOf(stationBasic.getSequenceNbr()));
// regionNationWideDto.setStaitionName(stationBasic.getStationName());
// regionNationWideDto.setStaitionType(stationBasic.getStationType());
// String speendOrirradiate = "";
// regionNationWideDto.setStationCapacity(String.valueOf(getStationCaPACITYL(stationBasic.getStationNumber())));
// if (stationBasic.getStationType().equals("FDZ")) {
// speendOrirradiate = String.valueOf(commonServiceImpl.getAvgvalueByIndicatior(stationBasic.getFanGatewayId(), "30秒平均风速"));
// } else {
// speendOrirradiate = String.valueOf(commonServiceImpl.getTotalByIndicatior(stationBasic.getBoosterGatewayId(), "WTX-801_25_WTX-801_总辐射"));
// }
// regionNationWideDto.setSpeendOrirradiate(speendOrirradiate);
// StationCoordinate stationCoordinate = stationCoordinateList.stream().filter(stationCoordinate1 -> stationCoordinate1.getStationId().equals(stationBasic.getSequenceNbr())).collect(Collectors.toList()).get(0);
// hashMap.put("lng", Double.valueOf(stationCoordinate.getLongitude()));
// hashMap.put("lat", Double.valueOf(stationCoordinate.getLaitude()));
// regionNationWideDto.setPosition(hashMap);
// regionNationWideDtoList.add(regionNationWideDto);
// }
// }
// List<StationBasic> finalList = list;
// String finalProvinceName1 = provinceName;
// Thread thread = new Thread(() -> {
// getCompletionOfPowerIndicatorsByCurrentData(finalList, finalProvinceName1);
// });
// thread.start();
// return regionNationWideDtoList;
// }
public List<RegionNationWideDto> getNationWideInfo(String provinceName, String type) {
List<RegionNationWideDto> regionNationWideDtoList = new ArrayList<>();
List<StationCacheInfoDto> stationCacheInfoDtoList=commonServiceImpl.getListStationCacheInfoDto();
List<StationCacheInfoDto> stationCacheInfoDtoList = commonServiceImpl.getListStationCacheInfoDto();
List<Region> regionList = this.regionMapper.selectList(new QueryWrapper<Region>().eq("level", 1));
List<StationCacheInfoDto> list = new ArrayList<>();
//如果 provinceName 为空则表示当前为全国地图 否则则为省份地图
......@@ -191,8 +98,8 @@ public class MonitoringServiceImpl {
RegionNationWideDto regionNationWideDto = new RegionNationWideDto();
Region region = regionList.get(i);
list = stationCacheInfoDtoList.stream().filter(stationCacheInfoDto -> stationCacheInfoDto.getBelongProvince().equals(region.getRegionName())).collect(Collectors.toList());
List<StationCacheInfoDto> fdlist=list.stream().filter(stationCacheInfoDto -> stationCacheInfoDto.getStationType().equals("FDZ")).collect(Collectors.toList());
List<StationCacheInfoDto> gflist=list.stream().filter(stationCacheInfoDto -> !stationCacheInfoDto.getStationType().equals("FDZ")).collect(Collectors.toList());
List<StationCacheInfoDto> fdlist = list.stream().filter(stationCacheInfoDto -> stationCacheInfoDto.getStationType().equals("FDZ")).collect(Collectors.toList());
List<StationCacheInfoDto> gflist = list.stream().filter(stationCacheInfoDto -> !stationCacheInfoDto.getStationType().equals("FDZ")).collect(Collectors.toList());
if (list.size() > 0) {
regionNationWideDto.setJsJoin(true);
} else {
......@@ -200,8 +107,8 @@ public class MonitoringServiceImpl {
}
regionNationWideDto.setFengdian(String.valueOf(fdlist.size()));
regionNationWideDto.setGuangfu(String.valueOf(gflist.size()));
regionNationWideDto.setGuangfuMW(String.format("%.2f",gflist.stream().mapToDouble(stationCacheInfoDto->Double.parseDouble(stationCacheInfoDto.getInstalledCapacity())).sum()));
regionNationWideDto.setFengdianMV(String.format("%.2f",fdlist.stream().mapToDouble(stationCacheInfoDto->Double.parseDouble(stationCacheInfoDto.getInstalledCapacity())).sum()));
regionNationWideDto.setGuangfuMW(String.format(CommonConstans.Twodecimalplaces, gflist.stream().mapToDouble(stationCacheInfoDto -> Double.parseDouble(stationCacheInfoDto.getInstalledCapacity())).sum()));
regionNationWideDto.setFengdianMV(String.format(CommonConstans.Twodecimalplaces, fdlist.stream().mapToDouble(stationCacheInfoDto -> Double.parseDouble(stationCacheInfoDto.getInstalledCapacity())).sum()));
regionNationWideDto.setName(region.getRegionName());
regionNationWideDtoList.add(regionNationWideDto);
}
......@@ -222,6 +129,7 @@ public class MonitoringServiceImpl {
List<StationCoordinate> stationCoordinateList = stationCoordinateMapper.selectList(new QueryWrapper<StationCoordinate>().isNotNull("station_id").eq("is_main_coordinate", 0));
for (int i = 0; i < list.size(); i++) {
HashMap<String, Double> hashMap = new HashMap<>();
StationCacheInfoDto stationCacheInfoDto = list.get(i);
RegionNationWideDto regionNationWideDto = new RegionNationWideDto();
regionNationWideDto.setStaitionId(String.valueOf(stationCacheInfoDto.getStationId()));
......@@ -230,9 +138,18 @@ public class MonitoringServiceImpl {
String speendOrirradiate = "";
regionNationWideDto.setStationCapacity(stationCacheInfoDto.getInstalledCapacity());
if (stationCacheInfoDto.getStationType().equals("FDZ")) {
speendOrirradiate = String.valueOf(commonServiceImpl.getAvgvalueByIndicatior(stationCacheInfoDto.getFanGatewayId(), "30秒平均风速"));
//用于组装-es查询条件
Map<String, List<String>> queryCondtion = new HashMap<>();
queryCondtion.put(CommonConstans.QueryStringEquipmentIndexName, Arrays.asList("30秒平均风速"));
queryCondtion.put(CommonConstans.QueryStringGateWayId, Arrays.asList(stationCacheInfoDto.getFanGatewayId()));
List<ESEquipments> result = commonServiceImpl.getListDataByCondtions(queryCondtion, null, ESEquipments.class);
speendOrirradiate = String.format(CommonConstans.Twodecimalplaces, commonServiceImpl.getAvagerByEquipmentIndxName(result, "30秒平均风速"));
} else {
speendOrirradiate = String.valueOf(commonServiceImpl.getTotalByIndicatior(stationCacheInfoDto.getBoosterGatewayId(), "WTX-801_25_WTX-801_总辐射"));
Map<String, List<String>> queryCondtion = new HashMap<>();
queryCondtion.put(CommonConstans.QueryStringEquipmentIndexName, Arrays.asList("WTX-801_25_WTX-801_总辐射"));
queryCondtion.put(CommonConstans.QueryStringGateWayId, Arrays.asList(stationCacheInfoDto.getBoosterGatewayId()));
List<ESEquipments> result = commonServiceImpl.getListDataByCondtions(queryCondtion, null, ESEquipments.class);
speendOrirradiate = String.format(CommonConstans.Twodecimalplaces, commonServiceImpl.getSumByEquipmentIndxName(result, "WTX-801_25_WTX-801_总辐射"));
}
regionNationWideDto.setSpeendOrirradiate(speendOrirradiate);
StationCoordinate stationCoordinate = stationCoordinateList.stream().filter(stationCoordinate1 -> String.valueOf(stationCoordinate1.getStationId()).equals(stationCacheInfoDto.getStationId())).collect(Collectors.toList()).get(0);
......@@ -270,38 +187,42 @@ public class MonitoringServiceImpl {
colModels.add(colModelDailyPower);
colModels.add(colModelMonthlyPower);
colModels.add(colModelAnnualPower);
Region region = this.regionMapper.selectOne(new QueryWrapper<Region>().eq("level", 1).eq("region_name", provinceName));
List<StationBasic> stationBasicList = stationBasicMapper.selectList(new QueryWrapper<StationBasic>().like("belong_area", region.getRegionCode()));
List<StationCacheInfoDto> stationCacheInfoDtoList = commonServiceImpl.getListStationCacheInfoDto();
List<StationCacheInfoDto> stationCacheInfoDtos = stationCacheInfoDtoList.stream().filter(stationCacheInfoDto -> stationCacheInfoDto.getBelongProvince().equals(provinceName)).collect(Collectors.toList());
//遍历列表
stationBasicList.forEach(stationBasic -> {
stationCacheInfoDtos.forEach(stationCacheInfoDto -> {
CompletionOfPowerIndicatorsDto completionOfPowerIndicatorsDto = new CompletionOfPowerIndicatorsDto();
completionOfPowerIndicatorsDto.setStationName(stationBasic.getStationName());
completionOfPowerIndicatorsDto.setInstallCapactity("0");
if (getStationCaPACITYL(stationBasic.getStationNumber()) != null) {
completionOfPowerIndicatorsDto.setInstallCapactity(String.format("%.2f", getStationCaPACITYL(stationBasic.getStationNumber())));
}
completionOfPowerIndicatorsDto.setStationName(stationCacheInfoDto.getStationName());
completionOfPowerIndicatorsDto.setInstallCapactity(stationCacheInfoDto.getInstalledCapacity());
try {
List<Map<String, Object>> mapList;
List<Map<String, Object>> mapList1;
if (stationBasic.getStationType().equals("FDZ")) {
mapList = influxdbUtil.query("SELECT * FROM indicators_" + stationBasic.getFanGatewayId() + " where (equipmentIndexName='日发电量' or equipmentIndexName='月发电量' or equipmentIndexName='年发电量' or equipmentIndexName='有功功率' or equipmentIndexName='30秒平均风速' )");
completionOfPowerIndicatorsDto.setWindSpeedOrIrradiance(String.valueOf(commonServiceImpl.getAvgvalueByIndicatior(mapList, "30秒平均风速")));
completionOfPowerIndicatorsDto.setActivePower(String.valueOf(commonServiceImpl.getTotalByIndicatior(mapList, "有功功率")));
completionOfPowerIndicatorsDto.setDailyPower(String.valueOf(commonServiceImpl.getTotalByIndicatior(mapList, "日发电量")));
completionOfPowerIndicatorsDto.setMonthlyPower(String.valueOf(commonServiceImpl.getTotalByIndicatior(mapList, "月发电量")));
completionOfPowerIndicatorsDto.setAnnualPower(String.valueOf(commonServiceImpl.getTotalByIndicatior(mapList, "年发电量")));
if (stationCacheInfoDto.getStationType().equals("FDZ")) {
//用于组装-es查询条件
Map<String, List<String>> queryCondtion = new HashMap<>();
queryCondtion.put(CommonConstans.QueryStringEquipmentIndexName, Arrays.asList("30秒平均风速", "有功功率", "日发电量", "月发电量", "年发电量"));
queryCondtion.put(CommonConstans.QueryStringGateWayId, Arrays.asList(stationCacheInfoDto.getFanGatewayId()));
List<ESEquipments> result = commonServiceImpl.getListDataByCondtions(queryCondtion, null, ESEquipments.class);
completionOfPowerIndicatorsDto.setWindSpeedOrIrradiance(String.format(CommonConstans.Twodecimalplaces, commonServiceImpl.getAvagerByEquipmentIndxName(result, "30秒平均风速")));
completionOfPowerIndicatorsDto.setActivePower(String.format(CommonConstans.Twodecimalplaces, commonServiceImpl.getSumByEquipmentIndxName(result, "有功功率")));
completionOfPowerIndicatorsDto.setDailyPower(String.format(CommonConstans.Fourdecimalplaces, commonServiceImpl.getSumByEquipmentIndxName(result, "日发电量")));
completionOfPowerIndicatorsDto.setMonthlyPower(String.format(CommonConstans.Fourdecimalplaces, commonServiceImpl.getSumByEquipmentIndxName(result, "月发电量")));
completionOfPowerIndicatorsDto.setAnnualPower(String.format(CommonConstans.Fourdecimalplaces, commonServiceImpl.getSumByEquipmentIndxName(result, "年发电量")));
} else {
mapList = influxdbUtil.query("SELECT * FROM indicators_" + stationBasic.getFanGatewayId() + " where frontModule=~/逆变器/ and(equipmentIndexName='日发电量' or equipmentIndexName='月发电量' or equipmentIndexName='年发电量' or equipmentIndexName='有功功率')");
mapList1 = influxdbUtil.query("SELECT * FROM indicators_" + stationBasic.getBoosterGatewayId() + " where equipmentIndexName='WTX-801_25_WTX-801_总辐射'");
completionOfPowerIndicatorsDto.setWindSpeedOrIrradiance(String.valueOf(commonServiceImpl.getTotalByIndicatior(mapList1, "WTX-801_25_WTX-801_总辐射")));
completionOfPowerIndicatorsDto.setActivePower(String.valueOf(commonServiceImpl.getTotalByIndicatior(mapList, "有功功率")));
completionOfPowerIndicatorsDto.setDailyPower(String.format("%.2f",commonServiceImpl.getTotalByIndicatior(mapList, "日发电量") * CommonConstans.pvGenPoweActor));
completionOfPowerIndicatorsDto.setMonthlyPower(String.format("%.2f",commonServiceImpl.getTotalByIndicatior(mapList, "月发电量") * CommonConstans.pvGenPoweActor));
completionOfPowerIndicatorsDto.setAnnualPower(String.format("%.2f", new BigDecimal(commonServiceImpl.getTotalByIndicatior(mapList, "年发电量") * CommonConstans.pvGenPoweActor)));
Map<String, List<String>> queryCondtion = new HashMap<>();
queryCondtion.put(CommonConstans.QueryStringEquipmentIndexName, Arrays.asList("有功功率", "日发电量", "月发电量", "年发电量"));
queryCondtion.put(CommonConstans.QueryStringGateWayId, Arrays.asList(stationCacheInfoDto.getFanGatewayId()));
Map<String, String> shouldQueryCondtion = new HashMap<>();
shouldQueryCondtion.put("frontModule", "逆变器");
Map<String, List<String>> queryCondtion1 = new HashMap<>();
queryCondtion1.put(CommonConstans.QueryStringEquipmentIndexName, Arrays.asList("WTX-801_25_WTX-801_总辐射"));
queryCondtion1.put(CommonConstans.QueryStringGateWayId, Arrays.asList(stationCacheInfoDto.getBoosterGatewayId()));
List<ESEquipments> result = commonServiceImpl.getListDataByCondtions(queryCondtion, shouldQueryCondtion, ESEquipments.class);
List<ESEquipments> result1 = commonServiceImpl.getListDataByCondtions(queryCondtion1, null, ESEquipments.class);
completionOfPowerIndicatorsDto.setWindSpeedOrIrradiance(String.format(CommonConstans.Twodecimalplaces, commonServiceImpl.getSumByEquipmentIndxName(result1, "WTX-801_25_WTX-801_总辐射")));
completionOfPowerIndicatorsDto.setActivePower(String.format(CommonConstans.Twodecimalplaces, commonServiceImpl.getSumByEquipmentIndxName(result, "有功功率")));
completionOfPowerIndicatorsDto.setDailyPower(String.format(CommonConstans.Fourdecimalplaces, commonServiceImpl.getSumByEquipmentIndxName(result, "日发电量") * CommonConstans.pvGenPoweActor));
completionOfPowerIndicatorsDto.setMonthlyPower(String.format(CommonConstans.Fourdecimalplaces, commonServiceImpl.getSumByEquipmentIndxName(result, "月发电量") * CommonConstans.pvGenPoweActor));
completionOfPowerIndicatorsDto.setAnnualPower(String.format(CommonConstans.Fourdecimalplaces, new BigDecimal(commonServiceImpl.getSumByEquipmentIndxName(result, "年发电量") * CommonConstans.pvGenPoweActor)));
}
} catch (Exception exception) {
completionOfPowerIndicatorsDto.setWindSpeedOrIrradiance("0");
completionOfPowerIndicatorsDto.setActivePower("0");
......@@ -346,47 +267,47 @@ public class MonitoringServiceImpl {
//年利用小时数
AtomicReference<Double> useHours = new AtomicReference<>(0.0);
AtomicReference<Double> installCapacity = new AtomicReference<>(0.0);
stationBasicList.forEach(stationBasic -> {
List<Map<String, Object>> mapList = new ArrayList<>();
Map<String,List<String>> queryMap = new HashMap<>();
queryMap.put("equipmentIndexName.keyword",Arrays.asList("日发电量","月发电量","年发电量"));
queryMap.put("gatewayId.keyword",Arrays.asList(stationBasic.getFanGatewayId()));
if (stationBasic.getStationType().equals("FDZ")) {
List<? extends Terms.Bucket> lidatesum =commonServiceImpl.getgroupsum(queryMap,"valueDouble","equipmentIndexName.keyword", ESEquipments.class);
mapList = influxdbUtil.query("SELECT * FROM indicators_" + stationBasic.getFanGatewayId() + " where (equipmentIndexName='日发电量' or equipmentIndexName='月发电量' or equipmentIndexName='年发电量' )");
stationBasicList.forEach(stationCacheInfoDto -> {
Map<String, List<String>> queryMap = new HashMap<>();
queryMap.put("equipmentIndexName.keyword", Arrays.asList("日发电量", "月发电量", "年发电量"));
queryMap.put("gatewayId.keyword", Arrays.asList(stationCacheInfoDto.getFanGatewayId()));
if ("FDZ".equals(stationCacheInfoDto.getStationType())) {
Map<String, List<String>> queryCondtion = new HashMap<>();
queryCondtion.put(CommonConstans.QueryStringEquipmentIndexName, Arrays.asList("日发电量", "月发电量", "年发电量"));
queryCondtion.put(CommonConstans.QueryStringGateWayId, Arrays.asList(stationCacheInfoDto.getFanGatewayId()));
List<ESEquipments> result = commonServiceImpl.getListDataByCondtions(queryCondtion, null, ESEquipments.class);
dailyPower.updateAndGet(v -> v + commonServiceImpl.getSumByEquipmentIndxName(result, "日发电量"));
monthlyPower.updateAndGet(v -> v + commonServiceImpl.getSumByEquipmentIndxName(result, "月发电量"));
annualPower.updateAndGet(v -> v + commonServiceImpl.getSumByEquipmentIndxName(result, "年发电量"));
} else {
mapList = influxdbUtil.query("SELECT * FROM indicators_" + stationBasic.getFanGatewayId() + " where frontModule=~/逆变器/ and (equipmentIndexName='日发电量' or equipmentIndexName='月发电量' or equipmentIndexName='年发电量' )");
Map<String, List<String>> queryCondtion = new HashMap<>();
queryCondtion.put(CommonConstans.QueryStringEquipmentIndexName, Arrays.asList("日发电量", "月发电量", "年发电量"));
queryCondtion.put(CommonConstans.QueryStringGateWayId, Arrays.asList(stationCacheInfoDto.getFanGatewayId()));
List<ESEquipments> result = commonServiceImpl.getListDataByCondtions(queryCondtion, null, ESEquipments.class);
dailyPower.updateAndGet(v -> v + commonServiceImpl.getSumByEquipmentIndxName(result, "日发电量") * CommonConstans.pvGenPoweActor);
monthlyPower.updateAndGet(v -> v + commonServiceImpl.getSumByEquipmentIndxName(result, "月发电量") * CommonConstans.pvGenPoweActor);
annualPower.updateAndGet(v -> v + commonServiceImpl.getSumByEquipmentIndxName(result, "年发电量") * CommonConstans.pvGenPoweActor);
}
List<Map<String, Object>> finalMapList = mapList;
if ("FDZ".equals(stationBasic.getStationType())) {
dailyPower.updateAndGet(v -> v + commonServiceImpl.getTotalByIndicatior(finalMapList, "日发电量"));
monthlyPower.updateAndGet(v -> v + commonServiceImpl.getTotalByIndicatior(finalMapList, "月发电量"));
annualPower.updateAndGet(v -> v + commonServiceImpl.getTotalByIndicatior(finalMapList, "年发电量"));
} else {
dailyPower.updateAndGet(v -> v + commonServiceImpl.getTotalByIndicatior(finalMapList, "日发电量") * CommonConstans.pvGenPoweActor);
monthlyPower.updateAndGet(v -> v + commonServiceImpl.getTotalByIndicatior(finalMapList, "月发电量") * CommonConstans.pvGenPoweActor);
annualPower.updateAndGet(v -> v + commonServiceImpl.getTotalByIndicatior(finalMapList, "年发电量") * CommonConstans.pvGenPoweActor);
}
installCapacity.updateAndGet(v -> v + getStationCaPACITYL(stationBasic.getStationNumber()));
installCapacity.updateAndGet(v -> v + Double.parseDouble(stationCacheInfoDto.getInstalledCapacity()));
});
SocialContributionDto dailyPowerdto = new SocialContributionDto();
dailyPowerdto.setTitle(String.format("%.2f", dailyPower.get()));
dailyPowerdto.setTitle(String.format(CommonConstans.Twodecimalplaces, dailyPower.get()));
dailyPowerdto.setUnit("万kWh");
SocialContributionDto monthlyPowerdto = new SocialContributionDto();
monthlyPowerdto.setTitle(String.format("%.2f", monthlyPower.get()));
monthlyPowerdto.setTitle(String.format(CommonConstans.Twodecimalplaces, monthlyPower.get()));
monthlyPowerdto.setUnit("万kWh");
SocialContributionDto annualPowerdto = new SocialContributionDto();
annualPowerdto.setTitle(String.format("%.2f", annualPower.get()));
annualPowerdto.setTitle(String.format(CommonConstans.Twodecimalplaces, annualPower.get()));
annualPowerdto.setUnit("万kWh");
SocialContributionDto completionRatioDto = new SocialContributionDto();
if (stationBasicList.size() > 0) {
completionRatioDto.setTitle(String.format("%.2f", 23.21 + Math.random() * 10));
completionRatioDto.setTitle(String.format(CommonConstans.Twodecimalplaces, 23.21 + Math.random() * 10));
} else {
completionRatioDto.setTitle(completionRatio);
}
completionRatioDto.setUnit("%");
SocialContributionDto useHoursDto = new SocialContributionDto();
useHoursDto.setTitle(String.format("%.2f", annualPower.get() / installCapacity.get()));
useHoursDto.setTitle(String.format(CommonConstans.Twodecimalplaces, annualPower.get() / installCapacity.get()));
useHoursDto.setUnit("h");
socialContributionDtoList.add(dailyPowerdto);
socialContributionDtoList.add(monthlyPowerdto);
......@@ -501,19 +422,30 @@ public class MonitoringServiceImpl {
//设置场站类型
homeMapStationInfoDto.setStationType(stationBasic.getStationType());
//设置装机容量
homeMapStationInfoDto.setStationInstalledCapacity(String.format("%.2f", getStationCaPACITYL(stationBasic.getStationNumber())));
homeMapStationInfoDto.setStationInstalledCapacity(String.format(CommonConstans.Twodecimalplaces, getStationCaPACITYL(stationBasic.getStationNumber())));
//设置风速辐照度
List<Map<String, Object>> mapList;
List<Map<String, Object>> mapList1;
if (stationBasic.getStationType().equals("FDZ")) {
mapList = influxdbUtil.query("SELECT * FROM indicators_" + stationBasic.getFanGatewayId() + " where (equipmentIndexName='日发电量' or equipmentIndexName='月发电量' or equipmentIndexName='年发电量' or equipmentIndexName='有功功率' or equipmentIndexName='30秒平均风速' )");
homeMapStationInfoDto.setSpeendOrirradiate(String.valueOf(commonServiceImpl.getAvgvalueByIndicatior(mapList, "30秒平均风速")));
homeMapStationInfoDto.setCurrentPower(String.valueOf(commonServiceImpl.getTotalByIndicatior(mapList, "有功功率")));
Map<String, List<String>> queryCondtion = new HashMap<>();
queryCondtion.put(CommonConstans.QueryStringEquipmentIndexName, Arrays.asList("30秒平均风速", "有功功率"));
queryCondtion.put(CommonConstans.QueryStringGateWayId, Arrays.asList(stationBasic.getFanGatewayId()));
List<ESEquipments> result = commonServiceImpl.getListDataByCondtions(queryCondtion, null, ESEquipments.class);
homeMapStationInfoDto.setSpeendOrirradiate(String.format(CommonConstans.Twodecimalplaces, commonServiceImpl.getAvagerByEquipmentIndxName(result, "30秒平均风速")));
homeMapStationInfoDto.setCurrentPower(String.format(CommonConstans.Twodecimalplaces, commonServiceImpl.getSumByEquipmentIndxName(result, "有功功率")));
} else {
mapList = influxdbUtil.query("SELECT * FROM indicators_" + stationBasic.getFanGatewayId() + " where frontModule=~/逆变器/ and(equipmentIndexName='日发电量' or equipmentIndexName='月发电量' or equipmentIndexName='年发电量' or equipmentIndexName='有功功率')");
mapList1 = influxdbUtil.query("SELECT * FROM indicators_" + stationBasic.getBoosterGatewayId() + " where equipmentIndexName='WTX-801_25_WTX-801_总辐射'");
homeMapStationInfoDto.setSpeendOrirradiate(String.valueOf(commonServiceImpl.getTotalByIndicatior(mapList1, "WTX-801_25_WTX-801_总辐射")));
homeMapStationInfoDto.setCurrentPower(String.valueOf(commonServiceImpl.getTotalByIndicatior(mapList, "有功功率")));
Map<String, List<String>> queryCondtion = new HashMap<>();
queryCondtion.put(CommonConstans.QueryStringEquipmentIndexName, Arrays.asList("有功功率"));
queryCondtion.put(CommonConstans.QueryStringGateWayId, Arrays.asList(stationBasic.getFanGatewayId()));
Map<String, String> shouldQueryCondtion = new HashMap<>();
shouldQueryCondtion.put("frontModule", "逆变器");
Map<String, List<String>> queryCondtion1 = new HashMap<>();
queryCondtion1.put(CommonConstans.QueryStringEquipmentIndexName, Arrays.asList("WTX-801_25_WTX-801_总辐射"));
queryCondtion1.put(CommonConstans.QueryStringGateWayId, Arrays.asList(stationBasic.getBoosterGatewayId()));
List<ESEquipments> result = commonServiceImpl.getListDataByCondtions(queryCondtion, shouldQueryCondtion, ESEquipments.class);
List<ESEquipments> result1 = commonServiceImpl.getListDataByCondtions(queryCondtion1, null, ESEquipments.class);
homeMapStationInfoDto.setSpeendOrirradiate(String.format(CommonConstans.Twodecimalplaces, commonServiceImpl.getSumByEquipmentIndxName(result1, "WTX-801_25_WTX-801_总辐射")));
homeMapStationInfoDto.setCurrentPower(String.format(CommonConstans.Twodecimalplaces, commonServiceImpl.getSumByEquipmentIndxName(result, "有功功率")));
}
StationCoordinate stationCoordinate = stationCoordinateList.stream().filter(stationCoordinate1 -> stationCoordinate1.getStationId().equals(stationBasic.getSequenceNbr())).collect(Collectors.toList()).get(0);
//获取场站经纬度
......@@ -538,83 +470,36 @@ public class MonitoringServiceImpl {
}
}
});
return String.format("%.2f", total.get());
return String.format(CommonConstans.Twodecimalplaces, total.get());
}
public String getPowerOfDaily(List<StationBasic> stationBasicList) {
AtomicReference<Double> total = new AtomicReference<>(0.0);
stationBasicList.forEach(stationBasic -> {
if (stationBasic.getFanGatewayId() != null) {
try {
if ("FDZ".equals(stationBasic.getStationType())) {
total.updateAndGet(v -> v + commonServiceImpl.getTotalByIndicatior(stationBasic.getFanGatewayId(), "日发电量"));
Map<String, List<String>> queryCondtion = new HashMap<>();
queryCondtion.put(CommonConstans.QueryStringEquipmentIndexName, Arrays.asList("日发电量"));
queryCondtion.put(CommonConstans.QueryStringGateWayId, Arrays.asList(stationBasic.getFanGatewayId()));
List<ESEquipments> result = commonServiceImpl.getListDataByCondtions(queryCondtion, null, ESEquipments.class);
total.updateAndGet(v -> v + commonServiceImpl.getSumByEquipmentIndxName(result, "日发电量"));
} else {
total.updateAndGet(v -> v + commonServiceImpl.getTotalByIndicatior(stationBasic.getFanGatewayId(), "日发电量") * CommonConstans.pvGenPoweActor);
Map<String, List<String>> queryCondtion = new HashMap<>();
queryCondtion.put(CommonConstans.QueryStringEquipmentIndexName, Arrays.asList("日发电量"));
queryCondtion.put(CommonConstans.QueryStringGateWayId, Arrays.asList(stationBasic.getFanGatewayId()));
Map<String, String> shouldQueryCondtion = new HashMap<>();
shouldQueryCondtion.put("frontModule", "逆变器");
List<ESEquipments> result = commonServiceImpl.getListDataByCondtions(queryCondtion, shouldQueryCondtion, ESEquipments.class);
total.updateAndGet(v -> v + commonServiceImpl.getSumByEquipmentIndxName(result, "日发电量") * CommonConstans.pvGenPoweActor);
}
} catch (Exception e) {
}
}
});
return String.format("%.2f", total.get());
}
public List<Map<String, String>> getStaionCategoryInfo(String areaName) {
List<StationBasic> stationBasicListAll = new ArrayList<>();
List<Map<String, String>> result = new ArrayList<>();
if (!ObjectUtils.isEmpty(areaName)) {
stationBasicListAll = getListOfStationBasicByAreaName(areaName);
} else {
stationBasicListAll = stationBasicMapper.selectList(new QueryWrapper<StationBasic>().isNotNull("fan_gateway_id"));
}
Map<String, List<StationBasic>> listMap = stationBasicListAll.stream().collect(Collectors.groupingBy(stationBasic -> stationBasic.getStationTypeName()));
listMap.keySet().forEach(key -> {
Map<String, String> stringStringMap = new HashMap<>();
stringStringMap.put("name", key);
stringStringMap.put("value", String.valueOf(listMap.get(key).size()));
result.add(stringStringMap);
});
return result;
}
//获取装机容量
public HashMap<String, String> getInstallCapityByAreaName(String areaName) {
HashMap<String, String> hashMap = new HashMap<>();
AtomicReference<Double> total = new AtomicReference<>(0.0);
List<StationBasic> stationBasicListAll = new ArrayList<>();
if (!ObjectUtils.isEmpty(areaName)) {
stationBasicListAll = getListOfStationBasicByAreaName(areaName);
} else {
stationBasicListAll = stationBasicMapper.selectList(new QueryWrapper<StationBasic>().isNotNull("fan_gateway_id"));
}
stationBasicListAll.forEach(stationBasic -> {
total.updateAndGet(v -> v + getStationCaPACITYL(stationBasic.getStationNumber()));
});
hashMap.put("title", String.format("%.2f", total.get()));
return hashMap;
}
//获取有功功率
public HashMap<String, String> getActivePowerByAreaName(String areaName) {
HashMap<String, String> hashMap = new HashMap<>();
AtomicReference<Double> total = new AtomicReference<>(0.0);
List<StationBasic> stationBasicListAll = new ArrayList<>();
if (!ObjectUtils.isEmpty(areaName)) {
stationBasicListAll = getListOfStationBasicByAreaName(areaName);
} else {
stationBasicListAll = stationBasicMapper.selectList(new QueryWrapper<StationBasic>().isNotNull("fan_gateway_id"));
}
stationBasicListAll.forEach(stationBasic -> {
total.updateAndGet(v -> v + commonServiceImpl.getTotalByIndicatior(stationBasic.getFanGatewayId(), "有功功率"));
});
//有功功率换算
hashMap.put("title", String.format("%.2f", total.get()));
return hashMap;
return String.format(CommonConstans.Twodecimalplaces, total.get());
}
//获取社会贡献
/**
......@@ -638,11 +523,19 @@ public class MonitoringServiceImpl {
String finalIndicator = "年发电量";
Double total1 = 0.00;
if (!stationBasic.getStationType().equals("FDZ")) {
mapListData = influxdbUtil.query("SELECT * FROM indicators_" + stationBasic.getFanGatewayId() + " where frontModule=~/逆变器/ and (equipmentIndexName='" + finalIndicator + "' )");
total1 = commonServiceImpl.getTotalByIndicatior(mapListData, finalIndicator) * CommonConstans.pvGenPoweActor;
Map<String, List<String>> queryCondtion = new HashMap<>();
queryCondtion.put(CommonConstans.QueryStringEquipmentIndexName, Arrays.asList(finalIndicator));
queryCondtion.put(CommonConstans.QueryStringGateWayId, Arrays.asList(stationBasic.getFanGatewayId()));
Map<String, String> shouldQueryCondtion = new HashMap<>();
shouldQueryCondtion.put("frontModule", "逆变器");
List<ESEquipments> result = commonServiceImpl.getListDataByCondtions(queryCondtion, shouldQueryCondtion, ESEquipments.class);
total1 = commonServiceImpl.getSumByEquipmentIndxName(result, finalIndicator) * CommonConstans.pvGenPoweActor;
} else {
mapListData = influxdbUtil.query("SELECT * FROM indicators_" + stationBasic.getFanGatewayId() + " where (equipmentIndexName='" + finalIndicator + "' )");
total1 = commonServiceImpl.getTotalByIndicatior(mapListData, finalIndicator);
Map<String, List<String>> queryCondtion = new HashMap<>();
queryCondtion.put(CommonConstans.QueryStringEquipmentIndexName, Arrays.asList(finalIndicator));
queryCondtion.put(CommonConstans.QueryStringGateWayId, Arrays.asList(stationBasic.getFanGatewayId()));
List<ESEquipments> result = commonServiceImpl.getListDataByCondtions(queryCondtion, null, ESEquipments.class);
total1 = commonServiceImpl.getSumByEquipmentIndxName(result, finalIndicator);
}
Double finalTotal = total1;
total.updateAndGet(v -> v + finalTotal);
......@@ -664,19 +557,26 @@ public class MonitoringServiceImpl {
Double total = 0.00;
String finalIndicator = "月发电量";
if (!stationBasic.getStationType().equals("FDZ")) {
mapListData = influxdbUtil.query("SELECT * FROM indicators_" + stationBasic.getFanGatewayId() + " where frontModule=~/逆变器/ and (equipmentIndexName='" + finalIndicator + "' )");
total = commonServiceImpl.getTotalByIndicatior(mapListData, finalIndicator) * CommonConstans.pvGenPoweActor;
Map<String, List<String>> queryCondtion = new HashMap<>();
queryCondtion.put(CommonConstans.QueryStringEquipmentIndexName, Arrays.asList(finalIndicator));
queryCondtion.put(CommonConstans.QueryStringGateWayId, Arrays.asList(stationBasic.getFanGatewayId()));
Map<String, String> shouldQueryCondtion = new HashMap<>();
shouldQueryCondtion.put("frontModule", "逆变器");
List<ESEquipments> result = commonServiceImpl.getListDataByCondtions(queryCondtion, shouldQueryCondtion, ESEquipments.class);
total = commonServiceImpl.getSumByEquipmentIndxName(result, finalIndicator) * CommonConstans.pvGenPoweActor;
} else {
mapListData = influxdbUtil.query("SELECT * FROM indicators_" + stationBasic.getFanGatewayId() + " where (equipmentIndexName='" + finalIndicator + "' )");
total = commonServiceImpl.getTotalByIndicatior(mapListData, finalIndicator);
Map<String, List<String>> queryCondtion = new HashMap<>();
queryCondtion.put(CommonConstans.QueryStringEquipmentIndexName, Arrays.asList(finalIndicator));
queryCondtion.put(CommonConstans.QueryStringGateWayId, Arrays.asList(stationBasic.getFanGatewayId()));
List<ESEquipments> result = commonServiceImpl.getListDataByCondtions(queryCondtion, null, ESEquipments.class);
total = commonServiceImpl.getSumByEquipmentIndxName(result, finalIndicator);
}
Double finalTotal = total;
monthlyPower.updateAndGet(v -> v + finalTotal);
});
HashMap<String, List<String>> hashMap = new HashMap<>();
List<String> xList = getXListofRecentOneYear();
List<String> yList = Arrays.asList("0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "12000", String.format("%.2f", monthlyPower.get()));
List<String> yList = Arrays.asList("0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "12000", String.format(CommonConstans.Twodecimalplaces, monthlyPower.get()));
hashMap.put("axisData", xList);
hashMap.put("seriesData", yList);
return hashMap;
......@@ -693,31 +593,34 @@ public class MonitoringServiceImpl {
//年发电量
AtomicReference<Double> annualPower = new AtomicReference<>(0.0);
stationBasicList.forEach(stationBasic -> {
List<Map<String, Object>> mapList = new ArrayList<>();
if (stationBasic.getStationType().equals("FDZ")) {
mapList = influxdbUtil.query("SELECT * FROM indicators_" + stationBasic.getFanGatewayId() + " where (equipmentIndexName='日发电量' or equipmentIndexName='月发电量' or equipmentIndexName='年发电量' )");
} else {
mapList = influxdbUtil.query("SELECT * FROM indicators_" + stationBasic.getFanGatewayId() + " where frontModule=~/逆变器/ and (equipmentIndexName='日发电量' or equipmentIndexName='月发电量' or equipmentIndexName='年发电量' )");
}
List<Map<String, Object>> finalMapList = mapList;
if ("FDZ".equals(stationBasic.getStationType())) {
dailyPower.updateAndGet(v -> v + commonServiceImpl.getTotalByIndicatior(finalMapList, "日发电量"));
monthlyPower.updateAndGet(v -> v + commonServiceImpl.getTotalByIndicatior(finalMapList, "月发电量"));
annualPower.updateAndGet(v -> v + commonServiceImpl.getTotalByIndicatior(finalMapList, "年发电量"));
Map<String, List<String>> queryCondtion = new HashMap<>();
queryCondtion.put(CommonConstans.QueryStringEquipmentIndexName, Arrays.asList("日发电量", "月发电量", "年发电量"));
queryCondtion.put(CommonConstans.QueryStringGateWayId, Arrays.asList(stationBasic.getFanGatewayId()));
Map<String, String> shouldQueryCondtion = new HashMap<>();
shouldQueryCondtion.put("frontModule", "逆变器");
List<ESEquipments> result = commonServiceImpl.getListDataByCondtions(queryCondtion, shouldQueryCondtion, ESEquipments.class);
dailyPower.updateAndGet(v -> v + commonServiceImpl.getSumByEquipmentIndxName(result, "日发电量"));
monthlyPower.updateAndGet(v -> v + commonServiceImpl.getSumByEquipmentIndxName(result, "月发电量"));
annualPower.updateAndGet(v -> v + commonServiceImpl.getSumByEquipmentIndxName(result, "年发电量"));
} else {
dailyPower.updateAndGet(v -> v + commonServiceImpl.getTotalByIndicatior(finalMapList, "日发电量") * CommonConstans.pvGenPoweActor);
monthlyPower.updateAndGet(v -> v + commonServiceImpl.getTotalByIndicatior(finalMapList, "月发电量") * CommonConstans.pvGenPoweActor);
annualPower.updateAndGet(v -> v + commonServiceImpl.getTotalByIndicatior(finalMapList, "年发电量") * CommonConstans.pvGenPoweActor);
Map<String, List<String>> queryCondtion = new HashMap<>();
queryCondtion.put(CommonConstans.QueryStringEquipmentIndexName, Arrays.asList("日发电量", "月发电量", "年发电量"));
queryCondtion.put(CommonConstans.QueryStringGateWayId, Arrays.asList(stationBasic.getFanGatewayId()));
List<ESEquipments> result = commonServiceImpl.getListDataByCondtions(queryCondtion, null, ESEquipments.class);
dailyPower.updateAndGet(v -> v + commonServiceImpl.getSumByEquipmentIndxName(result, "日发电量") * CommonConstans.pvGenPoweActor);
monthlyPower.updateAndGet(v -> v + commonServiceImpl.getSumByEquipmentIndxName(result, "月发电量") * CommonConstans.pvGenPoweActor);
annualPower.updateAndGet(v -> v + commonServiceImpl.getSumByEquipmentIndxName(result, "年发电量") * CommonConstans.pvGenPoweActor);
}
});
HashMap<String, String> dayHashMap = new HashMap<>();
dayHashMap.put("title", String.format("%.2f", dailyPower.get()) + "万KWh");
dayHashMap.put("title", String.format(CommonConstans.Twodecimalplaces, dailyPower.get()) + "万KWh");
HashMap<String, String> monthHashMap = new HashMap<>();
monthHashMap.put("title", String.format("%.2f", monthlyPower.get()) + "万KWh");
monthHashMap.put("title", String.format(CommonConstans.Twodecimalplaces, monthlyPower.get()) + "万KWh");
HashMap<String, String> annualHashMap = new HashMap<>();
annualHashMap.put("title", String.format("%.2f", annualPower.get()) + "万KWh");
annualHashMap.put("title", String.format(CommonConstans.Twodecimalplaces, annualPower.get()) + "万KWh");
HashMap<String, String> totalHashMap = new HashMap<>();
totalHashMap.put("title", String.format("%.2f", annualPower.get()) + "万KWh");
totalHashMap.put("title", String.format(CommonConstans.Twodecimalplaces, annualPower.get()) + "万KWh");
hashMapList.add(dayHashMap);
hashMapList.add(monthHashMap);
hashMapList.add(annualHashMap);
......@@ -755,18 +658,26 @@ public class MonitoringServiceImpl {
String finalIndicator = "月发电量";
Double total = 0.00;
if (!stationBasic.getStationType().equals("FDZ")) {
mapListData = influxdbUtil.query("SELECT * FROM indicators_" + stationBasic.getFanGatewayId() + " where frontModule=~/逆变器/ and (equipmentIndexName='" + finalIndicator + "' )");
total = commonServiceImpl.getTotalByIndicatior(mapListData, finalIndicator) * CommonConstans.pvGenPoweActor;
Map<String, List<String>> queryCondtion = new HashMap<>();
queryCondtion.put(CommonConstans.QueryStringEquipmentIndexName, Arrays.asList(finalIndicator));
queryCondtion.put(CommonConstans.QueryStringGateWayId, Arrays.asList(stationBasic.getFanGatewayId()));
Map<String, String> shouldQueryCondtion = new HashMap<>();
shouldQueryCondtion.put("frontModule", "逆变器");
List<ESEquipments> result = commonServiceImpl.getListDataByCondtions(queryCondtion, shouldQueryCondtion, ESEquipments.class);
total = commonServiceImpl.getSumByEquipmentIndxName(result, finalIndicator) * CommonConstans.pvGenPoweActor;
} else {
mapListData = influxdbUtil.query("SELECT * FROM indicators_" + stationBasic.getFanGatewayId() + " where (equipmentIndexName='" + finalIndicator + "' )");
total = commonServiceImpl.getTotalByIndicatior(mapListData, finalIndicator);
Map<String, List<String>> queryCondtion = new HashMap<>();
queryCondtion.put(CommonConstans.QueryStringEquipmentIndexName, Arrays.asList(finalIndicator));
queryCondtion.put(CommonConstans.QueryStringGateWayId, Arrays.asList(stationBasic.getFanGatewayId()));
List<ESEquipments> result = commonServiceImpl.getListDataByCondtions(queryCondtion, null, ESEquipments.class);
total = commonServiceImpl.getSumByEquipmentIndxName(result, finalIndicator);
}
Double finalTotal = total;
monthlyPower.updateAndGet(v -> v + finalTotal);
});
HashMap<String, List<String>> hashMap = new HashMap<>();
List<String> xList = getXListofRecentOneYear();
List<String> yList = Arrays.asList("0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "120", String.format("%.2f", monthlyPower.get() % 200));
List<String> yList = Arrays.asList("0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "120", String.format(CommonConstans.Twodecimalplaces, monthlyPower.get() % 200));
hashMap.put("axisData", xList);
hashMap.put("seriesData", yList);
return hashMap;
......@@ -791,14 +702,22 @@ public class MonitoringServiceImpl {
stationBasicListAll.forEach(stationBasic -> {
List<Map<String, Object>> mapListData = new ArrayList<>();
if (!stationBasic.getStationType().equals("FDZ")) {
mapListData = influxdbUtil.query("SELECT * FROM indicators_" + stationBasic.getFanGatewayId() + " where frontModule=~/逆变器/ and (equipmentIndexName='" + finalIndicator + "' )");
total.set(commonServiceImpl.getTotalByIndicatior(mapListData, finalIndicator) * CommonConstans.pvGenPoweActor);
Map<String, List<String>> queryCondtion = new HashMap<>();
queryCondtion.put(CommonConstans.QueryStringEquipmentIndexName, Arrays.asList(finalIndicator));
queryCondtion.put(CommonConstans.QueryStringGateWayId, Arrays.asList(stationBasic.getFanGatewayId()));
Map<String, String> shouldQueryCondtion = new HashMap<>();
shouldQueryCondtion.put("frontModule", "逆变器");
List<ESEquipments> result = commonServiceImpl.getListDataByCondtions(queryCondtion, shouldQueryCondtion, ESEquipments.class);
total.set(commonServiceImpl.getSumByEquipmentIndxName(result, finalIndicator) * CommonConstans.pvGenPoweActor);
} else {
mapListData = influxdbUtil.query("SELECT * FROM indicators_" + stationBasic.getFanGatewayId() + " where (equipmentIndexName='" + finalIndicator + "' )");
total.set(commonServiceImpl.getTotalByIndicatior(mapListData, finalIndicator));
Map<String, List<String>> queryCondtion = new HashMap<>();
queryCondtion.put(CommonConstans.QueryStringEquipmentIndexName, Arrays.asList(finalIndicator));
queryCondtion.put(CommonConstans.QueryStringGateWayId, Arrays.asList(stationBasic.getFanGatewayId()));
List<ESEquipments> result = commonServiceImpl.getListDataByCondtions(queryCondtion, null, ESEquipments.class);
total.set(commonServiceImpl.getSumByEquipmentIndxName(result, finalIndicator));
}
stationBasic.setAddress(String.format("%.2f", total.get() % 100));
stationBasic.setAddress(String.format(CommonConstans.Twodecimalplaces, total.get() % 100));
});
List<StationBasic> sorted = stationBasicListAll.stream().sorted(Comparator.comparing(StationBasic::getAddress, Comparator.comparingDouble(Double::parseDouble)).reversed()).collect(Collectors.toList());
sorted.forEach(stationBasic -> {
......@@ -850,13 +769,21 @@ public class MonitoringServiceImpl {
Double total = 0.00;
List<Map<String, Object>> mapListData = new ArrayList<>();
if (!stationBasic.getStationType().equals("FDZ")) {
mapListData = influxdbUtil.query("SELECT * FROM indicators_" + stationBasic.getFanGatewayId() + " where frontModule=~/逆变器/ and (equipmentIndexName='" + finalIndicator + "' )");
total = commonServiceImpl.getTotalByIndicatior(mapListData, finalIndicator) * CommonConstans.pvGenPoweActor;
Map<String,List<String>> queryCondtion = new HashMap<>();
queryCondtion.put(CommonConstans.QueryStringEquipmentIndexName,Arrays.asList(finalIndicator));
queryCondtion.put(CommonConstans.QueryStringGateWayId,Arrays.asList(stationBasic.getFanGatewayId()));
Map<String,String> shouldQueryCondtion = new HashMap<>();
shouldQueryCondtion.put("frontModule","逆变器");
List<ESEquipments> result = commonServiceImpl.getListDataByCondtions(queryCondtion,shouldQueryCondtion,ESEquipments.class);
total = commonServiceImpl.getSumByEquipmentIndxName(result, finalIndicator) * CommonConstans.pvGenPoweActor;
} else {
mapListData = influxdbUtil.query("SELECT * FROM indicators_" + stationBasic.getFanGatewayId() + " where (equipmentIndexName='" + finalIndicator + "' )");
total = commonServiceImpl.getTotalByIndicatior(mapListData, finalIndicator);
Map<String,List<String>> queryCondtion = new HashMap<>();
queryCondtion.put(CommonConstans.QueryStringEquipmentIndexName,Arrays.asList(finalIndicator));
queryCondtion.put(CommonConstans.QueryStringGateWayId,Arrays.asList(stationBasic.getFanGatewayId()));
List<ESEquipments> result = commonServiceImpl.getListDataByCondtions(queryCondtion,null,ESEquipments.class);
total = commonServiceImpl.getSumByEquipmentIndxName(result, finalIndicator) * CommonConstans.pvGenPoweActor;
}
stationBasic.setAddress(String.format("%.2f", (total * 10) / install));
stationBasic.setAddress(String.format(CommonConstans.Twodecimalplaces, (total * 10) / install));
if (stationBasic.getAddress().equals("NaN")) {
stationBasic.setAddress("0.00");
}
......@@ -941,63 +868,69 @@ public class MonitoringServiceImpl {
AtomicReference<Double> powerOfMonthGF = new AtomicReference<>(new Double(0.00));
AtomicReference<Double> powerOfAnnualGF = new AtomicReference<>(new Double(0.00));
fdzList.forEach(stationBasic -> {
List<Map<String, Object>> mapList;
mapList = influxdbUtil.query("SELECT * FROM indicators_" + stationBasic.getFanGatewayId() + " where (equipmentIndexName='日发电量' or equipmentIndexName='月发电量' or equipmentIndexName='年发电量' )");
powerOfDayFD.updateAndGet(v -> v + commonServiceImpl.getTotalByIndicatior(mapList, "日发电量"));
powerOfMonthFD.updateAndGet(v -> v + commonServiceImpl.getTotalByIndicatior(mapList, "月发电量"));
powerOfAnnualFD.updateAndGet(v -> v + commonServiceImpl.getTotalByIndicatior(mapList, "年发电量"));
Map<String,List<String>> queryCondtion = new HashMap<>();
queryCondtion.put(CommonConstans.QueryStringEquipmentIndexName,Arrays.asList("日发电量","月发电量","年发电量"));
queryCondtion.put(CommonConstans.QueryStringGateWayId,Arrays.asList(stationBasic.getFanGatewayId()));
List<ESEquipments> result = commonServiceImpl.getListDataByCondtions(queryCondtion,null,ESEquipments.class);
powerOfDayFD.updateAndGet(v -> v + commonServiceImpl.getSumByEquipmentIndxName(result, "日发电量"));
powerOfMonthFD.updateAndGet(v -> v + commonServiceImpl.getSumByEquipmentIndxName(result, "月发电量"));
powerOfAnnualFD.updateAndGet(v -> v + commonServiceImpl.getSumByEquipmentIndxName(result, "年发电量"));
});
gfList.forEach(stationBasic -> {
List<Map<String, Object>> mapList;
mapList = influxdbUtil.query("SELECT * FROM indicators_" + stationBasic.getFanGatewayId() + " where frontModule=~/逆变器/ and (equipmentIndexName='日发电量' or equipmentIndexName='月发电量' or equipmentIndexName='年发电量' )");
powerOfDayGF.updateAndGet(v -> v + commonServiceImpl.getTotalByIndicatior(mapList, "日发电量"));
powerOfMonthGF.updateAndGet(v -> v + commonServiceImpl.getTotalByIndicatior(mapList, "月发电量"));
powerOfAnnualGF.updateAndGet(v -> v + commonServiceImpl.getTotalByIndicatior(mapList, "年发电量"));
Map<String,List<String>> queryCondtion = new HashMap<>();
queryCondtion.put(CommonConstans.QueryStringEquipmentIndexName,Arrays.asList("日发电量","月发电量","年发电量"));
queryCondtion.put(CommonConstans.QueryStringGateWayId,Arrays.asList(stationBasic.getFanGatewayId()));
Map<String,String> shouldQueryCondtion = new HashMap<>();
shouldQueryCondtion.put("frontModule","逆变器");
List<ESEquipments> result = commonServiceImpl.getListDataByCondtions(queryCondtion,shouldQueryCondtion,ESEquipments.class);
powerOfDayGF.updateAndGet(v -> v + commonServiceImpl.getSumByEquipmentIndxName(result, "日发电量"));
powerOfMonthGF.updateAndGet(v -> v + commonServiceImpl.getSumByEquipmentIndxName(result, "月发电量"));
powerOfAnnualGF.updateAndGet(v -> v + commonServiceImpl.getSumByEquipmentIndxName(result, "年发电量"));
});
HashMap<String, String> stringHashMap4 = new HashMap<>();
stringHashMap4.put("title", String.format("%.2f", powerOfDayFD.get()) + "/" + String.format("%.2f", powerOfDayGF.get() * CommonConstans.pvGenPoweActor));
stringHashMap4.put("title", String.format(CommonConstans.Twodecimalplaces, powerOfDayFD.get()) + "/" + String.format(CommonConstans.Twodecimalplaces, powerOfDayGF.get() * CommonConstans.pvGenPoweActor));
list1.add(stringHashMap4);
HashMap<String, String> stringHashMap5 = new HashMap<>();
stringHashMap5.put("title", String.format("%.2f", powerOfMonthFD.get()) + "/" + String.format("%.2f", powerOfMonthGF.get() * CommonConstans.pvGenPoweActor));
stringHashMap5.put("title", String.format(CommonConstans.Twodecimalplaces, powerOfMonthFD.get()) + "/" + String.format(CommonConstans.Twodecimalplaces, powerOfMonthGF.get() * CommonConstans.pvGenPoweActor));
list1.add(stringHashMap5);
HashMap<String, String> stringHashMap6 = new HashMap<>();
stringHashMap6.put("title", String.format("%.2f", powerOfAnnualFD.get()) + "/" + String.format("%.2f", powerOfAnnualGF.get() * CommonConstans.pvGenPoweActor));
stringHashMap6.put("title", String.format(CommonConstans.Twodecimalplaces, powerOfAnnualFD.get()) + "/" + String.format(CommonConstans.Twodecimalplaces, powerOfAnnualGF.get() * CommonConstans.pvGenPoweActor));
list1.add(stringHashMap6);
HashMap<String, String> stringHashMap7 = new HashMap<>();
stringHashMap7.put("title", String.format("%.2f", powerOfAnnualFD.get() % 200) + "/" + String.format("%.2f", powerOfAnnualGF.get() % 200));
stringHashMap7.put("title", String.format(CommonConstans.Twodecimalplaces, powerOfAnnualFD.get() % 200) + "/" + String.format(CommonConstans.Twodecimalplaces, powerOfAnnualGF.get() % 200));
list1.add(stringHashMap7);
HashMap<String, String> stringHashMap8 = new HashMap<>();
stringHashMap8.put("title", String.format("%.2f", (powerOfAnnualFD.get() * CommonConstans.wkwhToMv) / fdzInstall.doubleValue()) + "/" + String.format("%.2f", (powerOfAnnualGF.get() * CommonConstans.pvGenPoweActor * CommonConstans.wkwhToMv) / gfInstall.doubleValue()));
stringHashMap8.put("title", String.format(CommonConstans.Twodecimalplaces, (powerOfAnnualFD.get() * CommonConstans.wkwhToMv) / fdzInstall.doubleValue()) + "/" + String.format(CommonConstans.Twodecimalplaces, (powerOfAnnualGF.get() * CommonConstans.pvGenPoweActor * CommonConstans.wkwhToMv) / gfInstall.doubleValue()));
list1.add(stringHashMap8);
page1.setRecords(list1);
HashMap<String, String> stringHashMap9 = new HashMap<>();
stringHashMap9.put("title", String.format("%.2f", powerOfDayFD.get() + powerOfDayGF.get() * CommonConstans.pvGenPoweActor));
stringHashMap9.put("title", String.format(CommonConstans.Twodecimalplaces, powerOfDayFD.get() + powerOfDayGF.get() * CommonConstans.pvGenPoweActor));
list2.add(stringHashMap9);
HashMap<String, String> stringHashMap10 = new HashMap<>();
stringHashMap10.put("title", String.format("%.2f", powerOfMonthFD.get() + powerOfMonthGF.get() * CommonConstans.pvGenPoweActor));
stringHashMap10.put("title", String.format(CommonConstans.Twodecimalplaces, powerOfMonthFD.get() + powerOfMonthGF.get() * CommonConstans.pvGenPoweActor));
list2.add(stringHashMap10);
HashMap<String, String> stringHashMap11 = new HashMap<>();
stringHashMap11.put("title", String.format("%.2f", powerOfAnnualFD.get() + powerOfAnnualGF.get() * CommonConstans.pvGenPoweActor));
stringHashMap11.put("title", String.format(CommonConstans.Twodecimalplaces, powerOfAnnualFD.get() + powerOfAnnualGF.get() * CommonConstans.pvGenPoweActor));
list2.add(stringHashMap11);
HashMap<String, String> stringHashMap12 = new HashMap<>();
stringHashMap12.put("title", String.format("%.2f", (powerOfAnnualFD.get() % 200 + powerOfAnnualGF.get() % 200) / 2));
stringHashMap12.put("title", String.format(CommonConstans.Twodecimalplaces, (powerOfAnnualFD.get() % 200 + powerOfAnnualGF.get() % 200) / 2));
list2.add(stringHashMap12);
page2.setRecords(list2);
Double totalAnnual = (powerOfAnnualFD.get() + powerOfAnnualGF.get() * CommonConstans.pvGenPoweActor);
HashMap<String, String> stringHashMap13 = new HashMap<>();
stringHashMap13.put("title1", String.format("%.2f", (totalAnnual * CommonConstans.carbonDioxide)));
stringHashMap13.put("title1", String.format(CommonConstans.Twodecimalplaces, (totalAnnual * CommonConstans.carbonDioxide)));
stringHashMap13.put("title2", "二氧化碳减排量(万t)");
list3.add(stringHashMap13);
HashMap<String, String> stringHashMap14 = new HashMap<>();
stringHashMap14.put("title1", String.format("%.2f", (totalAnnual * CommonConstans.standardCoal)));
stringHashMap14.put("title1", String.format(CommonConstans.Twodecimalplaces, (totalAnnual * CommonConstans.standardCoal)));
stringHashMap14.put("title2", "节约标准煤(万t)");
list3.add(stringHashMap14);
HashMap<String, String> stringHashMap15 = new HashMap<>();
stringHashMap15.put("title1", String.format("%.2f", (totalAnnual * CommonConstans.toner * CommonConstans.tToWT)));
stringHashMap15.put("title1", String.format(CommonConstans.Twodecimalplaces, (totalAnnual * CommonConstans.toner * CommonConstans.tToWT)));
stringHashMap15.put("title2", "碳粉尘减排量(万t)");
list3.add(stringHashMap15);
HashMap<String, String> stringHashMap16 = new HashMap<>();
stringHashMap16.put("title1", String.format("%.2f", (totalAnnual * CommonConstans.sulfurDioxide * CommonConstans.tToWT)));
stringHashMap16.put("title1", String.format(CommonConstans.Twodecimalplaces, (totalAnnual * CommonConstans.sulfurDioxide * CommonConstans.tToWT)));
stringHashMap16.put("title2", "二氧化硫减排量(万t)");
list3.add(stringHashMap16);
page3.setRecords(list3);
......@@ -1017,11 +950,19 @@ public class MonitoringServiceImpl {
stationBasicListAll.forEach(stationBasic -> {
List<Map<String, Object>> mapList;
if (stationBasic.getStationType().equals("FDZ")) {
mapList = influxdbUtil.query("SELECT * FROM indicators_" + stationBasic.getFanGatewayId() + " where (equipmentIndexName='日发电量' or equipmentIndexName='月发电量' or equipmentIndexName='年发电量' )");
stationBasic.setAddress(String.format("%.2f", commonServiceImpl.getTotalByIndicatior(mapList, "年发电量")));
Map<String,List<String>> queryCondtion = new HashMap<>();
queryCondtion.put(CommonConstans.QueryStringEquipmentIndexName,Arrays.asList("年发电量"));
queryCondtion.put(CommonConstans.QueryStringGateWayId,Arrays.asList(stationBasic.getFanGatewayId()));
List<ESEquipments> result = commonServiceImpl.getListDataByCondtions(queryCondtion,null,ESEquipments.class);
stationBasic.setAddress(String.format(CommonConstans.Twodecimalplaces, commonServiceImpl.getSumByEquipmentIndxName(result, "年发电量")));
} else {
mapList = influxdbUtil.query("SELECT * FROM indicators_" + stationBasic.getFanGatewayId() + " where frontModule=~/逆变器/ and (equipmentIndexName='日发电量' or equipmentIndexName='月发电量' or equipmentIndexName='年发电量' )");
stationBasic.setAddress(String.format("%.2f", commonServiceImpl.getTotalByIndicatior(mapList, "年发电量") * CommonConstans.pvGenPoweActor));
Map<String,List<String>> queryCondtion = new HashMap<>();
queryCondtion.put(CommonConstans.QueryStringEquipmentIndexName,Arrays.asList("年发电量"));
queryCondtion.put(CommonConstans.QueryStringGateWayId,Arrays.asList(stationBasic.getFanGatewayId()));
Map<String,String> shouldQueryCondtion = new HashMap<>();
shouldQueryCondtion.put("frontModule","逆变器");
List<ESEquipments> result = commonServiceImpl.getListDataByCondtions(queryCondtion,shouldQueryCondtion,ESEquipments.class);
stationBasic.setAddress(String.format(CommonConstans.Twodecimalplaces, commonServiceImpl.getSumByEquipmentIndxName(result, "年发电量") * CommonConstans.pvGenPoweActor));
}
});
List<StationBasic> fdzList = stationBasicListAll.stream().filter(stationBasic -> stationBasic.getStationType().equals("FDZ")).collect(Collectors.toList());
......@@ -1099,9 +1040,9 @@ public class MonitoringServiceImpl {
for (int i = 0; i < 25; i++) {
xdata.add(String.format("%02d", i) + ":00");
Random random = new Random();
currentPowerYdata.add(String.format("%.2f", random.nextDouble() * 30));
shortPowerYdata.add(String.format("%.2f", random.nextDouble() * 40));
superPowerShortYdata.add(String.format("%.2f", random.nextDouble() * 50));
currentPowerYdata.add(String.format(CommonConstans.Twodecimalplaces, random.nextDouble() * 30));
shortPowerYdata.add(String.format(CommonConstans.Twodecimalplaces, random.nextDouble() * 40));
superPowerShortYdata.add(String.format(CommonConstans.Twodecimalplaces, random.nextDouble() * 50));
}
result.put("xData", xdata);
HashMap<String, Object> currentPowerHashMap = new HashMap<>();
......@@ -1117,9 +1058,9 @@ public class MonitoringServiceImpl {
superShortPowerHashMap.put("yData", superPowerShortYdata);
result.put("superShortPower", superShortPowerHashMap);
HashMap<String, Object> footerList = new HashMap<>();
String currentMin = String.format("%.2f", currentPowerYdata.stream().mapToDouble(Double::parseDouble).min().getAsDouble());
String shortMin = String.format("%.2f", shortPowerYdata.stream().mapToDouble(Double::parseDouble).min().getAsDouble());
String supreMin = String.format("%.2f", superPowerShortYdata.stream().mapToDouble(Double::parseDouble).min().getAsDouble());
String currentMin = String.format(CommonConstans.Twodecimalplaces, currentPowerYdata.stream().mapToDouble(Double::parseDouble).min().getAsDouble());
String shortMin = String.format(CommonConstans.Twodecimalplaces, shortPowerYdata.stream().mapToDouble(Double::parseDouble).min().getAsDouble());
String supreMin = String.format(CommonConstans.Twodecimalplaces, superPowerShortYdata.stream().mapToDouble(Double::parseDouble).min().getAsDouble());
List<String> gz = new ArrayList<>();
List<String> sj1 = new ArrayList<>();
gz.add(currentMin);
......@@ -1129,9 +1070,9 @@ public class MonitoringServiceImpl {
gz.add(supreMin);
sj1.add(xdata.get(superPowerShortYdata.indexOf(supreMin)));
String currentMax = String.format("%.2f", currentPowerYdata.stream().mapToDouble(Double::parseDouble).max().getAsDouble());
String shortMax = String.format("%.2f", shortPowerYdata.stream().mapToDouble(Double::parseDouble).max().getAsDouble());
String supreMax = String.format("%.2f", superPowerShortYdata.stream().mapToDouble(Double::parseDouble).max().getAsDouble());
String currentMax = String.format(CommonConstans.Twodecimalplaces, currentPowerYdata.stream().mapToDouble(Double::parseDouble).max().getAsDouble());
String shortMax = String.format(CommonConstans.Twodecimalplaces, shortPowerYdata.stream().mapToDouble(Double::parseDouble).max().getAsDouble());
String supreMax = String.format(CommonConstans.Twodecimalplaces, superPowerShortYdata.stream().mapToDouble(Double::parseDouble).max().getAsDouble());
List<String> zdz = new ArrayList<>();
List<String> sj2 = new ArrayList<>();
zdz.add(currentMax);
......@@ -1140,9 +1081,9 @@ public class MonitoringServiceImpl {
sj2.add(xdata.get(currentPowerYdata.indexOf(currentMax)));
sj2.add(xdata.get(shortPowerYdata.indexOf(shortMax)));
sj2.add(xdata.get(superPowerShortYdata.indexOf(supreMax)));
String currentAvg = String.format("%.2f", currentPowerYdata.stream().mapToDouble(Double::parseDouble).average().getAsDouble());
String shortAvg = String.format("%.2f", shortPowerYdata.stream().mapToDouble(Double::parseDouble).average().getAsDouble());
String supreAvg = String.format("%.2f", superPowerShortYdata.stream().mapToDouble(Double::parseDouble).average().getAsDouble());
String currentAvg = String.format(CommonConstans.Twodecimalplaces, currentPowerYdata.stream().mapToDouble(Double::parseDouble).average().getAsDouble());
String shortAvg = String.format(CommonConstans.Twodecimalplaces, shortPowerYdata.stream().mapToDouble(Double::parseDouble).average().getAsDouble());
String supreAvg = String.format(CommonConstans.Twodecimalplaces, superPowerShortYdata.stream().mapToDouble(Double::parseDouble).average().getAsDouble());
List<String> pjz = new ArrayList<>();
List<String> fjl = new ArrayList<>();
pjz.add(currentAvg);
......@@ -1160,9 +1101,66 @@ public class MonitoringServiceImpl {
return result;
}
public HashMap<String,String> getSecDays(String secStartDate) {
HashMap<String,String> result = new HashMap<>();
result.put("title",String.valueOf(DateUtil.between(DateUtil.parse(secStartDate), DateUtil.date(), DateUnit.DAY)));
public HashMap<String, String> getSecDays(String secStartDate) {
HashMap<String, String> result = new HashMap<>();
result.put("title", String.valueOf(DateUtil.between(DateUtil.parse(secStartDate), DateUtil.date(), DateUnit.DAY)));
return result;
}
public List<Map<String, String>> getStaionCategoryInfo(String areaName) {
List<StationBasic> stationBasicListAll = new ArrayList<>();
List<Map<String, String>> result = new ArrayList<>();
if (!ObjectUtils.isEmpty(areaName)) {
stationBasicListAll = getListOfStationBasicByAreaName(areaName);
} else {
stationBasicListAll = stationBasicMapper.selectList(new QueryWrapper<StationBasic>().isNotNull("fan_gateway_id"));
}
Map<String, List<StationBasic>> listMap = stationBasicListAll.stream().collect(Collectors.groupingBy(stationBasic -> stationBasic.getStationTypeName()));
listMap.keySet().forEach(key -> {
Map<String, String> stringStringMap = new HashMap<>();
stringStringMap.put("name", key);
stringStringMap.put("value", String.valueOf(listMap.get(key).size()));
result.add(stringStringMap);
});
return result;
}
//获取装机容量
public HashMap<String, String> getInstallCapityByAreaName(String areaName) {
HashMap<String, String> hashMap = new HashMap<>();
AtomicReference<Double> total = new AtomicReference<>(0.0);
List<StationBasic> stationBasicListAll = new ArrayList<>();
if (!ObjectUtils.isEmpty(areaName)) {
stationBasicListAll = getListOfStationBasicByAreaName(areaName);
} else {
stationBasicListAll = stationBasicMapper.selectList(new QueryWrapper<StationBasic>().isNotNull("fan_gateway_id"));
}
stationBasicListAll.forEach(stationBasic -> {
total.updateAndGet(v -> v + getStationCaPACITYL(stationBasic.getStationNumber()));
});
hashMap.put("title", String.format(CommonConstans.Twodecimalplaces, total.get()));
return hashMap;
}
//获取有功功率
public HashMap<String, String> getActivePowerByAreaName(String areaName) {
HashMap<String, String> hashMap = new HashMap<>();
AtomicReference<Double> total = new AtomicReference<>(0.0);
List<StationBasic> stationBasicListAll = new ArrayList<>();
Map<String,List<String>> queryCondtion = new HashMap<>();
if (!ObjectUtils.isEmpty(areaName)) {
stationBasicListAll = getListOfStationBasicByAreaName(areaName);
} else {
stationBasicListAll = stationBasicMapper.selectList(new QueryWrapper<StationBasic>().isNotNull("fan_gateway_id"));
}
stationBasicListAll.forEach(stationBasic -> {
queryCondtion.put(CommonConstans.QueryStringGateWayId,Arrays.asList(stationBasic.getFanGatewayId()));
queryCondtion.put(CommonConstans.QueryStringEquipmentIndexName,Arrays.asList("有功功率"));
List<ESEquipments> esEquipmentsList = commonServiceImpl.getListDataByCondtions(queryCondtion,null,ESEquipments.class);
total.updateAndGet(v -> v + commonServiceImpl.getSumByEquipmentIndxName(esEquipmentsList,"有功功率"));
});
//有功功率换算
hashMap.put("title", String.format(CommonConstans.Twodecimalplaces, total.get()));
return hashMap;
}
}
package com.yeejoin.amos.boot.module.jxiop.biz.service.impl;
import com.yeejoin.amos.boot.module.jxiop.api.dto.IndexDto;
import com.yeejoin.amos.boot.module.jxiop.biz.ESDto.ESDailyPowerGeneration;
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.StationCacheInfoDto;
import com.yeejoin.amos.boot.module.jxiop.biz.repository.ESDailyPowerGenerationRepository;
import com.yeejoin.amos.boot.module.jxiop.biz.repository.ESEquipmentsRepository;
import com.yeejoin.amos.boot.module.jxiop.biz.repository.ESMoonPowerGenerationRepository;
import com.yeejoin.amos.boot.module.jxiop.biz.repository.ESYearPowerGenerationRepository;
import com.yeejoin.amos.boot.module.jxiop.biz.utils.InfluxDButils;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import java.text.SimpleDateFormat;
import java.util.*;
/**
* @description:
* @author: tw
* @createDate: 2023/8/9
*/
@Service
public class PowerGenerationImpl {
@Autowired
InfluxDButils influxDButils;
@Autowired
private ElasticsearchRestTemplate elasticsearchTemplate;
@Autowired
ESYearPowerGenerationRepository yearPowerGenerationRepository;
@Autowired
ESMoonPowerGenerationRepository moonPowerGenerationRepository;
@Autowired
ESDailyPowerGenerationRepository dailyPowerGenerationRepository;
//获取指定指标,当天最后一条数据
public List<IndexDto> getlast(String gatewayId, String value,String daty){
IndexDto indexDto=null;
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);
return queryList;
}
public List<IndexDto> getlastgf(String gatewayId, String value,String daty){
IndexDto indexDto=null;
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);
return queryList;
}
//更新es 数据
//@Async("jxiopAsyncExecutor")
public void addPowerGeneration(StationCacheInfoDto stationCacheInfoDto,String gatewayId, String value, String dateFormat, String type, String stationType,String datyvalue){
//获取指标值
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);
Date now=new Date();
String daty= myFmt2.format(now);
this.PowerGeneration(stationCacheInfoDto,indexDto,daty,type);
}
//更新es
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);
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),monthy);
dailyPowerGenerationRepository.saveAll(listd);
break;
case "moon":
List<ESMoonPowerGeneration> listm= this.getESMoonPowerGeneration(stationCacheInfoDto,indexDto,daty,String.valueOf(month),yeary);
moonPowerGenerationRepository.saveAll(listm);
break;
case "year":
List<ESYearPowerGeneration> listy= this.getESYearPowerGeneration(stationCacheInfoDto,indexDto,daty,String.valueOf(year));
yearPowerGenerationRepository.saveAll(listy);
break;
default:
break;
}
}
// 组装数据
public List<ESDailyPowerGeneration> getESDailyPowerGeneration(StationCacheInfoDto stationCacheInfoDto,List<IndexDto> indexDto,String daty,String day,String month){
List<ESDailyPowerGeneration> list=new ArrayList<>();
if(indexDto!=null&&!indexDto.isEmpty()){
for (IndexDto dto : indexDto) {
ESDailyPowerGeneration dailyPowerGeneration=new ESDailyPowerGeneration(
daty+"_"+dto.getAddress(),
stationCacheInfoDto.getStationId(),
stationCacheInfoDto.getStationName(),
stationCacheInfoDto.getStationType(),
stationCacheInfoDto.getBelongProvince(),
stationCacheInfoDto.getBelongArea(),
day,
dto.getGatewayId(),
new Date(),
dto.getValue()!=null?Double.valueOf(dto.getValue()):null,
dto.getEquipmentIndexName(),
dto.getEquipmentNumber(),
dto.getAddress(),
month
);
list.add(dailyPowerGeneration);
}
}
return list;
}
public List<ESMoonPowerGeneration> getESMoonPowerGeneration(StationCacheInfoDto stationCacheInfoDto,List<IndexDto> indexDto,String daty,String day,String year){
List<ESMoonPowerGeneration> list=new ArrayList<>();
if(indexDto!=null&&!indexDto.isEmpty()){
for (IndexDto dto : indexDto) {
ESMoonPowerGeneration moonPowerGeneration=new ESMoonPowerGeneration(
daty+"_"+dto.getAddress(),
stationCacheInfoDto.getStationId(),
stationCacheInfoDto.getStationName(),
stationCacheInfoDto.getStationType(),
stationCacheInfoDto.getBelongProvince(),
stationCacheInfoDto.getBelongArea(),
day,
dto.getGatewayId(),
new Date(),
dto.getValue()!=null?Double.valueOf(dto.getValue()):null,
dto.getEquipmentIndexName(),
dto.getEquipmentNumber(),
dto.getAddress(),
year
);
list.add(moonPowerGeneration);
}
}
return list;
}
public List<ESYearPowerGeneration> getESYearPowerGeneration(StationCacheInfoDto stationCacheInfoDto,List<IndexDto> indexDto,String daty,String day){
List<ESYearPowerGeneration> list=new ArrayList<>();
if(indexDto!=null&&!indexDto.isEmpty()){
for (IndexDto dto : indexDto) {
ESYearPowerGeneration yearPowerGeneration=new ESYearPowerGeneration(
daty+"_"+dto.getAddress(),
stationCacheInfoDto.getStationId(),
stationCacheInfoDto.getStationName(),
stationCacheInfoDto.getStationType(),
stationCacheInfoDto.getBelongProvince(),
stationCacheInfoDto.getBelongArea(),
day,
dto.getGatewayId(),
new Date(),
dto.getValue()!=null?Double.valueOf(dto.getValue()):null,
dto.getEquipmentIndexName(),
dto.getEquipmentNumber(),
dto.getAddress()
);
list.add(yearPowerGeneration);
}
}
return list;
}
}
//package com.yeejoin.amos.boot.module.jxiop.biz.service.impl;
//
//import com.yeejoin.amos.boot.module.jxiop.api.dto.IndexDto;
//import com.yeejoin.amos.boot.module.jxiop.biz.ESDto.ESDailyPowerGeneration;
//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.StationCacheInfoDto;
//import com.yeejoin.amos.boot.module.jxiop.biz.repository.ESDailyPowerGenerationRepository;
//import com.yeejoin.amos.boot.module.jxiop.biz.repository.ESEquipmentsRepository;
//import com.yeejoin.amos.boot.module.jxiop.biz.repository.ESMoonPowerGenerationRepository;
//import com.yeejoin.amos.boot.module.jxiop.biz.repository.ESYearPowerGenerationRepository;
//import com.yeejoin.amos.boot.module.jxiop.biz.utils.InfluxDButils;
//import org.apache.poi.ss.formula.functions.T;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
//import org.springframework.scheduling.annotation.Async;
//import org.springframework.stereotype.Service;
//
//import java.text.SimpleDateFormat;
//import java.util.*;
//
///**
// * @description:
// * @author: tw
// * @createDate: 2023/8/9
// */
//@Service
//public class PowerGenerationImpl {
//
// @Autowired
// InfluxDButils influxDButils;
// @Autowired
// private ElasticsearchRestTemplate elasticsearchTemplate;
// @Autowired
// ESYearPowerGenerationRepository yearPowerGenerationRepository;
// @Autowired
// ESMoonPowerGenerationRepository moonPowerGenerationRepository;
// @Autowired
// ESDailyPowerGenerationRepository dailyPowerGenerationRepository;
//
//
// //获取指定指标,当天最后一条数据
// public List<IndexDto> getlast(String gatewayId, String value,String daty){
// IndexDto indexDto=null;
//
// 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);
// return queryList;
// }
// public List<IndexDto> getlastgf(String gatewayId, String value,String daty){
// IndexDto indexDto=null;
// 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);
// return queryList;
// }
// //更新es 数据
//
// //@Async("jxiopAsyncExecutor")
// public void addPowerGeneration(StationCacheInfoDto stationCacheInfoDto,String gatewayId, String value, String dateFormat, String type, String stationType,String datyvalue){
// //获取指标值
// 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);
// Date now=new Date();
// String daty= myFmt2.format(now);
// this.PowerGeneration(stationCacheInfoDto,indexDto,daty,type);
// }
//
//
// //更新es
// 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);
//
// 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),monthy);
// dailyPowerGenerationRepository.saveAll(listd);
// break;
// case "moon":
// List<ESMoonPowerGeneration> listm= this.getESMoonPowerGeneration(stationCacheInfoDto,indexDto,daty,String.valueOf(month),yeary);
// moonPowerGenerationRepository.saveAll(listm);
// break;
// case "year":
// List<ESYearPowerGeneration> listy= this.getESYearPowerGeneration(stationCacheInfoDto,indexDto,daty,String.valueOf(year));
// yearPowerGenerationRepository.saveAll(listy);
// break;
// default:
// break;
// }
//
// }
//
//// 组装数据
//
// public List<ESDailyPowerGeneration> getESDailyPowerGeneration(StationCacheInfoDto stationCacheInfoDto,List<IndexDto> indexDto,String daty,String day,String month){
//
// List<ESDailyPowerGeneration> list=new ArrayList<>();
// if(indexDto!=null&&!indexDto.isEmpty()){
// for (IndexDto dto : indexDto) {
// ESDailyPowerGeneration dailyPowerGeneration=new ESDailyPowerGeneration(
// daty+"_"+dto.getAddress(),
// stationCacheInfoDto.getStationId(),
// stationCacheInfoDto.getStationName(),
// stationCacheInfoDto.getStationType(),
// stationCacheInfoDto.getBelongProvince(),
// stationCacheInfoDto.getBelongArea(),
// day,
// dto.getGatewayId(),
// new Date(),
// dto.getValue()!=null?Double.valueOf(dto.getValue()):null,
// dto.getEquipmentIndexName(),
// dto.getEquipmentNumber(),
// dto.getAddress(),
// month
// );
// list.add(dailyPowerGeneration);
// }
// }
// return list;
// }
// public List<ESMoonPowerGeneration> getESMoonPowerGeneration(StationCacheInfoDto stationCacheInfoDto,List<IndexDto> indexDto,String daty,String day,String year){
// List<ESMoonPowerGeneration> list=new ArrayList<>();
// if(indexDto!=null&&!indexDto.isEmpty()){
// for (IndexDto dto : indexDto) {
// ESMoonPowerGeneration moonPowerGeneration=new ESMoonPowerGeneration(
// daty+"_"+dto.getAddress(),
// stationCacheInfoDto.getStationId(),
// stationCacheInfoDto.getStationName(),
// stationCacheInfoDto.getStationType(),
// stationCacheInfoDto.getBelongProvince(),
// stationCacheInfoDto.getBelongArea(),
// day,
// dto.getGatewayId(),
// new Date(),
// dto.getValue()!=null?Double.valueOf(dto.getValue()):null,
// dto.getEquipmentIndexName(),
// dto.getEquipmentNumber(),
// dto.getAddress(),
// year
// );
// list.add(moonPowerGeneration);
// }
// }
// return list;
// }
// public List<ESYearPowerGeneration> getESYearPowerGeneration(StationCacheInfoDto stationCacheInfoDto,List<IndexDto> indexDto,String daty,String day){
// List<ESYearPowerGeneration> list=new ArrayList<>();
// if(indexDto!=null&&!indexDto.isEmpty()){
// for (IndexDto dto : indexDto) {
// ESYearPowerGeneration yearPowerGeneration=new ESYearPowerGeneration(
// daty+"_"+dto.getAddress(),
// stationCacheInfoDto.getStationId(),
// stationCacheInfoDto.getStationName(),
// stationCacheInfoDto.getStationType(),
// stationCacheInfoDto.getBelongProvince(),
// stationCacheInfoDto.getBelongArea(),
// day,
// dto.getGatewayId(),
// new Date(),
// dto.getValue()!=null?Double.valueOf(dto.getValue()):null,
// dto.getEquipmentIndexName(),
// dto.getEquipmentNumber(),
// dto.getAddress()
// );
// list.add(yearPowerGeneration);
// }
// }
// return list;
// }
//
//
//
//
//
//
//
//}
package com.yeejoin.amos.boot.module.jxiop.biz.service.impl;
import com.google.common.collect.Lists;
import com.yeejoin.amos.boot.module.jxiop.api.dto.DeviceDto;
import com.yeejoin.amos.boot.module.jxiop.api.dto.IndexDto;
import com.yeejoin.amos.boot.module.jxiop.api.dto.StationTaksDto;
import com.yeejoin.amos.boot.module.jxiop.api.entity.StationBasic;
import com.yeejoin.amos.boot.module.jxiop.api.service.IStationDataTask;
import com.yeejoin.amos.boot.module.jxiop.biz.entity.SjglZsjZsbtz;
import com.yeejoin.amos.boot.module.jxiop.biz.entity.TpriDmpDatabook;
import com.yeejoin.amos.boot.module.jxiop.biz.utils.InfluxDButils;
import com.yeejoin.amos.component.influxdb.InfluxDbConnection;
import org.influxdb.dto.QueryResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
@Component
public class StationDataTaskImpl {
@Autowired
StationBasicServiceImpl stationBasicServiceImpl;
@Autowired
SjglZsjZsbtzServiceImpl sjglZsjZsbtzServiceImpl;
@Autowired
TpriDmpDatabookServiceImpl tpriDmpDatabookServiceImpl;
@Autowired
MonitorFanIndicatorImpl monitorFanIndicatorImpl;
@Value("${station.section}")
private int stationSection;
@Value("${station.isok}")
private boolean isok;
@Autowired
InfluxDButils influxDButils;
@Autowired
MonitorFanIndicatorAsync monitorFanIndicatorAsync;
/**
* 获取 List<StationTaksDto>
* @return <StationTaksDto>
*/
public List<StationTaksDto> getListStationBasic() {
return stationBasicServiceImpl.getStationTaksDtoList();
}
/**
* @deprecated 获取该场站下所有的风机信息
* @param stationTaksDto
* @return List<DeviceDto> 设备信息列表
*/
public List<DeviceDto> getListDevice(StationTaksDto stationTaksDto) {
List<DeviceDto> deviceDtoList = new ArrayList<>();
//获取风机的字典id
TpriDmpDatabook tpriDmpDatabook = tpriDmpDatabookServiceImpl.getTpriDmpDatabookByDataName("风机");
//根据字典id与场站编码获取所有的风机列表
List<SjglZsjZsbtz> sjglZsjZsbtzList = sjglZsjZsbtzServiceImpl .getSjglZsjZsbtzList(tpriDmpDatabook.getDataid(),stationTaksDto.getStationNumber());
//遍历风机列表对于需要的参数进行组装
sjglZsjZsbtzList.forEach(sjglZsjZsbtz -> {
DeviceDto deviceDto = new DeviceDto();
deviceDto.setGateway(stationTaksDto.getGateway());
String kksbm = sjglZsjZsbtz.getKksbm();
String [] kksbms = kksbm.split(" ");
String numberName = kksbms[kksbms.length-1].replace("MD","");
deviceDto.setNumberName(numberName);
deviceDtoList.add(deviceDto);
});
return deviceDtoList;
}
// @Async("jxiopAsyncExecutor")
public List<IndexDto> getIndexDto(DeviceDto deviceDto) {
String querysql ="SELECT createdTime ,gatewayId,address,valueLabel ,equipmentsIdx FROM iot_data WHERE equipmentSpecificName=~/.*"+deviceDto.getNumberName()+"风机"+".*/ and gatewayId='"+deviceDto.getGateway()+"' ORDER BY time desc LIMIT 600";
//每个分机的指标数据
List<IndexDto> list = influxDButils.getListData(querysql,IndexDto.class);
if(list!=null&&list.size()>0){
//对数据切片处理 默认创建
if(stationSection>list.size()||!isok){
monitorFanIndicatorImpl.UpdateMonitorFanIndicator(list);
}else{
//进行分片处理
List<List<IndexDto>> listfp4= Lists.partition(list,stationSection);
for (List<IndexDto> indexDtos : listfp4) {
//每个分级信息处理
monitorFanIndicatorAsync.UpdateMonitorFanIndicator(indexDtos);
}
}
}
return list;
}
}
//package com.yeejoin.amos.boot.module.jxiop.biz.service.impl;
//
//import com.google.common.collect.Lists;
//import com.yeejoin.amos.boot.module.jxiop.api.dto.DeviceDto;
//import com.yeejoin.amos.boot.module.jxiop.api.dto.IndexDto;
//import com.yeejoin.amos.boot.module.jxiop.api.dto.StationTaksDto;
//import com.yeejoin.amos.boot.module.jxiop.api.entity.StationBasic;
//import com.yeejoin.amos.boot.module.jxiop.api.service.IStationDataTask;
//import com.yeejoin.amos.boot.module.jxiop.biz.entity.SjglZsjZsbtz;
//import com.yeejoin.amos.boot.module.jxiop.biz.entity.TpriDmpDatabook;
//import com.yeejoin.amos.boot.module.jxiop.biz.utils.InfluxDButils;
//import com.yeejoin.amos.component.influxdb.InfluxDbConnection;
//import org.influxdb.dto.QueryResult;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.scheduling.annotation.Async;
//import org.springframework.scheduling.annotation.EnableAsync;
//import org.springframework.stereotype.Component;
//import org.springframework.stereotype.Service;
//
//import java.util.ArrayList;
//import java.util.List;
////已废弃
//@Component
//public class StationDataTaskImpl {
// @Autowired
// StationBasicServiceImpl stationBasicServiceImpl;
//
// @Autowired
// SjglZsjZsbtzServiceImpl sjglZsjZsbtzServiceImpl;
//
// @Autowired
// TpriDmpDatabookServiceImpl tpriDmpDatabookServiceImpl;
//
// @Autowired
// MonitorFanIndicatorImpl monitorFanIndicatorImpl;
// @Value("${station.section}")
// private int stationSection;
// @Value("${station.isok}")
// private boolean isok;
//
// @Autowired
// InfluxDButils influxDButils;
//// @Autowired
//// MonitorFanIndicatorAsync monitorFanIndicatorAsync;
//
// /**
// * 获取 List<StationTaksDto>
// * @return <StationTaksDto>
// */
// public List<StationTaksDto> getListStationBasic() {
// return stationBasicServiceImpl.getStationTaksDtoList();
// }
//
//
// /**
// * @deprecated 获取该场站下所有的风机信息
// * @param stationTaksDto
// * @return List<DeviceDto> 设备信息列表
// */
// public List<DeviceDto> getListDevice(StationTaksDto stationTaksDto) {
// List<DeviceDto> deviceDtoList = new ArrayList<>();
// //获取风机的字典id
// TpriDmpDatabook tpriDmpDatabook = tpriDmpDatabookServiceImpl.getTpriDmpDatabookByDataName("风机");
// //根据字典id与场站编码获取所有的风机列表
// List<SjglZsjZsbtz> sjglZsjZsbtzList = sjglZsjZsbtzServiceImpl .getSjglZsjZsbtzList(tpriDmpDatabook.getDataid(),stationTaksDto.getStationNumber());
// //遍历风机列表对于需要的参数进行组装
// sjglZsjZsbtzList.forEach(sjglZsjZsbtz -> {
// DeviceDto deviceDto = new DeviceDto();
// deviceDto.setGateway(stationTaksDto.getGateway());
// String kksbm = sjglZsjZsbtz.getKksbm();
// String [] kksbms = kksbm.split(" ");
// String numberName = kksbms[kksbms.length-1].replace("MD","");
// deviceDto.setNumberName(numberName);
// deviceDtoList.add(deviceDto);
// });
// return deviceDtoList;
// }
//
//// @Async("jxiopAsyncExecutor")
// public List<IndexDto> getIndexDto(DeviceDto deviceDto) {
// String querysql ="SELECT createdTime ,gatewayId,address,valueLabel ,equipmentsIdx FROM iot_data WHERE equipmentSpecificName=~/.*"+deviceDto.getNumberName()+"风机"+".*/ and gatewayId='"+deviceDto.getGateway()+"' ORDER BY time desc LIMIT 600";
// //每个分机的指标数据
// List<IndexDto> list = influxDButils.getListData(querysql,IndexDto.class);
// if(list!=null&&list.size()>0){
// //对数据切片处理 默认创建
// if(stationSection>list.size()||!isok){
// monitorFanIndicatorImpl.UpdateMonitorFanIndicator(list);
// }else{
// //进行分片处理
//
// List<List<IndexDto>> listfp4= Lists.partition(list,stationSection);
// for (List<IndexDto> indexDtos : listfp4) {
// //每个分级信息处理
// monitorFanIndicatorAsync.UpdateMonitorFanIndicator(indexDtos);
// }
// }
// }
//
// return list;
// }
//
//
//
//
//
//}
package com.yeejoin.amos.boot.module.jxiop.biz.tasks;
import com.yeejoin.amos.boot.module.jxiop.api.dto.DeviceDto;
import com.yeejoin.amos.boot.module.jxiop.api.dto.IndexDto;
import com.yeejoin.amos.boot.module.jxiop.api.dto.StationTaksDto;
import com.yeejoin.amos.boot.module.jxiop.biz.service.impl.StationDataTaskImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* @description: 定时获取场站最新数据
* @author: tw
* @createDate: 2023/7/3
*/
@Component
@EnableScheduling
public class StationDataTask {
@Autowired
StationDataTaskImpl stationDataTask;
//定时获取场站指标最新数据
// @Scheduled(cron = "${station.task.cron}")
public void getStationDataTask(){
//获取所有场站信息
List<StationTaksDto> list=stationDataTask.getListStationBasic();
for (StationTaksDto stationTaksDto : list) {
//获取分机
List<DeviceDto> listDeviceDto= stationDataTask.getListDevice(stationTaksDto);
if(listDeviceDto!=null&&listDeviceDto.size()>0){
for (DeviceDto deviceDto : listDeviceDto) {
List<IndexDto> listIndexDto = stationDataTask.getIndexDto(deviceDto);
}
}
}
}
}
//package com.yeejoin.amos.boot.module.jxiop.biz.tasks;
//
//import com.yeejoin.amos.boot.module.jxiop.api.dto.DeviceDto;
//import com.yeejoin.amos.boot.module.jxiop.api.dto.IndexDto;
//import com.yeejoin.amos.boot.module.jxiop.api.dto.StationTaksDto;
////import com.yeejoin.amos.boot.module.jxiop.biz.service.impl.StationDataTaskImpl;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.scheduling.annotation.EnableScheduling;
//import org.springframework.scheduling.annotation.Scheduled;
//import org.springframework.stereotype.Component;
//
//import java.util.List;
//
///**
// * @description: 定时获取场站最新数据
// * @author: tw
// * @createDate: 2023/7/3
// */
//
//@Component
//@EnableScheduling
//public class StationDataTask {
//
// @Autowired
// StationDataTaskImpl stationDataTask;
//
//
// //定时获取场站指标最新数据
// // @Scheduled(cron = "${station.task.cron}")
// public void getStationDataTask(){
// //获取所有场站信息
// List<StationTaksDto> list=stationDataTask.getListStationBasic();
// for (StationTaksDto stationTaksDto : list) {
// //获取分机
// List<DeviceDto> listDeviceDto= stationDataTask.getListDevice(stationTaksDto);
// if(listDeviceDto!=null&&listDeviceDto.size()>0){
// for (DeviceDto deviceDto : listDeviceDto) {
// List<IndexDto> listIndexDto = stationDataTask.getIndexDto(deviceDto);
// }
// }
// }
// }
//}
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