|
@@ -1,14 +1,22 @@
|
|
|
package com.ims.eval.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.ims.common.utils.StringUtils;
|
|
|
+import com.ims.eval.entity.OrganizationEvaluationRule;
|
|
|
import com.ims.eval.entity.OrganizationStructure;
|
|
|
import com.ims.eval.dao.OrganizationStructureMapper;
|
|
|
import com.ims.eval.service.IOrganizationStructureService;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
|
|
|
* <p>
|
|
|
- * 服务实现类
|
|
|
+ * 服务实现类
|
|
|
* </p>
|
|
|
*
|
|
|
* @author wang
|
|
@@ -17,4 +25,86 @@ import org.springframework.stereotype.Service;
|
|
|
@Service
|
|
|
public class OrganizationStructureServiceImpl extends ServiceImpl<OrganizationStructureMapper, OrganizationStructure> implements IOrganizationStructureService {
|
|
|
|
|
|
+ private static Integer length = 0;
|
|
|
+
|
|
|
+ private static String type = null;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<OrganizationStructure> getTree(String id, Integer num, String type1) {
|
|
|
+
|
|
|
+ if (null != type1 && type1.length()>0){
|
|
|
+ type = type1;
|
|
|
+ }
|
|
|
+
|
|
|
+ QueryWrapper<OrganizationStructure> qw = new QueryWrapper<>();
|
|
|
+
|
|
|
+ List<OrganizationStructure> list = baseMapper.selectList(qw);
|
|
|
+ List<OrganizationStructure> tr = convert(list, id, num);
|
|
|
+ return tr;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 转换为有树形结构的列表
|
|
|
+ *
|
|
|
+ * @param source 源数据所有数据
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<OrganizationStructure> convert(List<OrganizationStructure> source, String id, Integer num) {
|
|
|
+ if (CollectionUtil.isEmpty(source)) {
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+ List<OrganizationStructure> result = new ArrayList<>();
|
|
|
+ List<String> idList = new ArrayList<>();
|
|
|
+ if (null == id || id.length() <= 0) {
|
|
|
+ idList = source.stream().map(OrganizationStructure::getId).collect(Collectors.toList());
|
|
|
+
|
|
|
+ for (OrganizationStructure domainTreeSelectVO : source) {
|
|
|
+
|
|
|
+ if (!idList.contains(domainTreeSelectVO.getParentId())) {
|
|
|
+
|
|
|
+ result.add(domainTreeSelectVO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+
|
|
|
+ result.add(this.baseMapper.selectById(id));
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ for (OrganizationStructure domainTreeSelectVO : result) {
|
|
|
+
|
|
|
+ length = num + domainTreeSelectVO.getParentIds().split(",").length;
|
|
|
+ getChildren(source, domainTreeSelectVO);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ * 循环设置子级
|
|
|
+ *
|
|
|
+ * @param list 所有元素列表
|
|
|
+ * @param treeSelectVO 父级元素
|
|
|
+ * @return 父级元素
|
|
|
+ */
|
|
|
+ public static OrganizationStructure getChildren(List<OrganizationStructure> list, OrganizationStructure treeSelectVO) {
|
|
|
+
|
|
|
+ for (OrganizationStructure domainTreeSelectVO : list) {
|
|
|
+ if (treeSelectVO.getId().equals(domainTreeSelectVO.getParentId())) {
|
|
|
+ List<OrganizationStructure> children = CollectionUtil.isEmpty(treeSelectVO.getChildren()) ? new ArrayList<>() : treeSelectVO.getChildren();
|
|
|
+ if (null != type && !type.equals(domainTreeSelectVO.getType())) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (null != length && length < domainTreeSelectVO.getParentIds().split(",").length) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ children.add(getChildren(list, domainTreeSelectVO));
|
|
|
+ treeSelectVO.setChildren(children);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return treeSelectVO;
|
|
|
+ }
|
|
|
}
|