This commit is contained in:
zhangchenbiao
2023-06-29 10:27:33 +08:00
parent 21ed32a2b4
commit 573d60e97e
2 changed files with 16 additions and 1 deletions

View File

@@ -5,6 +5,7 @@ import com.google.common.collect.Lists;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import java.util.ArrayList;
@@ -21,6 +22,7 @@ import java.util.stream.Collectors;
*/
@Data
@ApiModel
@Slf4j
public class OpenAreaTreeVO {
@@ -48,6 +50,7 @@ public class OpenAreaTreeVO {
public static List<OpenAreaTreeVO> convertTree(List<HyOpenAreaInfoDO> allOpenArea, String keyword){
long startTime = System.currentTimeMillis();
List<HyOpenAreaInfoDO> firstArea = allOpenArea.stream().filter(o -> Objects.isNull(o.getParentId())).collect(Collectors.toList());
Map<Long, List<HyOpenAreaInfoDO>> openAreaParentMap = allOpenArea.stream().filter(o->Objects.nonNull(o.getParentId())).collect(Collectors.groupingBy(k -> k.getParentId()));
List<OpenAreaTreeVO> allTree = new ArrayList<>();
@@ -57,6 +60,7 @@ public class OpenAreaTreeVO {
node.setChildNode(childList);
allTree.add(node);
}
log.info("1#耗时:{}", System.currentTimeMillis() - startTime);
Map<Long, List<OpenAreaTreeVO>> childMap = allTree.stream().collect(Collectors.toMap(k -> k.getId(), v -> v.getChildNode()));
List<HyOpenAreaInfoDO> filterList = allOpenArea.stream().filter(o -> o.getAreaPath().contains(keyword)).collect(Collectors.toList());
Map<Long, HyOpenAreaInfoDO> openAreaMap = allOpenArea.stream().collect(Collectors.toMap(k -> k.getId(), Function.identity()));
@@ -72,6 +76,7 @@ public class OpenAreaTreeVO {
list.add(openAreaInfo);
}
}
log.info("2#耗时:{}", System.currentTimeMillis() - startTime);
List<OpenAreaTreeVO> resultList = new ArrayList<>();
List<HyOpenAreaInfoDO> filterFirstArea = list.stream().filter(o -> Objects.isNull(o.getParentId())).distinct().collect(Collectors.toList());
Map<Long, List<HyOpenAreaInfoDO>> filterOpenAreaParentMap = list.stream().filter(Objects::nonNull).filter(o->Objects.nonNull(o.getParentId())).collect(Collectors.groupingBy(k -> k.getParentId()));
@@ -84,6 +89,7 @@ public class OpenAreaTreeVO {
node.setChildNode(childList);
resultList.add(node);
}
log.info("2#耗时:{}", System.currentTimeMillis() - startTime);
return resultList;
}

View File

@@ -13,6 +13,7 @@ import com.cool.store.vo.OpenAreaVO;
import com.cool.store.vo.OpenProvinceVO;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
@@ -27,6 +28,7 @@ import java.util.stream.Collectors;
* @Date 2023/6/13 22:11
* @Version 1.0
*/
@Slf4j
@Service
public class OpenAreaServiceImpl implements OpenAreaService {
@@ -64,13 +66,15 @@ public class OpenAreaServiceImpl implements OpenAreaService {
@Override
public List<OpenAreaTreeVO> queryAllOpenAreaByKeyword(String keyword,Boolean applyFlag, Boolean flag) {
long startTime = System.currentTimeMillis();
//先查出所有的一级菜单
List<HyOpenAreaInfoDO> openArea = hyOpenAreaInfoDAO.queryFirstLevel();
log.info("11耗时{}", System.currentTimeMillis() - startTime);
Map<Long, HyOpenAreaInfoDO> longHyOpenAreaInfoDOMap = openArea.stream().collect(Collectors.toMap(HyOpenAreaInfoDO::getId, x -> x));
//查询关键字下所有的数据 原始的数据
List<HyOpenAreaInfoDO> hyOpenAreaInfoDOS = hyOpenAreaInfoDAO.queryByKeyword(keyword,applyFlag,null,flag);
log.info("22耗时{}", System.currentTimeMillis() - startTime);
Map<Long, HyOpenAreaInfoDO> hyMap = hyOpenAreaInfoDOS.stream().collect(Collectors.toMap(HyOpenAreaInfoDO::getId, x -> x));
Set list = new HashSet();
@@ -82,6 +86,7 @@ public class OpenAreaServiceImpl implements OpenAreaService {
list.add(x.getParentId());
}
});
log.info("33耗时{}", System.currentTimeMillis() - startTime);
if (CollectionUtils.isNotEmpty(list)){
//二级采单
List<HyOpenAreaInfoDO> hyOpenAreaInfoDOList = hyOpenAreaInfoDAO.queryByIdsExcludeFirstLevel(new ArrayList<>(list));
@@ -104,15 +109,19 @@ public class OpenAreaServiceImpl implements OpenAreaService {
}
});
}
log.info("44耗时{}", System.currentTimeMillis() - startTime);
JSONArray objects = buildTree(JSONArray.parseArray(JSONObject.toJSONString(hyOpenAreaInfoDOS)), "id", "parentId","childNode" );
List<OpenAreaTreeVO> openAreaTreeVOS = JSONObject.parseArray(objects.toJSONString(), OpenAreaTreeVO.class);
log.info("55耗时{}", System.currentTimeMillis() - startTime);
return openAreaTreeVOS;
}
@Override
public List<OpenAreaTreeVO> searchOpenArea(String keyword,Boolean applyFlag, Boolean flag) {
long startTime = System.currentTimeMillis();
//先查出所有的一级菜单
List<HyOpenAreaInfoDO> allOpenArea = hyOpenAreaInfoDAO.getAllOpenArea();
log.info("11耗时{}", System.currentTimeMillis() - startTime);
return OpenAreaTreeVO.convertTree(allOpenArea, keyword);
}