diff --git a/README.md b/README.md
index f476d0fd534716ee6044568c15ebd34a2e7a22b9..54a1189e0369f707765c1b50214a69306e2dd2e0 100644
--- a/README.md
+++ b/README.md
@@ -21,11 +21,14 @@ secret-boot脚手架(根据核心依赖版本长期更新,正常更新周期
| ---- | ---- |
| secret-boot-framework-core | 框架核心模块 |
| secret-boot-framework-cache | 框架缓存模块 |
-| secret-boot-framework-mybatis-plus | mybatis-plus扩展模块 |
| secret-boot-framework-captcha | 图形验证码 |
-| secret-boot-framework-ffmpeg | ffmpet工具模块 |
+| secret-boot-framework-dozer | dozer工具模块 |
| secret-boot-framework-excel | excel工具模块 |
+| secret-boot-framework-ffmpeg | ffmpet工具模块 |
| secret-boot-framework-jpa | jpa扩展模块 |
+| secret-boot-framework-mail | mail封装模块 |
+| secret-boot-framework-mybatis-plus | mybatis-plus扩展模块 |
+| secret-boot-framework-poi | poi封装模块 |
| secret-boot-framework-security | spring-security扩展模块 |
| secret-boot-framework-shiro | shiro扩展模块 |
@@ -40,6 +43,7 @@ secret-boot脚手架(根据核心依赖版本长期更新,正常更新周期

+
#### 使用方法
已发布到maven中央仓库,建议使用1.4.0+版本
```
@@ -48,7 +52,7 @@ secret-boot脚手架(根据核心依赖版本长期更新,正常更新周期
com.gitee.secretopen
secret-boot-framework-dependencies
- 1.5.0
+ 1.6.0
pom
import
@@ -58,18 +62,18 @@ secret-boot脚手架(根据核心依赖版本长期更新,正常更新周期
com.gitee.secretopen
secret-boot-framework-all
- 1.5.0
+ 1.6.0
```
#### 核心依赖
| 组件 | 版本 |
| ---- | ---- |
-| springboot | 2.4.3 |
-| mybatis-plus | 3.4.2 |
+| springboot | 2.5.3 |
+| mybatis-plus | 3.4.3 |
| mysql | 5.7/8.x |
| redis | |
-| hutool | 5.5.9 |
+| hutool | |
#### 截图

diff --git a/pom.xml b/pom.xml
index b779e5affe2df95b3ba098e11e65f3714417740f..f2f18eff1386272020fface810a21c8a094d168f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -15,6 +15,9 @@
secret-boot-framework-security
secret-boot-framework-dependencies
secret-boot-framework-shiro
+ secret-boot-framework-mail
+ secret-boot-framework-poi
+ secret-boot-framework-dozer
@@ -22,7 +25,7 @@
com.gitee.secretopen
secret-boot-framework
- 1.5.0
+ 1.6.0
${project.groupId}:${project.artifactId}
secret-boot-framework是一个基于springboot的快速开发框架,实现开发中最基础的springboot、mybatis、redis整合,内置丰富的基础工具类,开箱即用
@@ -33,7 +36,7 @@
3.2.1
- 2.9.1
+ 3.3.0
1.6
@@ -97,15 +100,15 @@
org.apache.maven.plugins
maven-javadoc-plugin
${maven-javadoc-plugin.version}
-
- -Xdoclint:none
-
package
jar
+
+ -Xdoclint:none
+
diff --git a/secret-boot-framework-all/pom.xml b/secret-boot-framework-all/pom.xml
index cf06cf5db8959aed19d1b6968b3af8588e8a7553..73c78eb37c46222ea418e994cb942d902017c025 100644
--- a/secret-boot-framework-all/pom.xml
+++ b/secret-boot-framework-all/pom.xml
@@ -5,7 +5,7 @@
secret-boot-framework
com.gitee.secretopen
- 1.5.0
+ 1.6.0
4.0.0
@@ -14,38 +14,43 @@
com.gitee.secretopen
- secret-boot-framework-core
- ${project.parent.version}
+ secret-boot-framework-captcha
com.gitee.secretopen
secret-boot-framework-cache
- ${project.parent.version}
com.gitee.secretopen
- secret-boot-framework-jpa
- ${project.parent.version}
+ secret-boot-framework-captcha
com.gitee.secretopen
- secret-boot-framework-captcha
- ${project.parent.version}
+ secret-boot-framework-core
com.gitee.secretopen
- secret-boot-framework-ffmpeg
- ${project.parent.version}
+ secret-boot-framework-dozer
com.gitee.secretopen
secret-boot-framework-excel
- ${project.parent.version}
+
+
+ com.gitee.secretopen
+ secret-boot-framework-ffmpeg
+
+
+ com.gitee.secretopen
+ secret-boot-framework-jpa
+
+
+ com.gitee.secretopen
+ secret-boot-framework-mail
com.gitee.secretopen
secret-boot-framework-security
- ${project.parent.version}
diff --git a/secret-boot-framework-cache/pom.xml b/secret-boot-framework-cache/pom.xml
index e611448fccc4a5fd5966692983fd087d2714c88a..6ffbf706fb3cdf60cd42c7e46cd6bbea632057ee 100644
--- a/secret-boot-framework-cache/pom.xml
+++ b/secret-boot-framework-cache/pom.xml
@@ -5,7 +5,7 @@
secret-boot-framework
com.gitee.secretopen
- 1.5.0
+ 1.6.0
${project.artifactId}
4.0.0
@@ -16,7 +16,6 @@
com.gitee.secretopen
secret-boot-framework-core
- ${project.parent.version}
diff --git a/secret-boot-framework-cache/src/main/java/cn/chenc/framework/cache/aspect/RedisCacheAspect.java b/secret-boot-framework-cache/src/main/java/cn/chenc/framework/cache/aspect/RedisCacheAspect.java
index bb6e1b1c05b027afda2c03a0d128a5a03c308862..a8c6dda8d6865b0e91073808b712a884e54794d1 100644
--- a/secret-boot-framework-cache/src/main/java/cn/chenc/framework/cache/aspect/RedisCacheAspect.java
+++ b/secret-boot-framework-cache/src/main/java/cn/chenc/framework/cache/aspect/RedisCacheAspect.java
@@ -1,7 +1,7 @@
package cn.chenc.framework.cache.aspect;
import cn.chenc.framework.cache.annotation.RedisCache;
-import cn.chenc.framework.cache.util.RedisUtils;
+import cn.chenc.framework.cache.service.RedisService;
import cn.chenc.framework.core.util.AspectUtil;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
@@ -24,7 +24,7 @@ public class RedisCacheAspect {
private static final String BIZ_CACHE_PREFIX = "biz_cache_";
@Autowired
- private RedisUtils redisUtils;
+ private RedisService redisService;
@Pointcut(value = "@annotation(cn.chenc.framework.cache.annotation.RedisCache)")
public void pointcut() {
@@ -43,22 +43,22 @@ public class RedisCacheAspect {
if (flush) {
String classPrefix = AspectUtil.INSTANCE.getKey(point, BIZ_CACHE_PREFIX);
log.info("清空缓存 - {}*", classPrefix);
- redisUtils.delBatch(classPrefix);
+ redisService.delBatch(classPrefix);
return point.proceed();
}
String key = AspectUtil.INSTANCE.getKey(point, cache.key(), BIZ_CACHE_PREFIX);
- boolean hasKey = redisUtils.hasKey(key);
+ boolean hasKey = redisService.hasKey(key);
if (hasKey) {
try {
log.info("{}从缓存中获取数据", key);
- return redisUtils.get(key);
+ return redisService.get(key);
} catch (Exception e) {
log.error("从缓存中获取数据失败!", e);
}
}
//先执行业务
Object result = point.proceed();
- redisUtils.set(key, result, cache.expire(), cache.unit());
+ redisService.set(key, result, cache.expire(), cache.unit());
log.info("{}从数据库中获取数据", key);
return result;
}
diff --git a/secret-boot-framework-cache/src/main/java/cn/chenc/framework/cache/util/RedisUtils.java b/secret-boot-framework-cache/src/main/java/cn/chenc/framework/cache/service/RedisService.java
similarity index 99%
rename from secret-boot-framework-cache/src/main/java/cn/chenc/framework/cache/util/RedisUtils.java
rename to secret-boot-framework-cache/src/main/java/cn/chenc/framework/cache/service/RedisService.java
index 1ec6eb0be400ba0e27d8ef642be66b866cef3b94..bc2108e0f7bf71a222002f8605daa3e9b823f82a 100644
--- a/secret-boot-framework-cache/src/main/java/cn/chenc/framework/cache/util/RedisUtils.java
+++ b/secret-boot-framework-cache/src/main/java/cn/chenc/framework/cache/service/RedisService.java
@@ -1,4 +1,4 @@
-package cn.chenc.framework.cache.util;
+package cn.chenc.framework.cache.service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.*;
@@ -15,7 +15,7 @@ import java.util.concurrent.TimeUnit;
*
*/
@Component
-public class RedisUtils {
+public class RedisService {
@Autowired
private RedisTemplate redisTemplate;
diff --git a/secret-boot-framework-cache/src/main/java/cn/chenc/framework/cache/util/RedissLockUtil.java b/secret-boot-framework-cache/src/main/java/cn/chenc/framework/cache/service/RedissLockService.java
similarity index 98%
rename from secret-boot-framework-cache/src/main/java/cn/chenc/framework/cache/util/RedissLockUtil.java
rename to secret-boot-framework-cache/src/main/java/cn/chenc/framework/cache/service/RedissLockService.java
index 5e174f0a123cd5e74f3d2f0d51f4ebde2d61f7a0..7c1d2778c97706806805058fc66b7105828dc7d1 100644
--- a/secret-boot-framework-cache/src/main/java/cn/chenc/framework/cache/util/RedissLockUtil.java
+++ b/secret-boot-framework-cache/src/main/java/cn/chenc/framework/cache/service/RedissLockService.java
@@ -1,4 +1,4 @@
-package cn.chenc.framework.cache.util;
+package cn.chenc.framework.cache.service;
import org.redisson.api.RLock;
import org.redisson.api.RMapCache;
@@ -12,7 +12,7 @@ import java.util.concurrent.TimeUnit;
* @date 2021/5/7 15:27
*
*/
-public class RedissLockUtil {
+public class RedissLockService {
private static RedissonClient redissonClient;
diff --git a/secret-boot-framework-captcha/pom.xml b/secret-boot-framework-captcha/pom.xml
index 7c3a904315ce8f0fa19bedb1ab9fd27c1410a149..201d138a175bf014454ef1e03e27ff49cf191483 100644
--- a/secret-boot-framework-captcha/pom.xml
+++ b/secret-boot-framework-captcha/pom.xml
@@ -5,7 +5,7 @@
secret-boot-framework
com.gitee.secretopen
- 1.5.0
+ 1.6.0
${project.artifactId}
4.0.0
@@ -15,7 +15,6 @@
com.gitee.secretopen
secret-boot-framework-core
- ${project.parent.version}
diff --git a/secret-boot-framework-core/pom.xml b/secret-boot-framework-core/pom.xml
index c11bf1ec6be23226bafb73f2b4659d0bd64f3940..20cc2900e5e1b4a3426ae793999ce33e468d1360 100644
--- a/secret-boot-framework-core/pom.xml
+++ b/secret-boot-framework-core/pom.xml
@@ -5,7 +5,7 @@
secret-boot-framework
com.gitee.secretopen
- 1.5.0
+ 1.6.0
${project.artifactId}
jar
@@ -37,13 +37,28 @@
spring-boot-starter-data-redis
true
-
+
+
+ org.springframework.boot
+ spring-boot-starter-jdbc
+ true
+
+
+
+ org.springframework.boot
+ spring-boot-starter-validation
+
+
com.google.guava
guava
-
-
+
+
+ com.alibaba
+ druid-spring-boot-starter
+ true
+
commons-fileupload
diff --git a/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/annotation/ChangDataSource.java b/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/annotation/ChangDataSource.java
new file mode 100644
index 0000000000000000000000000000000000000000..a7e64ef1d56e68b1e89ad3a2c38fc2197055ed65
--- /dev/null
+++ b/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/annotation/ChangDataSource.java
@@ -0,0 +1,17 @@
+package cn.chenc.framework.core.annotation;
+
+import java.lang.annotation.*;
+
+/**
+ * @description: 切换数据源
+ * @author secret
+ * @date 2021/7/21 22:59
+ *
+ */
+@Target({ElementType.METHOD})
+@Retention(RetentionPolicy.RUNTIME)
+@Documented
+public @interface ChangDataSource {
+ String name() default "master";
+}
+
diff --git a/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/aspect/DataSourceAspect.java b/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/aspect/DataSourceAspect.java
new file mode 100644
index 0000000000000000000000000000000000000000..98acf768dd27ed3255823ddfa5b3b85636bdeb07
--- /dev/null
+++ b/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/aspect/DataSourceAspect.java
@@ -0,0 +1,83 @@
+package cn.chenc.framework.core.aspect;
+
+import cn.chenc.framework.core.annotation.ChangDataSource;
+import cn.chenc.framework.core.mutidatasource.DynamicDataSource;
+import org.aspectj.lang.JoinPoint;
+import org.aspectj.lang.annotation.AfterReturning;
+import org.aspectj.lang.annotation.Aspect;
+import org.aspectj.lang.annotation.Before;
+import org.aspectj.lang.annotation.Pointcut;
+import org.aspectj.lang.reflect.MethodSignature;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.core.annotation.AnnotationUtils;
+import org.springframework.core.annotation.Order;
+import org.springframework.stereotype.Component;
+
+import java.util.Objects;
+
+/**
+ * @description: 动态数据源
+ * @author secret
+ * @date 2021/7/21 23:02
+ *
+ */
+@Aspect
+@Order(-10)
+@Component
+public class DataSourceAspect {
+ Logger logger = LoggerFactory.getLogger(DynamicDataSource.class);
+
+
+ public DataSourceAspect() {
+ }
+
+ @Pointcut("@annotation(cn.chenc.framework.core.annotation.ChangDataSource)"
+ + "|| @within(cn.chenc.framework.core.annotation.ChangDataSource)")
+ public void dsPointCut() {
+
+ }
+
+ /**
+ * 方法执行前进行
+ * @param point
+ * @throws Exception
+ */
+ @Before("dsPointCut()")
+ public void changeDataSource(JoinPoint point) throws Exception {
+ ChangDataSource source = getDataSource(point);
+ String name = source.name();
+ this.logger.info("change dataSource :" + name);
+ if (!DynamicDataSource.checkDataSourceType(name)) {
+ throw new Exception("数据源" + name + "不存在,使用默认数据源 ");
+ } else {
+ //切换数据源
+ DynamicDataSource.setDataSourceType(name);
+ }
+ }
+
+ /**
+ * 方法结束后进行
+ * @param point
+ */
+ @AfterReturning("dsPointCut()")
+ public void restoreDataSource(JoinPoint point) {
+ //方法执行结束后,销毁数据源
+ DynamicDataSource.clearDataSourceType();
+ }
+
+ /**
+ * 获取需要切换的数据源
+ */
+ public ChangDataSource getDataSource(JoinPoint point)
+ {
+ MethodSignature signature = (MethodSignature) point.getSignature();
+ ChangDataSource dataSource = AnnotationUtils.findAnnotation(signature.getMethod(), ChangDataSource.class);
+ if (Objects.nonNull(dataSource))
+ {
+ return dataSource;
+ }
+
+ return AnnotationUtils.findAnnotation(signature.getDeclaringType(), ChangDataSource.class);
+ }
+}
diff --git a/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/aspect/PreAuthorizeAspect.java b/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/aspect/PreAuthorizeAspect.java
index b59add1600bb0d2e0d4364a2dadc8a6fe599bb3c..1dd2462e6e2e12cbc7dc716cc77ffc2d0a4b1d71 100644
--- a/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/aspect/PreAuthorizeAspect.java
+++ b/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/aspect/PreAuthorizeAspect.java
@@ -1,9 +1,9 @@
package cn.chenc.framework.core.aspect;
import cn.chenc.framework.core.annotation.PreAuthorize;
-import cn.chenc.framework.core.component.JwtTemplate;
+import cn.chenc.framework.core.component.AbstractJwtTemplate;
import cn.chenc.framework.core.exception.PreAuthorizeException;
-import cn.chenc.framework.core.model.LoginUser;
+import cn.chenc.framework.core.model.AbstractLoginUser;
import cn.chenc.framework.core.model.request.RequestHolder;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
@@ -29,7 +29,7 @@ import java.util.Collection;
public class PreAuthorizeAspect {
@Autowired(required = false)
- private JwtTemplate jwtTemplate;
+ private AbstractJwtTemplate jwtTemplate;
/** 所有权限标识 */
private static final String ALL_PERMISSION = "*:*:*";
@@ -96,7 +96,7 @@ public class PreAuthorizeAspect {
* @return 用户是否具备某权限
*/
public boolean hasPermi(String permission) {
- LoginUser userInfo = jwtTemplate.getLoginUser(RequestHolder.getRequest());
+ AbstractLoginUser userInfo = jwtTemplate.getLoginUser(RequestHolder.getRequest());
if (StringUtils.isEmpty(userInfo) || CollectionUtils.isEmpty(userInfo.getPermissions())) {
return false;
}
@@ -120,7 +120,7 @@ public class PreAuthorizeAspect {
* @return 用户是否具有以下任意一个权限
*/
public boolean hasAnyPermi(String[] permissions) {
- LoginUser userInfo = jwtTemplate.getLoginUser(RequestHolder.getRequest());
+ AbstractLoginUser userInfo = jwtTemplate.getLoginUser(RequestHolder.getRequest());
if (StringUtils.isEmpty(userInfo) || CollectionUtils.isEmpty(userInfo.getPermissions())) {
return false;
}
@@ -140,7 +140,7 @@ public class PreAuthorizeAspect {
* @return 用户是否具备某角色
*/
public boolean hasRole(String role) {
- LoginUser userInfo = jwtTemplate.getLoginUser(RequestHolder.getRequest());
+ AbstractLoginUser userInfo = jwtTemplate.getLoginUser(RequestHolder.getRequest());
if (StringUtils.isEmpty(userInfo) || CollectionUtils.isEmpty(userInfo.getRoles())) {
return false;
}
@@ -169,7 +169,7 @@ public class PreAuthorizeAspect {
* @return 用户是否具有以下任意一个角色
*/
public boolean hasAnyRoles(String[] roles) {
- LoginUser userInfo = jwtTemplate.getLoginUser(RequestHolder.getRequest());
+ AbstractLoginUser userInfo = jwtTemplate.getLoginUser(RequestHolder.getRequest());
if (StringUtils.isEmpty(userInfo) || CollectionUtils.isEmpty(userInfo.getRoles())) {
return false;
}
diff --git a/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/component/AbstractJwtTemplate.java b/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/component/AbstractJwtTemplate.java
new file mode 100644
index 0000000000000000000000000000000000000000..930a6a01f9a47866d54afcaf6e2bf7f1d55b6cc2
--- /dev/null
+++ b/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/component/AbstractJwtTemplate.java
@@ -0,0 +1,61 @@
+package cn.chenc.framework.core.component;
+
+import cn.chenc.framework.core.model.AbstractLoginUser;
+
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ * @description: JwtTemplate抽象接口
+ * @author secret
+ * @date 2021/7/1 22:48
+ *
+ */
+public interface AbstractJwtTemplate {
+
+
+ /**
+ * 获取登录用户
+ * @param request
+ * @return
+ */
+ AbstractLoginUser getLoginUser(HttpServletRequest request);
+
+ /**
+ * 设置登录用户
+ * @param loginUser
+ */
+ void setLoginUser(AbstractLoginUser loginUser);
+
+ /**
+ * 删除登录用户
+ * @param token
+ */
+ void delLoginUser(String token);
+
+ /**
+ * 创建token
+ * @param loginUser
+ * @return
+ */
+ String createToken(AbstractLoginUser loginUser);
+
+ /**
+ * 验证令牌有效期,相差不足20分钟,自动刷新缓存
+ * @param loginUser
+ * @return 令牌
+ */
+ void verifyToken(AbstractLoginUser loginUser);
+
+ /**
+ * 刷新令牌有效期
+ * @param loginUser 登录信息
+ */
+ void refreshToken(AbstractLoginUser loginUser);
+
+ /**
+ * 设置用户代理信息
+ * @param loginUser 登录信息
+ */
+ void setUserAgent(AbstractLoginUser loginUser);
+
+}
diff --git a/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/component/JwtTemplate.java b/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/component/JwtTemplate.java
index 262db30192d6222f65061de76a586fc74ef85d89..136dade3397ace9f3d3895e7fe204ee573eef8e4 100644
--- a/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/component/JwtTemplate.java
+++ b/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/component/JwtTemplate.java
@@ -2,7 +2,7 @@ package cn.chenc.framework.core.component;
import cn.chenc.framework.core.consts.CommonConst;
-import cn.chenc.framework.core.model.LoginUser;
+import cn.chenc.framework.core.model.AbstractLoginUser;
import cn.chenc.framework.core.model.request.RequestHolder;
import cn.chenc.framework.core.util.StringUtils;
import cn.chenc.framework.core.util.ip.IpUtils;
@@ -20,7 +20,7 @@ import java.util.Map;
* jwt token验证处理
*
*/
-public class JwtTemplate {
+public class JwtTemplate implements AbstractJwtTemplate{
// 令牌自定义标识
private String header= CommonConst.HEADER;
@@ -66,7 +66,8 @@ public class JwtTemplate {
*
* @return 用户信息
*/
- public LoginUser getLoginUser(HttpServletRequest request)
+ @Override
+ public AbstractLoginUser getLoginUser(HttpServletRequest request)
{
// 获取请求携带的令牌
String token = getToken(request);
@@ -76,7 +77,7 @@ public class JwtTemplate {
// 解析对应的权限以及用户信息
String uuid = (String) claims.get(CommonConst.LOGIN_USER_KEY);
String userKey = getTokenKey(uuid);
- LoginUser user = (LoginUser) RequestHolder.getSession(userKey);
+ AbstractLoginUser user = (AbstractLoginUser) RequestHolder.getSession(userKey);
return user;
}
return null;
@@ -85,7 +86,8 @@ public class JwtTemplate {
/**
* 设置用户身份信息
*/
- public void setLoginUser(LoginUser loginUser)
+ @Override
+ public void setLoginUser(AbstractLoginUser loginUser)
{
if (StringUtils.isNotNull(loginUser) && StringUtils.isNotEmpty(loginUser.getToken()))
{
@@ -96,6 +98,7 @@ public class JwtTemplate {
/**
* 删除用户身份信息
*/
+ @Override
public void delLoginUser(String token) {
if (StringUtils.isNotEmpty(token))
{
@@ -110,7 +113,8 @@ public class JwtTemplate {
* @param loginUser 用户信息
* @return 令牌
*/
- public String createToken(LoginUser loginUser)
+ @Override
+ public String createToken(AbstractLoginUser loginUser)
{
String token = IdUtils.fastUUID();
loginUser.setToken(token);
@@ -128,7 +132,8 @@ public class JwtTemplate {
* @param loginUser
* @return 令牌
*/
- public void verifyToken(LoginUser loginUser)
+ @Override
+ public void verifyToken(AbstractLoginUser loginUser)
{
long expireTime = loginUser.getExpireTime();
long currentTime = System.currentTimeMillis();
@@ -143,7 +148,8 @@ public class JwtTemplate {
*
* @param loginUser 登录信息
*/
- public void refreshToken(LoginUser loginUser) {
+ @Override
+ public void refreshToken(AbstractLoginUser loginUser) {
loginUser.setLoginTime(System.currentTimeMillis());
loginUser.setExpireTime(loginUser.getLoginTime() + expireTime * MILLIS_MINUTE);
// 根据uuid将loginUser缓存
@@ -153,14 +159,15 @@ public class JwtTemplate {
/**
* 设置用户代理信息
- *
* @param loginUser 登录信息
*/
- public void setUserAgent(LoginUser loginUser)
- {
+ @Override
+ public void setUserAgent(AbstractLoginUser loginUser) {
UserAgent userAgent = UserAgent.parseUserAgentString(RequestHolder.getRequest().getHeader("User-Agent"));
String ip = IpUtils.getIpAddr(RequestHolder.getRequest());
loginUser.setIpaddr(ip);
+ loginUser.setBrowser(userAgent.getBrowser().getName());
+ loginUser.setOs(userAgent.getOperatingSystem().getName());
}
/**
@@ -183,8 +190,7 @@ public class JwtTemplate {
* @param token 令牌
* @return 数据声明
*/
- private Claims parseToken(String token)
- {
+ private Claims parseToken(String token) {
return Jwts.parser()
.setSigningKey(secret)
.parseClaimsJws(token)
@@ -193,19 +199,16 @@ public class JwtTemplate {
/**
* 从令牌中获取用户名
- *
* @param token 令牌
* @return 用户名
*/
- public String getUsernameFromToken(String token)
- {
+ public String getUsernameFromToken(String token) {
Claims claims = parseToken(token);
return claims.getSubject();
}
/**
* 获取请求token
- *
* @param request
* @return token
*/
diff --git a/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/component/RedisJwtTemplate.java b/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/component/RedisJwtTemplate.java
index 24f24134f7c287c8fd6c5f5eaa69813f3131d508..d16abf97c0adcaef2f3e59a2d00188128dec2cd7 100644
--- a/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/component/RedisJwtTemplate.java
+++ b/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/component/RedisJwtTemplate.java
@@ -1,6 +1,7 @@
package cn.chenc.framework.core.component;
import cn.chenc.framework.core.consts.CommonConst;
+import cn.chenc.framework.core.model.AbstractLoginUser;
import cn.chenc.framework.core.model.LoginUser;
import cn.chenc.framework.core.model.request.RequestHolder;
import cn.chenc.framework.core.util.StringUtils;
@@ -42,7 +43,7 @@ public class RedisJwtTemplate extends JwtTemplate {
* @return 用户信息
*/
@Override
- public LoginUser getLoginUser(HttpServletRequest request) {
+ public AbstractLoginUser getLoginUser(HttpServletRequest request) {
// 获取请求携带的令牌
String token = getToken(request);
if (StringUtils.isNotEmpty(token)) {
@@ -60,7 +61,7 @@ public class RedisJwtTemplate extends JwtTemplate {
* 设置用户身份信息
*/
@Override
- public void setLoginUser(LoginUser loginUser) {
+ public void setLoginUser(AbstractLoginUser loginUser) {
if (StringUtils.isNotNull(loginUser) && StringUtils.isNotEmpty(loginUser.getToken())) {
refreshToken(loginUser);
}
@@ -84,7 +85,7 @@ public class RedisJwtTemplate extends JwtTemplate {
* @return 令牌
*/
@Override
- public String createToken(LoginUser loginUser) {
+ public String createToken(AbstractLoginUser loginUser) {
String token = IdUtils.fastUUID();
loginUser.setToken(token);
setUserAgent(loginUser);
@@ -101,7 +102,7 @@ public class RedisJwtTemplate extends JwtTemplate {
* @param loginUser 登录信息
*/
@Override
- public void setUserAgent(LoginUser loginUser) {
+ public void setUserAgent(AbstractLoginUser loginUser) {
UserAgent userAgent = UserAgent.parseUserAgentString(RequestHolder.getRequest().getHeader("User-Agent"));
String ip = IpUtils.getIpAddr(RequestHolder.getRequest());
loginUser.setIpaddr(ip);
@@ -116,7 +117,7 @@ public class RedisJwtTemplate extends JwtTemplate {
* @param loginUser 登录信息
*/
@Override
- public void refreshToken(LoginUser loginUser) {
+ public void refreshToken(AbstractLoginUser loginUser) {
loginUser.setLoginTime(System.currentTimeMillis());
loginUser.setExpireTime(loginUser.getLoginTime() + getExpireTime() * MILLIS_MINUTE);
// 根据uuid将loginUser缓存
@@ -131,7 +132,7 @@ public class RedisJwtTemplate extends JwtTemplate {
* @return 令牌
*/
@Override
- public void verifyToken(LoginUser loginUser) {
+ public void verifyToken(AbstractLoginUser loginUser) {
long expireTime = loginUser.getExpireTime();
long currentTime = System.currentTimeMillis();
if (expireTime - currentTime <= MILLIS_MINUTE_TEN)
diff --git a/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/config/SecretConfig.java b/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/config/SecretConfig.java
index afb801ce3bff27a10fb2f69df5da059e4ed2a63e..d9e77285fa2a8b9a2eb9b21cc0ef88cee39caa22 100644
--- a/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/config/SecretConfig.java
+++ b/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/config/SecretConfig.java
@@ -78,4 +78,20 @@ public class SecretConfig {
public void setAddressEnabled(boolean addressEnabled) {
SecretConfig.addressEnabled = addressEnabled;
}
+
+ /**
+ * 获取下载路径
+ */
+ public static String getDownloadPath()
+ {
+ return getProfile() + "/download/";
+ }
+
+ /**
+ * 获取上传路径
+ */
+ public static String getUploadPath()
+ {
+ return getProfile() + "/upload";
+ }
}
diff --git a/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/config/properties/DruidProperties.java b/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/config/properties/DruidProperties.java
new file mode 100644
index 0000000000000000000000000000000000000000..28ae511510f1b29008bad01f87b9dc1776858db5
--- /dev/null
+++ b/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/config/properties/DruidProperties.java
@@ -0,0 +1,214 @@
+package cn.chenc.framework.core.config.properties;
+
+import com.alibaba.druid.pool.DruidDataSource;
+
+/**
+ * @description: DruidProperties
+ * @author secret
+ * @date 2021/7/22 23:42
+ *
+ */
+public class DruidProperties {
+ private String connectionInitSqls;
+
+ private String driverClassName;
+
+ private String type;
+
+ private String url;
+
+ private String username;
+
+ private String password;
+
+ private int initialSize;
+
+ private int minIdle;
+
+ private int maxActive;
+
+ private int maxWait;
+
+ private int timeBetweenEvictionRunsMillis;
+
+ private int minEvictableIdleTimeMillis;
+
+ private int maxEvictableIdleTimeMillis;
+
+ private String validationQuery;
+
+ private boolean testWhileIdle;
+
+ private boolean testOnBorrow;
+
+ private boolean testOnReturn;
+
+ public DruidDataSource dataSource(DruidDataSource datasource) {
+ datasource.setDriverClassName(driverClassName);
+ datasource.setUrl(this.url);
+ datasource.setUsername(this.username);
+ datasource.setPassword(this.password);
+ /** 配置初始化大小、最小、最大 */
+ datasource.setInitialSize(initialSize);
+ datasource.setMaxActive(maxActive);
+ datasource.setMinIdle(minIdle);
+
+ /** 配置获取连接等待超时的时间 */
+ datasource.setMaxWait(maxWait);
+
+ /** 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 */
+ datasource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
+
+ /** 配置一个连接在池中最小、最大生存的时间,单位是毫秒 */
+ datasource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
+ datasource.setMaxEvictableIdleTimeMillis(maxEvictableIdleTimeMillis);
+
+ /**
+ * 用来检测连接是否有效的sql,要求是一个查询语句,常用select 'x'。如果validationQuery为null,testOnBorrow、testOnReturn、testWhileIdle都不会起作用。
+ */
+ datasource.setValidationQuery(validationQuery);
+ /** 建议配置为true,不影响性能,并且保证安全性。申请连接的时候检测,如果空闲时间大于timeBetweenEvictionRunsMillis,执行validationQuery检测连接是否有效。 */
+ datasource.setTestWhileIdle(testWhileIdle);
+ /** 申请连接时执行validationQuery检测连接是否有效,做了这个配置会降低性能。 */
+ datasource.setTestOnBorrow(testOnBorrow);
+ /** 归还连接时执行validationQuery检测连接是否有效,做了这个配置会降低性能。 */
+ datasource.setTestOnReturn(testOnReturn);
+ return datasource;
+ }
+
+ public String getConnectionInitSqls() {
+ return connectionInitSqls;
+ }
+
+ public void setConnectionInitSqls(String connectionInitSqls) {
+ this.connectionInitSqls = connectionInitSqls;
+ }
+
+ public String getDriverClassName() {
+ return driverClassName;
+ }
+
+ public void setDriverClassName(String driverClassName) {
+ this.driverClassName = driverClassName;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public String getUrl() {
+ return url;
+ }
+
+ public void setUrl(String url) {
+ this.url = url;
+ }
+
+ public String getUsername() {
+ return username;
+ }
+
+ public void setUsername(String username) {
+ this.username = username;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
+ public int getInitialSize() {
+ return initialSize;
+ }
+
+ public void setInitialSize(int initialSize) {
+ this.initialSize = initialSize;
+ }
+
+ public int getMinIdle() {
+ return minIdle;
+ }
+
+ public void setMinIdle(int minIdle) {
+ this.minIdle = minIdle;
+ }
+
+ public int getMaxActive() {
+ return maxActive;
+ }
+
+ public void setMaxActive(int maxActive) {
+ this.maxActive = maxActive;
+ }
+
+ public int getMaxWait() {
+ return maxWait;
+ }
+
+ public void setMaxWait(int maxWait) {
+ this.maxWait = maxWait;
+ }
+
+ public int getTimeBetweenEvictionRunsMillis() {
+ return timeBetweenEvictionRunsMillis;
+ }
+
+ public void setTimeBetweenEvictionRunsMillis(int timeBetweenEvictionRunsMillis) {
+ this.timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis;
+ }
+
+ public int getMinEvictableIdleTimeMillis() {
+ return minEvictableIdleTimeMillis;
+ }
+
+ public void setMinEvictableIdleTimeMillis(int minEvictableIdleTimeMillis) {
+ this.minEvictableIdleTimeMillis = minEvictableIdleTimeMillis;
+ }
+
+ public int getMaxEvictableIdleTimeMillis() {
+ return maxEvictableIdleTimeMillis;
+ }
+
+ public void setMaxEvictableIdleTimeMillis(int maxEvictableIdleTimeMillis) {
+ this.maxEvictableIdleTimeMillis = maxEvictableIdleTimeMillis;
+ }
+
+ public String getValidationQuery() {
+ return validationQuery;
+ }
+
+ public void setValidationQuery(String validationQuery) {
+ this.validationQuery = validationQuery;
+ }
+
+ public boolean isTestWhileIdle() {
+ return testWhileIdle;
+ }
+
+ public void setTestWhileIdle(boolean testWhileIdle) {
+ this.testWhileIdle = testWhileIdle;
+ }
+
+ public boolean isTestOnBorrow() {
+ return testOnBorrow;
+ }
+
+ public void setTestOnBorrow(boolean testOnBorrow) {
+ this.testOnBorrow = testOnBorrow;
+ }
+
+ public boolean isTestOnReturn() {
+ return testOnReturn;
+ }
+
+ public void setTestOnReturn(boolean testOnReturn) {
+ this.testOnReturn = testOnReturn;
+ }
+}
diff --git a/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/consts/CommonConst.java b/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/consts/CommonConst.java
index a88e1d67557eaa7504f9170399ba780cc0b99cba..283d5f844f16b4e830cb5f6082452f74cd7eea5f 100644
--- a/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/consts/CommonConst.java
+++ b/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/consts/CommonConst.java
@@ -65,6 +65,8 @@ public class CommonConst {
*/
public static final String LOGIN_TOKEN_KEY = "login_tokens:";
+ public static final String SYS_DICT_KEY = "sys_dict";
+
}
diff --git a/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/context/SecretBanner.java b/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/context/SecretBanner.java
index fb27bed12d82ccd617bfdfa4731db9f36421e527..08e5901a4560febca9d6b4babd478e16fcbe7e94 100644
--- a/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/context/SecretBanner.java
+++ b/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/context/SecretBanner.java
@@ -7,7 +7,7 @@ package cn.chenc.framework.core.context;
*
*/
public class SecretBanner {
- public static final String INIT_VERSION = "1.5.0";
+ public static final String INIT_VERSION = "1.6.0";
public static final String LOGO =
" ________ _______ ________ ________ _______ _________\n" +
diff --git a/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/model/AbstractDictData.java b/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/model/AbstractDictData.java
new file mode 100644
index 0000000000000000000000000000000000000000..9f6cc49660861e67b60e2cb4f87a2332c94d736d
--- /dev/null
+++ b/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/model/AbstractDictData.java
@@ -0,0 +1,23 @@
+package cn.chenc.framework.core.model;
+
+/**
+ * @description: 字典实体抽象
+ * @author secret
+ * @date 2021/7/26 21:53
+ *
+ */
+public interface AbstractDictData {
+
+ /**
+ * 获取字典标签
+ * @return
+ */
+ String getDictLabel();
+
+ /**
+ * 获取字典键值
+ * @return
+ */
+ String getDictValue();
+
+}
diff --git a/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/model/AbstractLoginUser.java b/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/model/AbstractLoginUser.java
new file mode 100644
index 0000000000000000000000000000000000000000..ea9bf8c8f2d63478a5a1ebe7e58aad5d171db76e
--- /dev/null
+++ b/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/model/AbstractLoginUser.java
@@ -0,0 +1,114 @@
+package cn.chenc.framework.core.model;
+
+import java.util.Set;
+
+/**
+ * @description: LoginUser抽象接口
+ * @author secret
+ * @date 2021/7/1 22:25
+ *
+ */
+public interface AbstractLoginUser {
+
+ /**
+ * 获取token
+ * @return
+ */
+ String getToken();
+
+ /**
+ * 设置token
+ * @param token
+ */
+ void setToken(String token);
+
+ /**
+ * 获取用户名
+ * @return
+ */
+ String getUsername();
+
+ /**
+ * 获取登录时间
+ * @return
+ */
+ Long getLoginTime();
+
+ /**
+ * 设置登录时间
+ * @param loginTime
+ */
+ void setLoginTime(Long loginTime);
+
+ /**
+ * 获取过期时间
+ * @return
+ */
+ Long getExpireTime();
+
+ /**
+ * 设置过期时间
+ * @param expireTime
+ */
+ void setExpireTime(Long expireTime);
+
+ /**
+ * 获取ip地址
+ * @return
+ */
+ String getIpaddr();
+
+ /**
+ * 设置ip地址
+ * @param ipaddr
+ */
+ void setIpaddr(String ipaddr);
+
+ /**
+ * 获取登录地址
+ * @return
+ */
+ String getLoginLocation();
+
+ /**
+ * 设置登录地址
+ * @param loginLocation
+ */
+ void setLoginLocation(String loginLocation);
+
+ /**
+ * 获取浏览器
+ * @return
+ */
+ String getBrowser();
+
+ /**
+ * 设置浏览器
+ * @param browser
+ */
+ void setBrowser(String browser);
+
+ /**
+ * 获取操作系统
+ * @return
+ */
+ String getOs();
+
+ /**
+ * 设置操作系统
+ * @param os
+ */
+ void setOs(String os);
+
+ Set getPermissions();
+
+ void setPermissions(Set permissions);
+
+ Set getRoles();
+
+ void setRoles(Set roles);
+
+ LoginUserDetails getUser();
+
+ void setUser(LoginUserDetails user);
+}
diff --git a/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/model/LoginUser.java b/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/model/LoginUser.java
index 3b2c27f4c0e5af8656376e29ea34a71e3073bc09..16639257396d93565560b9f70c9c1071a682122f 100644
--- a/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/model/LoginUser.java
+++ b/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/model/LoginUser.java
@@ -11,7 +11,7 @@ import java.util.Set;
* @date 2021/4/8 10:01
*
*/
-public class LoginUser implements Serializable {
+public class LoginUser implements AbstractLoginUser,Serializable {
private static final long serialVersionUID = 1L;
@@ -75,11 +75,13 @@ public class LoginUser implements Serializable {
}
+ @Override
public String getToken()
{
return token;
}
+ @Override
public void setToken(String token)
{
this.token = token;
@@ -95,6 +97,7 @@ public class LoginUser implements Serializable {
this.userid = userid;
}
+ @Override
public String getUsername(){
return user.getUsername();
}
@@ -103,83 +106,101 @@ public class LoginUser implements Serializable {
return user.getPassword();
}
+ @Override
public Long getLoginTime()
{
return loginTime;
}
+ @Override
public void setLoginTime(Long loginTime)
{
this.loginTime = loginTime;
}
+ @Override
public Long getExpireTime()
{
return expireTime;
}
+ @Override
public void setExpireTime(Long expireTime)
{
this.expireTime = expireTime;
}
+ @Override
public String getIpaddr()
{
return ipaddr;
}
+ @Override
public void setIpaddr(String ipaddr)
{
this.ipaddr = ipaddr;
}
+ @Override
public String getLoginLocation() {
return loginLocation;
}
+ @Override
public void setLoginLocation(String loginLocation) {
this.loginLocation = loginLocation;
}
+ @Override
public String getBrowser() {
return browser;
}
+ @Override
public void setBrowser(String browser) {
this.browser = browser;
}
+ @Override
public String getOs() {
return os;
}
+ @Override
public void setOs(String os) {
this.os = os;
}
+ @Override
public Set getPermissions()
{
return permissions;
}
+ @Override
public void setPermissions(Set permissions)
{
this.permissions = permissions;
}
+ @Override
public Set getRoles() {
return roles;
}
+ @Override
public void setRoles(Set roles) {
this.roles = roles;
}
- public Object getUser()
+ @Override
+ public LoginUserDetails getUser()
{
return user;
}
+ @Override
public void setUser(LoginUserDetails user)
{
this.user = user;
diff --git a/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/model/LoginUserDetails.java b/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/model/LoginUserDetails.java
index fd92fa6a9570ab23638bb0fed5bdfc925d931c6e..cd3970be338313e2dd4e0188876b454d35ac524a 100644
--- a/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/model/LoginUserDetails.java
+++ b/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/model/LoginUserDetails.java
@@ -1,7 +1,7 @@
package cn.chenc.framework.core.model;
/**
- * @description: 通用登录用户接口
+ * @description: 通用登录用户信息接口
* @author secret
* @date 2021/4/19 10:45
*
diff --git a/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/model/response/AjaxResult.java b/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/model/response/AjaxResult.java
index ec54e7b0a991b038efe3fb7865b51cbc4e7d47bb..fcfe853c50bd720ea2900a6cf5f2b74480b85317 100644
--- a/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/model/response/AjaxResult.java
+++ b/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/model/response/AjaxResult.java
@@ -146,4 +146,10 @@ public class AjaxResult extends HashMap
{
return new AjaxResult(code, msg, null);
}
+
+ @Override
+ public AjaxResult put(String key, Object value){
+ super.put(key,value);
+ return this;
+ }
}
diff --git a/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/model/response/CustomCode.java b/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/model/response/CustomCode.java
index bc5145761d3c95ffef3744457b7bc5613702bdc9..de10e39ae2f8cd95ea321e0df0b165dd0bbf3294 100644
--- a/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/model/response/CustomCode.java
+++ b/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/model/response/CustomCode.java
@@ -50,4 +50,9 @@ public class CustomCode implements ResultCode {
public static ResultCode error(String message){
return new CustomCode(false,HttpStatus.ERROR,message);
}
+
+ public static ResultCode vo(int code,String message){
+ return new CustomCode(false,code,message);
+ }
+
}
diff --git a/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/mutidatasource/DataSourceName.java b/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/mutidatasource/DataSourceName.java
new file mode 100644
index 0000000000000000000000000000000000000000..e6fb4c5429b0970b584e0d5ea906cdb0d94f186a
--- /dev/null
+++ b/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/mutidatasource/DataSourceName.java
@@ -0,0 +1,11 @@
+package cn.chenc.framework.core.mutidatasource;
+
+/**
+ * @description: 数据源名称
+ * @author secret
+ * @date 2021/7/21 23:15
+ *
+ */
+public interface DataSourceName {
+ public final static String MASTER = "masterDataSource";
+}
diff --git a/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/mutidatasource/DynamicDataSource.java b/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/mutidatasource/DynamicDataSource.java
new file mode 100644
index 0000000000000000000000000000000000000000..62e6c7361e48c1e75173d47a1c6fb353bc154641
--- /dev/null
+++ b/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/mutidatasource/DynamicDataSource.java
@@ -0,0 +1,45 @@
+package cn.chenc.framework.core.mutidatasource;
+
+import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @description: 多数据源配置
+ * @author secret
+ * @date 2021/7/21 22:28
+ *
+ */
+public class DynamicDataSource extends AbstractRoutingDataSource {
+ private static final ThreadLocal contextHolder = new ThreadLocal();
+ private static List dataSourceList = new ArrayList();
+
+ public DynamicDataSource() {
+ }
+
+ public static void setDataSourceType(String dataSourceType) {
+ contextHolder.set(dataSourceType);
+ }
+
+ public static String getDataSourceType() {
+ return contextHolder.get() == null ? DataSourceName.MASTER : (String)contextHolder.get();
+ }
+
+ public static void clearDataSourceType() {
+ contextHolder.remove();
+ }
+
+ public static void saveDataSourceTypeName(String name) {
+ dataSourceList.add(name);
+ }
+
+ public static boolean checkDataSourceType(String name) {
+ return dataSourceList.contains(name);
+ }
+
+ @Override
+ protected Object determineCurrentLookupKey() {
+ return getDataSourceType();
+ }
+}
diff --git a/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/util/AssertUtil.java b/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/util/AssertUtil.java
new file mode 100644
index 0000000000000000000000000000000000000000..e3cf848dcf9844fb4d016bbb871fed04346c2fbc
--- /dev/null
+++ b/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/util/AssertUtil.java
@@ -0,0 +1,48 @@
+package cn.chenc.framework.core.util;
+
+import cn.hutool.core.collection.CollectionUtil;
+import cn.hutool.core.util.ArrayUtil;
+import cn.hutool.core.util.StrUtil;
+
+import java.util.Collection;
+import java.util.Map;
+
+/**
+ * @description: TODO
+ * @author secret
+ * @date 2021/6/5 23:17
+ *
+ */
+public class AssertUtil {
+
+ public static void isTrue(boolean expression, String message) {
+ if (!expression) {
+ throw new IllegalArgumentException(StrUtil.format(message, new Object[0]));
+ }
+ }
+
+ public static void isFalse(boolean expression, String message) {
+ isTrue(!expression, message);
+ }
+
+ public static void isNull(Object object, String message) {
+ isTrue(object == null, message);
+ }
+
+ public static void notNull(Object object, String message) {
+ isTrue(object != null, message);
+ }
+
+ public static void notEmpty(Collection> collection, String message) {
+ isTrue(CollectionUtil.isNotEmpty(collection), message);
+ }
+
+ public static void notEmpty(Map, ?> map, String message) {
+ isTrue(CollectionUtil.isNotEmpty(map), message);
+ }
+
+ public static void notEmpty(Object[] array, String message) {
+ isTrue(ArrayUtil.isNotEmpty(array), message);
+ }
+
+}
diff --git a/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/util/DateUtils.java b/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/util/DateUtils.java
index 64c1cba1dae2b1972510acecfcf4fe7069b0c72c..9f713678dd3d340a8a4dae124e83a22c32ef9d90 100644
--- a/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/util/DateUtils.java
+++ b/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/util/DateUtils.java
@@ -10,13 +10,19 @@ import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.*;
+import java.util.regex.Pattern;
-public class DateUtils {
+public class DateUtils extends org.apache.commons.lang3.time.DateUtils{
public static final String YYYYMMDDHHMMSS = "yyyy-MM-dd HH:mm:ss";
public static final String YYYYMMDD = "yyyy-MM-dd";
public static final String YYYYMMDDHHMM = "yyyy-MM-dd HH:mm";
public static final String YYYYMM = "yyyy-MM";
+ private static String[] parsePatterns = {
+ "yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy-MM",
+ "yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm", "yyyy/MM",
+ "yyyy.MM.dd", "yyyy.MM.dd HH:mm:ss", "yyyy.MM.dd HH:mm", "yyyy.MM"};
+
public DateUtils() {
}
@@ -52,6 +58,21 @@ public class DateUtils {
}
}
+ /**
+ * 日期型字符串转化为日期 格式
+ */
+ public static Date parseDate(Object str) {
+ if (str == null) {
+ return null;
+ }
+ try {
+ return parseDate(str.toString(), parsePatterns);
+ }
+ catch (ParseException e) {
+ return null;
+ }
+ }
+
/**
* @description: 将日期字符串按自定义格式化转化为Date对象
* @param date 日期字符串
@@ -383,6 +404,12 @@ public class DateUtils {
return localDateTime;
}
+ public static LocalDateTime parseLocalDateTime(String dateStr){
+ String patten = getDateFormat(dateStr);
+ Date date = parse(dateStr,patten);
+ return dateToLocalDateTime(date);
+ }
+
/**
* 日期路径 即年/月/日 如2018/08/08
*/
@@ -420,4 +447,66 @@ public class DateUtils {
// long sec = diff % nd % nh % nm / ns;
return day + "天" + hour + "小时" + min + "分钟";
}
+
+ /**
+ * 常规自动日期格式识别
+ * @param str 时间字符串
+ * @return String
+ * @author secret
+ * 如:1998-09-27 -> yyyy-MM-dd
+ */
+ public static String getDateFormat(String str){
+ boolean year = false;
+ Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$");
+ if(pattern.matcher(str.substring(0, 4)).matches()) {
+ year = true;
+ }
+ StringBuilder sb = new StringBuilder();
+ int index = 0;
+ if(!year) {
+ if(str.contains("月") || str.contains("-") || str.contains("/")) {
+ if(Character.isDigit(str.charAt(0))) {
+ index = 1;
+ }
+ }else {
+ index = 3;
+ }
+ }
+ for (int i = 0; i < str.length(); i++) {
+ char chr = str.charAt(i);
+ if(Character.isDigit(chr)) {
+ if(index==0) {
+ sb.append("y");
+ }
+ if(index==1) {
+ sb.append("M");
+ }
+ if(index==2) {
+ sb.append("d");
+ }
+ if(index==3) {
+ sb.append("H");
+ }
+ if(index==4) {
+ sb.append("m");
+ }
+ if(index==5) {
+ sb.append("s");
+ }
+ if(index==6) {
+ sb.append("S");
+ }
+ }else {
+ if(i>0) {
+ char lastChar = str.charAt(i-1);
+ if(Character.isDigit(lastChar)) {
+ index++;
+ }
+ }
+ sb.append(chr);
+ }
+ }
+ return sb.toString();
+ }
+
}
diff --git a/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/util/DictUtils.java b/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/util/DictUtils.java
new file mode 100644
index 0000000000000000000000000000000000000000..5cea18c951d3c8968527e44d6ade94f8929328e8
--- /dev/null
+++ b/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/util/DictUtils.java
@@ -0,0 +1,175 @@
+package cn.chenc.framework.core.util;
+
+import cn.chenc.framework.core.component.SpringContextHolder;
+import cn.chenc.framework.core.consts.CommonConst;
+import cn.chenc.framework.core.model.AbstractDictData;
+import org.springframework.data.redis.core.RedisTemplate;
+
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * @description: 字典工具类
+ * @author secret
+ * @date 2021/7/26 21:48
+ *
+ */
+public class DictUtils {
+
+ /**
+ * 分隔符
+ */
+ public static final String SEPARATOR = ",";
+
+ /**
+ * 设置字典缓存
+ *
+ * @param key 参数键
+ * @param dictDatas 字典数据列表
+ */
+ public static void setDictCache(String key, List dictDatas) {
+ SpringContextHolder.getBean(RedisTemplate.class).opsForValue().set(getCacheKey(key), dictDatas);
+ }
+
+ /**
+ * 获取字典缓存
+ *
+ * @param key 参数键
+ * @return dictDatas 字典数据列表
+ */
+ public static List getDictCache(String key)
+ {
+ Object cacheObj = SpringContextHolder.getBean(RedisTemplate.class).opsForValue().get(getCacheKey(key));
+ if (StringUtils.isNotNull(cacheObj))
+ {
+ List dictDatas = StringUtils.cast(cacheObj);
+ return dictDatas;
+ }
+ return null;
+ }
+
+ /**
+ * 根据字典类型和字典值获取字典标签
+ *
+ * @param dictType 字典类型
+ * @param dictValue 字典值
+ * @return 字典标签
+ */
+ public static String getDictLabel(String dictType, String dictValue)
+ {
+ return getDictLabel(dictType, dictValue, SEPARATOR);
+ }
+
+ /**
+ * 根据字典类型和字典标签获取字典值
+ *
+ * @param dictType 字典类型
+ * @param dictLabel 字典标签
+ * @return 字典值
+ */
+ public static String getDictValue(String dictType, String dictLabel)
+ {
+ return getDictValue(dictType, dictLabel, SEPARATOR);
+ }
+
+ /**
+ * 根据字典类型和字典值获取字典标签
+ *
+ * @param dictType 字典类型
+ * @param dictValue 字典值
+ * @param separator 分隔符
+ * @return 字典标签
+ */
+ public static String getDictLabel(String dictType, String dictValue, String separator)
+ {
+ StringBuilder propertyString = new StringBuilder();
+ List datas = getDictCache(dictType);
+
+ if (StringUtils.containsAny(separator, dictValue) && StringUtils.isNotEmpty(datas))
+ {
+ for (AbstractDictData dict : datas)
+ {
+ for (String value : dictValue.split(separator))
+ {
+ if (value.equals(dict.getDictValue()))
+ {
+ propertyString.append(dict.getDictLabel() + separator);
+ break;
+ }
+ }
+ }
+ }
+ else
+ {
+ for (AbstractDictData dict : datas)
+ {
+ if (dictValue.equals(dict.getDictValue()))
+ {
+ return dict.getDictLabel();
+ }
+ }
+ }
+ return StringUtils.stripEnd(propertyString.toString(), separator);
+ }
+
+ /**
+ * 根据字典类型和字典标签获取字典值
+ *
+ * @param dictType 字典类型
+ * @param dictLabel 字典标签
+ * @param separator 分隔符
+ * @return 字典值
+ */
+ public static String getDictValue(String dictType, String dictLabel, String separator)
+ {
+ StringBuilder propertyString = new StringBuilder();
+ List datas = getDictCache(dictType);
+
+ if (StringUtils.containsAny(separator, dictLabel) && StringUtils.isNotEmpty(datas)){
+ for (AbstractDictData dict : datas) {
+ for (String label : dictLabel.split(separator)) {
+ if (label.equals(dict.getDictLabel())) {
+ propertyString.append(dict.getDictValue() + separator);
+ break;
+ }
+ }
+ }
+ }
+ else {
+ for (AbstractDictData dict : datas) {
+ if (dictLabel.equals(dict.getDictLabel())) {
+ return dict.getDictValue();
+ }
+ }
+ }
+ return StringUtils.stripEnd(propertyString.toString(), separator);
+ }
+
+ /**
+ * 删除指定字典缓存
+ *
+ * @param key 字典键
+ */
+ public static void removeDictCache(String key) {
+ SpringContextHolder.getBean(RedisTemplate.class).delete(getCacheKey(key));
+ }
+
+ /**
+ * 清空字典缓存
+ */
+ public static void clearDictCache() {
+ Collection keys = SpringContextHolder.getBean(RedisTemplate.class).keys(CommonConst.SYS_DICT_KEY + "*");
+ SpringContextHolder.getBean(RedisTemplate.class).delete(keys);
+ }
+
+ /**
+ * 设置cache key
+ *
+ * @param configKey 参数键
+ * @return 缓存键key
+ */
+ public static String getCacheKey(String configKey) {
+ return CommonConst.SYS_DICT_KEY + configKey;
+ }
+
+}
diff --git a/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/util/ValidatorUtil.java b/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/util/ValidatorUtil.java
new file mode 100644
index 0000000000000000000000000000000000000000..59fc5a8501373e730c4b49955b41cadba5199a38
--- /dev/null
+++ b/secret-boot-framework-core/src/main/java/cn/chenc/framework/core/util/ValidatorUtil.java
@@ -0,0 +1,92 @@
+package cn.chenc.framework.core.util;
+
+
+import javax.validation.ConstraintViolation;
+import javax.validation.Validation;
+import javax.validation.Validator;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * @description: TODO
+ * @author secret
+ * @date 2021/3/22 11:42
+ *
+ */
+public class ValidatorUtil {
+
+ private static Validator validator;
+
+ static {
+ validator = Validation.buildDefaultValidatorFactory().getValidator();
+ }
+
+ /**
+ * 校验对象
+ *
+ * @param object 待校验对象
+ * @param groups 待校验的组
+ * @return 返回消息list
+ */
+ public static List validateEntityAll(Object object, Class>... groups) {
+ List list=new ArrayList<>();
+ Set> constraintViolations = validator.validate(object, groups);
+ if (!constraintViolations.isEmpty()) {
+ constraintViolations.forEach(o -> {
+ list.add(o.getMessage());
+ });
+ }
+ return list;
+ }
+
+ /**
+ * 校验对象
+ *
+ * @param object 待校验对象
+ */
+ public static List validateEntityAll(Object object) {
+ List list=new ArrayList<>();
+ Set> constraintViolations = validator.validate(object);
+ if (!constraintViolations.isEmpty()) {
+ constraintViolations.forEach(o -> {
+ list.add(o.getMessage());
+ });
+ }
+ return list;
+ }
+
+ /**
+ * 校验对象
+ *
+ * @param object 待校验对象
+ * @param groups 待校验的组
+ * @return 返回单个校验消息
+ */
+ public static String validateEntityFirst(Object object, Class>... groups) {
+ Set> constraintViolations = validator.validate(object, groups);
+ if (!constraintViolations.isEmpty()) {
+ for(ConstraintViolation
+
+
+
+
com.gitee.secretopen
- secret-boot-framework-excel
+ secret-boot-framework-captcha
com.gitee.secretopen
- secret-boot-framework-captcha
+ secret-boot-framework-mail
+
+
+ com.gitee.secretopen
+ secret-boot-framework-poi
+
+
+ com.gitee.secretopen
+ secret-boot-framework-dozer
diff --git a/secret-boot-framework-demo/common-demo/src/main/java/cn/chenc/framework/demo/CommonDemoApplication.java b/secret-boot-framework-demo/common-demo/src/main/java/cn/chenc/framework/demo/CommonDemoApplication.java
index eb1e2d4cf089dcab3ffa004df9e940d16eff7ba1..9e2810bb372952affa1b55603f10273a36b4f5d6 100644
--- a/secret-boot-framework-demo/common-demo/src/main/java/cn/chenc/framework/demo/CommonDemoApplication.java
+++ b/secret-boot-framework-demo/common-demo/src/main/java/cn/chenc/framework/demo/CommonDemoApplication.java
@@ -2,6 +2,8 @@ package cn.chenc.framework.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
+import org.springframework.context.annotation.ComponentScan;
import org.springframework.transaction.annotation.EnableTransactionManagement;
/**
@@ -10,8 +12,8 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
* @date 2020/11/28 13:54
*
*/
-@SpringBootApplication
@EnableTransactionManagement
+@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class })
public class CommonDemoApplication {
public static void main(String[] args){
diff --git a/secret-boot-framework-demo/common-demo/src/main/java/cn/chenc/framework/demo/aspect/MyRedisCacheAspect.java b/secret-boot-framework-demo/common-demo/src/main/java/cn/chenc/framework/demo/aspect/MyRedisCacheAspect.java
index c7615b34b74404f015c4a065874c4d5a115fa908..de7c30662abe3b1941fc13099d3bc3c4c2d8fa20 100644
--- a/secret-boot-framework-demo/common-demo/src/main/java/cn/chenc/framework/demo/aspect/MyRedisCacheAspect.java
+++ b/secret-boot-framework-demo/common-demo/src/main/java/cn/chenc/framework/demo/aspect/MyRedisCacheAspect.java
@@ -1,7 +1,7 @@
package cn.chenc.framework.demo.aspect;
import cn.chenc.framework.cache.annotation.RedisCache;
-import cn.chenc.framework.cache.util.RedisUtils;
+import cn.chenc.framework.cache.service.RedisService;
import cn.chenc.framework.core.util.AspectUtil;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
@@ -24,7 +24,7 @@ public class MyRedisCacheAspect {
private static final String BIZ_CACHE_PREFIX = "biz_cache_";
@Autowired
- private RedisUtils redisUtils;
+ private RedisService redisService;
@Pointcut(value = "@annotation(cn.chenc.framework.cache.annotation.RedisCache)")
public void pointcut() {
@@ -43,22 +43,22 @@ public class MyRedisCacheAspect {
if (flush) {
String classPrefix = AspectUtil.INSTANCE.getKey(point, BIZ_CACHE_PREFIX);
log.info("清空缓存 - {}*", classPrefix);
- redisUtils.delBatch(classPrefix);
+ redisService.delBatch(classPrefix);
return point.proceed();
}
String key = AspectUtil.INSTANCE.getKey(point, cache.key(), BIZ_CACHE_PREFIX);
- boolean hasKey = redisUtils.hasKey(key);
+ boolean hasKey = redisService.hasKey(key);
if (hasKey) {
try {
log.info("{}从缓存中获取数据", key);
- return redisUtils.get(key);
+ return redisService.get(key);
} catch (Exception e) {
log.error("从缓存中获取数据失败!", e);
}
}
//先执行业务
Object result = point.proceed();
- redisUtils.set(key, result, cache.expire(), cache.unit());
+ redisService.set(key, result, cache.expire(), cache.unit());
log.info("{}从数据库中获取数据", key);
return result;
}
diff --git a/secret-boot-framework-demo/common-demo/src/main/java/cn/chenc/framework/demo/config/DruidConfig.java b/secret-boot-framework-demo/common-demo/src/main/java/cn/chenc/framework/demo/config/DruidConfig.java
new file mode 100644
index 0000000000000000000000000000000000000000..98379777ff4d1cc16344291c7ea0dc89747ad326
--- /dev/null
+++ b/secret-boot-framework-demo/common-demo/src/main/java/cn/chenc/framework/demo/config/DruidConfig.java
@@ -0,0 +1,80 @@
+package cn.chenc.framework.demo.config;
+
+import cn.chenc.framework.core.config.properties.DruidProperties;
+import cn.chenc.framework.core.mutidatasource.DynamicDataSource;
+import com.alibaba.druid.pool.DruidDataSource;
+import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Primary;
+import org.springframework.jdbc.core.JdbcTemplate;
+
+import javax.sql.DataSource;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @description: druid 多数据源配置
+ * @author secret
+ * @date 2021/7/30 23:40
+ *
+ */
+@Configuration
+public class DruidConfig {
+
+ @Bean(name = "masterDruidProperties")
+ @ConfigurationProperties("spring.datasource.druid.master")
+ public DruidProperties masterDruidProperties(){
+ return new DruidProperties();
+ }
+
+ @Bean(name = "slaveDruidProperties")
+ @ConfigurationProperties("spring.datasource.druid.slave")
+ public DruidProperties slaveDruidProperties(){
+ return new DruidProperties();
+ }
+
+ @Bean
+ public DataSource masterDataSource(DruidProperties masterDruidProperties) {
+ DruidDataSource dataSource = DruidDataSourceBuilder.create().build();
+ return masterDruidProperties.dataSource(dataSource);
+ }
+
+ @Bean
+ public DataSource slaveDataSource(DruidProperties slaveDruidProperties) {
+ DruidDataSource dataSource = DruidDataSourceBuilder.create().build();
+ return slaveDruidProperties.dataSource(dataSource);
+ }
+
+ @Bean(name = "dynamicDataSource")
+ @Primary
+ public DynamicDataSource dataSource(Map dataSources) {
+ DynamicDataSource dynamicDataSource = new DynamicDataSource();
+ Map targetDataSources = new HashMap<>();
+ targetDataSources.putAll(dataSources);
+ dynamicDataSource.setTargetDataSources(targetDataSources);
+ dynamicDataSource.setDefaultTargetDataSource(dataSources.get("masterDataSource"));
+ dynamicDataSource.afterPropertiesSet();
+ // 遍历存入list中
+ for (Map.Entry entry : dataSources.entrySet()) {
+ DynamicDataSource.saveDataSourceTypeName(entry.getKey());
+ }
+ return dynamicDataSource;
+ }
+
+ /**
+ * 向spring容器暴露组合数据源JdbcTemplate
+ * @param dataSource
+ * @return
+ * @author secret
+ */
+ @Bean(name = "multipleDataJdbcTemplate")
+ public JdbcTemplate primaryJdbcTemplate(@Qualifier("dynamicDataSource") DataSource dataSource) {
+ return new JdbcTemplate(dataSource);
+ }
+
+
+
+}
diff --git a/secret-boot-framework-demo/common-demo/src/main/java/cn/chenc/framework/demo/config/ExcelConfig.java b/secret-boot-framework-demo/common-demo/src/main/java/cn/chenc/framework/demo/config/ExcelConfig.java
index b0ba54237be3304f9b411ea177bf2417aa0c566e..066db05a66457fe3ab8f387f02afd47dc869bbdd 100644
--- a/secret-boot-framework-demo/common-demo/src/main/java/cn/chenc/framework/demo/config/ExcelConfig.java
+++ b/secret-boot-framework-demo/common-demo/src/main/java/cn/chenc/framework/demo/config/ExcelConfig.java
@@ -1,19 +1,7 @@
package cn.chenc.framework.demo.config;
-import cn.chenc.framework.demo.converters.MyLocalDateTimeConverter;
-import cn.chenc.framework.excel.config.CustomerDefaultConverterLoader;
-import cn.chenc.framework.excel.converters.LocalDateTimeConverter;
-import cn.chenc.framework.excel.converters.NumberToLocalDateTimeConverter;
-import com.alibaba.excel.converters.Converter;
-import com.alibaba.excel.converters.ConverterKeyBuild;
-import com.alibaba.excel.converters.DefaultConverterLoader;
-import org.springframework.boot.autoconfigure.AutoConfigureAfter;
-import org.springframework.context.annotation.Bean;
+//import cn.chenc.framework.excel.config.CustomerDefaultConverterLoader;
import org.springframework.context.annotation.Configuration;
-import org.springframework.context.annotation.Primary;
-
-import java.lang.reflect.Field;
-import java.util.Map;
/**
* @description: TODO
@@ -22,45 +10,45 @@ import java.util.Map;
*
*/
@Configuration
-@AutoConfigureAfter(CustomerDefaultConverterLoader.class)
+//@AutoConfigureAfter(CustomerDefaultConverterLoader.class)
public class ExcelConfig {
- //存放写时用到的converter
- private static final String ALL_CONVERTER = "allConverter";
- //存放所有的converter
- private static final String WRITE_CONVERTER = "defaultWriteConverter";
-
- @Bean
- @Primary
- public DefaultConverterLoader addConverter() throws IllegalAccessException {
- DefaultConverterLoader converters = new DefaultConverterLoader();
- Field[] fields = converters.getClass().getDeclaredFields();
- for (Field field : fields) {
- field.setAccessible(true);
- if (field.getType() == Map.class) {
- Map oldMap = (Map) field.get(converters);
- if (oldMap != null && !oldMap.isEmpty()) {
- if (WRITE_CONVERTER.equalsIgnoreCase(field.getName())) {
- putWriteConverter(oldMap, new LocalDateTimeConverter());
- putAllConverter(oldMap,new NumberToLocalDateTimeConverter());
- putWriteConverter(oldMap, new MyLocalDateTimeConverter());
- } else if (ALL_CONVERTER.equalsIgnoreCase(field.getName())) {
- putAllConverter(oldMap, new LocalDateTimeConverter());
- putAllConverter(oldMap,new NumberToLocalDateTimeConverter());
- putWriteConverter(oldMap, new MyLocalDateTimeConverter());
- }
- field.set(converters, oldMap);
- }
- }
- }
- return converters;
- }
-
- private void putWriteConverter(Map map, Converter converter) {
- map.put(ConverterKeyBuild.buildKey(converter.supportJavaTypeKey()), converter);
- }
-
- private void putAllConverter(Map map, Converter converter) {
- map.put(ConverterKeyBuild.buildKey(converter.supportJavaTypeKey(), converter.supportExcelTypeKey()), converter);
- }
+// //存放写时用到的converter
+// private static final String ALL_CONVERTER = "allConverter";
+// //存放所有的converter
+// private static final String WRITE_CONVERTER = "defaultWriteConverter";
+//
+// @Bean
+// @Primary
+// public DefaultConverterLoader addConverter() throws IllegalAccessException {
+// DefaultConverterLoader converters = new DefaultConverterLoader();
+// Field[] fields = converters.getClass().getDeclaredFields();
+// for (Field field : fields) {
+// field.setAccessible(true);
+// if (field.getType() == Map.class) {
+// Map oldMap = (Map) field.get(converters);
+// if (oldMap != null && !oldMap.isEmpty()) {
+// if (WRITE_CONVERTER.equalsIgnoreCase(field.getName())) {
+// putWriteConverter(oldMap, new LocalDateTimeConverter());
+// putAllConverter(oldMap,new NumberToLocalDateTimeConverter());
+// putWriteConverter(oldMap, new MyLocalDateTimeConverter());
+// } else if (ALL_CONVERTER.equalsIgnoreCase(field.getName())) {
+// putAllConverter(oldMap, new LocalDateTimeConverter());
+// putAllConverter(oldMap,new NumberToLocalDateTimeConverter());
+// putWriteConverter(oldMap, new MyLocalDateTimeConverter());
+// }
+// field.set(converters, oldMap);
+// }
+// }
+// }
+// return converters;
+// }
+//
+// private void putWriteConverter(Map map, Converter converter) {
+// map.put(ConverterKeyBuild.buildKey(converter.supportJavaTypeKey()), converter);
+// }
+//
+// private void putAllConverter(Map map, Converter converter) {
+// map.put(ConverterKeyBuild.buildKey(converter.supportJavaTypeKey(), converter.supportExcelTypeKey()), converter);
+// }
}
diff --git a/secret-boot-framework-demo/common-demo/src/main/java/cn/chenc/framework/demo/config/MyBatisPlusConfig.java b/secret-boot-framework-demo/common-demo/src/main/java/cn/chenc/framework/demo/config/MyBatisPlusConfig.java
index 8903ddebacbc0fe00677cc54c0174eb2cf023bb7..1504f5c13405feea7713047b7a11f4fb7de47c49 100644
--- a/secret-boot-framework-demo/common-demo/src/main/java/cn/chenc/framework/demo/config/MyBatisPlusConfig.java
+++ b/secret-boot-framework-demo/common-demo/src/main/java/cn/chenc/framework/demo/config/MyBatisPlusConfig.java
@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
/**
* @description: mybatisplus配置
@@ -12,7 +13,7 @@ import org.springframework.context.annotation.Bean;
* @date 2020/3/21 21:56
*
*/
-//@Configuration
+@Configuration
public class MyBatisPlusConfig {
/**
@@ -26,9 +27,18 @@ public class MyBatisPlusConfig {
return interceptor;
}
- @Bean
- public ConfigurationCustomizer configurationCustomizer() {
- return configuration -> configuration.setUseDeprecatedExecutor(false);
- }
+
+// @Bean
+// public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception {
+//
+// VFS.addImplClass(SpringBootVFS.class);
+// MybatisConfiguration configuration = new MybatisConfiguration();
+// final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
+// sessionFactory.setDataSource(dataSource);
+// sessionFactory.setConfiguration(configuration);
+// return sessionFactory.getObject();
+//
+// }
+
}
diff --git a/secret-boot-framework-demo/common-demo/src/main/java/cn/chenc/framework/demo/controller/RoleController.java b/secret-boot-framework-demo/common-demo/src/main/java/cn/chenc/framework/demo/controller/RoleController.java
new file mode 100644
index 0000000000000000000000000000000000000000..524b13134f73531e89c05fc00c7b0c2c2a68348d
--- /dev/null
+++ b/secret-boot-framework-demo/common-demo/src/main/java/cn/chenc/framework/demo/controller/RoleController.java
@@ -0,0 +1,30 @@
+package cn.chenc.framework.demo.controller;
+
+import cn.chenc.framework.core.model.response.AjaxResult;
+import cn.chenc.framework.demo.entity.Role;
+import cn.chenc.framework.demo.service.RoleService;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * @description: TODO
+ * @author secret
+ * @date 2021/7/31 0:05
+ *
+ */
+@RestController
+@RequestMapping("/role")
+public class RoleController {
+
+ @Autowired
+ private RoleService roleService;
+
+ @GetMapping("/list")
+ public AjaxResult queryRolePageList(Role role){
+ IPage iPage=roleService.queryRolePageList(role);
+ return AjaxResult.success(iPage);
+ }
+}
diff --git a/secret-boot-framework-demo/common-demo/src/main/java/cn/chenc/framework/demo/controller/UserController.java b/secret-boot-framework-demo/common-demo/src/main/java/cn/chenc/framework/demo/controller/UserController.java
index 1a1f97200a5326289fe55395efe3123e5d3bbf2e..e6985eb71adb014e9c1a7d8eacdd8795b58181df 100644
--- a/secret-boot-framework-demo/common-demo/src/main/java/cn/chenc/framework/demo/controller/UserController.java
+++ b/secret-boot-framework-demo/common-demo/src/main/java/cn/chenc/framework/demo/controller/UserController.java
@@ -1,16 +1,31 @@
package cn.chenc.framework.demo.controller;
import cn.chenc.framework.core.annotation.PreAuthorize;
+import cn.chenc.framework.core.component.AbstractJwtTemplate;
+import cn.chenc.framework.core.model.AbstractDictData;
import cn.chenc.framework.core.model.response.AjaxResult;
import cn.chenc.framework.core.model.response.ResponseVO;
import cn.chenc.framework.core.model.response.ResultUtil;
+import cn.chenc.framework.core.util.DictUtils;
+import cn.chenc.framework.core.util.file.FileUtils;
+import cn.chenc.framework.demo.entity.Dict;
import cn.chenc.framework.demo.entity.User;
+import cn.chenc.framework.demo.entity.UserCopy;
import cn.chenc.framework.demo.service.UserService;
+import cn.chenc.framework.dozer.component.DozerTemplate;
+import cn.chenc.framework.mail.core.MailTemplate;
+import cn.chenc.framework.poi.util.ExcelUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.mail.MailProperties;
import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.web.bind.annotation.*;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
/**
* @description: TODO
* @author secret
@@ -25,6 +40,11 @@ public class UserController {
private UserService userService;
@Autowired
RedisTemplate redisTemplate;
+ @Autowired
+ private MailTemplate mailTemplate;
+ @Autowired
+ private DozerTemplate dozerTemplate;
+
@GetMapping("/test")
public ResponseVO test(){
@@ -46,8 +66,8 @@ public class UserController {
return ResultUtil.success(new User());
}
- @PostMapping("/list")
- public ResponseVO queryUserPageList(@RequestBody User user){
+ @GetMapping("/list")
+ public ResponseVO queryUserPageList(User user){
IPage iPage=userService.queryUserPageList(user);
return ResultUtil.success(iPage);
}
@@ -73,5 +93,40 @@ public class UserController {
return AjaxResult.success();
}
+ @GetMapping("/testMail")
+ public AjaxResult testMail(){
+ mailTemplate.sendSimpleMail("1029693356@qq.com","邮件标题","发送邮件测试");
+ return AjaxResult.success();
+ }
+
+ @GetMapping("/testExportPoi")
+ public AjaxResult testExportPoi(){
+ ExcelUtil excelUtil = new ExcelUtil(User.class);
+ List list = userService.list();
+ List dictList = new ArrayList<>();
+ Dict dict = new Dict();
+ dict.setDictLabel("男");
+ dict.setDictValue("0");
+ dictList.add(dict);
+ DictUtils.setDictCache("user_sex",dictList);
+ return excelUtil.exportExcel(list,"导出用户列表");
+ }
+
+ @GetMapping("/testImportPoi")
+ public AjaxResult testImportPoi() throws Exception{
+ ExcelUtil excelUtil = new ExcelUtil(User.class);
+ File file = new File("E:\\upload\\secret-boot-framework\\upload\\导入用户列表.xlsx");
+ List list = excelUtil.importExcel(FileUtils.openInputStream(file));
+ return AjaxResult.success(list);
+ }
+
+ @GetMapping("/testDozer")
+ public AjaxResult testDozer() {
+ User user = new User();
+ user.setUsername("secret");
+ user.setSex(0);
+ UserCopy userCopy = dozerTemplate.map(user, UserCopy.class);
+ return AjaxResult.success(userCopy);
+ }
}
diff --git a/secret-boot-framework-demo/common-demo/src/main/java/cn/chenc/framework/demo/converters/MyLocalDateTimeConverter.java b/secret-boot-framework-demo/common-demo/src/main/java/cn/chenc/framework/demo/converters/MyLocalDateTimeConverter.java
index 4a1557724940654a6ea660f47198a7abd8017861..027e3559f298af75e77cf78d3afa67138984231f 100644
--- a/secret-boot-framework-demo/common-demo/src/main/java/cn/chenc/framework/demo/converters/MyLocalDateTimeConverter.java
+++ b/secret-boot-framework-demo/common-demo/src/main/java/cn/chenc/framework/demo/converters/MyLocalDateTimeConverter.java
@@ -1,25 +1,20 @@
package cn.chenc.framework.demo.converters;
-import com.alibaba.excel.annotation.format.DateTimeFormat;
-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 java.time.LocalDate;
-import java.time.LocalDateTime;
-import java.time.format.DateTimeFormatter;
-import java.util.Objects;
+//import com.alibaba.excel.annotation.format.DateTimeFormat;
+//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;
/**
- * @description: TODO
+ * @description: easyexcel自定义格式转化器
* @author 陈_C
* @date 2020/8/26 16:32
*
*/
-public class MyLocalDateTimeConverter implements Converter {
+public class MyLocalDateTimeConverter /*implements Converter*/ {
/**
* 不使用{@code @LocalDateTimeFormat}注解指定日期格式时,默认会使用该格式.
@@ -32,15 +27,15 @@ public class MyLocalDateTimeConverter implements Converter {
private static final String READ_PATTERN = "yyyy-MM-dd";
- @Override
- public Class supportJavaTypeKey() {
- return LocalDateTime.class;
- }
-
- @Override
- public CellDataTypeEnum supportExcelTypeKey() {
- return CellDataTypeEnum.STRING;
- }
+// @Override
+// public Class supportJavaTypeKey() {
+// return LocalDateTime.class;
+// }
+//
+// @Override
+// public CellDataTypeEnum supportExcelTypeKey() {
+// return CellDataTypeEnum.STRING;
+// }
/**
* 这里读的时候会调用
@@ -50,15 +45,15 @@ public class MyLocalDateTimeConverter implements Converter {
* @param globalConfiguration 全局配置 (NotNull)
* @return 读取到内存中的数据
*/
- @Override
- public LocalDateTime convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
- DateTimeFormat annotation = contentProperty.getField().getAnnotation(DateTimeFormat.class);
- LocalDate localDate = LocalDate.parse(cellData.getStringValue(), DateTimeFormatter.ofPattern(Objects.nonNull(annotation) ? annotation.value() : READ_PATTERN));
- LocalDateTime localDateTime = localDate.atStartOfDay();
-// return LocalDateTime.parse(cellData.getStringValue(),
-// DateTimeFormatter.ofPattern(Objects.nonNull(annotation) ? annotation.value() : DEFAULT_PATTERN));
- return localDateTime;
- }
+// @Override
+// public LocalDateTime convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
+// DateTimeFormat annotation = contentProperty.getField().getAnnotation(DateTimeFormat.class);
+// LocalDate localDate = LocalDate.parse(cellData.getStringValue(), DateTimeFormatter.ofPattern(Objects.nonNull(annotation) ? annotation.value() : READ_PATTERN));
+// LocalDateTime localDateTime = localDate.atStartOfDay();
+//// return LocalDateTime.parse(cellData.getStringValue(),
+//// DateTimeFormatter.ofPattern(Objects.nonNull(annotation) ? annotation.value() : DEFAULT_PATTERN));
+// return localDateTime;
+// }
/**
@@ -69,10 +64,10 @@ public class MyLocalDateTimeConverter implements Converter {
* @param globalConfiguration 全局配置 (NotNull)
* @return 写出到excel文件的数据
*/
- @Override
- public CellData convertToExcelData(LocalDateTime value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
- DateTimeFormat annotation = contentProperty.getField().getAnnotation(DateTimeFormat.class);
- return new CellData(value.format(DateTimeFormatter.ofPattern(Objects.nonNull(annotation) ? annotation.value() : DEFAULT_PATTERN)));
- }
+// @Override
+// public CellData convertToExcelData(LocalDateTime value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
+// DateTimeFormat annotation = contentProperty.getField().getAnnotation(DateTimeFormat.class);
+// return new CellData(value.format(DateTimeFormatter.ofPattern(Objects.nonNull(annotation) ? annotation.value() : DEFAULT_PATTERN)));
+// }
}
diff --git a/secret-boot-framework-demo/common-demo/src/main/java/cn/chenc/framework/demo/entity/Dict.java b/secret-boot-framework-demo/common-demo/src/main/java/cn/chenc/framework/demo/entity/Dict.java
new file mode 100644
index 0000000000000000000000000000000000000000..cb46aa5d79349b879606b7002d6e382f9190a76b
--- /dev/null
+++ b/secret-boot-framework-demo/common-demo/src/main/java/cn/chenc/framework/demo/entity/Dict.java
@@ -0,0 +1,36 @@
+package cn.chenc.framework.demo.entity;
+
+import cn.chenc.framework.core.model.AbstractDictData;
+
+import java.io.Serializable;
+
+/**
+ * @description: TODO
+ * @author secret
+ * @date 2021/7/31 23:06
+ *
+ */
+public class Dict implements AbstractDictData, Serializable {
+
+ private String dictLabel;
+
+ private String dictValue;
+
+ public void setDictLabel(String dictLabel) {
+ this.dictLabel = dictLabel;
+ }
+
+ public void setDictValue(String dictValue) {
+ this.dictValue = dictValue;
+ }
+
+ @Override
+ public String getDictLabel() {
+ return dictLabel;
+ }
+
+ @Override
+ public String getDictValue() {
+ return dictValue;
+ }
+}
diff --git a/secret-boot-framework-demo/common-demo/src/main/java/cn/chenc/framework/demo/entity/Role.java b/secret-boot-framework-demo/common-demo/src/main/java/cn/chenc/framework/demo/entity/Role.java
new file mode 100644
index 0000000000000000000000000000000000000000..261b8c0831b2c913531d987018635587adeab183
--- /dev/null
+++ b/secret-boot-framework-demo/common-demo/src/main/java/cn/chenc/framework/demo/entity/Role.java
@@ -0,0 +1,52 @@
+package cn.chenc.framework.demo.entity;
+
+import cn.chenc.framework.mybatisplus.model.BaseEntity;
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+
+import java.io.Serializable;
+
+/**
+ * @description: TODO
+ * @author secret
+ * @date 2021/7/30 23:59
+ *
+ */
+public class Role extends BaseEntity implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * 主键id
+ */
+ @TableId(value = "id", type = IdType.AUTO)
+ private Integer id;
+
+ private String roleName;
+
+ private String roleCode;
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public String getRoleName() {
+ return roleName;
+ }
+
+ public void setRoleName(String roleName) {
+ this.roleName = roleName;
+ }
+
+ public String getRoleCode() {
+ return roleCode;
+ }
+
+ public void setRoleCode(String roleCode) {
+ this.roleCode = roleCode;
+ }
+}
diff --git a/secret-boot-framework-demo/common-demo/src/main/java/cn/chenc/framework/demo/entity/User.java b/secret-boot-framework-demo/common-demo/src/main/java/cn/chenc/framework/demo/entity/User.java
index eca74d95141515a3c9807b3e3d12e5581df940fa..2049e97411ee10838c2208c14d6e701eedd11707 100644
--- a/secret-boot-framework-demo/common-demo/src/main/java/cn/chenc/framework/demo/entity/User.java
+++ b/secret-boot-framework-demo/common-demo/src/main/java/cn/chenc/framework/demo/entity/User.java
@@ -1,6 +1,7 @@
package cn.chenc.framework.demo.entity;
import cn.chenc.framework.mybatisplus.model.BaseEntity;
+import cn.chenc.framework.poi.annotation.Excel;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
@@ -30,16 +31,19 @@ public class User extends BaseEntity implements Serializable {
/**
* 用户名
*/
+ @Excel(name="用户名")
private String username;
/**
* 性别,0:女,1男
*/
+ @Excel(name="性别",dictType = "user_sex")
private Integer sex;
/**
* 生日
*/
+ @Excel(name="生日",dateFormat = "yyyy-MM-dd")
private LocalDateTime birthday;
@TableField(exist = false)
diff --git a/secret-boot-framework-demo/common-demo/src/main/java/cn/chenc/framework/demo/entity/UserCopy.java b/secret-boot-framework-demo/common-demo/src/main/java/cn/chenc/framework/demo/entity/UserCopy.java
new file mode 100644
index 0000000000000000000000000000000000000000..d51b26f6df930af3c09a54f1d8762cf2eef69a46
--- /dev/null
+++ b/secret-boot-framework-demo/common-demo/src/main/java/cn/chenc/framework/demo/entity/UserCopy.java
@@ -0,0 +1,25 @@
+package cn.chenc.framework.demo.entity;
+
+import cn.chenc.framework.poi.annotation.Excel;
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * @description: TODO
+ * @author secret
+ * @date 2021/8/1 15:57
+ *
+ */
+@Data
+public class UserCopy implements Serializable {
+ /**
+ * 用户名
+ */
+ private String username;
+
+ /**
+ * 性别,0:女,1男
+ */
+ private Integer sex;
+}
diff --git a/secret-boot-framework-demo/common-demo/src/main/java/cn/chenc/framework/demo/mapper/RoleMapper.java b/secret-boot-framework-demo/common-demo/src/main/java/cn/chenc/framework/demo/mapper/RoleMapper.java
new file mode 100644
index 0000000000000000000000000000000000000000..058aa7cecdfbf6cb4dd2f24497d3b8b49897a269
--- /dev/null
+++ b/secret-boot-framework-demo/common-demo/src/main/java/cn/chenc/framework/demo/mapper/RoleMapper.java
@@ -0,0 +1,17 @@
+package cn.chenc.framework.demo.mapper;
+
+import cn.chenc.framework.demo.entity.Role;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Mapper;
+import org.springframework.stereotype.Repository;
+
+/**
+ * @description: TODO
+ * @author secret
+ * @date 2020/11/30 10:03
+ *
+ */
+@Mapper
+@Repository
+public interface RoleMapper extends BaseMapper {
+}
diff --git a/secret-boot-framework-demo/common-demo/src/main/java/cn/chenc/framework/demo/service/RoleService.java b/secret-boot-framework-demo/common-demo/src/main/java/cn/chenc/framework/demo/service/RoleService.java
new file mode 100644
index 0000000000000000000000000000000000000000..3485c9665550f7922cc4d90981467ec9e2e7a0ac
--- /dev/null
+++ b/secret-boot-framework-demo/common-demo/src/main/java/cn/chenc/framework/demo/service/RoleService.java
@@ -0,0 +1,15 @@
+package cn.chenc.framework.demo.service;
+
+import cn.chenc.framework.demo.entity.Role;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.service.IService;
+
+/**
+ * @description: TODO
+ * @author secret
+ * @date 2020/11/30 10:06
+ *
+ */
+public interface RoleService extends IService {
+ IPage queryRolePageList(Role role);
+}
diff --git a/secret-boot-framework-demo/common-demo/src/main/java/cn/chenc/framework/demo/service/impl/RoleServiceImpl.java b/secret-boot-framework-demo/common-demo/src/main/java/cn/chenc/framework/demo/service/impl/RoleServiceImpl.java
new file mode 100644
index 0000000000000000000000000000000000000000..4f961b7fd57d550e6fd5b0f46c78ed922363e4bd
--- /dev/null
+++ b/secret-boot-framework-demo/common-demo/src/main/java/cn/chenc/framework/demo/service/impl/RoleServiceImpl.java
@@ -0,0 +1,31 @@
+package cn.chenc.framework.demo.service.impl;
+
+import cn.chenc.framework.core.annotation.ChangDataSource;
+import cn.chenc.framework.demo.entity.Role;
+import cn.chenc.framework.demo.mapper.RoleMapper;
+import cn.chenc.framework.demo.service.RoleService;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.stereotype.Service;
+
+/**
+ * @description: TODO
+ * @author secret
+ * @date 2020/11/30 10:09
+ *
+ */
+@Service
+public class RoleServiceImpl extends ServiceImpl implements RoleService {
+
+ @Override
+ @ChangDataSource(name = "slaveDataSource")
+ public IPage queryRolePageList(Role role) {
+ IPage page=new Page(role.getPageIndex(),role.getPageSize());
+ IPage iPage=this.page(page,null);
+ return iPage;
+ }
+
+
+
+}
diff --git a/secret-boot-framework-demo/common-demo/src/main/resources/application-dev.yml b/secret-boot-framework-demo/common-demo/src/main/resources/application-dev.yml
index 6fa8d6da83ef87e767ab64b459cf9b0a03158c1a..7b878dd9cdc7c61810ba88643a7dadbaf5037d77 100644
--- a/secret-boot-framework-demo/common-demo/src/main/resources/application-dev.yml
+++ b/secret-boot-framework-demo/common-demo/src/main/resources/application-dev.yml
@@ -6,24 +6,47 @@ server:
spring:
datasource:
druid:
- connection-init-sqls: set names utf8mb4
- driver-class-name: com.mysql.cj.jdbc.Driver
- initial-size: 5
- min-idle: 5
- max-active: 20
- # 配置获取连接等待超时的时间
- max-wait: 180000
- # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
- time-between-eviction-runs-millis: 180000
- # 配置一个连接在池中最小生存的时间,单位是毫秒
- min-evictable-idle-time-millis: 300000
- test-while-idle: true
- test-on-borrow: false
- test-on-return: false
- type: com.alibaba.druid.pool.DruidDataSource
- url: jdbc:mysql://127.0.0.1:3306/secret_framework?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT&rewriteBatchedStatements=true
- username: root
- password: 111111
+ master:
+ connection-init-sqls: set names utf8mb4
+ driver-class-name: com.mysql.cj.jdbc.Driver
+ initial-size: 5
+ min-idle: 5
+ max-active: 20
+ # 配置获取连接等待超时的时间
+ max-wait: 180000
+ # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
+ time-between-eviction-runs-millis: 180000
+ # 配置一个连接在池中最小生存的时间,单位是毫秒
+ min-evictable-idle-time-millis: 300000
+ # 配置一个连接在池中最大生存的时间,单位是毫秒
+ max-evictable-idle-time-millis: 900000
+ test-while-idle: true
+ test-on-borrow: false
+ test-on-return: false
+ type: com.alibaba.druid.pool.DruidDataSource
+ url: jdbc:mysql://127.0.0.1:3306/secret_framework?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT&rewriteBatchedStatements=true
+ username: root
+ password: 111111
+ slave:
+ connection-init-sqls: set names utf8mb4
+ driver-class-name: com.mysql.cj.jdbc.Driver
+ initial-size: 5
+ min-idle: 5
+ max-active: 20
+ # 配置获取连接等待超时的时间
+ max-wait: 180000
+ # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
+ time-between-eviction-runs-millis: 180000
+ # 配置一个连接在池中最小生存的时间,单位是毫秒
+ min-evictable-idle-time-millis: 300000
+ # 配置一个连接在池中最大生存的时间,单位是毫秒
+ max-evictable-idle-time-millis: 900000
+ test-while-idle: true
+ test-on-borrow: false
+ test-on-return: false
+ url: jdbc:mysql://127.0.0.1:3306/secret_framework_slave?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT&rewriteBatchedStatements=true
+ username: root
+ password: 111111
# Redis数据库索引(默认为0)
redis:
jedis:
@@ -40,6 +63,27 @@ spring:
timeout: 5000ms
# 默认的数据过期时间
expire: 2592000
+ mail:
+ #smtp服务主机 qq邮箱则为smtp.qq.com
+ host: smtp.qq.com
+ #服务协议
+ protocol: smtp
+ # 编码集
+ default-encoding: UTF-8
+ #发送邮件的账户
+ username: 1029693356@qq.com
+ #授权码
+ password: wtktmncfdiivbejh
+ test-connection: false
+ # 服务端口
+ port: 587
+ properties:
+ mail:
+ smtp:
+ auth: true
+ starttls:
+ enable: true
+ required: true
#日志
logging:
@@ -47,5 +91,8 @@ logging:
root: debug
# org.springframework.scheduling: INFO
+#secret-config
+secret-config:
+ profile: E:\upload\secret-boot-framework
####################################自定义配置##########################################
diff --git a/secret-boot-framework-demo/common-demo/src/main/resources/mapper/RoleMapper.xml b/secret-boot-framework-demo/common-demo/src/main/resources/mapper/RoleMapper.xml
new file mode 100644
index 0000000000000000000000000000000000000000..a1b1d80eeede8a8bef41d91095f64d253dd7975c
--- /dev/null
+++ b/secret-boot-framework-demo/common-demo/src/main/resources/mapper/RoleMapper.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/secret-boot-framework-demo/jpa-demo/pom.xml b/secret-boot-framework-demo/jpa-demo/pom.xml
index 3c5319a524eddd3d16cdfda4602e3c2064ee3aba..d3676d6a07285e260555bd8c19fa0465cd919032 100644
--- a/secret-boot-framework-demo/jpa-demo/pom.xml
+++ b/secret-boot-framework-demo/jpa-demo/pom.xml
@@ -13,7 +13,7 @@
com.gitee.secretopen
secret-boot-framework-dependencies
- 1.5.0
+ 1.6.0
pom
import
diff --git a/secret-boot-framework-demo/jpa-demo/src/main/java/cn/chenc/framework/demo/config/DemoSourceConfig.java b/secret-boot-framework-demo/jpa-demo/src/main/java/cn/chenc/framework/demo/config/DemoSourceConfig.java
new file mode 100644
index 0000000000000000000000000000000000000000..7592d09172f42facb1077582d745d286422db0ef
--- /dev/null
+++ b/secret-boot-framework-demo/jpa-demo/src/main/java/cn/chenc/framework/demo/config/DemoSourceConfig.java
@@ -0,0 +1,21 @@
+package cn.chenc.framework.demo.config;
+
+import cn.chenc.framework.jpa.support.BaseJpaRepositoryFactoryBean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
+
+/**
+ * @description: TODO
+ * @author secret
+ * @date 2021/7/21 20:47
+ *
+ */
+@Configuration
+@EnableJpaRepositories(
+ // 设置Repository所在位置
+ basePackages = { "cn.chenc.framework.demo.dao" },
+ // 覆盖SpringBoot提供的默认配置
+ repositoryFactoryBeanClass = BaseJpaRepositoryFactoryBean.class)
+public class DemoSourceConfig {
+
+}
diff --git a/secret-boot-framework-demo/jpa-demo/src/main/java/cn/chenc/framework/demo/controller/UserController.java b/secret-boot-framework-demo/jpa-demo/src/main/java/cn/chenc/framework/demo/controller/UserController.java
index 37a423ee92c5c76b0aac7586e3b1f1b8e2386e56..b6b0b93777e5b0b6c82ff3ade8c61d733b4131c8 100644
--- a/secret-boot-framework-demo/jpa-demo/src/main/java/cn/chenc/framework/demo/controller/UserController.java
+++ b/secret-boot-framework-demo/jpa-demo/src/main/java/cn/chenc/framework/demo/controller/UserController.java
@@ -5,7 +5,6 @@ import cn.chenc.framework.demo.entity.UserEntity;
import cn.chenc.framework.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
-import org.springframework.web.bind.annotation.*;
import java.util.List;
@@ -38,4 +37,9 @@ public class UserController {
return AjaxResult.success();
}
+ @GetMapping("/baseApiPage")
+ public Page baseApiPage(UserEntity userEntity) throws Exception {
+ return userService.baseApiPage(userEntity);
+ }
+
}
diff --git a/secret-boot-framework-demo/jpa-demo/src/main/java/cn/chenc/framework/demo/dao/UserRepository.java b/secret-boot-framework-demo/jpa-demo/src/main/java/cn/chenc/framework/demo/dao/UserRepository.java
index 756c3baf146bb1a78db989d947a9f6cf93a32562..87a64f9deb5047d9ad87100df62b09faba4eab55 100644
--- a/secret-boot-framework-demo/jpa-demo/src/main/java/cn/chenc/framework/demo/dao/UserRepository.java
+++ b/secret-boot-framework-demo/jpa-demo/src/main/java/cn/chenc/framework/demo/dao/UserRepository.java
@@ -1,8 +1,8 @@
package cn.chenc.framework.demo.dao;
import cn.chenc.framework.demo.entity.UserEntity;
-import org.springframework.data.jpa.repository.JpaRepository;
-import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+import cn.chenc.framework.jpa.repository.BaseRepository;
+import org.springframework.stereotype.Repository;
/**
* @description: TODO
@@ -10,7 +10,8 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
* @date 2021/5/14 15:26
*
*/
-public interface UserRepository extends JpaRepository, JpaSpecificationExecutor {
+@Repository
+public interface UserRepository extends BaseRepository {//JpaRepository, JpaSpecificationExecutor {
diff --git a/secret-boot-framework-demo/jpa-demo/src/main/java/cn/chenc/framework/demo/entity/UserEntity.java b/secret-boot-framework-demo/jpa-demo/src/main/java/cn/chenc/framework/demo/entity/UserEntity.java
index 594090d1b5c9dec6dc6d89b72ca762ff06ef6187..e51dc5b5f5350671878c451704c3216b93e9108e 100644
--- a/secret-boot-framework-demo/jpa-demo/src/main/java/cn/chenc/framework/demo/entity/UserEntity.java
+++ b/secret-boot-framework-demo/jpa-demo/src/main/java/cn/chenc/framework/demo/entity/UserEntity.java
@@ -2,7 +2,6 @@ package cn.chenc.framework.demo.entity;
import cn.chenc.framework.jpa.model.BaseEntity;
-import javax.persistence.*;
import java.io.Serializable;
import java.time.LocalDateTime;
diff --git a/secret-boot-framework-demo/jpa-demo/src/main/java/cn/chenc/framework/demo/service/UserService.java b/secret-boot-framework-demo/jpa-demo/src/main/java/cn/chenc/framework/demo/service/UserService.java
index d734cffe5fee833044d1df838fd2d8ea45627a54..f86c49497ca29e5db3e8d5605143725744f7a4c5 100644
--- a/secret-boot-framework-demo/jpa-demo/src/main/java/cn/chenc/framework/demo/service/UserService.java
+++ b/secret-boot-framework-demo/jpa-demo/src/main/java/cn/chenc/framework/demo/service/UserService.java
@@ -1,6 +1,8 @@
package cn.chenc.framework.demo.service;
+
import cn.chenc.framework.demo.entity.UserEntity;
+import cn.chenc.framework.jpa.service.BaseService;
import org.springframework.data.domain.Page;
import java.util.List;
@@ -11,11 +13,13 @@ import java.util.List;
* @date 2021/5/14 15:45
*
*/
-public interface UserService {
+public interface UserService extends BaseService {
List queryAll();
Page queryUserPageList(UserEntity userEntity);
void insertUser(UserEntity userEntity);
+
+ Page baseApiPage(UserEntity userEntity) throws Exception;
}
diff --git a/secret-boot-framework-demo/jpa-demo/src/main/java/cn/chenc/framework/demo/service/impl/UserServiceImpl.java b/secret-boot-framework-demo/jpa-demo/src/main/java/cn/chenc/framework/demo/service/impl/UserServiceImpl.java
index ea759bc060c12cbda431a646257e1549d6a7b530..c1a1e808984d55b3a70e9dd4c7ff5f4a757a6dcf 100644
--- a/secret-boot-framework-demo/jpa-demo/src/main/java/cn/chenc/framework/demo/service/impl/UserServiceImpl.java
+++ b/secret-boot-framework-demo/jpa-demo/src/main/java/cn/chenc/framework/demo/service/impl/UserServiceImpl.java
@@ -4,6 +4,7 @@ import cn.chenc.framework.core.util.StringUtils;
import cn.chenc.framework.demo.dao.UserRepository;
import cn.chenc.framework.demo.entity.UserEntity;
import cn.chenc.framework.demo.service.UserService;
+import cn.chenc.framework.jpa.service.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
@@ -26,7 +27,7 @@ import java.util.List;
*
*/
@Service
-public class UserServiceImpl implements UserService {
+public class UserServiceImpl extends BaseServiceImpl implements UserService {
@Autowired
private UserRepository userRepository;
@@ -60,4 +61,10 @@ public class UserServiceImpl implements UserService {
userRepository.save(userEntity);
}
+ @Override
+ public Page baseApiPage(UserEntity userEntity) throws Exception {
+ Page page = userRepository.getListByObject(userEntity,PageRequest.of(0,10));
+ return page;
+ }
+
}
diff --git a/secret-boot-framework-demo/security-demo/pom.xml b/secret-boot-framework-demo/security-demo/pom.xml
index be2a508da1e7dee816e7bf031fd8081bb0dd1794..1399ec804c566c57582429028e1ce9171fe0decc 100644
--- a/secret-boot-framework-demo/security-demo/pom.xml
+++ b/secret-boot-framework-demo/security-demo/pom.xml
@@ -14,7 +14,7 @@
com.gitee.secretopen
secret-boot-framework-dependencies
- 1.5.0
+ 1.6.0
pom
import
diff --git a/secret-boot-framework-demo/security-demo/src/main/java/cn/chenc/framework/demo/config/JwtConfig.java b/secret-boot-framework-demo/security-demo/src/main/java/cn/chenc/framework/demo/config/JwtConfig.java
index 806d33c1a8dec4090b555830a13e434195d9ab25..36134f2bbd4ea299b1900258a611afb4adf1f972 100644
--- a/secret-boot-framework-demo/security-demo/src/main/java/cn/chenc/framework/demo/config/JwtConfig.java
+++ b/secret-boot-framework-demo/security-demo/src/main/java/cn/chenc/framework/demo/config/JwtConfig.java
@@ -1,7 +1,7 @@
package cn.chenc.framework.demo.config;
-import cn.chenc.framework.security.jwt.SecurityJwtTemplate;
-import cn.chenc.framework.security.jwt.SecurityRedisJwtTemplate;
+import cn.chenc.framework.core.component.AbstractJwtTemplate;
+import cn.chenc.framework.core.component.RedisJwtTemplate;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -15,8 +15,8 @@ import org.springframework.context.annotation.Configuration;
public class JwtConfig {
@Bean
- public SecurityJwtTemplate securityJwtTemplate(){
- SecurityRedisJwtTemplate securityRedisJwtTemplate = new SecurityRedisJwtTemplate();
+ public AbstractJwtTemplate securityJwtTemplate(){
+ AbstractJwtTemplate securityRedisJwtTemplate = new RedisJwtTemplate();
return securityRedisJwtTemplate;
}
diff --git a/secret-boot-framework-demo/security-demo/src/main/java/cn/chenc/framework/demo/controller/LoginController.java b/secret-boot-framework-demo/security-demo/src/main/java/cn/chenc/framework/demo/controller/LoginController.java
index 4703a18ff9d5441f137815a499da72c05935ace6..d9255111b3b8bf250725da4d54c0eeba4652eec0 100644
--- a/secret-boot-framework-demo/security-demo/src/main/java/cn/chenc/framework/demo/controller/LoginController.java
+++ b/secret-boot-framework-demo/security-demo/src/main/java/cn/chenc/framework/demo/controller/LoginController.java
@@ -7,7 +7,7 @@ import cn.chenc.framework.core.model.response.AjaxResult;
import cn.chenc.framework.core.model.response.CustomCode;
import cn.chenc.framework.demo.entity.User;
import cn.chenc.framework.security.jwt.SecurityJwtTemplate;
-import cn.chenc.framework.security.model.LoginUser;
+import cn.chenc.framework.security.model.SecurityLoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.authentication.AuthenticationManager;
@@ -46,8 +46,8 @@ public class LoginController {
throw new CustomException(CustomCode.error(e.getMessage()));
}
//登录成功
- LoginUser loginUser = (LoginUser) authentication.getPrincipal();
- String token=securityJwtTemplate.createToken(loginUser);
+ SecurityLoginUser securityLoginUser = (SecurityLoginUser) authentication.getPrincipal();
+ String token=securityJwtTemplate.createToken(securityLoginUser);
AjaxResult ajax=AjaxResult.success();
ajax.put("token",token);
return ajax;
@@ -57,8 +57,8 @@ public class LoginController {
@ResponseBody
@PostMapping("getInfo")
public AjaxResult getInfo(@RequestBody User user){
- LoginUser loginUser=securityJwtTemplate.getLoginUser(RequestHolder.getRequest());
- return AjaxResult.success(loginUser);
+ SecurityLoginUser securityLoginUser = (SecurityLoginUser) securityJwtTemplate.getLoginUser(RequestHolder.getRequest());
+ return AjaxResult.success(securityLoginUser);
}
@PreAuthorize("@ss.hasPermi('test')")
diff --git a/secret-boot-framework-demo/security-demo/src/main/java/cn/chenc/framework/demo/service/impl/UserDetailsServiceImpl.java b/secret-boot-framework-demo/security-demo/src/main/java/cn/chenc/framework/demo/service/impl/UserDetailsServiceImpl.java
index 0c5f1da3f82b2e2cfea95e708aa2470208d86a7d..d2e2d7fc334bdb7e8a98a01ded30b195f9446bd1 100644
--- a/secret-boot-framework-demo/security-demo/src/main/java/cn/chenc/framework/demo/service/impl/UserDetailsServiceImpl.java
+++ b/secret-boot-framework-demo/security-demo/src/main/java/cn/chenc/framework/demo/service/impl/UserDetailsServiceImpl.java
@@ -1,7 +1,7 @@
package cn.chenc.framework.demo.service.impl;
import cn.chenc.framework.demo.entity.User;
-import cn.chenc.framework.security.model.LoginUser;
+import cn.chenc.framework.security.model.SecurityLoginUser;
import cn.chenc.framework.security.util.SecurityUtil;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
@@ -27,7 +27,7 @@ public class UserDetailsServiceImpl implements UserDetailsService {
}
public UserDetails createLoginUser(User user) {
- return new LoginUser(user, null);
+ return new SecurityLoginUser(user, null);
}
}
diff --git a/secret-boot-framework-demo/shiro-demo/pom.xml b/secret-boot-framework-demo/shiro-demo/pom.xml
index 77e9c5eb180d4290e424bf43092e869058fa65a1..4ce60a2a88c2cf84c04893047dff51df43d36acc 100644
--- a/secret-boot-framework-demo/shiro-demo/pom.xml
+++ b/secret-boot-framework-demo/shiro-demo/pom.xml
@@ -13,7 +13,7 @@
com.gitee.secretopen
secret-boot-framework-dependencies
- 1.5.0
+ 1.6.0
pom
import
diff --git a/secret-boot-framework-dependencies/pom.xml b/secret-boot-framework-dependencies/pom.xml
index bf1aadacb0b491e4e80de60529c910b482305d8a..7251c2da452ef853ab73daf5637fc4877aa789dd 100644
--- a/secret-boot-framework-dependencies/pom.xml
+++ b/secret-boot-framework-dependencies/pom.xml
@@ -5,11 +5,11 @@
org.springframework.boot
spring-boot-starter-parent
- 2.4.5
+ 2.5.3
4.0.0
- 1.5.0
+ 1.6.0
com.gitee.secretopen
secret-boot-framework-dependencies
pom
@@ -20,37 +20,39 @@
1.8
- 1.5.0
- 2.4.3.RELEASE
+ 1.6.0
1.2.6
- 8.0.25
+ 8.0.26
- 2.8.0
+ 2.11.0
1.4
1.9
3.8.0
- 1.10.10
+ 1.10.11
4.5.13
4.9.1
1.18.20
3.0.0
30.1.1-jre
- 3.4.2
- 1.13.1
+ 3.4.3.1
+ 1.14.1
1.21
0.62.2
- 5.6.5
+ 5.7.6
2.2.9
+ 4.1.2
0.9.1
1.7.1
- 3.15.4
+ 3.16.1
+
+ 6.5.2
3.2.1
- 2.9.1
+ 3.3.0
1.6
@@ -77,6 +79,11 @@
secret-boot-framework-captcha
${secret-boot.version}
+
+ ${project.groupId}
+ secret-boot-framework-dozer
+ ${secret-boot.version}
+
${project.groupId}
secret-boot-framework-excel
@@ -87,6 +94,11 @@
secret-boot-framework-ffmpeg
${secret-boot.version}
+
+ ${project.groupId}
+ secret-boot-framework-jpa
+ ${secret-boot.version}
+
${project.groupId}
secret-boot-framework-mybatisplus
@@ -94,12 +106,17 @@
${project.groupId}
- secret-boot-framework-security
+ secret-boot-framework-mail
${secret-boot.version}
${project.groupId}
- secret-boot-framework-jpa
+ secret-boot-framework-poi
+ ${secret-boot.version}
+
+
+ ${project.groupId}
+ secret-boot-framework-security
${secret-boot.version}
@@ -113,23 +130,25 @@
mysql-connector-java
${mysql-connector-java.version}
+
com.baomidou
mybatis-plus-boot-starter
${mybatis-plus.version}
-
+
com.alibaba
druid-spring-boot-starter
${druid.version}
+
com.squareup.okhttp3
okhttp
${okhttp.version}
-
+
commons-fileupload
commons-fileupload
@@ -166,19 +185,19 @@
ant
${ant.version}
-
-
+
org.apache.httpcomponents
httpclient
${httpclient.version}
-
+
org.projectlombok
lombok
${lombok.version}
+
io.springfox
springfox-swagger2
@@ -189,6 +208,7 @@
springfox-swagger-ui
${springfox-swagger.version}
+
com.google.guava
guava
@@ -215,7 +235,6 @@
${flexmark.version}
-
cn.hutool
@@ -223,13 +242,18 @@
${hutool.version}
compile
-
com.alibaba
easyexcel
${easyexcel.version}
+
+
+ org.apache.poi
+ poi-ooxml
+ ${poi.version}
+
io.jsonwebtoken
@@ -248,6 +272,17 @@
redisson-spring-boot-starter
${redisson.version}
+
+
+ com.github.dozermapper
+ dozer-core
+ ${dozer.version}
+
+
+ com.github.dozermapper
+ dozer-spring4
+ ${dozer.version}
+
@@ -298,15 +333,15 @@
org.apache.maven.plugins
maven-javadoc-plugin
${maven-javadoc-plugin.version}
-
- -Xdoclint:none
-
package
jar
+
+ -Xdoclint:none
+
diff --git a/secret-boot-framework-dozer/pom.xml b/secret-boot-framework-dozer/pom.xml
new file mode 100644
index 0000000000000000000000000000000000000000..a1d374d56441311fb9346b1f866bebac0c7317d9
--- /dev/null
+++ b/secret-boot-framework-dozer/pom.xml
@@ -0,0 +1,29 @@
+
+
+
+ secret-boot-framework
+ com.gitee.secretopen
+ 1.6.0
+
+ 4.0.0
+
+ secret-boot-framework-dozer
+
+
+
+ org.springframework.boot
+ spring-boot-autoconfigure
+
+
+
+ com.github.dozermapper
+ dozer-core
+
+
+ com.github.dozermapper
+ dozer-spring4
+
+
+
diff --git a/secret-boot-framework-dozer/src/main/java/cn/chenc/framework/dozer/component/DozerTemplate.java b/secret-boot-framework-dozer/src/main/java/cn/chenc/framework/dozer/component/DozerTemplate.java
new file mode 100644
index 0000000000000000000000000000000000000000..0b9bdcbd770b665b5fef2f1447d35eccb8c25bac
--- /dev/null
+++ b/secret-boot-framework-dozer/src/main/java/cn/chenc/framework/dozer/component/DozerTemplate.java
@@ -0,0 +1,128 @@
+package cn.chenc.framework.dozer.component;
+
+import com.github.dozermapper.core.Mapper;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * @description: TODO
+ * @author secret
+ * @date 2021/7/26 23:25
+ *
+ */
+public class DozerTemplate {
+ private Mapper mapper;
+
+ public DozerTemplate(Mapper mapper) {
+ this.mapper = mapper;
+ }
+
+ public Mapper getMapper() {
+ return this.mapper;
+ }
+
+ /**
+ * 构造destinationClass的新实例,并在源代码之间执行映射
+ *
+ * @param source
+ * @param destinationClass
+ * @param
+ * @return
+ */
+ public T map(Object source, Class destinationClass) {
+ if (source == null) {
+ return null;
+ }
+ return mapper.map(source, destinationClass);
+ }
+
+ public T map2(Object source, Class destinationClass) {
+ if (source == null) {
+ try {
+ return destinationClass.newInstance();
+ } catch (Exception e) {
+ }
+ }
+ return mapper.map(source, destinationClass);
+ }
+
+ /**
+ * 在源对象和目标对象之间执行映射
+ *
+ * @param source
+ * @param destination
+ */
+ public void map(Object source, Object destination) {
+ if (source == null) {
+ return;
+ }
+ mapper.map(source, destination);
+ }
+
+ /**
+ * 构造destinationClass的新实例,并在源代码之间执行映射
+ *
+ * @param source
+ * @param destinationClass
+ * @param mapId
+ * @param
+ * @return
+ */
+ public T map(Object source, Class destinationClass, String mapId) {
+ if (source == null) {
+ return null;
+ }
+ return mapper.map(source, destinationClass, mapId);
+ }
+
+ /**
+ * 在源对象和目标对象之间执行映射
+ *
+ * @param source
+ * @param destination
+ * @param mapId
+ */
+ public void map(Object source, Object destination, String mapId) {
+ if (source == null) {
+ return;
+ }
+ mapper.map(source, destination, mapId);
+ }
+
+ /**
+ * 将集合转成集合
+ * List --> List
+ *
+ * @param sourceList 源集合
+ * @param destinationClass 待转类型
+ * @param
+ * @return
+ */
+ public List mapList(Collection sourceList, Class destinationClass) {
+ return mapPage(sourceList, destinationClass);
+ }
+
+
+ public List mapPage(Collection sourceList, Class destinationClass) {
+ if (sourceList == null || sourceList.isEmpty() || destinationClass == null) {
+ return Collections.emptyList();
+ }
+ List destinationList = sourceList.parallelStream()
+ .filter(item -> item != null)
+ .map((sourceObject) -> mapper.map(sourceObject, destinationClass))
+ .collect(Collectors.toList());
+
+ return destinationList;
+ }
+
+ public Set mapSet(Collection sourceList, Class destinationClass) {
+ if (sourceList == null || sourceList.isEmpty() || destinationClass == null) {
+ return Collections.emptySet();
+ }
+ return sourceList.parallelStream().map((sourceObject) -> mapper.map(sourceObject, destinationClass)).collect(Collectors.toSet());
+ }
+}
diff --git a/secret-boot-framework-dozer/src/main/java/cn/chenc/framework/dozer/config/DozerConfiguration.java b/secret-boot-framework-dozer/src/main/java/cn/chenc/framework/dozer/config/DozerConfiguration.java
new file mode 100644
index 0000000000000000000000000000000000000000..3cb6c77ae151cd012d183529da88fe3a0d9984a3
--- /dev/null
+++ b/secret-boot-framework-dozer/src/main/java/cn/chenc/framework/dozer/config/DozerConfiguration.java
@@ -0,0 +1,57 @@
+package cn.chenc.framework.dozer.config;
+
+import cn.chenc.framework.dozer.component.DozerTemplate;
+import cn.chenc.framework.dozer.properties.DozerProperties;
+import com.github.dozermapper.core.Mapper;
+import com.github.dozermapper.spring.DozerBeanMapperFactoryBean;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+import java.io.IOException;
+
+/**
+ * @description: Dozer配置
+ * @author secret
+ * @date 2021/7/26 23:07
+ *
+ */
+@Configuration
+@ConditionalOnClass({DozerBeanMapperFactoryBean.class, Mapper.class})
+@ConditionalOnMissingBean(Mapper.class)
+@EnableConfigurationProperties(DozerProperties.class)
+public class DozerConfiguration {
+ private final DozerProperties properties;
+
+
+ /**
+ * Constructor for creating auto configuration.
+ *
+ * @param properties properties
+ */
+ public DozerConfiguration(DozerProperties properties) {
+ this.properties = properties;
+ }
+
+ @Bean
+ public DozerTemplate dozerTemplate(Mapper mapper) {
+ return new DozerTemplate(mapper);
+ }
+
+ /**
+ * Creates default Dozer mapper
+ *
+ * @return Dozer mapper
+ * @throws IOException if there is an exception during initialization.
+ */
+ @Bean
+ public DozerBeanMapperFactoryBean dozerMapper() throws IOException {
+ DozerBeanMapperFactoryBean factoryBean = new DozerBeanMapperFactoryBean();
+ // 官方这样子写,没法用 匹配符!
+ //factoryBean.setMappingFiles(properties.getMappingFiles());
+ factoryBean.setMappingFiles(properties.resolveMapperLocations());
+ return factoryBean;
+ }
+}
diff --git a/secret-boot-framework-dozer/src/main/java/cn/chenc/framework/dozer/properties/DozerProperties.java b/secret-boot-framework-dozer/src/main/java/cn/chenc/framework/dozer/properties/DozerProperties.java
new file mode 100644
index 0000000000000000000000000000000000000000..644184dc73a9717349a5b812d0539e383bab5e66
--- /dev/null
+++ b/secret-boot-framework-dozer/src/main/java/cn/chenc/framework/dozer/properties/DozerProperties.java
@@ -0,0 +1,62 @@
+package cn.chenc.framework.dozer.properties;
+
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.core.io.Resource;
+import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
+import org.springframework.core.io.support.ResourcePatternResolver;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Optional;
+import java.util.stream.Stream;
+
+/**
+ * @description: Dozer属性
+ * @author secret
+ * @date 2021/7/26 23:01
+ *
+ */
+@ConfigurationProperties(prefix = "dozer")
+public class DozerProperties {
+ private static final ResourcePatternResolver PATTERN_RESOLVER = new PathMatchingResourcePatternResolver();
+
+ /**
+ * Mapping files configuration.
+ * For example "classpath:*.dozer.xml".
+ */
+ private String[] mappingFiles = new String[]{"classpath*:dozer/*.dozer.xml"};
+
+ /**
+ * Mapping files configuration.
+ *
+ * @return mapping files
+ */
+ public String[] getMappingFiles() {
+ return Arrays.copyOf(mappingFiles, mappingFiles.length);
+ }
+
+ /**
+ * Set mapping files configuration. For example classpath:*.dozer.xml.
+ *
+ * @param mappingFiles dozer mapping files
+ * @return dozer properties
+ */
+ public DozerProperties setMappingFiles(String[] mappingFiles) {
+ this.mappingFiles = Arrays.copyOf(mappingFiles, mappingFiles.length);
+ return this;
+ }
+
+ public Resource[] resolveMapperLocations() {
+ return Stream.of(Optional.ofNullable(this.mappingFiles).orElse(new String[0]))
+ .flatMap(location -> Stream.of(getResources(location)))
+ .toArray(Resource[]::new);
+ }
+
+ private Resource[] getResources(String location) {
+ try {
+ return PATTERN_RESOLVER.getResources(location);
+ } catch (IOException var3) {
+ return new Resource[0];
+ }
+ }
+}
diff --git a/secret-boot-framework-dozer/src/main/resources/dozer/global.dozer.xml b/secret-boot-framework-dozer/src/main/resources/dozer/global.dozer.xml
new file mode 100644
index 0000000000000000000000000000000000000000..095df4c5f9373b8467c9977e0edee51fecbed296
--- /dev/null
+++ b/secret-boot-framework-dozer/src/main/resources/dozer/global.dozer.xml
@@ -0,0 +1,18 @@
+
+
+
+
+
+ yyyy-MM-dd HH:mm:ss
+
+
+
+
diff --git a/secret-boot-framework-excel/pom.xml b/secret-boot-framework-excel/pom.xml
index 047fd4cbebd4db542fcb8837806e140c97e20a17..70cdcc34581a70fef26fc0b35a539406f7c6581a 100644
--- a/secret-boot-framework-excel/pom.xml
+++ b/secret-boot-framework-excel/pom.xml
@@ -5,7 +5,7 @@
secret-boot-framework
com.gitee.secretopen
- 1.5.0
+ 1.6.0
4.0.0
@@ -15,7 +15,6 @@
com.gitee.secretopen
secret-boot-framework-core
- ${project.parent.version}
diff --git a/secret-boot-framework-ffmpeg/pom.xml b/secret-boot-framework-ffmpeg/pom.xml
index 39136b422b3eaa81c299bcbc0caad84385fecf70..dad057d11e5f5e4f7d11061a2c25918c36e7f4c3 100644
--- a/secret-boot-framework-ffmpeg/pom.xml
+++ b/secret-boot-framework-ffmpeg/pom.xml
@@ -5,7 +5,7 @@
secret-boot-framework
com.gitee.secretopen
- 1.5.0
+ 1.6.0
4.0.0
@@ -15,7 +15,6 @@
com.gitee.secretopen
secret-boot-framework-core
- ${project.parent.version}
diff --git a/secret-boot-framework-jpa/pom.xml b/secret-boot-framework-jpa/pom.xml
index b3e490d8753e81b8d3f723eb71d41263d82ddd55..b24d28279bd2fb8e9f9b2bec363f2132b59652ab 100644
--- a/secret-boot-framework-jpa/pom.xml
+++ b/secret-boot-framework-jpa/pom.xml
@@ -5,7 +5,7 @@
secret-boot-framework
com.gitee.secretopen
- 1.5.0
+ 1.6.0
4.0.0
@@ -15,7 +15,6 @@
com.gitee.secretopen
secret-boot-framework-core
- ${project.parent.version}
diff --git a/secret-boot-framework-jpa/src/main/java/cn/chenc/framework/jpa/exception/RepositoryException.java b/secret-boot-framework-jpa/src/main/java/cn/chenc/framework/jpa/exception/RepositoryException.java
new file mode 100644
index 0000000000000000000000000000000000000000..6489305a45ecb47f437c87edbafdb87c440b69a9
--- /dev/null
+++ b/secret-boot-framework-jpa/src/main/java/cn/chenc/framework/jpa/exception/RepositoryException.java
@@ -0,0 +1,96 @@
+package cn.chenc.framework.jpa.exception;
+
+/**
+ * @description: jpa异常
+ * @author secret
+ * @date 2021/6/5 22:16
+ *
+ */
+public class RepositoryException extends Exception {
+
+ private static final long serialVersionUID = 1L;
+ private String module;
+ private String code = "500";
+ private Object[] args;
+ private String msg;
+
+ public RepositoryException(String msg) {
+ super(msg);
+ this.msg = msg;
+ }
+
+ public RepositoryException(String code, Object[] args) {
+ this.code = code;
+ this.args = args;
+ }
+
+ public RepositoryException(String code, String msg) {
+ this.code = code;
+ this.msg = msg;
+ }
+
+ public RepositoryException(String module, String code, Object[] args) {
+ this.module = module;
+ this.code = code;
+ this.args = args;
+ }
+
+ public RepositoryException(String module, String code, Object[] args, String msg) {
+ this.module = module;
+ this.code = code;
+ this.args = args;
+ this.msg = msg;
+ }
+
+ public RepositoryException(Throwable throwable) {
+ super(throwable);
+ }
+
+ public RepositoryException(String msg, Throwable e) {
+ super(msg, e);
+ this.msg = msg;
+ }
+
+ public RepositoryException(String msg, String code, Throwable e) {
+ super(msg, e);
+ this.msg = msg;
+ this.code = code;
+ }
+
+ @Override
+ public String toString() {
+ return this.getClass() + "{" + "module='" + this.module + '\'' + ", message='" + this.getMessage() + '\'' + '}';
+ }
+
+ public String getModule() {
+ return this.module;
+ }
+
+ public String getCode() {
+ return this.code;
+ }
+
+ public Object[] getArgs() {
+ return this.args;
+ }
+
+ public String getMsg() {
+ return this.msg;
+ }
+
+ public void setModule(final String module) {
+ this.module = module;
+ }
+
+ public void setCode(final String code) {
+ this.code = code;
+ }
+
+ public void setArgs(final Object[] args) {
+ this.args = args;
+ }
+
+ public void setMsg(final String msg) {
+ this.msg = msg;
+ }
+}
diff --git a/secret-boot-framework-jpa/src/main/java/cn/chenc/framework/jpa/exception/ServiceException.java b/secret-boot-framework-jpa/src/main/java/cn/chenc/framework/jpa/exception/ServiceException.java
new file mode 100644
index 0000000000000000000000000000000000000000..73bbfa50962f5e9d335073ae287fa4ef81fd3498
--- /dev/null
+++ b/secret-boot-framework-jpa/src/main/java/cn/chenc/framework/jpa/exception/ServiceException.java
@@ -0,0 +1,95 @@
+package cn.chenc.framework.jpa.exception;
+
+/**
+ * @description: service 异常
+ * @author secret
+ * @date 2021/6/5 23:31
+ *
+ */
+public class ServiceException extends Exception {
+ private static final long serialVersionUID = 1L;
+ private String module;
+ private String code = "500";
+ private Object[] args;
+ private String msg;
+
+ public ServiceException(String msg) {
+ super(msg);
+ this.msg = msg;
+ }
+
+ public ServiceException(String code, Object[] args) {
+ this.code = code;
+ this.args = args;
+ }
+
+ public ServiceException(String code, String msg) {
+ this.code = code;
+ this.msg = msg;
+ }
+
+ public ServiceException(String module, String code, Object[] args) {
+ this.module = module;
+ this.code = code;
+ this.args = args;
+ }
+
+ public ServiceException(String module, String code, Object[] args, String msg) {
+ this.module = module;
+ this.code = code;
+ this.args = args;
+ this.msg = msg;
+ }
+
+ public ServiceException(Throwable throwable) {
+ super(throwable);
+ }
+
+ public ServiceException(String msg, Throwable e) {
+ super(msg, e);
+ this.msg = msg;
+ }
+
+ public ServiceException(String msg, String code, Throwable e) {
+ super(msg, e);
+ this.msg = msg;
+ this.code = code;
+ }
+
+ @Override
+ public String toString() {
+ return this.getClass() + "{" + "module='" + this.module + '\'' + ", message='" + this.getMessage() + '\'' + '}';
+ }
+
+ public String getModule() {
+ return this.module;
+ }
+
+ public String getCode() {
+ return this.code;
+ }
+
+ public Object[] getArgs() {
+ return this.args;
+ }
+
+ public String getMsg() {
+ return this.msg;
+ }
+
+ public void setModule(final String module) {
+ this.module = module;
+ }
+
+ public void setCode(final String code) {
+ this.code = code;
+ }
+
+ public void setArgs(final Object[] args) {
+ this.args = args;
+ }
+
+ public void setMsg(final String msg) {
+ this.msg = msg;
+ }
+}
diff --git a/secret-boot-framework-jpa/src/main/java/cn/chenc/framework/jpa/jdbc/BaseJdbcTemplate.java b/secret-boot-framework-jpa/src/main/java/cn/chenc/framework/jpa/jdbc/BaseJdbcTemplate.java
new file mode 100644
index 0000000000000000000000000000000000000000..6dea0856fbe16f31a98af955307b27e996d3eddd
--- /dev/null
+++ b/secret-boot-framework-jpa/src/main/java/cn/chenc/framework/jpa/jdbc/BaseJdbcTemplate.java
@@ -0,0 +1,40 @@
+package cn.chenc.framework.jpa.jdbc;
+
+import cn.chenc.framework.jpa.exception.RepositoryException;
+import cn.chenc.framework.jpa.model.PageInfo;
+import org.springframework.jdbc.core.JdbcTemplate;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @description: TODO
+ * @author secret
+ * @date 2021/7/21 22:07
+ *
+ */
+public interface BaseJdbcTemplate {
+
+ List