From fc444728c90e1495f0b69a58a679e7920326d602 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Wed, 13 Jan 2021 01:09:26 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E5=A2=9E=E5=8A=A0=E5=AD=97=E5=85=B8?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E7=9A=84=E7=BC=93=E5=AD=98=E4=B8=8E=20util?= =?UTF-8?q?=202.=20=E5=BC=95=E5=85=A5=20Excel=20=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 85 ++----------------- .../dict/config/DictConfiguration.java | 18 ++++ .../framework/dict/core/util/DictUtils.java | 9 ++ .../dashboard/framework/excel/Excel.java | 1 + .../dashboard/framework/excel/Excels.java | 1 + .../excel/core/annotations/DictFormat.java | 19 +++++ .../excel/core/convert/DictConvert.java | 64 ++++++++++++++ .../framework/excel/core/package-info.java | 1 + .../framework/excel/package-info.java | 4 + .../controller/dept/SysDeptController.java | 4 +- .../controller/dept/SysPostController.java | 2 +- .../dict/SysDictDataController.java | 4 +- .../dict/SysDictTypeController.java | 4 +- .../permission/SysMenuController.java | 2 +- .../permission/SysPermissionController.java | 4 +- .../permission/SysRoleController.java | 4 +- .../controller/user/SysUserController.java | 4 +- ...espVO.java => SysUserExcelRespBackVO.java} | 8 +- .../user/vo/user/SysUserExcelVO.java | 54 ++++++++++++ .../system/enums/dict/DictTypeEnum.java | 23 +++++ .../service/dict/SysDictDataService.java | 13 ++- .../dict/impl/SysDictDataServiceImpl.java | 47 ++++++++++ 22 files changed, 277 insertions(+), 98 deletions(-) create mode 100644 src/main/java/cn/iocoder/dashboard/framework/dict/config/DictConfiguration.java create mode 100644 src/main/java/cn/iocoder/dashboard/framework/excel/core/annotations/DictFormat.java create mode 100644 src/main/java/cn/iocoder/dashboard/framework/excel/core/convert/DictConvert.java create mode 100644 src/main/java/cn/iocoder/dashboard/framework/excel/core/package-info.java create mode 100644 src/main/java/cn/iocoder/dashboard/framework/excel/package-info.java rename src/main/java/cn/iocoder/dashboard/modules/system/controller/user/vo/user/{SysUserExcelRespVO.java => SysUserExcelRespBackVO.java} (93%) create mode 100644 src/main/java/cn/iocoder/dashboard/modules/system/controller/user/vo/user/SysUserExcelVO.java create mode 100644 src/main/java/cn/iocoder/dashboard/modules/system/enums/dict/DictTypeEnum.java diff --git a/pom.xml b/pom.xml index d49efbdfb..01c8d42be 100644 --- a/pom.xml +++ b/pom.xml @@ -11,6 +11,7 @@ ruoyi http://www.ruoyi.vip 若依管理系统 + jar UTF-8 @@ -54,19 +55,13 @@ 0.9.1 1.2.75 5.5.6 + 2.2.7 - - - - - - - @@ -74,13 +69,6 @@ - - - - - - - @@ -100,30 +88,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - @@ -138,39 +102,11 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -184,16 +120,6 @@ - - - - - - - - - jar - @@ -306,6 +232,13 @@ hutool-captcha ${hutool.version} + + + com.alibaba + easyexcel + ${easyexcel.verion} + + diff --git a/src/main/java/cn/iocoder/dashboard/framework/dict/config/DictConfiguration.java b/src/main/java/cn/iocoder/dashboard/framework/dict/config/DictConfiguration.java new file mode 100644 index 000000000..d2ff54d10 --- /dev/null +++ b/src/main/java/cn/iocoder/dashboard/framework/dict/config/DictConfiguration.java @@ -0,0 +1,18 @@ +package cn.iocoder.dashboard.framework.dict.config; + +import cn.iocoder.dashboard.framework.dict.core.service.DictDataFrameworkService; +import cn.iocoder.dashboard.framework.dict.core.util.DictUtils; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class DictConfiguration { + + @Bean + @SuppressWarnings("InstantiationOfUtilityClass") + public DictUtils dictUtils(DictDataFrameworkService service) { + DictUtils.init(service); + return new DictUtils(); + } + +} diff --git a/src/main/java/cn/iocoder/dashboard/framework/dict/core/util/DictUtils.java b/src/main/java/cn/iocoder/dashboard/framework/dict/core/util/DictUtils.java index 6e8fe2164..bb329ed21 100644 --- a/src/main/java/cn/iocoder/dashboard/framework/dict/core/util/DictUtils.java +++ b/src/main/java/cn/iocoder/dashboard/framework/dict/core/util/DictUtils.java @@ -1,6 +1,7 @@ package cn.iocoder.dashboard.framework.dict.core.util; import cn.iocoder.dashboard.framework.dict.core.service.DictDataFrameworkService; +import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dict.SysDictDataDO; import lombok.extern.slf4j.Slf4j; /** @@ -16,4 +17,12 @@ public class DictUtils { log.info("[init][初始化 DictUtils 成功]"); } + public static SysDictDataDO getDictDataFromCache(String type, String value) { + return service.getDictDataFromCache(type, value); + } + + public static SysDictDataDO parseDictDataFromCache(String type, String label) { + return service.getDictDataFromCache(type, label); + } + } diff --git a/src/main/java/cn/iocoder/dashboard/framework/excel/Excel.java b/src/main/java/cn/iocoder/dashboard/framework/excel/Excel.java index 6b793269d..490a01b74 100644 --- a/src/main/java/cn/iocoder/dashboard/framework/excel/Excel.java +++ b/src/main/java/cn/iocoder/dashboard/framework/excel/Excel.java @@ -11,6 +11,7 @@ import java.math.BigDecimal; * * @author ruoyi */ +@Deprecated @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) public @interface Excel { diff --git a/src/main/java/cn/iocoder/dashboard/framework/excel/Excels.java b/src/main/java/cn/iocoder/dashboard/framework/excel/Excels.java index 3264f7148..ad767b596 100644 --- a/src/main/java/cn/iocoder/dashboard/framework/excel/Excels.java +++ b/src/main/java/cn/iocoder/dashboard/framework/excel/Excels.java @@ -10,6 +10,7 @@ import java.lang.annotation.Target; * * @author ruoyi */ +@Deprecated @Target(ElementType.FIELD) @Retention(RetentionPolicy.RUNTIME) public @interface Excels diff --git a/src/main/java/cn/iocoder/dashboard/framework/excel/core/annotations/DictFormat.java b/src/main/java/cn/iocoder/dashboard/framework/excel/core/annotations/DictFormat.java new file mode 100644 index 000000000..ae3144016 --- /dev/null +++ b/src/main/java/cn/iocoder/dashboard/framework/excel/core/annotations/DictFormat.java @@ -0,0 +1,19 @@ +package cn.iocoder.dashboard.framework.excel.core.annotations; + +import cn.iocoder.dashboard.modules.system.enums.dict.DictTypeEnum; + +import java.lang.annotation.*; + +/** + * 字典格式化 + * + * 实现将字典数据的值,格式化成字典数据的标签 + */ +@Target({ElementType.FIELD}) +@Retention(RetentionPolicy.RUNTIME) +@Inherited +public @interface DictFormat { + + DictTypeEnum value(); + +} diff --git a/src/main/java/cn/iocoder/dashboard/framework/excel/core/convert/DictConvert.java b/src/main/java/cn/iocoder/dashboard/framework/excel/core/convert/DictConvert.java new file mode 100644 index 000000000..1a65505d9 --- /dev/null +++ b/src/main/java/cn/iocoder/dashboard/framework/excel/core/convert/DictConvert.java @@ -0,0 +1,64 @@ +package cn.iocoder.dashboard.framework.excel.core.convert; + + +import cn.hutool.core.convert.Convert; +import cn.iocoder.dashboard.framework.dict.core.util.DictUtils; +import cn.iocoder.dashboard.framework.excel.core.annotations.DictFormat; +import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dict.SysDictDataDO; +import cn.iocoder.dashboard.modules.system.enums.dict.DictTypeEnum; +import com.alibaba.excel.converters.Converter; +import com.alibaba.excel.enums.CellDataTypeEnum; +import com.alibaba.excel.metadata.CellData; +import com.alibaba.excel.metadata.GlobalConfiguration; +import com.alibaba.excel.metadata.property.ExcelContentProperty; +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class DictConvert implements Converter { + + @Override + public Class supportJavaTypeKey() { + throw new UnsupportedOperationException("暂不支持,也不需要"); + } + + @Override + public CellDataTypeEnum supportExcelTypeKey() { + throw new UnsupportedOperationException("暂不支持,也不需要"); + } + + @Override + public Object convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, + GlobalConfiguration globalConfiguration) { + // 使用字典解析 + DictTypeEnum type = getType(contentProperty); + String label = cellData.getStringValue(); + SysDictDataDO dictData = DictUtils.parseDictDataFromCache(type.getValue(), label); + if (dictData == null) { + log.error("[convertToJavaData][type({}) 解析不掉 label({})]", type, label); + return null; + } + // 将 String 的 value 转换成对应的属性 + Class fieldClazz = contentProperty.getField().getType(); + return Convert.convert(fieldClazz, dictData.getValue()); + } + + @Override + public CellData convertToExcelData(Object object, ExcelContentProperty contentProperty, + GlobalConfiguration globalConfiguration) { + // 使用字典格式化 + DictTypeEnum type = getType(contentProperty); + String value = String.valueOf(object); + SysDictDataDO dictData = DictUtils.getDictDataFromCache(type.getValue(), value); + if (dictData == null) { + log.error("[convertToExcelData][type({}) 转换不了 label({})]", type, value); + return null; + } + // 生成 Excel 小表格 + return new CellData<>(dictData.getValue()); + } + + private static DictTypeEnum getType(ExcelContentProperty contentProperty) { + return contentProperty.getField().getAnnotation(DictFormat.class).value(); + } + +} diff --git a/src/main/java/cn/iocoder/dashboard/framework/excel/core/package-info.java b/src/main/java/cn/iocoder/dashboard/framework/excel/core/package-info.java new file mode 100644 index 000000000..54ffd9e8e --- /dev/null +++ b/src/main/java/cn/iocoder/dashboard/framework/excel/core/package-info.java @@ -0,0 +1 @@ +package cn.iocoder.dashboard.framework.excel.core; diff --git a/src/main/java/cn/iocoder/dashboard/framework/excel/package-info.java b/src/main/java/cn/iocoder/dashboard/framework/excel/package-info.java new file mode 100644 index 000000000..293498c5a --- /dev/null +++ b/src/main/java/cn/iocoder/dashboard/framework/excel/package-info.java @@ -0,0 +1,4 @@ +/** + * 基于 EasyExcel 实现 Excel 相关的操作 + */ +package cn.iocoder.dashboard.framework.excel; diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/controller/dept/SysDeptController.java b/src/main/java/cn/iocoder/dashboard/modules/system/controller/dept/SysDeptController.java index 869b57931..0105e08c3 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/controller/dept/SysDeptController.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/controller/dept/SysDeptController.java @@ -48,7 +48,7 @@ public class SysDeptController { } @ApiOperation("获得部门信息") - @ApiImplicitParam(name = "id", value = "编号", readOnly = true, example = "1024") + @ApiImplicitParam(name = "id", value = "编号", readOnly = true, example = "1024", dataTypeClass = Long.class) // @PreAuthorize("@ss.hasPermi('system:dept:query')") @GetMapping("/get") public CommonResult getDept(@RequestParam("id") Long id) { @@ -74,7 +74,7 @@ public class SysDeptController { } @ApiOperation("删除部门") - @ApiImplicitParam(name = "id", value = "编号", readOnly = true, example = "1024") + @ApiImplicitParam(name = "id", value = "编号", readOnly = true, example = "1024", dataTypeClass = Long.class) @PostMapping("delete") // @PreAuthorize("@ss.hasPermi('system:dept:remove')") // @Log(title = "部门管理", businessType = BusinessType.DELETE) diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/controller/dept/SysPostController.java b/src/main/java/cn/iocoder/dashboard/modules/system/controller/dept/SysPostController.java index 110540c92..cc52cf846 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/controller/dept/SysPostController.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/controller/dept/SysPostController.java @@ -73,7 +73,7 @@ public class SysPostController { } @ApiOperation("获得岗位信息") - @ApiImplicitParam(name = "id", value = "岗位编号", readOnly = true, example = "1024") + @ApiImplicitParam(name = "id", value = "岗位编号", readOnly = true, example = "1024", dataTypeClass = Long.class) // @PreAuthorize("@ss.hasPermi('system:post:query')") @GetMapping(value = "/get") public CommonResult getPost(@RequestParam("id") Long id) { diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/controller/dict/SysDictDataController.java b/src/main/java/cn/iocoder/dashboard/modules/system/controller/dict/SysDictDataController.java index b34557d97..ffc9c30d1 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/controller/dict/SysDictDataController.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/controller/dict/SysDictDataController.java @@ -41,7 +41,7 @@ public class SysDictDataController { } @ApiOperation("/查询字典数据详细") - @ApiImplicitParam(name = "id", value = "编号", readOnly = true, example = "1024") + @ApiImplicitParam(name = "id", value = "编号", readOnly = true, example = "1024", dataTypeClass = Long.class) @GetMapping(value = "/get") // @PreAuthorize("@ss.hasPermi('system:dict:query')") public CommonResult getDictData(@RequestParam("id") Long id) { @@ -67,7 +67,7 @@ public class SysDictDataController { } @ApiOperation("删除字典数据") - @ApiImplicitParam(name = "id", value = "编号", readOnly = true, example = "1024") + @ApiImplicitParam(name = "id", value = "编号", readOnly = true, example = "1024", dataTypeClass = Long.class) @PostMapping("/delete") // @PreAuthorize("@ss.hasPermi('system:dict:remove')") public CommonResult deleteDictData(Long id) { diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/controller/dict/SysDictTypeController.java b/src/main/java/cn/iocoder/dashboard/modules/system/controller/dict/SysDictTypeController.java index b9a7e54bf..a7e8bbf19 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/controller/dict/SysDictTypeController.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/controller/dict/SysDictTypeController.java @@ -33,7 +33,7 @@ public class SysDictTypeController { } @ApiOperation("/查询字典类型详细") - @ApiImplicitParam(name = "id", value = "编号", readOnly = true, example = "1024") + @ApiImplicitParam(name = "id", value = "编号", readOnly = true, example = "1024", dataTypeClass = Long.class) @GetMapping(value = "/get") // @PreAuthorize("@ss.hasPermi('system:dict:query')") public CommonResult getDictType(@RequestParam("id") Long id) { @@ -59,7 +59,7 @@ public class SysDictTypeController { } @ApiOperation("删除字典类型") - @ApiImplicitParam(name = "id", value = "编号", readOnly = true, example = "1024") + @ApiImplicitParam(name = "id", value = "编号", readOnly = true, example = "1024", dataTypeClass = Long.class) @PostMapping("/delete") // @PreAuthorize("@ss.hasPermi('system:dict:remove')") public CommonResult deleteDictType(Long id) { diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/controller/permission/SysMenuController.java b/src/main/java/cn/iocoder/dashboard/modules/system/controller/permission/SysMenuController.java index 18edfaefc..d2f93c777 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/controller/permission/SysMenuController.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/controller/permission/SysMenuController.java @@ -88,7 +88,7 @@ public class SysMenuController { @ApiOperation("删除菜单") @PostMapping("/delete") - @ApiImplicitParam(name = "id", value = "角色编号", required= true, example = "1024") + @ApiImplicitParam(name = "id", value = "角色编号", required= true, example = "1024", dataTypeClass = Long.class) // @Log(title = "菜单管理", businessType = BusinessType.DELETE) public CommonResult deleteMenu(@RequestParam("id") Long id) { menuService.deleteMenu(id); diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/controller/permission/SysPermissionController.java b/src/main/java/cn/iocoder/dashboard/modules/system/controller/permission/SysPermissionController.java index 3e0f8ae3f..fe4e74ab8 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/controller/permission/SysPermissionController.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/controller/permission/SysPermissionController.java @@ -30,8 +30,8 @@ public class SysPermissionController { private SysPermissionService permissionService; @ApiOperation("获得角色拥有的菜单编号") + @ApiImplicitParam(name = "roleId", value = "角色编号", required = true, dataTypeClass = Long.class) @GetMapping("/list-role-resources") - @ApiImplicitParam(name = "roleId", value = "角色编号", required = true) // @RequiresPermissions("system:permission:assign-role-menu") public CommonResult> listRoleMenus(Long roleId) { return success(permissionService.listRoleMenuIds(roleId)); @@ -55,7 +55,7 @@ public class SysPermissionController { } @ApiOperation("获得管理员拥有的角色编号列表") - @ApiImplicitParam(name = "userId", value = "用户编号", required = true) + @ApiImplicitParam(name = "userId", value = "用户编号", required = true, dataTypeClass = Long.class) @GetMapping("/list-user-roles") // @RequiresPermissions("system:permission:assign-user-role") public CommonResult> listAdminRoles(@RequestParam("userId") Long userId) { diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/controller/permission/SysRoleController.java b/src/main/java/cn/iocoder/dashboard/modules/system/controller/permission/SysRoleController.java index 75565c6d6..358dc798b 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/controller/permission/SysRoleController.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/controller/permission/SysRoleController.java @@ -64,10 +64,10 @@ public class SysRoleController { @ApiOperation("删除角色") @PostMapping("/delete") - @ApiImplicitParam(name = "id", value = "角色编号", required = true, example = "1024") + @ApiImplicitParam(name = "id", value = "角色编号", required = true, example = "1024", dataTypeClass = Long.class) // @PreAuthorize("@ss.hasPermi('system:role:remove')") // @Log(title = "角色管理", businessType = BusinessType.DELETE) - public CommonResult remove(@RequestParam("id") Long id) { + public CommonResult deleteRole(@RequestParam("id") Long id) { roleService.deleteRole(id); return success(true); } diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/controller/user/SysUserController.java b/src/main/java/cn/iocoder/dashboard/modules/system/controller/user/SysUserController.java index 1a6288517..7e392e762 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/controller/user/SysUserController.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/controller/user/SysUserController.java @@ -63,7 +63,7 @@ public class SysUserController { * 根据用户编号获取详细信息 */ @ApiOperation("获得用户详情") - @ApiImplicitParam(name = "id", value = "编号", readOnly = true, example = "1024") + @ApiImplicitParam(name = "id", value = "编号", readOnly = true, example = "1024", dataTypeClass = Long.class) @GetMapping("/get") // @PreAuthorize("@ss.hasPermi('system:user:query')") public CommonResult getInfo(@RequestParam("id") Long id) { @@ -89,7 +89,7 @@ public class SysUserController { } @ApiOperation("删除用户") - @ApiImplicitParam(name = "id", value = "编号", readOnly = true, example = "1024") + @ApiImplicitParam(name = "id", value = "编号", readOnly = true, example = "1024", dataTypeClass = Long.class) @PostMapping("/delete") // @PreAuthorize("@ss.hasPermi('system:user:remove')") // @Log(title = "用户管理", businessType = BusinessType.DELETE) diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/controller/user/vo/user/SysUserExcelRespVO.java b/src/main/java/cn/iocoder/dashboard/modules/system/controller/user/vo/user/SysUserExcelRespBackVO.java similarity index 93% rename from src/main/java/cn/iocoder/dashboard/modules/system/controller/user/vo/user/SysUserExcelRespVO.java rename to src/main/java/cn/iocoder/dashboard/modules/system/controller/user/vo/user/SysUserExcelRespBackVO.java index 928d21968..0c97d2fc2 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/controller/user/vo/user/SysUserExcelRespVO.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/controller/user/vo/user/SysUserExcelRespBackVO.java @@ -11,20 +11,14 @@ import java.util.Date; * 用户 Excel 导出响应 VO */ @Data -public class SysUserExcelRespVO { +public class SysUserExcelRespBackVO { @Excel(name = "用户序号", cellType = Excel.ColumnType.NUMERIC, prompt = "用户编号") private Long id; - /** - * 用户账号 - */ @Excel(name = "登录名称") private String username; - /** - * 用户昵称 - */ @Excel(name = "用户名称") private String nickname; diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/controller/user/vo/user/SysUserExcelVO.java b/src/main/java/cn/iocoder/dashboard/modules/system/controller/user/vo/user/SysUserExcelVO.java new file mode 100644 index 000000000..b3ca002dd --- /dev/null +++ b/src/main/java/cn/iocoder/dashboard/modules/system/controller/user/vo/user/SysUserExcelVO.java @@ -0,0 +1,54 @@ +package cn.iocoder.dashboard.modules.system.controller.user.vo.user; + +import cn.iocoder.dashboard.framework.excel.core.annotations.DictFormat; +import cn.iocoder.dashboard.framework.excel.core.convert.DictConvert; +import com.alibaba.excel.annotation.ExcelProperty; +import lombok.Data; + +import java.util.Date; + +import static cn.iocoder.dashboard.modules.system.enums.dict.DictTypeEnum.SYS_COMMON_STATUS; +import static cn.iocoder.dashboard.modules.system.enums.dict.DictTypeEnum.SYS_USER_SEX; + +/** + * 用户 Excel 导出 VO + */ +@Data +public class SysUserExcelVO { + + @ExcelProperty("用户编号") + private Long id; + + @ExcelProperty("用户名称") + private String username; + + @ExcelProperty("用户名称") + private String nickname; + + @ExcelProperty("用户邮箱") + private String email; + + @ExcelProperty("手机号码") + private String mobile; + + @ExcelProperty(value = "用户性别", converter = DictConvert.class) + @DictFormat(SYS_USER_SEX) + private Integer sex; + + @ExcelProperty(value = "帐号状态", converter = DictConvert.class) + @DictFormat(SYS_COMMON_STATUS) + private Integer status; + + @ExcelProperty("最后登录IP") + private String loginIp; + + @ExcelProperty("最后登录时间") + private Date loginDate; + + @ExcelProperty("部门名称") + private String deptName; + + @ExcelProperty("部门负责人") + private String deptLeader; + +} diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/enums/dict/DictTypeEnum.java b/src/main/java/cn/iocoder/dashboard/modules/system/enums/dict/DictTypeEnum.java new file mode 100644 index 000000000..c4147f032 --- /dev/null +++ b/src/main/java/cn/iocoder/dashboard/modules/system/enums/dict/DictTypeEnum.java @@ -0,0 +1,23 @@ +package cn.iocoder.dashboard.modules.system.enums.dict; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * 字典类型的类型枚举 + */ +@Getter +@AllArgsConstructor +public enum DictTypeEnum { + + SYS_USER_SEX("sys_user_sex"), // 用户性别 + SYS_COMMON_STATUS("sys_common_status"), // 系统状态 + ; + + + /** + * 值 + */ + private final String value; + +} diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/service/dict/SysDictDataService.java b/src/main/java/cn/iocoder/dashboard/modules/system/service/dict/SysDictDataService.java index 1cfd5b331..9606972c4 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/service/dict/SysDictDataService.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/service/dict/SysDictDataService.java @@ -1,6 +1,7 @@ package cn.iocoder.dashboard.modules.system.service.dict; import cn.iocoder.dashboard.common.pojo.PageResult; +import cn.iocoder.dashboard.framework.dict.core.service.DictDataFrameworkService; import cn.iocoder.dashboard.modules.system.controller.dict.vo.data.SysDictDataCreateReqVO; import cn.iocoder.dashboard.modules.system.controller.dict.vo.data.SysDictDataPageReqVO; import cn.iocoder.dashboard.modules.system.controller.dict.vo.data.SysDictDataUpdateReqVO; @@ -13,8 +14,18 @@ import java.util.List; * * @author ruoyi */ -public interface SysDictDataService { +public interface SysDictDataService extends DictDataFrameworkService { + /** + * 初始化,主要是初始化缓存 + */ + void init(); + + /** + * 获得字典数据列表 + * + * @return 字典数据全列表 + */ List listDictDatas(); /** diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/service/dict/impl/SysDictDataServiceImpl.java b/src/main/java/cn/iocoder/dashboard/modules/system/service/dict/impl/SysDictDataServiceImpl.java index 23ad9e060..f15b7fb5a 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/service/dict/impl/SysDictDataServiceImpl.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/service/dict/impl/SysDictDataServiceImpl.java @@ -12,9 +12,11 @@ import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dict.SysDictData import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dict.SysDictTypeDO; import cn.iocoder.dashboard.modules.system.service.dict.SysDictDataService; import cn.iocoder.dashboard.modules.system.service.dict.SysDictTypeService; +import com.google.common.collect.ImmutableTable; import org.springframework.stereotype.Service; import javax.annotation.Resource; +import java.util.ArrayList; import java.util.Comparator; import java.util.List; @@ -32,12 +34,42 @@ public class SysDictDataServiceImpl implements SysDictDataService { .comparing(SysDictDataDO::getDictType) .thenComparingInt(SysDictDataDO::getSort); + /** + * 字典数据缓存,第二个 key 使用 label + * + * key1:字典类型 dictType + * key2:字典标签 label + */ + private ImmutableTable labelDictDataCache; + /** + * 字典数据缓存,第二个 key 使用 value + * + * key1:字典类型 dictType + * key2:字典值 value + */ + private ImmutableTable valueDictDataCache; + @Resource private SysDictTypeService dictTypeService; @Resource private SysDictDataMapper dictDataMapper; + @Override + public void init() { + // 获得字典数据 + List list = this.listDictDatas(); + // 构建缓存 + ImmutableTable.Builder labelDictDataBuilder = ImmutableTable.builder(); + ImmutableTable.Builder valueDictDataBuilder = ImmutableTable.builder(); + list.forEach(dictData -> { + labelDictDataBuilder.put(dictData.getDictType(), dictData.getLabel(), dictData); + valueDictDataBuilder.put(dictData.getDictType(), dictData.getValue(), dictData); + }); + labelDictDataCache = labelDictDataBuilder.build(); + valueDictDataCache = valueDictDataBuilder.build(); + } + @Override public List listDictDatas() { List list = dictDataMapper.selectList(); @@ -130,4 +162,19 @@ public class SysDictDataServiceImpl implements SysDictDataService { } } + @Override + public SysDictDataDO getDictDataFromCache(String type, String value) { + return valueDictDataCache.get(type, value); + } + + @Override + public SysDictDataDO parseDictDataFromCache(String type, String label) { + return labelDictDataCache.get(type, label); + } + + @Override + public List listDictDatasFromCache(String type) { + return new ArrayList<>(labelDictDataCache.row(type).values()); + } + }