DeptLevelUtil.java 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package com.sooka.sponest.data.utils;
  2. import com.ruoyi.common.security.utils.SecurityUtils;
  3. import com.ruoyi.system.api.RemoteDeptService;
  4. import com.ruoyi.system.api.domain.SysDept;
  5. import net.bytebuddy.implementation.bytecode.Throw;
  6. import org.springframework.beans.factory.annotation.Autowired;
  7. import org.springframework.stereotype.Component;
  8. import java.io.IOException;
  9. import java.util.ArrayList;
  10. import java.util.HashMap;
  11. import java.util.List;
  12. import java.util.Map;
  13. @Component
  14. public class DeptLevelUtil {
  15. @Autowired
  16. private RemoteDeptService remoteDeptService;
  17. public List<Map<String, Object>> getDeptLevel(List<Map<String,Object>> list) throws IOException {
  18. List<Map<String,Object>> mapList = new ArrayList<>();
  19. if (list.isEmpty()||!list.get(0).containsKey("ancestors")){
  20. throw new IOException("入参为空或入参没有key:'ancestors'");
  21. }
  22. String deptId = SecurityUtils.getLoginUser().getSysUser().getDeptId().toString();
  23. List<SysDept> sysDeptList = remoteDeptService.selectChildrenCountyOrVillagesDeptListByDeptId(deptId).getData();
  24. for (SysDept sysDept : sysDeptList){//部门
  25. Map<String,Object> map = new HashMap<>();
  26. //map中增加key
  27. for (String key : list.get(0).keySet()) {
  28. if (!key.equals("ancestors")&&!key.equals("deptId")){
  29. map.put(key,0);
  30. }
  31. }
  32. for (Map<String,Object> ancestors : list){//资源数据
  33. if (ancestors.get("ancestors").toString().concat(",").concat(ancestors.get("deptId").toString()).contains(sysDept.getAncestors().concat(",").concat(sysDept.getDeptId().toString()))){
  34. for (String key : ancestors.keySet()) {
  35. if (!key.equals("ancestors")&&!key.equals("deptId")){
  36. map.put(key,Long.parseLong(map.get(key).toString())+Long.parseLong(ancestors.get(key).toString()));
  37. }
  38. }
  39. }
  40. }
  41. map.put("deptId",sysDept.getDeptId());
  42. map.put("deptName",sysDept.getDeptName());
  43. mapList.add(map);
  44. }
  45. return mapList;
  46. }
  47. }