|
|
@ -17,29 +17,33 @@ |
|
|
|
|
|
|
|
package com.elink.esua.epdc.modules.suggestion.service.impl; |
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil; |
|
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
import com.elink.esua.epdc.commons.mybatis.service.impl.BaseServiceImpl; |
|
|
|
import com.elink.esua.epdc.commons.tools.constant.Constant; |
|
|
|
import com.elink.esua.epdc.commons.tools.constant.FieldConstant; |
|
|
|
import com.elink.esua.epdc.commons.tools.constant.NumConstant; |
|
|
|
import com.elink.esua.epdc.commons.tools.page.PageData; |
|
|
|
import com.elink.esua.epdc.commons.tools.utils.ConvertUtils; |
|
|
|
import com.elink.esua.epdc.commons.tools.constant.FieldConstant; |
|
|
|
import com.elink.esua.epdc.commons.tools.utils.Result; |
|
|
|
import com.elink.esua.epdc.commons.tools.utils.TreeUtils; |
|
|
|
import com.elink.esua.epdc.dto.DeptOption; |
|
|
|
import com.elink.esua.epdc.dto.TypeNode; |
|
|
|
import com.elink.esua.epdc.dto.suggestion.SuggestionTypeDTO; |
|
|
|
import com.elink.esua.epdc.modules.suggestion.dao.SuggestionTypeDao; |
|
|
|
import com.elink.esua.epdc.modules.suggestion.entity.SuggestionTypeEntity; |
|
|
|
import com.elink.esua.epdc.modules.suggestion.redis.SuggestionTypeRedis; |
|
|
|
import com.elink.esua.epdc.modules.suggestion.service.SuggestionTypeService; |
|
|
|
import com.google.common.collect.Lists; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
/** |
|
|
@ -65,8 +69,9 @@ public class SuggestionTypeServiceImpl extends BaseServiceImpl<SuggestionTypeDao |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<SuggestionTypeDTO> list(Map<String, Object> params) { |
|
|
|
// List<SuggestionTypeDTO> result = baseDao.getList(params);
|
|
|
|
return null;//TreeUtils.build(result);
|
|
|
|
List<SuggestionTypeDTO> dtos = baseDao.getList(params); |
|
|
|
|
|
|
|
return TreeUtils.build(dtos); |
|
|
|
} |
|
|
|
|
|
|
|
private QueryWrapper<SuggestionTypeEntity> getWrapper(Map<String, Object> params){ |
|
|
@ -80,14 +85,14 @@ public class SuggestionTypeServiceImpl extends BaseServiceImpl<SuggestionTypeDao |
|
|
|
|
|
|
|
@Override |
|
|
|
public SuggestionTypeDTO get(String id) { |
|
|
|
SuggestionTypeEntity entity = baseDao.selectById(id); |
|
|
|
return ConvertUtils.sourceToTarget(entity, SuggestionTypeDTO.class); |
|
|
|
return baseDao.getById(id); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void save(SuggestionTypeDTO dto) { |
|
|
|
SuggestionTypeEntity entity = ConvertUtils.sourceToTarget(dto, SuggestionTypeEntity.class); |
|
|
|
entity.setPids(getPidList(entity.getPid())); |
|
|
|
insert(entity); |
|
|
|
} |
|
|
|
|
|
|
@ -108,10 +113,54 @@ public class SuggestionTypeServiceImpl extends BaseServiceImpl<SuggestionTypeDao |
|
|
|
@Override |
|
|
|
public Result<List<TypeNode>> getSuggestionTypeTree() { |
|
|
|
List<TypeNode> nodes = baseDao.selectListSuggestionTypeTree(); |
|
|
|
Map<String, List<TypeNode>> children = nodes.stream().filter(node -> !(node.getPid().equals(NumConstant.ZERO_STR))) |
|
|
|
Map<String, List<TypeNode>> children = nodes.stream().filter(node -> !(node.getPid().equals(NumConstant.ZERO))) |
|
|
|
.collect(Collectors.groupingBy(node -> node.getPid())); |
|
|
|
nodes.forEach(node -> node.setChildren(children.get(node.getValue()))); |
|
|
|
List<TypeNode> result = nodes.stream().filter(node -> node.getPid().equals(NumConstant.ZERO_STR)).collect(Collectors.toList()); |
|
|
|
return new Result<List<TypeNode>>().ok(result); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 获取所有上级部门ID |
|
|
|
* |
|
|
|
* @param pid 上级ID |
|
|
|
*/ |
|
|
|
private String getPidList(Long pid) { |
|
|
|
//顶级部门,无上级部门
|
|
|
|
if (Constant.DEPT_ROOT.equals(pid)) { |
|
|
|
return Constant.DEPT_ROOT + ""; |
|
|
|
} |
|
|
|
|
|
|
|
//所有部门的id、pid列表
|
|
|
|
List<SuggestionTypeEntity> deptList = baseDao.getIdAndPidList(); |
|
|
|
|
|
|
|
//list转map
|
|
|
|
Map<Long, SuggestionTypeEntity> map = new HashMap<>(deptList.size()); |
|
|
|
for (SuggestionTypeEntity entity : deptList) { |
|
|
|
map.put(entity.getId(), entity); |
|
|
|
} |
|
|
|
|
|
|
|
//递归查询所有上级部门ID列表
|
|
|
|
List<Long> pidList = new ArrayList<>(); |
|
|
|
getPidTree(pid, map, pidList); |
|
|
|
|
|
|
|
return StringUtils.join(pidList, ","); |
|
|
|
} |
|
|
|
|
|
|
|
private void getPidTree(Long pid, Map<Long, SuggestionTypeEntity> map, List<Long> pidList) { |
|
|
|
//顶级部门,无上级部门
|
|
|
|
if (Constant.DEPT_ROOT.equals(pid)) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
//上级部门存在
|
|
|
|
SuggestionTypeEntity parent = map.get(pid); |
|
|
|
if (parent != null) { |
|
|
|
getPidTree(parent.getPid(), map, pidList); |
|
|
|
} |
|
|
|
|
|
|
|
pidList.add(pid); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|