|
@@ -1,22 +1,29 @@
|
|
package com.citu.module.menduner.system.service.tag;
|
|
package com.citu.module.menduner.system.service.tag;
|
|
|
|
|
|
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
|
+import com.citu.framework.common.pojo.PageResult;
|
|
|
|
+import com.citu.framework.common.util.object.BeanUtils;
|
|
|
|
+import com.citu.module.menduner.system.controller.app.industry.vo.AppIndustryChildrenRespVO;
|
|
|
|
+import com.citu.module.menduner.system.controller.base.tag.TagChildrenRespVO;
|
|
import com.citu.module.menduner.system.controller.base.tag.TagPageReqVO;
|
|
import com.citu.module.menduner.system.controller.base.tag.TagPageReqVO;
|
|
import com.citu.module.menduner.system.controller.base.tag.TagSaveReqVO;
|
|
import com.citu.module.menduner.system.controller.base.tag.TagSaveReqVO;
|
|
|
|
+import com.citu.module.menduner.system.convert.IndustryConvert;
|
|
|
|
+import com.citu.module.menduner.system.convert.TagConvert;
|
|
|
|
+import com.citu.module.menduner.system.dal.dataobject.tag.TagDO;
|
|
|
|
+import com.citu.module.menduner.system.dal.mysql.tag.TagMapper;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
-import javax.annotation.Resource;
|
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
import org.springframework.validation.annotation.Validated;
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
-import com.citu.module.menduner.system.dal.dataobject.tag.TagDO;
|
|
|
|
-import com.citu.framework.common.pojo.PageResult;
|
|
|
|
-import com.citu.framework.common.pojo.PageParam;
|
|
|
|
-import com.citu.framework.common.util.object.BeanUtils;
|
|
|
|
-
|
|
|
|
-import com.citu.module.menduner.system.dal.mysql.tag.TagMapper;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
|
+import java.util.Collections;
|
|
|
|
+import java.util.Comparator;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Objects;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
import static com.citu.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
import static com.citu.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
-import static com.citu.module.menduner.system.enums.ErrorCodeConstants.*;
|
|
|
|
|
|
+import static com.citu.module.menduner.system.enums.ErrorCodeConstants.TAG_NOT_EXISTS;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 标签管理 Service 实现类
|
|
* 标签管理 Service 实现类
|
|
@@ -72,4 +79,44 @@ public class TagServiceImpl implements TagService {
|
|
return tagMapper.selectPage(pageReqVO);
|
|
return tagMapper.selectPage(pageReqVO);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public List<TagChildrenRespVO> getTagByType(String type) {
|
|
|
|
+ List<TagDO> list = tagMapper.selectListByType(type);
|
|
|
|
+ if (CollUtil.isEmpty(list)) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ List<TagChildrenRespVO> convertList = TagConvert.INSTANCE.convertList(list);
|
|
|
|
+ List<TagChildrenRespVO> convertListSort = convertList.stream()
|
|
|
|
+ .sorted(Comparator.comparing(TagChildrenRespVO::getLevel))
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+
|
|
|
|
+ List<TagChildrenRespVO> rootList = convertListSort.stream()
|
|
|
|
+ .filter(root -> root.getParentId() == 0)
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+
|
|
|
|
+ return rootList.stream().peek(root -> {
|
|
|
|
+ root.setPath(String.valueOf(root.getId()));
|
|
|
|
+ root.setChildren(getChildren(root, convertListSort));
|
|
|
|
+ }).collect(Collectors.toList());
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 递归查询子节点
|
|
|
|
+ *
|
|
|
|
+ * @param root 根节点
|
|
|
|
+ * @param all 所有节点
|
|
|
|
+ * @return 根节点信息
|
|
|
|
+ */
|
|
|
|
+ private List<TagChildrenRespVO> getChildren(TagChildrenRespVO root, List<TagChildrenRespVO> all) {
|
|
|
|
+ return all.stream()
|
|
|
|
+ .filter(child -> Objects.equals(child.getParentId(), root.getId()))
|
|
|
|
+ .map(child -> {
|
|
|
|
+ child.setPath(root.getPath() + "," + child.getId());
|
|
|
|
+ child.setChildren(getChildren(child, all));
|
|
|
|
+ return child;
|
|
|
|
+ })
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+ }
|
|
}
|
|
}
|