风险管控清单-左侧目录
parent
3702da0c36
commit
7d594dd6d9
|
|
@ -0,0 +1,56 @@
|
|||
package com.gunshi.project.xyt.controller;
|
||||
|
||||
import com.gunshi.core.result.R;
|
||||
import com.gunshi.project.xyt.model.RiskControlMenu;
|
||||
import com.gunshi.project.xyt.service.RiskControlMenuService;
|
||||
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;
|
||||
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;
|
||||
/**
|
||||
* 描述: 风险管控目录
|
||||
* author: xusan
|
||||
* date: 2024-08-22 14:16:35
|
||||
*/
|
||||
@Tag(name = "风险管控目录")
|
||||
@RestController
|
||||
@RequestMapping(value="/risk/menu")
|
||||
public class RiskControlMenuController {
|
||||
|
||||
@Autowired
|
||||
private RiskControlMenuService service;
|
||||
|
||||
|
||||
@Operation(summary = "新增")
|
||||
@PostMapping("/insert")
|
||||
public R<RiskControlMenu> insert(@Validated(Insert.class) @RequestBody RiskControlMenu dto) {
|
||||
return R.ok(service.saveData(dto));
|
||||
}
|
||||
|
||||
@Operation(summary = "修改")
|
||||
@PostMapping("/update")
|
||||
public R<RiskControlMenu> update(@Validated(Update.class) @RequestBody RiskControlMenu dto) {
|
||||
return R.ok(service.updateData(dto));
|
||||
}
|
||||
|
||||
@Operation(summary = "删除")
|
||||
@GetMapping("/del/{id}")
|
||||
public R<Boolean> del(@Schema(name = "id") @PathVariable("id") Serializable id) {
|
||||
return R.ok(service.delData(id));
|
||||
}
|
||||
|
||||
@Operation(summary = "树")
|
||||
@PostMapping("/tree")
|
||||
public R<List<RiskControlMenu>> tree() {
|
||||
return R.ok(service.tree());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -15,6 +15,7 @@ import jakarta.validation.constraints.Size;
|
|||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 描述: 风险管控目录
|
||||
|
|
@ -62,4 +63,9 @@ public class RiskControlMenu implements Serializable {
|
|||
@Schema(description="排序")
|
||||
private Integer orderIndex;
|
||||
|
||||
|
||||
@TableField(exist = false)
|
||||
@Schema(description="子集")
|
||||
private List<RiskControlMenu> children;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,91 @@
|
|||
package com.gunshi.project.xyt.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.gunshi.project.xyt.mapper.RiskControlInfoMapper;
|
||||
import com.gunshi.project.xyt.mapper.RiskControlMenuMapper;
|
||||
import com.gunshi.project.xyt.model.RiskControlInfo;
|
||||
import com.gunshi.project.xyt.model.RiskControlMenu;
|
||||
import com.gunshi.util.common.tree.TreeUtil;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 描述: 风险管控目录
|
||||
* author: xusan
|
||||
* date: 2024-08-22 14:16:35
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public class RiskControlMenuService extends ServiceImpl<RiskControlMenuMapper, RiskControlMenu>
|
||||
{
|
||||
|
||||
@Resource
|
||||
private RiskControlInfoMapper riskControlInfoMapper;
|
||||
|
||||
public RiskControlMenu saveData(RiskControlMenu dto) {
|
||||
if (Objects.isNull(dto.getParentId())){
|
||||
dto.setParentId(0L);
|
||||
}
|
||||
dto.setId(IdWorker.getId());
|
||||
QueryWrapper<RiskControlMenu> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("parent_id", dto.getParentId());
|
||||
queryWrapper.orderBy(true, false, "order_index");
|
||||
RiskControlMenu lastOne = super.getOne(queryWrapper, false);
|
||||
int order = 0;
|
||||
if (lastOne == null) {
|
||||
order = 1;
|
||||
} else {
|
||||
order = lastOne.getOrderIndex() + 1;
|
||||
}
|
||||
dto.setOrderIndex(order);
|
||||
this.save(dto);
|
||||
return dto;
|
||||
}
|
||||
|
||||
public RiskControlMenu updateData(RiskControlMenu dto) {
|
||||
if (Objects.isNull(this.getById(dto.getId()))) {
|
||||
throw new IllegalArgumentException("当前数据不存在");
|
||||
}
|
||||
this.updateById(dto);
|
||||
return dto;
|
||||
}
|
||||
|
||||
public Boolean delData(Serializable id) {
|
||||
if (Objects.isNull(this.getById(id))) {
|
||||
throw new IllegalArgumentException("当前数据不存在");
|
||||
}
|
||||
Long count = this.lambdaQuery()
|
||||
.eq(RiskControlMenu::getParentId, id)
|
||||
.count();
|
||||
if(count > 0){
|
||||
throw new IllegalArgumentException("请先删除下级目录");
|
||||
}
|
||||
//判断是否关联风险清单
|
||||
LambdaQueryWrapper<RiskControlInfo> wrapper = Wrappers.lambdaQuery();
|
||||
wrapper.eq(RiskControlInfo::getMenuId,id);
|
||||
if(riskControlInfoMapper.selectCount(wrapper) > 0){
|
||||
throw new IllegalArgumentException("请先删除关联的风险管控清单");
|
||||
}
|
||||
return this.removeById(id);
|
||||
}
|
||||
|
||||
public List<RiskControlMenu> tree() {
|
||||
LambdaQueryWrapper<RiskControlMenu> queryWrapper = Wrappers.lambdaQuery();
|
||||
queryWrapper.orderBy(true, true, RiskControlMenu::getOrderIndex);
|
||||
List<RiskControlMenu> list = this.list(queryWrapper);
|
||||
return TreeUtil.list2ListTree(list, 0L, RiskControlMenu::getId, RiskControlMenu::getParentId, RiskControlMenu::setChildren, null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue