Browse Source

Merge branch 'master-2023-10-23' into dev

# Conflicts:
#	blade-ops/blade-resource/src/main/java/org/springblade/resource/builder/OssBuilder.java
#	blade-ops/blade-resource/src/main/resources/application.yml
#	blade-service/blade-system/src/main/java/org/springblade/system/service/impl/TenantServiceImpl.java
pull/1/head
pref_mail@163.com 1 year ago
parent
commit
239e4ba3bb
  1. 2
      blade-auth/pom.xml
  2. 2
      blade-auth/src/main/resources/templates/confirm.ftl
  3. 2
      blade-auth/src/main/resources/templates/login.ftl
  4. 2
      blade-common/pom.xml
  5. 2
      blade-gateway/pom.xml
  6. 9
      blade-gateway/src/main/java/org/springblade/gateway/filter/AuthFilter.java
  7. 2
      blade-ops-api/blade-flow-api/pom.xml
  8. 2
      blade-ops-api/blade-resource-api/pom.xml
  9. 4
      blade-ops-api/pom.xml
  10. 2
      blade-ops/blade-admin/pom.xml
  11. 2
      blade-ops/blade-admin/src/main/resources/bootstrap.yml
  12. 2
      blade-ops/blade-develop/pom.xml
  13. 2
      blade-ops/blade-flow/pom.xml
  14. 2
      blade-ops/blade-log/pom.xml
  15. 2
      blade-ops/blade-report/pom.xml
  16. 7
      blade-ops/blade-resource/pom.xml
  17. 80
      blade-ops/blade-resource/src/main/java/org/springblade/resource/builder/OssBuilder.java
  18. 51
      blade-ops/blade-resource/src/main/java/org/springblade/resource/builder/SmsBuilder.java
  19. 8
      blade-ops/blade-resource/src/main/java/org/springblade/resource/config/BladeOssConfiguration.java
  20. 7
      blade-ops/blade-resource/src/main/java/org/springblade/resource/config/BladeSmsConfiguration.java
  21. 2
      blade-ops/blade-resource/src/main/java/org/springblade/resource/endpoint/OssEndpoint.java
  22. 2
      blade-ops/blade-resource/src/main/java/org/springblade/resource/endpoint/SmsEndpoint.java
  23. 2
      blade-ops/blade-resource/src/main/java/org/springblade/resource/feign/SmsClient.java
  24. 64
      blade-ops/blade-resource/src/main/java/org/springblade/resource/rule/context/OssContext.java
  25. 64
      blade-ops/blade-resource/src/main/java/org/springblade/resource/rule/context/SmsContext.java
  26. 40
      blade-ops/blade-resource/src/main/java/org/springblade/resource/rule/oss/AliOssRule.java
  27. 25
      blade-ops/blade-resource/src/main/java/org/springblade/resource/rule/oss/AmazonS3Rule.java
  28. 58
      blade-ops/blade-resource/src/main/java/org/springblade/resource/rule/oss/FinallyOssRule.java
  29. 24
      blade-ops/blade-resource/src/main/java/org/springblade/resource/rule/oss/HuaweiObsRule.java
  30. 39
      blade-ops/blade-resource/src/main/java/org/springblade/resource/rule/oss/MinioRule.java
  31. 53
      blade-ops/blade-resource/src/main/java/org/springblade/resource/rule/oss/OssBuildRule.java
  32. 42
      blade-ops/blade-resource/src/main/java/org/springblade/resource/rule/oss/OssCacheRule.java
  33. 45
      blade-ops/blade-resource/src/main/java/org/springblade/resource/rule/oss/OssDataRule.java
  34. 48
      blade-ops/blade-resource/src/main/java/org/springblade/resource/rule/oss/OssReadRule.java
  35. 42
      blade-ops/blade-resource/src/main/java/org/springblade/resource/rule/oss/OssTemplateRule.java
  36. 52
      blade-ops/blade-resource/src/main/java/org/springblade/resource/rule/oss/PreOssRule.java
  37. 26
      blade-ops/blade-resource/src/main/java/org/springblade/resource/rule/oss/QiniuOssRule.java
  38. 27
      blade-ops/blade-resource/src/main/java/org/springblade/resource/rule/oss/TencentCosRule.java
  39. 28
      blade-ops/blade-resource/src/main/java/org/springblade/resource/rule/sms/AliSmsRule.java
  40. 52
      blade-ops/blade-resource/src/main/java/org/springblade/resource/rule/sms/CacheSmsRule.java
  41. 58
      blade-ops/blade-resource/src/main/java/org/springblade/resource/rule/sms/FinallySmsRule.java
  42. 52
      blade-ops/blade-resource/src/main/java/org/springblade/resource/rule/sms/PreSmsRule.java
  43. 27
      blade-ops/blade-resource/src/main/java/org/springblade/resource/rule/sms/QiniuSmsRule.java
  44. 53
      blade-ops/blade-resource/src/main/java/org/springblade/resource/rule/sms/SmsBuildRule.java
  45. 27
      blade-ops/blade-resource/src/main/java/org/springblade/resource/rule/sms/TencentSmsRule.java
  46. 27
      blade-ops/blade-resource/src/main/java/org/springblade/resource/rule/sms/YunpianSmsRule.java
  47. 12
      blade-ops/blade-resource/src/main/resources/application.yml
  48. BIN
      blade-ops/blade-resource/src/main/resources/liteflow/oss.el.png
  49. 24
      blade-ops/blade-resource/src/main/resources/liteflow/oss.el.xml
  50. BIN
      blade-ops/blade-resource/src/main/resources/liteflow/sms.el.png
  51. 16
      blade-ops/blade-resource/src/main/resources/liteflow/sms.el.xml
  52. 2
      blade-ops/blade-swagger/pom.xml
  53. 4
      blade-ops/pom.xml
  54. 4
      blade-plugin-api/README.md
  55. 4
      blade-plugin-api/pom.xml
  56. 4
      blade-plugin/README.md
  57. 4
      blade-plugin/pom.xml
  58. 2
      blade-service-api/blade-desk-api/pom.xml
  59. 2
      blade-service-api/blade-dict-api/pom.xml
  60. 2
      blade-service-api/blade-scope-api/pom.xml
  61. 2
      blade-service-api/blade-system-api/pom.xml
  62. 2
      blade-service-api/blade-user-api/pom.xml
  63. 4
      blade-service-api/pom.xml
  64. 2
      blade-service/blade-desk/pom.xml
  65. 3
      blade-service/blade-desk/src/main/java/org/springblade/desk/controller/NoticeController.java
  66. 6
      blade-service/blade-system/pom.xml
  67. 91
      blade-service/blade-system/src/main/java/org/springblade/system/rule/TenantContext.java
  68. 53
      blade-service/blade-system/src/main/java/org/springblade/system/rule/TenantDeptRule.java
  69. 81
      blade-service/blade-system/src/main/java/org/springblade/system/rule/TenantDictBizRule.java
  70. 49
      blade-service/blade-system/src/main/java/org/springblade/system/rule/TenantPostRule.java
  71. 79
      blade-service/blade-system/src/main/java/org/springblade/system/rule/TenantRoleMenuRule.java
  72. 48
      blade-service/blade-system/src/main/java/org/springblade/system/rule/TenantRoleRule.java
  73. 71
      blade-service/blade-system/src/main/java/org/springblade/system/rule/TenantRule.java
  74. 63
      blade-service/blade-system/src/main/java/org/springblade/system/rule/TenantUserRule.java
  75. 194
      blade-service/blade-system/src/main/java/org/springblade/system/service/impl/TenantServiceImpl.java
  76. BIN
      blade-service/blade-system/src/main/resources/liteflow/tenant.el.png
  77. 16
      blade-service/blade-system/src/main/resources/liteflow/tenant.el.xml
  78. 4
      blade-service/pom.xml
  79. 6
      doc/nacos/blade.yaml
  80. 4
      pom.xml
  81. 2
      script/docker/app/.env
  82. 48
      script/docker/skywalking/docker-compose.yml

2
blade-auth/pom.xml

@ -8,7 +8,7 @@
<parent>
<artifactId>BladeX</artifactId>
<groupId>org.springblade</groupId>
<version>3.1.1.RELEASE</version>
<version>3.2.0.RELEASE</version>
</parent>
<artifactId>blade-auth</artifactId>

2
blade-auth/src/main/resources/templates/confirm.ftl

@ -29,7 +29,7 @@
</div>
</form>
<div class="other-links">
<span>Copyrights © 2022 <a href="https://bladex.vip" target="_blank">BladeX</a> All Rights Reserved.</span>
<span>Copyrights © 2023 <a href="https://bladex.cn" target="_blank">BladeX</a> All Rights Reserved.</span>
</div>
</div>
</div>

2
blade-auth/src/main/resources/templates/login.ftl

@ -30,7 +30,7 @@
</div>
</form>
<div class="other-links">
<span>Copyrights © 2022 <a href="https://bladex.vip" target="_blank">BladeX</a> All Rights Reserved.</span>
<span>Copyrights © 2023 <a href="https://bladex.cn" target="_blank">BladeX</a> All Rights Reserved.</span>
</div>
</div>
</div>

2
blade-common/pom.xml

@ -5,7 +5,7 @@
<parent>
<artifactId>BladeX</artifactId>
<groupId>org.springblade</groupId>
<version>3.1.1.RELEASE</version>
<version>3.2.0.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>

2
blade-gateway/pom.xml

@ -5,7 +5,7 @@
<parent>
<artifactId>BladeX</artifactId>
<groupId>org.springblade</groupId>
<version>3.1.1.RELEASE</version>
<version>3.2.0.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>

9
blade-gateway/src/main/java/org/springblade/gateway/filter/AuthFilter.java

