Commit fc444728c90e1495f0b69a58a679e7920326d602
1 parent
ec009365
1. 增加字典数据的缓存与 util
2. 引入 Excel 组件
Showing
22 changed files
with
277 additions
and
98 deletions
pom.xml
| ... | ... | @@ -11,6 +11,7 @@ |
| 11 | 11 | <name>ruoyi</name> |
| 12 | 12 | <url>http://www.ruoyi.vip</url> |
| 13 | 13 | <description>若依管理系统</description> |
| 14 | + <packaging>jar</packaging> | |
| 14 | 15 | |
| 15 | 16 | <properties> |
| 16 | 17 | <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> |
| ... | ... | @@ -54,19 +55,13 @@ |
| 54 | 55 | <jjwt.version>0.9.1</jjwt.version> |
| 55 | 56 | <fastjson.version>1.2.75</fastjson.version> |
| 56 | 57 | <hutool.version>5.5.6</hutool.version> |
| 58 | + <easyexcel.verion>2.2.7</easyexcel.verion> | |
| 57 | 59 | </properties> |
| 58 | 60 | |
| 59 | 61 | <!-- 依赖声明 --> |
| 60 | 62 | <dependencyManagement> |
| 61 | 63 | <dependencies> |
| 62 | 64 | |
| 63 | -<!-- <!–阿里数据库连接池 –>--> | |
| 64 | -<!-- <dependency>--> | |
| 65 | -<!-- <groupId>com.alibaba</groupId>--> | |
| 66 | -<!-- <artifactId>druid-spring-boot-starter</artifactId>--> | |
| 67 | -<!-- <version>${druid.version}</version>--> | |
| 68 | -<!-- </dependency>--> | |
| 69 | - | |
| 70 | 65 | <!-- <!– 解析客户端操作系统、浏览器等 –>--> |
| 71 | 66 | <!-- <dependency>--> |
| 72 | 67 | <!-- <groupId>eu.bitwalker</groupId>--> |
| ... | ... | @@ -74,13 +69,6 @@ |
| 74 | 69 | <!-- <version>${bitwalker.version}</version>--> |
| 75 | 70 | <!-- </dependency>--> |
| 76 | 71 | |
| 77 | -<!-- <!– pagehelper 分页插件 –>--> | |
| 78 | -<!-- <dependency>--> | |
| 79 | -<!-- <groupId>com.github.pagehelper</groupId>--> | |
| 80 | -<!-- <artifactId>pagehelper-spring-boot-starter</artifactId>--> | |
| 81 | -<!-- <version>${pagehelper.boot.version}</version>--> | |
| 82 | -<!-- </dependency>--> | |
| 83 | - | |
| 84 | 72 | <!-- <!– 获取系统信息 –>--> |
| 85 | 73 | <!-- <dependency>--> |
| 86 | 74 | <!-- <groupId>com.github.oshi</groupId>--> |
| ... | ... | @@ -100,30 +88,6 @@ |
| 100 | 88 | <!-- <version>${jna.version}</version>--> |
| 101 | 89 | <!-- </dependency>--> |
| 102 | 90 | |
| 103 | -<!-- <!– swagger2–>--> | |
| 104 | -<!-- <dependency>--> | |
| 105 | -<!-- <groupId>io.springfox</groupId>--> | |
| 106 | -<!-- <artifactId>springfox-swagger2</artifactId>--> | |
| 107 | -<!-- <version>${swagger.version}</version>--> | |
| 108 | -<!-- <exclusions>--> | |
| 109 | -<!-- <exclusion>--> | |
| 110 | -<!-- <groupId>io.swagger</groupId>--> | |
| 111 | -<!-- <artifactId>swagger-annotations</artifactId>--> | |
| 112 | -<!-- </exclusion>--> | |
| 113 | -<!-- <exclusion>--> | |
| 114 | -<!-- <groupId>io.swagger</groupId>--> | |
| 115 | -<!-- <artifactId>swagger-models</artifactId>--> | |
| 116 | -<!-- </exclusion>--> | |
| 117 | -<!-- </exclusions>--> | |
| 118 | -<!-- </dependency>--> | |
| 119 | - | |
| 120 | -<!-- <!– swagger2-UI–>--> | |
| 121 | -<!-- <dependency>--> | |
| 122 | -<!-- <groupId>io.springfox</groupId>--> | |
| 123 | -<!-- <artifactId>springfox-swagger-ui</artifactId>--> | |
| 124 | -<!-- <version>${swagger.version}</version>--> | |
| 125 | -<!-- </dependency>--> | |
| 126 | - | |
| 127 | 91 | <!-- <!–io常用工具类 –>--> |
| 128 | 92 | <!-- <dependency>--> |
| 129 | 93 | <!-- <groupId>commons-io</groupId>--> |
| ... | ... | @@ -138,13 +102,6 @@ |
| 138 | 102 | <!-- <version>${commons.fileupload.version}</version>--> |
| 139 | 103 | <!-- </dependency>--> |
| 140 | 104 | |
| 141 | -<!-- <!– excel工具 –>--> | |
| 142 | -<!-- <dependency>--> | |
| 143 | -<!-- <groupId>org.apache.poi</groupId>--> | |
| 144 | -<!-- <artifactId>poi-ooxml</artifactId>--> | |
| 145 | -<!-- <version>${poi.version}</version>--> | |
| 146 | -<!-- </dependency>--> | |
| 147 | - | |
| 148 | 105 | <!-- <!–velocity代码生成使用模板 –>--> |
| 149 | 106 | <!-- <dependency>--> |
| 150 | 107 | <!-- <groupId>org.apache.velocity</groupId>--> |
| ... | ... | @@ -152,27 +109,6 @@ |
| 152 | 109 | <!-- <version>${velocity.version}</version>--> |
| 153 | 110 | <!-- </dependency>--> |
| 154 | 111 | |
| 155 | -<!-- <!– 阿里JSON解析器 –>--> | |
| 156 | -<!-- <dependency>--> | |
| 157 | -<!-- <groupId>com.alibaba</groupId>--> | |
| 158 | -<!-- <artifactId>fastjson</artifactId>--> | |
| 159 | -<!-- <version>${fastjson.version}</version>--> | |
| 160 | -<!-- </dependency>--> | |
| 161 | - | |
| 162 | -<!-- <!–Token生成与解析–>--> | |
| 163 | -<!-- <dependency>--> | |
| 164 | -<!-- <groupId>io.jsonwebtoken</groupId>--> | |
| 165 | -<!-- <artifactId>jjwt</artifactId>--> | |
| 166 | -<!-- <version>${jwt.version}</version>--> | |
| 167 | -<!-- </dependency>--> | |
| 168 | - | |
| 169 | -<!-- <!–验证码 –>--> | |
| 170 | -<!-- <dependency>--> | |
| 171 | -<!-- <groupId>com.github.penggle</groupId>--> | |
| 172 | -<!-- <artifactId>kaptcha</artifactId>--> | |
| 173 | -<!-- <version>${kaptcha.version}</version>--> | |
| 174 | -<!-- </dependency>--> | |
| 175 | - | |
| 176 | 112 | <!-- 统一依赖管理 --> |
| 177 | 113 | <dependency> |
| 178 | 114 | <groupId>org.springframework.boot</groupId> |
| ... | ... | @@ -184,16 +120,6 @@ |
| 184 | 120 | </dependencies> |
| 185 | 121 | </dependencyManagement> |
| 186 | 122 | |
| 187 | -<!-- <modules>--> | |
| 188 | -<!-- <module>ruoyi-admin</module>--> | |
| 189 | -<!-- <module>ruoyi-framework</module>--> | |
| 190 | -<!-- <module>ruoyi-system</module>--> | |
| 191 | -<!-- <module>ruoyi-quartz</module>--> | |
| 192 | -<!-- <module>ruoyi-generator</module>--> | |
| 193 | -<!-- <module>ruoyi-common</module>--> | |
| 194 | -<!-- </modules>--> | |
| 195 | - <packaging>jar</packaging> | |
| 196 | - | |
| 197 | 123 | <dependencies> |
| 198 | 124 | <!-- Spring 核心 --> |
| 199 | 125 | <dependency> |
| ... | ... | @@ -306,6 +232,13 @@ |
| 306 | 232 | <artifactId>hutool-captcha</artifactId> |
| 307 | 233 | <version>${hutool.version}</version> |
| 308 | 234 | </dependency> |
| 235 | + | |
| 236 | + <dependency> | |
| 237 | + <groupId>com.alibaba</groupId> | |
| 238 | + <artifactId>easyexcel</artifactId> | |
| 239 | + <version>${easyexcel.verion}</version> | |
| 240 | + </dependency> | |
| 241 | + | |
| 309 | 242 | </dependencies> |
| 310 | 243 | |
| 311 | 244 | ... | ... |
src/main/java/cn/iocoder/dashboard/framework/dict/config/DictConfiguration.java
0 → 100644
| 1 | +package cn.iocoder.dashboard.framework.dict.config; | |
| 2 | + | |
| 3 | +import cn.iocoder.dashboard.framework.dict.core.service.DictDataFrameworkService; | |
| 4 | +import cn.iocoder.dashboard.framework.dict.core.util.DictUtils; | |
| 5 | +import org.springframework.context.annotation.Bean; | |
| 6 | +import org.springframework.context.annotation.Configuration; | |
| 7 | + | |
| 8 | +@Configuration | |
| 9 | +public class DictConfiguration { | |
| 10 | + | |
| 11 | + @Bean | |
| 12 | + @SuppressWarnings("InstantiationOfUtilityClass") | |
| 13 | + public DictUtils dictUtils(DictDataFrameworkService service) { | |
| 14 | + DictUtils.init(service); | |
| 15 | + return new DictUtils(); | |
| 16 | + } | |
| 17 | + | |
| 18 | +} | ... | ... |
src/main/java/cn/iocoder/dashboard/framework/dict/core/util/DictUtils.java
| 1 | 1 | package cn.iocoder.dashboard.framework.dict.core.util; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.dashboard.framework.dict.core.service.DictDataFrameworkService; |
| 4 | +import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dict.SysDictDataDO; | |
| 4 | 5 | import lombok.extern.slf4j.Slf4j; |
| 5 | 6 | |
| 6 | 7 | /** |
| ... | ... | @@ -16,4 +17,12 @@ public class DictUtils { |
| 16 | 17 | log.info("[init][初始化 DictUtils 成功]"); |
| 17 | 18 | } |
| 18 | 19 | |
| 20 | + public static SysDictDataDO getDictDataFromCache(String type, String value) { | |
| 21 | + return service.getDictDataFromCache(type, value); | |
| 22 | + } | |
| 23 | + | |
| 24 | + public static SysDictDataDO parseDictDataFromCache(String type, String label) { | |
| 25 | + return service.getDictDataFromCache(type, label); | |
| 26 | + } | |
| 27 | + | |
| 19 | 28 | } | ... | ... |
src/main/java/cn/iocoder/dashboard/framework/excel/Excel.java
src/main/java/cn/iocoder/dashboard/framework/excel/Excels.java
src/main/java/cn/iocoder/dashboard/framework/excel/core/annotations/DictFormat.java
0 → 100644
| 1 | +package cn.iocoder.dashboard.framework.excel.core.annotations; | |
| 2 | + | |
| 3 | +import cn.iocoder.dashboard.modules.system.enums.dict.DictTypeEnum; | |
| 4 | + | |
| 5 | +import java.lang.annotation.*; | |
| 6 | + | |
| 7 | +/** | |
| 8 | + * 字典格式化 | |
| 9 | + * | |
| 10 | + * 实现将字典数据的值,格式化成字典数据的标签 | |
| 11 | + */ | |
| 12 | +@Target({ElementType.FIELD}) | |
| 13 | +@Retention(RetentionPolicy.RUNTIME) | |
| 14 | +@Inherited | |
| 15 | +public @interface DictFormat { | |
| 16 | + | |
| 17 | + DictTypeEnum value(); | |
| 18 | + | |
| 19 | +} | ... | ... |
src/main/java/cn/iocoder/dashboard/framework/excel/core/convert/DictConvert.java
0 → 100644
| 1 | +package cn.iocoder.dashboard.framework.excel.core.convert; | |
| 2 | + | |
| 3 | + | |
| 4 | +import cn.hutool.core.convert.Convert; | |
| 5 | +import cn.iocoder.dashboard.framework.dict.core.util.DictUtils; | |
| 6 | +import cn.iocoder.dashboard.framework.excel.core.annotations.DictFormat; | |
| 7 | +import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dict.SysDictDataDO; | |
| 8 | +import cn.iocoder.dashboard.modules.system.enums.dict.DictTypeEnum; | |
| 9 | +import com.alibaba.excel.converters.Converter; | |
| 10 | +import com.alibaba.excel.enums.CellDataTypeEnum; | |
| 11 | +import com.alibaba.excel.metadata.CellData; | |
| 12 | +import com.alibaba.excel.metadata.GlobalConfiguration; | |
| 13 | +import com.alibaba.excel.metadata.property.ExcelContentProperty; | |
| 14 | +import lombok.extern.slf4j.Slf4j; | |
| 15 | + | |
| 16 | +@Slf4j | |
| 17 | +public class DictConvert implements Converter<Object> { | |
| 18 | + | |
| 19 | + @Override | |
| 20 | + public Class<?> supportJavaTypeKey() { | |
| 21 | + throw new UnsupportedOperationException("暂不支持,也不需要"); | |
| 22 | + } | |
| 23 | + | |
| 24 | + @Override | |
| 25 | + public CellDataTypeEnum supportExcelTypeKey() { | |
| 26 | + throw new UnsupportedOperationException("暂不支持,也不需要"); | |
| 27 | + } | |
| 28 | + | |
| 29 | + @Override | |
| 30 | + public Object convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, | |
| 31 | + GlobalConfiguration globalConfiguration) { | |
| 32 | + // 使用字典解析 | |
| 33 | + DictTypeEnum type = getType(contentProperty); | |
| 34 | + String label = cellData.getStringValue(); | |
| 35 | + SysDictDataDO dictData = DictUtils.parseDictDataFromCache(type.getValue(), label); | |
| 36 | + if (dictData == null) { | |
| 37 | + log.error("[convertToJavaData][type({}) 解析不掉 label({})]", type, label); | |
| 38 | + return null; | |
| 39 | + } | |
| 40 | + // 将 String 的 value 转换成对应的属性 | |
| 41 | + Class<?> fieldClazz = contentProperty.getField().getType(); | |
| 42 | + return Convert.convert(fieldClazz, dictData.getValue()); | |
| 43 | + } | |
| 44 | + | |
| 45 | + @Override | |
| 46 | + public CellData<String> convertToExcelData(Object object, ExcelContentProperty contentProperty, | |
| 47 | + GlobalConfiguration globalConfiguration) { | |
| 48 | + // 使用字典格式化 | |
| 49 | + DictTypeEnum type = getType(contentProperty); | |
| 50 | + String value = String.valueOf(object); | |
| 51 | + SysDictDataDO dictData = DictUtils.getDictDataFromCache(type.getValue(), value); | |
| 52 | + if (dictData == null) { | |
| 53 | + log.error("[convertToExcelData][type({}) 转换不了 label({})]", type, value); | |
| 54 | + return null; | |
| 55 | + } | |
| 56 | + // 生成 Excel 小表格 | |
| 57 | + return new CellData<>(dictData.getValue()); | |
| 58 | + } | |
| 59 | + | |
| 60 | + private static DictTypeEnum getType(ExcelContentProperty contentProperty) { | |
| 61 | + return contentProperty.getField().getAnnotation(DictFormat.class).value(); | |
| 62 | + } | |
| 63 | + | |
| 64 | +} | ... | ... |
src/main/java/cn/iocoder/dashboard/framework/excel/core/package-info.java
0 → 100644
| 1 | +package cn.iocoder.dashboard.framework.excel.core; | ... | ... |
src/main/java/cn/iocoder/dashboard/framework/excel/package-info.java
0 → 100644
src/main/java/cn/iocoder/dashboard/modules/system/controller/dept/SysDeptController.java
| ... | ... | @@ -48,7 +48,7 @@ public class SysDeptController { |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | @ApiOperation("获得部门信息") |
| 51 | - @ApiImplicitParam(name = "id", value = "编号", readOnly = true, example = "1024") | |
| 51 | + @ApiImplicitParam(name = "id", value = "编号", readOnly = true, example = "1024", dataTypeClass = Long.class) | |
| 52 | 52 | // @PreAuthorize("@ss.hasPermi('system:dept:query')") |
| 53 | 53 | @GetMapping("/get") |
| 54 | 54 | public CommonResult<SysDeptRespVO> getDept(@RequestParam("id") Long id) { |
| ... | ... | @@ -74,7 +74,7 @@ public class SysDeptController { |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | @ApiOperation("删除部门") |
| 77 | - @ApiImplicitParam(name = "id", value = "编号", readOnly = true, example = "1024") | |
| 77 | + @ApiImplicitParam(name = "id", value = "编号", readOnly = true, example = "1024", dataTypeClass = Long.class) | |
| 78 | 78 | @PostMapping("delete") |
| 79 | 79 | // @PreAuthorize("@ss.hasPermi('system:dept:remove')") |
| 80 | 80 | // @Log(title = "部门管理", businessType = BusinessType.DELETE) | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/system/controller/dept/SysPostController.java
| ... | ... | @@ -73,7 +73,7 @@ public class SysPostController { |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | @ApiOperation("获得岗位信息") |
| 76 | - @ApiImplicitParam(name = "id", value = "岗位编号", readOnly = true, example = "1024") | |
| 76 | + @ApiImplicitParam(name = "id", value = "岗位编号", readOnly = true, example = "1024", dataTypeClass = Long.class) | |
| 77 | 77 | // @PreAuthorize("@ss.hasPermi('system:post:query')") |
| 78 | 78 | @GetMapping(value = "/get") |
| 79 | 79 | public CommonResult<SysPostRespVO> getPost(@RequestParam("id") Long id) { | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/system/controller/dict/SysDictDataController.java
| ... | ... | @@ -41,7 +41,7 @@ public class SysDictDataController { |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | @ApiOperation("/查询字典数据详细") |
| 44 | - @ApiImplicitParam(name = "id", value = "编号", readOnly = true, example = "1024") | |
| 44 | + @ApiImplicitParam(name = "id", value = "编号", readOnly = true, example = "1024", dataTypeClass = Long.class) | |
| 45 | 45 | @GetMapping(value = "/get") |
| 46 | 46 | // @PreAuthorize("@ss.hasPermi('system:dict:query')") |
| 47 | 47 | public CommonResult<SysDictDataRespVO> getDictData(@RequestParam("id") Long id) { |
| ... | ... | @@ -67,7 +67,7 @@ public class SysDictDataController { |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | @ApiOperation("删除字典数据") |
| 70 | - @ApiImplicitParam(name = "id", value = "编号", readOnly = true, example = "1024") | |
| 70 | + @ApiImplicitParam(name = "id", value = "编号", readOnly = true, example = "1024", dataTypeClass = Long.class) | |
| 71 | 71 | @PostMapping("/delete") |
| 72 | 72 | // @PreAuthorize("@ss.hasPermi('system:dict:remove')") |
| 73 | 73 | public CommonResult<Boolean> deleteDictData(Long id) { | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/system/controller/dict/SysDictTypeController.java
| ... | ... | @@ -33,7 +33,7 @@ public class SysDictTypeController { |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | @ApiOperation("/查询字典类型详细") |
| 36 | - @ApiImplicitParam(name = "id", value = "编号", readOnly = true, example = "1024") | |
| 36 | + @ApiImplicitParam(name = "id", value = "编号", readOnly = true, example = "1024", dataTypeClass = Long.class) | |
| 37 | 37 | @GetMapping(value = "/get") |
| 38 | 38 | // @PreAuthorize("@ss.hasPermi('system:dict:query')") |
| 39 | 39 | public CommonResult<SysDictTypeRespVO> getDictType(@RequestParam("id") Long id) { |
| ... | ... | @@ -59,7 +59,7 @@ public class SysDictTypeController { |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | @ApiOperation("删除字典类型") |
| 62 | - @ApiImplicitParam(name = "id", value = "编号", readOnly = true, example = "1024") | |
| 62 | + @ApiImplicitParam(name = "id", value = "编号", readOnly = true, example = "1024", dataTypeClass = Long.class) | |
| 63 | 63 | @PostMapping("/delete") |
| 64 | 64 | // @PreAuthorize("@ss.hasPermi('system:dict:remove')") |
| 65 | 65 | public CommonResult<Boolean> deleteDictType(Long id) { | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/system/controller/permission/SysMenuController.java
| ... | ... | @@ -88,7 +88,7 @@ public class SysMenuController { |
| 88 | 88 | |
| 89 | 89 | @ApiOperation("删除菜单") |
| 90 | 90 | @PostMapping("/delete") |
| 91 | - @ApiImplicitParam(name = "id", value = "角色编号", required= true, example = "1024") | |
| 91 | + @ApiImplicitParam(name = "id", value = "角色编号", required= true, example = "1024", dataTypeClass = Long.class) | |
| 92 | 92 | // @Log(title = "菜单管理", businessType = BusinessType.DELETE) |
| 93 | 93 | public CommonResult<Boolean> deleteMenu(@RequestParam("id") Long id) { |
| 94 | 94 | menuService.deleteMenu(id); | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/system/controller/permission/SysPermissionController.java
| ... | ... | @@ -30,8 +30,8 @@ public class SysPermissionController { |
| 30 | 30 | private SysPermissionService permissionService; |
| 31 | 31 | |
| 32 | 32 | @ApiOperation("获得角色拥有的菜单编号") |
| 33 | + @ApiImplicitParam(name = "roleId", value = "角色编号", required = true, dataTypeClass = Long.class) | |
| 33 | 34 | @GetMapping("/list-role-resources") |
| 34 | - @ApiImplicitParam(name = "roleId", value = "角色编号", required = true) | |
| 35 | 35 | // @RequiresPermissions("system:permission:assign-role-menu") |
| 36 | 36 | public CommonResult<Set<Long>> listRoleMenus(Long roleId) { |
| 37 | 37 | return success(permissionService.listRoleMenuIds(roleId)); |
| ... | ... | @@ -55,7 +55,7 @@ public class SysPermissionController { |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | @ApiOperation("获得管理员拥有的角色编号列表") |
| 58 | - @ApiImplicitParam(name = "userId", value = "用户编号", required = true) | |
| 58 | + @ApiImplicitParam(name = "userId", value = "用户编号", required = true, dataTypeClass = Long.class) | |
| 59 | 59 | @GetMapping("/list-user-roles") |
| 60 | 60 | // @RequiresPermissions("system:permission:assign-user-role") |
| 61 | 61 | public CommonResult<Set<Long>> listAdminRoles(@RequestParam("userId") Long userId) { | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/system/controller/permission/SysRoleController.java
| ... | ... | @@ -64,10 +64,10 @@ public class SysRoleController { |
| 64 | 64 | |
| 65 | 65 | @ApiOperation("删除角色") |
| 66 | 66 | @PostMapping("/delete") |
| 67 | - @ApiImplicitParam(name = "id", value = "角色编号", required = true, example = "1024") | |
| 67 | + @ApiImplicitParam(name = "id", value = "角色编号", required = true, example = "1024", dataTypeClass = Long.class) | |
| 68 | 68 | // @PreAuthorize("@ss.hasPermi('system:role:remove')") |
| 69 | 69 | // @Log(title = "角色管理", businessType = BusinessType.DELETE) |
| 70 | - public CommonResult<Boolean> remove(@RequestParam("id") Long id) { | |
| 70 | + public CommonResult<Boolean> deleteRole(@RequestParam("id") Long id) { | |
| 71 | 71 | roleService.deleteRole(id); |
| 72 | 72 | return success(true); |
| 73 | 73 | } | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/system/controller/user/SysUserController.java
| ... | ... | @@ -63,7 +63,7 @@ public class SysUserController { |
| 63 | 63 | * 根据用户编号获取详细信息 |
| 64 | 64 | */ |
| 65 | 65 | @ApiOperation("获得用户详情") |
| 66 | - @ApiImplicitParam(name = "id", value = "编号", readOnly = true, example = "1024") | |
| 66 | + @ApiImplicitParam(name = "id", value = "编号", readOnly = true, example = "1024", dataTypeClass = Long.class) | |
| 67 | 67 | @GetMapping("/get") |
| 68 | 68 | // @PreAuthorize("@ss.hasPermi('system:user:query')") |
| 69 | 69 | public CommonResult<SysUserRespVO> getInfo(@RequestParam("id") Long id) { |
| ... | ... | @@ -89,7 +89,7 @@ public class SysUserController { |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | @ApiOperation("删除用户") |
| 92 | - @ApiImplicitParam(name = "id", value = "编号", readOnly = true, example = "1024") | |
| 92 | + @ApiImplicitParam(name = "id", value = "编号", readOnly = true, example = "1024", dataTypeClass = Long.class) | |
| 93 | 93 | @PostMapping("/delete") |
| 94 | 94 | // @PreAuthorize("@ss.hasPermi('system:user:remove')") |
| 95 | 95 | // @Log(title = "用户管理", businessType = BusinessType.DELETE) | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/system/controller/user/vo/user/SysUserExcelRespVO.java renamed to src/main/java/cn/iocoder/dashboard/modules/system/controller/user/vo/user/SysUserExcelRespBackVO.java
| ... | ... | @@ -11,20 +11,14 @@ import java.util.Date; |
| 11 | 11 | * 用户 Excel 导出响应 VO |
| 12 | 12 | */ |
| 13 | 13 | @Data |
| 14 | -public class SysUserExcelRespVO { | |
| 14 | +public class SysUserExcelRespBackVO { | |
| 15 | 15 | |
| 16 | 16 | @Excel(name = "用户序号", cellType = Excel.ColumnType.NUMERIC, prompt = "用户编号") |
| 17 | 17 | private Long id; |
| 18 | 18 | |
| 19 | - /** | |
| 20 | - * 用户账号 | |
| 21 | - */ | |
| 22 | 19 | @Excel(name = "登录名称") |
| 23 | 20 | private String username; |
| 24 | 21 | |
| 25 | - /** | |
| 26 | - * 用户昵称 | |
| 27 | - */ | |
| 28 | 22 | @Excel(name = "用户名称") |
| 29 | 23 | private String nickname; |
| 30 | 24 | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/system/controller/user/vo/user/SysUserExcelVO.java
0 → 100644
| 1 | +package cn.iocoder.dashboard.modules.system.controller.user.vo.user; | |
| 2 | + | |
| 3 | +import cn.iocoder.dashboard.framework.excel.core.annotations.DictFormat; | |
| 4 | +import cn.iocoder.dashboard.framework.excel.core.convert.DictConvert; | |
| 5 | +import com.alibaba.excel.annotation.ExcelProperty; | |
| 6 | +import lombok.Data; | |
| 7 | + | |
| 8 | +import java.util.Date; | |
| 9 | + | |
| 10 | +import static cn.iocoder.dashboard.modules.system.enums.dict.DictTypeEnum.SYS_COMMON_STATUS; | |
| 11 | +import static cn.iocoder.dashboard.modules.system.enums.dict.DictTypeEnum.SYS_USER_SEX; | |
| 12 | + | |
| 13 | +/** | |
| 14 | + * 用户 Excel 导出 VO | |
| 15 | + */ | |
| 16 | +@Data | |
| 17 | +public class SysUserExcelVO { | |
| 18 | + | |
| 19 | + @ExcelProperty("用户编号") | |
| 20 | + private Long id; | |
| 21 | + | |
| 22 | + @ExcelProperty("用户名称") | |
| 23 | + private String username; | |
| 24 | + | |
| 25 | + @ExcelProperty("用户名称") | |
| 26 | + private String nickname; | |
| 27 | + | |
| 28 | + @ExcelProperty("用户邮箱") | |
| 29 | + private String email; | |
| 30 | + | |
| 31 | + @ExcelProperty("手机号码") | |
| 32 | + private String mobile; | |
| 33 | + | |
| 34 | + @ExcelProperty(value = "用户性别", converter = DictConvert.class) | |
| 35 | + @DictFormat(SYS_USER_SEX) | |
| 36 | + private Integer sex; | |
| 37 | + | |
| 38 | + @ExcelProperty(value = "帐号状态", converter = DictConvert.class) | |
| 39 | + @DictFormat(SYS_COMMON_STATUS) | |
| 40 | + private Integer status; | |
| 41 | + | |
| 42 | + @ExcelProperty("最后登录IP") | |
| 43 | + private String loginIp; | |
| 44 | + | |
| 45 | + @ExcelProperty("最后登录时间") | |
| 46 | + private Date loginDate; | |
| 47 | + | |
| 48 | + @ExcelProperty("部门名称") | |
| 49 | + private String deptName; | |
| 50 | + | |
| 51 | + @ExcelProperty("部门负责人") | |
| 52 | + private String deptLeader; | |
| 53 | + | |
| 54 | +} | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/system/enums/dict/DictTypeEnum.java
0 → 100644
| 1 | +package cn.iocoder.dashboard.modules.system.enums.dict; | |
| 2 | + | |
| 3 | +import lombok.AllArgsConstructor; | |
| 4 | +import lombok.Getter; | |
| 5 | + | |
| 6 | +/** | |
| 7 | + * 字典类型的类型枚举 | |
| 8 | + */ | |
| 9 | +@Getter | |
| 10 | +@AllArgsConstructor | |
| 11 | +public enum DictTypeEnum { | |
| 12 | + | |
| 13 | + SYS_USER_SEX("sys_user_sex"), // 用户性别 | |
| 14 | + SYS_COMMON_STATUS("sys_common_status"), // 系统状态 | |
| 15 | + ; | |
| 16 | + | |
| 17 | + | |
| 18 | + /** | |
| 19 | + * 值 | |
| 20 | + */ | |
| 21 | + private final String value; | |
| 22 | + | |
| 23 | +} | ... | ... |
src/main/java/cn/iocoder/dashboard/modules/system/service/dict/SysDictDataService.java
| 1 | 1 | package cn.iocoder.dashboard.modules.system.service.dict; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.dashboard.common.pojo.PageResult; |
| 4 | +import cn.iocoder.dashboard.framework.dict.core.service.DictDataFrameworkService; | |
| 4 | 5 | import cn.iocoder.dashboard.modules.system.controller.dict.vo.data.SysDictDataCreateReqVO; |
| 5 | 6 | import cn.iocoder.dashboard.modules.system.controller.dict.vo.data.SysDictDataPageReqVO; |
| 6 | 7 | import cn.iocoder.dashboard.modules.system.controller.dict.vo.data.SysDictDataUpdateReqVO; |
| ... | ... | @@ -13,8 +14,18 @@ import java.util.List; |
| 13 | 14 | * |
| 14 | 15 | * @author ruoyi |
| 15 | 16 | */ |
| 16 | -public interface SysDictDataService { | |
| 17 | +public interface SysDictDataService extends DictDataFrameworkService { | |
| 17 | 18 | |
| 19 | + /** | |
| 20 | + * 初始化,主要是初始化缓存 | |
| 21 | + */ | |
| 22 | + void init(); | |
| 23 | + | |
| 24 | + /** | |
| 25 | + * 获得字典数据列表 | |
| 26 | + * | |
| 27 | + * @return 字典数据全列表 | |
| 28 | + */ | |
| 18 | 29 | List<SysDictDataDO> listDictDatas(); |
| 19 | 30 | |
| 20 | 31 | /** | ... | ... |
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 |
| 12 | 12 | import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dict.SysDictTypeDO; |
| 13 | 13 | import cn.iocoder.dashboard.modules.system.service.dict.SysDictDataService; |
| 14 | 14 | import cn.iocoder.dashboard.modules.system.service.dict.SysDictTypeService; |
| 15 | +import com.google.common.collect.ImmutableTable; | |
| 15 | 16 | import org.springframework.stereotype.Service; |
| 16 | 17 | |
| 17 | 18 | import javax.annotation.Resource; |
| 19 | +import java.util.ArrayList; | |
| 18 | 20 | import java.util.Comparator; |
| 19 | 21 | import java.util.List; |
| 20 | 22 | |
| ... | ... | @@ -32,6 +34,21 @@ public class SysDictDataServiceImpl implements SysDictDataService { |
| 32 | 34 | .comparing(SysDictDataDO::getDictType) |
| 33 | 35 | .thenComparingInt(SysDictDataDO::getSort); |
| 34 | 36 | |
| 37 | + /** | |
| 38 | + * 字典数据缓存,第二个 key 使用 label | |
| 39 | + * | |
| 40 | + * key1:字典类型 dictType | |
| 41 | + * key2:字典标签 label | |
| 42 | + */ | |
| 43 | + private ImmutableTable<String, String, SysDictDataDO> labelDictDataCache; | |
| 44 | + /** | |
| 45 | + * 字典数据缓存,第二个 key 使用 value | |
| 46 | + * | |
| 47 | + * key1:字典类型 dictType | |
| 48 | + * key2:字典值 value | |
| 49 | + */ | |
| 50 | + private ImmutableTable<String, String, SysDictDataDO> valueDictDataCache; | |
| 51 | + | |
| 35 | 52 | @Resource |
| 36 | 53 | private SysDictTypeService dictTypeService; |
| 37 | 54 | |
| ... | ... | @@ -39,6 +56,21 @@ public class SysDictDataServiceImpl implements SysDictDataService { |
| 39 | 56 | private SysDictDataMapper dictDataMapper; |
| 40 | 57 | |
| 41 | 58 | @Override |
| 59 | + public void init() { | |
| 60 | + // 获得字典数据 | |
| 61 | + List<SysDictDataDO> list = this.listDictDatas(); | |
| 62 | + // 构建缓存 | |
| 63 | + ImmutableTable.Builder<String, String, SysDictDataDO> labelDictDataBuilder = ImmutableTable.builder(); | |
| 64 | + ImmutableTable.Builder<String, String, SysDictDataDO> valueDictDataBuilder = ImmutableTable.builder(); | |
| 65 | + list.forEach(dictData -> { | |
| 66 | + labelDictDataBuilder.put(dictData.getDictType(), dictData.getLabel(), dictData); | |
| 67 | + valueDictDataBuilder.put(dictData.getDictType(), dictData.getValue(), dictData); | |
| 68 | + }); | |
| 69 | + labelDictDataCache = labelDictDataBuilder.build(); | |
| 70 | + valueDictDataCache = valueDictDataBuilder.build(); | |
| 71 | + } | |
| 72 | + | |
| 73 | + @Override | |
| 42 | 74 | public List<SysDictDataDO> listDictDatas() { |
| 43 | 75 | List<SysDictDataDO> list = dictDataMapper.selectList(); |
| 44 | 76 | list.sort(COMPARATOR_TYPE_AND_SORT); |
| ... | ... | @@ -130,4 +162,19 @@ public class SysDictDataServiceImpl implements SysDictDataService { |
| 130 | 162 | } |
| 131 | 163 | } |
| 132 | 164 | |
| 165 | + @Override | |
| 166 | + public SysDictDataDO getDictDataFromCache(String type, String value) { | |
| 167 | + return valueDictDataCache.get(type, value); | |
| 168 | + } | |
| 169 | + | |
| 170 | + @Override | |
| 171 | + public SysDictDataDO parseDictDataFromCache(String type, String label) { | |
| 172 | + return labelDictDataCache.get(type, label); | |
| 173 | + } | |
| 174 | + | |
| 175 | + @Override | |
| 176 | + public List<SysDictDataDO> listDictDatasFromCache(String type) { | |
| 177 | + return new ArrayList<>(labelDictDataCache.row(type).values()); | |
| 178 | + } | |
| 179 | + | |
| 133 | 180 | } | ... | ... |