ConfigUtil

package util;

 

import java.io.BufferedInputStream;

import java.io.FileInputStream;

import java.io.FileNotFoundException;

import java.io.IOException;

import java.util.Properties;

 

 

public class ConfigUtil

{

      private Properties prop = new Properties();

      public ConfigUtil() throws FileNotFoundException, IOException

      {

            prop.load(new BufferedInputStream(new FileInputStream("./config/config.properties")));

      }

     

      public void listValue()

      {

            prop.list(System.out);

      }

     

      public String getValue(String name)

      {

            return prop.getProperty(name);

      }

}

 

 

 

配置文件位置:

projectRootFolder/config/config.properties

@Override public ResponseDto getDepartmentTreeList(Integer departmentId,Integer isPeople) { Integer rootOrg; if (Objects.isNull(departmentId)) { rootOrg = ConfigUtil.getInt(ConfigUtil.ROOT_TISSUE); } else { rootOrg = departmentId; } String redisKey = ObjectUtil.join(Contacts.SYNTHESIZE_DEPART_TREE_CACHE,rootOrg,":",isPeople); if (RedisUtil.exists(redisKey)) { String dataStr = RedisUtil.get(redisKey); return ResponseDto.success(JSONArray.parseArray(dataStr)); } final DepartDto[] dto = new DepartDto[1]; List<DepartDto> departmentList = noticeMapper.getDepartmentList(null); Map<Integer, List<DepartDto>> collect = departmentList.stream().collect(Collectors.groupingBy(DepartDto::getParentid)); departmentList.forEach(e -> { if (Objects.equals(rootOrg, e.getId())) { dto[0] = e; } e.setChildNode(collect.get(e.getId())); }); List<DepartDto> collect1 = departmentList.stream().filter(e -> Objects.equals(rootOrg, e.getParentid())).collect(Collectors.toList()); if (isPeople == 1) { dto[0].setChildNode(collect1); RedisUtil.set(redisKey,JSONArray.toJSONString(dto),1,TimeUnit.DAYS); return ResponseDto.success(dto); } CountDownLatch countDownLatch = new CountDownLatch(collect1.size()); JSONArray childNodes = new JSONArray(); JSONObject deptDto = new JSONObject(); try { collect1.forEach(departDto-> executor.execute(()->{ JSONObject object = JSONObject.parseObject(JSONObject.toJSONString(departDto)); if (Assert.isNotEmpty(departDto.getChildNode())) { JSONArray leader = getChildNodeLeaderList(departDto.getId()); JSONArray childNode = object.getJSONArray("childNode"); leader.addAll(childNode); object.put("childNode",leader); } childNodes.add(object); countDownLatch.countDown(); })); countDownLatch.await(); } catch (InterruptedException e) { throw new RuntimeException(e); } JSONArray leader = getChildNodeLeaderList(rootOrg); leader.addAll(childNodes); deptDto.putAll(JSONObject.parseObject(JSONObject.toJSONString(dto[0]))); deptDto.put("childNode",leader); JSONArray result = new JSONArray(); result.add(deptDto); RedisUtil.set(redisKey,JSONArray.toJSONString(result),1,TimeUnit.DAYS); return ResponseDto.success(result); }解释代码
09-17
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值