116 lines
3.7 KiB
Java
116 lines
3.7 KiB
Java
package com.gunshi.project.hsz.controller;
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
|
|
import com.gunshi.core.result.R;
|
|
import com.gunshi.project.hsz.entity.so.ResCodeSo;
|
|
import com.gunshi.project.hsz.model.ResPlanB;
|
|
import com.gunshi.project.hsz.service.FileAssociationsService;
|
|
import com.gunshi.project.hsz.service.ResPlanBService;
|
|
import com.gunshi.project.hsz.validate.markers.Insert;
|
|
import com.gunshi.project.hsz.validate.markers.Update;
|
|
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.apache.commons.collections4.CollectionUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
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.Date;
|
|
import java.util.List;
|
|
import java.util.Objects;
|
|
|
|
/**
|
|
* 描述: 水库预案表
|
|
* author: xusan
|
|
* date: 2024-07-08 17:40:37
|
|
*/
|
|
@Tag(name = "水库预案表")
|
|
@RestController
|
|
@RequestMapping(value="/resPlanB")
|
|
public class ResPlanBController extends AbstractCommonFileController{
|
|
|
|
@Autowired
|
|
private ResPlanBService service;
|
|
|
|
@Autowired
|
|
private FileAssociationsService fileService;
|
|
|
|
|
|
@Operation(summary = "新增")
|
|
@PostMapping("/insert")
|
|
public R<ResPlanB> insert(@Validated(Insert.class) @RequestBody ResPlanB dto) {
|
|
dto.setId(IdWorker.getId());
|
|
dto.setModitime(new Date());
|
|
boolean result = service.save(dto);
|
|
|
|
if (result){
|
|
fileService.saveFile(dto.getFiles(), getGroupId(), String.valueOf( dto.getId()));
|
|
}
|
|
|
|
return R.ok(result ? dto : null);
|
|
}
|
|
|
|
@Operation(summary = "修改")
|
|
@PostMapping("/update")
|
|
public R<ResPlanB> update(@Validated(Update.class) @RequestBody ResPlanB dto) {
|
|
if (Objects.isNull(service.getById(dto.getId()))) {
|
|
throw new IllegalArgumentException("当前数据不存在");
|
|
}
|
|
boolean result = service.updateById(dto);
|
|
|
|
if (result) {
|
|
fileService.saveFile(dto.getFiles(), getGroupId(), String.valueOf( dto.getId()));
|
|
}
|
|
|
|
return R.ok(result ? dto : null);
|
|
}
|
|
|
|
@Operation(summary = "删除")
|
|
@GetMapping("/del/{id}")
|
|
public R<Boolean> del(@Schema(name = "id") @PathVariable("id") Serializable id) {
|
|
if (Objects.isNull(service.getById(id))) {
|
|
throw new IllegalArgumentException("当前数据不存在");
|
|
}
|
|
boolean data = service.removeById(id);
|
|
|
|
if (data){
|
|
fileService.deleteFile(getGroupId(),id.toString());
|
|
}
|
|
|
|
return R.ok(data);
|
|
}
|
|
|
|
@Operation(summary = "列表")
|
|
@PostMapping("/list")
|
|
public R<List<ResPlanB>> list(@Validated @RequestBody ResCodeSo so) {
|
|
LambdaQueryChainWrapper<ResPlanB> query = service.lambdaQuery();
|
|
if (StringUtils.isNotBlank(so.getResCode())){
|
|
query.eq(ResPlanB::getResCode, so.getResCode());
|
|
}
|
|
if (StringUtils.isNotBlank(so.getType())){
|
|
query.eq(ResPlanB::getType, so.getType());
|
|
}
|
|
query.orderByDesc(ResPlanB::getModitime);
|
|
List<ResPlanB> list = query.list();
|
|
|
|
if (CollectionUtils.isNotEmpty(list)){
|
|
list.forEach(o -> o.setFiles(fileService.getFiles(getGroupId(),String.valueOf( o.getId()))));
|
|
}
|
|
|
|
return R.ok(list);
|
|
}
|
|
// @Operation(summary = "分页")
|
|
// @PostMapping("/page")
|
|
public R<List<ResPlanB>> page() {
|
|
return R.ok(service.page(null,null));
|
|
}
|
|
|
|
@Override
|
|
public String getGroupId() {
|
|
return "ResPlanB";
|
|
}
|
|
} |