Browse Source

#降雨量统计修改

zhongwei
yang_shj 9 months ago
parent
commit
2fd2217c3b
  1. 25
      hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/home/wind/RainMon.java
  2. 3
      hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/constant/MainConstants.java
  3. 2
      hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/WaterMonDataVo.java
  4. 4
      hzims-service-api/weather-api/src/main/java/com/hnac/hzims/hzimsweather/feign/IHeWeatherWeatherClient.java
  5. 14
      hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/mapper/operation/RainFallMapper.java
  6. 13
      hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/RealTargetScheduledTask.java
  7. 11
      hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/RainFallService.java
  8. 21
      hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/impl/RainFallServiceImpl.java
  9. 12
      hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/RealTargetService.java
  10. 134
      hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/impl/RealTargetServiceImpl.java
  11. 2
      hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/monitor/impl/MonitorServiceImpl.java
  12. 6
      hzims-service/hzims-scheduled/src/main/resources/mapper/operation/RainFallMapper.xml
  13. 74
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/WaterServiceImpl.java

25
hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/home/wind/RainMon.java

@ -0,0 +1,25 @@
package com.hnac.hzims.operational.home.wind;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @author ysj
*/
@Data
@ApiModel(value = "降雨月数据")
public class RainMon {
@ApiModelProperty(value = "年份")
private Integer year;
@ApiModelProperty(value = "月份")
private Integer month;
@ApiModelProperty(value = "字符串格式月份")
private String strMon;
@ApiModelProperty(value = "降雨量")
private Double rain;
}

3
hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/constant/MainConstants.java

