Skip to content

Commit 9319a0d

Browse files
🚔 V1.4.0 用户角色权限部门验证码
1 parent de94916 commit 9319a0d

22 files changed

+380
-142
lines changed

CHANGELOG.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
- 优化LogAop配置
1414
- 代码生成模板优化,三种生成策略
1515
- 自定义生成Shiro `RequiresPermissions`注解
16-
- Jackson工具类,按字段顺序格式化输出
16+
- `Jackson`工具类,按字段顺序格式化输出
17+
- `BaseEnum` 枚举父接口,`EnumController`,`BaseEnumUtil`, `EnumTypeValidator` 校验/获取枚举信息
1718

1819
### 🐞 Bug Fixes
1920
- fix #81 刷新token问题
@@ -29,6 +30,7 @@
2930
- Upgrade to `lombok` 1.18.10
3031
- Upgrade to `hutool` 5.0.3
3132
- Upgrade to `mapstruct` 1.3.1.Final
33+
- Upgrade to `hutool` 5.0.4
3234

3335

3436
## [V1.3.1-RELEASE] 2019.10.15

pom.xml

+14-1
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,13 @@
6464
<reflections.version>0.9.11</reflections.version>
6565
<jansi.version>1.18</jansi.version>
6666
<lombok.version>1.18.10</lombok.version>
67-
<hutool.version>5.0.3</hutool.version>
67+
<hutool.version>5.0.4</hutool.version>
6868
<junit.version>4.12</junit.version>
6969
<ini4j.version>0.5.4</ini4j.version>
7070
<mapstruct.version>1.3.1.Final</mapstruct.version>
7171
<shiro.version>1.4.1</shiro.version>
7272
<jwt.version>3.8.3</jwt.version>
73+
<guava.version>28.1-jre</guava.version>
7374

7475
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
7576
<maven-resources-plugin.version>3.1.0</maven-resources-plugin.version>
@@ -175,6 +176,12 @@
175176
<groupId>io.springfox</groupId>
176177
<artifactId>springfox-swagger2</artifactId>
177178
<version>${swagger2.version}</version>
179+
<exclusions>
180+
<exclusion>
181+
<groupId>com.google.guava</groupId>
182+
<artifactId>guava</artifactId>
183+
</exclusion>
184+
</exclusions>
178185
</dependency>
179186
<dependency>
180187
<groupId>io.springfox</groupId>
@@ -224,6 +231,12 @@
224231
<version>${reflections.version}</version>
225232
</dependency>
226233

234+
<dependency>
235+
<groupId>com.google.guava</groupId>
236+
<artifactId>guava</artifactId>
237+
<version>${guava.version}</version>
238+
</dependency>
239+
227240
<dependency>
228241
<groupId>org.fusesource.jansi</groupId>
229242
<artifactId>jansi</artifactId>

src/main/java/io/geekidea/springbootplus/common/constraints/EnumType.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package io.geekidea.springbootplus.common.constraints;
1818

19-
import io.geekidea.springbootplus.common.enums.BaseTypeStateEnum;
19+
import io.geekidea.springbootplus.common.enums.BaseEnum;
2020

