Browse Source

建议类别 级联器选项 PC端

origin/epidemic_user
zhangyongzhangyong 4 years ago
parent
commit
2e4c6409aa
  1. 23
      epdc-cloud-custom/src/main/java/com/elink/esua/epdc/modules/suggestion/controller/SuggestionTypeController.java
  2. 10
      epdc-cloud-custom/src/main/java/com/elink/esua/epdc/modules/suggestion/service/SuggestionTypeService.java
  3. 69
      epdc-cloud-custom/src/main/java/com/elink/esua/epdc/modules/suggestion/service/impl/SuggestionTypeServiceImpl.java

23
epdc-cloud-custom/src/main/java/com/elink/esua/epdc/modules/suggestion/controller/SuggestionTypeController.java

@ -25,6 +25,7 @@ import com.elink.esua.epdc.commons.tools.validator.ValidatorUtils;
import com.elink.esua.epdc.commons.tools.validator.group.AddGroup;
import com.elink.esua.epdc.commons.tools.validator.group.DefaultGroup;
import com.elink.esua.epdc.commons.tools.validator.group.UpdateGroup;
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;
@ -113,4 +114,26 @@ public class SuggestionTypeController {
return suggestionTypeService.getSuggestionTypeTree();
}
/**
* 获取 建议类别 级联器选项 PC端
*
* @param
* @return com.elink.esua.epdc.commons.tools.utils.Result<com.elink.esua.epdc.dto.CascadeOptions>
* @Author zhangyong
* @Date 10:02 2021-09-18
**/
@GetMapping("getSuggestionTypeOptions")
public Result<CascadeOptions> getSuggestionTypeOptions() {
return suggestionTypeService.getSuggestionTypeOptions();
}
}
class A {
public static void main(String[] args) {
Long a = 1L;
long aa = 1L;
System.out.println(a.equals(aa));
// System.out.println(a == a);
}
}

10
epdc-cloud-custom/src/main/java/com/elink/esua/epdc/modules/suggestion/service/SuggestionTypeService.java

@ -20,6 +20,7 @@ package com.elink.esua.epdc.modules.suggestion.service;
import com.elink.esua.epdc.commons.mybatis.service.BaseService;
import com.elink.esua.epdc.commons.tools.page.PageData;
import com.elink.esua.epdc.commons.tools.utils.Result;
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;
@ -106,4 +107,13 @@ public interface SuggestionTypeService extends BaseService<SuggestionTypeEntity>
**/
Result<List<TypeNode>> getSuggestionTypeTree();
/**
* 获取 建议类别 级联器选项 PC端
*
* @param
* @return com.elink.esua.epdc.commons.tools.utils.Result<com.elink.esua.epdc.dto.CascadeOptions>
* @Author zhangyong
* @Date 10:02 2021-09-18
**/
Result<CascadeOptions> getSuggestionTypeOptions();
}

69
epdc-cloud-custom/src/main/java/com/elink/esua/epdc/modules/suggestion/service/impl/SuggestionTypeServiceImpl.java

@ -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
*

Loading…
Cancel
Save