mirror of
https://gitee.com/dromara/RuoYi-Cloud-Plus.git
synced 2025-12-30 09:52:26 +00:00
update 优化 优化rpc查询实现 减少rpc调用次数
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
package org.dromara.common.mybatis.service;
|
||||
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.dromara.common.core.constant.CacheNames;
|
||||
import org.dromara.system.api.RemoteDataScopeService;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
@@ -24,6 +26,7 @@ public class SysDataScopeService {
|
||||
* @param roleId 角色ID
|
||||
* @return 返回角色的自定义权限语句,如果没有找到则返回 null
|
||||
*/
|
||||
@Cacheable(cacheNames = CacheNames.SYS_ROLE_CUSTOM, key = "#roleId", condition = "#roleId != null")
|
||||
public String getRoleCustom(Long roleId) {
|
||||
return remoteDataScopeService.getRoleCustom(roleId);
|
||||
}
|
||||
@@ -34,6 +37,7 @@ public class SysDataScopeService {
|
||||
* @param deptId 部门ID
|
||||
* @return 返回部门及其下级的权限语句,如果没有找到则返回 null
|
||||
*/
|
||||
@Cacheable(cacheNames = CacheNames.SYS_DEPT_AND_CHILD, key = "#deptId", condition = "#deptId != null")
|
||||
public String getDeptAndChild(Long deptId) {
|
||||
return remoteDataScopeService.getDeptAndChild(deptId);
|
||||
}
|
||||
|
||||
@@ -1,12 +1,19 @@
|
||||
package org.dromara.common.translation.core.impl;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.dromara.common.core.constant.CacheNames;
|
||||
import org.dromara.common.core.utils.StringUtils;
|
||||
import org.dromara.common.redis.utils.CacheUtils;
|
||||
import org.dromara.common.translation.annotation.TranslationType;
|
||||
import org.dromara.common.translation.constant.TransConstant;
|
||||
import org.dromara.common.translation.core.TranslationInterface;
|
||||
import org.dromara.system.api.RemoteUserService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用户昵称翻译实现
|
||||
*
|
||||
@@ -22,9 +29,22 @@ public class NicknameTranslationImpl implements TranslationInterface<String> {
|
||||
@Override
|
||||
public String translation(Object key, String other) {
|
||||
if (key instanceof Long id) {
|
||||
return remoteUserService.selectNicknameByIds(id.toString());
|
||||
String nickname = CacheUtils.get(CacheNames.SYS_NICKNAME, key);
|
||||
if (StringUtils.isNotBlank(nickname)) {
|
||||
return nickname;
|
||||
}
|
||||
return remoteUserService.selectNicknameById(id);
|
||||
} else if (key instanceof String ids) {
|
||||
return remoteUserService.selectNicknameByIds(ids);
|
||||
List<String> list = new ArrayList<>();
|
||||
for (Long id : StringUtils.splitTo(ids, Convert::toLong)) {
|
||||
String nickname = CacheUtils.get(CacheNames.SYS_NICKNAME, key);
|
||||
if (StringUtils.isNotBlank(nickname)) {
|
||||
list.add(nickname);
|
||||
} else {
|
||||
list.add(remoteUserService.selectNicknameById(id));
|
||||
}
|
||||
}
|
||||
return StringUtils.joinComma(list);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
package org.dromara.common.translation.core.impl;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import org.dromara.common.core.constant.CacheNames;
|
||||
import org.dromara.common.core.utils.StringUtils;
|
||||
import org.dromara.common.redis.utils.CacheUtils;
|
||||
import org.dromara.common.translation.annotation.TranslationType;
|
||||
import org.dromara.common.translation.constant.TransConstant;
|
||||
import org.dromara.common.translation.core.TranslationInterface;
|
||||
@@ -21,6 +25,11 @@ public class UserNameTranslationImpl implements TranslationInterface<String> {
|
||||
|
||||
@Override
|
||||
public String translation(Object key, String other) {
|
||||
return remoteUserService.selectUserNameById((Long) key);
|
||||
Long userId = Convert.toLong(key);
|
||||
String username = CacheUtils.get(CacheNames.SYS_USER_NAME, userId);
|
||||
if (StringUtils.isNotBlank(username)) {
|
||||
return username;
|
||||
}
|
||||
return remoteUserService.selectUserNameById(userId);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user