典型年降雨资料
parent
e79dd9ce45
commit
c9f1735b9f
|
|
@ -1,6 +1,9 @@
|
|||
package com.gunshi.project.xyt.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.gunshi.core.result.R;
|
||||
import com.gunshi.project.xyt.entity.so.TyYearRainfallPageSo;
|
||||
import com.gunshi.project.xyt.entity.vo.TyYearRainfallVo;
|
||||
import com.gunshi.project.xyt.model.TyYearRainfall;
|
||||
import com.gunshi.project.xyt.service.TyYearRainfallService;
|
||||
import com.gunshi.project.xyt.validate.markers.Insert;
|
||||
|
|
@ -12,7 +15,6 @@ 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;
|
||||
/**
|
||||
* 描述: 典型年降雨资料表
|
||||
|
|
@ -30,22 +32,20 @@ public class TyYearRainfallController {
|
|||
|
||||
@Operation(summary = "新增")
|
||||
@PostMapping("/insert")
|
||||
public R<TyYearRainfall> insert(@Validated(Insert.class) @RequestBody TyYearRainfall dto) {
|
||||
boolean result = service.save(dto);
|
||||
return R.ok(result ? dto : null);
|
||||
public R<Boolean> insert(@Validated(Insert.class) @RequestBody TyYearRainfallVo dto) {
|
||||
return R.ok(service.saveData(dto));
|
||||
}
|
||||
|
||||
@Operation(summary = "修改")
|
||||
@PostMapping("/update")
|
||||
public R<TyYearRainfall> update(@Validated(Update.class) @RequestBody TyYearRainfall dto) {
|
||||
boolean result = service.updateById(dto);
|
||||
return R.ok(result ? dto : null);
|
||||
public R<Boolean> update(@Validated(Update.class) @RequestBody TyYearRainfallVo dto) {
|
||||
return R.ok(service.updateData(dto));
|
||||
}
|
||||
|
||||
@Operation(summary = "删除")
|
||||
@GetMapping("/del/{id}")
|
||||
public R<Boolean> del(@Schema(name = "id") @PathVariable("id") Serializable id) {
|
||||
return R.ok(service.removeById(id));
|
||||
public R<Boolean> del(@Schema(name = "id") @PathVariable("id") Long id) {
|
||||
return R.ok(service.removeData(id));
|
||||
}
|
||||
|
||||
@Operation(summary = "列表")
|
||||
|
|
@ -56,8 +56,8 @@ public class TyYearRainfallController {
|
|||
|
||||
@Operation(summary = "分页")
|
||||
@PostMapping("/page")
|
||||
public R<List<TyYearRainfall>> page() {
|
||||
return R.ok(service.page(null,null));
|
||||
public R<Page<TyYearRainfallVo>> pageQuery(@RequestBody TyYearRainfallPageSo tyYearRainfallPageSo) {
|
||||
return R.ok(service.pageQuery(tyYearRainfallPageSo));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
package com.gunshi.project.xyt.entity.so;
|
||||
|
||||
import com.gunshi.db.dto.PageSo;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* Description:
|
||||
* Created by wanyan on 2024/3/19
|
||||
*
|
||||
* @author wanyan
|
||||
* @version 1.0
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "典型年降雨分页查询对象")
|
||||
public class TyYearRainfallPageSo {
|
||||
|
||||
@NotNull(message = "分页参数不能为空")
|
||||
@Schema(description = "分页参数")
|
||||
private PageSo pageSo;
|
||||
|
||||
@Schema(description="丰平枯(1枯 2偏枯 3平 4偏丰 5丰)")
|
||||
private Integer status;
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
package com.gunshi.project.xyt.entity.vo;
|
||||
|
||||
import com.gunshi.project.xyt.model.TyYearRainfall;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Description:
|
||||
* Created by wanyan on 2024/7/15
|
||||
*
|
||||
* @author wanyan
|
||||
* @version 1.0
|
||||
*/
|
||||
@Data
|
||||
public class TyYearRainfallVo extends TyYearRainfall {
|
||||
|
||||
@Schema(description = "月降雨量")
|
||||
private List<TyYearRainfall> list;
|
||||
}
|
||||
|
|
@ -1,8 +1,13 @@
|
|||
package com.gunshi.project.xyt.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.gunshi.project.xyt.entity.so.TyYearRainfallPageSo;
|
||||
import com.gunshi.project.xyt.entity.vo.TyYearRainfallVo;
|
||||
import com.gunshi.project.xyt.model.TyYearRainfall;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
/**
|
||||
* 描述: 典型年降雨资料表
|
||||
|
|
@ -12,4 +17,14 @@ import org.apache.ibatis.annotations.Mapper;
|
|||
@Mapper
|
||||
public interface TyYearRainfallMapper extends BaseMapper<TyYearRainfall> {
|
||||
|
||||
@Select("""
|
||||
<script>
|
||||
select * from public.ty_year_rainfall where type = 1
|
||||
<if test="obj.status != null">
|
||||
and status = #{obj.status}
|
||||
</if>
|
||||
order by year desc
|
||||
</script>
|
||||
""")
|
||||
Page<TyYearRainfallVo> pageQuery(Page<TyYearRainfallVo> page,@Param("obj") TyYearRainfallPageSo tyYearRainfallPageSo);
|
||||
}
|
||||
|
|
@ -5,15 +5,14 @@ import com.baomidou.mybatisplus.annotation.IdType;
|
|||
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.gunshi.core.dateformat.DateFormatString;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 描述: 典型年降雨资料表
|
||||
|
|
@ -33,8 +32,8 @@ public class TyYearRainfall implements Serializable {
|
|||
*/
|
||||
@TableId(value="id", type= IdType.AUTO)
|
||||
@Schema(description="id")
|
||||
// @Size(max = 0,message = "id最大长度要小于 0")
|
||||
@NotBlank(message = "id不能为空")
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
|
|
@ -42,7 +41,6 @@ public class TyYearRainfall implements Serializable {
|
|||
*/
|
||||
@TableField(value="type")
|
||||
@Schema(description="类型(1年 2月)")
|
||||
// @Size(max = 0,message = "类型(1年 2月)最大长度要小于 0")
|
||||
private Integer type;
|
||||
|
||||
/**
|
||||
|
|
@ -50,7 +48,6 @@ public class TyYearRainfall implements Serializable {
|
|||
*/
|
||||
@TableField(value="year")
|
||||
@Schema(description="年")
|
||||
// @Size(max = 0,message = "年最大长度要小于 0")
|
||||
private Integer year;
|
||||
|
||||
/**
|
||||
|
|
@ -58,7 +55,6 @@ public class TyYearRainfall implements Serializable {
|
|||
*/
|
||||
@TableField(value="month")
|
||||
@Schema(description="月")
|
||||
// @Size(max = 0,message = "月最大长度要小于 0")
|
||||
private Integer month;
|
||||
|
||||
/**
|
||||
|
|
@ -66,15 +62,13 @@ public class TyYearRainfall implements Serializable {
|
|||
*/
|
||||
@TableField(value="drp")
|
||||
@Schema(description="降雨量")
|
||||
// @Size(max = 0,message = "降雨量最大长度要小于 0")
|
||||
private String drp;
|
||||
private BigDecimal drp;
|
||||
|
||||
/**
|
||||
* 丰平枯(1枯 2偏枯 3平 4偏丰 5丰)
|
||||
*/
|
||||
@TableField(value="status")
|
||||
@Schema(description="丰平枯(1枯 2偏枯 3平 4偏丰 5丰)")
|
||||
// @Size(max = 0,message = "丰平枯(1枯 2偏枯 3平 4偏丰 5丰)最大长度要小于 0")
|
||||
private Integer status;
|
||||
|
||||
}
|
||||
|
|
@ -156,7 +156,7 @@ public class ReservoirWaterService {
|
|||
AttResBase attResBase = attResBaseMapper.selectById(resCode);
|
||||
vo.setFlLowLimLev(attResBase.getFlLowLimLev());
|
||||
//默认查询近一周水位
|
||||
String endTime = DateUtil.convertDateToString(new Date());
|
||||
String endTime = DateUtil.convertDateToMDSString(new Date());
|
||||
String startTime = DateUtil.getMinusTime(endTime, 7 * 24);
|
||||
vo.setList(attResBaseMapper.queryRzList(attResBase.getStcd(),startTime,endTime));
|
||||
return vo;
|
||||
|
|
|
|||
|
|
@ -1,13 +1,23 @@
|
|||
package com.gunshi.project.xyt.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.gunshi.project.xyt.entity.so.TyYearRainfallPageSo;
|
||||
import com.gunshi.project.xyt.entity.vo.TyYearRainfallVo;
|
||||
import com.gunshi.project.xyt.mapper.TyYearRainfallMapper;
|
||||
import com.gunshi.project.xyt.model.TyYearRainfall;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 描述: 典型年降雨资料表
|
||||
|
|
@ -20,6 +30,88 @@ import java.util.Date;
|
|||
public class TyYearRainfallService extends ServiceImpl<TyYearRainfallMapper, TyYearRainfall>
|
||||
{
|
||||
|
||||
@Resource
|
||||
private TyYearRainfallMapper mapper;
|
||||
|
||||
public boolean saveData(TyYearRainfallVo dto) {
|
||||
checkParam(dto);
|
||||
TyYearRainfall tyYearRainfall = new TyYearRainfall();
|
||||
BeanUtils.copyProperties(dto,tyYearRainfall);
|
||||
tyYearRainfall.setId(IdWorker.getId());
|
||||
List<TyYearRainfall> list = dto.getList();
|
||||
if(CollectionUtils.isNotEmpty(list)){
|
||||
list.stream().map(o->{
|
||||
o.setId(IdWorker.getId());
|
||||
return o;
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
list.add(tyYearRainfall);
|
||||
return this.saveBatch(list);
|
||||
}
|
||||
|
||||
private void checkParam(TyYearRainfallVo dto) {
|
||||
Long id = dto.getId();
|
||||
LambdaQueryWrapper<TyYearRainfall> queryWrapper = Wrappers.lambdaQuery();
|
||||
queryWrapper.eq(TyYearRainfall::getYear,dto.getYear())
|
||||
.eq(TyYearRainfall::getType,1);
|
||||
if(id != null){
|
||||
queryWrapper.ne(TyYearRainfall::getId,id);
|
||||
}
|
||||
if(this.count(queryWrapper ) > 0){
|
||||
throw new IllegalArgumentException("该年份已存在典型年降雨资料");
|
||||
}
|
||||
Long len = dto.getList().stream().map(TyYearRainfall::getMonth).distinct().collect(Collectors.counting());
|
||||
if(dto.getList().size() != len.intValue()){
|
||||
throw new IllegalArgumentException("月份不可重复");
|
||||
}
|
||||
}
|
||||
|
||||
public Page<TyYearRainfallVo> pageQuery(TyYearRainfallPageSo tyYearRainfallPageSo) {
|
||||
Page<TyYearRainfallVo> page = mapper.pageQuery(tyYearRainfallPageSo.getPageSo().toPage(), tyYearRainfallPageSo);
|
||||
fillList(page);
|
||||
return page;
|
||||
}
|
||||
|
||||
private void fillList(Page<TyYearRainfallVo> ret) {
|
||||
if (ret.getRecords() != null) {
|
||||
for (TyYearRainfallVo record : ret.getRecords()) {
|
||||
LambdaQueryWrapper<TyYearRainfall> queryWrapper = Wrappers.lambdaQuery();
|
||||
queryWrapper.eq(TyYearRainfall::getYear,record.getYear())
|
||||
.eq(TyYearRainfall::getType,2)
|
||||
.orderByAsc(TyYearRainfall::getMonth);
|
||||
record.setList(this.list(queryWrapper));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean updateData(TyYearRainfallVo dto) {
|
||||
checkParam(dto);
|
||||
TyYearRainfall tyYearRainfall = new TyYearRainfall();
|
||||
BeanUtils.copyProperties(dto,tyYearRainfall);
|
||||
this.updateById(tyYearRainfall);
|
||||
deleteMonthData(dto.getYear());
|
||||
List<TyYearRainfall> list = dto.getList();
|
||||
if(CollectionUtils.isNotEmpty(list)){
|
||||
list.stream().map(o->{
|
||||
o.setId(IdWorker.getId());
|
||||
return o;
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
return this.saveBatch(list);
|
||||
}
|
||||
|
||||
private void deleteMonthData(Integer year) {
|
||||
LambdaQueryWrapper<TyYearRainfall> queryWrapper = Wrappers.lambdaQuery();
|
||||
queryWrapper.eq(TyYearRainfall::getYear,year)
|
||||
.eq(TyYearRainfall::getType,2);
|
||||
this.remove(queryWrapper);
|
||||
}
|
||||
|
||||
public Boolean removeData(Long id) {
|
||||
TyYearRainfall tyYearRainfall = this.getById(id);
|
||||
deleteMonthData(tyYearRainfall.getYear());
|
||||
return this.removeById(id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue