优化queryDictionary接口

topo_dev
xueqingkun 10 months ago
parent c54c2fc3e0
commit 9d4fba4221

@ -1,5 +1,6 @@
package com.supervision.police.service.impl; package com.supervision.police.service.impl;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
@ -68,30 +69,33 @@ public class ComDictionaryServiceImpl extends ServiceImpl<ComDictionaryMapper, C
*/ */
private Map<String, List<ComDictionary>> queryDictionary(DictionaryByTypeParam dictionaryByTypeParam) { private Map<String, List<ComDictionary>> queryDictionary(DictionaryByTypeParam dictionaryByTypeParam) {
Map<String,List<ComDictionary>> resultMap = new HashMap<>(); Map<String,List<ComDictionary>> resultMap = new HashMap<>();
List<String> typeList = new ArrayList<>();
if (dictionaryByTypeParam.getList() == null || dictionaryByTypeParam.getList().size() <=0) { List<String> typeList = CollUtil.isEmpty(dictionaryByTypeParam.getList()) ?
typeList = comDictionaryMapper.queryAllType(); comDictionaryMapper.queryAllType() : dictionaryByTypeParam.getList();
} else {
typeList = dictionaryByTypeParam.getList();
}
for (String dictType : typeList) { for (String dictType : typeList) {
List<ComDictionary> queryList = new ArrayList<>(); List<ComDictionary> queryList;
List<ComDictionary> otherList = new ArrayList<>(); List<ComDictionary> otherList = new ArrayList<>();
ComDictionary comDictionary = new ComDictionary(); ComDictionary comDictionary = new ComDictionary();
comDictionary.setType(dictType); comDictionary.setType(dictType);
Wrapper<ComDictionary> wrapper = Wrappers.query(comDictionary); Wrapper<ComDictionary> wrapper = Wrappers.query(comDictionary);
queryList = this.comDictionaryMapper.selectList(wrapper); queryList = this.comDictionaryMapper.selectList(wrapper);
changeTree(queryList,otherList); changeTree(queryList,otherList);
if (otherList.size() > 1) {
if (dictionaryByTypeParam.getIsTree() != null && dictionaryByTypeParam.getIsTree() == 0) { if (CollUtil.size(otherList) > 1) {
// 平铺数据
if (Integer.valueOf(0).equals(dictionaryByTypeParam.getIsTree())) {
resultMap.put(dictType,queryList); resultMap.put(dictType,queryList);
}else { }else {
// 树形数据
resultMap.put(dictType,otherList); resultMap.put(dictType,otherList);
} }
} else { } else {
if (dictionaryByTypeParam.getIsTree() != null && dictionaryByTypeParam.getIsTree() == 0){ // 平铺数据
if (Integer.valueOf(0).equals(dictionaryByTypeParam.getIsTree())){
resultMap.put(dictType,otherList.get(0).getChild()); resultMap.put(dictType,otherList.get(0).getChild());
}else { }else {
// 树形数据
resultMap.put(dictType,otherList); resultMap.put(dictType,otherList);
} }
} }
@ -129,7 +133,7 @@ public class ComDictionaryServiceImpl extends ServiceImpl<ComDictionaryMapper, C
// 先找到所有的一级菜单 // 先找到所有的一级菜单
for (ComDictionary comDictionary : queryList) { for (ComDictionary comDictionary : queryList) {
// 一级菜单没有parentId // 一级菜单没有parentId
if (comDictionary.getPid() == null || comDictionary.getPid() == 0l) { if (Long.valueOf(0L).equals(comDictionary.getPid())) {
resultList.add(comDictionary); resultList.add(comDictionary);
} }
} }

Loading…
Cancel
Save