预报方案分页查询增加条件;参数配置保存接口优化
parent
bae7a0ea9f
commit
4cd6e74627
|
|
@ -1,6 +1,7 @@
|
|||
package com.gunshi.project.xyt.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
|
|
@ -22,7 +23,10 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 描述: 预报_前期影响雨量折减系数表
|
||||
* author: cxw
|
||||
|
|
@ -47,6 +51,12 @@ public class ForecastKController {
|
|||
@Operation(summary = "修改")
|
||||
@PostMapping("/update")
|
||||
public R<ForecastK> update(@Validated(Update.class) @RequestBody ForecastK dto) {
|
||||
ForecastK oldK = service.getById(dto.getMonth());
|
||||
if (Objects.isNull(oldK)) {
|
||||
throw new IllegalArgumentException("当前数据不存在");
|
||||
}
|
||||
dto.setChtm(oldK.getChtm());
|
||||
dto.setUpdateTime(new Date());
|
||||
boolean result = service.updateById(dto);
|
||||
return R.ok(result ? dto : null);
|
||||
}
|
||||
|
|
@ -77,4 +87,16 @@ public class ForecastKController {
|
|||
return R.ok(service.page(forecastK.getPageSo().toPage(), wrapper));
|
||||
}
|
||||
|
||||
@Operation(summary = "批量保存")
|
||||
@PostMapping("/saveBatch")
|
||||
public R<Boolean> saveBatch(@RequestBody List<ForecastK> dtos) {
|
||||
boolean result = false;
|
||||
if (CollectionUtils.isNotEmpty(dtos)) {
|
||||
boolean remove = service.remove(new QueryWrapper<>());
|
||||
if (remove) {
|
||||
result = service.saveBatch(dtos);
|
||||
}
|
||||
}
|
||||
return R.ok(result);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -77,4 +77,13 @@ public class ForecastPPaRController {
|
|||
return R.ok(service.page(forecastPPaR.getPageSo().toPage(), wrapper));
|
||||
}
|
||||
|
||||
@Operation(summary = "批量保存")
|
||||
@PostMapping("/saveBatch")
|
||||
public R<Boolean> saveBatch(@RequestBody String[][] PPaRList) {
|
||||
if (PPaRList.length == 0) {
|
||||
throw new IllegalArgumentException("数据格式不正确");
|
||||
}
|
||||
boolean result = service.handleSaveBatch(PPaRList);
|
||||
return R.ok(result);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -80,8 +80,9 @@ public class ForecastProjectController {
|
|||
@PostMapping("/list")
|
||||
public R<List<ForecastProject>> list(@RequestBody @Validated ForecastProject forecastProject) {
|
||||
QueryWrapper<ForecastProject> wrapper = new QueryWrapper<ForecastProject>()
|
||||
.in("status", "0", "1")// 只返回启用和暂停的
|
||||
.like(ObjectUtils.isNotNull(forecastProject.getName()), "name", forecastProject.getName());
|
||||
.like(ObjectUtils.isNotNull(forecastProject.getName()), "name", forecastProject.getName())
|
||||
.ge(ObjectUtils.isNotNull(forecastProject.getStartTm()), "forecast_tm", forecastProject.getStartTm())
|
||||
.le(ObjectUtils.isNotNull(forecastProject.getEndTm()), "forecast_tm", forecastProject.getEndTm());
|
||||
if(StringUtils.isNotBlank(forecastProject.getSortField())){
|
||||
wrapper.orderBy(true, ObjectUtils.isEmpty(forecastProject.getIsAsc()) ? false : forecastProject.getIsAsc(), forecastProject.getSortField());
|
||||
}
|
||||
|
|
@ -92,8 +93,9 @@ public class ForecastProjectController {
|
|||
@PostMapping("/page")
|
||||
public R<Page<ForecastProject>> page(@RequestBody @Validated ForecastProject forecastProject) {
|
||||
QueryWrapper<ForecastProject> wrapper = new QueryWrapper<ForecastProject>()
|
||||
.in("status", "0", "1")// 只返回启用和暂停的
|
||||
.like(ObjectUtils.isNotNull(forecastProject.getName()), "name", forecastProject.getName());
|
||||
.like(ObjectUtils.isNotNull(forecastProject.getName()), "name", forecastProject.getName())
|
||||
.ge(ObjectUtils.isNotNull(forecastProject.getStartTm()), "forecast_tm", forecastProject.getStartTm())
|
||||
.le(ObjectUtils.isNotNull(forecastProject.getEndTm()), "forecast_tm", forecastProject.getEndTm());
|
||||
if(StringUtils.isNotBlank(forecastProject.getSortField())){
|
||||
wrapper.orderBy(true, ObjectUtils.isEmpty(forecastProject.getIsAsc()) ? false : forecastProject.getIsAsc(), forecastProject.getSortField());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package com.gunshi.project.xyt.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||||
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||
|
|
@ -23,7 +24,10 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 描述: 预报_时段单位线表
|
||||
* author: cxw
|
||||
|
|
@ -49,6 +53,12 @@ public class ForecastUController {
|
|||
@Operation(summary = "修改")
|
||||
@PostMapping("/update")
|
||||
public R<ForecastU> update(@Validated(Update.class) @RequestBody ForecastU dto) {
|
||||
ForecastU oldU = service.getById(dto.getId());
|
||||
if (Objects.isNull(oldU)) {
|
||||
throw new IllegalArgumentException("当前数据不存在");
|
||||
}
|
||||
dto.setChtm(oldU.getChtm());
|
||||
dto.setUpdateTime(new Date());
|
||||
boolean result = service.updateById(dto);
|
||||
return R.ok(result ? dto : null);
|
||||
}
|
||||
|
|
@ -79,4 +89,19 @@ public class ForecastUController {
|
|||
return R.ok(service.page(forecastU.getPageSo().toPage(), wrapper));
|
||||
}
|
||||
|
||||
@Operation(summary = "批量保存")
|
||||
@PostMapping("/saveBatch")
|
||||
public R<Boolean> saveBatch(@RequestBody List<ForecastU> dtos) {
|
||||
boolean result = false;
|
||||
if (CollectionUtils.isNotEmpty(dtos)) {
|
||||
boolean remove = service.remove(new QueryWrapper<>());
|
||||
if (remove) {
|
||||
for (ForecastU u : dtos) {
|
||||
u.setId(IdWorker.getId());
|
||||
}
|
||||
result = service.saveBatch(dtos);
|
||||
}
|
||||
}
|
||||
return R.ok(result);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,8 +12,6 @@ import com.gunshi.core.dateformat.DateFormatString;
|
|||
import com.gunshi.project.xyt.entity.page.GenericPageParams;
|
||||
import com.gunshi.project.xyt.entity.vo.ForecastResultVo;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import lombok.Data;
|
||||
|
||||
|
|
@ -50,8 +48,6 @@ public class ForecastProject extends GenericPageParams implements Serializable {
|
|||
@TableField(value="name")
|
||||
@Schema(description="预报任务名称")
|
||||
@Size(max = 255,message = "预报任务名称最大长度要小于 255")
|
||||
@NotBlank(message = "预报任务名称不能为空")
|
||||
@NotNull(message = "预报任务名称不能为空")
|
||||
private String name;
|
||||
|
||||
/**
|
||||
|
|
@ -60,8 +56,6 @@ public class ForecastProject extends GenericPageParams implements Serializable {
|
|||
@TableField(value="type")
|
||||
@Schema(description="类型(1:自动 2:手动)")
|
||||
@Size(max = 1,message = "类型(1:自动 2:手动)最大长度要小于 1")
|
||||
@NotBlank(message = "类型(1:自动 2:手动)不能为空")
|
||||
@NotNull(message = "类型(1:自动 2:手动)不能为空")
|
||||
private String type;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.gunshi.project.xyt.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.gunshi.project.xyt.mapper.ForecastPPaRMapper;
|
||||
import com.gunshi.project.xyt.model.ForecastPPaR;
|
||||
|
|
@ -7,6 +8,12 @@ import lombok.extern.slf4j.Slf4j;
|
|||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 描述: 预报_降雨径流关系表
|
||||
* author: cxw
|
||||
|
|
@ -18,6 +25,68 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
public class ForecastPPaRService extends ServiceImpl<ForecastPPaRMapper, ForecastPPaR>
|
||||
{
|
||||
|
||||
/**
|
||||
* @description: 处理批量保存
|
||||
* @param PPaRList
|
||||
* @return: boolean
|
||||
* @auther: cxw
|
||||
* @date: 2024-08-06, 周二, 15:29:29
|
||||
*/
|
||||
public boolean handleSaveBatch(String[][] PPaRList) {
|
||||
Boolean ret = false;
|
||||
List<String> paStr = new ArrayList<>();
|
||||
List<String> pStr = new ArrayList<>();
|
||||
Map<String, BigDecimal> rMap = new HashMap<>();
|
||||
// 行
|
||||
for (int i = 0; i < PPaRList.length; i++) {
|
||||
String p = "";
|
||||
// 列
|
||||
for (int j = 0; j < PPaRList[i].length; j++) {
|
||||
String pa = "";
|
||||
// 第一行:pa
|
||||
if(i == 0 && j > 0){
|
||||
pa = PPaRList[i][j];
|
||||
paStr.add(pa);
|
||||
}
|
||||
// 第一列:p
|
||||
if(i > 0 && j == 0){
|
||||
p = PPaRList[i][j];
|
||||
pStr.add(p);
|
||||
}
|
||||
// rMap:key=P-Pa
|
||||
if (i > 0 && j > 0) {
|
||||
rMap.put(p + "-" + paStr.get(j - 1), new BigDecimal(PPaRList[i][j]));
|
||||
}
|
||||
}
|
||||
}
|
||||
// 组装数据
|
||||
if (paStr.size() > 0 && pStr.size() > 0 && rMap.size() > 0) {
|
||||
List<ForecastPPaR> forecastPPaRList = new ArrayList<>();
|
||||
// 外层pa
|
||||
for (String pa : paStr) {
|
||||
// 循环一次pa,rSum需要重置
|
||||
BigDecimal rSum = BigDecimal.ZERO;
|
||||
// 内层p
|
||||
for (String p : pStr) {
|
||||
ForecastPPaR forecastPPaR = new ForecastPPaR();
|
||||
BigDecimal r = rMap.get(p + "-" + pa);
|
||||
forecastPPaR.setR(r.stripTrailingZeros());
|
||||
forecastPPaR.setPsum(new BigDecimal(p).stripTrailingZeros());
|
||||
// 循环累加
|
||||
rSum = rSum.add(r);
|
||||
forecastPPaR.setRsum(rSum.stripTrailingZeros());
|
||||
forecastPPaR.setPa(new BigDecimal(pa).stripTrailingZeros());
|
||||
forecastPPaRList.add(forecastPPaR);
|
||||
}
|
||||
}
|
||||
if (forecastPPaRList.size() > 0) {
|
||||
// 先全部删除
|
||||
this.remove(new QueryWrapper<>());
|
||||
ret = this.saveBatch(forecastPPaRList);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue