Commit ae1e58c6 by 刘鑫

Merge remote-tracking branch 'origin/develop' into develop

2 parents 8805a566 7161058b
......@@ -13,6 +13,11 @@ public enum RedisKeyGroup {
/**
* 认证ak对应的认证信息
*/
appKey;
appKey,
/**
* 资源信息
*/
resourceKey;
}
......@@ -3,17 +3,21 @@ package com.dituhui.pea.user.service;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject;
import com.dituhui.pea.common.PageResult;
import com.dituhui.pea.enums.RedisKeyGroup;
import com.dituhui.pea.enums.StatusCodeEnum;
import com.dituhui.pea.exception.BusinessException;
import com.dituhui.pea.pojo.PageRequest;
import com.dituhui.pea.pojo.ResourceInfo;
import com.dituhui.pea.pojo.RoleInfo;
import com.dituhui.pea.pojo.role.RoleResourceInfo;
import com.dituhui.pea.user.commom.RedisService;
import com.dituhui.pea.user.dao.*;
import com.dituhui.pea.user.entity.*;
import com.google.common.collect.Lists;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
......@@ -49,6 +53,14 @@ public class RoleService {
@Autowired
RoleResourceDao roleResourceDao;
@Autowired
RedisService redisService;
/**
* 失效时间ms
*/
private static final int LIVE_TIME_MILLIS = 360000;
@Transactional(rollbackFor = Exception.class)
public RoleInfo addRole(RoleInfo roleInfo) {
......@@ -263,7 +275,23 @@ public class RoleService {
}
public List<ResourceInfo> allResource() {
String redisValue = redisService.get(RedisKeyGroup.resourceKey.name());
if (StringUtils.isNotBlank(redisValue)) {
return JSONObject.parseObject(redisValue, List.class);
}
List<ResourceEntity> all = resourceDao.findAll();
return all.stream().map(entity -> BeanUtil.copyProperties(entity, ResourceInfo.class)).collect(Collectors.toList());
List<ResourceInfo> collect = all.stream().filter(resourceEntity -> StringUtils.isBlank(resourceEntity.getParentId())).map(entity -> BeanUtil.copyProperties(entity, ResourceInfo.class)).collect(Collectors.toList());
for (ResourceInfo entity : collect) {
List<ResourceInfo> twoResource = all.stream().filter(resourceEntity -> entity.getParentId().equals(entity.getId())).map(e -> BeanUtil.copyProperties(e, ResourceInfo.class)).collect(Collectors.toList());
for (ResourceInfo twoEntity : twoResource) {
List<ResourceInfo> threeResource = all.stream().filter(resourceEntity -> entity.getParentId().equals(twoEntity.getId())).map(e -> BeanUtil.copyProperties(e, ResourceInfo.class)).collect(Collectors.toList());
twoEntity.setChildren(threeResource);
}
entity.setChildren(twoResource);
}
long timestamp = System.currentTimeMillis() + LIVE_TIME_MILLIS;
redisService.set(RedisKeyGroup.resourceKey.name(), JSONObject.toJSONString(collect), timestamp / 1000);
return collect;
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!