Commit 438cce9b by shenweidong

更新输出组织机构接口

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