mirror of
https://gitcode.com/ageerle/ruoyi-ai.git
synced 2026-03-27 19:43:42 +08:00
添加知识库权限控制功能
This commit is contained in:
@@ -28,6 +28,11 @@ public interface IKnowledgeInfoService {
|
||||
*/
|
||||
TableDataInfo<KnowledgeInfoVo> queryPageList(KnowledgeInfoBo bo, PageQuery pageQuery);
|
||||
|
||||
/**
|
||||
* 查询知识库列表
|
||||
*/
|
||||
TableDataInfo<KnowledgeInfoVo> queryPageListByRole(PageQuery pageQuery);
|
||||
|
||||
/**
|
||||
* 查询知识库列表
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
package org.ruoyi.service;
|
||||
|
||||
import org.ruoyi.core.page.PageQuery;
|
||||
import org.ruoyi.core.page.TableDataInfo;
|
||||
import org.ruoyi.domain.bo.KnowledgeRoleGroupBo;
|
||||
import org.ruoyi.domain.vo.KnowledgeRoleGroupVo;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 知识库角色组Service接口
|
||||
*
|
||||
* @author ageerle
|
||||
* @date 2025-07-19
|
||||
*/
|
||||
public interface IKnowledgeRoleGroupService {
|
||||
|
||||
/**
|
||||
* 查询知识库角色组
|
||||
*/
|
||||
KnowledgeRoleGroupVo queryById(Long id);
|
||||
|
||||
/**
|
||||
* 查询知识库角色组列表
|
||||
*/
|
||||
TableDataInfo<KnowledgeRoleGroupVo> queryPageList(KnowledgeRoleGroupBo bo, PageQuery pageQuery);
|
||||
|
||||
/**
|
||||
* 查询知识库角色组列表
|
||||
*/
|
||||
List<KnowledgeRoleGroupVo> queryList(KnowledgeRoleGroupBo bo);
|
||||
|
||||
/**
|
||||
* 新增知识库角色组
|
||||
*/
|
||||
Boolean insertByBo(KnowledgeRoleGroupBo bo);
|
||||
|
||||
/**
|
||||
* 修改知识库角色组
|
||||
*/
|
||||
Boolean updateByBo(KnowledgeRoleGroupBo bo);
|
||||
|
||||
/**
|
||||
* 校验并批量删除知识库角色组信息
|
||||
*/
|
||||
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package org.ruoyi.service;
|
||||
|
||||
import org.ruoyi.core.page.PageQuery;
|
||||
import org.ruoyi.core.page.TableDataInfo;
|
||||
import org.ruoyi.domain.bo.KnowledgeRoleRelationBo;
|
||||
import org.ruoyi.domain.vo.KnowledgeRoleRelationVo;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 知识库角色与知识库关联Service接口
|
||||
*
|
||||
* @author ageerle
|
||||
* @date 2025-07-19
|
||||
*/
|
||||
public interface IKnowledgeRoleRelationService {
|
||||
|
||||
/**
|
||||
* 查询知识库角色与知识库关联
|
||||
*/
|
||||
KnowledgeRoleRelationVo queryById(Long id);
|
||||
|
||||
/**
|
||||
* 查询知识库角色与知识库关联列表
|
||||
*/
|
||||
TableDataInfo<KnowledgeRoleRelationVo> queryPageList(KnowledgeRoleRelationBo bo, PageQuery pageQuery);
|
||||
|
||||
/**
|
||||
* 查询知识库角色与知识库关联列表
|
||||
*/
|
||||
List<KnowledgeRoleRelationVo> queryList(KnowledgeRoleRelationBo bo);
|
||||
|
||||
/**
|
||||
* 新增知识库角色与知识库关联
|
||||
*/
|
||||
Boolean insertByBo(KnowledgeRoleRelationBo bo);
|
||||
|
||||
/**
|
||||
* 修改知识库角色与知识库关联
|
||||
*/
|
||||
Boolean updateByBo(KnowledgeRoleRelationBo bo);
|
||||
|
||||
/**
|
||||
* 校验并批量删除知识库角色与知识库关联信息
|
||||
*/
|
||||
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package org.ruoyi.service;
|
||||
|
||||
import org.ruoyi.core.page.PageQuery;
|
||||
import org.ruoyi.core.page.TableDataInfo;
|
||||
import org.ruoyi.domain.bo.KnowledgeRoleBo;
|
||||
import org.ruoyi.domain.vo.KnowledgeRoleVo;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 知识库角色Service接口
|
||||
*
|
||||
* @author ageerle
|
||||
* @date 2025-07-19
|
||||
*/
|
||||
public interface IKnowledgeRoleService {
|
||||
|
||||
/**
|
||||
* 查询知识库角色
|
||||
*/
|
||||
KnowledgeRoleVo queryById(Long id);
|
||||
|
||||
/**
|
||||
* 查询知识库角色列表
|
||||
*/
|
||||
TableDataInfo<KnowledgeRoleVo> queryPageList(KnowledgeRoleBo bo, PageQuery pageQuery);
|
||||
|
||||
/**
|
||||
* 查询知识库角色列表
|
||||
*/
|
||||
List<KnowledgeRoleVo> queryList(KnowledgeRoleBo bo);
|
||||
|
||||
/**
|
||||
* 新增知识库角色
|
||||
*/
|
||||
Boolean insertByBo(KnowledgeRoleBo bo);
|
||||
|
||||
/**
|
||||
* 修改知识库角色
|
||||
*/
|
||||
Boolean updateByBo(KnowledgeRoleBo bo);
|
||||
|
||||
/**
|
||||
* 校验并批量删除知识库角色信息
|
||||
*/
|
||||
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
package org.ruoyi.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.ruoyi.common.core.utils.MapstructUtils;
|
||||
import org.ruoyi.common.core.utils.StringUtils;
|
||||
import org.ruoyi.core.page.PageQuery;
|
||||
import org.ruoyi.core.page.TableDataInfo;
|
||||
import org.ruoyi.domain.KnowledgeRoleGroup;
|
||||
import org.ruoyi.domain.bo.KnowledgeRoleGroupBo;
|
||||
import org.ruoyi.domain.vo.KnowledgeRoleGroupVo;
|
||||
import org.ruoyi.mapper.KnowledgeRoleGroupMapper;
|
||||
import org.ruoyi.service.IKnowledgeRoleGroupService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 知识库角色组Service业务层处理
|
||||
*
|
||||
* @author ageerle
|
||||
* @date 2025-07-19
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
@Service
|
||||
public class KnowledgeRoleGroupServiceImpl implements IKnowledgeRoleGroupService {
|
||||
|
||||
private final KnowledgeRoleGroupMapper baseMapper;
|
||||
|
||||
/**
|
||||
* 查询知识库角色组
|
||||
*/
|
||||
@Override
|
||||
public KnowledgeRoleGroupVo queryById(Long id) {
|
||||
return baseMapper.selectVoById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询知识库角色组列表
|
||||
*/
|
||||
@Override
|
||||
public TableDataInfo<KnowledgeRoleGroupVo> queryPageList(KnowledgeRoleGroupBo bo, PageQuery pageQuery) {
|
||||
LambdaQueryWrapper<KnowledgeRoleGroup> lqw = buildQueryWrapper(bo);
|
||||
Page<KnowledgeRoleGroupVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
||||
return TableDataInfo.build(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询知识库角色组列表
|
||||
*/
|
||||
@Override
|
||||
public List<KnowledgeRoleGroupVo> queryList(KnowledgeRoleGroupBo bo) {
|
||||
LambdaQueryWrapper<KnowledgeRoleGroup> lqw = buildQueryWrapper(bo);
|
||||
return baseMapper.selectVoList(lqw);
|
||||
}
|
||||
|
||||
private LambdaQueryWrapper<KnowledgeRoleGroup> buildQueryWrapper(KnowledgeRoleGroupBo bo) {
|
||||
Map<String, Object> params = bo.getParams();
|
||||
LambdaQueryWrapper<KnowledgeRoleGroup> lqw = Wrappers.lambdaQuery();
|
||||
lqw.like(StringUtils.isNotBlank(bo.getName()), KnowledgeRoleGroup::getName, bo.getName());
|
||||
return lqw;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增知识库角色组
|
||||
*/
|
||||
@Override
|
||||
public Boolean insertByBo(KnowledgeRoleGroupBo bo) {
|
||||
KnowledgeRoleGroup add = MapstructUtils.convert(bo, KnowledgeRoleGroup.class);
|
||||
validEntityBeforeSave(add);
|
||||
boolean flag = baseMapper.insert(add) > 0;
|
||||
if (flag) {
|
||||
bo.setId(add.getId());
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改知识库角色组
|
||||
*/
|
||||
@Override
|
||||
public Boolean updateByBo(KnowledgeRoleGroupBo bo) {
|
||||
KnowledgeRoleGroup update = MapstructUtils.convert(bo, KnowledgeRoleGroup.class);
|
||||
validEntityBeforeSave(update);
|
||||
return baseMapper.updateById(update) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存前的数据校验
|
||||
*/
|
||||
private void validEntityBeforeSave(KnowledgeRoleGroup entity) {
|
||||
//TODO 做一些数据校验,如唯一约束
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除知识库角色组
|
||||
*/
|
||||
@Override
|
||||
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
||||
if (isValid) {
|
||||
//TODO 做一些业务上的校验,判断是否需要校验
|
||||
}
|
||||
return baseMapper.deleteBatchIds(ids) > 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
package org.ruoyi.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.ruoyi.common.core.utils.MapstructUtils;
|
||||
import org.ruoyi.core.page.PageQuery;
|
||||
import org.ruoyi.core.page.TableDataInfo;
|
||||
import org.ruoyi.domain.KnowledgeRoleRelation;
|
||||
import org.ruoyi.domain.bo.KnowledgeRoleRelationBo;
|
||||
import org.ruoyi.domain.vo.KnowledgeRoleRelationVo;
|
||||
import org.ruoyi.mapper.KnowledgeRoleRelationMapper;
|
||||
import org.ruoyi.service.IKnowledgeRoleRelationService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 知识库角色与知识库关联Service业务层处理
|
||||
*
|
||||
* @author ageerle
|
||||
* @date 2025-07-19
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
@Service
|
||||
public class KnowledgeRoleRelationServiceImpl implements IKnowledgeRoleRelationService {
|
||||
|
||||
private final KnowledgeRoleRelationMapper baseMapper;
|
||||
private final KnowledgeRoleRelationMapper knowledgeRoleRelationMapper;
|
||||
|
||||
/**
|
||||
* 查询知识库角色与知识库关联
|
||||
*/
|
||||
@Override
|
||||
public KnowledgeRoleRelationVo queryById(Long id) {
|
||||
return baseMapper.selectVoById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询知识库角色与知识库关联列表
|
||||
*/
|
||||
@Override
|
||||
public TableDataInfo<KnowledgeRoleRelationVo> queryPageList(KnowledgeRoleRelationBo bo, PageQuery pageQuery) {
|
||||
LambdaQueryWrapper<KnowledgeRoleRelation> lqw = buildQueryWrapper(bo);
|
||||
Page<KnowledgeRoleRelationVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
||||
return TableDataInfo.build(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询知识库角色与知识库关联列表
|
||||
*/
|
||||
@Override
|
||||
public List<KnowledgeRoleRelationVo> queryList(KnowledgeRoleRelationBo bo) {
|
||||
LambdaQueryWrapper<KnowledgeRoleRelation> lqw = buildQueryWrapper(bo);
|
||||
return baseMapper.selectVoList(lqw);
|
||||
}
|
||||
|
||||
private LambdaQueryWrapper<KnowledgeRoleRelation> buildQueryWrapper(KnowledgeRoleRelationBo bo) {
|
||||
Map<String, Object> params = bo.getParams();
|
||||
LambdaQueryWrapper<KnowledgeRoleRelation> lqw = Wrappers.lambdaQuery();
|
||||
lqw.eq(bo.getKnowledgeRoleId() != null, KnowledgeRoleRelation::getKnowledgeRoleId, bo.getKnowledgeRoleId());
|
||||
lqw.eq(bo.getKnowledgeId() != null, KnowledgeRoleRelation::getKnowledgeId, bo.getKnowledgeId());
|
||||
return lqw;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增知识库角色与知识库关联
|
||||
*/
|
||||
@Override
|
||||
public Boolean insertByBo(KnowledgeRoleRelationBo bo) {
|
||||
KnowledgeRoleRelation add = MapstructUtils.convert(bo, KnowledgeRoleRelation.class);
|
||||
validEntityBeforeSave(add);
|
||||
boolean flag = baseMapper.insert(add) > 0;
|
||||
if (flag) {
|
||||
bo.setId(add.getId());
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改知识库角色与知识库关联
|
||||
*/
|
||||
@Override
|
||||
public Boolean updateByBo(KnowledgeRoleRelationBo bo) {
|
||||
KnowledgeRoleRelation update = MapstructUtils.convert(bo, KnowledgeRoleRelation.class);
|
||||
validEntityBeforeSave(update);
|
||||
return baseMapper.updateById(update) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存前的数据校验
|
||||
*/
|
||||
private void validEntityBeforeSave(KnowledgeRoleRelation entity) {
|
||||
//TODO 做一些数据校验,如唯一约束
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除知识库角色与知识库关联
|
||||
*/
|
||||
@Override
|
||||
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
||||
if (isValid) {
|
||||
//TODO 做一些业务上的校验,判断是否需要校验
|
||||
}
|
||||
return baseMapper.deleteBatchIds(ids) > 0;
|
||||
}
|
||||
|
||||
public void saveRoleKnowledgeRelations(Long knowledgeRoleId, List<Long> knowledgeIds) {
|
||||
if (knowledgeRoleId == null) {
|
||||
throw new IllegalArgumentException("knowledgeRoleId不能为空");
|
||||
}
|
||||
|
||||
// 1. 删除旧的关联记录
|
||||
knowledgeRoleRelationMapper.deleteByRoleId(knowledgeRoleId);
|
||||
|
||||
// 2. 插入新的关联记录
|
||||
if (CollectionUtils.isNotEmpty(knowledgeIds)) {
|
||||
List<KnowledgeRoleRelation> insertList = new ArrayList<>();
|
||||
knowledgeIds.forEach(knowledgeId -> {
|
||||
KnowledgeRoleRelation knowledgeRoleRelation = new KnowledgeRoleRelation();
|
||||
knowledgeRoleRelation.setKnowledgeId(knowledgeId);
|
||||
knowledgeRoleRelation.setKnowledgeRoleId(knowledgeRoleId);
|
||||
insertList.add(knowledgeRoleRelation);
|
||||
});
|
||||
knowledgeRoleRelationMapper.insertBatch(insertList);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,213 @@
|
||||
package org.ruoyi.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.ruoyi.common.core.utils.MapstructUtils;
|
||||
import org.ruoyi.core.page.PageQuery;
|
||||
import org.ruoyi.core.page.TableDataInfo;
|
||||
import org.ruoyi.domain.KnowledgeRole;
|
||||
import org.ruoyi.domain.KnowledgeRoleGroup;
|
||||
import org.ruoyi.domain.KnowledgeRoleRelation;
|
||||
import org.ruoyi.domain.bo.KnowledgeRoleBo;
|
||||
import org.ruoyi.domain.vo.KnowledgeRoleVo;
|
||||
import org.ruoyi.mapper.KnowledgeRoleGroupMapper;
|
||||
import org.ruoyi.mapper.KnowledgeRoleMapper;
|
||||
import org.ruoyi.mapper.KnowledgeRoleRelationMapper;
|
||||
import org.ruoyi.service.IKnowledgeRoleService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 知识库角色Service业务层处理
|
||||
*
|
||||
* @author ageerle
|
||||
* @date 2025-07-19
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
@Service
|
||||
public class KnowledgeRoleServiceImpl implements IKnowledgeRoleService {
|
||||
|
||||
private final KnowledgeRoleMapper baseMapper;
|
||||
private final KnowledgeRoleGroupMapper knowledgeRoleGroupMapper;
|
||||
private final KnowledgeRoleRelationMapper knowledgeRoleRelationMapper;
|
||||
private final KnowledgeRoleRelationServiceImpl knowledgeRoleRelationServiceImpl;
|
||||
|
||||
/**
|
||||
* 查询知识库角色
|
||||
*/
|
||||
@Override
|
||||
public KnowledgeRoleVo queryById(Long id) {
|
||||
KnowledgeRoleVo vo = baseMapper.selectVoById(id);
|
||||
fillKnowledgeIds(vo);
|
||||
fillKnowledgeRoleGroupName(vo);
|
||||
return vo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询知识库角色列表
|
||||
*/
|
||||
@Override
|
||||
public TableDataInfo<KnowledgeRoleVo> queryPageList(KnowledgeRoleBo bo, PageQuery pageQuery) {
|
||||
LambdaQueryWrapper<KnowledgeRole> lqw = buildQueryWrapper(bo);
|
||||
Page<KnowledgeRoleVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
||||
|
||||
fillKnowledgeIds(result.getRecords());
|
||||
fillKnowledgeRoleGroupName(result.getRecords());
|
||||
return TableDataInfo.build(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询知识库角色列表
|
||||
*/
|
||||
@Override
|
||||
public List<KnowledgeRoleVo> queryList(KnowledgeRoleBo bo) {
|
||||
LambdaQueryWrapper<KnowledgeRole> lqw = buildQueryWrapper(bo);
|
||||
List<KnowledgeRoleVo> knowledgeRoleVos = baseMapper.selectVoList(lqw);
|
||||
fillKnowledgeIds(knowledgeRoleVos);
|
||||
fillKnowledgeRoleGroupName(knowledgeRoleVos);
|
||||
return knowledgeRoleVos;
|
||||
}
|
||||
|
||||
private LambdaQueryWrapper<KnowledgeRole> buildQueryWrapper(KnowledgeRoleBo bo) {
|
||||
Map<String, Object> params = bo.getParams();
|
||||
LambdaQueryWrapper<KnowledgeRole> lqw = Wrappers.lambdaQuery();
|
||||
lqw.eq(bo.getGroupId() != null, KnowledgeRole::getGroupId, bo.getGroupId());
|
||||
return lqw;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增知识库角色
|
||||
*/
|
||||
@Override
|
||||
public Boolean insertByBo(KnowledgeRoleBo bo) {
|
||||
KnowledgeRole add = MapstructUtils.convert(bo, KnowledgeRole.class);
|
||||
validEntityBeforeSave(add);
|
||||
boolean flag = baseMapper.insert(add) > 0;
|
||||
if (flag) {
|
||||
bo.setId(add.getId());
|
||||
|
||||
// 生成relation数据
|
||||
knowledgeRoleRelationServiceImpl.saveRoleKnowledgeRelations(bo.getId(), bo.getKnowledgeIds());
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改知识库角色
|
||||
*/
|
||||
@Override
|
||||
public Boolean updateByBo(KnowledgeRoleBo bo) {
|
||||
KnowledgeRole update = MapstructUtils.convert(bo, KnowledgeRole.class);
|
||||
validEntityBeforeSave(update);
|
||||
int count = baseMapper.updateById(update);
|
||||
if (count > 0) {
|
||||
// 生成relation数据
|
||||
knowledgeRoleRelationServiceImpl.saveRoleKnowledgeRelations(bo.getId(), bo.getKnowledgeIds());
|
||||
}
|
||||
|
||||
return count > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存前的数据校验
|
||||
*/
|
||||
private void validEntityBeforeSave(KnowledgeRole entity) {
|
||||
//TODO 做一些数据校验,如唯一约束
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除知识库角色
|
||||
*/
|
||||
@Override
|
||||
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
||||
if (isValid) {
|
||||
//TODO 做一些业务上的校验,判断是否需要校验
|
||||
}
|
||||
int count = baseMapper.deleteBatchIds(ids);
|
||||
if (count > 0) {
|
||||
knowledgeRoleRelationMapper.deleteByRoleIds(ids.stream().toList());
|
||||
}
|
||||
|
||||
return count > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 填充 VO 的 knowledgeIds 字段(从中间表查询)
|
||||
*/
|
||||
private void fillKnowledgeIds(KnowledgeRoleVo vo) {
|
||||
if (vo == null) return;
|
||||
List<Long> knowledgeIds = knowledgeRoleRelationMapper.selectKnowledgeIdsByRoleId(vo.getId());
|
||||
vo.setKnowledgeIds(knowledgeIds);
|
||||
}
|
||||
|
||||
private void fillKnowledgeIds(List<KnowledgeRoleVo> list) {
|
||||
if (CollectionUtils.isEmpty(list)) return;
|
||||
|
||||
// 1. 提取所有 roleId
|
||||
Set<Long> roleIds = list.stream()
|
||||
.map(KnowledgeRoleVo::getId)
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
if (roleIds.isEmpty()) return;
|
||||
|
||||
// 2. 一次性查询所有 roleId 对应的 knowledgeId 列表
|
||||
List<KnowledgeRoleRelation> relations = knowledgeRoleRelationMapper.selectList(
|
||||
new LambdaQueryWrapper<KnowledgeRoleRelation>()
|
||||
.in(KnowledgeRoleRelation::getKnowledgeRoleId, roleIds)
|
||||
);
|
||||
|
||||
// 3. 转为 Map<roleId, List<knowledgeId>>
|
||||
Map<Long, List<Long>> roleIdToKnowledgeIds = relations.stream()
|
||||
.collect(Collectors.groupingBy(
|
||||
KnowledgeRoleRelation::getKnowledgeRoleId,
|
||||
Collectors.mapping(KnowledgeRoleRelation::getKnowledgeId, Collectors.toList())
|
||||
));
|
||||
|
||||
// 4. 回填到 VO 中
|
||||
for (KnowledgeRoleVo vo : list) {
|
||||
vo.setKnowledgeIds(roleIdToKnowledgeIds.getOrDefault(vo.getId(), Collections.emptyList()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 填充 VO 的 knowledgeRoleGroupName 字段
|
||||
*/
|
||||
private void fillKnowledgeRoleGroupName(KnowledgeRoleVo vo) {
|
||||
if (vo == null || vo.getGroupId() == null) return;
|
||||
|
||||
KnowledgeRoleGroup group = knowledgeRoleGroupMapper.selectById(vo.getGroupId());
|
||||
if (group != null) {
|
||||
vo.setGroupName(group.getName());
|
||||
}
|
||||
}
|
||||
|
||||
private void fillKnowledgeRoleGroupName(List<KnowledgeRoleVo> list) {
|
||||
if (CollectionUtils.isEmpty(list)) return;
|
||||
|
||||
// 1. 提取所有 groupId(去重)
|
||||
Set<Long> groupIds = list.stream()
|
||||
.map(KnowledgeRoleVo::getGroupId)
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
if (groupIds.isEmpty()) return;
|
||||
|
||||
// 2. 一次性查出所有角色组信息
|
||||
List<KnowledgeRoleGroup> groupList = knowledgeRoleGroupMapper.selectBatchIds(groupIds);
|
||||
|
||||
// 3. 转为 Map<id, name>
|
||||
Map<Long, String> groupNameMap = groupList.stream()
|
||||
.collect(Collectors.toMap(KnowledgeRoleGroup::getId, KnowledgeRoleGroup::getName));
|
||||
|
||||
// 4. 回填到每个 VO
|
||||
for (KnowledgeRoleVo vo : list) {
|
||||
vo.setGroupName(groupNameMap.get(vo.getGroupId()));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user