|
@@ -1,11 +1,16 @@
|
|
package com.ims.eval.service.impl;
|
|
package com.ims.eval.service.impl;
|
|
|
|
|
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
import com.ims.eval.entity.MultipleBrand;
|
|
import com.ims.eval.entity.MultipleBrand;
|
|
import com.ims.eval.dao.MultipleBrandMapper;
|
|
import com.ims.eval.dao.MultipleBrandMapper;
|
|
import com.ims.eval.service.IMultipleBrandService;
|
|
import com.ims.eval.service.IMultipleBrandService;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* <p>
|
|
* <p>
|
|
* 服务实现类
|
|
* 服务实现类
|
|
@@ -17,4 +22,66 @@ import org.springframework.stereotype.Service;
|
|
@Service
|
|
@Service
|
|
public class MultipleBrandServiceImpl extends ServiceImpl<MultipleBrandMapper, MultipleBrand> implements IMultipleBrandService {
|
|
public class MultipleBrandServiceImpl extends ServiceImpl<MultipleBrandMapper, MultipleBrand> implements IMultipleBrandService {
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public List<MultipleBrand> getMultipleBranTree(String id, String parentId) {
|
|
|
|
+ List<MultipleBrand> list = baseMapper.selectMultipleBranTree(id,parentId);
|
|
|
|
+ List<MultipleBrand> tree = convert(list);
|
|
|
|
+ return tree;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public List<MultipleBrand> getMultipleBranList(String id, String parentId) {
|
|
|
|
+ List<MultipleBrand> list = baseMapper.selectMultipleBranList(id,parentId);
|
|
|
|
+ return list;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 转换为有树形结构的列表
|
|
|
|
+ *
|
|
|
|
+ * @param brands 源数据所有数据
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public List<MultipleBrand> convert(List<MultipleBrand> brands) {
|
|
|
|
+ if (CollectionUtil.isEmpty(brands)) {
|
|
|
|
+ return new ArrayList<>();
|
|
|
|
+ }
|
|
|
|
+ List<MultipleBrand> result = new ArrayList<>();
|
|
|
|
+ List<String> idList = brands.stream().map(MultipleBrand::getId).collect(Collectors.toList());
|
|
|
|
+ // 设置最外层顶级
|
|
|
|
+ for (MultipleBrand brandsVO : brands) {
|
|
|
|
+ // 判断所有列表里面父级未在集合中放置到一级
|
|
|
|
+ if (!idList.contains(brandsVO.getParentId())) {
|
|
|
|
+ result.add(brandsVO);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ for (MultipleBrand brandsVO : result) {
|
|
|
|
+ // 循环一级之后子级
|
|
|
|
+ getChildren(brands, brandsVO);
|
|
|
|
+ }
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 循环设置子级
|
|
|
|
+ *
|
|
|
|
+ * @param list 所有元素列表
|
|
|
|
+ * @param treeSelectVO 父级元素
|
|
|
|
+ * @return 父级元素
|
|
|
|
+ */
|
|
|
|
+ public static MultipleBrand getChildren(List<MultipleBrand> list, MultipleBrand treeSelectVO) {
|
|
|
|
+ for (MultipleBrand MultipleBrand : list) {
|
|
|
|
+ if (treeSelectVO.getId().equals(MultipleBrand.getParentId())) {
|
|
|
|
+ List<MultipleBrand> children = CollectionUtil.isEmpty(treeSelectVO.getChildren()) ? new ArrayList<>() : treeSelectVO.getChildren();
|
|
|
|
+ children.add(getChildren(list, MultipleBrand));
|
|
|
|
+ treeSelectVO.setChildren(children);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return treeSelectVO;
|
|
|
|
+ }
|
|
}
|
|
}
|