|
@@ -1,15 +1,20 @@
|
|
package com.ims.eval.service.impl;
|
|
package com.ims.eval.service.impl;
|
|
|
|
|
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
+import com.ims.eval.cache.CacheContext;
|
|
import com.ims.eval.config.CustomException;
|
|
import com.ims.eval.config.CustomException;
|
|
import com.ims.eval.entity.BinSection;
|
|
import com.ims.eval.entity.BinSection;
|
|
import com.ims.eval.dao.BinSectionMapper;
|
|
import com.ims.eval.dao.BinSectionMapper;
|
|
import com.ims.eval.service.IBinSectionService;
|
|
import com.ims.eval.service.IBinSectionService;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
/**
|
|
* <p>
|
|
* <p>
|
|
@@ -22,17 +27,18 @@ import java.util.List;
|
|
@Service
|
|
@Service
|
|
public class BinSectionServiceImpl extends ServiceImpl<BinSectionMapper, BinSection> implements IBinSectionService {
|
|
public class BinSectionServiceImpl extends ServiceImpl<BinSectionMapper, BinSection> implements IBinSectionService {
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private CacheContext cache;
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public List<BinSection> list(String id, String sectionName, String sectionCode) {
|
|
public List<BinSection> list(String id, String sectionName, String sectionCode) {
|
|
|
|
|
|
- QueryWrapper<BinSection> qw = new QueryWrapper();
|
|
|
|
- qw.lambda().eq(BinSection::getId, id);
|
|
|
|
- qw.lambda().like(BinSection::getSectionName, sectionName);
|
|
|
|
- qw.lambda().eq(BinSection::getSectionCode, sectionCode);
|
|
|
|
- qw.lambda().orderByAsc(BinSection::getOrderNum);
|
|
|
|
- List<BinSection> list = baseMapper.selectList(qw);
|
|
|
|
|
|
+ List<BinSection> list =CacheContext.bsnList;
|
|
|
|
+ List<BinSection> treeList = convert(list);
|
|
|
|
|
|
- return list;
|
|
|
|
|
|
+ return treeList;
|
|
}
|
|
}
|
|
|
|
|
|
@Transactional
|
|
@Transactional
|
|
@@ -60,4 +66,53 @@ public class BinSectionServiceImpl extends ServiceImpl<BinSectionMapper, BinSect
|
|
return super.saveOrUpdate(entity);
|
|
return super.saveOrUpdate(entity);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 转换为有树形结构的列表
|
|
|
|
+ *
|
|
|
|
+ * @param source 源数据所有数据
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public List<BinSection> convert(List<BinSection> source) {
|
|
|
|
+ if (CollectionUtil.isEmpty(source)) {
|
|
|
|
+ return new ArrayList<>();
|
|
|
|
+ }
|
|
|
|
+ List<BinSection> result = new ArrayList<>();
|
|
|
|
+ List<String> idList = source.stream().map(BinSection::getId).collect(Collectors.toList());
|
|
|
|
+ // 设置最外层顶级
|
|
|
|
+ for (BinSection menuVO : source) {
|
|
|
|
+ // 判断所有列表里面父级未在集合中放置到一级
|
|
|
|
+ if (!idList.contains(menuVO.getParentId())) {
|
|
|
|
+ result.add(menuVO);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ for (BinSection menuVO : result) {
|
|
|
|
+ // 循环一级之后子级
|
|
|
|
+ getChildren(source, menuVO);
|
|
|
|
+ }
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 循环设置子级
|
|
|
|
+ *
|
|
|
|
+ * @param list 所有元素列表
|
|
|
|
+ * @param treeSelectVO 父级元素
|
|
|
|
+ * @return 父级元素
|
|
|
|
+ */
|
|
|
|
+ public static BinSection getChildren(List<BinSection> list, BinSection treeSelectVO) {
|
|
|
|
+ for (BinSection section : list) {
|
|
|
|
+ if (treeSelectVO.getId().equals(section.getParentId())) {
|
|
|
|
+ List<BinSection> children = CollectionUtil.isEmpty(treeSelectVO.getChildren()) ? new ArrayList<>() : treeSelectVO.getChildren();
|
|
|
|
+ children.add(getChildren(list, section));
|
|
|
|
+ treeSelectVO.setChildren(children);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return treeSelectVO;
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|