From 5c7f9e73839d1bd9fbd93e3f08389fb498684294 Mon Sep 17 00:00:00 2001 From: yang_shj <1069818635@QQ.com> Date: Wed, 7 Feb 2024 09:55:19 +0800 Subject: [PATCH] =?UTF-8?q?#=E6=BC=94=E7=A4=BA=E5=B9=B3=E5=8F=B0=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E3=80=8130=E5=A4=A9=E5=8F=91=E7=94=B5=E9=87=8F?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hzims/operational/data/vo/WeatherRainVo.java | 20 ++++ .../hzims/operational/data/vo/WeatherWaterVo.java | 23 ++++ .../operation/home/impl/RealTargetServiceImpl.java | 16 ++- .../data/controller/HzimsDataController.java | 11 +- .../operational/data/service/HzimsDataService.java | 3 + .../data/service/impl/HzimsDataServiceImpl.java | 124 ++++++++++++++++++++- 6 files changed, 183 insertions(+), 14 deletions(-) create mode 100644 hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/data/vo/WeatherRainVo.java create mode 100644 hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/data/vo/WeatherWaterVo.java diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/data/vo/WeatherRainVo.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/data/vo/WeatherRainVo.java new file mode 100644 index 0000000..d011057 --- /dev/null +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/data/vo/WeatherRainVo.java @@ -0,0 +1,20 @@ +package com.hnac.hzims.operational.data.vo; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * @author ysj + */ +@Data +public class WeatherRainVo { + + @ApiModelProperty("时间") + private String time; + + @ApiModelProperty("水位") + private Double water; + + @ApiModelProperty("降雨量") + private Double rain; +} \ No newline at end of file diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/data/vo/WeatherWaterVo.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/data/vo/WeatherWaterVo.java new file mode 100644 index 0000000..f8a4ee1 --- /dev/null +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/data/vo/WeatherWaterVo.java @@ -0,0 +1,23 @@ +package com.hnac.hzims.operational.data.vo; + +import com.hnac.hzims.hzimsweather.response.weather.Daily; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.List; + +/** + * @author ysj + */ +@Data +public class WeatherWaterVo { + + @ApiModelProperty("站点名称") + private String stationName; + + @ApiModelProperty("天气") + private List dailys; + + @ApiModelProperty("发电量") + private List weatherRains; +} \ No newline at end of file diff --git a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/impl/RealTargetServiceImpl.java b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/impl/RealTargetServiceImpl.java index 1706a4c..21a72c7 100644 --- a/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/impl/RealTargetServiceImpl.java +++ b/hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/impl/RealTargetServiceImpl.java @@ -14,18 +14,17 @@ import com.hnac.hzims.operational.station.entity.HzimsAnalyzeModelStationEntity; import com.hnac.hzims.operational.station.entity.StationEntity; import com.hnac.hzims.scheduled.service.equipment.DeviceParamService; import com.hnac.hzims.scheduled.service.equipment.DeviceService; -import com.hnac.hzims.scheduled.service.operation.home.ModelStationService; -import com.hnac.hzims.scheduled.service.operation.home.RealTargetService; import com.hnac.hzims.scheduled.service.operation.fill.GenerateService; import com.hnac.hzims.scheduled.service.operation.fill.PowerService; import com.hnac.hzims.scheduled.service.operation.fill.UseService; +import com.hnac.hzims.scheduled.service.operation.home.ModelStationService; +import com.hnac.hzims.scheduled.service.operation.home.RealTargetService; +import com.hnac.hzims.scheduled.service.operation.plate.DataService; import com.hnac.hzims.scheduled.service.operation.station.StationAttributeService; import com.hnac.hzims.scheduled.service.operation.station.StationService; -import com.hnac.hzims.scheduled.service.operation.plate.DataService; import com.hnac.hzinfo.datasearch.PointData; import com.hnac.hzinfo.datasearch.analyse.IAnalyseDataSearchClient; import com.hnac.hzinfo.datasearch.analyse.domain.FieldsData; -import com.hnac.hzinfo.datasearch.analyse.po.AnalyseCodeByAnalyseDataPO; import com.hnac.hzinfo.datasearch.analyse.vo.AnalyseDataTaosVO; import com.hnac.hzinfo.datasearch.analyse.vo.AnalyzeCodeBySignagesVO; import com.hnac.hzinfo.datasearch.history.IHistoryDataSearchClient; @@ -1589,8 +1588,13 @@ public class RealTargetServiceImpl implements RealTargetService { * @return */ private List getGenerationPowerList(EminfoAndEmParamVo device) { - String start = DateUtil.format(new Date(), "yyyy-MM") + "-01 00:00:00"; - String end = DateUtil.format(new Date(), DateUtil.PATTERN_DATETIME); + 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 = dataService.periodTargetData(start,end,5,EquipmentConstants.CycleTypeEnum.DAY_CYCLE.getType(),device.getEmCode(),HomePageConstant.HYDROPOWER_GENERATE_POWER); if(CollectionUtil.isEmpty(records)){ return new ArrayList<>(); diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/data/controller/HzimsDataController.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/data/controller/HzimsDataController.java index 03f730b..373f3c9 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/data/controller/HzimsDataController.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/data/controller/HzimsDataController.java @@ -51,11 +51,18 @@ public class HzimsDataController { } @ApiLog - @GetMapping("/power") + @GetMapping("/weather") @ApiOperationSupport(order = 4) + @ApiOperation(value = "站点天气、降雨、水位", notes = "传入站点code") + public R weather(@RequestParam("stationCode") String stationCode) { + return R.data(service.weather(stationCode)); + } + + @ApiLog + @GetMapping("/power") + @ApiOperationSupport(order = 5) @ApiOperation(value = "站点功率换算电量", notes = "传入站点code") public R power(@RequestParam("stationCode") String stationCode) { return R.data(service.power(stationCode)); } - } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/data/service/HzimsDataService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/data/service/HzimsDataService.java index a37e6fe..8c6a8bb 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/data/service/HzimsDataService.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/data/service/HzimsDataService.java @@ -1,6 +1,7 @@ package com.hnac.hzims.operational.data.service; import com.hnac.hzims.operational.data.vo.PowerConvertVo; +import com.hnac.hzims.operational.data.vo.WeatherWaterVo; import com.hnac.hzims.operational.main.vo.HydropowerStationVo; import javax.servlet.http.HttpServletRequest; @@ -22,5 +23,7 @@ public interface HzimsDataService { HydropowerStationVo station(String stationCode); + WeatherWaterVo weather(String stationCode); + PowerConvertVo power(String stationCode); } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/data/service/impl/HzimsDataServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/data/service/impl/HzimsDataServiceImpl.java index 19332c2..af4d929 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/data/service/impl/HzimsDataServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/data/service/impl/HzimsDataServiceImpl.java @@ -6,15 +6,15 @@ import com.hnac.hzims.equipment.entity.PlanGenerationEntity; import com.hnac.hzims.equipment.feign.IEmInfoClient; import com.hnac.hzims.equipment.feign.IPlanGenertionClient; import com.hnac.hzims.equipment.vo.EminfoAndEmParamVo; +import com.hnac.hzims.hzimsweather.response.weather.HeWeatherWeatherDailyResponse; import com.hnac.hzims.operational.data.service.HzimsDataService; import com.hnac.hzims.operational.data.vo.AreaVo; -import com.hnac.hzims.operational.data.vo.ConverElectricityVo; -import com.hnac.hzims.operational.data.vo.LoadWaterLevelVo; -import com.hnac.hzims.operational.data.vo.PowerConvertVo; +import com.hnac.hzims.operational.data.vo.*; import com.hnac.hzims.operational.main.constant.HomePageConstant; import com.hnac.hzims.operational.main.service.AreaService; import com.hnac.hzims.operational.main.service.IAnalyseDataService; import com.hnac.hzims.operational.main.service.IMainSystemMonitoringService; +import com.hnac.hzims.operational.main.service.IWeatherService; import com.hnac.hzims.operational.main.vo.*; import com.hnac.hzims.operational.station.entity.HzimsAnalyzeModelStationEntity; import com.hnac.hzims.operational.station.entity.StationEntity; @@ -67,16 +67,18 @@ public class HzimsDataServiceImpl implements HzimsDataService { private final IStationService stationService; + private final IWeatherService weatherService; + private final IAnalyseDataService dataService; private final IHzimsAnalyzeModelStationService modelStationService; private final IMainSystemMonitoringService maintenanceTaskService; - private final IEmInfoClient deviceClient; - private final ISysClient sysClient; + private final IEmInfoClient deviceClient; + private final IPlanGenertionClient planGenertionClient; private final RedisTemplate redisTemplate; @@ -88,6 +90,8 @@ public class HzimsDataServiceImpl implements HzimsDataService { private final static String conver_power_key = "hzims:operation:conver:power:"; + private final static String conver_weather_key = "hzims:operation:conver:weather:"; + private final static String recent_year_power_data = "hzims:operation:key:power:data"; private final static String loadwater_level_key = "hzims:operation:loadwater:level:key"; @@ -235,6 +239,40 @@ public class HzimsDataServiceImpl implements HzimsDataService { } /** + * 站点天气、降雨、水位 + * @param stationCode + * @return + */ + @Override + public WeatherWaterVo weather(String stationCode) { + WeatherWaterVo redisCache = (WeatherWaterVo) redisTemplate.opsForValue().get(conver_weather_key + stationCode); + if(!ObjectUtil.isEmpty(redisCache)){ + return redisCache; + } + WeatherWaterVo weatherWater = new WeatherWaterVo(); + // 查询站点 + StationEntity station = stationService.getOne(Wrappers.lambdaQuery(). + eq(StationEntity::getCode,stationCode) + ); + if(ObjectUtil.isEmpty(station)){ + return new WeatherWaterVo(); + } + weatherWater.setStationName(station.getName()); + // 七天天气 + Map weekWeather = this.getWeekWeather(Collections.singletonList(station.getCode())); + if(!MapUtils.isEmpty(weekWeather)){ + HeWeatherWeatherDailyResponse week = weekWeather.get(stationCode); + if(!ObjectUtil.isEmpty(week)){ + weatherWater.setDailys(week.getDaily()); + } + } + weatherWater.setWeatherRains(this.waterRain(stationCode)); + redisTemplate.opsForValue().set(conver_weather_key + stationCode,weatherWater); + redisTemplate.expire(conver_weather_key + stationCode,30, TimeUnit.MINUTES); + return weatherWater; + } + + /** * 站点功率换算电量 * @param stationCode * @return @@ -263,6 +301,58 @@ public class HzimsDataServiceImpl implements HzimsDataService { return convert; } + + /** + * 获取七天天气 + * @param codes + */ + private Map getWeekWeather(List codes) { + if(CollectionUtil.isEmpty(codes)){ + return null; + } + // 实时天气 + return this.weatherService.getWeekWeather(codes); + } + + /** + * 30天水位、降雨量 + * @param stationCode + * @return + */ + private List waterRain(String stationCode) { + Calendar calendar = Calendar.getInstance(); + String endTime = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATETIME); + 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)); + calendar.add(Calendar.DAY_OF_MONTH,-29); + String startTime = DateUtil.format(calendar.getTime(),DateUtil.PATTERN_DATETIME); + // 查询水位数据 + List waters = this.water(startTime,endTime,stationCode); + // TODO 查询降雨数据 + // 近30天水位、降雨量 + List days = this.get30Day(); + return days.stream().map(day->{ + WeatherRainVo weatherRain = new WeatherRainVo(); + weatherRain.setTime(day); + // 水位 + if(CollectionUtil.isEmpty(waters)){ + weatherRain.setWater(0.0); + }else{ + weatherRain.setWater(waters.stream().filter(o->o.getTs().contains(day)).mapToDouble(water->{ + if(StringUtil.isEmpty(water.getVal())){ + return 0.0; + }else{ + return Double.parseDouble(water.getVal()); + } + }).sum()); + } + // TODO 降雨量数据 + weatherRain.setRain(0.0); + return weatherRain; + }).collect(Collectors.toList()); + } + /** * 查询近30天发电量 * @param deptId @@ -375,7 +465,7 @@ public class HzimsDataServiceImpl implements HzimsDataService { return new ArrayList<>(); } // 水位查询 - return dataService.periodTargetData(startTime,endTime,3,2,model.getInstanceCode(),HomePageConstant.FRONT_WATER_LEVEL); + return dataService.periodTargetData(startTime,endTime,3,3,model.getInstanceCode(),HomePageConstant.FRONT_WATER_LEVEL); } @@ -400,6 +490,28 @@ public class HzimsDataServiceImpl implements HzimsDataService { } /** + * 获取30天 + * @return + */ + private List get30Day() { + List times = new ArrayList<>(); + Calendar calendar = Calendar.getInstance(); + Date end = calendar.getTime(); + 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)); + calendar.add(Calendar.DAY_OF_MONTH,-29); + Date start = calendar.getTime(); + while (start.compareTo(end) < 0) { + times.add(DateUtil.format(calendar.getTime(),"yyyy-MM-dd")); + calendar.add(Calendar.DAY_OF_MONTH,1); + start = calendar.getTime(); + } + return times; + } + + + /** * 获取24小时 * @return */