92 lines
3.3 KiB
Java
92 lines
3.3 KiB
Java
package com.gunshi.project.ss.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.ss.mapper.RiskControlInfoMapper;
|
|
import com.gunshi.project.ss.mapper.RiskControlMenuMapper;
|
|
import com.gunshi.project.ss.model.RiskControlInfo;
|
|
import com.gunshi.project.ss.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);
|
|
}
|
|
}
|
|
|
|
|