2121
import javax.validation.Constraint;
2222
import javax.validation.Payload;
@@ -39,7 +39,7 @@
3939
public @interface EnumType {
4040
String message() default "请输入正确的类型值";
4141

42-
Class<? extends BaseTypeStateEnum> type();
42+
Class<? extends BaseEnum> type();
4343

4444
Class<?>[] groups() default { };
4545

src/main/java/io/geekidea/springbootplus/common/constraints/EnumTypeValidator.java

+18-17
Original file line numberDiff line numberDiff line change
@@ -16,35 +16,36 @@
1616

1717
package io.geekidea.springbootplus.common.constraints;
1818

19-
import io.geekidea.springbootplus.common.enums.BaseTypeStateEnum;
19+
import io.geekidea.springbootplus.common.enums.BaseEnum;
2020
import io.geekidea.springbootplus.common.exception.BusinessException;
21-
import io.geekidea.springbootplus.util.EnumUtil;
21+
import io.geekidea.springbootplus.util.BaseEnumUtil;
2222

2323
import javax.validation.ConstraintValidator;
2424
import javax.validation.ConstraintValidatorContext;
2525

2626
/**
2727
* 自定义系统内的枚举验证注解实现类
28+
*
2829
* @author geekidea
2930
* @date 2018-11-08
3031
*/
3132
public class EnumTypeValidator implements ConstraintValidator<EnumType, Integer> {
3233

33-
private Class<? extends BaseTypeStateEnum> baseTypeStateEnum;
34+
private Class<? extends BaseEnum> baseEnum;
3435

35-
@Override
36-
public void initialize(EnumType parameters) {
37-
baseTypeStateEnum = parameters.type();
38-
if (baseTypeStateEnum == null){
39-
throw new BusinessException("请传入枚举类型类");
40-
}
41-
}
36+
@Override
37+
public void initialize(EnumType parameters) {
38+
baseEnum = parameters.type();
39+
if (baseEnum == null) {
40+
throw new BusinessException("请传入枚举类型类");
41+
}
42+
}
4243

43-
@Override
44-
public boolean isValid(Integer value, ConstraintValidatorContext constraintValidatorContext) {
45-
if (value ==null){
46-
return true;
47-
}
48-
return EnumUtil.exists(baseTypeStateEnum,value);
49-
}
44+
@Override
45+
public boolean isValid(Integer value, ConstraintValidatorContext constraintValidatorContext) {
46+
if (value == null) {
47+
return true;
48+
}
49+
return BaseEnumUtil.exists(baseEnum, value);
50+
}
5051
}

src/main/java/io/geekidea/springbootplus/common/controller/ApiDocController.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@
3535
public class ApiDocController extends BaseController {
3636

3737
/**
38-
* swaggerUI
39-
*/
38+
* swaggerUI
39+
*/
4040
@GetMapping("")
41-
public String swaggerUI(){
41+
public String swaggerUI() {
4242
return "redirect:/swagger-ui.html";
4343
}
4444

src/main/java/io/geekidea/springbootplus/common/controller/BaseController.java

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public abstract class BaseController extends ApiController {
3939
public HttpServletRequest getRequest() {
4040
return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
4141
}
42+
4243
/**
4344
* 获取当前请求
4445
*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/*
2+
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.geekidea.springbootplus.common.controller;
18+
19+
import io.geekidea.springbootplus.common.api.ApiResult;
20+
import io.geekidea.springbootplus.common.enums.BaseEnum;
21+
import io.geekidea.springbootplus.common.vo.EnumVo;
22+
import io.geekidea.springbootplus.util.BaseEnumUtil;
23+
import lombok.extern.slf4j.Slf4j;
24+
import org.apache.commons.collections4.CollectionUtils;
25+
import org.apache.commons.lang3.ArrayUtils;
26+
import org.reflections.Reflections;
27+
import org.springframework.beans.factory.annotation.Value;
28+
import org.springframework.web.bind.annotation.GetMapping;
29+
import org.springframework.web.bind.annotation.RestController;
30+
31+
import javax.annotation.PostConstruct;
32+
import java.lang.reflect.Method;
33+
import java.util.*;
34+
35+
/**
36+
* <p>
37+
* 展示实现BaseEnum接口的所有枚举值
38+
* </p>
39+
*
40+
* @author geekidea
41+
* @date 2018/11/02
42+
*/
43+
@RestController
44+
@Slf4j
45+
public class EnumController {
46+
47+
/**
48+
* 枚举包路径
49+
*/
50+
@Value("${spring-boot-plus.enum-packages}")
51+
private String[] enumPackages;
52+
53+
@GetMapping("/enum")
54+
public ApiResult<String> enumList() {
55+
log.debug("enumList...");
56+
return ApiResult.ok(BaseEnumUtil.getEnumMap());
57+
}
58+
59+
@PostConstruct
60+
public void init() {
61+
try {
62+
// 获取BaseEnum接口的所有实现
63+
log.debug("enumPackages:" + Arrays.toString(enumPackages));
64+
if (ArrayUtils.isEmpty(enumPackages)) {
65+
log.info("enumPackages为空");
66+
return;
67+
}
68+
Reflections reflections = new Reflections(enumPackages);
69+
Set<Class<? extends BaseEnum>> set = reflections.getSubTypesOf(BaseEnum.class);
70+
if (CollectionUtils.isEmpty(set)) {
71+
return;
72+
}
73+
// 循环获取BaseEnum枚举
74+
for (Class<? extends BaseEnum> clazz : set) {
75+
List<EnumVo> list = new ArrayList<>();
76+
Object[] objects = clazz.getEnumConstants();
77+
Method codeMethod = clazz.getDeclaredMethod("getCode");
78+
Method descMethod = clazz.getDeclaredMethod("getDesc");
79+
Map<Integer, String> codeDescMap = new HashMap<>(objects.length);
80+
for (Object object : objects) {
81+
Integer code = (Integer) codeMethod.invoke(object);
82+
String desc = (String) descMethod.invoke(object);
83+
EnumVo enumVo = new EnumVo();
84+
enumVo.setCode(code);
85+
enumVo.setDesc(desc);
86+
list.add(enumVo);
87+
codeDescMap.put(code, desc);
88+
}
89+
// 设置map
90+
BaseEnumUtil.getEnumMap().put(clazz.getSimpleName(), list);
91+
BaseEnumUtil.getEnumClassMap().put(clazz.getName(), codeDescMap);
92+
}
93+
log.debug("baseEnumMap:{}", BaseEnumUtil.getEnumMap());
94+
log.debug("baseEnumClassMap:{}", BaseEnumUtil.getEnumClassMap());
95+
} catch (Exception e) {
96+
log.error("获取BaseEnum枚举map异常", e);
97+
}
98+
}
99+
100+
}

src/main/java/io/geekidea/springbootplus/common/controller/IndexController.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@
2424

2525
/**
2626
* <p>
27-
* 项目根路径提示信息
27+
* 项目根路径提示信息
2828
* </p>
29+
*
2930
* @author geekidea
3031
* @date 2018/11/12
3132
*/
@@ -35,7 +36,7 @@
3536
public class IndexController {
3637

3738
@RequestMapping("/index")
38-
public ApiResult<String> index(){
39+
public ApiResult<String> index() {
3940
log.debug("index...");
4041
return ApiResult.ok("Welcome to Spring Boot Plus Project...");
4142
}

src/main/java/io/geekidea/springbootplus/common/enums/BaseTypeStateEnum.java renamed to src/main/java/io/geekidea/springbootplus/common/enums/BaseEnum.java

+15-4
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,25 @@
1717
package io.geekidea.springbootplus.common.enums;
1818

1919
/**
20+
* 枚举类型父接口
21+
*
2022
* @author geekidea
2123
* @date 2018-11-08
2224
*/
23-
public interface BaseTypeStateEnum {
24-
25-
Integer getKey();
25+
public interface BaseEnum {
2626

27-
String getValue();
27+
/**
28+
* 获取枚举索引
29+
*
30+
* @return
31+
*/
32+
Integer getCode();
2833

34+
/**
35+
* 获取描述
36+
*
37+
* @return
38+
*/
39+
String getDesc();
2940

3041
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.geekidea.springbootplus.common.vo;
18+
19+
import lombok.Data;
20+
21+
/**
22+
* 枚举类型VO
23+
*
24+
* @author geekidea
25+
* @date 2019-11-02
26+
**/
27+
@Data
28+
public class EnumVo {
29+
30+
/**
31+
* 枚举code
32+
*/
33+
private Integer code;
34+
35+
/**
36+
* 枚举描述
37+
*/
38+
private String desc;
39+
40+
}

src/main/java/io/geekidea/springbootplus/core/properties/SpringBootPlusProperties.java

+7
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
/**
2929
* spring-boot-plus属性配置信息
30+
*
3031
* @author geekidea
3132
* @date 2019-08-04
3233
* @since 1.2.0-RELEASE
@@ -45,6 +46,11 @@ public class SpringBootPlusProperties {
4546
*/
4647
private boolean enableVerifyCode;
4748

49+
/**
50+
* 实现BaseEnum接口的枚举包
51+
*/
52+
private String[] enumPackages;
53+
4854
/**
4955
* 拦截器配置
5056
*/
@@ -97,6 +103,7 @@ public class SpringBootPlusProperties {
97103

98104
/**
99105
* 项目静态资源访问配置
106+
*
100107
* @see SpringBootPlusWebMvcConfig addResourceHandlers
101108
*/
102109
private String resourceHandlers;

0 commit comments

Comments
 (0)