132 lines
4.8 KiB
Java
132 lines
4.8 KiB
Java
package com.gunshi.project.xyt.controller;
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
|
|
import com.gunshi.core.result.R;
|
|
import com.gunshi.project.xyt.model.AttResBase;
|
|
import com.gunshi.project.xyt.model.StZvarlB;
|
|
import com.gunshi.project.xyt.service.AttResBaseService;
|
|
import com.gunshi.project.xyt.service.StStbprpBService;
|
|
import com.gunshi.project.xyt.service.StZvarlBService;
|
|
import com.gunshi.project.xyt.validate.markers.Delete;
|
|
import com.gunshi.project.xyt.validate.markers.Insert;
|
|
import com.gunshi.project.xyt.validate.markers.Update;
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
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.PostMapping;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
import java.util.Date;
|
|
import java.util.List;
|
|
import java.util.Objects;
|
|
|
|
/**
|
|
* 描述: 库( 湖)容曲线表
|
|
* author: xusan
|
|
* date: 2024-07-08 17:40:37
|
|
*/
|
|
@Tag(name = "库( 湖)容曲线表")
|
|
@RestController
|
|
@RequestMapping(value="/stZvarlB")
|
|
public class StZvarlBController {
|
|
|
|
@Autowired
|
|
private StZvarlBService service;
|
|
|
|
@Autowired
|
|
private AttResBaseService resBaseService;
|
|
|
|
@Autowired
|
|
private StStbprpBService stStbprpBService;
|
|
|
|
@Operation(summary = "新增")
|
|
@PostMapping("/insert")
|
|
public R<StZvarlB> insert(@Validated(Insert.class) @RequestBody StZvarlB dto) {
|
|
if (StringUtils.isNotBlank(dto.getResCode())){
|
|
AttResBase one = resBaseService.lambdaQuery().eq(AttResBase::getResCode, dto.getResCode()).one();
|
|
if (Objects.isNull(one)){
|
|
throw new IllegalArgumentException("水库编码不存在");
|
|
}
|
|
if (StringUtils.isBlank(dto.getStcd())){
|
|
dto.setStcd(one.getStcd());
|
|
}
|
|
}
|
|
if (StringUtils.isNotBlank(dto.getStcd()) && Objects.isNull(stStbprpBService.getById(dto.getStcd()))){
|
|
throw new IllegalArgumentException("测站编码不存在");
|
|
}
|
|
if (service.lambdaQuery()
|
|
.eq(StZvarlB::getStcd, dto.getStcd())
|
|
.eq(StZvarlB::getRz, dto.getRz())
|
|
.eq(StZvarlB::getW, dto.getW())
|
|
.count() > 0) {
|
|
throw new IllegalArgumentException("当前数据已存在");
|
|
}
|
|
dto.setId(IdWorker.getId());
|
|
dto.setModitime(new Date());
|
|
boolean result = service.save(dto);
|
|
return R.ok(result ? dto : null);
|
|
}
|
|
|
|
@Operation(summary = "修改")
|
|
@PostMapping("/update")
|
|
public R<StZvarlB> update(@Validated(Update.class) @RequestBody StZvarlB dto) {
|
|
if (StringUtils.isNotBlank(dto.getStcd()) && Objects.isNull(stStbprpBService.getById(dto.getStcd()))){
|
|
throw new IllegalArgumentException("测站编码不存在");
|
|
}
|
|
|
|
|
|
if (service.lambdaQuery()
|
|
.eq(StZvarlB::getStcd, dto.getStcd())
|
|
.eq(StZvarlB::getRz, dto.getRz())
|
|
.eq(StZvarlB::getW, dto.getW())
|
|
.ne(StZvarlB::getId, dto.getId())
|
|
.count() > 0) {
|
|
throw new IllegalArgumentException("当前数据已存在");
|
|
}
|
|
|
|
|
|
boolean result = service.lambdaUpdate()
|
|
.set(StZvarlB::getRz, dto.getRz())
|
|
.set(StZvarlB::getW, dto.getW())
|
|
.set(StZvarlB::getWsfa, dto.getWsfa())
|
|
.eq(StZvarlB::getId, dto.getId())
|
|
.update();
|
|
return R.ok(result ? dto : null);
|
|
}
|
|
|
|
@Operation(summary = "删除")
|
|
@PostMapping("/del")
|
|
public R<Boolean> del(@Validated(Delete.class) @RequestBody StZvarlB dto) {
|
|
if (service.lambdaQuery()
|
|
.eq(StZvarlB::getId, dto.getId())
|
|
.count() == 0) {
|
|
throw new IllegalArgumentException("当前数据不存在");
|
|
}
|
|
return R.ok(service.lambdaUpdate()
|
|
.eq(StZvarlB::getId, dto.getId())
|
|
.remove() );
|
|
}
|
|
|
|
@Operation(summary = "列表")
|
|
@PostMapping("/list")
|
|
public R<List<StZvarlB>> list(@RequestBody StZvarlB dto) {
|
|
LambdaQueryChainWrapper<StZvarlB> q = service.lambdaQuery().orderByAsc(StZvarlB::getRz);
|
|
String stcd = dto.getStcd();
|
|
if (StringUtils.isNotBlank(stcd)){
|
|
q.eq(StZvarlB::getStcd, stcd);
|
|
}
|
|
return R.ok(q.list());
|
|
}
|
|
|
|
// @Operation(summary = "分页")
|
|
// @PostMapping("/page")
|
|
public R<List<StZvarlB>> page() {
|
|
return R.ok(service.page(null,null));
|
|
}
|
|
|
|
} |