|
|
@ -30,6 +30,7 @@ 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.utils.Result; |
|
|
|
import com.elink.esua.epdc.commons.tools.utils.TreeUtils; |
|
|
|
import com.elink.esua.epdc.dto.CascadeOptions; |
|
|
|
import com.elink.esua.epdc.dto.DeptOption; |
|
|
|
import com.elink.esua.epdc.dto.TypeNode; |
|
|
|
import com.elink.esua.epdc.dto.suggestion.SuggestionTypeDTO; |
|
|
@ -120,6 +121,74 @@ public class SuggestionTypeServiceImpl extends BaseServiceImpl<SuggestionTypeDao |
|
|
|
return new Result<List<TypeNode>>().ok(result); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public Result<CascadeOptions> getSuggestionTypeOptions() { |
|
|
|
List<TypeNode> allSuggestionType = baseDao.selectListSuggestionTypeTree(); |
|
|
|
|
|
|
|
JSONObject node; |
|
|
|
JSONArray headNodes = new JSONArray(); |
|
|
|
for (TypeNode itemDto : allSuggestionType) { |
|
|
|
if (itemDto.getPid().equals(NumConstant.ZERO_L)) { |
|
|
|
node = new JSONObject(); |
|
|
|
node.put("value", itemDto.getValue()); |
|
|
|
node.put("label", itemDto.getLabel()); |
|
|
|
headNodes.add(node); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 用于存放所有父级节点
|
|
|
|
JSONArray parent; |
|
|
|
parent = headNodes; |
|
|
|
// 用于存放所有子级节点
|
|
|
|
JSONArray allChildren = new JSONArray(); |
|
|
|
JSONArray children; |
|
|
|
// 用于存放单个子级节点
|
|
|
|
JSONObject childNode; |
|
|
|
// 存放其余未处理的类别(节点)
|
|
|
|
List<TypeNode> others = this.getOtherDept(allSuggestionType, parent); |
|
|
|
while (!others.isEmpty()) { |
|
|
|
for (int i = 0; i < parent.size(); i++) { |
|
|
|
node = parent.getJSONObject(i); |
|
|
|
children = new JSONArray(); |
|
|
|
for (TypeNode categoryTreeDto : others) { |
|
|
|
if (categoryTreeDto.getPid().equals(node.get("value"))) { |
|
|
|
childNode = new JSONObject(); |
|
|
|
childNode.put("value", categoryTreeDto.getValue()); |
|
|
|
childNode.put("label", categoryTreeDto.getLabel()); |
|
|
|
children.add(childNode); |
|
|
|
allChildren.add(childNode); |
|
|
|
} |
|
|
|
} |
|
|
|
if (!children.isEmpty()) { |
|
|
|
node.put("children", children); |
|
|
|
} |
|
|
|
} |
|
|
|
parent = allChildren; |
|
|
|
others = this.getOtherDept(others, parent); |
|
|
|
} |
|
|
|
CascadeOptions option = new CascadeOptions(); |
|
|
|
option.setOptions(headNodes); |
|
|
|
|
|
|
|
return new Result<CascadeOptions>().ok(option); |
|
|
|
} |
|
|
|
|
|
|
|
public List<TypeNode> getOtherDept(List<TypeNode> deptList, JSONArray parent) { |
|
|
|
List<Long> already = Lists.newArrayList(); |
|
|
|
for (int i = 0; i < parent.size(); i++) { |
|
|
|
already.add((Long) parent.getJSONObject(i).get("value")); |
|
|
|
} |
|
|
|
|
|
|
|
List<TypeNode> others = Lists.newArrayList(); |
|
|
|
|
|
|
|
for (TypeNode categoryTreeDto : deptList) { |
|
|
|
Long categoryTreeDtoId = categoryTreeDto.getValue(); |
|
|
|
if (!already.contains(categoryTreeDtoId)) { |
|
|
|
others.add(categoryTreeDto); |
|
|
|
} |
|
|
|
} |
|
|
|
return others; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 获取所有上级部门ID |
|
|
|
* |
|
|
|