Commit 0a3a3e78 authored by 赵啸非's avatar 赵啸非

添加菜单资源配置

parent 26c85420
......@@ -123,11 +123,11 @@ public class AuthTokenServiceImpl implements IAuthTokenService {
}
//更新resource 路径
String menuUrlCode = cacheService.hget(RedisKey.KEY_USER_MENU_CACHE, userEntity.getId().toString(), String.class);
if (ObjectUtils.isEmpty(menuUrlCode)) {
Set<String> urls = resourceService.findUrlSetByUserId(userEntity.getId());
menuUrlCode = MenuEncodeUtil.generateMenuUrlCode(urls);
cacheService.hset(RedisKey.KEY_USER_MENU_CACHE, userEntity.getId().toString(), menuUrlCode);
}
// if (ObjectUtils.isEmpty(menuUrlCode)) {
// Set<String> urls = resourceService.findUrlSetByUserId(userEntity.getId());
// menuUrlCode = MenuEncodeUtil.generateMenuUrlCode(urls);
// cacheService.hset(RedisKey.KEY_USER_MENU_CACHE, userEntity.getId().toString(), menuUrlCode);
// }
userEntity.setMenuUrl(menuUrlCode);
return userEntity;
}
......
......@@ -69,7 +69,6 @@ public class ResourceServiceImpl extends AbstractCRUDServiceImpl<ResourceDao, Re
continue;
}
urls.add(url);
// url = url.replaceAll(",", ",");
}
return urls;
}
......
......@@ -21,7 +21,9 @@ import com.mortals.xhx.base.system.resource.service.ResourceService;
import com.mortals.xhx.base.system.role.dao.RoleAuthDao;
import com.mortals.xhx.base.system.role.model.RoleAuthEntity;
import com.mortals.xhx.base.system.role.model.RoleAuthQuery;
import com.mortals.xhx.base.system.role.model.RoleUserQuery;
import com.mortals.xhx.base.system.role.service.RoleAuthService;
import com.mortals.xhx.base.system.role.service.RoleUserService;
import com.mortals.xhx.common.key.RedisKey;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
......@@ -49,6 +51,8 @@ public class RoleAuthServiceImpl extends AbstractCRUDServiceImpl<RoleAuthDao, Ro
private ICacheService cacheService;
@Autowired
private MenuService menuService;
@Autowired
private RoleUserService roleUserService;
@Autowired
@Lazy
......@@ -56,12 +60,9 @@ public class RoleAuthServiceImpl extends AbstractCRUDServiceImpl<RoleAuthDao, Ro
@Override
public void doDistributionSource(RoleAuthQuery query, Context context) {
if (ObjectUtils.isEmpty(query.getRoleId())) throw new AppException("角色不能为空!");
// 删除角色资源老数据
Long roleId = query.getRoleId();
/* Map<String, Object> condition = new HashMap<>();
condition.put("roleId", roleId);
this.dao.delete(condition);*/
//todo
RoleAuthQuery roleAuthQuery = new RoleAuthQuery();
roleAuthQuery.setRoleId(roleId);
Long[] delIds = this.find(roleAuthQuery).stream()
......@@ -80,17 +81,23 @@ public class RoleAuthServiceImpl extends AbstractCRUDServiceImpl<RoleAuthDao, Ro
}
this.dao.insertBatch(list);
this.updateUserMenuUrlCache();
//查询所有有这个用户角色的用户
// this.find(new RoleAuthQuery().roleId(roleId)).stream().filter(f->f.get)
List<Long> userIdList = roleUserService.find(new RoleUserQuery().roleId(query.getRoleId())).stream()
.map(m -> m.getUserId())
.filter(f -> f != null)
.distinct().collect(Collectors.toList());
this.updateUserMenuUrlCache(userIdList);
}
@Override
public void doDistributionMenu(RoleAuthQuery query, Context context) {
if (ObjectUtils.isEmpty(query.getRoleId())) throw new AppException("角色不能为空!");
// 删除角色资源老数据
Long roleId = query.getRoleId();
/* Map<String, Object> condition = new HashMap<>();
condition.put("roleId", roleId);
this.dao.delete(condition);*/
//todo
RoleAuthQuery roleAuthQuery = new RoleAuthQuery();
roleAuthQuery.setRoleId(roleId);
Long[] delIds = this.find(roleAuthQuery).stream()
......@@ -108,13 +115,16 @@ public class RoleAuthServiceImpl extends AbstractCRUDServiceImpl<RoleAuthDao, Ro
list.add(entity);
}
this.dao.insertBatch(list);
this.updateUserMenuUrlCache();
List<Long> userIdList = roleUserService.find(new RoleUserQuery().roleId(query.getRoleId())).stream()
.map(m -> m.getUserId())
.filter(f -> f != null)
.distinct().collect(Collectors.toList());
this.updateUserMenuUrlCache(userIdList);
}
@Override
public List<MenuTreeSelect> editMenu(RoleAuthQuery query, Context context) {
if (ObjectUtils.isEmpty(query.getRoleId())) throw new AppException("角色不能为空");
if (ObjectUtils.isEmpty(query.getRoleId())) throw new AppException("角色不能为空!");
RoleAuthQuery roleAuthQuery = new RoleAuthQuery();
roleAuthQuery.setRoleId(query.getRoleId());
......@@ -131,13 +141,11 @@ public class RoleAuthServiceImpl extends AbstractCRUDServiceImpl<RoleAuthDao, Ro
}
private void updateUserMenuUrlCache() {
//更新用户菜单
Set<String> hkeys = cacheService.hkeys(RedisKey.KEY_USER_MENU_CACHE);
for (String userId : hkeys) {
Set<String> urls = resourceService.findUrlSetByUserId(DataUtil.converStr2Long(userId, 0L));
private void updateUserMenuUrlCache(List<Long> userIdList) {
for (Long userId : userIdList) {
Set<String> urls = resourceService.findUrlSetByUserId(userId);
String menuUrlCode = generateMenuUrlCode(urls);
cacheService.hset(RedisKey.KEY_USER_MENU_CACHE, userId, menuUrlCode);
cacheService.hset(RedisKey.KEY_USER_MENU_CACHE, userId.toString(), menuUrlCode);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment