init
This commit is contained in:
38
ruoyi-common/ruoyi-common-service-impl/pom.xml
Normal file
38
ruoyi-common/ruoyi-common-service-impl/pom.xml
Normal file
@@ -0,0 +1,38 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<groupId>org.dromara</groupId>
|
||||
<artifactId>ruoyi-common</artifactId>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>ruoyi-common-service-impl</artifactId>
|
||||
|
||||
<description>
|
||||
ruoyi-common-service-impl 通用service实现模块(用于处理core模块中的通用业务service类)
|
||||
</description>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<!-- RuoYi Common Security -->
|
||||
<dependency>
|
||||
<groupId>org.dromara</groupId>
|
||||
<artifactId>ruoyi-common-redis</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.dromara</groupId>
|
||||
<artifactId>ruoyi-api-system</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-spring-boot-starter</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</project>
|
@@ -0,0 +1,98 @@
|
||||
package org.dromara.common.core.service.impl;
|
||||
|
||||
import com.github.benmanes.caffeine.cache.Cache;
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.dromara.common.core.constant.CacheConstants;
|
||||
import org.dromara.common.core.service.DictService;
|
||||
import org.dromara.common.core.utils.StreamUtils;
|
||||
import org.dromara.common.core.utils.StringUtils;
|
||||
import org.dromara.system.api.RemoteDictService;
|
||||
import org.dromara.system.api.domain.vo.RemoteDictDataVo;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 字典服务服务
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
@Service
|
||||
public class DictServiceImpl implements DictService {
|
||||
|
||||
@Autowired
|
||||
private Cache<Object, Object> ceffeine;
|
||||
|
||||
@DubboReference
|
||||
private RemoteDictService remoteDictService;
|
||||
|
||||
/**
|
||||
* 根据字典类型和字典值获取字典标签
|
||||
*
|
||||
* @param dictType 字典类型
|
||||
* @param dictValue 字典值
|
||||
* @param separator 分隔符
|
||||
* @return 字典标签
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public String getDictLabel(String dictType, String dictValue, String separator) {
|
||||
// 优先从本地缓存获取
|
||||
List<RemoteDictDataVo> datas = (List<RemoteDictDataVo>) ceffeine.get(CacheConstants.SYS_DICT_KEY + "remote:" + dictType, k -> {
|
||||
return remoteDictService.selectDictDataByType(dictType);
|
||||
});
|
||||
Map<String, String> map = StreamUtils.toMap(datas, RemoteDictDataVo::getDictValue, RemoteDictDataVo::getDictLabel);
|
||||
if (StringUtils.containsAny(dictValue, separator)) {
|
||||
return Arrays.stream(dictValue.split(separator))
|
||||
.map(v -> map.getOrDefault(v, StringUtils.EMPTY))
|
||||
.collect(Collectors.joining(separator));
|
||||
} else {
|
||||
return map.getOrDefault(dictValue, StringUtils.EMPTY);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据字典类型和字典标签获取字典值
|
||||
*
|
||||
* @param dictType 字典类型
|
||||
* @param dictLabel 字典标签
|
||||
* @param separator 分隔符
|
||||
* @return 字典值
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public String getDictValue(String dictType, String dictLabel, String separator) {
|
||||
// 优先从本地缓存获取
|
||||
List<RemoteDictDataVo> datas = (List<RemoteDictDataVo>) ceffeine.get(CacheConstants.SYS_DICT_KEY + "remote:" + dictType, k -> {
|
||||
return remoteDictService.selectDictDataByType(dictType);
|
||||
});
|
||||
Map<String, String> map = StreamUtils.toMap(datas, RemoteDictDataVo::getDictLabel, RemoteDictDataVo::getDictValue);
|
||||
if (StringUtils.containsAny(dictLabel, separator)) {
|
||||
return Arrays.stream(dictLabel.split(separator))
|
||||
.map(l -> map.getOrDefault(l, StringUtils.EMPTY))
|
||||
.collect(Collectors.joining(separator));
|
||||
} else {
|
||||
return map.getOrDefault(dictLabel, StringUtils.EMPTY);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取字典下所有的字典值与标签
|
||||
*
|
||||
* @param dictType 字典类型
|
||||
* @return dictValue为key,dictLabel为值组成的Map
|
||||
*/
|
||||
@Override
|
||||
public Map<String, String> getAllDictByDictType(String dictType) {
|
||||
List<RemoteDictDataVo> list = remoteDictService.selectDictDataByType(dictType);
|
||||
// 保证顺序
|
||||
LinkedHashMap<String, String> map = new LinkedHashMap<>();
|
||||
for (RemoteDictDataVo vo : list) {
|
||||
map.put(vo.getDictValue(), vo.getDictLabel());
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,31 @@
|
||||
package org.dromara.common.core.service.impl;
|
||||
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.dromara.common.core.service.PermissionService;
|
||||
import org.dromara.system.api.RemotePermissionService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 权限服务
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
@Service
|
||||
public class PermissionServiceImpl implements PermissionService {
|
||||
|
||||
@DubboReference
|
||||
private RemotePermissionService remotePermissionService;
|
||||
|
||||
@Override
|
||||
public Set<String> getRolePermission(Long userId) {
|
||||
return remotePermissionService.getRolePermission(userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getMenuPermission(Long userId) {
|
||||
return remotePermissionService.getMenuPermission(userId);
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,51 @@
|
||||
package org.dromara.common.core.utils;
|
||||
|
||||
import org.dromara.common.core.constant.CacheNames;
|
||||
import org.dromara.common.redis.utils.CacheUtils;
|
||||
import org.dromara.system.api.domain.vo.RemoteDictDataVo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 字典工具类
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class DictUtils {
|
||||
/**
|
||||
* 设置字典缓存
|
||||
*
|
||||
* @param key 参数键
|
||||
* @param dictDatas 字典数据列表
|
||||
*/
|
||||
public static void setDictCache(String key, List<RemoteDictDataVo> dictDatas) {
|
||||
CacheUtils.put(CacheNames.SYS_DICT, key, dictDatas);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取字典缓存
|
||||
*
|
||||
* @param key 参数键
|
||||
* @return dictDatas 字典数据列表
|
||||
*/
|
||||
public static List<RemoteDictDataVo> getDictCache(String key) {
|
||||
return CacheUtils.get(CacheNames.SYS_DICT, key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定字典缓存
|
||||
*
|
||||
* @param key 字典键
|
||||
*/
|
||||
public static void removeDictCache(String key) {
|
||||
CacheUtils.evict(CacheNames.SYS_DICT, key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清空字典缓存
|
||||
*/
|
||||
public static void clearDictCache() {
|
||||
CacheUtils.clear(CacheNames.SYS_DICT);
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,2 @@
|
||||
org.dromara.common.core.service.impl.DictServiceImpl
|
||||
org.dromara.common.core.service.impl.PermissionServiceImpl
|
Reference in New Issue
Block a user