155 lines
5.4 KiB
Java
155 lines
5.4 KiB
Java
|
|
package com.gunshi.project.hsz.controller;
|
|||
|
|
|
|||
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|||
|
|
import com.gunshi.core.result.R;
|
|||
|
|
import com.gunshi.project.hsz.model.SzTreatmentBasis;
|
|||
|
|
import com.gunshi.project.hsz.service.SzTreatmentBasisService;
|
|||
|
|
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.springframework.beans.factory.annotation.Autowired;
|
|||
|
|
import org.springframework.validation.annotation.Validated;
|
|||
|
|
import org.springframework.web.bind.annotation.*;
|
|||
|
|
|
|||
|
|
import java.io.Serializable;
|
|||
|
|
import java.util.*;
|
|||
|
|
import java.util.stream.Collectors;
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 描述: 案件登记表
|
|||
|
|
* author: xusan
|
|||
|
|
* date: 2024-07-08 17:40:37
|
|||
|
|
*/
|
|||
|
|
@Tag(name = "处理依据表")
|
|||
|
|
@RestController
|
|||
|
|
@RequestMapping(value="/szTreatmentBasis")
|
|||
|
|
public class SzTreatmentBasisController{
|
|||
|
|
|
|||
|
|
@Autowired
|
|||
|
|
private SzTreatmentBasisService service;
|
|||
|
|
|
|||
|
|
@Operation(summary = "新增")
|
|||
|
|
@PostMapping("/insert")
|
|||
|
|
public R<SzTreatmentBasis> insert(@Validated(Insert.class) @RequestBody SzTreatmentBasis dto) {
|
|||
|
|
|
|||
|
|
if (service.lambdaQuery().eq(SzTreatmentBasis::getLegalName,dto.getLegalName())
|
|||
|
|
.count() > 0) {
|
|||
|
|
throw new IllegalArgumentException("当前名称已存在");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (Objects.isNull(dto.getPId())){
|
|||
|
|
dto.setPId(0L);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
dto.setCreateTime(new Date());
|
|||
|
|
dto.setId(IdWorker.getId());
|
|||
|
|
|
|||
|
|
if (dto.getStatus() == 0) {
|
|||
|
|
dto.setDisplay(0);
|
|||
|
|
} else {
|
|||
|
|
dto.setDisplay(1);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
boolean result = service.save(dto);
|
|||
|
|
|
|||
|
|
return R.ok(result ? dto : null);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
@Operation(summary = "修改")
|
|||
|
|
@PostMapping("/update")
|
|||
|
|
public R<SzTreatmentBasis> update(@Validated(Update.class) @RequestBody SzTreatmentBasis dto) {
|
|||
|
|
|
|||
|
|
|
|||
|
|
if (service.lambdaQuery()
|
|||
|
|
.ne(SzTreatmentBasis::getId,dto.getId())
|
|||
|
|
.eq(SzTreatmentBasis::getLegalName,dto.getLegalName())
|
|||
|
|
.count() > 0) {
|
|||
|
|
throw new IllegalArgumentException("当前名称已存在");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
dto.setCreateTime(null);
|
|||
|
|
dto.setCreateBy(null);
|
|||
|
|
dto.setCreateName(null);
|
|||
|
|
dto.setUpdateTime(new Date());
|
|||
|
|
if (dto.getStatus() == 0) {
|
|||
|
|
dto.setDisplay(0);
|
|||
|
|
} else {
|
|||
|
|
dto.setDisplay(1);
|
|||
|
|
}
|
|||
|
|
boolean result = service.updateById(dto);
|
|||
|
|
|
|||
|
|
return R.ok(result ? dto : null);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
@Operation(summary = "获取详情")
|
|||
|
|
@GetMapping("/get/{id}")
|
|||
|
|
public R<SzTreatmentBasis> get(@Schema(name = "id") @PathVariable("id") Serializable id) {
|
|||
|
|
if (Objects.isNull(service.getById(id))) {
|
|||
|
|
throw new IllegalArgumentException("当前数据不存在");
|
|||
|
|
}
|
|||
|
|
return R.ok(service.getById(id));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
@Operation(summary = "获取树")
|
|||
|
|
@GetMapping("/get/tree")
|
|||
|
|
public R<List<SzTreatmentBasis>> getTree() {
|
|||
|
|
List<SzTreatmentBasis> list = service.list();
|
|||
|
|
if (CollectionUtils.isEmpty(list)){
|
|||
|
|
return R.ok(list);
|
|||
|
|
}
|
|||
|
|
Map<Long, List<SzTreatmentBasis>> listMap = list.stream().collect(Collectors.groupingBy(SzTreatmentBasis::getPId));
|
|||
|
|
|
|||
|
|
list.forEach(o -> o.setChildren(listMap.get(o.getId())));
|
|||
|
|
List<SzTreatmentBasis> parentList = list.stream()
|
|||
|
|
.filter(o -> 0L == o.getPId())
|
|||
|
|
.collect(Collectors.toList());
|
|||
|
|
|
|||
|
|
return R.ok(parentList);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
@Operation(summary = "获取树-不显示禁用的")
|
|||
|
|
@GetMapping("/get/treeFiltered")
|
|||
|
|
public R<List<SzTreatmentBasis>> getTreeFiltered() {
|
|||
|
|
List<SzTreatmentBasis> list = service.list();
|
|||
|
|
if (CollectionUtils.isEmpty(list)){
|
|||
|
|
return R.ok(list);
|
|||
|
|
}
|
|||
|
|
Map<Long, List<SzTreatmentBasis>> listMap = list.stream().collect(Collectors.groupingBy(SzTreatmentBasis::getPId));
|
|||
|
|
|
|||
|
|
list.forEach(o -> o.setChildren(listMap.get(o.getId())));
|
|||
|
|
List<SzTreatmentBasis> parentList = list.stream()
|
|||
|
|
.filter(o -> 0L == o.getPId())
|
|||
|
|
.collect(Collectors.toList());
|
|||
|
|
|
|||
|
|
parentList.forEach(this::trim);
|
|||
|
|
parentList.removeIf(node -> CollectionUtils.isEmpty(node.getChildren()) && (Integer.valueOf(0).equals(node.getDisplay()) || node.getDisplay() == null));
|
|||
|
|
|
|||
|
|
return R.ok(parentList);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private boolean trim(SzTreatmentBasis node) {
|
|||
|
|
List<SzTreatmentBasis> children = node.getChildren();
|
|||
|
|
boolean isMiddleNode = false;
|
|||
|
|
if (CollectionUtils.isNotEmpty(children)) {
|
|||
|
|
isMiddleNode = true;
|
|||
|
|
children.removeIf(this::trim);
|
|||
|
|
}
|
|||
|
|
//没有子节点的节点,且display是0,是末端节点;没有子节点的节点,且曾经有过子节点,是中间节点
|
|||
|
|
//末端节点的display是0就删,中间节点没有子节点就删
|
|||
|
|
return CollectionUtils.isEmpty(children) && (isMiddleNode || Integer.valueOf(0).equals(node.getDisplay()));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
@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));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|