2024-07-08 17:47:02 +08:00
|
|
|
package com.gunshi.project.xyt.controller;
|
|
|
|
|
|
2024-07-18 18:00:27 +08:00
|
|
|
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
|
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
2024-07-08 17:47:02 +08:00
|
|
|
import com.gunshi.core.result.R;
|
2024-07-18 18:00:27 +08:00
|
|
|
import com.gunshi.project.xyt.entity.page.GenericPageParams;
|
2024-07-08 17:47:02 +08:00
|
|
|
import com.gunshi.project.xyt.model.SysDictB;
|
|
|
|
|
import com.gunshi.project.xyt.service.SysDictBService;
|
|
|
|
|
import com.gunshi.project.xyt.validate.markers.Insert;
|
|
|
|
|
import com.gunshi.project.xyt.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;
|
2024-07-18 18:00:27 +08:00
|
|
|
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.List;
|
2024-07-18 18:00:27 +08:00
|
|
|
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="/sysDictB")
|
|
|
|
|
public class SysDictBController {
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private SysDictBService service;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "新增")
|
|
|
|
|
@PostMapping("/insert")
|
|
|
|
|
public R<SysDictB> insert(@Validated(Insert.class) @RequestBody SysDictB dto) {
|
2024-07-18 18:00:27 +08:00
|
|
|
|
|
|
|
|
if (StringUtils.isNotBlank(dto.getDictNm())){
|
|
|
|
|
if (service.lambdaQuery().eq(SysDictB::getDictNm,dto.getDictNm())
|
|
|
|
|
.count() > 0) {
|
2024-07-22 17:11:26 +08:00
|
|
|
throw new IllegalArgumentException("当前名称已存在");
|
2024-07-18 18:00:27 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (Objects.nonNull(dto.getPid())){
|
|
|
|
|
if (service.lambdaQuery().eq(SysDictB::getId,dto.getPid())
|
|
|
|
|
.count() == 0) {
|
2024-07-22 17:11:26 +08:00
|
|
|
throw new IllegalArgumentException("当父级不存在");
|
2024-07-18 18:00:27 +08:00
|
|
|
}
|
|
|
|
|
}
|
2024-07-08 17:47:02 +08:00
|
|
|
boolean result = service.save(dto);
|
|
|
|
|
return R.ok(result ? dto : null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "修改")
|
|
|
|
|
@PostMapping("/update")
|
|
|
|
|
public R<SysDictB> update(@Validated(Update.class) @RequestBody SysDictB dto) {
|
2024-07-18 18:00:27 +08:00
|
|
|
|
|
|
|
|
if (StringUtils.isNotBlank(dto.getDictNm())){
|
|
|
|
|
if (service.lambdaQuery().eq(SysDictB::getDictNm,dto.getDictNm())
|
|
|
|
|
.count() > 0) {
|
2024-07-22 17:11:26 +08:00
|
|
|
throw new IllegalArgumentException("当前名称已存在");
|
2024-07-18 18:00:27 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (Objects.nonNull(dto.getPid())){
|
|
|
|
|
if (service.lambdaQuery().eq(SysDictB::getId,dto.getPid())
|
|
|
|
|
.count() == 0) {
|
2024-07-22 17:11:26 +08:00
|
|
|
throw new IllegalArgumentException("当父级不存在");
|
2024-07-18 18:00:27 +08:00
|
|
|
}
|
|
|
|
|
}
|
2024-07-08 17:47:02 +08:00
|
|
|
boolean result = service.updateById(dto);
|
|
|
|
|
return R.ok(result ? dto : null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "删除")
|
|
|
|
|
@GetMapping("/del/{id}")
|
|
|
|
|
public R<Boolean> del(@Schema(name = "id") @PathVariable("id") Serializable id) {
|
2024-07-18 18:00:27 +08:00
|
|
|
if (Objects.isNull(service.getById(id))) {
|
2024-07-22 17:11:26 +08:00
|
|
|
throw new IllegalArgumentException("当前数据不存在");
|
2024-07-18 18:00:27 +08:00
|
|
|
}
|
2024-07-08 17:47:02 +08:00
|
|
|
return R.ok(service.removeById(id));
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-18 18:00:27 +08:00
|
|
|
@Operation(summary = "列表 通过父id查子项")
|
2024-07-08 17:47:02 +08:00
|
|
|
@PostMapping("/list")
|
2024-07-18 18:00:27 +08:00
|
|
|
public R<List<SysDictB>> list(@RequestBody SysDictB dto) {
|
|
|
|
|
LambdaQueryChainWrapper<SysDictB> query = service.lambdaQuery();
|
|
|
|
|
Long pid = dto.getPid();
|
|
|
|
|
if (Objects.nonNull(pid)){
|
|
|
|
|
query.eq(SysDictB::getPid, pid);
|
|
|
|
|
}
|
|
|
|
|
return R.ok(query.list());
|
2024-07-08 17:47:02 +08:00
|
|
|
}
|
|
|
|
|
|
2024-07-18 18:00:27 +08:00
|
|
|
@Operation(summary = "分页 只查父项")
|
2024-07-08 17:47:02 +08:00
|
|
|
@PostMapping("/page")
|
2024-07-18 18:00:27 +08:00
|
|
|
public R<Page<SysDictB>> page(@RequestBody GenericPageParams page) {
|
|
|
|
|
|
|
|
|
|
Page<SysDictB> data = service.page(page.getPageSo().toPage(), service.lambdaQuery().isNull(SysDictB::getPid));
|
|
|
|
|
return R.ok(data);
|
2024-07-08 17:47:02 +08:00
|
|
|
}
|
|
|
|
|
|
2024-07-18 18:00:27 +08:00
|
|
|
@Operation(summary = "树")
|
|
|
|
|
@GetMapping("/tree")
|
|
|
|
|
public R<List<SysDictB>> tree() {
|
|
|
|
|
return R.ok(service.tree());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-07-08 17:47:02 +08:00
|
|
|
}
|