✨ DictResolver根据字典类型获取字典
This commit is contained in:
1 parent
c91549d129
commit
c7404cd1a0
3 files changed
+13
-18
No files matched your search
+7
-15
@@ -14,31 +14,27 @@ import java.util.List;
|
||||
|
||||
/**
|
||||
* @author fxz
|
||||
* @date 2022/3/24
|
||||
* 字典解析器
|
||||
* @date 2022/3/24 字典解析器
|
||||
*/
|
||||
@UtilityClass
|
||||
public class DictResolver {
|
||||
|
||||
/**
|
||||
* 根据字典类型获取所有字典项
|
||||
*
|
||||
* @param type 字典类型
|
||||
* @return 字典数据项集合
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<SysDictItem> getDictItemsByType(String type) {
|
||||
Assert.isNull(type, "参数不合法");
|
||||
Assert.isTrue(StringUtils.isNotBlank(type), "参数不合法");
|
||||
|
||||
RemoteDictService remoteDictService = SpringContextHolder.getBean(RemoteDictService.class);
|
||||
|
||||
return (List<SysDictItem>) remoteDictService.getDictByType(type).getData();
|
||||
return remoteDictService.getDictByType(type).getData();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据字典类型以及字典项字典值获取字典标签
|
||||
*
|
||||
* @param type 字典类型
|
||||
* @param type 字典类型
|
||||
* @param itemValue 字典项字典值
|
||||
* @return 字典项标签值
|
||||
*/
|
||||
@@ -52,8 +48,7 @@ public class DictResolver {
|
||||
|
||||
/**
|
||||
* 根据字典类型以及字典标签获取字典值
|
||||
*
|
||||
* @param type 字典类型
|
||||
* @param type 字典类型
|
||||
* @param itemLabel 字典数据标签
|
||||
* @return 字典数据项值
|
||||
*/
|
||||
@@ -67,8 +62,7 @@ public class DictResolver {
|
||||
|
||||
/**
|
||||
* 根据字典类型以及字典值获取字典项
|
||||
*
|
||||
* @param type 字典类型
|
||||
* @param type 字典类型
|
||||
* @param itemValue 字典数据值
|
||||
* @return 字典数据项
|
||||
*/
|
||||
@@ -86,8 +80,7 @@ public class DictResolver {
|
||||
|
||||
/**
|
||||
* 根据字典类型以及字典标签获取字典项
|
||||
*
|
||||
* @param type 字典类型
|
||||
* @param type 字典类型
|
||||
* @param itemLabel 字典数据项标签
|
||||
* @return 字典数据项
|
||||
*/
|
||||
@@ -103,5 +96,4 @@ public class DictResolver {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+4
-2
@@ -1,11 +1,14 @@
|
||||
package com.pig4cloud.pigx.admin.api.feign;
|
||||
|
||||
import com.pig4cloud.pigx.admin.api.entity.SysDictItem;
|
||||
import com.pig4cloud.pigx.common.core.constant.ServiceNameConstants;
|
||||
import com.pig4cloud.pigx.common.core.util.R;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2020/5/12
|
||||
@@ -17,11 +20,10 @@ public interface RemoteDictService {
|
||||
|
||||
/**
|
||||
* 通过字典类型查找字典
|
||||
*
|
||||
* @param type 字典类型
|
||||
* @return 同类型字典
|
||||
*/
|
||||
@GetMapping("/dict/type/{type}")
|
||||
R getDictByType(@PathVariable String type);
|
||||
R<List<SysDictItem>> getDictByType(@PathVariable("type") String type);
|
||||
|
||||
}
|
||||
+2
-1
@@ -37,6 +37,7 @@ import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -83,7 +84,7 @@ public class SysDictController {
|
||||
*/
|
||||
@GetMapping("/type/{type}")
|
||||
@Cacheable(value = CacheConstants.DICT_DETAILS, key = "#type", unless = "#result.data.isEmpty()")
|
||||
public R getDictByType(@PathVariable String type) {
|
||||
public R<List<SysDictItem>> getDictByType(@PathVariable String type) {
|
||||
return R.ok(sysDictItemService.list(Wrappers.<SysDictItem>query().lambda().eq(SysDictItem::getDictType, type)));
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user