139 lines
5.2 KiB
Java
139 lines
5.2 KiB
Java
package com.gunshi.project.hsz.controller;
|
||
|
||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||
import com.gunshi.core.result.R;
|
||
import com.gunshi.project.hsz.entity.so.GeneralDataPage;
|
||
import com.gunshi.project.hsz.model.AttDamBase;
|
||
import com.gunshi.project.hsz.service.AttDamBaseService;
|
||
import com.gunshi.project.hsz.service.AttResBaseService;
|
||
import com.gunshi.project.hsz.service.FileAssociationsService;
|
||
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.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="/attDamBase")
|
||
public class AttDamBaseController extends AbstractCommonFileController{
|
||
|
||
@Autowired
|
||
private AttDamBaseService service;
|
||
|
||
@Autowired
|
||
private FileAssociationsService fileService;
|
||
|
||
@Autowired
|
||
private AttResBaseService resService;
|
||
|
||
@Operation(summary = "新增")
|
||
@PostMapping("/insert")
|
||
public R<AttDamBase> insert(@Validated(Insert.class) @RequestBody AttDamBase dto) {
|
||
if (StringUtils.isNotBlank(dto.getResCode()) && Objects.isNull(resService.getById(dto.getResCode()))){
|
||
throw new RuntimeException("当前水库不存在");
|
||
}
|
||
dto.setDamCode(IdWorker.get32UUID());
|
||
dto.setCreateTime(new Date());
|
||
boolean result = service.save(dto);
|
||
if (result){
|
||
fileService.saveFile(dto.getFiles(), getGroupId(), dto.getDamCode());
|
||
}
|
||
return R.ok(result ? dto : null);
|
||
}
|
||
|
||
@Operation(summary = "修改")
|
||
@PostMapping("/update")
|
||
public R<AttDamBase> update(@Validated(Update.class) @RequestBody AttDamBase dto) {
|
||
if (StringUtils.isNotBlank(dto.getResCode()) && Objects.isNull(resService.getById(dto.getResCode()))){
|
||
throw new RuntimeException("当前水库不存在");
|
||
}
|
||
if (Objects.isNull(service.getById(dto.getDamCode()))) {
|
||
throw new IllegalArgumentException("当前数据不存在");
|
||
}
|
||
boolean result = service.updateById(dto);
|
||
if (result){
|
||
fileService.saveFile(dto.getFiles(), getGroupId(), dto.getDamCode());
|
||
}
|
||
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<AttDamBase>> list() {
|
||
List<AttDamBase> list = service.lambdaQuery().list();
|
||
for (AttDamBase attDamBase : list) {
|
||
attDamBase.setFiles(fileService.getFiles(getGroupId(), attDamBase.getDamCode()));
|
||
}
|
||
return R.ok(list);
|
||
}
|
||
|
||
@Operation(summary = "获取主副坝,拦洪坝信息")
|
||
@GetMapping("/info")
|
||
public R<List<AttDamBase>> info(@Schema(name = "isMain",description = "是否主坝(0否 1是 2拦洪坝)") @RequestParam(name = "isMain") Integer isMain) {
|
||
List<AttDamBase> list = service.lambdaQuery().eq(AttDamBase::getIsMain, isMain).list();
|
||
for (AttDamBase attDamBase : list) {
|
||
attDamBase.setFiles(fileService.getFiles(getGroupId(), attDamBase.getDamCode()));
|
||
}
|
||
return R.ok(list);
|
||
}
|
||
|
||
@Operation(summary = "分页")
|
||
@PostMapping("/page")
|
||
public R<Page<AttDamBase>> page(@RequestBody @Validated GeneralDataPage page) {
|
||
LambdaQueryWrapper<AttDamBase> query = Wrappers.lambdaQuery();
|
||
|
||
if (ObjectUtils.isNotNull(page.getCode())){
|
||
query.like(AttDamBase::getDamCode, page.getCode());
|
||
}
|
||
if (ObjectUtils.isNotNull(page.getName())){
|
||
query.like(AttDamBase::getDamName, page.getName());
|
||
}
|
||
return R.ok(service.page(page.getPageSo().toPage(),query));
|
||
}
|
||
@Operation(summary = "查看详情")
|
||
@GetMapping("/get/{id}")
|
||
public R<AttDamBase> page(@PathVariable("id") Serializable id) {
|
||
AttDamBase data = service.getById(id);
|
||
if (Objects.nonNull(data)){
|
||
data.setFiles(fileService.getFiles(getGroupId(),data.getDamCode()));
|
||
}
|
||
return R.ok(data);
|
||
}
|
||
|
||
@Override
|
||
public String getGroupId() {
|
||
return "attDamBase";
|
||
}
|
||
} |