Commit 438cce9b by shenweidong

更新输出组织机构接口

parent d500e7e9
......@@ -5,6 +5,7 @@ import com.junmp.jyzb.utils.HttpStatus;
import com.junmp.jyzb.utils.RedisUtils;
import com.junmp.jyzb.utils.ResponseResult;
import com.junmp.jyzb.utils.ReturnMsg;
import com.sun.javafx.collections.MappingChange;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
......@@ -99,52 +100,59 @@ public class PubOrgServiceImpl implements PubOrgService{
}
if (orgInfo == -1) {
modifyList(resultList);
// 如果输入的是浙江省公安厅,就将下级的组织机构进行排序
for (Map<String, Object> orgMsg : resultList) {
List<Map<String, Object>> children = (List<Map<String, Object>>) orgMsg.get("children");
// 根据findCode从小到大排序
children.sort(Comparator.comparing(m -> m.get("findCode").toString()));
}
return new ResponseResult(HttpStatus.SUCCESS, "操作成功", resultList);
}
if (orgInfo.equals(1369509498032808905L)){ //排序
// 根据findCode从小到大排序
resultList.sort(Comparator.comparing(m -> m.get("findCode").toString()));
return new ResponseResult(HttpStatus.SUCCESS, "操作成功", resultList);
}
//将resultList的内容放在顶级菜单的resultList中
for (Map<String,Object> oneMap:topList){
oneMap.put("children",resultList);
}
//topList = setParentMsg(topList);
// 遍历并添加父类的相关信息到children的第一个位置
traverseList(topList);
modifyList(topList);
if (orgInfo.equals(1369509498032808905L)) {
// 如果输入的是浙江省公安厅,就将下级的组织机构进行排序
for (Map<String, Object> orgMsg : topList) {
List<Map<String, Object>> children = (List<Map<String, Object>>) orgMsg.get("children");
// 根据findCode从小到大排序
children.sort(Comparator.comparing(m -> m.get("findCode").toString()));
}
return new ResponseResult(HttpStatus.SUCCESS, "操作成功", topList);
}
// 返回结果
return new ResponseResult(HttpStatus.SUCCESS, "操作成功", topList);
}
//将父类信息放在children的第一个位置
public static List<Map<String,Object>> setParentMsg(List<Map<String,Object>> resultList){
// 遍历并添加父类的相关信息到children的第一个位置
for (Map<String, Object> data : resultList) {
List<Map<String, Object>> children = (List<Map<String, Object>>) data.get("children");
if (!children.isEmpty()) {
Map<String, Object> parentInfo = new HashMap<>(data);
children.add(0, parentInfo);
}
}
return resultList;
}
public static void traverseList(List<Map<String, Object>> list) {
for (Map<String, Object> data : list) {
List<Map<String, Object>> children = (List<Map<String, Object>>) data.get("children");
if (!children.isEmpty()) {
Map<String, Object> parentInfo = new HashMap<>(data);
children.add(0, parentInfo);
traverseList(children);
private static void modifyList(List<Map<String, Object>> list) {
for (Map<String, Object> item : list) {
// 获取当前节点的ID
Map<String,Object> setMsg = new HashMap<>();
setMsg.put("id", Long.valueOf(item.get("id").toString()));
setMsg.put("parentId", item.get("parentId").toString());
setMsg.put("findCode", item.get("findCode").toString());
setMsg.put("orgName", item.get("orgName").toString());
// 将当前节点的ID添加到子节点的第一个位置
@SuppressWarnings("unchecked")
List<Map<String, Object>> children = (List<Map<String, Object>>) item.get("children");
if (children != null && children.size() > 0) {
//将父类的相关信息放在children的第一个位置
children.set(0,setMsg);
// 递归处理子节点
modifyList(children);
}
}
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论