gunshi-project-ss/src/main/java/com/gunshi/project/hsz/controller/AttDamBaseController.java

139 lines
5.2 KiB
Java
Raw Normal View History

2025-07-17 15:26:39 +08:00
package com.gunshi.project.hsz.controller;
2024-07-08 17:47:02 +08:00
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;
2024-07-08 17:47:02 +08:00
import com.gunshi.core.result.R;
2025-07-17 15:26:39 +08:00
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;
2024-07-08 17:47:02 +08:00
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;
2024-07-08 17:47:02 +08:00
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;
2024-07-08 17:47:02 +08:00
import java.util.List;
import java.util.Objects;
2024-07-08 17:47:02 +08:00
/**
* :
* author: xusan
* date: 2024-07-08 17:40:37
*/
@Tag(name = "大坝表")
@RestController
@RequestMapping(value="/attDamBase")
public class AttDamBaseController extends AbstractCommonFileController{
2024-07-08 17:47:02 +08:00
@Autowired
private AttDamBaseService service;
@Autowired
private FileAssociationsService fileService;
2024-07-08 17:47:02 +08:00
@Autowired
private AttResBaseService resService;
2024-07-08 17:47:02 +08:00
@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());
2024-07-08 17:47:02 +08:00
boolean result = service.save(dto);
if (result){
2024-08-15 17:32:55 +08:00
fileService.saveFile(dto.getFiles(), getGroupId(), dto.getDamCode());
}
2024-07-08 17:47:02 +08:00
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("当前数据不存在");
}
2024-07-08 17:47:02 +08:00
boolean result = service.updateById(dto);
if (result){
2024-08-15 17:32:55 +08:00
fileService.saveFile(dto.getFiles(), getGroupId(), dto.getDamCode());
}
2024-07-08 17:47:02 +08:00
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);
2024-07-08 17:47:02 +08:00
}
@Operation(summary = "列表")
@PostMapping("/list")
public R<List<AttDamBase>> list() {
2025-09-03 14:11:20 +08:00
List<AttDamBase> list = service.lambdaQuery().list();
for (AttDamBase attDamBase : list) {
attDamBase.setFiles(fileService.getFiles(getGroupId(), attDamBase.getDamCode()));
}
return R.ok(list);
2024-07-08 17:47:02 +08:00
}
@Operation(summary = "获取主副坝,拦洪坝信息")
@GetMapping("/info")
public R<List<AttDamBase>> info(@Schema(name = "isMain",description = "是否主坝0否 1是 2拦洪坝") @RequestParam(name = "isMain") Integer isMain) {
2025-09-03 14:11:20 +08:00
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);
}
2024-07-08 17:47:02 +08:00
@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));
2024-07-08 17:47:02 +08:00
}
@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);
}
2024-07-08 17:47:02 +08:00
@Override
public String getGroupId() {
return "attDamBase";
}
2024-07-08 17:47:02 +08:00
}