parent
7844d16cf8
commit
c07f286215
|
|
@ -0,0 +1,63 @@
|
||||||
|
package com.gunshi.project.hsz.controller;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.gunshi.core.result.R;
|
||||||
|
import com.gunshi.project.hsz.common.validate.markers.Insert;
|
||||||
|
import com.gunshi.project.hsz.common.validate.markers.Update;
|
||||||
|
import com.gunshi.project.hsz.entity.dto.icWaterForecastCaculateDto;
|
||||||
|
import com.gunshi.project.hsz.entity.so.IcWaterForecastPageSo;
|
||||||
|
import com.gunshi.project.hsz.mapper.IaCBsnssinfoMapper;
|
||||||
|
import com.gunshi.project.hsz.model.IcWaterForecast;
|
||||||
|
import com.gunshi.project.hsz.model.IcWaterForecastDetail;
|
||||||
|
import com.gunshi.project.hsz.model.InspectPoint;
|
||||||
|
import com.gunshi.project.hsz.service.IcWaterForecastService;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Tag(name = "来水预测")
|
||||||
|
@RestController
|
||||||
|
@RequestMapping(value="/icWaterForecast")
|
||||||
|
public class IcWaterForecastController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IcWaterForecastService icWaterForecastService;
|
||||||
|
|
||||||
|
@Operation(summary = "分页查询")
|
||||||
|
@PostMapping("/page")
|
||||||
|
public R<Page<IcWaterForecast>> page(@RequestBody IcWaterForecastPageSo pageSo) {
|
||||||
|
return R.ok(icWaterForecastService.pageQuery(pageSo));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Operation(summary = "来水预测计算")
|
||||||
|
@PostMapping("/caculate")
|
||||||
|
public R<List<IcWaterForecastDetail>> caculate(@RequestBody icWaterForecastCaculateDto dto) {
|
||||||
|
return R.ok(icWaterForecastService.caculate(dto));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "修改")
|
||||||
|
@PostMapping("/update")
|
||||||
|
public R<IcWaterForecast> update(@Validated(Update.class) @RequestBody IcWaterForecast dto) {
|
||||||
|
return R.ok(icWaterForecastService.updateData(dto));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "删除")
|
||||||
|
@GetMapping("/del/{id}")
|
||||||
|
public R<Boolean> del(@Schema(name = "id") @PathVariable("id") Serializable id) {
|
||||||
|
return R.ok(icWaterForecastService.delData(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "新增")
|
||||||
|
@PostMapping("/insert")
|
||||||
|
public R<IcWaterForecast> insert(@RequestBody IcWaterForecast dto) {
|
||||||
|
return R.ok(icWaterForecastService.saveData(dto));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,29 @@
|
||||||
|
package com.gunshi.project.hsz.entity.dto;
|
||||||
|
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class icWaterForecastCaculateDto {
|
||||||
|
|
||||||
|
//预测开始时间(用于长期预测)
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||||
|
private LocalDateTime startTime;
|
||||||
|
|
||||||
|
//预测结束时间(用于长期预测)
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||||
|
private LocalDateTime endTime;
|
||||||
|
|
||||||
|
//典型年降雨量(用于长期预测)
|
||||||
|
private Integer year;
|
||||||
|
|
||||||
|
//预测小时(用于短期预测)
|
||||||
|
private Integer hours;
|
||||||
|
|
||||||
|
private Integer type;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
package com.gunshi.project.hsz.entity.so;
|
||||||
|
|
||||||
|
import com.gunshi.db.dto.DateTimeRangeSo;
|
||||||
|
import com.gunshi.db.dto.PageSo;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class IcWaterForecastPageSo {
|
||||||
|
|
||||||
|
private String planName;
|
||||||
|
|
||||||
|
private Integer type;
|
||||||
|
|
||||||
|
private DateTimeRangeSo dateTimeRangeSo;
|
||||||
|
|
||||||
|
@NotNull(message = "分页参数不能为空")
|
||||||
|
@Schema(description = "分页参数")
|
||||||
|
private PageSo pageSo;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
package com.gunshi.project.hsz.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.gunshi.project.hsz.model.IcWaterForecastDetail;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface IcWaterForecastDetailMapper extends BaseMapper<IcWaterForecastDetail> {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
package com.gunshi.project.hsz.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.gunshi.project.hsz.model.IcWaterForecast;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface IcWaterForecastMapper extends BaseMapper<IcWaterForecast> {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,88 @@
|
||||||
|
package com.gunshi.project.hsz.model;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||||
|
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||||
|
import com.gunshi.project.hsz.common.validate.markers.Insert;
|
||||||
|
import com.gunshi.project.hsz.common.validate.markers.Update;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@TableName(value = "ic_water_forecast")
|
||||||
|
public class IcWaterForecast implements Serializable {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主键
|
||||||
|
*/
|
||||||
|
@TableId(value = "id")
|
||||||
|
@Schema(description = "主键")
|
||||||
|
@JsonSerialize(using = ToStringSerializer.class)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 方案名称
|
||||||
|
*/
|
||||||
|
@TableField(value = "plan_name")
|
||||||
|
@Schema(description = "方案名称")
|
||||||
|
@NotNull(message = "方案名称不能为空", groups = {Insert.class, Update.class})
|
||||||
|
private String planName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 预测开始时间
|
||||||
|
*/
|
||||||
|
@TableField(value = "start_time")
|
||||||
|
@Schema(description = "预测开始时间")
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||||
|
private LocalDateTime startTime;//ps:这个地方你截取一下哈,长期的截到年月日,短期不用截
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 预测结束时间
|
||||||
|
*/
|
||||||
|
@TableField(value = "end_time")
|
||||||
|
@Schema(description = "预测结束时间")
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||||
|
private LocalDateTime endTime;//ps:这个地方你截取一下哈,长期的截到年月日,短期不用截
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 预测来水量
|
||||||
|
*/
|
||||||
|
@TableField(value = "forecast_water")
|
||||||
|
@Schema(description = "预测来水量")
|
||||||
|
private BigDecimal forecastWater;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 制定时间
|
||||||
|
*/
|
||||||
|
@TableField(value = "create_time")
|
||||||
|
@Schema(description = "制定时间")
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||||
|
private LocalDateTime createTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 制定人
|
||||||
|
*/
|
||||||
|
@TableField(value = "create_name")
|
||||||
|
@Schema(description = "制定人")
|
||||||
|
private String createName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 类型:0-长期预测,1-短期预测
|
||||||
|
*/
|
||||||
|
@TableField(value = "type")
|
||||||
|
@Schema(description = "类型:0-长期预测,1-短期预测")
|
||||||
|
private Integer type;
|
||||||
|
|
||||||
|
|
||||||
|
@TableField(exist = false)
|
||||||
|
private List<IcWaterForecastDetail> details;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,47 @@
|
||||||
|
package com.gunshi.project.hsz.model;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||||
|
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@TableName(value = "ic_water_forecast_detail")
|
||||||
|
public class IcWaterForecastDetail implements Serializable {
|
||||||
|
|
||||||
|
@TableId(value = "id")
|
||||||
|
@Schema(description = "主键")
|
||||||
|
@JsonSerialize(using = ToStringSerializer.class)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@TableField(value = "ic_water_id")
|
||||||
|
@Schema(description = "来水预测表主键")
|
||||||
|
private Long icWaterId;
|
||||||
|
|
||||||
|
@TableField(value = "start_time")
|
||||||
|
@Schema(description = "预测开始时间(长期)")
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
|
||||||
|
private LocalDateTime startTime;
|
||||||
|
|
||||||
|
@TableField(value = "end_time")
|
||||||
|
@Schema(description = "预测结束时间(长期)")
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
|
||||||
|
private LocalDateTime endTime;
|
||||||
|
|
||||||
|
@TableField(value = "forecast_time")
|
||||||
|
@Schema(description = "预测时间(短期)")
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH", timezone = "GMT+8")
|
||||||
|
private LocalDateTime forecastTime;
|
||||||
|
|
||||||
|
@TableField(value = "forecast_water")
|
||||||
|
@Schema(description = "预测水量")
|
||||||
|
private BigDecimal forecastWater;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,31 @@
|
||||||
|
package com.gunshi.project.hsz.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.gunshi.project.hsz.mapper.IcWaterForecastDetailMapper;
|
||||||
|
import com.gunshi.project.hsz.model.IcWaterForecastDetail;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@Slf4j
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public class IcWaterForecastDetailService extends ServiceImpl<IcWaterForecastDetailMapper, IcWaterForecastDetail> {
|
||||||
|
|
||||||
|
|
||||||
|
public List<IcWaterForecastDetail> listByForecastId(Long forecastId) {
|
||||||
|
LambdaQueryWrapper<IcWaterForecastDetail> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
queryWrapper.eq(IcWaterForecastDetail::getIcWaterId,forecastId);
|
||||||
|
List<IcWaterForecastDetail> icWaterForecastDetails = this.baseMapper.selectList(queryWrapper);
|
||||||
|
return icWaterForecastDetails;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeByForecastId(Long id) {
|
||||||
|
LambdaQueryWrapper<IcWaterForecastDetail> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
queryWrapper.eq(IcWaterForecastDetail::getIcWaterId,id);
|
||||||
|
this.remove(queryWrapper);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,277 @@
|
||||||
|
package com.gunshi.project.hsz.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.gunshi.project.hsz.common.util.LocalDateTimeConverter;
|
||||||
|
import com.gunshi.project.hsz.entity.dto.icWaterForecastCaculateDto;
|
||||||
|
import com.gunshi.project.hsz.entity.so.IcWaterForecastPageSo;
|
||||||
|
import com.gunshi.project.hsz.entity.vo.ForecastResultVo;
|
||||||
|
import com.gunshi.project.hsz.mapper.IcWaterForecastMapper;
|
||||||
|
import com.gunshi.project.hsz.model.*;
|
||||||
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.math.RoundingMode;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.YearMonth;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.time.temporal.ChronoUnit;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@Slf4j
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public class IcWaterForecastService extends ServiceImpl<IcWaterForecastMapper, IcWaterForecast> {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IcWaterForecastDetailService icWaterForecastDetailService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ForecastUseparamService forecastUseparamService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private TyYearRainfallService tyYearRainfallService;//典型年降雨资料
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ForecastResultsService forecastResultsService;//洪水预报
|
||||||
|
|
||||||
|
|
||||||
|
public IcWaterForecast saveData(IcWaterForecast dto) {
|
||||||
|
BigDecimal totalWater = BigDecimal.ZERO;
|
||||||
|
dto.setCreateTime(LocalDateTime.now());
|
||||||
|
List<IcWaterForecastDetail> details = dto.getDetails();
|
||||||
|
for (IcWaterForecastDetail detail : details) {
|
||||||
|
totalWater = totalWater.add(detail.getForecastWater() != null?detail.getForecastWater():BigDecimal.ZERO);
|
||||||
|
}
|
||||||
|
dto.setForecastWater(totalWater);
|
||||||
|
save(dto);
|
||||||
|
details.stream().forEach(item -> {
|
||||||
|
item.setIcWaterId(dto.getId());
|
||||||
|
});
|
||||||
|
dto.setDetails(details);
|
||||||
|
icWaterForecastDetailService.saveBatch(details);
|
||||||
|
return dto;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Page<IcWaterForecast> pageQuery(IcWaterForecastPageSo pageSo) {
|
||||||
|
LambdaQueryWrapper<IcWaterForecast> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
if (pageSo.getType() != null) {
|
||||||
|
queryWrapper.eq(IcWaterForecast::getType, pageSo.getType());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!StringUtils.isBlank(pageSo.getPlanName())) {
|
||||||
|
queryWrapper.like(IcWaterForecast::getPlanName, pageSo.getPlanName());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pageSo.getDateTimeRangeSo() != null) {
|
||||||
|
queryWrapper.ge(IcWaterForecast::getCreateTime, pageSo.getDateTimeRangeSo().getStart());
|
||||||
|
queryWrapper.le(IcWaterForecast::getCreateTime, pageSo.getDateTimeRangeSo().getEnd());
|
||||||
|
}
|
||||||
|
queryWrapper.orderByDesc(IcWaterForecast::getCreateTime);
|
||||||
|
Page<IcWaterForecast> icWaterForecastPage = this.baseMapper.selectPage(pageSo.getPageSo().toPage(), queryWrapper);
|
||||||
|
for (IcWaterForecast record : icWaterForecastPage.getRecords()) {
|
||||||
|
List<IcWaterForecastDetail> icWaterForecastDetails = icWaterForecastDetailService.listByForecastId(record.getId());
|
||||||
|
record.setDetails(icWaterForecastDetails);
|
||||||
|
}
|
||||||
|
return icWaterForecastPage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IcWaterForecast updateData(IcWaterForecast dto) {
|
||||||
|
icWaterForecastDetailService.removeByForecastId(dto.getId());
|
||||||
|
save(dto);
|
||||||
|
dto.getDetails().stream().forEach(item -> {
|
||||||
|
item.setIcWaterId(dto.getId());
|
||||||
|
});
|
||||||
|
icWaterForecastDetailService.saveBatch(dto.getDetails());
|
||||||
|
return dto;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean delData(Serializable id) {
|
||||||
|
icWaterForecastDetailService.removeByForecastId(Long.valueOf(id.toString()));
|
||||||
|
removeById(id);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<IcWaterForecastDetail> caculate(icWaterForecastCaculateDto dto) {
|
||||||
|
//获取水库承雨面积
|
||||||
|
// 承雨面积areaF:"cymj", 河道长lengthL:"hdc", 河道坡降j:"hdpj", 时段∆t:"dt", h毫米净雨:"h"
|
||||||
|
QueryWrapper<ForecastUseparam> qw = new QueryWrapper<ForecastUseparam>().in("param_code", "cymj", "hdc", "hdpj", "dt", "h");
|
||||||
|
List<Map<String, Object>> uMaps = forecastUseparamService.listMaps(qw);
|
||||||
|
Map<String, String> uMap = uMaps.stream().collect(Collectors.toMap(map -> (String) map.get("param_code"), map -> (String) map.get("param_value")));
|
||||||
|
if(uMap.size() <=0 || uMap.get("cymj") == null){
|
||||||
|
throw new IllegalArgumentException("水库承雨面积参数为空,请检查");
|
||||||
|
}
|
||||||
|
List<IcWaterForecastDetail> icWaterForecastDetails;
|
||||||
|
if(dto.getType() == 0){
|
||||||
|
//长期预测
|
||||||
|
icWaterForecastDetails = longForecast(new BigDecimal(uMap.get("cymj")), dto);
|
||||||
|
}else{
|
||||||
|
//短期预测
|
||||||
|
ForecastTask forecastTask = new ForecastTask();
|
||||||
|
// 设置当前时间整点
|
||||||
|
Integer hours = dto.getHours();
|
||||||
|
LocalDateTime now = LocalDateTime.now();
|
||||||
|
LocalDateTime nowHour = now.withMinute(0).withSecond(0).withNano(0);
|
||||||
|
forecastTask.setNowTime(LocalDateTimeConverter.toDate(nowHour));
|
||||||
|
|
||||||
|
// 设置开始时间(当前时间减去一天)
|
||||||
|
LocalDateTime startTime = nowHour.minusDays(1);
|
||||||
|
forecastTask.setStartTime(LocalDateTimeConverter.toDate(startTime));
|
||||||
|
|
||||||
|
// 设置结束时间(当前时间加上durationHours)
|
||||||
|
LocalDateTime endTime = nowHour.plusHours(hours);
|
||||||
|
forecastTask.setEndTime(LocalDateTimeConverter.toDate(endTime));
|
||||||
|
|
||||||
|
forecastTask.setForecastWarm(1);
|
||||||
|
forecastTask.setForecastPeriod(hours); // 设置预报时长
|
||||||
|
icWaterForecastDetails = shortForecast(forecastTask);
|
||||||
|
}
|
||||||
|
return icWaterForecastDetails;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<IcWaterForecastDetail> shortForecast(ForecastTask forecastTask) {
|
||||||
|
//进行洪水预测
|
||||||
|
List<ForecastResultVo> humanForecastResult = forecastResultsService.getHumanForecastResult(forecastTask);
|
||||||
|
List<ForecastResultVo> collect = humanForecastResult.stream().filter(o -> {
|
||||||
|
return o.getIspreDrp().equals("1");
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
List<IcWaterForecastDetail> res = new ArrayList<>();
|
||||||
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||||
|
if(humanForecastResult.size() > 0){
|
||||||
|
for (ForecastResultVo forecastResultVo : collect) {
|
||||||
|
IcWaterForecastDetail entity = new IcWaterForecastDetail();
|
||||||
|
//设置预测时间
|
||||||
|
entity.setForecastTime(LocalDateTime.parse(forecastResultVo.getTm(),formatter));
|
||||||
|
//设置来水量
|
||||||
|
entity.setForecastWater(forecastResultVo.getYcRkQValue().multiply(new BigDecimal(3600)));
|
||||||
|
res.add(entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
//获取典型年-月的降雨
|
||||||
|
public BigDecimal getYearAndMonthRainfall(Integer year, Integer month) {
|
||||||
|
LambdaQueryWrapper<TyYearRainfall> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
queryWrapper.eq(TyYearRainfall::getYear, year);
|
||||||
|
queryWrapper.eq(TyYearRainfall::getMonth, month);
|
||||||
|
TyYearRainfall tyYearRainfall = tyYearRainfallService.getBaseMapper().selectOne(queryWrapper);
|
||||||
|
if(tyYearRainfall == null){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return tyYearRainfall.getDrp();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public List<IcWaterForecastDetail> longForecast(BigDecimal areaF, icWaterForecastCaculateDto dto) {
|
||||||
|
Integer year = dto.getYear();
|
||||||
|
LocalDateTime startTime = dto.getStartTime();
|
||||||
|
LocalDateTime endTime = dto.getEndTime();
|
||||||
|
|
||||||
|
List<IcWaterForecastDetail> result = new ArrayList<>();
|
||||||
|
|
||||||
|
// 获取开始和结束的年月
|
||||||
|
int startYear = startTime.getYear();
|
||||||
|
int startMonth = startTime.getMonthValue();
|
||||||
|
int endYear = endTime.getYear();
|
||||||
|
int endMonth = endTime.getMonthValue();
|
||||||
|
|
||||||
|
// 遍历每个月份
|
||||||
|
int currentYear = startYear;
|
||||||
|
int currentMonth = startMonth;
|
||||||
|
|
||||||
|
while (currentYear < endYear || (currentYear == endYear && currentMonth <= endMonth)) {
|
||||||
|
// 获取该月份的天数
|
||||||
|
YearMonth yearMonth = YearMonth.of(currentYear, currentMonth);
|
||||||
|
int daysInMonth = yearMonth.lengthOfMonth();
|
||||||
|
|
||||||
|
// 计算该月份的起始日和结束日
|
||||||
|
LocalDateTime monthStart = (currentYear == startYear && currentMonth == startMonth)
|
||||||
|
? startTime
|
||||||
|
: LocalDateTime.of(currentYear, currentMonth, 1, 0, 0);
|
||||||
|
|
||||||
|
LocalDateTime monthEnd = (currentYear == endYear && currentMonth == endMonth)
|
||||||
|
? endTime
|
||||||
|
: LocalDateTime.of(currentYear, currentMonth, daysInMonth, 23, 59, 59);
|
||||||
|
|
||||||
|
// 计算该月份的实际天数(考虑开始和结束月份的部分天数)
|
||||||
|
long actualDays = calculateActualDays(monthStart, monthEnd);
|
||||||
|
|
||||||
|
// 获取该月份的降雨量
|
||||||
|
BigDecimal rainfall = getYearAndMonthRainfall(year, currentMonth);
|
||||||
|
if (rainfall == null) {
|
||||||
|
// 如果没有降雨数据,跳过该月份
|
||||||
|
currentMonth++;
|
||||||
|
if (currentMonth > 12) {
|
||||||
|
currentMonth = 1;
|
||||||
|
currentYear++;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 计算公式:=(降雨量/该月份天数*实际天数/1000*(areaF*10^6))/10000
|
||||||
|
BigDecimal forecastWater = calculateForecastWater(rainfall, daysInMonth, actualDays, areaF);
|
||||||
|
|
||||||
|
// 创建明细对象
|
||||||
|
IcWaterForecastDetail detail = new IcWaterForecastDetail();
|
||||||
|
detail.setStartTime(monthStart);
|
||||||
|
detail.setEndTime(monthEnd);
|
||||||
|
detail.setForecastWater(forecastWater);
|
||||||
|
result.add(detail);
|
||||||
|
|
||||||
|
// 移动到下个月
|
||||||
|
currentMonth++;
|
||||||
|
if (currentMonth > 12) {
|
||||||
|
currentMonth = 1;
|
||||||
|
currentYear++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 计算实际天数
|
||||||
|
*/
|
||||||
|
private long calculateActualDays(LocalDateTime start, LocalDateTime end) {
|
||||||
|
return ChronoUnit.DAYS.between(start.toLocalDate(), end.toLocalDate()) + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 计算预测水量
|
||||||
|
* 公式:=(降雨量/该月份天数*实际天数/1000*(areaF*10^6))/10000
|
||||||
|
*/
|
||||||
|
private BigDecimal calculateForecastWater(BigDecimal rainfall, int daysInMonth, long actualDays, BigDecimal areaF) {
|
||||||
|
// 降雨量/该月份天数
|
||||||
|
BigDecimal dailyRainfall = rainfall.divide(BigDecimal.valueOf(daysInMonth), 10, RoundingMode.HALF_UP);
|
||||||
|
|
||||||
|
// * 实际天数
|
||||||
|
BigDecimal totalRainfall = dailyRainfall.multiply(BigDecimal.valueOf(actualDays));
|
||||||
|
|
||||||
|
// /1000
|
||||||
|
BigDecimal rainfallMeters = totalRainfall.divide(BigDecimal.valueOf(1000), 10, RoundingMode.HALF_UP);
|
||||||
|
|
||||||
|
// * (areaF * 10^6)
|
||||||
|
BigDecimal areaSquareMeters = areaF.multiply(BigDecimal.valueOf(1000000));
|
||||||
|
BigDecimal volumeCubicMeters = rainfallMeters.multiply(areaSquareMeters);
|
||||||
|
|
||||||
|
// /10000 转换为万立方米
|
||||||
|
BigDecimal volumeTenThousandCubicMeters = volumeCubicMeters.divide(BigDecimal.valueOf(10000), 2, RoundingMode.HALF_UP);
|
||||||
|
|
||||||
|
return volumeTenThousandCubicMeters;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -29,6 +29,7 @@ public class WarningRuleInfoService extends ServiceImpl<WarningRuleInfoMapper,Wa
|
||||||
queryWrapper.ge(WarningRuleInfo::getCreateTime,page.getDateTimeRangeSo().getStart());
|
queryWrapper.ge(WarningRuleInfo::getCreateTime,page.getDateTimeRangeSo().getStart());
|
||||||
queryWrapper.le(WarningRuleInfo::getCreateTime,page.getDateTimeRangeSo().getEnd());
|
queryWrapper.le(WarningRuleInfo::getCreateTime,page.getDateTimeRangeSo().getEnd());
|
||||||
}
|
}
|
||||||
|
queryWrapper.orderByDesc(WarningRuleInfo::getCreateTime);
|
||||||
Page<WarningRuleInfo> warningRuleInfoPage = this.baseMapper.selectPage(page.getPageSo().toPage(), queryWrapper);
|
Page<WarningRuleInfo> warningRuleInfoPage = this.baseMapper.selectPage(page.getPageSo().toPage(), queryWrapper);
|
||||||
return warningRuleInfoPage;
|
return warningRuleInfoPage;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -66,8 +66,8 @@ public class WarningRuleTask {
|
||||||
@Autowired
|
@Autowired
|
||||||
private RainBasinDivisionService rainBasinDivisionService;
|
private RainBasinDivisionService rainBasinDivisionService;
|
||||||
|
|
||||||
@Scheduled(fixedDelay = 60 * 60 * 1000) // 75分钟,单位毫秒
|
// @Scheduled(fixedDelay = 60 * 60 * 1000) // 75分钟,单位毫秒
|
||||||
@Async
|
// @Async
|
||||||
public void warningRuleExecute(){
|
public void warningRuleExecute(){
|
||||||
//获取配置的预警规则
|
//获取配置的预警规则
|
||||||
List<WarningRule> warningRules = warningRuleService.listData();
|
List<WarningRule> warningRules = warningRuleService.listData();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue