Skip to content

Commit

Permalink
🚔 V1.4.0 用户角色权限部门验证码
Browse files Browse the repository at this point in the history
  • Loading branch information
springboot-plus committed Nov 3, 2019
1 parent de94916 commit 9319a0d
Show file tree
Hide file tree
Showing 22 changed files with 380 additions and 142 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
- 优化LogAop配置
- 代码生成模板优化,三种生成策略
- 自定义生成Shiro `RequiresPermissions`注解
- Jackson工具类,按字段顺序格式化输出
- `Jackson`工具类,按字段顺序格式化输出
- `BaseEnum` 枚举父接口,`EnumController`,`BaseEnumUtil`, `EnumTypeValidator` 校验/获取枚举信息

### 🐞 Bug Fixes
- fix #81 刷新token问题
Expand All @@ -29,6 +30,7 @@
- Upgrade to `lombok` 1.18.10
- Upgrade to `hutool` 5.0.3
- Upgrade to `mapstruct` 1.3.1.Final
- Upgrade to `hutool` 5.0.4


## [V1.3.1-RELEASE] 2019.10.15
Expand Down
15 changes: 14 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,13 @@
<reflections.version>0.9.11</reflections.version>
<jansi.version>1.18</jansi.version>
<lombok.version>1.18.10</lombok.version>
<hutool.version>5.0.3</hutool.version>
<hutool.version>5.0.4</hutool.version>
<junit.version>4.12</junit.version>
<ini4j.version>0.5.4</ini4j.version>
<mapstruct.version>1.3.1.Final</mapstruct.version>
<shiro.version>1.4.1</shiro.version>
<jwt.version>3.8.3</jwt.version>
<guava.version>28.1-jre</guava.version>

<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
<maven-resources-plugin.version>3.1.0</maven-resources-plugin.version>
Expand Down Expand Up @@ -175,6 +176,12 @@
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${swagger2.version}</version>
<exclusions>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
Expand Down Expand Up @@ -224,6 +231,12 @@
<version>${reflections.version}</version>
</dependency>

<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>

<dependency>
<groupId>org.fusesource.jansi</groupId>
<artifactId>jansi</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package io.geekidea.springbootplus.common.constraints;

import io.geekidea.springbootplus.common.enums.BaseTypeStateEnum;
import io.geekidea.springbootplus.common.enums.BaseEnum;

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

Class<? extends BaseTypeStateEnum> type();
Class<? extends BaseEnum> type();

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,36 @@

package io.geekidea.springbootplus.common.constraints;

import io.geekidea.springbootplus.common.enums.BaseTypeStateEnum;
import io.geekidea.springbootplus.common.enums.BaseEnum;
import io.geekidea.springbootplus.common.exception.BusinessException;
import io.geekidea.springbootplus.util.EnumUtil;
import io.geekidea.springbootplus.util.BaseEnumUtil;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

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

private Class<? extends BaseTypeStateEnum> baseTypeStateEnum;
private Class<? extends BaseEnum> baseEnum;

@Override
public void initialize(EnumType parameters) {
baseTypeStateEnum = parameters.type();
if (baseTypeStateEnum == null){
throw new BusinessException("请传入枚举类型类");
}
}
@Override
public void initialize(EnumType parameters) {
baseEnum = parameters.type();
if (baseEnum == null) {
throw new BusinessException("请传入枚举类型类");
}
}