@ -22,9 +22,11 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import io.jsonwebtoken.Claims;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.jwt.JwtCrypto;
import org.springblade.core.jwt.JwtUtil;
import org.springblade.core.jwt.props.JwtProperties;
import org.springblade.core.launch.constant.TokenConstant;
import org.springblade.core.launch.props.BladeProperties;
import org.springblade.gateway.props.AuthProperties;
import org.springblade.gateway.provider.AuthProvider;
import org.springblade.gateway.provider.RequestProvider;
@ -43,6 +45,8 @@ import reactor.core.publisher.Mono;
import java.nio.charset.StandardCharsets;
import static org.springblade.core.jwt.JwtCrypto.BLADE_CRYPTO_AES_KEY;
/**
* 鉴权认证
*
@ -55,6 +59,7 @@ public class AuthFilter implements GlobalFilter, Ordered {
private final AuthProperties authProperties;
private final ObjectMapper objectMapper;
private final JwtProperties jwtProperties;
private final BladeProperties bladeProperties;
private final AntPathMatcher antPathMatcher = new AntPathMatcher();
@Override
@ -74,6 +79,10 @@ public class AuthFilter implements GlobalFilter, Ordered {
}
String auth = StringUtils.isBlank(headerToken) ? paramToken : headerToken;
String token = JwtUtil.getToken(auth);
//校验 加密Token 合法性
if (JwtUtil.isCrypto(auth)) {
token = JwtCrypto.decryptToString(token, bladeProperties.getEnvironment().getProperty(BLADE_CRYPTO_AES_KEY));
}
Claims claims = JwtUtil.parseJWT(token);
if (token == null || claims == null) {
return unAuth(resp, "请求未授权");

2
blade-ops-api/blade-flow-api/pom.xml

@ -5,7 +5,7 @@
<parent>
<artifactId>blade-ops-api</artifactId>
<groupId>org.springblade</groupId>
<version>3.1.1.RELEASE</version>
<version>3.2.0.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>

2
blade-ops-api/blade-resource-api/pom.xml

@ -5,7 +5,7 @@
<parent>
<artifactId>blade-ops-api</artifactId>
<groupId>org.springblade</groupId>
<version>3.1.1.RELEASE</version>
<version>3.2.0.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>

4
blade-ops-api/pom.xml

@ -5,13 +5,13 @@
<parent>
<artifactId>BladeX</artifactId>
<groupId>org.springblade</groupId>
<version>3.1.1.RELEASE</version>
<version>3.2.0.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>blade-ops-api</artifactId>
<name>${project.artifactId}</name>
<version>3.1.1.RELEASE</version>
<version>3.2.0.RELEASE</version>
<packaging>pom</packaging>
<description>BladeX 微服务API集合</description>

2
blade-ops/blade-admin/pom.xml

@ -5,7 +5,7 @@
<parent>
<artifactId>blade-ops</artifactId>
<groupId>org.springblade</groupId>
<version>3.1.1.RELEASE</version>
<version>3.2.0.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>

2
blade-ops/blade-admin/src/main/resources/bootstrap.yml

@ -24,7 +24,7 @@ spring:
title: BladeX Monitor
external-views:
- label: 架构官网
url: https://bladex.vip/
url: https://bladex.cn/
order: 1
iframe: true
# 用于内网安全,判断 admin proxy

2
blade-ops/blade-develop/pom.xml

@ -6,7 +6,7 @@
<parent>
<groupId>org.springblade</groupId>
<artifactId>blade-ops</artifactId>
<version>3.1.1.RELEASE</version>
<version>3.2.0.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>

2
blade-ops/blade-flow/pom.xml

@ -5,7 +5,7 @@
<parent>
<artifactId>blade-ops</artifactId>
<groupId>org.springblade</groupId>
<version>3.1.1.RELEASE</version>
<version>3.2.0.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>

2
blade-ops/blade-log/pom.xml

@ -5,7 +5,7 @@
<parent>
<artifactId>blade-ops</artifactId>
<groupId>org.springblade</groupId>
<version>3.1.1.RELEASE</version>
<version>3.2.0.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>

2
blade-ops/blade-report/pom.xml

@ -5,7 +5,7 @@
<parent>
<artifactId>blade-ops</artifactId>
<groupId>org.springblade</groupId>
<version>3.1.1.RELEASE</version>
<version>3.2.0.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>

7
blade-ops/blade-resource/pom.xml

@ -5,7 +5,7 @@
<parent>
<artifactId>blade-ops</artifactId>
<groupId>org.springblade</groupId>
<version>3.1.1.RELEASE</version>
<version>3.2.0.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@ -82,6 +82,11 @@
<groupId>com.yunpian.sdk</groupId>
<artifactId>yunpian-java-sdk</artifactId>
</dependency>
<!--liteflow-->
<dependency>
<groupId>org.springblade</groupId>
<artifactId>blade-starter-liteflow</artifactId>
</dependency>
<dependency>
<groupId>org.springblade</groupId>
<artifactId>blade-resource-api</artifactId>

80
blade-ops/blade-resource/src/main/java/org/springblade/resource/builder/oss/OssBuilder.java → blade-ops/blade-resource/src/main/java/org/springblade/resource/builder/OssBuilder.java

@ -14,25 +14,25 @@
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.resource.builder.oss;
package org.springblade.resource.builder;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.extern.slf4j.Slf4j;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.flow.LiteflowResponse;
import lombok.AllArgsConstructor;
import org.springblade.core.cache.utils.CacheUtil;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.oss.OssTemplate;
import org.springblade.core.oss.enums.OssEnum;
import org.springblade.core.oss.enums.OssStatusEnum;
import org.springblade.core.oss.props.OssProperties;
import org.springblade.core.oss.rule.BladeOssRule;
import org.springblade.core.oss.rule.OssRule;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.StringPool;
import org.springblade.core.tool.utils.StringUtil;
import org.springblade.core.tool.utils.WebUtil;
import org.springblade.resource.entity.Oss;
import org.springblade.resource.rule.context.OssContext;
import org.springblade.resource.service.IOssService;
import java.util.Map;
@ -45,7 +45,7 @@ import static org.springblade.core.cache.constant.CacheConstant.RESOURCE_CACHE;
*
* @author Chill
*/
@Slf4j
@AllArgsConstructor
public class OssBuilder {
public static final String OSS_CODE = "oss:code:";
@ -53,11 +53,7 @@ public class OssBuilder {
private final OssProperties ossProperties;
private final IOssService ossService;
public OssBuilder(OssProperties ossProperties, IOssService ossService) {
this.ossProperties = ossProperties;
this.ossService = ossService;
}
private final FlowExecutor flowExecutor;
/**
* OssTemplate配置缓存池
@ -86,54 +82,23 @@ public class OssBuilder {
*/
public OssTemplate template(String code) {
String tenantId = AuthUtil.getTenantId();
return template(code, tenantId);
}
Oss oss = getOss(tenantId, code);
OssContext ossContext = new OssContext();
ossContext.setOss(oss);
ossContext.setOssProperties(ossProperties);
ossContext.setOssPool(ossPool);
ossContext.setTemplatePool(templatePool);
/**
* 构建存储对象
* @param code
* @param tenantId
* @return
*/
public OssTemplate template(String code,String tenantId ) {
Oss oss = getOss(tenantId, code);
Oss ossCached = ossPool.get(tenantId);
OssTemplate template = templatePool.get(tenantId);
// 若为空或者不一致,则重新加载
if (Func.hasEmpty(template, ossCached) || !oss.getEndpoint().equals(ossCached.getEndpoint()) || !oss.getAccessKey().equals(ossCached.getAccessKey())) {
synchronized (OssBuilder.class) {
template = templatePool.get(tenantId);
if (Func.hasEmpty(template, ossCached) || !oss.getEndpoint().equals(ossCached.getEndpoint()) || !oss.getAccessKey().equals(ossCached.getAccessKey())) {
OssRule ossRule;
// 若采用默认设置则开启多租户模式, 若是用户自定义oss则不开启
if (oss.getEndpoint().equals(ossProperties.getEndpoint()) && oss.getAccessKey().equals(ossProperties.getAccessKey()) && ossProperties.getTenantMode()) {
ossRule = new BladeOssRule(Boolean.TRUE);
} else {
ossRule = new BladeOssRule(Boolean.FALSE);
}
if (oss.getCategory() == OssEnum.MINIO.getCategory()) {
template = MinioOssBuilder.template(oss, ossRule);
} else if (oss.getCategory() == OssEnum.QINIU.getCategory()) {
template = QiniuOssBuilder.template(oss, ossRule);
} else if (oss.getCategory() == OssEnum.ALI.getCategory()) {
template = AliOssBuilder.template(oss, ossRule);
} else if (oss.getCategory() == OssEnum.TENCENT.getCategory()) {
template = TencentCosBuilder.template(oss, ossRule);
} else if (oss.getCategory() == OssEnum.HUAWEI.getCategory()) {
template = HuaweiObsBuilder.template(oss, ossRule);
} else if (oss.getCategory() == OssEnum.AMAZONS3.getCategory()) {
template = AmazonS3OssBuilder.template(oss, ossRule);
}
templatePool.put(tenantId, template);
ossPool.put(tenantId, oss);
}
}
LiteflowResponse resp = flowExecutor.execute2Resp("ossChain", tenantId, ossContext);
if (resp.isSuccess()) {
OssContext contextBean = resp.getFirstContextBean();
return contextBean.getOssTemplate();
} else {
throw new ServiceException("未获取到对应的对象存储配置");
}
return template;
}
/**
* 获取对象存储实体
*
@ -141,13 +106,10 @@ public class OssBuilder {
* @return Oss
*/
public Oss getOss(String tenantId, String code) {
log.info(">>>>>>> tenantId ={}",tenantId);
log.info(">>>>>>> code ={}",code);
String key = tenantId;
LambdaQueryWrapper<Oss> lqw = Wrappers.<Oss>query().lambda().eq(Oss::getTenantId, tenantId);
// 获取传参的资源编号并查询,若有则返回,若没有则调启用的配置
String ossCode = StringUtil.isBlank(code) ? WebUtil.getParameter(OSS_PARAM_KEY) : code;
log.info(">>>>>>> ossCode ={}",ossCode);
if (StringUtil.isNotBlank(ossCode)) {
key = key.concat(StringPool.DASH).concat(ossCode);
lqw.eq(Oss::getOssCode, ossCode);
@ -156,7 +118,6 @@ public class OssBuilder {
}
Oss oss = CacheUtil.get(RESOURCE_CACHE, OSS_CODE, key, () -> {
Oss o = ossService.getOne(lqw);
log.info(">>>>>>> o ={}",o);
// 若为空则调用默认配置
if (o == null || o.getId() == null) {
Oss defaultOss = new Oss();
@ -166,13 +127,11 @@ public class OssBuilder {
defaultOss.setBucketName(ossProperties.getBucketName());
defaultOss.setAccessKey(ossProperties.getAccessKey());
defaultOss.setSecretKey(ossProperties.getSecretKey());
log.info(">>>>>>> defaultOss ={}",defaultOss);
return defaultOss;
} else {
return o;
}
});
if (oss == null || oss.getId() == null) {
throw new ServiceException("未获取到对应的对象存储配置");
} else {
@ -180,5 +139,4 @@ public class OssBuilder {
}
}
}

51
blade-ops/blade-resource/src/main/java/org/springblade/resource/builder/sms/SmsBuilder.java → blade-ops/blade-resource/src/main/java/org/springblade/resource/builder/SmsBuilder.java

@ -14,10 +14,13 @@
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.resource.builder.sms;
package org.springblade.resource.builder;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.flow.LiteflowResponse;
import lombok.AllArgsConstructor;
import org.springblade.core.cache.utils.CacheUtil;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.redis.cache.BladeRedis;
@ -26,11 +29,11 @@ import org.springblade.core.sms.SmsTemplate;
import org.springblade.core.sms.enums.SmsEnum;
import org.springblade.core.sms.enums.SmsStatusEnum;
import org.springblade.core.sms.props.SmsProperties;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.StringPool;
import org.springblade.core.tool.utils.StringUtil;
import org.springblade.core.tool.utils.WebUtil;
import org.springblade.resource.entity.Sms;
import org.springblade.resource.rule.context.SmsContext;
import org.springblade.resource.service.ISmsService;
import java.util.Map;
@ -43,6 +46,7 @@ import static org.springblade.core.cache.constant.CacheConstant.RESOURCE_CACHE;
*
* @author Chill
*/
@AllArgsConstructor
public class SmsBuilder {
public static final String SMS_CODE = "sms:code:";
@ -51,13 +55,7 @@ public class SmsBuilder {
private final SmsProperties smsProperties;
private final ISmsService smsService;
private final BladeRedis bladeRedis;
public SmsBuilder(SmsProperties smsProperties, ISmsService smsService, BladeRedis bladeRedis) {
this.smsProperties = smsProperties;
this.smsService = smsService;
this.bladeRedis = bladeRedis;
}
private final FlowExecutor flowExecutor;
/**
* SmsTemplate配置缓存池
@ -88,28 +86,21 @@ public class SmsBuilder {
public SmsTemplate template(String code) {
String tenantId = AuthUtil.getTenantId();
Sms sms = getSms(tenantId, code);
Sms smsCached = smsPool.get(tenantId);
SmsTemplate template = templatePool.get(tenantId);
// 若为空或者不一致,则重新加载
if (Func.hasEmpty(template, smsCached) || !sms.getTemplateId().equals(smsCached.getTemplateId()) || !sms.getAccessKey().equals(smsCached.getAccessKey())) {
synchronized (SmsBuilder.class) {
template = templatePool.get(tenantId);
if (Func.hasEmpty(template, smsCached) || !sms.getTemplateId().equals(smsCached.getTemplateId()) || !sms.getAccessKey().equals(smsCached.getAccessKey())) {
if (sms.getCategory() == SmsEnum.YUNPIAN.getCategory()) {
template = YunpianSmsBuilder.template(sms, bladeRedis);
} else if (sms.getCategory() == SmsEnum.QINIU.getCategory()) {
template = QiniuSmsBuilder.template(sms, bladeRedis);
} else if (sms.getCategory() == SmsEnum.ALI.getCategory()) {
template = AliSmsBuilder.template(sms, bladeRedis);
} else if (sms.getCategory() == SmsEnum.TENCENT.getCategory()) {
template = TencentSmsBuilder.template(sms, bladeRedis);
}
templatePool.put(tenantId, template);
smsPool.put(tenantId, sms);
}
}
SmsContext smsContext = new SmsContext();
smsContext.setSms(sms);
smsContext.setSmsProperties(smsProperties);
smsContext.setSmsPool(smsPool);
smsContext.setTemplatePool(templatePool);
smsContext.setBladeRedis(bladeRedis);
LiteflowResponse resp = flowExecutor.execute2Resp("smsChain", tenantId, smsContext);
if (resp.isSuccess()) {
SmsContext contextBean = resp.getFirstContextBean();
return contextBean.getSmsTemplate();
} else {
throw new ServiceException("未获取到对应的短信配置");
}
return template;
}

8
blade-ops/blade-resource/src/main/java/org/springblade/resource/config/BladeOssConfiguration.java

@ -16,9 +16,10 @@
*/
package org.springblade.resource.config;
import com.yomahub.liteflow.core.FlowExecutor;
import lombok.AllArgsConstructor;
import org.springblade.core.oss.props.OssProperties;
import org.springblade.resource.builder.oss.OssBuilder;
import org.springblade.resource.builder.OssBuilder;
import org.springblade.resource.service.IOssService;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@ -36,9 +37,10 @@ public class BladeOssConfiguration {
private final IOssService ossService;
private final FlowExecutor flowExecutor;
@Bean
public OssBuilder ossBuilder() {
return new OssBuilder(ossProperties, ossService);
return new OssBuilder(ossProperties, ossService, flowExecutor);
}
}

7
blade-ops/blade-resource/src/main/java/org/springblade/resource/config/BladeSmsConfiguration.java

@ -16,10 +16,11 @@
*/
package org.springblade.resource.config;
import com.yomahub.liteflow.core.FlowExecutor;
import lombok.AllArgsConstructor;
import org.springblade.core.redis.cache.BladeRedis;
import org.springblade.core.sms.props.SmsProperties;
import org.springblade.resource.builder.sms.SmsBuilder;
import org.springblade.resource.builder.SmsBuilder;
import org.springblade.resource.service.ISmsService;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@ -39,9 +40,11 @@ public class BladeSmsConfiguration {
private final BladeRedis bladeRedis;
private final FlowExecutor flowExecutor;
@Bean
public SmsBuilder smsBuilder() {
return new SmsBuilder(smsProperties, smsService, bladeRedis);
return new SmsBuilder(smsProperties, smsService, bladeRedis, flowExecutor);
}
}

2
blade-ops/blade-resource/src/main/java/org/springblade/resource/endpoint/OssEndpoint.java

@ -27,7 +27,7 @@ import org.springblade.core.tool.api.R;
import org.springblade.core.tool.constant.RoleConstant;
import org.springblade.core.tool.utils.FileUtil;
import org.springblade.core.tool.utils.Func;
import org.springblade.resource.builder.oss.OssBuilder;
import org.springblade.resource.builder.OssBuilder;
import org.springblade.resource.entity.Attach;
import org.springblade.resource.service.IAttachService;
import org.springframework.web.bind.annotation.*;

2
blade-ops/blade-resource/src/main/java/org/springblade/resource/endpoint/SmsEndpoint.java

@ -26,7 +26,7 @@ import org.springblade.core.tenant.annotation.NonDS;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.jackson.JsonUtil;
import org.springblade.core.tool.utils.Func;
import org.springblade.resource.builder.sms.SmsBuilder;
import org.springblade.resource.builder.SmsBuilder;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

2
blade-ops/blade-resource/src/main/java/org/springblade/resource/feign/SmsClient.java

@ -24,7 +24,7 @@ import org.springblade.core.tenant.annotation.NonDS;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.jackson.JsonUtil;
import org.springblade.core.tool.utils.Func;
import org.springblade.resource.builder.sms.SmsBuilder;
import org.springblade.resource.builder.SmsBuilder;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

64
blade-ops/blade-resource/src/main/java/org/springblade/resource/rule/context/OssContext.java

@ -0,0 +1,64 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.resource.rule.context;
import lombok.Data;
import org.springblade.core.oss.OssTemplate;
import org.springblade.core.oss.props.OssProperties;
import org.springblade.core.oss.rule.OssRule;
import org.springblade.resource.entity.Oss;
import java.util.Map;
/**
* Oss上下文
*
* @author Chill
*/
@Data
public class OssContext {
/**
* 是否有缓存
*/
private Boolean isCached;
/**
* oss数据
*/
private Oss oss;
/**
* oss规则
*/
private OssRule ossRule;
/**
* oss接口
*/
private OssTemplate ossTemplate;
/**
* oss配置
*/
private OssProperties ossProperties;
/**
* OssTemplate配置缓存池
*/
private Map<String, OssTemplate> templatePool;
/**
* oss配置缓存池
*/
private Map<String, Oss> ossPool;
}

64
blade-ops/blade-resource/src/main/java/org/springblade/resource/rule/context/SmsContext.java

@ -0,0 +1,64 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.resource.rule.context;
import lombok.Data;
import org.springblade.core.redis.cache.BladeRedis;
import org.springblade.core.sms.SmsTemplate;
import org.springblade.core.sms.props.SmsProperties;
import org.springblade.resource.entity.Sms;
import java.util.Map;
/**
* Sms上下文
*
* @author Chill
*/
@Data
public class SmsContext {
/**
* 是否有缓存
*/
private Boolean isCached;
/**
* sms数据
*/
private Sms sms;
/**
* sms接口
*/
private SmsTemplate smsTemplate;
/**
* sms配置
*/
private SmsProperties smsProperties;
/**
* redis工具
*/
private BladeRedis bladeRedis;
/**
* SmsTemplate配置缓存池
*/
private Map<String, SmsTemplate> templatePool;
/**
* sms配置缓存池
*/
private Map<String, Sms> smsPool;
}

40
blade-ops/blade-resource/src/main/java/org/springblade/resource/builder/oss/AliOssBuilder.java → blade-ops/blade-resource/src/main/java/org/springblade/resource/rule/oss/AliOssRule.java

@ -14,29 +14,43 @@
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.resource.builder.oss;
package org.springblade.resource.rule.oss;
import com.aliyun.oss.ClientConfiguration;
import com.aliyun.oss.OSSClient;
import com.aliyun.oss.common.auth.CredentialsProvider;
import com.aliyun.oss.common.auth.DefaultCredentialProvider;
import lombok.SneakyThrows;
import org.springblade.core.oss.OssTemplate;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
import org.springblade.core.oss.AliossTemplate;
import org.springblade.core.oss.OssTemplate;
import org.springblade.core.oss.props.OssProperties;
import org.springblade.core.oss.rule.OssRule;
import org.springblade.resource.entity.Oss;
import org.springblade.resource.rule.context.OssContext;
/**
* 阿里云存储构建类
*
* @author Chill
*/
public class AliOssBuilder {
@LiteflowComponent(id = "aliOssRule", name = "阿里云OSS构建")
public class AliOssRule extends NodeComponent {
@SneakyThrows
public static OssTemplate template(Oss oss, OssRule ossRule) {
// 创建ClientConfiguration。ClientConfiguration是OSSClient的配置类,可配置代理、连接超时、最大连接数等参数。
@Override
public void process() throws Exception {
// 获取上下文
OssContext contextBean = this.getContextBean(OssContext.class);
Oss oss = contextBean.getOss();
OssRule ossRule = contextBean.getOssRule();
// 创建配置类
OssProperties ossProperties = new OssProperties();
ossProperties.setEndpoint(oss.getEndpoint());
ossProperties.setAccessKey(oss.getAccessKey());
ossProperties.setSecretKey(oss.getSecretKey());
ossProperties.setBucketName(oss.getBucketName());
// 创建ClientConfiguration
ClientConfiguration conf = new ClientConfiguration();
// 设置OSSClient允许打开的最大HTTP连接数,默认为1024个。
conf.setMaxConnections(1024);
@ -50,14 +64,12 @@ public class AliOssBuilder {
conf.setIdleConnectionTime(60000);
// 设置失败请求重试次数,默认为3次。
conf.setMaxErrorRetry(5);
OssProperties ossProperties = new OssProperties();
ossProperties.setEndpoint(oss.getEndpoint());
ossProperties.setAccessKey(oss.getAccessKey());
ossProperties.setSecretKey(oss.getSecretKey());
ossProperties.setBucketName(oss.getBucketName());
CredentialsProvider credentialsProvider = new DefaultCredentialProvider(ossProperties.getAccessKey(), ossProperties.getSecretKey());
// 创建客户端
OSSClient ossClient = new OSSClient(ossProperties.getEndpoint(), credentialsProvider, conf);
return new AliossTemplate(ossClient, ossProperties, ossRule);
}
OssTemplate ossTemplate = new AliossTemplate(ossClient, ossProperties, ossRule);
// 设置上下文
contextBean.setOssTemplate(ossTemplate);
}
}

25
blade-ops/blade-resource/src/main/java/org/springblade/resource/builder/oss/AmazonS3OssBuilder.java → blade-ops/blade-resource/src/main/java/org/springblade/resource/rule/oss/AmazonS3Rule.java

@ -14,7 +14,7 @@
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.resource.builder.oss;
package org.springblade.resource.rule.oss;
import com.amazonaws.ClientConfiguration;
import com.amazonaws.auth.AWSCredentials;
@ -24,23 +24,31 @@ import com.amazonaws.client.builder.AwsClientBuilder;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import lombok.SneakyThrows;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
import org.springblade.core.oss.OssTemplate;
import org.springblade.core.oss.S3Template;
import org.springblade.core.oss.props.OssProperties;
import org.springblade.core.oss.rule.OssRule;
import org.springblade.core.tool.utils.StringUtil;
import org.springblade.resource.entity.Oss;
import org.springblade.resource.rule.context.OssContext;
/**
* Amazon S3 云存储构建类
*
* @author Chill
*/
public class AmazonS3OssBuilder {
@LiteflowComponent(id = "amazonS3Rule", name = "amazonS3OSS构建")
public class AmazonS3Rule extends NodeComponent {
@Override
public void process() throws Exception {
// 获取上下文
OssContext contextBean = this.getContextBean(OssContext.class);
Oss oss = contextBean.getOss();
OssRule ossRule = contextBean.getOssRule();
@SneakyThrows
public static OssTemplate template(Oss oss, OssRule ossRule) {
// 创建配置类
OssProperties ossProperties = new OssProperties();
ossProperties.setEndpoint(oss.getEndpoint());
@ -61,7 +69,10 @@ public class AmazonS3OssBuilder {
.withClientConfiguration(clientConfiguration)
.withCredentials(new AWSStaticCredentialsProvider(credentials))
.build();
return new S3Template(amazonS3, ossRule, ossProperties);
}
OssTemplate ossTemplate = new S3Template(amazonS3, ossRule, ossProperties);
// 设置上下文
contextBean.setOssTemplate(ossTemplate);
}
}

58
blade-ops/blade-resource/src/main/java/org/springblade/resource/rule/oss/FinallyOssRule.java

@ -0,0 +1,58 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.resource.rule.oss;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.oss.OssTemplate;
import org.springblade.core.tool.utils.Func;
import org.springblade.resource.entity.Oss;
import org.springblade.resource.rule.context.OssContext;
import java.util.Map;
/**
* Oss后置处理
*
* @author Chill
*/
@LiteflowComponent(id = "finallyOssRule", name = "OSS构建后置处理")
public class FinallyOssRule extends NodeComponent {
@Override
public void process() throws Exception {
String tenantId = this.getRequestData();
OssContext contextBean = this.getContextBean(OssContext.class);
Map<String, Oss> ossPool = contextBean.getOssPool();
Map<String, OssTemplate> templatePool = contextBean.getTemplatePool();
if (contextBean.getIsCached()) {
OssTemplate template = templatePool.get(tenantId);
contextBean.setOssTemplate(template);
} else {
Oss oss = contextBean.getOss();
OssTemplate template = contextBean.getOssTemplate();
if (Func.hasEmpty(template, oss)) {
throw new ServiceException("OSS接口读取失败!");
} else {
templatePool.put(tenantId, template);
ossPool.put(tenantId, oss);
}
}
}
}

24
blade-ops/blade-resource/src/main/java/org/springblade/resource/builder/oss/HuaweiObsBuilder.java → blade-ops/blade-resource/src/main/java/org/springblade/resource/rule/oss/HuaweiObsRule.java

@ -14,26 +14,33 @@
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.resource.builder.oss;
package org.springblade.resource.rule.oss;
import com.obs.services.ObsClient;
import com.obs.services.ObsConfiguration;
import lombok.SneakyThrows;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
import org.springblade.core.oss.HuaweiObsTemplate;
import org.springblade.core.oss.OssTemplate;
import org.springblade.core.oss.props.OssProperties;
import org.springblade.core.oss.rule.OssRule;
import org.springblade.resource.entity.Oss;
import org.springblade.resource.rule.context.OssContext;
/**
* 华为云存储构建类
*
* @author Chill
*/
public class HuaweiObsBuilder {
@LiteflowComponent(id = "huaweiObsRule", name = "华为OSS构建")
public class HuaweiObsRule extends NodeComponent {
@Override
public void process() throws Exception {
// 获取上下文
OssContext contextBean = this.getContextBean(OssContext.class);
Oss oss = contextBean.getOss();
OssRule ossRule = contextBean.getOssRule();
@SneakyThrows
public static OssTemplate template(Oss oss, OssRule ossRule) {
// 创建配置类
OssProperties ossProperties = new OssProperties();
ossProperties.setEndpoint(oss.getEndpoint());
@ -57,7 +64,10 @@ public class HuaweiObsBuilder {
conf.setMaxErrorRetry(5);
// 创建客户端
ObsClient obsClient = new ObsClient(ossProperties.getAccessKey(), ossProperties.getSecretKey(), conf);
return new HuaweiObsTemplate(obsClient, ossProperties, ossRule);
}
OssTemplate ossTemplate = new HuaweiObsTemplate(obsClient, ossProperties, ossRule);
// 设置上下文
contextBean.setOssTemplate(ossTemplate);
}
}

39
blade-ops/blade-resource/src/main/java/org/springblade/resource/builder/oss/MinioOssBuilder.java → blade-ops/blade-resource/src/main/java/org/springblade/resource/rule/oss/MinioRule.java

@ -14,35 +14,50 @@
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.resource.builder.oss;
package org.springblade.resource.rule.oss;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
import io.minio.MinioClient;
import lombok.SneakyThrows;
import org.springblade.core.oss.OssTemplate;
import org.springblade.core.oss.MinioTemplate;
import org.springblade.core.oss.OssTemplate;
import org.springblade.core.oss.props.OssProperties;
import org.springblade.core.oss.rule.OssRule;
import org.springblade.resource.entity.Oss;
import org.springblade.resource.rule.context.OssContext;
/**
* Minio云存储构建类
*
* @author Chill
*/
public class MinioOssBuilder {
@LiteflowComponent(id = "minioRule", name = "minioOSS构建")
public class MinioRule extends NodeComponent {
@SneakyThrows
public static OssTemplate template(Oss oss, OssRule ossRule) {
MinioClient minioClient = MinioClient.builder()
.endpoint(oss.getEndpoint())
.credentials(oss.getAccessKey(), oss.getSecretKey())
.build();
@Override
public void process() throws Exception {
// 获取上下文
OssContext contextBean = this.getContextBean(OssContext.class);
Oss oss = contextBean.getOss();
OssRule ossRule = contextBean.getOssRule();
OssProperties properties = contextBean.getOssProperties();
// 创建配置类
OssProperties ossProperties = new OssProperties();
ossProperties.setTransformEndpoint(properties.getTransformEndpoint());
ossProperties.setEndpoint(oss.getEndpoint());
ossProperties.setAccessKey(oss.getAccessKey());
ossProperties.setSecretKey(oss.getSecretKey());
ossProperties.setBucketName(oss.getBucketName());
return new MinioTemplate(minioClient, ossRule, ossProperties);
}
// 创建客户端
MinioClient minioClient = MinioClient.builder()
.endpoint(oss.getEndpoint())
.credentials(oss.getAccessKey(), oss.getSecretKey())
.build();
OssTemplate ossTemplate = new MinioTemplate(minioClient, ossRule, ossProperties);
// 设置上下文
contextBean.setOssTemplate(ossTemplate);
}
}

53
blade-ops/blade-resource/src/main/java/org/springblade/resource/rule/oss/OssBuildRule.java

@ -0,0 +1,53 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.resource.rule.oss;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeSwitchComponent;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.oss.enums.OssEnum;
import org.springblade.resource.entity.Oss;
import org.springblade.resource.rule.context.OssContext;
/**
* Oss构建判断
*
* @author Chill
*/
@LiteflowComponent(id = "ossBuildRule", name = "OSS构建条件判断")
public class OssBuildRule extends NodeSwitchComponent {
@Override
public String processSwitch() {
OssContext contextBean = this.getContextBean(OssContext.class);
Oss oss = contextBean.getOss();
if (oss.getCategory() == OssEnum.MINIO.getCategory()) {
return "minioRule";
} else if (oss.getCategory() == OssEnum.QINIU.getCategory()) {
return "qiniuOssRule";
} else if (oss.getCategory() == OssEnum.ALI.getCategory()) {
return "aliOssRule";
} else if (oss.getCategory() == OssEnum.TENCENT.getCategory()) {
return "tencentCosRule";
} else if (oss.getCategory() == OssEnum.HUAWEI.getCategory()) {
return "huaweiObsRule";
} else if (oss.getCategory() == OssEnum.AMAZONS3.getCategory()) {
return "amazonS3Rule";
}
throw new ServiceException("未找到OSS配置");
}
}

42
blade-ops/blade-resource/src/main/java/org/springblade/resource/rule/oss/OssCacheRule.java

@ -0,0 +1,42 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.resource.rule.oss;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeSwitchComponent;
import org.springblade.resource.rule.context.OssContext;
/**
* Oss缓存判断
*
* @author Chill
*/
@LiteflowComponent(id = "ossCacheRule", name = "OSS缓存判断")
public class OssCacheRule extends NodeSwitchComponent {
@Override
public String processSwitch() {
OssContext contextBean = this.getContextBean(OssContext.class);
// 若判断配置已缓存则直接读取,否则进入下一步构建新数据
if (contextBean.getIsCached()) {
return "ossReadRule";
} else {
return "ossNewRule";
}
}
}

45
blade-ops/blade-resource/src/main/java/org/springblade/resource/rule/oss/OssDataRule.java

@ -0,0 +1,45 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.resource.rule.oss;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
import org.springblade.core.oss.props.OssProperties;
import org.springblade.core.oss.rule.BladeOssRule;
import org.springblade.resource.entity.Oss;
import org.springblade.resource.rule.context.OssContext;
/**
* OSS数据创建
*
* @author Chill
*/
@LiteflowComponent(id = "ossDataRule", name = "OSS数据创建")
public class OssDataRule extends NodeComponent {
@Override
public void process() throws Exception {
OssContext contextBean = this.getContextBean(OssContext.class);
Oss oss = contextBean.getOss();
OssProperties ossProperties = contextBean.getOssProperties();
// 若采用默认设置则开启多租户模式, 若是用户自定义oss则不开启
if (oss.getEndpoint().equals(ossProperties.getEndpoint()) && oss.getAccessKey().equals(ossProperties.getAccessKey()) && ossProperties.getTenantMode()) {
contextBean.setOssRule(new BladeOssRule(Boolean.TRUE));
} else {
contextBean.setOssRule(new BladeOssRule(Boolean.FALSE));
}
}
}

48
blade-ops/blade-resource/src/main/java/org/springblade/resource/rule/oss/OssReadRule.java

@ -0,0 +1,48 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.resource.rule.oss;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.oss.OssTemplate;
import org.springblade.core.tool.utils.Func;
import org.springblade.resource.entity.Oss;
import org.springblade.resource.rule.context.OssContext;
import java.util.Map;
/**
* OSS缓存读取校验
*
* @author Chill
*/
@LiteflowComponent(id = "ossReadRule", name = "OSS缓存读取校验")
public class OssReadRule extends NodeComponent {
@Override
public void process() throws Exception {
String tenantId = this.getRequestData();
OssContext contextBean = this.getContextBean(OssContext.class);
Map<String, Oss> ossPool = contextBean.getOssPool();
Map<String, OssTemplate> templatePool = contextBean.getTemplatePool();
Oss ossCached = ossPool.get(tenantId);
OssTemplate template = templatePool.get(tenantId);
if (Func.hasEmpty(template, ossCached)) {
throw new ServiceException("OSS缓存读取失败!");
}
}
}

42
blade-ops/blade-resource/src/main/java/org/springblade/resource/rule/oss/OssTemplateRule.java

@ -0,0 +1,42 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.resource.rule.oss;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.oss.OssTemplate;
import org.springblade.core.tool.utils.Func;
import org.springblade.resource.rule.context.OssContext;
/**
* OSS接口读取校验
*
* @author Chill
*/
@LiteflowComponent(id = "ossTemplateRule", name = "OSS接口读取校验")
public class OssTemplateRule extends NodeComponent {
@Override
public void process() throws Exception {
OssContext contextBean = this.getContextBean(OssContext.class);
OssTemplate ossTemplate = contextBean.getOssTemplate();
if (Func.isEmpty(ossTemplate)) {
throw new ServiceException("OSS接口读取失败!");
}
}
}

52
blade-ops/blade-resource/src/main/java/org/springblade/resource/rule/oss/PreOssRule.java

@ -0,0 +1,52 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.resource.rule.oss;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
import org.springblade.core.oss.OssTemplate;
import org.springblade.core.tool.utils.Func;
import org.springblade.resource.entity.Oss;
import org.springblade.resource.rule.context.OssContext;
import java.util.Map;
/**
* Oss前置处理
*
* @author Chill
*/
@LiteflowComponent(id = "preOssRule", name = "OSS构建前置处理")
public class PreOssRule extends NodeComponent {
@Override
public void process() throws Exception {
String tenantId = this.getRequestData();
OssContext contextBean = this.getContextBean(OssContext.class);
Map<String, Oss> ossPool = contextBean.getOssPool();
Map<String, OssTemplate> templatePool = contextBean.getTemplatePool();
Oss oss = contextBean.getOss();
Oss ossCached = ossPool.get(tenantId);
OssTemplate template = templatePool.get(tenantId);
// 若为空或者不一致,则重新加载
if (Func.hasEmpty(template, ossCached) || !oss.getEndpoint().equals(ossCached.getEndpoint()) || !oss.getAccessKey().equals(ossCached.getAccessKey())) {
contextBean.setIsCached(Boolean.FALSE);
} else {
contextBean.setIsCached(Boolean.TRUE);
}
}
}

26
blade-ops/blade-resource/src/main/java/org/springblade/resource/builder/oss/QiniuOssBuilder.java → blade-ops/blade-resource/src/main/java/org/springblade/resource/rule/oss/QiniuOssRule.java

@ -14,29 +14,38 @@
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.resource.builder.oss;
package org.springblade.resource.rule.oss;
import com.qiniu.storage.BucketManager;
import com.qiniu.storage.Configuration;
import com.qiniu.storage.Region;
import com.qiniu.storage.UploadManager;
import com.qiniu.util.Auth;
import lombok.SneakyThrows;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
import org.springblade.core.oss.OssTemplate;
import org.springblade.core.oss.QiniuTemplate;
import org.springblade.core.oss.props.OssProperties;
import org.springblade.core.oss.rule.OssRule;
import org.springblade.resource.entity.Oss;
import org.springblade.resource.rule.context.OssContext;
/**
* 七牛云存储构建类
*
* @author Chill
*/
public class QiniuOssBuilder {
@LiteflowComponent(id = "qiniuOssRule", name = "七牛OSS构建")
public class QiniuOssRule extends NodeComponent {
@Override
public void process() throws Exception {
// 获取上下文
OssContext contextBean = this.getContextBean(OssContext.class);
Oss oss = contextBean.getOss();
OssRule ossRule = contextBean.getOssRule();
@SneakyThrows
public static OssTemplate template(Oss oss, OssRule ossRule) {
// 创建配置类
OssProperties ossProperties = new OssProperties();
ossProperties.setEndpoint(oss.getEndpoint());
@ -48,7 +57,10 @@ public class QiniuOssBuilder {
Auth auth = Auth.create(oss.getAccessKey(), oss.getSecretKey());
UploadManager uploadManager = new UploadManager(cfg);
BucketManager bucketManager = new BucketManager(auth, cfg);
return new QiniuTemplate(auth, uploadManager, bucketManager, ossProperties, ossRule);
}
OssTemplate ossTemplate = new QiniuTemplate(auth, uploadManager, bucketManager, ossProperties, ossRule);
// 设置上下文
contextBean.setOssTemplate(ossTemplate);
}
}

27
blade-ops/blade-resource/src/main/java/org/springblade/resource/builder/oss/TencentCosBuilder.java → blade-ops/blade-resource/src/main/java/org/springblade/resource/rule/oss/TencentCosRule.java

@ -14,29 +14,37 @@
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.resource.builder.oss;
package org.springblade.resource.rule.oss;
import com.qcloud.cos.COSClient;
import com.qcloud.cos.ClientConfig;
import com.qcloud.cos.auth.BasicCOSCredentials;
import com.qcloud.cos.auth.COSCredentials;
import com.qcloud.cos.region.Region;
import lombok.SneakyThrows;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
import org.springblade.core.oss.OssTemplate;
import org.springblade.core.oss.TencentCosTemplate;
import org.springblade.core.oss.props.OssProperties;
import org.springblade.core.oss.rule.OssRule;
import org.springblade.core.oss.TencentCosTemplate;
import org.springblade.resource.entity.Oss;
import org.springblade.resource.rule.context.OssContext;
/**
* 腾讯云存储构建类
*
* @author Chill
*/
public class TencentCosBuilder {
@LiteflowComponent(id = "tencentCosRule", name = "腾讯云OSS构建")
public class TencentCosRule extends NodeComponent {
@Override
public void process() throws Exception {
// 获取上下文
OssContext contextBean = this.getContextBean(OssContext.class);
Oss oss = contextBean.getOss();
OssRule ossRule = contextBean.getOssRule();
@SneakyThrows
public static OssTemplate template(Oss oss, OssRule ossRule) {
// 创建配置类
OssProperties ossProperties = new OssProperties();
ossProperties.setEndpoint(oss.getEndpoint());
@ -60,7 +68,10 @@ public class TencentCosBuilder {
// 设置从连接池中获取连接的超时时间(单位:毫秒),默认不超时。
clientConfig.setConnectionRequestTimeout(1000);
COSClient cosClient = new COSClient(credentials, clientConfig);
return new TencentCosTemplate(cosClient, ossProperties, ossRule);
}
OssTemplate ossTemplate = new TencentCosTemplate(cosClient, ossProperties, ossRule);
// 设置上下文
contextBean.setOssTemplate(ossTemplate);
}
}

28
blade-ops/blade-resource/src/main/java/org/springblade/resource/builder/sms/AliSmsBuilder.java → blade-ops/blade-resource/src/main/java/org/springblade/resource/rule/sms/AliSmsRule.java

@ -14,28 +14,36 @@
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.resource.builder.sms;
package org.springblade.resource.rule.sms;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
import lombok.SneakyThrows;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
import org.springblade.core.redis.cache.BladeRedis;
import org.springblade.core.sms.SmsTemplate;
import org.springblade.core.sms.AliSmsTemplate;
import org.springblade.core.sms.SmsTemplate;
import org.springblade.core.sms.props.SmsProperties;
import org.springblade.resource.entity.Sms;
import org.springblade.resource.rule.context.SmsContext;
/**
* 阿里云短信构建类
*
* @author Chill
*/
public class AliSmsBuilder {
@LiteflowComponent(id = "aliSmsRule", name = "阿里SMS构建")
public class AliSmsRule extends NodeComponent {
@Override
public void process() throws Exception {
// 获取上下文
SmsContext contextBean = this.getContextBean(SmsContext.class);
Sms sms = contextBean.getSms();
BladeRedis bladeRedis = contextBean.getBladeRedis();
@SneakyThrows
public static SmsTemplate template(Sms sms, BladeRedis bladeRedis) {
SmsProperties smsProperties = new SmsProperties();
smsProperties.setTemplateId(sms.getTemplateId());
smsProperties.setAccessKey(sms.getAccessKey());
@ -44,7 +52,11 @@ public class AliSmsBuilder {
smsProperties.setSignName(sms.getSignName());
IClientProfile profile = DefaultProfile.getProfile(smsProperties.getRegionId(), smsProperties.getAccessKey(), smsProperties.getSecretKey());
IAcsClient acsClient = new DefaultAcsClient(profile);
return new AliSmsTemplate(smsProperties, acsClient, bladeRedis);
}
SmsTemplate smsTemplate = new AliSmsTemplate(smsProperties, acsClient, bladeRedis);
// 设置上下文
contextBean.setSmsTemplate(smsTemplate);
}
}

52
blade-ops/blade-resource/src/main/java/org/springblade/resource/rule/sms/CacheSmsRule.java

@ -0,0 +1,52 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.resource.rule.sms;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.sms.SmsTemplate;
import org.springblade.core.tool.utils.Func;
import org.springblade.resource.entity.Sms;
import org.springblade.resource.rule.context.SmsContext;
import java.util.Map;
/**
* 缓存短信构建类
*
* @author Chill
*/
@LiteflowComponent(id = "cacheSmsRule", name = "缓存SMS构建")
public class CacheSmsRule extends NodeComponent {
@Override
public void process() throws Exception {
// 获取上下文
String tenantId = this.getRequestData();
SmsContext contextBean = this.getContextBean(SmsContext.class);
Map<String, Sms> smsPool = contextBean.getSmsPool();
Map<String, SmsTemplate> templatePool = contextBean.getTemplatePool();
Sms smsCached = smsPool.get(tenantId);
SmsTemplate template = templatePool.get(tenantId);
if (Func.hasEmpty(template, smsCached)) {
throw new ServiceException("SMS缓存读取失败!");
}
}
}

58
blade-ops/blade-resource/src/main/java/org/springblade/resource/rule/sms/FinallySmsRule.java

@ -0,0 +1,58 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.resource.rule.sms;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.sms.SmsTemplate;
import org.springblade.core.tool.utils.Func;
import org.springblade.resource.entity.Sms;
import org.springblade.resource.rule.context.SmsContext;
import java.util.Map;
/**
* Sms后置处理
*
* @author Chill
*/
@LiteflowComponent(id = "finallySmsRule", name = "SMS构建后置处理")
public class FinallySmsRule extends NodeComponent {
@Override
public void process() throws Exception {
String tenantId = this.getRequestData();
SmsContext contextBean = this.getContextBean(SmsContext.class);
Map<String, Sms> smsPool = contextBean.getSmsPool();
Map<String, SmsTemplate> templatePool = contextBean.getTemplatePool();
if (contextBean.getIsCached()) {
SmsTemplate template = templatePool.get(tenantId);
contextBean.setSmsTemplate(template);
} else {
Sms sms = contextBean.getSms();
SmsTemplate template = contextBean.getSmsTemplate();
if (Func.hasEmpty(template, sms)) {
throw new ServiceException("SMS接口读取失败!");
} else {
templatePool.put(tenantId, template);
smsPool.put(tenantId, sms);
}
}
}
}

52
blade-ops/blade-resource/src/main/java/org/springblade/resource/rule/sms/PreSmsRule.java

@ -0,0 +1,52 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.resource.rule.sms;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
import org.springblade.core.sms.SmsTemplate;
import org.springblade.core.tool.utils.Func;
import org.springblade.resource.entity.Sms;
import org.springblade.resource.rule.context.SmsContext;
import java.util.Map;
/**
* Sms前置处理
*
* @author Chill
*/
@LiteflowComponent(id = "preSmsRule", name = "SMS构建前置处理")
public class PreSmsRule extends NodeComponent {
@Override
public void process() throws Exception {
String tenantId = this.getRequestData();
SmsContext contextBean = this.getContextBean(SmsContext.class);
Map<String, Sms> smsPool = contextBean.getSmsPool();
Map<String, SmsTemplate> templatePool = contextBean.getTemplatePool();
Sms sms = contextBean.getSms();
Sms smsCached = smsPool.get(tenantId);
SmsTemplate template = templatePool.get(tenantId);
// 若为空或者不一致,则重新加载
if (Func.hasEmpty(template, smsCached) || !sms.getTemplateId().equals(smsCached.getTemplateId()) || !sms.getAccessKey().equals(smsCached.getAccessKey())) {
contextBean.setIsCached(Boolean.FALSE);
} else {
contextBean.setIsCached(Boolean.TRUE);
}
}
}

27
blade-ops/blade-resource/src/main/java/org/springblade/resource/builder/sms/QiniuSmsBuilder.java → blade-ops/blade-resource/src/main/java/org/springblade/resource/rule/sms/QiniuSmsRule.java

@ -14,26 +14,34 @@
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.resource.builder.sms;
package org.springblade.resource.rule.sms;
import com.qiniu.sms.SmsManager;
import com.qiniu.util.Auth;
import lombok.SneakyThrows;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
import org.springblade.core.redis.cache.BladeRedis;
import org.springblade.core.sms.QiniuSmsTemplate;
import org.springblade.core.sms.SmsTemplate;
import org.springblade.core.sms.props.SmsProperties;
import org.springblade.core.sms.QiniuSmsTemplate;
import org.springblade.resource.entity.Sms;
import org.springblade.resource.rule.context.SmsContext;
/**
* 七牛云短信构建类
*
* @author Chill
*/
public class QiniuSmsBuilder {
@LiteflowComponent(id = "qiniuSmsRule", name = "七牛SMS构建")
public class QiniuSmsRule extends NodeComponent {
@Override
public void process() throws Exception {
// 获取上下文
SmsContext contextBean = this.getContextBean(SmsContext.class);
Sms sms = contextBean.getSms();
BladeRedis bladeRedis = contextBean.getBladeRedis();
@SneakyThrows
public static SmsTemplate template(Sms sms, BladeRedis bladeRedis) {
SmsProperties smsProperties = new SmsProperties();
smsProperties.setTemplateId(sms.getTemplateId());
smsProperties.setAccessKey(sms.getAccessKey());
@ -41,7 +49,10 @@ public class QiniuSmsBuilder {
smsProperties.setSignName(sms.getSignName());
Auth auth = Auth.create(smsProperties.getAccessKey(), smsProperties.getSecretKey());
SmsManager smsManager = new SmsManager(auth);
return new QiniuSmsTemplate(smsProperties, smsManager, bladeRedis);
}
SmsTemplate smsTemplate = new QiniuSmsTemplate(smsProperties, smsManager, bladeRedis);
// 设置上下文
contextBean.setSmsTemplate(smsTemplate);
}
}

53
blade-ops/blade-resource/src/main/java/org/springblade/resource/rule/sms/SmsBuildRule.java

@ -0,0 +1,53 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.resource.rule.sms;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeSwitchComponent;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.sms.enums.SmsEnum;
import org.springblade.resource.entity.Sms;
import org.springblade.resource.rule.context.SmsContext;
/**
* Sms构建判断
*
* @author Chill
*/
@LiteflowComponent(id = "smsBuildRule", name = "SMS构建条件判断")
public class SmsBuildRule extends NodeSwitchComponent {
@Override
public String processSwitch() {
SmsContext contextBean = this.getContextBean(SmsContext.class);
Sms sms = contextBean.getSms();
if (contextBean.getIsCached()) {
return "cacheSmsRule";
} else if (sms.getCategory() == SmsEnum.YUNPIAN.getCategory()) {
return "yunpianSmsRule";
} else if (sms.getCategory() == SmsEnum.QINIU.getCategory()) {
return "qiniuSmsRule";
} else if (sms.getCategory() == SmsEnum.ALI.getCategory()) {
return "aliSmsRule";
} else if (sms.getCategory() == SmsEnum.TENCENT.getCategory()) {
return "tencentSmsRule";
}
throw new ServiceException("未找到SMS配置");
}
}

27
blade-ops/blade-resource/src/main/java/org/springblade/resource/builder/sms/TencentSmsBuilder.java → blade-ops/blade-resource/src/main/java/org/springblade/resource/rule/sms/TencentSmsRule.java

@ -14,33 +14,44 @@
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.resource.builder.sms;
package org.springblade.resource.rule.sms;
import com.github.qcloudsms.SmsMultiSender;
import lombok.SneakyThrows;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
import org.springblade.core.redis.cache.BladeRedis;
import org.springblade.core.sms.SmsTemplate;
import org.springblade.core.sms.props.SmsProperties;
import org.springblade.core.sms.TencentSmsTemplate;
import org.springblade.core.sms.props.SmsProperties;
import org.springblade.core.tool.utils.Func;
import org.springblade.resource.entity.Sms;
import org.springblade.resource.rule.context.SmsContext;
/**
* 腾讯云短信构建类
*
* @author Chill
*/
public class TencentSmsBuilder {
@LiteflowComponent(id = "tencentSmsRule", name = "腾讯SMS构建")
public class TencentSmsRule extends NodeComponent {
@Override
public void process() throws Exception {
// 获取上下文
SmsContext contextBean = this.getContextBean(SmsContext.class);
Sms sms = contextBean.getSms();
BladeRedis bladeRedis = contextBean.getBladeRedis();
@SneakyThrows
public static SmsTemplate template(Sms sms, BladeRedis bladeRedis) {
SmsProperties smsProperties = new SmsProperties();
smsProperties.setTemplateId(sms.getTemplateId());
smsProperties.setAccessKey(sms.getAccessKey());
smsProperties.setSecretKey(sms.getSecretKey());
smsProperties.setSignName(sms.getSignName());
SmsMultiSender smsSender = new SmsMultiSender(Func.toInt(smsProperties.getAccessKey()), sms.getSecretKey());
return new TencentSmsTemplate(smsProperties, smsSender, bladeRedis);
}
SmsTemplate smsTemplate = new TencentSmsTemplate(smsProperties, smsSender, bladeRedis);
// 设置上下文
contextBean.setSmsTemplate(smsTemplate);
}
}

27
blade-ops/blade-resource/src/main/java/org/springblade/resource/builder/sms/YunpianSmsBuilder.java → blade-ops/blade-resource/src/main/java/org/springblade/resource/rule/sms/YunpianSmsRule.java

@ -14,31 +14,42 @@
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.resource.builder.sms;
package org.springblade.resource.rule.sms;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
import com.yunpian.sdk.YunpianClient;
import lombok.SneakyThrows;
import org.springblade.core.redis.cache.BladeRedis;
import org.springblade.core.sms.SmsTemplate;
import org.springblade.core.sms.props.SmsProperties;
import org.springblade.core.sms.YunpianSmsTemplate;
import org.springblade.core.sms.props.SmsProperties;
import org.springblade.resource.entity.Sms;
import org.springblade.resource.rule.context.SmsContext;
/**
* 云片短信构建类
*
* @author Chill
*/
public class YunpianSmsBuilder {
@LiteflowComponent(id = "yunpianSmsRule", name = "云片SMS构建")
public class YunpianSmsRule extends NodeComponent {
@Override
public void process() throws Exception {
// 获取上下文
SmsContext contextBean = this.getContextBean(SmsContext.class);
Sms sms = contextBean.getSms();
BladeRedis bladeRedis = contextBean.getBladeRedis();
@SneakyThrows
public static SmsTemplate template(Sms sms, BladeRedis bladeRedis) {
SmsProperties smsProperties = new SmsProperties();
smsProperties.setTemplateId(sms.getTemplateId());
smsProperties.setAccessKey(sms.getAccessKey());
smsProperties.setSignName(sms.getSignName());
YunpianClient client = new YunpianClient(smsProperties.getAccessKey()).init();
return new YunpianSmsTemplate(smsProperties, client, bladeRedis);
}
SmsTemplate smsTemplate = new YunpianSmsTemplate(smsProperties, client, bladeRedis);
// 设置上下文
contextBean.setSmsTemplate(smsTemplate);
}
}

12
blade-ops/blade-resource/src/main/resources/application.yml

@ -2,12 +2,22 @@
server:
port: 8010
#默认对象存储配置
#oss默认配置
oss:
#开启oss配置
enabled: true
#开启oss类型
#minio、s3、qiniu、alioss、huaweiobs、tencentcos
name: minio
#租户模式
tenant-mode: true
#oss服务地址
endpoint: http://192.168.2.100:9000
#minio转换服务地址,用于内网上传后将返回地址改为转换的外网地址
transform-endpoint: http://192.168.2.100:9000
#访问key
access-key: minio
#密钥key
secret-key: 123123123
#存储桶
bucket-name: bladex

BIN
blade-ops/blade-resource/src/main/resources/liteflow/oss.el.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 229 KiB

24
blade-ops/blade-resource/src/main/resources/liteflow/oss.el.xml

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<flow>
<chain name="ossChain">
THEN(
preOssRule,
SWITCH(ossCacheRule).TO(
ossReadRule,
THEN(
ossDataRule,
SWITCH(ossBuildRule).TO(
aliOssRule,
amazonS3Rule,
huaweiObsRule,
minioRule,
qiniuOssRule,
tencentCosRule
),
ossTemplateRule
).id("ossNewRule")
),
finallyOssRule
);
</chain>
</flow>

BIN
blade-ops/blade-resource/src/main/resources/liteflow/sms.el.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 139 KiB

16
blade-ops/blade-resource/src/main/resources/liteflow/sms.el.xml

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<flow>
<chain name="smsChain">
THEN(
preSmsRule,
SWITCH(smsBuildRule).TO(
aliSmsRule,
qiniuSmsRule,
tencentSmsRule,
yunpianSmsRule,
cacheSmsRule
),
finallySmsRule
);
</chain>
</flow>

2
blade-ops/blade-swagger/pom.xml

@ -5,7 +5,7 @@
<parent>
<artifactId>blade-ops</artifactId>
<groupId>org.springblade</groupId>
<version>3.1.1.RELEASE</version>
<version>3.2.0.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>

4
blade-ops/pom.xml

@ -5,13 +5,13 @@
<parent>
<artifactId>BladeX</artifactId>
<groupId>org.springblade</groupId>
<version>3.1.1.RELEASE</version>
<version>3.2.0.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>blade-ops</artifactId>
<name>${project.artifactId}</name>
<version>3.1.1.RELEASE</version>
<version>3.2.0.RELEASE</version>
<packaging>pom</packaging>
<modules>

4
blade-plugin-api/README.md

@ -11,5 +11,5 @@
- 有需求的商业用户就能在应用市场更方便更省钱更省时地拿到所需要的功能模块
- 在应用市场您可以找到各种拓展增强后的插件与应用,也可以很方便地集成到BladeX架构内
- 我们的愿景是打造一个庞大的生态圈,相信在用户与官方的默契配合下,BladeX可以走得更远
- 市场地址:https://bladex.vip/#/market
- 入驻须知:https://bladex.vip/#/market/notice
- 市场地址:https://bladex.cn/#/market
- 入驻须知:https://bladex.cn/#/market/notice

4
blade-plugin-api/pom.xml

@ -5,13 +5,13 @@
<parent>
<artifactId>BladeX</artifactId>
<groupId>org.springblade</groupId>
<version>3.1.1.RELEASE</version>
<version>3.2.0.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>blade-plugin-api</artifactId>
<name>${project.artifactId}</name>
<version>3.1.1.RELEASE</version>
<version>3.2.0.RELEASE</version>
<packaging>pom</packaging>
<build>

4
blade-plugin/README.md

@ -11,5 +11,5 @@
- 有需求的商业用户就能在应用市场更方便更省钱更省时地拿到所需要的功能模块
- 在应用市场您可以找到各种拓展增强后的插件与应用,也可以很方便地集成到BladeX架构内
- 我们的愿景是打造一个庞大的生态圈,相信在用户与官方的默契配合下,BladeX可以走得更远
- 市场地址:https://bladex.vip/#/market
- 入驻须知:https://bladex.vip/#/market/notice
- 市场地址:https://bladex.cn/#/market
- 入驻须知:https://bladex.cn/#/market/notice

4
blade-plugin/pom.xml

@ -5,13 +5,13 @@
<parent>
<artifactId>BladeX</artifactId>
<groupId>org.springblade</groupId>
<version>3.1.1.RELEASE</version>
<version>3.2.0.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>blade-plugin</artifactId>
<name>${project.artifactId}</name>
<version>3.1.1.RELEASE</version>
<version>3.2.0.RELEASE</version>
<packaging>pom</packaging>
</project>

2
blade-service-api/blade-desk-api/pom.xml

@ -5,7 +5,7 @@
<parent>
<artifactId>blade-service-api</artifactId>
<groupId>org.springblade</groupId>
<version>3.1.1.RELEASE</version>
<version>3.2.0.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>

2
blade-service-api/blade-dict-api/pom.xml

@ -5,7 +5,7 @@
<parent>
<artifactId>blade-service-api</artifactId>
<groupId>org.springblade</groupId>
<version>3.1.1.RELEASE</version>
<version>3.2.0.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>

2
blade-service-api/blade-scope-api/pom.xml

@ -5,7 +5,7 @@
<parent>
<artifactId>blade-service-api</artifactId>
<groupId>org.springblade</groupId>
<version>3.1.1.RELEASE</version>
<version>3.2.0.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>

2
blade-service-api/blade-system-api/pom.xml

@ -5,7 +5,7 @@
<parent>
<artifactId>blade-service-api</artifactId>
<groupId>org.springblade</groupId>
<version>3.1.1.RELEASE</version>
<version>3.2.0.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>

2
blade-service-api/blade-user-api/pom.xml

@ -5,7 +5,7 @@
<parent>
<artifactId>blade-service-api</artifactId>
<groupId>org.springblade</groupId>
<version>3.1.1.RELEASE</version>
<version>3.2.0.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>

4
blade-service-api/pom.xml

@ -5,13 +5,13 @@
<parent>
<artifactId>BladeX</artifactId>
<groupId>org.springblade</groupId>
<version>3.1.1.RELEASE</version>
<version>3.2.0.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>blade-service-api</artifactId>
<name>${project.artifactId}</name>
<version>3.1.1.RELEASE</version>
<version>3.2.0.RELEASE</version>
<packaging>pom</packaging>
<description>BladeX 微服务API集合</description>

2
blade-service/blade-desk/pom.xml

@ -6,7 +6,7 @@
<parent>
<groupId>org.springblade</groupId>
<artifactId>blade-service</artifactId>
<version>3.1.1.RELEASE</version>
<version>3.2.0.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>

3
blade-service/blade-desk/src/main/java/org/springblade/desk/controller/NoticeController.java

@ -24,6 +24,8 @@ import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.mp.support.BladePage;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.secure.annotation.PreAuth;
import org.springblade.core.secure.constant.AuthConstant;
import org.springblade.core.tenant.annotation.TenantDS;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
@ -42,6 +44,7 @@ import java.util.Map;
*
* @author Chill
*/
@PreAuth(AuthConstant.HAS_CRYPTO)
@TenantDS
@RestController
@RequestMapping("notice")

6
blade-service/blade-system/pom.xml

@ -5,7 +5,7 @@
<parent>
<artifactId>blade-service</artifactId>
<groupId>org.springblade</groupId>
<version>3.1.1.RELEASE</version>
<version>3.2.0.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@ -27,6 +27,10 @@
<groupId>org.springblade</groupId>
<artifactId>blade-starter-swagger</artifactId>
</dependency>
<dependency>
<groupId>org.springblade</groupId>
<artifactId>blade-starter-liteflow</artifactId>
</dependency>
<dependency>
<groupId>org.springblade</groupId>
<artifactId>blade-system-api</artifactId>

91
blade-service/blade-system/src/main/java/org/springblade/system/rule/TenantContext.java

@ -0,0 +1,91 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.system.rule;
import lombok.Data;
import org.springblade.core.tenant.TenantId;
import org.springblade.system.entity.*;
import org.springblade.system.service.IDictBizService;
import org.springblade.system.service.IMenuService;
import org.springblade.system.service.ITenantService;
import java.util.List;
/**
* 租户上下文
*
* @author Chill
*/
@Data
public class TenantContext {
/**
* 菜单业务
*/
private IMenuService menuService;
/**
* 字典业务
*/
private IDictBizService dictBizService;
/**
* 租户业务
*/
private ITenantService tenantService;
/**
* 租户ID生成器
*/
private TenantId tenantIdGenerator;
/**
* 租户
*/
private Tenant tenant;
/**
* 角色
*/
private Role role;
/**
* 角色菜单合集
*/
private List<RoleMenu> roleMenuList;
/**
* 机构
*/
private Dept dept;
/**
* 岗位
*/
private Post post;
/**
* 业务字典合集
*/
private List<DictBiz> dictBizList;
/**
* 用户
*/
private User user;
}

53
blade-service/blade-system/src/main/java/org/springblade/system/rule/TenantDeptRule.java

@ -0,0 +1,53 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.system.rule;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
import org.springblade.core.tool.constant.BladeConstant;
import org.springblade.system.entity.Dept;
import org.springblade.system.entity.Tenant;
/**
* 租户机构构建
*
* @author Chill
*/
@LiteflowComponent(id = "tenantDeptRule", name = "租户机构构建")
public class TenantDeptRule extends NodeComponent {
@Override
public void process() throws Exception {
// 获取上下文
TenantContext contextBean = this.getFirstContextBean();
Tenant tenant = contextBean.getTenant();
// 新建租户对应的默认部门
Dept dept = new Dept();
dept.setTenantId(tenant.getTenantId());
dept.setParentId(BladeConstant.TOP_PARENT_ID);
dept.setAncestors(String.valueOf(BladeConstant.TOP_PARENT_ID));
dept.setDeptName(tenant.getTenantName());
dept.setFullName(tenant.getTenantName());
dept.setDeptCategory(1);
dept.setSort(2);
dept.setIsDeleted(BladeConstant.DB_NOT_DELETED);
// 设置上下文
contextBean.setDept(dept);
}
}

81
blade-service/blade-system/src/main/java/org/springblade/system/rule/TenantDictBizRule.java

@ -0,0 +1,81 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.system.rule;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
import org.springblade.core.tool.constant.BladeConstant;
import org.springblade.system.entity.DictBiz;
import org.springblade.system.entity.Tenant;
import org.springblade.system.service.IDictBizService;
import java.util.LinkedList;
import java.util.List;
/**
* 租户业务字典构建
*
* @author Chill
*/
@LiteflowComponent(id = "tenantDictBizRule", name = "租户业务字典构建")
public class TenantDictBizRule extends NodeComponent {
@Override
public void process() throws Exception {
// 获取上下文
TenantContext contextBean = this.getFirstContextBean();
Tenant tenant = contextBean.getTenant();
IDictBizService dictBizService = contextBean.getDictBizService();
// 新建租户对应的默认业务字典
LinkedList<DictBiz> dictBizs = new LinkedList<>();
List<DictBiz> dictBizList = getDictBizs(dictBizService, tenant.getTenantId(), dictBizs);
// 设置上下文
contextBean.setDictBizList(dictBizList);
}
private List<DictBiz> getDictBizs(IDictBizService dictBizService, String tenantId, LinkedList<DictBiz> dictBizs) {
List<DictBiz> dictBizList = dictBizService.list(Wrappers.<DictBiz>query().lambda().eq(DictBiz::getParentId, BladeConstant.TOP_PARENT_ID).eq(DictBiz::getIsDeleted, BladeConstant.DB_NOT_DELETED));
dictBizList.forEach(dictBiz -> {
Long oldParentId = dictBiz.getId();
Long newParentId = IdWorker.getId();
dictBiz.setId(newParentId);
dictBiz.setTenantId(tenantId);
dictBizs.add(dictBiz);
recursionDictBiz(dictBizService, tenantId, oldParentId, newParentId, dictBizs);
});
return dictBizs;
}
private void recursionDictBiz(IDictBizService dictBizService, String tenantId, Long oldParentId, Long newParentId, LinkedList<DictBiz> dictBizs) {
List<DictBiz> dictBizList = dictBizService.list(Wrappers.<DictBiz>query().lambda().eq(DictBiz::getParentId, oldParentId).eq(DictBiz::getIsDeleted, BladeConstant.DB_NOT_DELETED));
dictBizList.forEach(dictBiz -> {
Long oldSubParentId = dictBiz.getId();
Long newSubParentId = IdWorker.getId();
dictBiz.setId(newSubParentId);
dictBiz.setTenantId(tenantId);
dictBiz.setParentId(newParentId);
dictBizs.add(dictBiz);
recursionDictBiz(dictBizService, tenantId, oldSubParentId, newSubParentId, dictBizs);
});
}
}

49
blade-service/blade-system/src/main/java/org/springblade/system/rule/TenantPostRule.java

@ -0,0 +1,49 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.system.rule;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
import org.springblade.system.entity.Post;
import org.springblade.system.entity.Tenant;
/**
* 租户岗位构建
*
* @author Chill
*/
@LiteflowComponent(id = "tenantPostRule", name = "租户岗位构建")
public class TenantPostRule extends NodeComponent {
@Override
public void process() throws Exception {
// 获取上下文
TenantContext contextBean = this.getFirstContextBean();
Tenant tenant = contextBean.getTenant();
// 新建租户对应的默认岗位
Post post = new Post();
post.setTenantId(tenant.getTenantId());
post.setCategory(1);
post.setPostCode("ceo");
post.setPostName("首席执行官");
post.setSort(1);
// 设置上下文
contextBean.setPost(post);
}
}

79
blade-service/blade-system/src/main/java/org/springblade/system/rule/TenantRoleMenuRule.java

@ -0,0 +1,79 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.system.rule;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
import org.springblade.system.cache.ParamCache;
import org.springblade.core.tool.constant.BladeConstant;
import org.springblade.core.tool.utils.Func;
import org.springblade.system.entity.Menu;
import org.springblade.system.entity.RoleMenu;
import org.springblade.system.service.IMenuService;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import static org.springblade.common.constant.TenantConstant.ACCOUNT_MENU_CODE_KEY;
import static org.springblade.common.constant.TenantConstant.MENU_CODES;
/**
* 租户角色菜单构建
*
* @author Chill
*/
@LiteflowComponent(id = "tenantRoleMenuRule", name = "租户角色菜单构建")
public class TenantRoleMenuRule extends NodeComponent {
@Override
public void process() throws Exception {
// 获取上下文
TenantContext contextBean = this.getFirstContextBean();
IMenuService menuService = contextBean.getMenuService();
// 新建租户对应的角色菜单权限
LinkedList<Menu> userMenus = new LinkedList<>();
// 获取参数配置的默认菜单集合,逗号隔开
List<String> menuCodes = Func.toStrList(ParamCache.getValue(ACCOUNT_MENU_CODE_KEY));
List<Menu> menus = getMenus(menuService, (!menuCodes.isEmpty() ? menuCodes : MENU_CODES), userMenus);
List<RoleMenu> roleMenuList = new ArrayList<>();
menus.forEach(menu -> {
RoleMenu roleMenu = new RoleMenu();
roleMenu.setMenuId(menu.getId());
roleMenuList.add(roleMenu);
});
// 设置上下文
contextBean.setRoleMenuList(roleMenuList);
}
private List<Menu> getMenus(IMenuService menuService, List<String> codes, LinkedList<Menu> menus) {
codes.forEach(code -> {
Menu menu = menuService.getOne(Wrappers.<Menu>query().lambda().eq(Menu::getCode, code).eq(Menu::getIsDeleted, BladeConstant.DB_NOT_DELETED));
if (menu != null) {
menus.add(menu);
recursionMenu(menuService, menu.getId(), menus);
}
});
return menus;
}
private void recursionMenu(IMenuService menuService, Long parentId, LinkedList<Menu> menus) {
List<Menu> menuList = menuService.list(Wrappers.<Menu>query().lambda().eq(Menu::getParentId, parentId).eq(Menu::getIsDeleted, BladeConstant.DB_NOT_DELETED));
menus.addAll(menuList);
menuList.forEach(menu -> recursionMenu(menuService, menu.getId(), menus));
}
}

48
blade-service/blade-system/src/main/java/org/springblade/system/rule/TenantRoleRule.java

@ -0,0 +1,48 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.system.rule;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
import org.springblade.core.tool.constant.BladeConstant;
import org.springblade.system.entity.Role;
import org.springblade.system.entity.Tenant;
/**
* 租户角色构建
*
* @author Chill
*/
@LiteflowComponent(id = "tenantRoleRule", name = "租户角色构建")
public class TenantRoleRule extends NodeComponent {
@Override
public void process() throws Exception {
// 获取上下文
TenantContext contextBean = this.getFirstContextBean();
Tenant tenant = contextBean.getTenant();
// 新建租户对应的默认角色
Role role = new Role();
role.setTenantId(tenant.getTenantId());
role.setParentId(BladeConstant.TOP_PARENT_ID);
role.setRoleName("管理员");
role.setRoleAlias("admin");
role.setSort(2);
role.setIsDeleted(BladeConstant.DB_NOT_DELETED);
// 设置上下文
contextBean.setRole(role);
}
}

71
blade-service/blade-system/src/main/java/org/springblade/system/rule/TenantRule.java

@ -0,0 +1,71 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.system.rule;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
import org.springblade.system.cache.ParamCache;
import org.springblade.core.tenant.TenantId;
import org.springblade.core.tool.constant.BladeConstant;
import org.springblade.core.tool.utils.Func;
import org.springblade.system.entity.Tenant;
import org.springblade.system.service.ITenantService;
import java.util.List;
import java.util.stream.Collectors;
import static org.springblade.common.constant.TenantConstant.ACCOUNT_NUMBER_KEY;
import static org.springblade.common.constant.TenantConstant.DEFAULT_ACCOUNT_NUMBER;
/**
* 租户构建
*
* @author Chill
*/
@LiteflowComponent(id = "tenantRule", name = "租户构建")
public class TenantRule extends NodeComponent {
@Override
public void process() throws Exception {
// 获取上下文
TenantContext contextBean = this.getFirstContextBean();
Tenant tenant = contextBean.getTenant();
TenantId tenantIdGenerator = contextBean.getTenantIdGenerator();
ITenantService tenantService = contextBean.getTenantService();
// 获取租户ID
List<Tenant> tenants = tenantService.list(Wrappers.<Tenant>query().lambda().eq(Tenant::getIsDeleted, BladeConstant.DB_NOT_DELETED));
List<String> codes = tenants.stream().map(Tenant::getTenantId).collect(Collectors.toList());
String tenantId = getTenantId(tenantIdGenerator, codes);
tenant.setTenantId(tenantId);
// 获取参数配置的账号额度
int accountNumber = Func.toInt(ParamCache.getValue(ACCOUNT_NUMBER_KEY), DEFAULT_ACCOUNT_NUMBER);
tenant.setAccountNumber(accountNumber);
// 设置上下文
contextBean.setTenant(tenant);
}
private String getTenantId(TenantId tenantIdGenerator, List<String> codes) {
String code = tenantIdGenerator.generate();
if (codes.contains(code)) {
return getTenantId(tenantIdGenerator, codes);
}
return code;
}
}

63
blade-service/blade-system/src/main/java/org/springblade/system/rule/TenantUserRule.java

@ -0,0 +1,63 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.system.rule;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
import org.springblade.core.tool.constant.BladeConstant;
import org.springblade.core.tool.utils.Func;
import org.springblade.system.cache.ParamCache;
import org.springblade.system.entity.Tenant;
import org.springblade.system.entity.User;
import org.springblade.system.enums.UserEnum;
import java.util.Date;
import static org.springblade.common.constant.TenantConstant.DEFAULT_PASSWORD;
import static org.springblade.common.constant.TenantConstant.PASSWORD_KEY;
/**
* 租户用户构建
*
* @author Chill
*/
@LiteflowComponent(id = "tenantUserRule", name = "租户用户构建")
public class TenantUserRule extends NodeComponent {
@Override
public void process() throws Exception {
// 获取上下文
TenantContext contextBean = this.getFirstContextBean();
Tenant tenant = contextBean.getTenant();
// 新建租户对应的默认管理用户
User user = new User();
user.setTenantId(tenant.getTenantId());
user.setName("admin");
user.setRealName("admin");
user.setAccount("admin");
// 获取参数配置的密码
String password = Func.toStr(ParamCache.getValue(PASSWORD_KEY), DEFAULT_PASSWORD);
user.setPassword(password);
user.setBirthday(new Date());
user.setSex(1);
user.setUserType(UserEnum.WEB.getCategory());
user.setIsDeleted(BladeConstant.DB_NOT_DELETED);
// 设置上下文
contextBean.setUser(user);
}
}

194
blade-service/blade-system/src/main/java/org/springblade/system/service/impl/TenantServiceImpl.java

@ -17,37 +17,31 @@
package org.springblade.system.service.impl;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.flow.LiteflowResponse;
import lombok.AllArgsConstructor;
import org.springblade.core.cache.utils.CacheUtil;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.core.tenant.TenantId;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.constant.BladeConstant;
import org.springblade.core.tool.jackson.JsonUtil;
import org.springblade.core.tool.support.Kv;
import org.springblade.core.tool.utils.DesUtil;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.StringUtil;
import org.springblade.system.cache.ParamCache;
import org.springblade.system.entity.*;
import org.springblade.system.mapper.TenantMapper;
import org.springblade.system.rule.TenantContext;
import org.springblade.system.service.*;
import org.springblade.system.entity.User;
import org.springblade.system.enums.UserEnum;
import org.springblade.system.feign.IUserClient;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;
import static org.springblade.common.constant.TenantConstant.*;
import static org.springblade.common.constant.TenantConstant.DES_KEY;
import static org.springblade.core.cache.constant.CacheConstant.SYS_CACHE;
/**
@ -59,14 +53,15 @@ import static org.springblade.core.cache.constant.CacheConstant.SYS_CACHE;
@AllArgsConstructor
public class TenantServiceImpl extends BaseServiceImpl<TenantMapper, Tenant> implements ITenantService {
private final TenantId tenantId;
private final TenantId tenantIdGenerator;
private final IRoleService roleService;
private final IMenuService menuService;
private final IDeptService deptService;
private final IPostService postService;
private final IRoleMenuService roleMenuService;
private final IDictBizService dictBizService;
private final IUserClient userClient;
private final IUserService userService;
private final FlowExecutor flowExecutor;
@Override
public IPage<Tenant> selectTenantPage(IPage<Tenant> page, Tenant tenant) {
@ -82,84 +77,43 @@ public class TenantServiceImpl extends BaseServiceImpl<TenantMapper, Tenant> imp
@Transactional(rollbackFor = Exception.class)
public boolean submitTenant(Tenant tenant) {
if (Func.isEmpty(tenant.getId())) {
List<Tenant> tenants = baseMapper.selectList(Wrappers.<Tenant>query().lambda().eq(Tenant::getIsDeleted, BladeConstant.DB_NOT_DELETED));
List<String> codes = tenants.stream().map(Tenant::getTenantId).collect(Collectors.toList());
String tenantId = getTenantId(codes);
tenant.setTenantId(tenantId);
// 获取参数配置的账号额度
int accountNumber = Func.toInt(ParamCache.getValue(ACCOUNT_NUMBER_KEY), DEFAULT_ACCOUNT_NUMBER);
tenant.setAccountNumber(accountNumber);
// 新建租户对应的默认角色
Role role = new Role();
role.setTenantId(tenantId);
role.setParentId(BladeConstant.TOP_PARENT_ID);
role.setRoleName("管理员");
role.setRoleAlias("admin");
role.setSort(2);
role.setIsDeleted(BladeConstant.DB_NOT_DELETED);
roleService.save(role);
// 新建租户对应的角色菜单权限
LinkedList<Menu> userMenus = new LinkedList<>();
// 获取参数配置的默认菜单集合,逗号隔开
List<String> menuCodes = Func.toStrList(ParamCache.getValue(ACCOUNT_MENU_CODE_KEY));
List<Menu> menus = getMenus((menuCodes.size() > 0 ? menuCodes : MENU_CODES), userMenus);
List<RoleMenu> roleMenus = new ArrayList<>();
menus.forEach(menu -> {
RoleMenu roleMenu = new RoleMenu();
roleMenu.setMenuId(menu.getId());
roleMenu.setRoleId(role.getId());
roleMenus.add(roleMenu);
});
roleMenuService.saveBatch(roleMenus);
// 新建租户对应的默认部门
Dept dept = new Dept();
dept.setTenantId(tenantId);
dept.setParentId(BladeConstant.TOP_PARENT_ID);
dept.setAncestors(String.valueOf(BladeConstant.TOP_PARENT_ID));
dept.setDeptName(tenant.getTenantName());
dept.setFullName(tenant.getTenantName());
dept.setDeptCategory(1);
dept.setSort(2);
dept.setIsDeleted(BladeConstant.DB_NOT_DELETED);
deptService.save(dept);
// 新建租户对应的默认岗位
Post post = new Post();
post.setTenantId(tenantId);
post.setCategory(1);
post.setPostCode("ceo");
post.setPostName("首席执行官");
post.setSort(1);
postService.save(post);
// 新建租户对应的默认业务字典
LinkedList<DictBiz> dictBizs = new LinkedList<>();
List<DictBiz> dictBizList = getDictBizs(tenantId, dictBizs);
dictBizService.saveBatch(dictBizList);
// 新建租户对应的默认管理用户
User user = new User();
user.setTenantId(tenantId);
user.setName("admin");
user.setRealName("admin");
user.setAccount("admin");
// 获取参数配置的密码
String password = Func.toStr(ParamCache.getValue(PASSWORD_KEY), DEFAULT_PASSWORD);
user.setPassword(password);
user.setRoleId(String.valueOf(role.getId()));
user.setDeptId(String.valueOf(dept.getId()));
user.setPostId(String.valueOf(post.getId()));
user.setBirthday(new Date());
user.setSex(1);
user.setUserType(UserEnum.WEB.getCategory());
user.setIsDeleted(BladeConstant.DB_NOT_DELETED);
boolean temp = super.saveOrUpdate(tenant);
R<Boolean> result = userClient.saveUser(user);
if (!result.isSuccess()) {
throw new ServiceException(result.getMsg());
TenantContext tenantContext = new TenantContext();
tenantContext.setTenantIdGenerator(tenantIdGenerator);
tenantContext.setTenant(tenant);
tenantContext.setMenuService(menuService);
tenantContext.setDictBizService(dictBizService);
tenantContext.setTenantService(this);
LiteflowResponse resp = flowExecutor.execute2Resp("tenantChain", null, tenantContext);
if (resp.isSuccess()) {
Role role = tenantContext.getRole();
roleService.save(role);
Long roleId = role.getId();
List<RoleMenu> roleMenuList = tenantContext.getRoleMenuList();
roleMenuList.forEach(roleMenu -> roleMenu.setRoleId(roleId));
roleMenuService.saveBatch(roleMenuList);
Dept dept = tenantContext.getDept();
deptService.save(dept);
Post post = tenantContext.getPost();
postService.save(post);
List<DictBiz> dictBizList = tenantContext.getDictBizList();
dictBizService.saveBatch(dictBizList);
User user = tenantContext.getUser();
user.setRoleId(String.valueOf(role.getId()));
user.setDeptId(String.valueOf(dept.getId()));
user.setPostId(String.valueOf(post.getId()));
userService.submit(user);
} else {
throw new ServiceException("租户业务数据构建异常");
}
return temp;
} else {
CacheUtil.clear(SYS_CACHE, tenant.getTenantId());
return super.saveOrUpdate(tenant);
}
CacheUtil.clear(SYS_CACHE, tenant.getTenantId());
return super.saveOrUpdate(tenant);
}
@Override
@ -172,11 +126,8 @@ public class TenantServiceImpl extends BaseServiceImpl<TenantMapper, Tenant> imp
throw new ServiceException("不可删除管理租户!");
}
boolean tenantTemp = this.deleteLogic(ids);
R<Boolean> result = userClient.removeUser(StringUtil.join(tenantIds));
if (!result.isSuccess()) {
throw new ServiceException(result.getMsg());
}
return tenantTemp;
boolean userTemp = userService.remove(Wrappers.<User>query().lambda().in(User::getTenantId, tenantIds));
return tenantTemp && userTemp;
}
@Override
@ -198,61 +149,4 @@ public class TenantServiceImpl extends BaseServiceImpl<TenantMapper, Tenant> imp
return true;
}
@Override
public List<Tenant> selectTenantpageown() {
return baseMapper.selectTenantpageown();
}
private String getTenantId(List<String> codes) {
String code = tenantId.generate();
if (codes.contains(code)) {
return getTenantId(codes);
}
return code;
}
private List<Menu> getMenus(List<String> codes, LinkedList<Menu> menus) {
codes.forEach(code -> {
Menu menu = menuService.getOne(Wrappers.<Menu>query().lambda().eq(Menu::getCode, code).eq(Menu::getIsDeleted, BladeConstant.DB_NOT_DELETED));
if (menu != null) {
menus.add(menu);
recursionMenu(menu.getId(), menus);
}
});
return menus;
}
private void recursionMenu(Long parentId, LinkedList<Menu> menus) {
List<Menu> menuList = menuService.list(Wrappers.<Menu>query().lambda().eq(Menu::getParentId, parentId).eq(Menu::getIsDeleted, BladeConstant.DB_NOT_DELETED));
menus.addAll(menuList);
menuList.forEach(menu -> recursionMenu(menu.getId(), menus));
}
private List<DictBiz> getDictBizs(String tenantId, LinkedList<DictBiz> dictBizs) {
List<DictBiz> dictBizList = dictBizService.list(Wrappers.<DictBiz>query().lambda().eq(DictBiz::getParentId, BladeConstant.TOP_PARENT_ID).eq(DictBiz::getIsDeleted, BladeConstant.DB_NOT_DELETED));
dictBizList.forEach(dictBiz -> {
Long oldParentId = dictBiz.getId();
Long newParentId = IdWorker.getId();
dictBiz.setId(newParentId);
dictBiz.setTenantId(tenantId);
dictBizs.add(dictBiz);
recursionDictBiz(tenantId, oldParentId, newParentId, dictBizs);
});
return dictBizs;
}
private void recursionDictBiz(String tenantId, Long oldParentId, Long newParentId, LinkedList<DictBiz> dictBizs) {
List<DictBiz> dictBizList = dictBizService.list(Wrappers.<DictBiz>query().lambda().eq(DictBiz::getParentId, oldParentId).eq(DictBiz::getIsDeleted, BladeConstant.DB_NOT_DELETED));
dictBizList.forEach(dictBiz -> {
Long oldSubParentId = dictBiz.getId();
Long newSubParentId = IdWorker.getId();
dictBiz.setId(newSubParentId);
dictBiz.setTenantId(tenantId);
dictBiz.setParentId(newParentId);
dictBizs.add(dictBiz);
recursionDictBiz(tenantId, oldSubParentId, newSubParentId, dictBizs);
});
}
}

BIN
blade-service/blade-system/src/main/resources/liteflow/tenant.el.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 KiB

16
blade-service/blade-system/src/main/resources/liteflow/tenant.el.xml

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<flow>
<chain name="tenantChain">
THEN(
tenantRule,
WHEN(
tenantRoleRule,
tenantRoleMenuRule,
tenantDeptRule,
tenantPostRule,
tenantDictBizRule,
tenantUserRule
)
);
</chain>
</flow>

4
blade-service/pom.xml

@ -6,14 +6,14 @@
<parent>
<groupId>org.springblade</groupId>
<artifactId>BladeX</artifactId>
<version>3.1.1.RELEASE</version>
<version>3.2.0.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>blade-service</artifactId>
<name>${project.artifactId}</name>
<version>3.1.1.RELEASE</version>
<version>3.2.0.RELEASE</version>
<packaging>pom</packaging>
<description>BladeX 微服务集合</description>

6
doc/nacos/blade.yaml

@ -68,10 +68,10 @@ knife4j:
swagger:
title: BladeX 接口文档系统
description: BladeX 接口文档系统
version: 3.1.1.RELEASE
version: 3.2.0.RELEASE
license: Powered By BladeX
license-url: https://bladex.vip
terms-of-service-url: https://bladex.vip
license-url: https://bladex.cn
terms-of-service-url: https://bladex.cn
contact:
name: 翼宿
email: bladejava@qq.com

4
pom.xml

@ -5,11 +5,11 @@
<groupId>org.springblade</groupId>
<artifactId>BladeX</artifactId>
<version>3.1.1.RELEASE</version>
<version>3.2.0.RELEASE</version>
<packaging>pom</packaging>
<properties>
<bladex.project.version>3.1.1.RELEASE</bladex.project.version>
<bladex.project.version>3.2.0.RELEASE</bladex.project.version>
<java.version>1.8</java.version>
<maven.plugin.version>3.8.1</maven.plugin.version>

2
script/docker/app/.env

@ -1,2 +1,2 @@
REGISTER=192.168.0.188/blade
TAG=3.1.1.RELEASE
TAG=3.2.0.RELEASE

48
script/docker/skywalking/docker-compose.yml

@ -0,0 +1,48 @@
version: '3.3'
services:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:7.17.11
container_name: elasticsearch
restart: always
ports:
- 9200:9200
- 9300:9300
environment:
- discovery.type=single-node
- TZ=Asia/Shanghai
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms1024m -Xmx1024m"
ulimits:
memlock:
soft: -1
hard: -1
skywalking-oap:
image: docker.io/apache/skywalking-oap-server:9.5.0
container_name: skywalking-oap
depends_on:
- elasticsearch
restart: always
ports:
- 11800:11800
- 12800:12800
environment:
SW_CORE_RECORD_DATA_TTL: 15
SW_CORE_METRICS_DATA_TTL: 15
SW_STORAGE: elasticsearch
SW_STORAGE_ES_CLUSTER_NODES: elasticsearch:9200
SW_ENABLE_UPDATE_UI_TEMPLATE: "true"
TZ: Asia/Shanghai
JAVA_OPTS: "-Xms2048m -Xmx2048m"
skywalking-ui:
image: docker.io/apache/skywalking-ui:9.5.0
container_name: skywalking-ui
depends_on:
- skywalking-oap
links:
- skywalking-oap
restart: always
ports:
- 8880:8080
environment:
SW_OAP_ADDRESS: http://skywalking-oap:12800
Loading…
Cancel
Save