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,6 +11,7 @@ | ||
| 11 | <name>ruoyi</name> | 11 | <name>ruoyi</name> |
| 12 | <url>http://www.ruoyi.vip</url> | 12 | <url>http://www.ruoyi.vip</url> |
| 13 | <description>若依管理系统</description> | 13 | <description>若依管理系统</description> |
| 14 | + <packaging>jar</packaging> | ||
| 14 | 15 | ||
| 15 | <properties> | 16 | <properties> |
| 16 | <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> | 17 | <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> |
| @@ -54,19 +55,13 @@ | @@ -54,19 +55,13 @@ | ||
| 54 | <jjwt.version>0.9.1</jjwt.version> | 55 | <jjwt.version>0.9.1</jjwt.version> |
| 55 | <fastjson.version>1.2.75</fastjson.version> | 56 | <fastjson.version>1.2.75</fastjson.version> |
| 56 | <hutool.version>5.5.6</hutool.version> | 57 | <hutool.version>5.5.6</hutool.version> |
| 58 | + <easyexcel.verion>2.2.7</easyexcel.verion> | ||
| 57 | </properties> | 59 | </properties> |
| 58 | 60 | ||
| 59 | <!-- 依赖声明 --> | 61 | <!-- 依赖声明 --> |
| 60 | <dependencyManagement> | 62 | <dependencyManagement> |
| 61 | <dependencies> | 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 | <!-- <dependency>--> | 66 | <!-- <dependency>--> |
| 72 | <!-- <groupId>eu.bitwalker</groupId>--> | 67 | <!-- <groupId>eu.bitwalker</groupId>--> |
| @@ -74,13 +69,6 @@ | @@ -74,13 +69,6 @@ | ||
| 74 | <!-- <version>${bitwalker.version}</version>--> | 69 | <!-- <version>${bitwalker.version}</version>--> |
| 75 | <!-- </dependency>--> | 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 | <!-- <dependency>--> | 73 | <!-- <dependency>--> |
| 86 | <!-- <groupId>com.github.oshi</groupId>--> | 74 | <!-- <groupId>com.github.oshi</groupId>--> |
| @@ -100,30 +88,6 @@ | @@ -100,30 +88,6 @@ | ||
| 100 | <!-- <version>${jna.version}</version>--> | 88 | <!-- <version>${jna.version}</version>--> |
| 101 | <!-- </dependency>--> | 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 | <!-- <!–io常用工具类 –>--> | 91 | <!-- <!–io常用工具类 –>--> |
| 128 | <!-- <dependency>--> | 92 | <!-- <dependency>--> |
| 129 | <!-- <groupId>commons-io</groupId>--> | 93 | <!-- <groupId>commons-io</groupId>--> |
| @@ -138,13 +102,6 @@ | @@ -138,13 +102,6 @@ | ||
| 138 | <!-- <version>${commons.fileupload.version}</version>--> | 102 | <!-- <version>${commons.fileupload.version}</version>--> |
| 139 | <!-- </dependency>--> | 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 | <!-- <!–velocity代码生成使用模板 –>--> | 105 | <!-- <!–velocity代码生成使用模板 –>--> |
| 149 | <!-- <dependency>--> | 106 | <!-- <dependency>--> |
| 150 | <!-- <groupId>org.apache.velocity</groupId>--> | 107 | <!-- <groupId>org.apache.velocity</groupId>--> |
| @@ -152,27 +109,6 @@ | @@ -152,27 +109,6 @@ | ||
| 152 | <!-- <version>${velocity.version}</version>--> | 109 | <!-- <version>${velocity.version}</version>--> |
| 153 | <!-- </dependency>--> | 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 | <dependency> | 113 | <dependency> |
| 178 | <groupId>org.springframework.boot</groupId> | 114 | <groupId>org.springframework.boot</groupId> |
| @@ -184,16 +120,6 @@ | @@ -184,16 +120,6 @@ | ||
| 184 | </dependencies> | 120 | </dependencies> |
| 185 | </dependencyManagement> | 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 | <dependencies> | 123 | <dependencies> |
| 198 | <!-- Spring 核心 --> | 124 | <!-- Spring 核心 --> |
| 199 | <dependency> | 125 | <dependency> |
| @@ -306,6 +232,13 @@ | @@ -306,6 +232,13 @@ | ||
| 306 | <artifactId>hutool-captcha</artifactId> | 232 | <artifactId>hutool-captcha</artifactId> |
| 307 | <version>${hutool.version}</version> | 233 | <version>${hutool.version}</version> |
| 308 | </dependency> | 234 | </dependency> |
| 235 | + | ||
| 236 | + <dependency> | ||
| 237 | + <groupId>com.alibaba</groupId> | ||
| 238 | + <artifactId>easyexcel</artifactId> | ||
| 239 | + <version>${easyexcel.verion}</version> | ||
| 240 | + </dependency> | ||
| 241 | + | ||
| 309 | </dependencies> | 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 | package cn.iocoder.dashboard.framework.dict.core.util; | 1 | package cn.iocoder.dashboard.framework.dict.core.util; |
| 2 | 2 | ||
| 3 | import cn.iocoder.dashboard.framework.dict.core.service.DictDataFrameworkService; | 3 | import cn.iocoder.dashboard.framework.dict.core.service.DictDataFrameworkService; |
| 4 | +import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dict.SysDictDataDO; | ||
| 4 | import lombok.extern.slf4j.Slf4j; | 5 | import lombok.extern.slf4j.Slf4j; |
| 5 | 6 | ||
| 6 | /** | 7 | /** |
| @@ -16,4 +17,12 @@ public class DictUtils { | @@ -16,4 +17,12 @@ public class DictUtils { | ||
| 16 | log.info("[init][初始化 DictUtils 成功]"); | 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
| @@ -11,6 +11,7 @@ import java.math.BigDecimal; | @@ -11,6 +11,7 @@ import java.math.BigDecimal; | ||
| 11 | * | 11 | * |
| 12 | * @author ruoyi | 12 | * @author ruoyi |
| 13 | */ | 13 | */ |
| 14 | +@Deprecated | ||
| 14 | @Retention(RetentionPolicy.RUNTIME) | 15 | @Retention(RetentionPolicy.RUNTIME) |
| 15 | @Target(ElementType.FIELD) | 16 | @Target(ElementType.FIELD) |
| 16 | public @interface Excel { | 17 | public @interface Excel { |
src/main/java/cn/iocoder/dashboard/framework/excel/Excels.java
| @@ -10,6 +10,7 @@ import java.lang.annotation.Target; | @@ -10,6 +10,7 @@ import java.lang.annotation.Target; | ||
| 10 | * | 10 | * |
| 11 | * @author ruoyi | 11 | * @author ruoyi |
| 12 | */ | 12 | */ |
| 13 | +@Deprecated | ||
| 13 | @Target(ElementType.FIELD) | 14 | @Target(ElementType.FIELD) |
| 14 | @Retention(RetentionPolicy.RUNTIME) | 15 | @Retention(RetentionPolicy.RUNTIME) |
| 15 | public @interface Excels | 16 | public @interface Excels |
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,7 +48,7 @@ public class SysDeptController { | ||
| 48 | } | 48 | } |
| 49 | 49 | ||
| 50 | @ApiOperation("获得部门信息") | 50 | @ApiOperation("获得部门信息") |
| 51 | - @ApiImplicitParam(name = "id", value = "编号", readOnly = true, example = "1024") | 51 | + @ApiImplicitParam(name = "id", value = "编号", readOnly = true, example = "1024", dataTypeClass = Long.class) |
| 52 | // @PreAuthorize("@ss.hasPermi('system:dept:query')") | 52 | // @PreAuthorize("@ss.hasPermi('system:dept:query')") |
| 53 | @GetMapping("/get") | 53 | @GetMapping("/get") |
| 54 | public CommonResult<SysDeptRespVO> getDept(@RequestParam("id") Long id) { | 54 | public CommonResult<SysDeptRespVO> getDept(@RequestParam("id") Long id) { |
| @@ -74,7 +74,7 @@ public class SysDeptController { | @@ -74,7 +74,7 @@ public class SysDeptController { | ||
| 74 | } | 74 | } |
| 75 | 75 | ||
| 76 | @ApiOperation("删除部门") | 76 | @ApiOperation("删除部门") |
| 77 | - @ApiImplicitParam(name = "id", value = "编号", readOnly = true, example = "1024") | 77 | + @ApiImplicitParam(name = "id", value = "编号", readOnly = true, example = "1024", dataTypeClass = Long.class) |
| 78 | @PostMapping("delete") | 78 | @PostMapping("delete") |
| 79 | // @PreAuthorize("@ss.hasPermi('system:dept:remove')") | 79 | // @PreAuthorize("@ss.hasPermi('system:dept:remove')") |
| 80 | // @Log(title = "部门管理", businessType = BusinessType.DELETE) | 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,7 +73,7 @@ public class SysPostController { | ||
| 73 | } | 73 | } |
| 74 | 74 | ||
| 75 | @ApiOperation("获得岗位信息") | 75 | @ApiOperation("获得岗位信息") |
| 76 | - @ApiImplicitParam(name = "id", value = "岗位编号", readOnly = true, example = "1024") | 76 | + @ApiImplicitParam(name = "id", value = "岗位编号", readOnly = true, example = "1024", dataTypeClass = Long.class) |
| 77 | // @PreAuthorize("@ss.hasPermi('system:post:query')") | 77 | // @PreAuthorize("@ss.hasPermi('system:post:query')") |
| 78 | @GetMapping(value = "/get") | 78 | @GetMapping(value = "/get") |
| 79 | public CommonResult<SysPostRespVO> getPost(@RequestParam("id") Long id) { | 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,7 +41,7 @@ public class SysDictDataController { | ||
| 41 | } | 41 | } |
| 42 | 42 | ||
| 43 | @ApiOperation("/查询字典数据详细") | 43 | @ApiOperation("/查询字典数据详细") |
| 44 | - @ApiImplicitParam(name = "id", value = "编号", readOnly = true, example = "1024") | 44 | + @ApiImplicitParam(name = "id", value = "编号", readOnly = true, example = "1024", dataTypeClass = Long.class) |
| 45 | @GetMapping(value = "/get") | 45 | @GetMapping(value = "/get") |
| 46 | // @PreAuthorize("@ss.hasPermi('system:dict:query')") | 46 | // @PreAuthorize("@ss.hasPermi('system:dict:query')") |
| 47 | public CommonResult<SysDictDataRespVO> getDictData(@RequestParam("id") Long id) { | 47 | public CommonResult<SysDictDataRespVO> getDictData(@RequestParam("id") Long id) { |
| @@ -67,7 +67,7 @@ public class SysDictDataController { | @@ -67,7 +67,7 @@ public class SysDictDataController { | ||
| 67 | } | 67 | } |
| 68 | 68 | ||
| 69 | @ApiOperation("删除字典数据") | 69 | @ApiOperation("删除字典数据") |
| 70 | - @ApiImplicitParam(name = "id", value = "编号", readOnly = true, example = "1024") | 70 | + @ApiImplicitParam(name = "id", value = "编号", readOnly = true, example = "1024", dataTypeClass = Long.class) |
| 71 | @PostMapping("/delete") | 71 | @PostMapping("/delete") |
| 72 | // @PreAuthorize("@ss.hasPermi('system:dict:remove')") | 72 | // @PreAuthorize("@ss.hasPermi('system:dict:remove')") |
| 73 | public CommonResult<Boolean> deleteDictData(Long id) { | 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,7 +33,7 @@ public class SysDictTypeController { | ||
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | @ApiOperation("/查询字典类型详细") | 35 | @ApiOperation("/查询字典类型详细") |
| 36 | - @ApiImplicitParam(name = "id", value = "编号", readOnly = true, example = "1024") | 36 | + @ApiImplicitParam(name = "id", value = "编号", readOnly = true, example = "1024", dataTypeClass = Long.class) |
| 37 | @GetMapping(value = "/get") | 37 | @GetMapping(value = "/get") |
| 38 | // @PreAuthorize("@ss.hasPermi('system:dict:query')") | 38 | // @PreAuthorize("@ss.hasPermi('system:dict:query')") |
| 39 | public CommonResult<SysDictTypeRespVO> getDictType(@RequestParam("id") Long id) { | 39 | public CommonResult<SysDictTypeRespVO> getDictType(@RequestParam("id") Long id) { |
| @@ -59,7 +59,7 @@ public class SysDictTypeController { | @@ -59,7 +59,7 @@ public class SysDictTypeController { | ||
| 59 | } | 59 | } |
| 60 | 60 | ||
| 61 | @ApiOperation("删除字典类型") | 61 | @ApiOperation("删除字典类型") |
| 62 | - @ApiImplicitParam(name = "id", value = "编号", readOnly = true, example = "1024") | 62 | + @ApiImplicitParam(name = "id", value = "编号", readOnly = true, example = "1024", dataTypeClass = Long.class) |
| 63 | @PostMapping("/delete") | 63 | @PostMapping("/delete") |
| 64 | // @PreAuthorize("@ss.hasPermi('system:dict:remove')") | 64 | // @PreAuthorize("@ss.hasPermi('system:dict:remove')") |
| 65 | public CommonResult<Boolean> deleteDictType(Long id) { | 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,7 +88,7 @@ public class SysMenuController { | ||
| 88 | 88 | ||
| 89 | @ApiOperation("删除菜单") | 89 | @ApiOperation("删除菜单") |
| 90 | @PostMapping("/delete") | 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 | // @Log(title = "菜单管理", businessType = BusinessType.DELETE) | 92 | // @Log(title = "菜单管理", businessType = BusinessType.DELETE) |
| 93 | public CommonResult<Boolean> deleteMenu(@RequestParam("id") Long id) { | 93 | public CommonResult<Boolean> deleteMenu(@RequestParam("id") Long id) { |
| 94 | menuService.deleteMenu(id); | 94 | menuService.deleteMenu(id); |
src/main/java/cn/iocoder/dashboard/modules/system/controller/permission/SysPermissionController.java
| @@ -30,8 +30,8 @@ public class SysPermissionController { | @@ -30,8 +30,8 @@ public class SysPermissionController { | ||
| 30 | private SysPermissionService permissionService; | 30 | private SysPermissionService permissionService; |
| 31 | 31 | ||
| 32 | @ApiOperation("获得角色拥有的菜单编号") | 32 | @ApiOperation("获得角色拥有的菜单编号") |
| 33 | + @ApiImplicitParam(name = "roleId", value = "角色编号", required = true, dataTypeClass = Long.class) | ||
| 33 | @GetMapping("/list-role-resources") | 34 | @GetMapping("/list-role-resources") |
| 34 | - @ApiImplicitParam(name = "roleId", value = "角色编号", required = true) | ||
| 35 | // @RequiresPermissions("system:permission:assign-role-menu") | 35 | // @RequiresPermissions("system:permission:assign-role-menu") |
| 36 | public CommonResult<Set<Long>> listRoleMenus(Long roleId) { | 36 | public CommonResult<Set<Long>> listRoleMenus(Long roleId) { |
| 37 | return success(permissionService.listRoleMenuIds(roleId)); | 37 | return success(permissionService.listRoleMenuIds(roleId)); |
| @@ -55,7 +55,7 @@ public class SysPermissionController { | @@ -55,7 +55,7 @@ public class SysPermissionController { | ||
| 55 | } | 55 | } |
| 56 | 56 | ||
| 57 | @ApiOperation("获得管理员拥有的角色编号列表") | 57 | @ApiOperation("获得管理员拥有的角色编号列表") |
| 58 | - @ApiImplicitParam(name = "userId", value = "用户编号", required = true) | 58 | + @ApiImplicitParam(name = "userId", value = "用户编号", required = true, dataTypeClass = Long.class) |
| 59 | @GetMapping("/list-user-roles") | 59 | @GetMapping("/list-user-roles") |
| 60 | // @RequiresPermissions("system:permission:assign-user-role") | 60 | // @RequiresPermissions("system:permission:assign-user-role") |
| 61 | public CommonResult<Set<Long>> listAdminRoles(@RequestParam("userId") Long userId) { | 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,10 +64,10 @@ public class SysRoleController { | ||
| 64 | 64 | ||
| 65 | @ApiOperation("删除角色") | 65 | @ApiOperation("删除角色") |
| 66 | @PostMapping("/delete") | 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 | // @PreAuthorize("@ss.hasPermi('system:role:remove')") | 68 | // @PreAuthorize("@ss.hasPermi('system:role:remove')") |
| 69 | // @Log(title = "角色管理", businessType = BusinessType.DELETE) | 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 | roleService.deleteRole(id); | 71 | roleService.deleteRole(id); |
| 72 | return success(true); | 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,7 +63,7 @@ public class SysUserController { | ||
| 63 | * 根据用户编号获取详细信息 | 63 | * 根据用户编号获取详细信息 |
| 64 | */ | 64 | */ |
| 65 | @ApiOperation("获得用户详情") | 65 | @ApiOperation("获得用户详情") |
| 66 | - @ApiImplicitParam(name = "id", value = "编号", readOnly = true, example = "1024") | 66 | + @ApiImplicitParam(name = "id", value = "编号", readOnly = true, example = "1024", dataTypeClass = Long.class) |
| 67 | @GetMapping("/get") | 67 | @GetMapping("/get") |
| 68 | // @PreAuthorize("@ss.hasPermi('system:user:query')") | 68 | // @PreAuthorize("@ss.hasPermi('system:user:query')") |
| 69 | public CommonResult<SysUserRespVO> getInfo(@RequestParam("id") Long id) { | 69 | public CommonResult<SysUserRespVO> getInfo(@RequestParam("id") Long id) { |
| @@ -89,7 +89,7 @@ public class SysUserController { | @@ -89,7 +89,7 @@ public class SysUserController { | ||
| 89 | } | 89 | } |
| 90 | 90 | ||
| 91 | @ApiOperation("删除用户") | 91 | @ApiOperation("删除用户") |
| 92 | - @ApiImplicitParam(name = "id", value = "编号", readOnly = true, example = "1024") | 92 | + @ApiImplicitParam(name = "id", value = "编号", readOnly = true, example = "1024", dataTypeClass = Long.class) |
| 93 | @PostMapping("/delete") | 93 | @PostMapping("/delete") |
| 94 | // @PreAuthorize("@ss.hasPermi('system:user:remove')") | 94 | // @PreAuthorize("@ss.hasPermi('system:user:remove')") |
| 95 | // @Log(title = "用户管理", businessType = BusinessType.DELETE) | 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,20 +11,14 @@ import java.util.Date; | ||
| 11 | * 用户 Excel 导出响应 VO | 11 | * 用户 Excel 导出响应 VO |
| 12 | */ | 12 | */ |
| 13 | @Data | 13 | @Data |
| 14 | -public class SysUserExcelRespVO { | 14 | +public class SysUserExcelRespBackVO { |
| 15 | 15 | ||
| 16 | @Excel(name = "用户序号", cellType = Excel.ColumnType.NUMERIC, prompt = "用户编号") | 16 | @Excel(name = "用户序号", cellType = Excel.ColumnType.NUMERIC, prompt = "用户编号") |
| 17 | private Long id; | 17 | private Long id; |
| 18 | 18 | ||
| 19 | - /** | ||
| 20 | - * 用户账号 | ||
| 21 | - */ | ||
| 22 | @Excel(name = "登录名称") | 19 | @Excel(name = "登录名称") |
| 23 | private String username; | 20 | private String username; |
| 24 | 21 | ||
| 25 | - /** | ||
| 26 | - * 用户昵称 | ||
| 27 | - */ | ||
| 28 | @Excel(name = "用户名称") | 22 | @Excel(name = "用户名称") |
| 29 | private String nickname; | 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 | package cn.iocoder.dashboard.modules.system.service.dict; | 1 | package cn.iocoder.dashboard.modules.system.service.dict; |
| 2 | 2 | ||
| 3 | import cn.iocoder.dashboard.common.pojo.PageResult; | 3 | import cn.iocoder.dashboard.common.pojo.PageResult; |
| 4 | +import cn.iocoder.dashboard.framework.dict.core.service.DictDataFrameworkService; | ||
| 4 | import cn.iocoder.dashboard.modules.system.controller.dict.vo.data.SysDictDataCreateReqVO; | 5 | import cn.iocoder.dashboard.modules.system.controller.dict.vo.data.SysDictDataCreateReqVO; |
| 5 | import cn.iocoder.dashboard.modules.system.controller.dict.vo.data.SysDictDataPageReqVO; | 6 | import cn.iocoder.dashboard.modules.system.controller.dict.vo.data.SysDictDataPageReqVO; |
| 6 | import cn.iocoder.dashboard.modules.system.controller.dict.vo.data.SysDictDataUpdateReqVO; | 7 | import cn.iocoder.dashboard.modules.system.controller.dict.vo.data.SysDictDataUpdateReqVO; |
| @@ -13,8 +14,18 @@ import java.util.List; | @@ -13,8 +14,18 @@ import java.util.List; | ||
| 13 | * | 14 | * |
| 14 | * @author ruoyi | 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 | List<SysDictDataDO> listDictDatas(); | 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,9 +12,11 @@ import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dict.SysDictData | ||
| 12 | import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dict.SysDictTypeDO; | 12 | import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.dict.SysDictTypeDO; |
| 13 | import cn.iocoder.dashboard.modules.system.service.dict.SysDictDataService; | 13 | import cn.iocoder.dashboard.modules.system.service.dict.SysDictDataService; |
| 14 | import cn.iocoder.dashboard.modules.system.service.dict.SysDictTypeService; | 14 | import cn.iocoder.dashboard.modules.system.service.dict.SysDictTypeService; |
| 15 | +import com.google.common.collect.ImmutableTable; | ||
| 15 | import org.springframework.stereotype.Service; | 16 | import org.springframework.stereotype.Service; |
| 16 | 17 | ||
| 17 | import javax.annotation.Resource; | 18 | import javax.annotation.Resource; |
| 19 | +import java.util.ArrayList; | ||
| 18 | import java.util.Comparator; | 20 | import java.util.Comparator; |
| 19 | import java.util.List; | 21 | import java.util.List; |
| 20 | 22 | ||
| @@ -32,6 +34,21 @@ public class SysDictDataServiceImpl implements SysDictDataService { | @@ -32,6 +34,21 @@ public class SysDictDataServiceImpl implements SysDictDataService { | ||
| 32 | .comparing(SysDictDataDO::getDictType) | 34 | .comparing(SysDictDataDO::getDictType) |
| 33 | .thenComparingInt(SysDictDataDO::getSort); | 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 | @Resource | 52 | @Resource |
| 36 | private SysDictTypeService dictTypeService; | 53 | private SysDictTypeService dictTypeService; |
| 37 | 54 | ||
| @@ -39,6 +56,21 @@ public class SysDictDataServiceImpl implements SysDictDataService { | @@ -39,6 +56,21 @@ public class SysDictDataServiceImpl implements SysDictDataService { | ||
| 39 | private SysDictDataMapper dictDataMapper; | 56 | private SysDictDataMapper dictDataMapper; |
| 40 | 57 | ||
| 41 | @Override | 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 | public List<SysDictDataDO> listDictDatas() { | 74 | public List<SysDictDataDO> listDictDatas() { |
| 43 | List<SysDictDataDO> list = dictDataMapper.selectList(); | 75 | List<SysDictDataDO> list = dictDataMapper.selectList(); |
| 44 | list.sort(COMPARATOR_TYPE_AND_SORT); | 76 | list.sort(COMPARATOR_TYPE_AND_SORT); |
| @@ -130,4 +162,19 @@ public class SysDictDataServiceImpl implements SysDictDataService { | @@ -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 | } |