From 3d5e2d6ac63ab2658535da7cf898d9b01985c152 Mon Sep 17 00:00:00 2001 From: yang_shj Date: Sat, 8 Apr 2023 16:45:03 +0800 Subject: [PATCH] =?UTF-8?q?#=E5=85=89=E4=BC=8F=E9=A6=96=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/constant/HomePageConstant.java | 19 +- .../operational/main/vo/PhotovoltaicPowerVo.java | 2 +- .../main/vo/PhotovoltaicStationAppVo.java | 5 +- .../main/vo/PhotovoltaicSubordinateAppVo.java | 6 +- .../impl/HistoryAbnormalAlarmServiceImpl.java | 1 + .../main/scheduled/ScheduledCreateTask.java | 22 +- .../main/service/IAnalyseDataService.java | 1 + .../main/service/impl/AnalyseDataServiceImpl.java | 65 ++++- .../main/service/impl/HomePageServiceImpl.java | 71 +++-- .../main/service/impl/PhotovoltaicServiceImpl.java | 299 +++++++++++++-------- .../service/impl/RealMonitorServiceImpl.java | 41 +-- 11 files changed, 351 insertions(+), 181 deletions(-) diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/constant/HomePageConstant.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/constant/HomePageConstant.java index f4f2773..2a696c7 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/constant/HomePageConstant.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/constant/HomePageConstant.java @@ -61,7 +61,8 @@ public interface HomePageConstant { List SIGNAGES = Arrays.asList(HomePageConstant.JOINT_RELAY,HomePageConstant.SWITCH_ON_OFF,HomePageConstant.ELECTRICITY_CONSUMPTION, HomePageConstant.ACTIVE_POWER,HomePageConstant.REACTIVE_POWER,HomePageConstant.POWER_FACTOR,HomePageConstant.VOLTAGE,HomePageConstant.CURRENT, HomePageConstant.HYDROPOWER_GENERATE_POWER,HomePageConstant.HYDROPOWER_POWERFACTOR,HomePageConstant.HYDROPOWER_FREQUENCY,HomePageConstant.HYDROPOWER_GUIDEOPEN, - HomePageConstant.HYDROPOWER_VOLTAGE,HomePageConstant.HYDROPOWER_CURRENT,HomePageConstant.UNIT_SPEED,HomePageConstant.ACTIVE_POWER_GIVEN,HomePageConstant.REACTIVE_POWER_GIVEN); + HomePageConstant.HYDROPOWER_VOLTAGE,HomePageConstant.HYDROPOWER_CURRENT,HomePageConstant.UNIT_SPEED,HomePageConstant.ACTIVE_POWER_GIVEN,HomePageConstant.REACTIVE_POWER_GIVEN, + HomePageConstant.PV_GENERATION_DAY); /** * 站点类型 : 运维服务 @@ -168,16 +169,24 @@ public interface HomePageConstant { String P_ATTRIBUTES = "P"; /*==========================================================================================*/ // 光伏电站-电表-物模型监测点标识 + /**开关机状态**/ + String PV_JOINT_RELAY = "joint_relay"; /**总有功电度**/ String PV_GENERATION_CAPACITY = "generation_capacity"; + /**日发电量**/ + String PV_GENERATION_DAY = "generate_day"; + /**有功功率**/ + String PV_LOAD = "active_power"; /**正向无功**/ String PV_REACTIVE_POWER = "reactive_power"; - /**遥信1**/ - String PV_JOINT_RELAY = "joint_relay"; + /**电压**/ + String PV_VOLTAGE = "voltage"; + /**电流**/ + String PV_CURRENT = "current"; + /*==========================================================================================*/ // 光伏指标属性 - String PHOTOVOLTAIC_GENERATE = "generation_capacity"; // 发电量 - String PHOTOVOLTAIC_LOAD = "active_power"; // 功率 + String PHOTOVOLTAIC_OFF = "1.0"; // 开机 String PHOTOVOLTAIC_LOAD_TARGET = "0"; /*==========================================================================================*/ diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/PhotovoltaicPowerVo.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/PhotovoltaicPowerVo.java index 94e760d..f1cd386 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/PhotovoltaicPowerVo.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/PhotovoltaicPowerVo.java @@ -10,7 +10,7 @@ import lombok.Data; public class PhotovoltaicPowerVo { @ApiModelProperty(value = "小时") - private String hour; + private Integer hour; @ApiModelProperty(value = "有功功率") private String activePower; diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/PhotovoltaicStationAppVo.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/PhotovoltaicStationAppVo.java index baea493..83cb0eb 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/PhotovoltaicStationAppVo.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/PhotovoltaicStationAppVo.java @@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fasterxml.jackson.databind.ser.std.NullSerializer; import com.hnac.hzims.hzimsweather.response.weather.Daily; +import com.hnac.hzims.hzimsweather.response.weather.Now; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; @@ -50,8 +51,8 @@ public class PhotovoltaicStationAppVo { @JsonSerialize(nullsUsing = NullSerializer.class) private Double generate; - @ApiModelProperty(value = "站点实时温度") - private String temp; + @ApiModelProperty(value = "天气") + private Now now; @ApiModelProperty(value = "站点收益") private Double income; diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/PhotovoltaicSubordinateAppVo.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/PhotovoltaicSubordinateAppVo.java index 5c3e427..4ff8edd 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/PhotovoltaicSubordinateAppVo.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/PhotovoltaicSubordinateAppVo.java @@ -3,7 +3,7 @@ package com.hnac.hzims.operational.main.vo; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fasterxml.jackson.databind.ser.std.NullSerializer; -import com.hnac.hzims.hzimsweather.response.weather.Daily; +import com.hnac.hzims.hzimsweather.response.weather.Now; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; @@ -25,8 +25,8 @@ public class PhotovoltaicSubordinateAppVo { @ApiModelProperty(value = "机构名称") private String deptName; - @ApiModelProperty(value = "温度") - private String temp; + @ApiModelProperty(value = "天气") + private Now now; @ApiModelProperty(value = "地址") private String address; diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/HistoryAbnormalAlarmServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/HistoryAbnormalAlarmServiceImpl.java index 0d2f513..0ad4b3e 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/HistoryAbnormalAlarmServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/alert/service/impl/HistoryAbnormalAlarmServiceImpl.java @@ -270,6 +270,7 @@ public class HistoryAbnormalAlarmServiceImpl extends BaseServiceImpl("SUCCESS"); } @@ -292,30 +292,30 @@ public class ScheduledCreateTask { } /** - * 光伏站-逆变器指标加载 + * 光伏站-逆变器实时加载 * @return ReturnT */ - @XxlJob(LOAD_PHOTOVOLTAIC_TARGET) - //@Scheduled(cron = "0/40 * * * * ? ") - public ReturnT loadPhotovoltaicTarget(String param) throws Exception { + @XxlJob(LOAD_PHOTOVOLTAIC_REAL) + //@Scheduled(cron = "0/50 * * * * ? ") + public ReturnT loadPhotovoltaicReal(String param) throws Exception { if (Func.isBlank(param)) { param = DateUtil.format(new Date(), "yyyy-MM"); } - photovoltaicService.loadPhotovoltaicTarget(param); + photovoltaicService.loadPhotovoltaicReal(param); return new ReturnT<>("SUCCESS"); } /** - * 光伏站-逆变器实时加载 + * 光伏站-逆变器指标加载 * @return ReturnT */ - @XxlJob(LOAD_PHOTOVOLTAIC_REAL) - //@Scheduled(cron = "0/50 * * * * ? ") - public ReturnT loadPhotovoltaicReal(String param) throws Exception { + @XxlJob(LOAD_PHOTOVOLTAIC_TARGET) + //@Scheduled(cron = "0/40 * * * * ? ") + public ReturnT loadPhotovoltaicTarget(String param) throws Exception { if (Func.isBlank(param)) { param = DateUtil.format(new Date(), "yyyy-MM"); } - photovoltaicService.loadPhotovoltaicReal(param); + photovoltaicService.loadPhotovoltaicTarget(param); return new ReturnT<>("SUCCESS"); } } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/IAnalyseDataService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/IAnalyseDataService.java index 8dbc37b..421d09e 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/IAnalyseDataService.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/IAnalyseDataService.java @@ -18,4 +18,5 @@ public interface IAnalyseDataService { List periodTargetData(String startTime, String endTime, Integer accessRules, Integer cycleType, String deviceCode, String signages); + Float periodTargetFloat(String startTime, String endTime, Integer accessRules, Integer cycleType, String deviceCode, Integer ride ,String signages); } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/AnalyseDataServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/AnalyseDataServiceImpl.java index fe95831..c7acf95 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/AnalyseDataServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/AnalyseDataServiceImpl.java @@ -2,6 +2,7 @@ package com.hnac.hzims.operational.main.service.impl; import com.google.common.collect.Lists; import com.hnac.hzims.EquipmentConstants; +import com.hnac.hzims.equipment.vo.EminfoAndEmParamVo; import com.hnac.hzims.operational.main.service.IAnalyseDataService; import com.hnac.hzinfo.datasearch.analyse.IAnalyseDataSearchClient; import com.hnac.hzinfo.datasearch.analyse.po.AnalyseCodeByAnalyseDataPO; @@ -14,6 +15,8 @@ import lombok.AllArgsConstructor; import org.springblade.core.tool.api.R; import org.springblade.core.tool.utils.CollectionUtil; import org.springblade.core.tool.utils.DateUtil; +import org.springblade.core.tool.utils.ObjectUtil; +import org.springblade.core.tool.utils.StringUtil; import org.springframework.stereotype.Service; import java.time.LocalDateTime; @@ -21,6 +24,7 @@ import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.Date; import java.util.List; +import java.util.Random; import java.util.function.Function; import java.util.stream.Collectors; @@ -45,12 +49,13 @@ public class AnalyseDataServiceImpl implements IAnalyseDataService { } /*** - * 指标数据查询 + * 指标数据列表查询 * @param startTime 开始时间 * @param endTime 结束时间 - * @param cycleType - * @param deviceCode - * @param signages + * @param accessRules 取数规则 : 0=最早值 1=最大值 2=最小值 3=平均值 4=和值 5=差值 6=最新值 + * @param cycleType 间隔周期 : 0-> 秒 1-> 分 2-> 小时 3->天 4-> 周 5-> 月 6-> 年 + * @param deviceCode 设备编号 + * @param signages 指标 * @return */ @Override @@ -61,9 +66,7 @@ public class AnalyseDataServiceImpl implements IAnalyseDataService { analyzeDataConditionPO.setFull(1); po.setDeviceCode(deviceCode); analyzeDataConditionPO.setSignages(signages); - // 取数规则: 0=(整点值/最早值)、1=最大值、2=最小值、3=平均值、4=(累计值/和值)、5=(变化值/差值) 6=最新值 analyzeDataConditionPO.setAccessRules(accessRules); - // 周期类型: 0-> s(秒) 1->、m(分)、2->h(小时)3->、d(天)4->、w(周)5->、n(自然月)、6->y(自然年) analyzeDataConditionPO.setSaveTimeType(cycleType); // 间隔 analyzeDataConditionPO.setTimeInterval(1); @@ -78,5 +81,55 @@ public class AnalyseDataServiceImpl implements IAnalyseDataService { return result.getData().get(0).getList(); } + /*** + * 指标数据列表查询 + * @param startTime 开始时间 + * @param endTime 结束时间 + * @param accessRules 间隔周期 : 0-> 秒 1-> 分 2-> 小时 3->天 4-> 周 5-> 月 6-> 年 + * @param cycleType 取数规则 : 0=最早值 1=最大值 2=最小值 3=平均值 4=和值 5=差值 6=最新值 + * @param deviceCode 设备编号 + * @param ride 配电比 + * @param signages 指标 + * @return + */ + @Override + public Float periodTargetFloat(String startTime, String endTime, Integer accessRules, Integer cycleType, String deviceCode,Integer ride,String signages) { + AnalyseCodeByAnalyseDataPO po = new AnalyseCodeByAnalyseDataPO(); + List signboardConditions = new ArrayList<>(); + AnalyzeDataConditionPO analyzeDataConditionPO = new AnalyzeDataConditionPO(); + analyzeDataConditionPO.setFull(1); + po.setDeviceCode(deviceCode); + analyzeDataConditionPO.setSignages(signages); + analyzeDataConditionPO.setAccessRules(accessRules); + analyzeDataConditionPO.setSaveTimeType(cycleType); + // 间隔 + analyzeDataConditionPO.setTimeInterval(1); + analyzeDataConditionPO.setBeginTime(LocalDateTime.parse(DateUtil.format(new Date(), startTime), DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATETIME))); + analyzeDataConditionPO.setEndTime(LocalDateTime.parse(DateUtil.format(new Date(), endTime), DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATETIME))); + signboardConditions.add(analyzeDataConditionPO); + po.setSignboardConditions(signboardConditions); + R> result = analyseDataSearchClient.getAnalyzeDataByAnalyzeCodeAndSignages(po); + if (!result.isSuccess() || CollectionUtil.isEmpty(result.getData())) { + return 0f; + } + List records = result.getData(); + if(CollectionUtil.isEmpty(records)){ + return 0f; + } + AnalyzeDataConditionVO analyzeDataConditionVO = records.get(0); + if (ObjectUtil.isEmpty(analyzeDataConditionVO)) { + return 0f; + } + List analyseDataTaosVOList = analyzeDataConditionVO.getList(); + if (CollectionUtil.isEmpty(analyseDataTaosVOList)) { + return 0f; + } + AnalyseDataTaosVO analyseDataTaosVO = analyzeDataConditionVO.getList().get(0); + if (ObjectUtil.isEmpty(analyseDataTaosVO) || StringUtil.isBlank(analyseDataTaosVO.getVal())) { + return 0f; + } + return Float.parseFloat(analyseDataTaosVO.getVal()) * ride; + } + } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/HomePageServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/HomePageServiceImpl.java index 06ce852..e2fc91b 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/HomePageServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/HomePageServiceImpl.java @@ -11,6 +11,7 @@ import com.hnac.hzims.equipment.vo.EminfoAndEmParamVo; import com.hnac.hzims.monitor.utils.DateUtils; import com.hnac.hzims.operational.fill.entity.*; import com.hnac.hzims.operational.fill.service.*; +import com.hnac.hzims.operational.main.service.IAnalyseDataService; import com.hnac.hzims.operational.main.service.IHomePageService; import com.hnac.hzims.operational.main.service.IMainSystemMonitoringService; import com.hnac.hzims.operational.main.service.IMainTaskStatisticService; @@ -69,7 +70,8 @@ import java.util.stream.Collectors; @Slf4j public class HomePageServiceImpl implements IHomePageService { - private final IAnalyseDataSearchClient analyseDataSearchClient; + + private final IAnalyseDataService analyseDataService; private final IPlanGenertionClient planGenertionClient; private final IMainSystemMonitoringService maintenanceTaskService; private final IMainTaskStatisticService mainTaskStatisticService; @@ -219,41 +221,70 @@ public class HomePageServiceImpl implements IHomePageService { * * @param param 时间 * @param serveType 站点类型 - * @param yearCount 近几年 + * @param year 近几年 */ @Override - public void loadPowerData(String param,List types, Integer serveType, int yearCount) { + public void loadPowerData(String param,List types, Integer serveType, int year) { // 站点查询 List stationList = stationService.getStationType(serveType, types, null); // 设备信息 - List equipmentInfoList = maintenanceTaskService.getEmInfoList(); + List devices = maintenanceTaskService.getEmInfoList(); + // 开始事件 + Calendar calendar = Calendar.getInstance(); + calendar.add(Calendar.MONTH, -calendar.get(Calendar.MONTH) + 12); + calendar.add(Calendar.DATE, -calendar.get(Calendar.DATE) + 1); + String end = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE) + " 00:00:00"; + // 结束日期 + calendar.set(Calendar.YEAR, calendar.get(Calendar.YEAR) - year); + calendar.add(Calendar.MONTH, -calendar.get(Calendar.MONTH)); + String start = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATE) + " 00:00:00"; // 存储数据map :<站点id,<月份,发电量>> Map> powerMap = new HashMap<>(); - // 获取需要遍历月份 - List monList = this.getMonthList(yearCount, 12,true); - Random random = new Random(); stationList.forEach(station -> { - Long departId = station.getRefDept(); - // 获取对应站点设备 - List effEmInfoList = equipmentInfoList.stream().filter(o -> departId.equals(o.getCreateDept())).collect(Collectors.toList()); - if (CollectionUtil.isEmpty(effEmInfoList)) { + // 站点设备集合 + List stationDevices = devices.stream().filter(device -> device.getCreateDept().equals(station.getRefDept())).collect(Collectors.toList()); + if(CollectionUtil.isEmpty(stationDevices)){ return; } - Map floatMap = new HashMap<>(); - for (int i = 0; i < monList.size() - 1; i++) { - if (this.compareDate(monList.get(i))) { - floatMap.put(monList.get(i), 0f); - continue; - } - float power = getPowerGeneration(effEmInfoList, monList.get(i) + " 00:00:00", monList.get(i + 1) + " 00:00:00",EquipmentConstants.CycleTypeEnum.MONTH_CYCLE.getType()); - floatMap.put(monList.get(i), power); + Map generateMap = this.getGenerateYear(stationDevices,start,end); + if(MapUtils.isEmpty(generateMap)){ + return; } - powerMap.put(station.getId(), floatMap); + powerMap.put(station.getId(),generateMap); }); redisTemplate.opsForValue().set(RECENT_YEAR_POWER_DATA, powerMap); } /** + * 获取年发电量 + * @param devices + * @param start + * @param end + * @return + */ + private Map getGenerateYear(List devices, String start, String end) { + List datas = new ArrayList<>(); + devices.forEach(device->{ + List records = analyseDataService.periodTargetData(start,end,5,5,device.getEmCode(),HomePageConstant.HYDROPOWER_GENERATE_POWER); + if(CollectionUtil.isEmpty(records)){ + return; + } + datas.addAll(records.stream().map(record -> { + PowerMonthVo generate = new PowerMonthVo(); + Date time = DateUtil.parse(record.getTs(), "yyyy-MM-dd HH:mm:ss.s"); + generate.setStrMonth(DateUtil.format(time,DateUtil.PATTERN_DATE)); + generate.setPower(Float.valueOf(Optional.ofNullable(record.getVal()).orElse("0")) * device.getRideCount()); + return generate; + }).collect(Collectors.toList())); + }); + if(CollectionUtil.isEmpty(datas)){ + return null; + } + return datas.stream().collect(Collectors.groupingBy(PowerMonthVo::getStrMonth, Collectors.collectingAndThen( + Collectors.mapping(PowerMonthVo::getPower, Collectors.reducing(Float::sum)),Optional::get))); + } + + /** * @param stationList * @return */ diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/PhotovoltaicServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/PhotovoltaicServiceImpl.java index 7c3a028..b12c294 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/PhotovoltaicServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/PhotovoltaicServiceImpl.java @@ -22,6 +22,7 @@ import com.hnac.hzinfo.datasearch.history.OriginalDataQuery; import com.hnac.hzinfo.sdk.core.response.HzPage; import com.hnac.hzinfo.sdk.core.response.Result; import lombok.RequiredArgsConstructor; +import net.sf.jsqlparser.expression.StringValue; import org.apache.commons.collections4.MapUtils; import org.springblade.core.log.exception.ServiceException; import org.springblade.core.tool.api.R; @@ -87,8 +88,6 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { private final static String recent_year_power_data = "hzims:operation:key:power:data"; - private final static String recent_year_load_data = "hzims:operation:key:load:data"; - @Value("${hzims.operation.realIdKey}") public String real_id_key; @@ -109,28 +108,33 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { } // 取redis实时数据 Map map = this.getRealData(); - List list = new ArrayList<>(); - Random random = new Random(); - devices.forEach(device -> { + if(MapUtils.isEmpty(map)){ + return; + } + // redis缓存设备实时数据 + List history = (List) redisTemplate.opsForValue().get(load_photovoltaic_real_key); + // 设备实时数据 + List list = devices.stream().map(device -> { PhotovoltaicRealVo real = new PhotovoltaicRealVo(); real.setDeptId(device.getCreateDept()); real.setDeviceCode(device.getEmCode()); real.setDeviceName(device.getName()); - real.setState(random.nextInt(2) - 1); + real.setState(this.getPhotovoltaicState(device,map)); // 容量 real.setCapacity(device.getInstalledCapacity()); // 发电量 - real.setGenerate(random.nextDouble() * 25000 * 300 * 2); + real.setGenerate(Double.valueOf(this.getSignageValue(device,map,HomePageConstant.PV_GENERATION_CAPACITY))); + // 功率 + real.setLoad(Double.valueOf(this.getSignageValue(device,map,HomePageConstant.PV_LOAD))); // 电压 - real.setVoltage(random.nextDouble() * 300); + real.setVoltage(Double.valueOf(this.getSignageValue(device,map,HomePageConstant.PV_VOLTAGE))); // 电流 - real.setCurrent(random.nextDouble() * 300); - // 功率 - real.setLoad(random.nextDouble() * 300); + real.setCurrent(Double.valueOf(this.getSignageValue(device,map,HomePageConstant.PV_CURRENT))); // 上次功率 - real.setLastLoad(random.nextDouble() * 300); - list.add(real); - }); + real.setLastLoad(this.getLastLoad(device,history)); + return real; + }).collect(Collectors.toList()); + // 存储redis redisTemplate.opsForValue().set(load_photovoltaic_real_key, list); } @@ -147,7 +151,6 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { return; } List list = new ArrayList<>(); - Random random = new Random(); devices.forEach(device -> { PhotovoltaicTargetVo target = new PhotovoltaicTargetVo(); target.setDeptId(device.getCreateDept()); @@ -155,53 +158,189 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { target.setDeviceName(device.getName()); target.setDeptName(device.getName()); // 当日运行时长 - // target.setRunHours(this.runHours(device.getPoint().get(HomePageConstant.PV_JOINT_RELAY))); - // 当天有功功率 - // List activePowerVoList = waterService.getActivePowerVoList(device); - // FIXME 测试数据 - // 当天运行时长 - target.setRunHours(new Random().nextDouble() * 24); + //target.setRunHours(this.runHours(device.getPoint().get(HomePageConstant.PV_JOINT_RELAY))); // 年发电量 - target.setGenerationYear(random.nextDouble() * 25000 * 360); + target.setGenerationYear((double) this.sumValueByTime(device.getEmCode(),device.getRideCount(),"0")); // 月发电量 - target.setGenerationMon(random.nextDouble() * 25000 * 30); + target.setGenerationMon((double) this.sumValueByTime(device.getEmCode(),device.getRideCount(),"1")); // 日发电量 - target.setGenerationDay(random.nextDouble() * 25000); + target.setGenerationDay((double) this.sumValueByTime(device.getEmCode(),device.getRideCount(),"2")); + // 昨日发电量 + target.setGenerationYesterday((double) this.sumValueByTime(device.getEmCode(),device.getRideCount(),"3")); // 收益 target.setIncome(target.getGenerationDay() * 0.34); - // 昨日发电量 - target.setGenerationYesterday(random.nextDouble() * 25000); // 节约标准煤 target.setTec(target.getGenerationMon() * 0.0001229); // 二氧化碳减排 target.setCo2(target.getGenerationMon() * 0.000997); // 减少森林砍伐 target.setDeforest(target.getGenerationMon() * 0.000553); - // FIXME 测试模拟数据30天功率 - List photovoltaicPowers = this.activePowerVoList(device); - target.setActivePowerVoList(photovoltaicPowers); + // 当天有功功率 + target.setActivePowerVoList(this.getLoadsByDay(device)); // 30天发电量 - List generationPowerVoList = this.getGenerationPowerList(device); - target.setGenerationPowerVoList(generationPowerVoList); + target.setGenerationPowerVoList(this.getGenerateByMon(device)); list.add(target); }); redisTemplate.opsForValue().set(load_photovoltaic_target_key, list); } - // FIXME 测试模拟 - private List activePowerVoList(EminfoAndEmParamVo device) { - List hours = getTestDay(); - Random random = new Random(); - return hours.stream().map(hour -> { - PhotovoltaicPowerVo power = new PhotovoltaicPowerVo(); - power.setHour(hour); - power.setActivePower(String.valueOf(random.nextDouble() * 500)); - return power; - }).collect(Collectors.toList()); + /** + * 当天有功功率 + * @param device + * @return + */ + private List getLoadsByDay(EminfoAndEmParamVo device) { + String start = DateUtil.format(new Date(),DateUtil.PATTERN_DATE) + " 00:00:00"; + String end = DateUtil.format(new Date(), DateUtil.PATTERN_DATETIME); + List records = analyseDataService.periodTargetData(start,end,1,2,device.getEmCode(),HomePageConstant.PV_LOAD); + if(CollectionUtil.isEmpty(records)){ + return new ArrayList<>(); + } + return records.stream().map(record -> { + PhotovoltaicPowerVo load = new PhotovoltaicPowerVo(); + Date time = DateUtil.parse(record.getTs(), "yyyy-MM-dd HH:mm:ss.s"); + load.setHour(time.getHours()); + load.setActivePower(Optional.ofNullable(record.getVal()).orElse("0")); + return load; + }).sorted(Comparator.comparing(PhotovoltaicPowerVo::getHour)).collect(Collectors.toList()); + } + + /** + * 近30天发电量 + * @param device + * @return + */ + private List getGenerateByMon(EminfoAndEmParamVo device) { + Calendar calendar = Calendar.getInstance(); + String end = DateUtil.format(calendar.getTime(), DateUtil.PATTERN_DATETIME); + calendar.add(Calendar.DAY_OF_MONTH, -29); + calendar.add(Calendar.HOUR_OF_DAY, -calendar.get(Calendar.HOUR_OF_DAY)); + calendar.add(Calendar.MINUTE, -calendar.get(Calendar.MINUTE)); + calendar.add(Calendar.SECOND, -calendar.get(Calendar.SECOND)); + String start = DateUtil.format(calendar.getTime(), DateUtil.PATTERN_DATETIME); + List records = analyseDataService.periodTargetData(start,end,5,3,device.getEmCode(),HomePageConstant.PV_GENERATION_CAPACITY); + if(CollectionUtil.isEmpty(records)){ + return new ArrayList<>(); + } + return records.stream().map(record -> { + GenerationPowerVo generate = new GenerationPowerVo(); + Date time = DateUtil.parse(record.getTs(), "yyyy-MM-dd HH:mm:ss.s"); + generate.setDate(DateUtil.format(time,DateUtil.PATTERN_DATE)); + generate.setGenerate(Float.valueOf(Optional.ofNullable(record.getVal()).orElse("0"))); + return generate; + }).sorted(Comparator.comparing(GenerationPowerVo::getDate)).collect(Collectors.toList()); } /** + * 根据事件查询数据值 + * @param deviceCode + * @param rideCount + * @param type + * @return + */ + private float sumValueByTime(String deviceCode, int rideCount,String type) { + Calendar calendar = Calendar.getInstance(); + String start = null,end = null; + Integer cycleType = 3; + switch (type){ + //年 + case "0": + calendar.add(Calendar.HOUR_OF_DAY, + 1); + end = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATETIME); + calendar.setTime(new Date()); + calendar.add(Calendar.MONTH, -calendar.get(Calendar.MONTH)); + calendar.add(Calendar.DAY_OF_MONTH, -calendar.get(Calendar.DATE) + 1); + calendar.add(Calendar.HOUR_OF_DAY, -calendar.get(Calendar.HOUR_OF_DAY)); + calendar.add(Calendar.MINUTE, -calendar.get(Calendar.MINUTE)); + calendar.add(Calendar.SECOND, -calendar.get(Calendar.SECOND)); + start = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATETIME); + cycleType = 6; + break; + //月 + case "1": + start = DateUtil.format(new Date(),"yyyy-MM") + "-01 00:00:00"; + end = DateUtil.format(new Date(), DateUtil.PATTERN_DATETIME); + cycleType = 5; + break; + //日 + case "2": + start = DateUtil.format(new Date(),DateUtil.PATTERN_DATE) + " 00:00:00"; + end = DateUtil.format(new Date(), DateUtil.PATTERN_DATETIME); + break; + //昨日 + case "3": + calendar.add(Calendar.DAY_OF_MONTH, - 1); + calendar.add(Calendar.HOUR_OF_DAY, -calendar.get(Calendar.HOUR_OF_DAY)); + calendar.add(Calendar.MINUTE, -calendar.get(Calendar.MINUTE)); + calendar.add(Calendar.SECOND, -calendar.get(Calendar.SECOND)); + start = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATETIME); + end = DateUtil.format(new Date(),DateUtil.PATTERN_DATE) + " 00:00:00"; + break; + } + return analyseDataService.periodTargetFloat(start,end,5,cycleType,deviceCode,rideCount,HomePageConstant.PV_GENERATION_CAPACITY); + } + + /** + * 获取上一次功率 + * @param device + * @param history + * @return + */ + private Double getLastLoad(EminfoAndEmParamVo device, List history) { + if(CollectionUtil.isEmpty(history)){ + return 0.0; + } + List historyDevice = history.stream().filter(o -> o.getDeviceCode().equals(device.getEmCode())).collect(Collectors.toList()); + if(CollectionUtil.isEmpty(historyDevice)){ + return 0.0; + } + return historyDevice.get(0).getLoad(); + } + + /** + * 获取开机状态 + * @param device + * @return + */ + private int getPhotovoltaicState(EminfoAndEmParamVo device,Map map) { + // 获取开关机监测点实时数据 + String value = this.getSignageValue(device,map,HomePageConstant.PV_JOINT_RELAY); + // 开机状态 + if (HomePageConstant.OFF.equals(value)) { + return 0; + } + return 1; + } + + /** + * 获取监测点实时数据 + * @param em + * @param map + * @param targets + * @return + */ + private String getSignageValue(EminfoAndEmParamVo em,Map map, String targets) { + if(ObjectUtil.isEmpty(em) || MapUtils.isEmpty(map)){ + return "0"; + } + Map point = em.getPoint(); + if(MapUtils.isEmpty(point)){ + return "0"; + } + String realId = point.get(targets); + if(StringUtil.isEmpty(realId)){ + return "0"; + } + String value = map.get(realId); + if(StringUtil.isEmpty(realId)){ + return "0"; + } + // 获取value + return value; + } + + /** * 当天运行时长 * * @param realId @@ -297,7 +436,7 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { private long runTime(List result, Date startDate, Date endDate) { if (result.size() == 1) { // 一直开机 - if (HomePageConstant.OFF.equals(result.get(0).getValue())) { + if (HomePageConstant.PHOTOVOLTAIC_OFF.equals(result.get(0).getValue())) { return endDate.getTime() - startDate.getTime(); } // 一直关机 @@ -365,56 +504,10 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { default: throw new IllegalStateException("Unexpected value: " + scope); } - return homePageService.getAnalyzeCodeAndSignages(device, startTime, endTime, cycle, HomePageConstant.PHOTOVOLTAIC_GENERATE); + return homePageService.getAnalyzeCodeAndSignages(device, startTime, endTime, cycle, HomePageConstant.PV_GENERATION_CAPACITY); } /** - * 近30天发电量 - * - * @param device - * @return - */ - private List getGenerationPowerList(EminfoAndEmParamVo device) { - List generationPowerVoList = new ArrayList<>(); - // 近30天日期集合 - Random random = new Random(); - List dayList = this.getRecent30Day(); - for (int i = 0; i < dayList.size() - 1; i++) { - GenerationPowerVo generationPowerVo = new GenerationPowerVo(); - generationPowerVo.setDate(dayList.get(i)); - // 某天发电量 - float power = homePageService.getAnalyzeCodeAndSignages(device, dayList.get(i) + " 00:00:00", dayList.get(i + 1) + " 00:00:00", EquipmentConstants.CycleTypeEnum.DAY_CYCLE.getType(), HomePageConstant.PHOTOVOLTAIC_GENERATE); - generationPowerVo.setGenerate(power); - generationPowerVo.setLoad((float) (random.nextDouble() * 500)); - generationPowerVoList.add(generationPowerVo); - } - return generationPowerVoList; - } - - /** - * 近7天发电量 - * - * @param device - * @return - */ - private List getGenerationPowerWeek(EminfoAndEmParamVo device) { - List generationPowerVoList = new ArrayList<>(); - // 近一周日期集合 - List dayList = this.getRecentWeek(); - SimpleDateFormat sdf = new SimpleDateFormat("EEEE"); - for (int i = 0; i < dayList.size() - 1; i++) { - GenerationPowerVo generationPowerVo = new GenerationPowerVo(); - generationPowerVo.setDate(sdf.format(DateUtil.parse(dayList.get(i), DateUtil.PATTERN_DATE))); - // 某天发电量 - float power = homePageService.getAnalyzeCodeAndSignages(device, dayList.get(i) + " 00:00:00", dayList.get(i + 1) + " 00:00:00", EquipmentConstants.CycleTypeEnum.DAY_CYCLE.getType(), HomePageConstant.PHOTOVOLTAIC_GENERATE); - generationPowerVo.setGenerate(power); - generationPowerVoList.add(generationPowerVo); - } - return generationPowerVoList; - } - - - /** * 当天功率 * * @return @@ -462,30 +555,6 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { } /** - * 获取近30天集合 - * - * @return - */ - private List getRecent30Day() { - // 日期格式化yyyy-mm-dd - SimpleDateFormat df = new SimpleDateFormat(DateUtil.PATTERN_DATE); - List list = new ArrayList<>(); - // 开始日期 - Calendar calendar = Calendar.getInstance(); - calendar.setTime(new Date()); - calendar.add(Calendar.DATE, +1); - list.add(df.format(calendar.getTime())); - // 获取日期之间的月 - int i = 0; - while (i < 30) { - calendar.add(Calendar.DATE, -1); - list.add(df.format(calendar.getTime())); - i++; - } - return list.stream().sorted(Comparator.comparing(String::valueOf)).collect(Collectors.toList()); - } - - /** * 获取实时数据 * * @return @@ -922,7 +991,7 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { // 获取实时天气 Map nowWeather = this.weatherService.getNowWeather(Collections.singletonList(station.getCode())); if (MapUtils.isNotEmpty(nowWeather)) { - subordinate.setTemp(nowWeather.get(station.getCode()).getNow().getTemp()); + subordinate.setNow(nowWeather.get(station.getCode()).getNow()); } // 容量、实时功率、今日发电量 this.subordinateTargetData(subordinate, entry.getValue().stream().collect(Collectors.toList()), deviceReals, deviceTargets); @@ -1049,7 +1118,7 @@ public class PhotovoltaicServiceImpl implements PhotovoltaicService { photovoltaic.setStationCode(station.getCode()); photovoltaic.setDeptId(station.getRefDept()); photovoltaic.setDeptName(station.getName()); - photovoltaic.setTemp(this.temp(weather, station.getCode())); + photovoltaic.setNow(weather.get(station.getCode()).getNow()); photovoltaic.setAddress(station.getAddress()); // 站点实时数据: 设备状态统计、实时功率、总发电量 、 日发电量 、 月发电量 、 co2减排 、 节约标准煤减排 、 减少森林砍伐 this.app_data(photovoltaic); diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/RealMonitorServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/RealMonitorServiceImpl.java index 3be9342..5181197 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/RealMonitorServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/RealMonitorServiceImpl.java @@ -16,11 +16,11 @@ import com.hnac.hzims.operational.config.service.StAlamRecordService; import com.hnac.hzims.operational.config.service.StFocusPropertiesService; import com.hnac.hzims.operational.config.vo.MessageParamVo; import com.hnac.hzims.operational.config.vo.StationRealVo; +import com.hnac.hzims.operational.main.constant.HomePageConstant; import com.hnac.hzims.operational.main.service.IMainSystemMonitoringService; import com.hnac.hzims.operational.main.service.IWeatherService; import com.hnac.hzims.operational.main.vo.JointRelayVo; import com.hnac.hzims.operational.main.vo.WaterLevelVo; -import com.hnac.hzims.operational.main.constant.HomePageConstant; import com.hnac.hzims.operational.station.entity.StationAttributeEntity; import com.hnac.hzims.operational.station.entity.StationEntity; import com.hnac.hzims.operational.station.service.IRealMonitorService; @@ -31,6 +31,7 @@ import com.hnac.hzims.operational.station.vo.RealAttributeVo; import com.hnac.hzims.operational.station.vo.RealDeviceVo; import com.hnac.hzims.operational.station.vo.RealStationVo; import com.hnac.hzims.operational.station.vo.WeatherVo; +import com.hnac.hzinfo.sdk.v5.redis.RedisClient; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.MapUtils; @@ -88,6 +89,8 @@ public class RealMonitorServiceImpl implements IRealMonitorService { @NotNull private final AbnormalAlarmService abnormalAlarmService; + private final RedisClient redisClient; + @NotNull private final ISysClient sysClient; @@ -131,8 +134,6 @@ public class RealMonitorServiceImpl implements IRealMonitorService { private final static String loadwater_level_key = "hzims:operation:loadwater:level:key"; - private final static String redis_real_prefix_key = "iot:real:data:"; - @Override public void realTimeData(String param) { @@ -146,10 +147,14 @@ public class RealMonitorServiceImpl implements IRealMonitorService { return ""; } String jointRelay = points.get(HomePageConstant.JOINT_RELAY); - if(StringUtil.isBlank(jointRelay)){ - return ""; + if(!StringUtil.isEmpty(jointRelay)){ + return jointRelay; + } + String onOff = points.get(HomePageConstant.SWITCH_ON_OFF); + if(!StringUtil.isEmpty(onOff)){ + return onOff; } - return jointRelay; + return ""; }).collect(Collectors.toList()); // 获取站点缓存数据 List stationRealVos = (List) redisTemplate.opsForValue().get(moniter_realId_key); @@ -169,11 +174,11 @@ public class RealMonitorServiceImpl implements IRealMonitorService { list.forEach(stations -> { stations.forEach(stationReal -> { String[] realIdArr = stationReal.getRealId(); - List realIds = Stream.of(realIdArr).map(o-> redis_real_prefix_key + stationReal.getStation() + ":" + o).collect(Collectors.toList()); + List realIds = Stream.of(realIdArr).collect(Collectors.toList()); if(CollectionUtil.isEmpty(realIds)){ return; } - List objects = redisTemplate.opsForValue().multiGet(realIds); + List objects = redisClient.getBatchRealDataByRealId(stationReal.getStation(),realIds); if(CollectionUtil.isEmpty(objects)){ return; } @@ -182,11 +187,12 @@ public class RealMonitorServiceImpl implements IRealMonitorService { log.error(realIds.get(i) + "is null"); continue; } - Map attribute = (Map) objects.get(i); - attribute.put("realId",realIdArr[i]); + Map attribute = (Map) JSONObject.parse(objects.get(i)); + attribute.put("realId",attribute.get("k")); attribute.put("value",attribute.get("v")); attribute.put("time",attribute.get("t")); attribute.remove("v"); + attribute.remove("k"); attribute.remove("t"); this.getCheckMap(attribute,switchOnOff); valueMap.put(realIdArr[i],attribute.get("value")); @@ -217,15 +223,15 @@ public class RealMonitorServiceImpl implements IRealMonitorService { * @param value * @return */ - private Map getCheckMap(Map value,List switchOnOff){ + private void getCheckMap(Map value,List switchOnOff){ try{ - String time = value.get("time"); - if(StringUtil.isEmpty(time)){ - return value; - } // 不处理开机状态监测点 if(switchOnOff.contains(value.get("realId"))){ - return value; + return; + } + String time = value.get("time"); + if(StringUtil.isEmpty(time)){ + return; } SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DateUtil.PATTERN_DATETIME); Date date = simpleDateFormat.parse(time); @@ -234,9 +240,8 @@ public class RealMonitorServiceImpl implements IRealMonitorService { value.put("value","0"); } }catch (ParseException e){ - return value; + return; } - return value; } /**