12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- package com.sooka.sponest.data.utils;
- import com.ruoyi.common.security.utils.SecurityUtils;
- import com.ruoyi.system.api.RemoteDeptService;
- import com.ruoyi.system.api.domain.SysDept;
- import net.bytebuddy.implementation.bytecode.Throw;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Component;
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- @Component
- public class DeptLevelUtil {
- @Autowired
- private RemoteDeptService remoteDeptService;
- public List<Map<String, Object>> getDeptLevel(List<Map<String,Object>> list) throws IOException {
- List<Map<String,Object>> mapList = new ArrayList<>();
- if (list.isEmpty()||!list.get(0).containsKey("ancestors")){
- throw new IOException("入参为空或入参没有key:'ancestors'");
- }
- String deptId = SecurityUtils.getLoginUser().getSysUser().getDeptId().toString();
- List<SysDept> sysDeptList = remoteDeptService.selectChildrenCountyOrVillagesDeptListByDeptId(deptId).getData();
- for (SysDept sysDept : sysDeptList){//部门
- Map<String,Object> map = new HashMap<>();
- //map中增加key
- for (String key : list.get(0).keySet()) {
- if (!key.equals("ancestors")&&!key.equals("deptId")){
- map.put(key,0);
- }
- }
- for (Map<String,Object> ancestors : list){//资源数据
- if (ancestors.get("ancestors").toString().concat(",").concat(ancestors.get("deptId").toString()).contains(sysDept.getAncestors().concat(",").concat(sysDept.getDeptId().toString()))){
- for (String key : ancestors.keySet()) {
- if (!key.equals("ancestors")&&!key.equals("deptId")){
- map.put(key,Long.parseLong(map.get(key).toString())+Long.parseLong(ancestors.get(key).toString()));
- }
- }
- }
- }
- map.put("deptId",sysDept.getDeptId());
- map.put("deptName",sysDept.getDeptName());
- mapList.add(map);
- }
- return mapList;
- }
- }
|