From 9d4fba422129894d6aafeff1702f6e2b9ebeb4b3 Mon Sep 17 00:00:00 2001 From: xueqingkun Date: Tue, 16 Jul 2024 10:44:15 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96queryDictionary=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/ComDictionaryServiceImpl.java | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/supervision/police/service/impl/ComDictionaryServiceImpl.java b/src/main/java/com/supervision/police/service/impl/ComDictionaryServiceImpl.java index fe38919..e67a7b8 100644 --- a/src/main/java/com/supervision/police/service/impl/ComDictionaryServiceImpl.java +++ b/src/main/java/com/supervision/police/service/impl/ComDictionaryServiceImpl.java @@ -1,5 +1,6 @@ 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.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; @@ -68,30 +69,33 @@ public class ComDictionaryServiceImpl extends ServiceImpl> queryDictionary(DictionaryByTypeParam dictionaryByTypeParam) { Map> resultMap = new HashMap<>(); - List typeList = new ArrayList<>(); - if (dictionaryByTypeParam.getList() == null || dictionaryByTypeParam.getList().size() <=0) { - typeList = comDictionaryMapper.queryAllType(); - } else { - typeList = dictionaryByTypeParam.getList(); - } + + List typeList = CollUtil.isEmpty(dictionaryByTypeParam.getList()) ? + comDictionaryMapper.queryAllType() : dictionaryByTypeParam.getList(); + for (String dictType : typeList) { - List queryList = new ArrayList<>(); + List queryList; List otherList = new ArrayList<>(); ComDictionary comDictionary = new ComDictionary(); comDictionary.setType(dictType); Wrapper wrapper = Wrappers.query(comDictionary); queryList = this.comDictionaryMapper.selectList(wrapper); 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); }else { + // 树形数据 resultMap.put(dictType,otherList); } } else { - if (dictionaryByTypeParam.getIsTree() != null && dictionaryByTypeParam.getIsTree() == 0){ + // 平铺数据 + if (Integer.valueOf(0).equals(dictionaryByTypeParam.getIsTree())){ resultMap.put(dictType,otherList.get(0).getChild()); }else { + // 树形数据 resultMap.put(dictType,otherList); } } @@ -129,7 +133,7 @@ public class ComDictionaryServiceImpl extends ServiceImpl