fix(资料中心): 资料中心完善
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
package com.jero.common.util;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class StreamUtils {
|
||||
|
||||
private StreamUtils(){
|
||||
}
|
||||
/**
|
||||
* 按某个指定字段去重
|
||||
*
|
||||
* @param keyExtractor 需要去重的字段
|
||||
* @return java.util.function.Predicate<T>
|
||||
* @author 陈賝
|
||||
* @date 2022/9/2 13:49
|
||||
*/
|
||||
public static <T> Predicate<T> distinctByKey(Function<? super T, ?> keyExtractor) {
|
||||
Map<Object, Boolean> seen = new ConcurrentHashMap<>();
|
||||
return t -> seen.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null;
|
||||
}
|
||||
}
|
||||
|
||||
+13
-13
@@ -1,25 +1,25 @@
|
||||
package com.jero.modules.laws.dataCenter.controller;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.jero.common.api.vo.Result;
|
||||
import com.jero.common.exception.JeroBootException;
|
||||
import com.jero.common.util.MessageUtils;
|
||||
import com.jero.common.api.vo.ResultCommon;
|
||||
import com.jero.common.aspect.annotation.AutoLog;
|
||||
import com.jero.common.exception.JeroBootException;
|
||||
import com.jero.common.system.base.controller.JeroController;
|
||||
import com.jero.common.util.MessageUtils;
|
||||
import com.jero.modules.laws.dataCenter.entity.LawsDataCenterFolder;
|
||||
import com.jero.modules.laws.dataCenter.service.ILawsDataCenterFolderService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import com.jero.common.system.base.controller.JeroController;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.poi.ss.formula.functions.T;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import com.jero.common.aspect.annotation.AutoLog;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.poi.ss.formula.functions.T;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
@@ -39,8 +39,8 @@ public class LawsDataCenterFolderController extends JeroController<LawsDataCente
|
||||
@AutoLog(value = "资料中心-文件夹-获取树型列表")
|
||||
@ApiOperation(value = "资料中心-文件夹-获取树型列表", notes = "资料中心-文件夹-获取树型列表")
|
||||
@GetMapping(value = "/getTreeList")
|
||||
public Result<List<LawsDataCenterFolder>> getTreeList() {
|
||||
List<LawsDataCenterFolder> treeList = lawsDataCenterFolderService.getTreeList();
|
||||
public Result<List<LawsDataCenterFolder>> getTreeList(String folderName) {
|
||||
List<LawsDataCenterFolder> treeList = lawsDataCenterFolderService.getTreeList(folderName);
|
||||
return Result.OK(treeList);
|
||||
}
|
||||
|
||||
|
||||
+5
@@ -143,4 +143,9 @@ public class LawsDataCenterFolder implements Serializable {
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
private java.lang.String pId;
|
||||
/**
|
||||
* 层级结构名 用于搜索过滤
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
private java.lang.String structureName;
|
||||
}
|
||||
|
||||
+12
-4
@@ -1,10 +1,11 @@
|
||||
package com.jero.modules.laws.dataCenter.mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import com.jero.modules.laws.dataCenter.entity.LawsDataCenterFile;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.jero.modules.laws.dataCenter.entity.LawsDataCenterFile;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
* @Description: 资料中心-文件数据
|
||||
@@ -14,4 +15,11 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
*/
|
||||
public interface LawsDataCenterFileMapper extends BaseMapper<LawsDataCenterFile> {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param page
|
||||
* @param queryWrapper
|
||||
* @return
|
||||
*/
|
||||
Page<LawsDataCenterFile> queryByPage(Page<LawsDataCenterFile> page, @Param(Constants.WRAPPER) QueryWrapper<LawsDataCenterFile> queryWrapper);
|
||||
}
|
||||
|
||||
+21
@@ -16,4 +16,25 @@
|
||||
<result column="folder_id" property="folderId" />
|
||||
<result column="owner_id" property="ownerId" />
|
||||
</resultMap>
|
||||
|
||||
<select id="queryByPage" resultType="com.jero.modules.laws.dataCenter.entity.LawsDataCenterFile">
|
||||
SELECT *
|
||||
FROM (SELECT id,
|
||||
create_by,
|
||||
create_time,
|
||||
update_by,
|
||||
update_time,
|
||||
org_code,
|
||||
del_flag,
|
||||
file_name,
|
||||
file_id,
|
||||
push_range_ids,
|
||||
file_description,
|
||||
folder_id,
|
||||
owner_id,
|
||||
uploader,
|
||||
(SELECT auth_manage_ids FROM laws_data_center_folder d WHERE d.id = folder_id) auth_manage_ids
|
||||
FROM laws_data_center_file) t
|
||||
${ew.customSqlSegment}
|
||||
</select>
|
||||
</mapper>
|
||||
+3
-1
@@ -27,6 +27,8 @@
|
||||
FROM
|
||||
laws_data_center_folder ldcf
|
||||
WHERE del_flag = 0 AND (ldcf.owner_id = #{userId}
|
||||
OR ldcf.auth_view_ids LIKE CONCAT('%',#{userId},'%'))
|
||||
OR ldcf.auth_view_ids LIKE CONCAT('%',#{userId},'%')
|
||||
OR ldcf.auth_manage_ids LIKE CONCAT('%',#{userId},'%'))
|
||||
order by ldcf.sort, ldcf.create_time
|
||||
</select>
|
||||
</mapper>
|
||||
+1
-1
@@ -17,7 +17,7 @@ public interface ILawsDataCenterFolderService extends IService<LawsDataCenterFol
|
||||
* @Date: 2023/10/26 17:16
|
||||
* @Description: 获取树型列表
|
||||
**/
|
||||
List<LawsDataCenterFolder> getTreeList();
|
||||
List<LawsDataCenterFolder> getTreeList(String folderName);
|
||||
|
||||
/**
|
||||
* 保存
|
||||
|
||||
+13
-17
@@ -1,6 +1,6 @@
|
||||
package com.jero.modules.laws.dataCenter.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
@@ -50,6 +50,8 @@ public class LawsDataCenterFileServiceImpl extends ServiceImpl<LawsDataCenterFil
|
||||
private IOSSFileService ossFileService;
|
||||
@Autowired
|
||||
private SendMessageAPI sendMessageAPI;
|
||||
@Autowired
|
||||
private LawsDataCenterFileMapper lawsDataCenterFileMapper;
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
@@ -61,33 +63,27 @@ public class LawsDataCenterFileServiceImpl extends ServiceImpl<LawsDataCenterFil
|
||||
*/
|
||||
@Override
|
||||
public IPage<LawsDataCenterFile> queryPage(LawsDataCenterFile lawsDataCenterFile, Integer pageNo, Integer pageSize) {
|
||||
LambdaQueryWrapper<LawsDataCenterFile> queryWrapper = new LambdaQueryWrapper<>();
|
||||
QueryWrapper<LawsDataCenterFile> queryWrapper = new QueryWrapper<>();
|
||||
Page<LawsDataCenterFile> page = new Page<>(pageNo, pageSize);
|
||||
queryWrapper.like(StringUtils.isNotBlank(lawsDataCenterFile.getFileName()),
|
||||
LawsDataCenterFile::getFileName, lawsDataCenterFile.getFileName());
|
||||
"file_name", lawsDataCenterFile.getFileName());
|
||||
queryWrapper.like(StringUtils.isNotBlank(lawsDataCenterFile.getUploader()),
|
||||
LawsDataCenterFile::getUploader, lawsDataCenterFile.getUploader());
|
||||
"uploader", lawsDataCenterFile.getUploader());
|
||||
if (StringUtils.isNotBlank(lawsDataCenterFile.getUploadTime())) {
|
||||
String[] timeArr = lawsDataCenterFile.getUploadTime().split(",");
|
||||
queryWrapper.between(LawsDataCenterFile::getCreateTime,
|
||||
queryWrapper.between("create_time",
|
||||
DateUtil.getDateSecond(timeArr[0]), DateUtil.getDateSecond(timeArr[1]));
|
||||
}
|
||||
if (StringUtils.isBlank(lawsDataCenterFile.getFolderId())) {
|
||||
queryWrapper.and(qw -> qw
|
||||
.isNull(LawsDataCenterFile::getFolderId).or()
|
||||
.like(LawsDataCenterFile::getPushRangeIds, CurrentUserUtil.getId())
|
||||
);
|
||||
} else {
|
||||
queryWrapper.eq(LawsDataCenterFile::getFolderId, lawsDataCenterFile.getFolderId());
|
||||
}
|
||||
queryWrapper.eq(StringUtils.isNotBlank(lawsDataCenterFile.getFolderId()), "folder_id", lawsDataCenterFile.getFolderId());
|
||||
if (!CurrentUserUtil.getRoles().contains(FieldCommon.ROLE_ADMIN)) {
|
||||
queryWrapper.and(qw -> qw
|
||||
.eq(LawsDataCenterFile::getOwnerId, CurrentUserUtil.getId()).or()
|
||||
.like(LawsDataCenterFile::getPushRangeIds, CurrentUserUtil.getId())
|
||||
.eq("owner_id", CurrentUserUtil.getId()).or()
|
||||
.like("push_range_ids", CurrentUserUtil.getId())
|
||||
.or().like("auth_manage_ids", CurrentUserUtil.getId())
|
||||
);
|
||||
}
|
||||
queryWrapper.orderByDesc(LawsDataCenterFile::getCreateTime);
|
||||
Page<LawsDataCenterFile> result = page(page, queryWrapper);
|
||||
queryWrapper.orderByDesc("create_time");
|
||||
Page<LawsDataCenterFile> result = lawsDataCenterFileMapper.queryByPage(page, queryWrapper);
|
||||
if (!CurrentUserUtil.getRoles().contains(FieldCommon.ROLE_ADMIN)){
|
||||
for (LawsDataCenterFile file : result.getRecords()) {
|
||||
// 管理权限标识
|
||||
|
||||
+66
-40
@@ -5,7 +5,9 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.jero.common.api.vo.ResultCommon;
|
||||
import com.jero.common.exception.JeroBootException;
|
||||
import com.jero.modules.laws.common.constant.FieldCommon;
|
||||
import com.jero.common.system.vo.LoginUser;
|
||||
import com.jero.common.util.BeanCopyUtils;
|
||||
import com.jero.common.util.StreamUtils;
|
||||
import com.jero.modules.laws.common.util.CurrentUserUtil;
|
||||
import com.jero.modules.laws.common.util.TreeNodeComparator;
|
||||
import com.jero.modules.laws.dataCenter.entity.LawsDataCenterFile;
|
||||
@@ -14,14 +16,15 @@ import com.jero.modules.laws.dataCenter.mapper.LawsDataCenterFolderMapper;
|
||||
import com.jero.modules.laws.dataCenter.service.ILawsDataCenterFileService;
|
||||
import com.jero.modules.laws.dataCenter.service.ILawsDataCenterFolderService;
|
||||
import com.jero.modules.system.service.ISysUserService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -35,6 +38,7 @@ import java.util.stream.Collectors;
|
||||
*/
|
||||
@Service
|
||||
@Transactional(rollbackFor = JeroBootException.class)
|
||||
@Slf4j
|
||||
public class LawsDataCenterFolderServiceImpl extends ServiceImpl<LawsDataCenterFolderMapper, LawsDataCenterFolder> implements ILawsDataCenterFolderService {
|
||||
|
||||
@Autowired
|
||||
@@ -43,54 +47,76 @@ public class LawsDataCenterFolderServiceImpl extends ServiceImpl<LawsDataCenterF
|
||||
private ILawsDataCenterFileService lawsDataCenterFileService;
|
||||
@Autowired
|
||||
private ISysUserService sysUserService;
|
||||
|
||||
/**
|
||||
* @Author: liao
|
||||
* @Date: 2023/10/26 17:17
|
||||
* @Description: 获取树型列表
|
||||
**/
|
||||
@Override
|
||||
public List<LawsDataCenterFolder> getTreeList() {
|
||||
// 获取全部文件夹集合
|
||||
List<LawsDataCenterFolder> folders = list();
|
||||
// 翻译
|
||||
folders.forEach(root -> {
|
||||
root.setAuthManageIdsDictText(sysUserService.dictByIdsOrUserNames(root.getAuthManageIds(), ""));
|
||||
root.setAuthViewIdsDictText(sysUserService.dictByIdsOrUserNames(root.getAuthViewIds(), ""));
|
||||
});
|
||||
public List<LawsDataCenterFolder> getTreeList(String folderName) {
|
||||
LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
||||
String roleIds = loginUser.getRoleIds();
|
||||
// 全部数据
|
||||
List<LawsDataCenterFolder> lawsDataCenterFolderList = list(new LambdaQueryWrapper<LawsDataCenterFolder>()
|
||||
.orderByAsc(LawsDataCenterFolder::getSort).orderByAsc(LawsDataCenterFolder::getCreateTime));
|
||||
List<LawsDataCenterFolder> allList = BeanCopyUtils.copyBeanList(lawsDataCenterFolderList, LawsDataCenterFolder.class);
|
||||
|
||||
// 创建节点映射,方便查找节点
|
||||
Map<String, LawsDataCenterFolder> nodeMap = new HashMap<>();
|
||||
folders.forEach(node -> {
|
||||
node.setPId(node.getParentId());
|
||||
nodeMap.put(node.getId(), node);
|
||||
});
|
||||
|
||||
// 非管理员角色只能查看自己拥有权限的文件夹
|
||||
if (!CurrentUserUtil.getRoles().contains(FieldCommon.ROLE_ADMIN)) {
|
||||
// 获取自己拥有权限的文件夹集合
|
||||
List<LawsDataCenterFolder> myFolders = lawsDataCenterFolderMapper.getMyFolderList(CurrentUserUtil.getId());
|
||||
|
||||
Map<String, LawsDataCenterFolder> myNodeMap = new HashMap<>();
|
||||
myFolders.forEach(node -> {
|
||||
node.setPId(node.getParentId());
|
||||
myNodeMap.put(node.getId(), node);
|
||||
});
|
||||
|
||||
// 如果有子级没有父级,则将子级挂在父级的父级上
|
||||
myFolders.forEach(node -> buildParent(node, nodeMap, myNodeMap));
|
||||
folders = myFolders;
|
||||
// 非管理员只能看到自己创建的 or 拥有管理权限 or 拥有查看权限的文件夹
|
||||
if (!roleIds.contains("admin")){
|
||||
lawsDataCenterFolderList = lawsDataCenterFolderList.stream()
|
||||
.filter(v -> (StringUtils.isNotBlank(v.getAuthManageIds()) && v.getAuthManageIds().contains(loginUser.getId()))
|
||||
|| (StringUtils.isNotBlank(v.getAuthViewIds()) && v.getAuthViewIds().contains(loginUser.getId()))
|
||||
|| v.getOwnerId().equals(loginUser.getId()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
// 创建根节点列表
|
||||
List<LawsDataCenterFolder> roots = folders.stream().filter(folder ->
|
||||
"0".equals(folder.getParentId())).collect(Collectors.toList());
|
||||
// 搜索
|
||||
if (StringUtils.isNotBlank(folderName)) {
|
||||
// 过滤搜索数据
|
||||
lawsDataCenterFolderList = lawsDataCenterFolderList.stream().filter(v -> v.getFolderName().contains(folderName)).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
// 对根节点进行排序
|
||||
roots.sort(new TreeNodeComparator());
|
||||
// 翻译
|
||||
for (LawsDataCenterFolder lawsDataCenterFolder : lawsDataCenterFolderList) {
|
||||
lawsDataCenterFolder.setAuthManageIdsDictText(sysUserService.dictByIdsOrUserNames(lawsDataCenterFolder.getAuthManageIds(), ""));
|
||||
lawsDataCenterFolder.setAuthViewIdsDictText(sysUserService.dictByIdsOrUserNames(lawsDataCenterFolder.getAuthViewIds(), ""));
|
||||
}
|
||||
|
||||
// 递归构建子节点
|
||||
roots.forEach(root -> buildChildren(root, nodeMap));
|
||||
return roots;
|
||||
// 寻找每个子级的父节点直到最上级
|
||||
List<LawsDataCenterFolder> fatherNodeList = new ArrayList<>();
|
||||
findFatherNode(lawsDataCenterFolderList, allList, fatherNodeList);
|
||||
lawsDataCenterFolderList.addAll(fatherNodeList);
|
||||
// 过滤重复数据
|
||||
lawsDataCenterFolderList = lawsDataCenterFolderList.stream().filter(StreamUtils.distinctByKey(LawsDataCenterFolder::getId)).collect(Collectors.toList());
|
||||
|
||||
// 构建树结构
|
||||
List<LawsDataCenterFolder> finalLawsDataCenterFolderList = lawsDataCenterFolderList;
|
||||
return lawsDataCenterFolderList.stream().filter(v -> "0".equals(v.getParentId()))
|
||||
.map(v -> v.setChildren(createChildrenList(v, finalLawsDataCenterFolderList)))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private void findFatherNode(List<LawsDataCenterFolder> lawsDataCenterFolderList, List<LawsDataCenterFolder> allList, List<LawsDataCenterFolder> fatherNodeList) {
|
||||
for (LawsDataCenterFolder lawsDataCenterFolder : lawsDataCenterFolderList) {
|
||||
String parentId = lawsDataCenterFolder.getParentId();
|
||||
if ("0".equals(parentId)){
|
||||
continue;
|
||||
}
|
||||
List<LawsDataCenterFolder> list = allList.stream().filter(v -> v.getId().equals(parentId)).collect(Collectors.toList());
|
||||
// 没被添加过
|
||||
boolean b = list.stream().noneMatch(v -> v.equals(lawsDataCenterFolder));
|
||||
if (!list.isEmpty() && b){
|
||||
fatherNodeList.add(list.get(0));
|
||||
findFatherNode(list, allList, fatherNodeList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List<LawsDataCenterFolder> createChildrenList(LawsDataCenterFolder treeList, List<LawsDataCenterFolder> lawsDataCenterFolderList) {
|
||||
return lawsDataCenterFolderList.stream().filter(children -> treeList.getId().equals(children.getParentId()))
|
||||
.map(folder -> folder.setChildren(createChildrenList(folder, lawsDataCenterFolderList)))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -153,7 +179,7 @@ public class LawsDataCenterFolderServiceImpl extends ServiceImpl<LawsDataCenterF
|
||||
*/
|
||||
@Override
|
||||
public void editById(LawsDataCenterFolder lawsDataCenterFolder) {
|
||||
saveOrUpdate(lawsDataCenterFolder);
|
||||
saveOrUpdate(lawsDataCenterFolder);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user