Просмотр исходного кода

:zap: 增强字典模块,增加字典枚举类,统一入口

smallchill 6 лет назад
Родитель
Сommit
84d9a22b5a

+ 27 - 4
src/main/java/org/springblade/common/cache/DictBizCache.java

@@ -16,6 +16,7 @@
  */
 package org.springblade.common.cache;
 
+import org.springblade.common.enums.DictBizEnum;
 import org.springblade.core.cache.utils.CacheUtil;
 import org.springblade.core.secure.utils.AuthUtil;
 import org.springblade.core.tool.utils.SpringUtil;
@@ -48,31 +49,53 @@ public class DictBizCache {
 	 * 获取字典实体
 	 *
 	 * @param id 主键
-	 * @return
+	 * @return DictBiz
 	 */
 	public static DictBiz getById(Long id) {
 		String keyPrefix = DICT_ID.concat(StringPool.DASH).concat(AuthUtil.getTenantId()).concat(StringPool.COLON);
 		return CacheUtil.get(DICT_CACHE, keyPrefix, id, () -> dictService.getById(id));
 	}
 
+	/**
+	 * 获取字典值
+	 *
+	 * @param code    字典编号枚举
+	 * @param dictKey Integer型字典键
+	 * @return String
+	 */
+	public static String getValue(DictBizEnum code, Integer dictKey) {
+		return getValue(code.getName(), dictKey);
+	}
+
 	/**
 	 * 获取字典值
 	 *
 	 * @param code    字典编号
 	 * @param dictKey Integer型字典键
-	 * @return
+	 * @return String
 	 */
 	public static String getValue(String code, Integer dictKey) {
 		String keyPrefix = DICT_VALUE.concat(StringPool.DASH).concat(AuthUtil.getTenantId()).concat(StringPool.COLON);
 		return CacheUtil.get(DICT_CACHE, keyPrefix + code + StringPool.COLON, String.valueOf(dictKey), () -> dictService.getValue(code, String.valueOf(dictKey)));
 	}
 
+	/**
+	 * 获取字典值
+	 *
+	 * @param code    字典编号枚举
+	 * @param dictKey String型字典键
+	 * @return String
+	 */
+	public static String getValue(DictBizEnum code, String dictKey) {
+		return getValue(code.getName(), dictKey);
+	}
+
 	/**
 	 * 获取字典值
 	 *
 	 * @param code    字典编号
 	 * @param dictKey String型字典键
-	 * @return
+	 * @return String
 	 */
 	public static String getValue(String code, String dictKey) {
 		String keyPrefix = DICT_VALUE.concat(StringPool.DASH).concat(AuthUtil.getTenantId()).concat(StringPool.COLON);
@@ -83,7 +106,7 @@ public class DictBizCache {
 	 * 获取字典集合
 	 *
 	 * @param code 字典编号
-	 * @return
+	 * @return List<DictBiz>
 	 */
 	public static List<DictBiz> getList(String code) {
 		String keyPrefix = DICT_LIST.concat(StringPool.DASH).concat(AuthUtil.getTenantId()).concat(StringPool.COLON);

+ 23 - 0
src/main/java/org/springblade/common/cache/DictCache.java

@@ -16,6 +16,7 @@
  */
 package org.springblade.common.cache;
 
+import org.springblade.common.enums.DictEnum;
 import org.springblade.core.cache.utils.CacheUtil;
 import org.springblade.core.tool.utils.SpringUtil;
 import org.springblade.core.tool.utils.StringPool;
@@ -74,6 +75,17 @@ public class DictCache {
 		}, TENANT_MODE);
 	}
 
+	/**
+	 * 获取字典值
+	 *
+	 * @param code    字典编号枚举
+	 * @param dictKey Integer型字典键
+	 * @return String
+	 */
+	public static String getValue(DictEnum code, Integer dictKey) {
+		return getValue(code.getName(), dictKey);
+	}
+
 	/**
 	 * 获取字典值
 	 *
@@ -85,6 +97,17 @@ public class DictCache {
 		return CacheUtil.get(DICT_CACHE, DICT_VALUE + code + StringPool.COLON, String.valueOf(dictKey), () -> dictService.getValue(code, String.valueOf(dictKey)), TENANT_MODE);
 	}
 
+	/**
+	 * 获取字典值
+	 *
+	 * @param code    字典编号枚举
+	 * @param dictKey String型字典键
+	 * @return String
+	 */
+	public static String getValue(DictEnum code, String dictKey) {
+		return getValue(code.getName(), dictKey);
+	}
+
 	/**
 	 * 获取字典值
 	 *

+ 39 - 0
src/main/java/org/springblade/common/enums/DictBizEnum.java

@@ -0,0 +1,39 @@
+/*
+ *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions are met:
+ *
+ *  Redistributions of source code must retain the above copyright notice,
+ *  this list of conditions and the following disclaimer.
+ *  Redistributions in binary form must reproduce the above copyright
+ *  notice, this list of conditions and the following disclaimer in the
+ *  documentation and/or other materials provided with the distribution.
+ *  Neither the name of the dreamlu.net developer nor the names of its
+ *  contributors may be used to endorse or promote products derived from
+ *  this software without specific prior written permission.
+ *  Author: Chill 庄骞 (smallchill@163.com)
+ */
+package org.springblade.common.enums;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+/**
+ * 业务字典枚举类
+ *
+ * @author Chill
+ */
+@Getter
+@AllArgsConstructor
+public enum DictBizEnum {
+
+	/**
+	 * 测试
+	 */
+	TEST("test"),
+	;
+
+	final String name;
+
+}

+ 91 - 0
src/main/java/org/springblade/common/enums/DictEnum.java

@@ -0,0 +1,91 @@
+/*
+ *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions are met:
+ *
+ *  Redistributions of source code must retain the above copyright notice,
+ *  this list of conditions and the following disclaimer.
+ *  Redistributions in binary form must reproduce the above copyright
+ *  notice, this list of conditions and the following disclaimer in the
+ *  documentation and/or other materials provided with the distribution.
+ *  Neither the name of the dreamlu.net developer nor the names of its
+ *  contributors may be used to endorse or promote products derived from
+ *  this software without specific prior written permission.
+ *  Author: Chill 庄骞 (smallchill@163.com)
+ */
+package org.springblade.common.enums;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+/**
+ * 系统字典枚举类
+ *
+ * @author Chill
+ */
+@Getter
+@AllArgsConstructor
+public enum DictEnum {
+
+	/**
+	 * 性别
+	 */
+	SEX("sex"),
+	/**
+	 * 通知类型
+	 */
+	NOTICE("notice"),
+	/**
+	 * 菜单类型
+	 */
+	MENU_CATEGORY("menu_category"),
+	/**
+	 * 按钮功能
+	 */
+	BUTTON_FUNC("button_func"),
+	/**
+	 * 是否
+	 */
+	YES_NO("yes_no"),
+	/**
+	 * 流程类型
+	 */
+	FLOW("flow"),
+	/**
+	 * 机构类型
+	 */
+	ORG_CATEGORY("org_category"),
+	/**
+	 * 数据权限
+	 */
+	DATA_SCOPE_TYPE("data_scope_type"),
+	/**
+	 * 接口权限
+	 */
+	API_SCOPE_TYPE("api_scope_type"),
+	/**
+	 * 权限类型
+	 */
+	SCOPE_CATEGORY("scope_category"),
+	/**
+	 * 对象存储类型
+	 */
+	OSS("oss"),
+	/**
+	 * 短信服务类型
+	 */
+	SMS("sms"),
+	/**
+	 * 岗位类型
+	 */
+	POST_CATEGORY("post_category"),
+	/**
+	 * 行政区划
+	 */
+	REGION("region"),
+	;
+
+	final String name;
+
+}

+ 2 - 1
src/main/java/org/springblade/modules/desk/wrapper/NoticeWrapper.java

@@ -17,6 +17,7 @@
 package org.springblade.modules.desk.wrapper;
 
 import org.springblade.common.cache.DictCache;
+import org.springblade.common.enums.DictEnum;
 import org.springblade.core.mp.support.BaseEntityWrapper;
 import org.springblade.core.tool.utils.BeanUtil;
 import org.springblade.modules.desk.entity.Notice;
@@ -38,7 +39,7 @@ public class NoticeWrapper extends BaseEntityWrapper<Notice, NoticeVO> {
 	@Override
 	public NoticeVO entityVO(Notice notice) {
 		NoticeVO noticeVO = Objects.requireNonNull(BeanUtil.copy(notice, NoticeVO.class));
-		String dictValue = DictCache.getValue("notice", noticeVO.getCategory());
+		String dictValue = DictCache.getValue(DictEnum.NOTICE, noticeVO.getCategory());
 		noticeVO.setCategoryName(dictValue);
 		return noticeVO;
 	}

+ 3 - 2
src/main/java/org/springblade/modules/resource/wrapper/OssWrapper.java

@@ -17,6 +17,7 @@
 package org.springblade.modules.resource.wrapper;
 
 import org.springblade.common.cache.DictCache;
+import org.springblade.common.enums.DictEnum;
 import org.springblade.core.mp.support.BaseEntityWrapper;
 import org.springblade.core.tool.utils.BeanUtil;
 import org.springblade.modules.resource.entity.Oss;
@@ -38,8 +39,8 @@ public class OssWrapper extends BaseEntityWrapper<Oss, OssVO> {
 	@Override
 	public OssVO entityVO(Oss oss) {
 		OssVO ossVO = Objects.requireNonNull(BeanUtil.copy(oss, OssVO.class));
-		String categoryName = DictCache.getValue("oss", oss.getCategory());
-		String statusName = DictCache.getValue("yes_no", oss.getStatus());
+		String categoryName = DictCache.getValue(DictEnum.OSS, oss.getCategory());
+		String statusName = DictCache.getValue(DictEnum.YES_NO, oss.getStatus());
 		ossVO.setCategoryName(categoryName);
 		ossVO.setStatusName(statusName);
 		return ossVO;

+ 3 - 2
src/main/java/org/springblade/modules/resource/wrapper/SmsWrapper.java

@@ -17,6 +17,7 @@
 package org.springblade.modules.resource.wrapper;
 
 import org.springblade.common.cache.DictCache;
+import org.springblade.common.enums.DictEnum;
 import org.springblade.core.mp.support.BaseEntityWrapper;
 import org.springblade.core.tool.utils.BeanUtil;
 import org.springblade.modules.resource.entity.Sms;
@@ -38,8 +39,8 @@ public class SmsWrapper extends BaseEntityWrapper<Sms, SmsVO> {
 	@Override
 	public SmsVO entityVO(Sms sms) {
 		SmsVO smsVO = Objects.requireNonNull(BeanUtil.copy(sms, SmsVO.class));
-		String categoryName = DictCache.getValue("sms", sms.getCategory());
-		String statusName = DictCache.getValue("yes_no", sms.getStatus());
+		String categoryName = DictCache.getValue(DictEnum.SMS, sms.getCategory());
+		String statusName = DictCache.getValue(DictEnum.YES_NO, sms.getStatus());
 		smsVO.setCategoryName(categoryName);
 		smsVO.setStatusName(statusName);
 		return smsVO;

+ 2 - 1
src/main/java/org/springblade/modules/system/controller/DeptController.java

@@ -21,6 +21,7 @@ import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
 import io.swagger.annotations.*;
 import lombok.AllArgsConstructor;
 import org.springblade.common.cache.DictCache;
+import org.springblade.common.enums.DictEnum;
 import org.springblade.core.boot.ctrl.BladeController;
 import org.springblade.core.cache.utils.CacheUtil;
 import org.springblade.core.launch.constant.AppConstant;
@@ -134,7 +135,7 @@ public class DeptController extends BladeController {
 			CacheUtil.clear(SYS_CACHE);
 			// 返回懒加载树更新节点所需字段
 			Kv kv = Kv.create().set("id", String.valueOf(dept.getId())).set("tenantId", dept.getTenantId())
-				.set("deptCategoryName", DictCache.getValue("org_category", dept.getDeptCategory()));
+				.set("deptCategoryName", DictCache.getValue(DictEnum.ORG_CATEGORY, dept.getDeptCategory()));
 			return R.data(kv);
 		}
 		return R.fail("操作失败");

+ 11 - 6
src/main/java/org/springblade/modules/system/controller/DictBizController.java

@@ -109,8 +109,6 @@ public class DictBizController extends BladeController {
 
 	/**
 	 * 获取字典树形结构
-	 *
-	 * @return
 	 */
 	@GetMapping("/tree")
 	@ApiOperationSupport(order = 5)
@@ -122,8 +120,6 @@ public class DictBizController extends BladeController {
 
 	/**
 	 * 获取字典树形结构
-	 *
-	 * @return
 	 */
 	@GetMapping("/parent-tree")
 	@ApiOperationSupport(order = 5)
@@ -158,8 +154,6 @@ public class DictBizController extends BladeController {
 
 	/**
 	 * 获取字典
-	 *
-	 * @return
 	 */
 	@GetMapping("/dictionary")
 	@ApiOperationSupport(order = 8)
@@ -169,5 +163,16 @@ public class DictBizController extends BladeController {
 		return R.data(tree);
 	}
 
+	/**
+	 * 获取字典树
+	 */
+	@GetMapping("/dictionary-tree")
+	@ApiOperationSupport(order = 9)
+	@ApiOperation(value = "获取字典树", notes = "获取字典树")
+	public R<List<DictBizVO>> dictionaryTree(String code) {
+		List<DictBiz> tree = dictService.getList(code);
+		return R.data(DictBizWrapper.build().listNodeVO(tree));
+	}
+
 
 }

+ 11 - 6
src/main/java/org/springblade/modules/system/controller/DictController.java

@@ -109,8 +109,6 @@ public class DictController extends BladeController {
 
 	/**
 	 * 获取字典树形结构
-	 *
-	 * @return
 	 */
 	@GetMapping("/tree")
 	@ApiOperationSupport(order = 5)
@@ -122,8 +120,6 @@ public class DictController extends BladeController {
 
 	/**
 	 * 获取字典树形结构
-	 *
-	 * @return
 	 */
 	@GetMapping("/parent-tree")
 	@ApiOperationSupport(order = 5)
@@ -157,8 +153,6 @@ public class DictController extends BladeController {
 
 	/**
 	 * 获取字典
-	 *
-	 * @return
 	 */
 	@GetMapping("/dictionary")
 	@ApiOperationSupport(order = 8)
@@ -168,5 +162,16 @@ public class DictController extends BladeController {
 		return R.data(tree);
 	}
 
+	/**
+	 * 获取字典树
+	 */
+	@GetMapping("/dictionary-tree")
+	@ApiOperationSupport(order = 9)
+	@ApiOperation(value = "获取字典树", notes = "获取字典树")
+	public R<List<DictVO>> dictionaryTree(String code) {
+		List<Dict> tree = dictService.getList(code);
+		return R.data(DictWrapper.build().listNodeVO(tree));
+	}
+
 
 }

+ 2 - 1
src/main/java/org/springblade/modules/system/wrapper/ApiScopeWrapper.java

@@ -17,6 +17,7 @@
 package org.springblade.modules.system.wrapper;
 
 import org.springblade.common.cache.DictCache;
+import org.springblade.common.enums.DictEnum;
 import org.springblade.core.mp.support.BaseEntityWrapper;
 import org.springblade.core.tool.utils.BeanUtil;
 import org.springblade.modules.system.entity.ApiScope;
@@ -39,7 +40,7 @@ public class ApiScopeWrapper extends BaseEntityWrapper<ApiScope, ApiScopeVO> {
 	@Override
 	public ApiScopeVO entityVO(ApiScope dataScope) {
 		ApiScopeVO apiScopeVO = Objects.requireNonNull(BeanUtil.copy(dataScope, ApiScopeVO.class));
-		String scopeTypeName = DictCache.getValue("api_scope_type", dataScope.getScopeType());
+		String scopeTypeName = DictCache.getValue(DictEnum.API_SCOPE_TYPE, dataScope.getScopeType());
 		apiScopeVO.setScopeTypeName(scopeTypeName);
 		return apiScopeVO;
 	}

+ 2 - 1
src/main/java/org/springblade/modules/system/wrapper/DataScopeWrapper.java

@@ -17,6 +17,7 @@
 package org.springblade.modules.system.wrapper;
 
 import org.springblade.common.cache.DictCache;
+import org.springblade.common.enums.DictEnum;
 import org.springblade.core.mp.support.BaseEntityWrapper;
 import org.springblade.core.tool.utils.BeanUtil;
 import org.springblade.modules.system.entity.DataScope;
@@ -39,7 +40,7 @@ public class DataScopeWrapper extends BaseEntityWrapper<DataScope, DataScopeVO>
 	@Override
 	public DataScopeVO entityVO(DataScope dataScope) {
 		DataScopeVO dataScopeVO = Objects.requireNonNull(BeanUtil.copy(dataScope, DataScopeVO.class));
-		String scopeTypeName = DictCache.getValue("data_scope_type", dataScope.getScopeType());
+		String scopeTypeName = DictCache.getValue(DictEnum.DATA_SCOPE_TYPE, dataScope.getScopeType());
 		dataScopeVO.setScopeTypeName(scopeTypeName);
 		return dataScopeVO;
 	}

+ 4 - 3
src/main/java/org/springblade/modules/system/wrapper/DeptWrapper.java

@@ -18,6 +18,7 @@ package org.springblade.modules.system.wrapper;
 
 import org.springblade.common.cache.DictCache;
 import org.springblade.common.cache.SysCache;
+import org.springblade.common.enums.DictEnum;
 import org.springblade.core.mp.support.BaseEntityWrapper;
 import org.springblade.core.tool.constant.BladeConstant;
 import org.springblade.core.tool.node.ForestNodeMerger;
@@ -50,7 +51,7 @@ public class DeptWrapper extends BaseEntityWrapper<Dept, DeptVO> {
 			Dept parent = SysCache.getDept(dept.getParentId());
 			deptVO.setParentName(parent.getDeptName());
 		}
-		String category = DictCache.getValue("org_category", dept.getDeptCategory());
+		String category = DictCache.getValue(DictEnum.ORG_CATEGORY, dept.getDeptCategory());
 		deptVO.setDeptCategoryName(category);
 		return deptVO;
 	}
@@ -58,7 +59,7 @@ public class DeptWrapper extends BaseEntityWrapper<Dept, DeptVO> {
 	public List<DeptVO> listNodeVO(List<Dept> list) {
 		List<DeptVO> collect = list.stream().map(dept -> {
 			DeptVO deptVO = BeanUtil.copy(dept, DeptVO.class);
-			String category = DictCache.getValue("org_category", dept.getDeptCategory());
+			String category = DictCache.getValue(DictEnum.ORG_CATEGORY, dept.getDeptCategory());
 			Objects.requireNonNull(deptVO).setDeptCategoryName(category);
 			return deptVO;
 		}).collect(Collectors.toList());
@@ -67,7 +68,7 @@ public class DeptWrapper extends BaseEntityWrapper<Dept, DeptVO> {
 
 	public List<DeptVO> listNodeLazyVO(List<DeptVO> list) {
 		List<DeptVO> collect = list.stream().peek(dept -> {
-			String category = DictCache.getValue("org_category", dept.getDeptCategory());
+			String category = DictCache.getValue(DictEnum.ORG_CATEGORY, dept.getDeptCategory());
 			Objects.requireNonNull(dept).setDeptCategoryName(category);
 		}).collect(Collectors.toList());
 		return ForestNodeMerger.merge(collect);

+ 4 - 3
src/main/java/org/springblade/modules/system/wrapper/MenuWrapper.java

@@ -18,6 +18,7 @@ package org.springblade.modules.system.wrapper;
 
 import org.springblade.common.cache.DictCache;
 import org.springblade.common.cache.SysCache;
+import org.springblade.common.enums.DictEnum;
 import org.springblade.core.mp.support.BaseEntityWrapper;
 import org.springblade.core.tool.constant.BladeConstant;
 import org.springblade.core.tool.node.ForestNodeMerger;
@@ -50,9 +51,9 @@ public class MenuWrapper extends BaseEntityWrapper<Menu, MenuVO> {
 			Menu parent = SysCache.getMenu(menu.getParentId());
 			menuVO.setParentName(parent.getName());
 		}
-		String category = DictCache.getValue("menu_category", Func.toInt(menuVO.getCategory()));
-		String action = DictCache.getValue("button_func", Func.toInt(menuVO.getAction()));
-		String open = DictCache.getValue("yes_no", Func.toInt(menuVO.getIsOpen()));
+		String category = DictCache.getValue(DictEnum.MENU_CATEGORY, Func.toInt(menuVO.getCategory()));
+		String action = DictCache.getValue(DictEnum.BUTTON_FUNC, Func.toInt(menuVO.getAction()));
+		String open = DictCache.getValue(DictEnum.YES_NO, Func.toInt(menuVO.getIsOpen()));
 		menuVO.setCategoryName(category);
 		menuVO.setActionName(action);
 		menuVO.setIsOpenName(open);

+ 2 - 1
src/main/java/org/springblade/modules/system/wrapper/PostWrapper.java

@@ -17,6 +17,7 @@
 package org.springblade.modules.system.wrapper;
 
 import org.springblade.common.cache.DictCache;
+import org.springblade.common.enums.DictEnum;
 import org.springblade.core.mp.support.BaseEntityWrapper;
 import org.springblade.core.tool.utils.BeanUtil;
 import org.springblade.modules.system.entity.Post;
@@ -38,7 +39,7 @@ public class PostWrapper extends BaseEntityWrapper<Post, PostVO> {
 	@Override
 	public PostVO entityVO(Post post) {
 		PostVO postVO = Objects.requireNonNull(BeanUtil.copy(post, PostVO.class));
-		String categoryName = DictCache.getValue("post_category", post.getCategory());
+		String categoryName = DictCache.getValue(DictEnum.POST_CATEGORY, post.getCategory());
 		postVO.setCategoryName(categoryName);
 		return postVO;
 	}

+ 2 - 1
src/main/java/org/springblade/modules/system/wrapper/UserWrapper.java

@@ -18,6 +18,7 @@ package org.springblade.modules.system.wrapper;
 
 import org.springblade.common.cache.DictCache;
 import org.springblade.common.cache.SysCache;
+import org.springblade.common.enums.DictEnum;
 import org.springblade.core.mp.support.BaseEntityWrapper;
 import org.springblade.core.tool.utils.BeanUtil;
 import org.springblade.core.tool.utils.Func;
@@ -50,7 +51,7 @@ public class UserWrapper extends BaseEntityWrapper<User, UserVO> {
 		userVO.setRoleName(Func.join(roleName));
 		userVO.setDeptName(Func.join(deptName));
 		userVO.setPostName(Func.join(postName));
-		userVO.setSexName(DictCache.getValue("sex", Func.toInt(user.getSex())));
+		userVO.setSexName(DictCache.getValue(DictEnum.SEX, Func.toInt(user.getSex())));
 		return userVO;
 	}