|
@@ -0,0 +1,590 @@
|
|
|
+package com.dragoninfo.dcuc.auth.list.service.impl;
|
|
|
+
|
|
|
+import com.dragoninfo.dcuc.app.entity.ApplyInfo;
|
|
|
+import com.dragoninfo.dcuc.app.enumresources.ResourceTypeEnum;
|
|
|
+import com.dragoninfo.dcuc.app.facade.IApplyInfoFacade;
|
|
|
+import com.dragoninfo.dcuc.auth.auth.entity.AppFunInfo;
|
|
|
+import com.dragoninfo.dcuc.auth.auth.service.IAppFunInfoService;
|
|
|
+import com.dragoninfo.dcuc.auth.auth.vo.AppFunInfoVo;
|
|
|
+import com.dragoninfo.dcuc.auth.list.dto.AppFunRedListAddDTO;
|
|
|
+import com.dragoninfo.dcuc.auth.list.dto.AppFunRedListDTO;
|
|
|
+import com.dragoninfo.dcuc.auth.list.dto.FunRedListTreeDTO;
|
|
|
+import com.dragoninfo.dcuc.auth.list.dto.RedListOperateDTO;
|
|
|
+import com.dragoninfo.dcuc.auth.list.entity.RedList;
|
|
|
+import com.dragoninfo.dcuc.auth.list.entity.RedListContent;
|
|
|
+import com.dragoninfo.dcuc.auth.list.repo.RedListContentRepository;
|
|
|
+import com.dragoninfo.dcuc.auth.list.repo.RedListRepository;
|
|
|
+import com.dragoninfo.dcuc.auth.list.repo.bo.FunCountDO;
|
|
|
+import com.dragoninfo.dcuc.auth.list.service.IRedListService;
|
|
|
+import com.dragoninfo.dcuc.auth.sub.enumresource.SubObjTypeEnum;
|
|
|
+import com.dragonsoft.duceap.base.entity.search.SearchDTO;
|
|
|
+import com.dragonsoft.duceap.base.enums.BooleanEnum;
|
|
|
+import com.dragonsoft.duceap.commons.util.collections.CollectionUtils;
|
|
|
+import com.dragonsoft.duceap.commons.util.string.StringUtils;
|
|
|
+import com.dragonsoft.duceap.core.search.Searchable;
|
|
|
+import com.dragonsoft.duceap.core.search.enums.SearchOperator;
|
|
|
+import com.dragonsoft.duceap.core.search.filter.Condition;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.domain.Example;
|
|
|
+import org.springframework.data.domain.Page;
|
|
|
+import org.springframework.data.domain.PageImpl;
|
|
|
+import org.springframework.data.jpa.domain.Specification;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import javax.persistence.criteria.CriteriaBuilder;
|
|
|
+import javax.persistence.criteria.Path;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author mazq
|
|
|
+ * @date 2021/7/12
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class RedListServiceImpl implements IRedListService {
|
|
|
+
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ RedListRepository redListRepository;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ RedListContentRepository contentRepository;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IAppFunInfoService appFunInfoService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IApplyInfoFacade applyInfoFacade;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean funRedListAdd(List<AppFunRedListAddDTO> dtos) {
|
|
|
+ if(CollectionUtils.isEmpty(dtos)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ List<String> appIds = dtos.stream()
|
|
|
+ .map(AppFunRedListAddDTO::getAppId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ //获取已经添加过的应用红名单
|
|
|
+ List<RedList> redLists = getRedListByObjIds(appIds);
|
|
|
+ Map<String, RedList> redListMap = redLists.stream()
|
|
|
+ .collect(Collectors.toMap(RedList::getObjId, item -> item));
|
|
|
+ //批量获取应用和功能
|
|
|
+ List<ApplyInfo> appInfos = applyInfoFacade.getAppById(appIds);
|
|
|
+ List<AppFunInfo> funInfos = appFunInfoService.getByAppIds(appIds);
|
|
|
+ Map<String, ApplyInfo> appInfoMap = appInfos
|
|
|
+ .stream()
|
|
|
+ .collect(Collectors.toMap(ApplyInfo::getId, item -> item, (old, last) -> last));
|
|
|
+ Map<String, AppFunInfo> funInfoMap = funInfos
|
|
|
+ .stream()
|
|
|
+ .collect(Collectors.toMap(AppFunInfo::getId, item -> item, (old, last) -> last));
|
|
|
+ for (AppFunRedListAddDTO dto : dtos) {
|
|
|
+ //应用是否已经添加过
|
|
|
+ String appId = dto.getAppId();
|
|
|
+ RedList exist = redListMap.get(appId);
|
|
|
+ RedList redList;
|
|
|
+ if(null == exist) {
|
|
|
+ redList = new RedList();
|
|
|
+ redList.setObjId(appId);
|
|
|
+ redList.setObjType(SubObjTypeEnum.OBJ_APP_FUN.getCode());
|
|
|
+ redList.setDeleted(BooleanEnum.FALSE.value);
|
|
|
+ redListRepository.save(redList);
|
|
|
+ } else {
|
|
|
+ redList = exist;
|
|
|
+ }
|
|
|
+ saveFunRedListContent(redList, dto, appInfoMap, funInfoMap);
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<RedList> getRedListByObjIds(List<String> appIds) {
|
|
|
+ if(CollectionUtils.isEmpty(appIds)) {
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+ Specification<RedList> specification = (root, query, criteriaBuilder) -> {
|
|
|
+ Path<String> objId = root.get("objId");
|
|
|
+ CriteriaBuilder.In<String> in = criteriaBuilder.in(objId);
|
|
|
+ appIds.forEach(in::value);
|
|
|
+ return in;
|
|
|
+ };
|
|
|
+ return redListRepository.findAll(specification);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(rollbackFor = RuntimeException.class)
|
|
|
+ @Override
|
|
|
+ public Boolean funRedListUpdateLevel(RedListOperateDTO dto) {
|
|
|
+ List<String> contentIds = dto.getListIds();
|
|
|
+ if(CollectionUtils.isEmpty(contentIds)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ String level = dto.getLevel();
|
|
|
+ contentRepository.updateLevelByIds(level, contentIds);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(rollbackFor = RuntimeException.class)
|
|
|
+ @Override
|
|
|
+ public Boolean funRedListBatchDel(RedListOperateDTO dto) {
|
|
|
+ List<String> contentIds = dto.getListIds();
|
|
|
+ if(CollectionUtils.isEmpty(contentIds)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ //判断哪些应用在客体红名单表中需要删除
|
|
|
+ List<String> delListIds = getDelRedList(contentIds);
|
|
|
+ for (String contentId : contentIds) {
|
|
|
+ contentRepository.deleteById(contentId);
|
|
|
+ }
|
|
|
+ delRedListByIds(delListIds);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 传入需要删除的红名单内容记录id集合
|
|
|
+ * 获取需要删除的红名单id
|
|
|
+ * @param delContentIds 要删除的红名单详细内容id集合
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<String> getDelRedList(List<String> delContentIds) {
|
|
|
+ Searchable searchable = Searchable.newSearchable();
|
|
|
+ searchable.addSearchFilter("id", SearchOperator.in, delContentIds);
|
|
|
+ List<RedListContent> delContentList = contentRepository.findAll(searchable);
|
|
|
+ Map<String, Long> delFunCountMap = delContentList
|
|
|
+ .stream()
|
|
|
+ .collect(Collectors.groupingBy(RedListContent::getRedListId, Collectors.counting()));
|
|
|
+ List<String> listIds = delContentList
|
|
|
+ .stream()
|
|
|
+ .map(RedListContent::getRedListId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ List<FunCountDO> allCountList = contentRepository.getCountByListIds(listIds);
|
|
|
+ return allCountList.stream().filter(item -> {
|
|
|
+ String listId = item.getListId();
|
|
|
+ Long funNum = item.getContentCount();
|
|
|
+ Long count = delFunCountMap.get(listId);
|
|
|
+ if(null == funNum) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return funNum.equals(count);
|
|
|
+ }).map(FunCountDO::getListId).distinct().collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(rollbackFor = RuntimeException.class)
|
|
|
+ @Override
|
|
|
+ public Boolean delRedListByIds(List<String> ids) {
|
|
|
+ if(CollectionUtils.isEmpty(ids)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ for (String id : ids) {
|
|
|
+ redListRepository.deleteById(id);
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(rollbackFor = RuntimeException.class)
|
|
|
+ @Override
|
|
|
+ public Boolean funRedListDel(String resourceType, String resourceId, Boolean isTreeNode) {
|
|
|
+ if(ResourceTypeEnum.TJ_APP.getResourceType().equals(resourceType)) {
|
|
|
+ RedList r = new RedList();
|
|
|
+ r.setObjId(resourceId);
|
|
|
+ Example<RedList> example = Example.of(r);
|
|
|
+ RedList redList = redListRepository.findOne(example).orElse(null);
|
|
|
+ if(null == redList) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ String listId = redList.getId();
|
|
|
+ redListRepository.deleteById(listId);
|
|
|
+ contentRepository.delByRedListId(listId);
|
|
|
+ return true;
|
|
|
+ } else if(ResourceTypeEnum.TJ_APP_MENU.getResourceType().equals(resourceType)) {
|
|
|
+
|
|
|
+ RedListOperateDTO operateDTO = new RedListOperateDTO();
|
|
|
+ List<String> contentIds = new ArrayList<>();
|
|
|
+ if(isTreeNode) {
|
|
|
+ //查询节点下有多少子节点
|
|
|
+ AppFunInfoVo appFunInfoVo = appFunInfoService.getById(resourceId);
|
|
|
+ List<AppFunInfo> funInfos = appFunInfoService.getByAppId(appFunInfoVo.getAppId());
|
|
|
+ Map<String, List<AppFunInfo>> pIdMap = funInfos
|
|
|
+ .stream()
|
|
|
+ .filter(item -> StringUtils.isNotBlank(item.getParentId()))
|
|
|
+ .collect(Collectors.groupingBy(AppFunInfo::getParentId));
|
|
|
+ List<AppFunInfo> delList = new ArrayList<>();
|
|
|
+ AppFunInfo appFunInfoDTO = new AppFunInfo();
|
|
|
+ BeanUtils.copyProperties(appFunInfoVo, appFunInfoDTO);
|
|
|
+ delList.add(appFunInfoDTO);
|
|
|
+ List<String> pIdList = new ArrayList<>();
|
|
|
+ pIdList.add(appFunInfoVo.getCode());
|
|
|
+ getChildFunList(pIdMap, delList, pIdList);
|
|
|
+ //节点下的所有菜单功能id
|
|
|
+ List<String> allFunIds = delList
|
|
|
+ .stream()
|
|
|
+ .map(AppFunInfo::getId)
|
|
|
+ .distinct()
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ //查询需要删除的contentId
|
|
|
+ List<RedListContent> contents = getRedListContentByFunIds(allFunIds);
|
|
|
+ contentIds = contents.stream().map(RedListContent::getId).distinct().collect(Collectors.toList());
|
|
|
+
|
|
|
+ } else {
|
|
|
+ RedListContent redListContent = getRedListContentByFunId(resourceId);
|
|
|
+ if(null == redListContent) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ contentIds.add(redListContent.getId());
|
|
|
+ }
|
|
|
+ //批量删除功能红名单
|
|
|
+ operateDTO.setListIds(contentIds);
|
|
|
+ return funRedListBatchDel(operateDTO);
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Page<FunRedListTreeDTO> funRedListPage(SearchDTO searchDTO) {
|
|
|
+ Searchable searchable = Searchable.toSearchable(searchDTO);
|
|
|
+ Condition appNameCondition = searchable.getSearchFilter("appName", SearchOperator.like);
|
|
|
+ Condition appCodeCondition = searchable.getSearchFilter("appCode", SearchOperator.like);
|
|
|
+ List<ApplyInfo> applyInfos = null;
|
|
|
+ //应用条件查询
|
|
|
+ if(appCodeCondition != null || appNameCondition != null) {
|
|
|
+ applyInfos = getApplyInfos(searchable, appNameCondition, appCodeCondition);
|
|
|
+ if (applyInfos == null) {
|
|
|
+ return new PageImpl<>(new ArrayList<>(), searchable.getPage(), 0L);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Page<RedList> redListPage = redListRepository.paging(searchable);
|
|
|
+ List<RedList> pageContent = redListPage.getContent();
|
|
|
+ if(CollectionUtils.isEmpty(pageContent)) {
|
|
|
+ return new PageImpl<>(new ArrayList<>(), searchable.getPage(), 0L);
|
|
|
+ }
|
|
|
+ //组装成列表树
|
|
|
+ List<FunRedListTreeDTO> treeDTOS = convertRedListToTree(applyInfos, pageContent);
|
|
|
+ return new PageImpl<>(treeDTOS, searchable.getPage(), redListPage.getTotalElements());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<String> funIdsInRedList(String appId) {
|
|
|
+ List<RedListContent> all = contentRepository.findAll();
|
|
|
+ if(StringUtils.isNotBlank(appId)) {
|
|
|
+ all = all.stream()
|
|
|
+ .filter(item->appId.equals(item.getAppId()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ return all.stream().map(RedListContent::getFunId).distinct().collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<AppFunRedListDTO> funRedListContentSearch(Searchable searchable) {
|
|
|
+ List<AppFunRedListDTO> list = new ArrayList<>();
|
|
|
+ List<RedListContent> all = contentRepository.findAll(searchable);
|
|
|
+ if(CollectionUtils.isEmpty(all)) {
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+ List<String> appIds = all
|
|
|
+ .stream()
|
|
|
+ .map(RedListContent::getAppId)
|
|
|
+ .distinct()
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ List<ApplyInfo> applyInfos = applyInfoFacade.getAppById(appIds);
|
|
|
+ List<AppFunInfo> funInfos = appFunInfoService.getByAppIds(appIds);
|
|
|
+ Map<String, ApplyInfo> appIdMap = applyInfos
|
|
|
+ .stream()
|
|
|
+ .collect(Collectors.toMap(ApplyInfo::getId, item -> item));
|
|
|
+ Map<String, AppFunInfo> funIdMap = funInfos
|
|
|
+ .stream()
|
|
|
+ .collect(Collectors.toMap(AppFunInfo::getId, item -> item));
|
|
|
+ for (RedListContent redListContent : all) {
|
|
|
+ String funId = redListContent.getFunId();
|
|
|
+ String appId = redListContent.getAppId();
|
|
|
+ ApplyInfo applyInfo = appIdMap.get(appId);
|
|
|
+ if(null == applyInfo) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ AppFunInfo appFunInfo = funIdMap.get(funId);
|
|
|
+ if(null == appFunInfo) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ AppFunRedListDTO dto = new AppFunRedListDTO();
|
|
|
+ dto.setAppCode(applyInfo.getApplyCode());
|
|
|
+ dto.setAppName(applyInfo.getApplyName());
|
|
|
+ dto.setFunCode(appFunInfo.getCode());
|
|
|
+ dto.setFunName(appFunInfo.getName());
|
|
|
+ dto.setLevel(redListContent.getLevel());
|
|
|
+ list.add(dto);
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 将查询到的功能列表组装成树结构
|
|
|
+ * @param applyInfos
|
|
|
+ * @param pageContent
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<FunRedListTreeDTO> convertRedListToTree(List<ApplyInfo> applyInfos, List<RedList> pageContent) {
|
|
|
+ List<String> appIds = pageContent.stream()
|
|
|
+ .map(RedList::getObjId)
|
|
|
+ .distinct()
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ List<RedListContent> redListContents = getRedListContentByAppIds(appIds);
|
|
|
+ Map<String, List<RedListContent>> listContentMap = redListContents
|
|
|
+ .stream()
|
|
|
+ .collect(Collectors.groupingBy(RedListContent::getAppId));
|
|
|
+ if(null == applyInfos) {
|
|
|
+ applyInfos = applyInfoFacade.getAppById(appIds);
|
|
|
+ }
|
|
|
+ Map<String, ApplyInfo> appInfoMap = applyInfos
|
|
|
+ .stream()
|
|
|
+ .collect(Collectors.toMap(ApplyInfo::getId, item -> item, (old, last) -> last));
|
|
|
+ List<AppFunInfo> funInfos = appFunInfoService.getByAppIds(appIds);
|
|
|
+ Map<String, List<AppFunInfo>> funMap = funInfos
|
|
|
+ .stream()
|
|
|
+ .collect(Collectors.groupingBy(AppFunInfo::getAppId));
|
|
|
+ List<FunRedListTreeDTO> treeDTOS = new ArrayList<>();
|
|
|
+ for (RedList redList : pageContent) {
|
|
|
+ String appId = redList.getObjId();
|
|
|
+ ApplyInfo applyInfo = appInfoMap.get(appId);
|
|
|
+ if(null == applyInfo) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ FunRedListTreeDTO treeDTO = new FunRedListTreeDTO();
|
|
|
+ treeDTO.setId(appId);
|
|
|
+ treeDTO.setCode(applyInfo.getApplyCode());
|
|
|
+ treeDTO.setLabel(applyInfo.getApplyName());
|
|
|
+ treeDTO.setIsTreeNode(true);
|
|
|
+ treeDTO.setListId(redList.getId());
|
|
|
+ List<FunRedListTreeDTO> childTree = getChildTreeDTO(listContentMap.get(appId), funMap.get(appId));
|
|
|
+ childTree.forEach(item->item.setPid(appId));
|
|
|
+ treeDTO.setChild(childTree);
|
|
|
+ treeDTO.setType(ResourceTypeEnum.TJ_APP.getResourceType());
|
|
|
+ treeDTOS.add(treeDTO);
|
|
|
+ }
|
|
|
+ return treeDTOS;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 将红名单中的应用功能菜单组装成树结构
|
|
|
+ * @param contentList 红名单中的功能菜单,只有最底层的功能和菜单
|
|
|
+ * @param funList 应用下的所有功能和菜单
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<FunRedListTreeDTO> getChildTreeDTO(List<RedListContent> contentList, List<AppFunInfo> funList) {
|
|
|
+ List<FunRedListTreeDTO> treeList = new ArrayList<>();
|
|
|
+ if(CollectionUtils.isEmpty(contentList)) {
|
|
|
+ return treeList;
|
|
|
+ }
|
|
|
+ if(CollectionUtils.isEmpty(funList)) {
|
|
|
+ return treeList;
|
|
|
+ }
|
|
|
+ Map<String, AppFunInfo> funCodeMap = funList
|
|
|
+ .stream()
|
|
|
+ .collect(Collectors.toMap(AppFunInfo::getCode, item -> item, (old, last) -> last));
|
|
|
+
|
|
|
+ //红名单中的功能转为树节点对象
|
|
|
+ List<FunRedListTreeDTO> redListTreeNodes = contentList.stream().map(item -> {
|
|
|
+ String funCode = item.getFunCode();
|
|
|
+ AppFunInfo funInfo = funCodeMap.get(funCode);
|
|
|
+ if (null == funInfo) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ FunRedListTreeDTO treeDTO = new FunRedListTreeDTO();
|
|
|
+ treeDTO.setId(item.getFunId());
|
|
|
+ treeDTO.setCode(funCode);
|
|
|
+ treeDTO.setLabel(funInfo.getName());
|
|
|
+ treeDTO.setListId(item.getId());
|
|
|
+ treeDTO.setLevel(item.getLevel());
|
|
|
+ changePid(funCodeMap, funInfo, treeDTO);
|
|
|
+ treeDTO.setType(ResourceTypeEnum.TJ_APP_MENU.getResourceType());
|
|
|
+ return treeDTO;
|
|
|
+ }).filter(item -> !Objects.isNull(item)).collect(Collectors.toList());
|
|
|
+ //组装成树结构
|
|
|
+ treeList = convertNodeToTree(redListTreeNodes);
|
|
|
+ return treeList;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 将节点转为树结构
|
|
|
+ * @param treeNodes
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<FunRedListTreeDTO> convertNodeToTree(List<FunRedListTreeDTO> treeNodes) {
|
|
|
+ Map<Boolean, List<FunRedListTreeDTO>> collect = treeNodes.stream()
|
|
|
+ .collect(Collectors.partitioningBy(item -> StringUtils.isBlank(item.getPid())));
|
|
|
+ List<FunRedListTreeDTO> topNodes = collect.get(Boolean.TRUE);
|
|
|
+ List<FunRedListTreeDTO> underNodes = collect.get(Boolean.FALSE);
|
|
|
+ Map<String, List<FunRedListTreeDTO>> pidMap = underNodes.stream()
|
|
|
+ .collect(Collectors.groupingBy(FunRedListTreeDTO::getPid));
|
|
|
+ innerConvertToTree(topNodes, pidMap);
|
|
|
+ return topNodes;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 递归将子节点转为树结构
|
|
|
+ * @param topNodes
|
|
|
+ * @param pidMap
|
|
|
+ */
|
|
|
+ private void innerConvertToTree(List<FunRedListTreeDTO> topNodes, Map<String, List<FunRedListTreeDTO>> pidMap) {
|
|
|
+ for (FunRedListTreeDTO topNode : topNodes) {
|
|
|
+ String topNodeId = topNode.getId();
|
|
|
+ List<FunRedListTreeDTO> childList = pidMap.get(topNodeId);
|
|
|
+ if(CollectionUtils.isNotEmpty(childList)) {
|
|
|
+ innerConvertToTree(childList, pidMap);
|
|
|
+ topNode.setChild(childList);
|
|
|
+ topNode.setIsTreeNode(true);
|
|
|
+ }else {
|
|
|
+ topNode.setIsTreeNode(false);
|
|
|
+ //前端要求放入空集合,不能是null
|
|
|
+ topNode.setChild(new ArrayList<>());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void changePid(Map<String, AppFunInfo> funCodeMap, AppFunInfo funInfo, FunRedListTreeDTO treeDTO) {
|
|
|
+ String parentId = funInfo.getParentId();
|
|
|
+ if (StringUtils.isNotBlank(parentId)) {
|
|
|
+ AppFunInfo parentFun = funCodeMap.get(parentId);
|
|
|
+ if (null != parentFun) {
|
|
|
+ treeDTO.setPid(parentFun.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private List<ApplyInfo> getApplyInfos(Searchable searchable, Condition appNameCondition, Condition appCodeCondition) {
|
|
|
+ Searchable appSearch = Searchable.newSearchable();
|
|
|
+ if(appCodeCondition != null) {
|
|
|
+ appSearch.addSearchFilter("apply_code", SearchOperator.like, appNameCondition.getValue().toString());
|
|
|
+ searchable.removeSearchFilter("appCode", SearchOperator.like);
|
|
|
+ }
|
|
|
+ if(appNameCondition != null) {
|
|
|
+ appSearch.addSearchFilter("apply_name", SearchOperator.like, appNameCondition.getValue().toString());
|
|
|
+ searchable.removeSearchFilter("appName", SearchOperator.like);
|
|
|
+ }
|
|
|
+ List<ApplyInfo> applyInfos = applyInfoFacade.appInfoSearch(appSearch.toSearchDTO());
|
|
|
+ if(CollectionUtils.isEmpty(applyInfos)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ List<String> appIds = applyInfos
|
|
|
+ .stream()
|
|
|
+ .map(ApplyInfo::getId)
|
|
|
+ .distinct()
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ searchable.addSearchFilter("objId", SearchOperator.in, appIds);
|
|
|
+ return applyInfos;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据功能id获取记录
|
|
|
+ * @param funId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private RedListContent getRedListContentByFunId(String funId) {
|
|
|
+ RedListContent redListContent = new RedListContent();
|
|
|
+ redListContent.setFunId(funId);
|
|
|
+ Example<RedListContent> ex = Example.of(redListContent);
|
|
|
+ return contentRepository.findOne(ex).orElse(null);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量
|
|
|
+ * 根据功能id获取记录
|
|
|
+ * @param funIds
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<RedListContent> getRedListContentByFunIds(List<String> funIds) {
|
|
|
+ Searchable searchable = Searchable.newSearchable();
|
|
|
+ searchable.addSearchFilter("funId", SearchOperator.in, funIds);
|
|
|
+ searchable.addSearchFilter("deleted", SearchOperator.eq, BooleanEnum.FALSE.value);
|
|
|
+ List<RedListContent> list = contentRepository.findAll(searchable);
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量
|
|
|
+ * 根据应用id获取记录
|
|
|
+ * @param appIds
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<RedListContent> getRedListContentByAppIds(List<String> appIds) {
|
|
|
+ Searchable searchable = Searchable.newSearchable();
|
|
|
+ searchable.addSearchFilter("appId", SearchOperator.in, appIds);
|
|
|
+ List<RedListContent> list = contentRepository.findAll(searchable);
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 将pIdList下所有子节点功能放入nodeList
|
|
|
+ * @param pIdMap 以pid分组的map
|
|
|
+ * @param nodeList
|
|
|
+ * @param pIdList
|
|
|
+ */
|
|
|
+ private void getChildFunList(Map<String, List<AppFunInfo>> pIdMap, List<AppFunInfo> nodeList, List<String> pIdList) {
|
|
|
+ ArrayList<String> childIdList = new ArrayList<>();
|
|
|
+ for (String pid : pIdList) {
|
|
|
+ List<AppFunInfo> childList = pIdMap.get(pid);
|
|
|
+ if(CollectionUtils.isNotEmpty(childList)) {
|
|
|
+ nodeList.addAll(childList);
|
|
|
+ List<String> collect = childList.stream().map(AppFunInfo::getCode).distinct().collect(Collectors.toList());
|
|
|
+ childIdList.addAll(collect);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(CollectionUtils.isNotEmpty(childIdList)) {
|
|
|
+ getChildFunList(pIdMap, nodeList, childIdList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存菜单功能红名单详细内容
|
|
|
+ * @param redList
|
|
|
+ * @param dto
|
|
|
+ * @param appInfoMap
|
|
|
+ * @param funInfoMap
|
|
|
+ */
|
|
|
+ private void saveFunRedListContent(RedList redList, AppFunRedListAddDTO dto,
|
|
|
+ Map<String, ApplyInfo> appInfoMap,
|
|
|
+ Map<String, AppFunInfo> funInfoMap) {
|
|
|
+ String listId = redList.getId();
|
|
|
+ //查询已经存在的功能和菜单
|
|
|
+ List<RedListContent> existContent = getRedListContentByRedListId(listId);
|
|
|
+ Set<String> existFunIds = existContent
|
|
|
+ .stream()
|
|
|
+ .map(RedListContent::getFunId)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+ for (String funId : dto.getFunIds()) {
|
|
|
+ //已添加的菜单不更新也不保存
|
|
|
+ if(existFunIds.contains(funId)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ AppFunInfo appFunInfo = funInfoMap.get(funId);
|
|
|
+ if(null == appFunInfo) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ String appId = appFunInfo.getAppId();
|
|
|
+ ApplyInfo applyInfo = appInfoMap.get(appId);
|
|
|
+ if(null == applyInfo) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ RedListContent redListContent = new RedListContent();
|
|
|
+ redListContent.setRedListId(listId);
|
|
|
+ redListContent.setAppId(appId);
|
|
|
+ redListContent.setAppCode(applyInfo.getApplyCode());
|
|
|
+ redListContent.setFunId(funId);
|
|
|
+ redListContent.setFunCode(appFunInfo.getCode());
|
|
|
+ redListContent.setLevel(dto.getLevel());
|
|
|
+ redListContent.setDeleted(BooleanEnum.FALSE.value);
|
|
|
+ redListContent.setContentType(redList.getObjType());
|
|
|
+ contentRepository.save(redListContent);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<RedListContent> getRedListContentByRedListId(String listId) {
|
|
|
+ RedListContent redListContent = new RedListContent();
|
|
|
+ redListContent.setRedListId(listId);
|
|
|
+ Example<RedListContent> example = Example.of(redListContent);
|
|
|
+ return contentRepository.findAll(example);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|