@ -32,6 +32,9 @@ public interface MainConstants {
// 水利-泵站指标数据
String LOAD_WATER_PUMP_TARGET = "loadWaterPumpTarget";
// 水利-降雨指标数据
String LOAD_RAINFALL_TARGET = "loadRainfallTarget";
String LOAD_HOME_TARGET = "loadHomeTarget";
// 水利-泵站实时数据

2
hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/main/vo/WaterMonDataVo.java

@ -21,5 +21,5 @@ public class WaterMonDataVo {
private Float use;
@ApiModelProperty(value = "降雨量")
private Float rainfall;
private Double rainfall;
}

4
hzims-service-api/weather-api/src/main/java/com/hnac/hzims/hzimsweather/feign/IHeWeatherWeatherClient.java

@ -80,7 +80,9 @@ public interface IHeWeatherWeatherClient {
* @return 降雨量月统计对象
*/
@GetMapping(API_PREFIX + "/getRainFallMonthCount/{year}/{stationCodes}")
R<Map<String,List<RainFallCountByMonthVo>>> getRainFallMonthCount(@PathVariable("year") @ApiParam("降雨量统计年份") String year,
R<Map<String,List<RainFallCountByMonthVo>>>
getRainFallMonthCount(@PathVariable("year") @ApiParam("降雨量统计年份") String year,
@PathVariable("stationCodes") @ApiParam("降雨量站点统计,多个按逗号分隔") String stationCodes);
/**

14
hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/mapper/operation/RainFallMapper.java

@ -0,0 +1,14 @@
package com.hnac.hzims.scheduled.mapper.operation;
import com.hnac.hzims.operational.fill.entity.RainfallEntity;
import org.springblade.core.datascope.mapper.UserDataScopeBaseMapper;
/**
* @author ysj
* @date 2024/03/06 09:23:14
* @version 4.0.0
*/
public interface RainFallMapper extends UserDataScopeBaseMapper<RainfallEntity> {
}

13
hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/scheduled/RealTargetScheduledTask.java

@ -95,6 +95,19 @@ public class RealTargetScheduledTask {
}
/**
* 水利-降雨指标加载
*/
@XxlJob(LOAD_RAINFALL_TARGET)
//@Scheduled(cron = "0/40 * * * * ? ")
public ReturnT<String> loadRainfallTarget(String param) {
if (Func.isBlank(param)) {
param = DateUtil.format(new Date(), "yyyy-MM");
}
service.loadRainfallTarget(param);
return new ReturnT<>("SUCCESS");
}
/**
* 水利-站点水位数据
*/
@XxlJob(LOAD_WATER_LEVEL)

11
hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/RainFallService.java

@ -0,0 +1,11 @@
package com.hnac.hzims.scheduled.service.operation.fill;
import com.hnac.hzims.operational.fill.entity.RainfallEntity;
import org.springblade.core.mp.base.BaseService;
/**
* @author ysj
*/
public interface RainFallService extends BaseService<RainfallEntity> {
}

21
hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/fill/impl/RainFallServiceImpl.java

@ -0,0 +1,21 @@
package com.hnac.hzims.scheduled.service.operation.fill.impl;
import com.hnac.hzims.operational.fill.entity.RainfallEntity;
import com.hnac.hzims.scheduled.mapper.operation.RainFallMapper;
import com.hnac.hzims.scheduled.service.operation.fill.RainFallService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springframework.stereotype.Service;
/**
* @author ysj
* @date 2023/04/10 11:16:07
* @version 4.0.0
*/
@Slf4j
@Service
@AllArgsConstructor
public class RainFallServiceImpl extends BaseServiceImpl<RainFallMapper, RainfallEntity> implements RainFallService {
}

12
hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/RealTargetService.java

@ -8,31 +8,25 @@ import java.util.List;
*/
public interface RealTargetService {
void loadEmInfo(String param);
// 水电站实时数据加载
void loadHydropowerReal(String param);
// 水电站指标数据加载
void loadHydropowerTarget(String param);
// 泵站实时数据加载
void loadWaterPumpReal(String param);
// 泵站指标数据加载
void loadWaterPumpTarget(String param);
// 站点水位指标数据
void loadRainfallTarget(String param);
void loadWaterLevel(String param);
// 光伏站实时数据加载
void loadPhotovoltaicReal(String param);
// 光伏站指标数据加载
void loadPhotovoltaicTarget(String param);
// 光伏、水电站近3年发电量
void loadPowerData(String param, List<Integer> types, Integer serveType, int year);
void loadPowerDataByWindEnergy(String param, List<Integer> types, Integer serveType, int year,String key);
}

134
hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/home/impl/RealTargetServiceImpl.java

@ -7,6 +7,10 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.hnac.hzims.EquipmentConstants;
import com.hnac.hzims.equipment.entity.EmParamEntity;
import com.hnac.hzims.equipment.vo.EminfoAndEmParamVo;
import com.hnac.hzims.hzimsweather.feign.IHeWeatherWeatherClient;
import com.hnac.hzims.hzimsweather.vo.RainFallCountByMonthVo;
import com.hnac.hzims.operational.fill.entity.RainfallEntity;
import com.hnac.hzims.operational.home.wind.RainMon;
import com.hnac.hzims.operational.main.constant.HomePageConstant;
import com.hnac.hzims.operational.main.vo.*;
import com.hnac.hzims.operational.station.StationConstants;
@ -46,6 +50,8 @@ import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@ -63,12 +69,18 @@ public class RealTargetServiceImpl implements RealTargetService {
private final DataService dataService;
private final WindService windService;
private final PowerService powerService;
private final DeviceService deviceService;
private final StationService stationService;
private final StorageService storageService;
private final RainFallService rainFallService;
private final GenerateService generateService;
private final DeviceParamService deviceParamService;
@ -78,8 +90,8 @@ public class RealTargetServiceImpl implements RealTargetService {
private final ModelStationService modelStationService;
private final RedisTemplate redisTemplate;
private final WindService windService;
private final StorageService storageService;
private final IHeWeatherWeatherClient heWeatherWeatherClient;
private final IHistoryDataSearchClient historyDataSearchClient;
@ -96,6 +108,7 @@ public class RealTargetServiceImpl implements RealTargetService {
private final static String load_hydropower_unit_target_key = "hzims:operation:loadhydropowerunit:target:key";
private final static String loadwaterpump_target_key = "hzims:operation:loadwaterpump:target:key";
private final static String loadwaterpump_real_key = "hzims:operation:loadwaterpump:real:key";
private final static String loadwaterpump_rain_key = "hzims:operation:loadwaterpump:rain:key";
private final static String loadwater_level_key = "hzims:operation:loadwater:level:key";
private final static String load_photovoltaic_real_key = "hzims:operation:photovoltaic:real:key";
private final static String load_photovoltaic_target_key = "hzims:operation:photovoltaic:target:key";
@ -377,6 +390,120 @@ public class RealTargetServiceImpl implements RealTargetService {
}
/**
* 降雨量数据加载
* @param param
*/
@Override
public void loadRainfallTarget(String param) {
// 查询带运维泵站/闸门
List<StationEntity> stations = stationService.list(Wrappers.<StationEntity>lambdaQuery()
.eq(StationEntity::getServeType,HomePageConstant.HYDROPOWER_SERVETYPE)
.in(StationEntity::getType,HomePageConstant.waterList)
);
if(CollectionUtil.isEmpty(stations)){
return;
}
// 查询水利站点天气降雨
Map<String,List<RainFallCountByMonthVo>> weathers = this.weatherRains(stations.stream().map(StationEntity::getCode).collect(Collectors.toList()));
// 查询填报降雨量
Map<String,List<RainfallEntity>> fills = this.rainFills(stations.stream().map(StationEntity::getCode).collect(Collectors.toList()));
if(MapUtils.isEmpty(weathers) && MapUtils.isEmpty(fills)){
return;
}
Map<String,List<RainMon>> rainMap = new HashMap<>();
stations.forEach(item->{
List<RainMon> rains = new ArrayList<>();
if(weathers.containsKey(item.getCode())){
rains.addAll(weathers.get(item.getCode()).stream().map(weather->{
RainMon rain = new RainMon();
LocalDate localDate = LocalDate.parse(DateUtil.format(new Date(), weather.getYearAndMonth() + "-01"), DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATE));
rain.setYear(localDate.getYear());
rain.setStrMon(weather.getYearAndMonth());
rain.setMonth(localDate.getMonthValue());
rain.setRain(weather.getRainFallCount());
return rain;
}).collect(Collectors.toList()));
}
if(fills.containsKey(item.getCode())){
rains.addAll(fills.get(item.getCode()).stream().map(fill->{
RainMon rain = new RainMon();
LocalDate localDate = LocalDate.parse(DateUtil.format(new Date(), fill.getFillDate() + "-01"), DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATE));
rain.setYear(localDate.getYear());
rain.setStrMon(fill.getFillDate());
rain.setMonth(localDate.getMonthValue());
rain.setRain(fill.getRain().doubleValue());
return rain;
}).collect(Collectors.toList()));
}
rainMap.put(item.getCode(),rains);
});
if(MapUtils.isEmpty(rainMap)){
return;
}
redisTemplate.opsForValue().set(loadwaterpump_rain_key,rainMap);
}
/**
* 查询天气降雨量
* @param stationCodes
* @return
*/
private Map<String, List<RainFallCountByMonthVo>> weatherRains(List<String> stationCodes) {
Calendar calendar = Calendar.getInstance();
// 当年
String first = DateUtil.format(calendar.getTime(),"yyyy");
R<Map<String, List<RainFallCountByMonthVo>>> firsts = heWeatherWeatherClient.getRainFallMonthCount(first,String.join(",",stationCodes));
// 上一年
calendar.add(Calendar.YEAR,-1);
String second = DateUtil.format(calendar.getTime(),"yyyy");
R<Map<String, List<RainFallCountByMonthVo>>> seconds = heWeatherWeatherClient.getRainFallMonthCount(second,String.join(",",stationCodes));
if(!firsts.isSuccess() && !seconds.isSuccess()){
return new HashMap<>();
}
if(MapUtils.isEmpty(firsts.getData()) && MapUtils.isEmpty(seconds.getData())){
return new HashMap<>();
}
if(MapUtils.isEmpty(firsts.getData())){
return seconds.getData();
}else if(MapUtils.isEmpty(seconds.getData())){
return firsts.getData();
}
return Stream.of(firsts.getData(), seconds.getData())
.flatMap(map -> map.entrySet().stream())
.collect(Collectors.toMap(Map.Entry::getKey,Map.Entry::getValue,(value1, value2) -> {
List<RainFallCountByMonthVo> rains = new ArrayList<>();
rains.addAll(value1);
rains.addAll(value2);
return rains;
}));
}
/**
* 查询填报降雨量
* @param stationCodes
* @return
*/
private Map<String, List<RainfallEntity>> rainFills(List<String> stationCodes) {
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.YEAR,1);
calendar.add(Calendar.MONTH,-(calendar.get(Calendar.MONTH) + 1));
String end = DateUtil.format(calendar.getTime(),"yyyy-MM");
calendar.add(Calendar.YEAR,-1);
calendar.add(Calendar.MONTH,-calendar.get(Calendar.MONTH));
String start = DateUtil.format(calendar.getTime(),"yyyy-MM");
List<RainfallEntity> rains = rainFallService.list(Wrappers.<RainfallEntity>lambdaQuery()
.in(RainfallEntity::getStationCode,stationCodes)
.ge(RainfallEntity::getFillDate,start)
.le(RainfallEntity::getFillDate,end)
);
if(CollectionUtil.isEmpty(rains)){
return new HashMap<>();
}
return rains.stream().collect(Collectors.groupingBy(RainfallEntity::getStationCode));
}
/**
* 水利-站点水位数据
* @param param
*/
@ -1217,9 +1344,8 @@ public class RealTargetServiceImpl implements RealTargetService {
* @return
*/
private Map<String, Float> getGenerateYearByWindEnergy(StationEntity station, String start, String end) {
List<PowerMonthVo> datas = new ArrayList<>();
// 补充填报数据
datas.addAll(this.generateFill(station,start,end));
List<PowerMonthVo> datas = new ArrayList<>(this.generateFill(station, start, end));
if(CollectionUtil.isEmpty(datas)){
return null;
}

2
hzims-service/hzims-scheduled/src/main/java/com/hnac/hzims/scheduled/service/operation/monitor/impl/MonitorServiceImpl.java

@ -372,7 +372,7 @@ public class MonitorServiceImpl implements MonitorService {
/**
* 设备处理
*
* @param list
* @param list
* @param map
* @param device
*/

6
hzims-service/hzims-scheduled/src/main/resources/mapper/operation/RainFallMapper.xml

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.hnac.hzims.scheduled.mapper.operation.RainFallMapper">
</mapper>

74
hzims-service/operational/src/main/java/com/hnac/hzims/operational/main/service/impl/WaterServiceImpl.java

@ -11,6 +11,7 @@ import com.hnac.hzims.hzimsweather.response.weather.HeWeatherWeatherDailyRespons
import com.hnac.hzims.hzimsweather.response.weather.HeWeatherWeatherNowResponse;
import com.hnac.hzims.hzimsweather.vo.RainFallCountByMonthVo;
import com.hnac.hzims.operational.fill.service.UseService;
import com.hnac.hzims.operational.home.wind.RainMon;
import com.hnac.hzims.operational.main.constant.HomePageConstant;
import com.hnac.hzims.operational.main.service.*;
import com.hnac.hzims.operational.main.vo.*;
@ -88,11 +89,9 @@ public class WaterServiceImpl implements IWaterService {
@Value("${hzims.operation.realIdKey}")
public String real_id_key;
private final static String loadwaterpump_target_key = "hzims:operation:loadwaterpump:target:key";
private final static String loadwaterpump_real_key = "hzims:operation:loadwaterpump:real:key";
private final static String loadwaterpump_rain_key = "hzims:operation:loadwaterpump:rain:key";
private final static String loadwater_level_key = "hzims:operation:loadwater:level:key";
/**
@ -1058,51 +1057,48 @@ public class WaterServiceImpl implements IWaterService {
*/
@Override
public List<WaterYearDataVo> waterYearRain(Long deptId) {
R<List<Dept>> R = sysClient.getDeptByCurrentUser();
if (!R.isSuccess() || ObjectUtil.isEmpty(R.getData())) {
return null;
Map<String, List<RainMon>> rainMap = (Map<String, List<RainMon>>) redisTemplate.opsForValue().get(loadwaterpump_rain_key);
if(MapUtils.isEmpty(rainMap)){
return new ArrayList<>();
}
// 获取水利站点
List<StationEntity> stationList = stationService.getStationList(R.getData(),deptId,HomePageConstant.waterList,HomePageConstant.HYDROPOWER_SERVETYPE,false);
if(CollectionUtil.isEmpty(stationList)){
return null;
R<List<Dept>> depts = sysClient.getDeptChild(deptId);
if (!depts.isSuccess() || ObjectUtil.isEmpty(depts.getData())) {
return new ArrayList<>();
}
List<String> codeList = stationList.stream().map(StationEntity::getCode).filter(StringUtil::isNotBlank).collect(Collectors.toList());
if(CollectionUtil.isEmpty(codeList)){
return null;
// 获取水利站点
List<StationEntity> stations = stationService.list(Wrappers.<StationEntity>lambdaQuery()
.in(StationEntity::getRefDept,depts.getData().stream().map(Dept::getId).collect(Collectors.toList()))
.in(StationEntity::getType,HomePageConstant.waterList)
.eq(StationEntity::getServeType,HomePageConstant.HYDROPOWER_SERVETYPE));
if(CollectionUtil.isEmpty(stations)){
return new ArrayList<>();
}
// 获取降雨数据
Map<String,List<RainFallCountByMonthVo>> map = this.getYearRain(codeList,1);
if(MapUtils.isEmpty(map)){
return null;
List<RainMon> rains = new ArrayList<>();
stations.forEach(station->{
if(!rainMap.containsKey(station.getCode())){
return;
}
// 对象转换
List<WaterMonDataVo> waterMonDataVoList = new ArrayList<>();
map.forEach((key,value) -> {
WaterMonDataVo waterMonDataVo = new WaterMonDataVo();
waterMonDataVo.setStrMonth(key);
LocalDate localDate = LocalDate.parse(DateUtil.format(new Date(), key+"-01"), DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATE));
waterMonDataVo.setYear(localDate.getYear());
waterMonDataVo.setMonth(localDate.getMonthValue());
float rain = (float) value.stream().mapToDouble(RainFallCountByMonthVo::getRainFallCount).sum();
waterMonDataVo.setRainfall(rain);
waterMonDataVoList.add(waterMonDataVo);
rains.addAll(rainMap.get(station.getCode()));
});
if (CollectionUtil.isEmpty(waterMonDataVoList)) {
if (CollectionUtil.isEmpty(rains)) {
return null;
}
// 根据年份分组
Map<Integer, List<WaterMonDataVo>> yearMap = waterMonDataVoList.stream().collect(Collectors.groupingBy(WaterMonDataVo::getYear));
Map<Integer, List<RainMon>> years = rains.stream().collect(Collectors.groupingBy(RainMon::getYear));
// 遍历为返回结构
List<WaterYearDataVo> result = new ArrayList<>();
yearMap.forEach((key, value) -> {
WaterYearDataVo vo = new WaterYearDataVo();
vo.setYear(key);
List<WaterMonDataVo> sortValue = value.stream().sorted(Comparator.comparing(WaterMonDataVo::getMonth)).collect(Collectors.toList());
vo.setMonList(sortValue);
result.add(vo);
});
return result;
return years.entrySet().stream().map(entry-> {
WaterYearDataVo year = new WaterYearDataVo();
year.setYear(entry.getKey());
year.setMonList(entry.getValue().stream().collect(Collectors.groupingBy(RainMon::getStrMon)).entrySet().stream().map(mon -> {
WaterMonDataVo waterMon = new WaterMonDataVo();
LocalDate localDate = LocalDate.parse(DateUtil.format(new Date(), mon.getKey() + "-01"), DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATE));
waterMon.setStrMonth(mon.getKey());
waterMon.setMonth(localDate.getMonthValue());
waterMon.setRainfall(mon.getValue().stream().mapToDouble(RainMon::getRain).sum());
return waterMon;
}).sorted(Comparator.comparing(WaterMonDataVo::getStrMonth)).collect(Collectors.toList()));
return year;
}).collect(Collectors.toList());
}
/**

Loading…
Cancel
Save