@Override
public boolean isValid(Integer value, ConstraintValidatorContext constraintValidatorContext) {
if (value ==null){
return true;
}
return EnumUtil.exists(baseTypeStateEnum,value);
}
@Override
public boolean isValid(Integer value, ConstraintValidatorContext constraintValidatorContext) {
if (value == null) {
return true;
}
return BaseEnumUtil.exists(baseEnum, value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@
public class ApiDocController extends BaseController {

/**
* swaggerUI
*/
* swaggerUI
*/
@GetMapping("")
public String swaggerUI(){
public String swaggerUI() {
return "redirect:/swagger-ui.html";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public abstract class BaseController extends ApiController {
public HttpServletRequest getRequest() {
return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
}

/**
* 获取当前请求
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.geekidea.springbootplus.common.controller;

import io.geekidea.springbootplus.common.api.ApiResult;
import io.geekidea.springbootplus.common.enums.BaseEnum;
import io.geekidea.springbootplus.common.vo.EnumVo;
import io.geekidea.springbootplus.util.BaseEnumUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.reflections.Reflections;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.PostConstruct;
import java.lang.reflect.Method;
import java.util.*;

/**
* <p>
* 展示实现BaseEnum接口的所有枚举值
* </p>
*
* @author geekidea
* @date 2018/11/02
*/
@RestController
@Slf4j
public class EnumController {

/**
* 枚举包路径
*/
@Value("${spring-boot-plus.enum-packages}")
private String[] enumPackages;

@GetMapping("/enum")
public ApiResult<String> enumList() {
log.debug("enumList...");
return ApiResult.ok(BaseEnumUtil.getEnumMap());
}

@PostConstruct
public void init() {
try {
// 获取BaseEnum接口的所有实现
log.debug("enumPackages:" + Arrays.toString(enumPackages));
if (ArrayUtils.isEmpty(enumPackages)) {
log.info("enumPackages为空");
return;
}
Reflections reflections = new Reflections(enumPackages);
Set<Class<? extends BaseEnum>> set = reflections.getSubTypesOf(BaseEnum.class);
if (CollectionUtils.isEmpty(set)) {
return;
}
// 循环获取BaseEnum枚举
for (Class<? extends BaseEnum> clazz : set) {
List<EnumVo> list = new ArrayList<>();
Object[] objects = clazz.getEnumConstants();
Method codeMethod = clazz.getDeclaredMethod("getCode");
Method descMethod = clazz.getDeclaredMethod("getDesc");
Map<Integer, String> codeDescMap = new HashMap<>(objects.length);
for (Object object : objects) {
Integer code = (Integer) codeMethod.invoke(object);
String desc = (String) descMethod.invoke(object);
EnumVo enumVo = new EnumVo();
enumVo.setCode(code);
enumVo.setDesc(desc);
list.add(enumVo);
codeDescMap.put(code, desc);
}
// 设置map
BaseEnumUtil.getEnumMap().put(clazz.getSimpleName(), list);
BaseEnumUtil.getEnumClassMap().put(clazz.getName(), codeDescMap);
}
log.debug("baseEnumMap:{}", BaseEnumUtil.getEnumMap());
log.debug("baseEnumClassMap:{}", BaseEnumUtil.getEnumClassMap());
} catch (Exception e) {
log.error("获取BaseEnum枚举map异常", e);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@

/**
* <p>
* 项目根路径提示信息
* 项目根路径提示信息
* </p>
*
* @author geekidea
* @date 2018/11/12
*/
Expand All @@ -35,7 +36,7 @@
public class IndexController {

@RequestMapping("/index")
public ApiResult<String> index(){
public ApiResult<String> index() {
log.debug("index...");
return ApiResult.ok("Welcome to Spring Boot Plus Project...");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,25 @@
package io.geekidea.springbootplus.common.enums;

/**
* 枚举类型父接口
*
* @author geekidea
* @date 2018-11-08
*/
public interface BaseTypeStateEnum {

Integer getKey();
public interface BaseEnum {

String getValue();
/**
* 获取枚举索引
*
* @return
*/
Integer getCode();

/**
* 获取描述
*
* @return
*/
String getDesc();

}
40 changes: 40 additions & 0 deletions src/main/java/io/geekidea/springbootplus/common/vo/EnumVo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2019-2029 geekidea(https://github.com/geekidea)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.geekidea.springbootplus.common.vo;

import lombok.Data;

/**
* 枚举类型VO
*
* @author geekidea
* @date 2019-11-02
**/
@Data
public class EnumVo {

/**
* 枚举code
*/
private Integer code;

/**
* 枚举描述
*/
private String desc;

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

/**
* spring-boot-plus属性配置信息
*
* @author geekidea
* @date 2019-08-04
* @since 1.2.0-RELEASE
Expand All @@ -45,6 +46,11 @@ public class SpringBootPlusProperties {
*/
private boolean enableVerifyCode;

/**
* 实现BaseEnum接口的枚举包
*/
private String[] enumPackages;

/**
* 拦截器配置
*/
Expand Down Expand Up @@ -97,6 +103,7 @@ public class SpringBootPlusProperties {

/**
* 项目静态资源访问配置
*
* @see SpringBootPlusWebMvcConfig addResourceHandlers
*/
private String resourceHandlers;
Expand Down
Loading

0 comments on commit 9319a0d

Please sign in to comment.