90 lines
2.9 KiB
Java
90 lines
2.9 KiB
Java
package com.whdc.controller;
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.whdc.exception.MyException;
|
|
import com.whdc.model.dto.ShPeriodDto;
|
|
import com.whdc.model.entity.ShPeriod;
|
|
import com.whdc.model.group.Insert;
|
|
import com.whdc.model.group.Update;
|
|
import com.whdc.service.ShPeriodService;
|
|
import com.whdc.utils.ResultJson;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import io.swagger.v3.oas.annotations.media.Schema;
|
|
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;
|
|
|
|
/**
|
|
* 描述: 防汛周期
|
|
* author: xusan
|
|
* date: 2024-07-29 17:27:25
|
|
*/
|
|
@Api(tags = "防汛周期")
|
|
@RestController
|
|
@RequestMapping(value="/shPeriod")
|
|
public class ShPeriodController {
|
|
|
|
@Autowired
|
|
private ShPeriodService service;
|
|
|
|
|
|
@ApiOperation(value = "新增")
|
|
@PostMapping("/insert")
|
|
public ResultJson<ShPeriod> insert(@Validated(Insert.class) @RequestBody ShPeriod dto) {
|
|
if (service.lambdaQuery().eq(ShPeriod::getName, dto.getName()).count() > 0){
|
|
throw new MyException("名称重复");
|
|
}
|
|
boolean result = service.save(dto);
|
|
return ResultJson.ok(result ? dto : null);
|
|
}
|
|
|
|
@ApiOperation(value = "修改")
|
|
@PostMapping("/update")
|
|
public ResultJson<ShPeriod> update(@Validated(Update.class) @RequestBody ShPeriod dto) {
|
|
if (service.lambdaQuery()
|
|
.eq(ShPeriod::getName, dto.getName())
|
|
.ne(ShPeriod::getId, dto.getId())
|
|
.count() > 0){
|
|
throw new MyException("名称重复");
|
|
}
|
|
boolean result = service.updateById(dto);
|
|
return ResultJson.ok(result ? dto : null);
|
|
}
|
|
|
|
@ApiOperation(value = "删除")
|
|
@GetMapping("/del/{id}")
|
|
public ResultJson<Boolean> del(@Schema(name = "id") @PathVariable("id") Serializable id) {
|
|
return ResultJson.ok(service.removeById(id));
|
|
}
|
|
|
|
// @ApiOperation(value = "列表")
|
|
// @PostMapping("/list")
|
|
public ResultJson<List<ShPeriod>> list() {
|
|
return ResultJson.ok(service.lambdaQuery().list());
|
|
}
|
|
|
|
@ApiOperation(value = "分页")
|
|
@PostMapping("/page")
|
|
public ResultJson<IPage<ShPeriod>> page(@RequestBody ShPeriodDto dto) {
|
|
// LambdaQueryChainWrapper<ShPeriod> query = service.lambdaQuery();
|
|
// if (Objects.nonNull(dto.getStm()) && Objects.nonNull(dto.getEtm())){
|
|
// query.between(ShPeriod::getCreateTime,dto.getStm(),dto.getEtm());
|
|
// }
|
|
//
|
|
// if (StringUtils.isNotBlank(dto.getName())){
|
|
// query.eq(ShPeriod::getName,dto.getName());
|
|
// }
|
|
//
|
|
// query.orderByDesc(ShPeriod::getCreateTime);
|
|
//
|
|
// return ResultJson.ok(service.page(dto.getPage(),query));
|
|
return ResultJson.ok(service.page(dto));
|
|
}
|
|
|
|
|
|
|
|
} |