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

132 lines
4.8 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.entity.vo.ProfilePressTreeVo;
import com.gunshi.project.hsz.model.AttDamProfile;
import com.gunshi.project.hsz.service.AttDamProfileService;
import com.gunshi.project.hsz.service.FileAssociationsService;
import com.gunshi.project.hsz.common.validate.markers.Insert;
import com.gunshi.project.hsz.common.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.List;
import java.util.Objects;
/**
* 描述: 监测断面信息表
* author: xusan
* date: 2024-07-08 17:40:37
*/
@Tag(name = "监测断面信息表")
@RestController
@RequestMapping(value="/attDamProfile")
public class AttDamProfileController extends AbstractCommonFileController{
@Autowired
private AttDamProfileService service;
@Autowired
private FileAssociationsService fileService;
@Operation(summary = "新增")
@PostMapping("/insert")
public R<AttDamProfile> insert(@Validated(Insert.class) @RequestBody AttDamProfile dto) {
if (Objects.nonNull(service.getById(dto.getProfileCode()))) {
throw new IllegalArgumentException("当前编号已存在");
}else{
dto.setProfileCode(String.valueOf(IdWorker.getId()));
}
if (StringUtils.isNotBlank(dto.getProfileName())){
if (service.lambdaQuery().eq(AttDamProfile::getProfileName,dto.getProfileName()).count() > 0) {
throw new IllegalArgumentException("当前名称已存在");
}
}
boolean result = service.save(dto);
if (result){
fileService.saveFile(dto.getFiles(), getGroupId(), dto.getProfileCode());
}
return R.ok(result ? dto : null);
}
@Operation(summary = "修改")
@PostMapping("/update")
public R<AttDamProfile> update(@Validated(Update.class) @RequestBody AttDamProfile dto) {
if (Objects.isNull(service.getById(dto.getProfileCode()))) {
throw new IllegalArgumentException("当前数据不存在");
}
if (StringUtils.isNotBlank(dto.getProfileName())){
if (service.lambdaQuery().eq(AttDamProfile::getProfileName,dto.getProfileName())
.ne(AttDamProfile::getProfileCode,dto.getProfileCode())
.count() > 0) {
throw new IllegalArgumentException("当前名称已存在");
}
}
boolean result = service.updateById(dto);
if (result){
fileService.saveFile(dto.getFiles(), getGroupId(), dto.getProfileCode());
}
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("当前数据不存在");
}
return R.ok(service.removeById(id));
}
@Operation(summary = "列表")
@PostMapping("/list")
public R<List<AttDamProfile>> list() {
LambdaQueryWrapper<AttDamProfile> wq = new LambdaQueryWrapper();
wq.orderByAsc(AttDamProfile::getProfileCode);
List<AttDamProfile> list = service.list(wq);
return R.ok(list);
}
@Operation(summary = "断面渗压树")
@PostMapping("/tree")
public R<List<ProfilePressTreeVo>> tree() {
return R.ok(service.tree());
}
@Operation(summary = "分页")
@PostMapping("/page")
public R<Page<AttDamProfile>> page(@RequestBody @Validated GeneralDataPage page) {
LambdaQueryWrapper<AttDamProfile> query = Wrappers.lambdaQuery();
if (ObjectUtils.isNotNull(page.getName())) {
query.like(AttDamProfile::getProfileName, page.getName());
}
Page<AttDamProfile> data = service.page(page.getPageSo().toPage(), query);
data.getRecords().forEach(o -> o.setFiles(
fileService.getFiles(getGroupId(),o.getProfileCode())
));
return R.ok(data);
}
@Override
public String getGroupId() {
return "AttDamProfile";
}
}