init
This commit is contained in:
45
src/test/java/org/springblade/test/BladeTest.java
Normal file
45
src/test/java/org/springblade/test/BladeTest.java
Normal file
@@ -0,0 +1,45 @@
|
||||
package org.springblade.test;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springblade.core.test.BladeBootTest;
|
||||
import org.springblade.core.test.BladeSpringExtension;
|
||||
import org.springblade.core.tool.utils.StringUtil;
|
||||
import org.springblade.flow.engine.entity.FlowModel;
|
||||
import org.springblade.flow.engine.service.FlowEngineService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Blade单元测试
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
@ExtendWith(BladeSpringExtension.class)
|
||||
@BladeBootTest(appName = "blade-runner", enableLoader = true)
|
||||
public class BladeTest {
|
||||
|
||||
@Autowired
|
||||
private FlowEngineService service;
|
||||
|
||||
//@Test
|
||||
public void contextLoads() {
|
||||
System.out.println("=====数据迁移启动=====");
|
||||
|
||||
// 获取 ACT_DE_MODEL 表需要转换的数据
|
||||
List<FlowModel> list = service.list();
|
||||
// 循环转换
|
||||
list.forEach(flowModel -> {
|
||||
if (StringUtil.isBlank(flowModel.getModelEditorXml())) {
|
||||
service.update(Wrappers.<FlowModel>lambdaUpdate()
|
||||
.set(FlowModel::getModelEditorXml, new String(service.getModelEditorXML(flowModel)))
|
||||
.ge(FlowModel::getId, flowModel.getId())
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
System.out.println("=====数据迁移完毕=====");
|
||||
}
|
||||
|
||||
}
|
||||
54
src/test/java/org/springblade/test/CryptoKeyGenerator.java
Normal file
54
src/test/java/org/springblade/test/CryptoKeyGenerator.java
Normal file
@@ -0,0 +1,54 @@
|
||||
package org.springblade.test;
|
||||
|
||||
import org.springblade.core.tool.utils.*;
|
||||
|
||||
/**
|
||||
* Key生成器
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
public class CryptoKeyGenerator {
|
||||
|
||||
public static void main(String[] args) {
|
||||
String cryptoKey = AesUtil.genAesKey();
|
||||
String aesKey = AesUtil.genAesKey();
|
||||
String desKey = DesUtil.genDesKey();
|
||||
|
||||
System.out.println("=========== blade.token.crypto-key 配置如下 ============");
|
||||
System.out.println("#blade配置\n" +
|
||||
"blade:\n" +
|
||||
" token:\n" +
|
||||
" crypto-key: " + cryptoKey);
|
||||
System.out.println("=======================================================");
|
||||
|
||||
System.out.println(StringPool.EMPTY);
|
||||
System.out.println("============ blade.key.crypto-key 配置如下 =============");
|
||||
System.out.println("#blade配置\n" +
|
||||
"blade:\n" +
|
||||
" key:\n" +
|
||||
" enabled: true\n" +
|
||||
" crypto-key: " + cryptoKey);
|
||||
System.out.println("=======================================================");
|
||||
|
||||
System.out.println(StringPool.EMPTY);
|
||||
System.out.println("============== blade.api.crypto 配置如下 ===============");
|
||||
System.out.println("#blade配置\n" +
|
||||
"blade:\n" +
|
||||
" api:\n" +
|
||||
" crypto:\n" +
|
||||
" enabled: true\n" +
|
||||
" aes-key: " + aesKey + "\n" +
|
||||
" des-key: " + desKey);
|
||||
System.out.println("=======================================================");
|
||||
|
||||
System.out.println(StringPool.EMPTY);
|
||||
System.out.println("============== saber crypto.js 配置如下 ===============");
|
||||
System.out.println("export default class crypto {\n" +
|
||||
" static cryptoKey = '" + cryptoKey + "';\n" +
|
||||
" static aesKey = '" + aesKey + "';\n" +
|
||||
" static desKey = '" + desKey + "';\n" +
|
||||
"}");
|
||||
System.out.println("=======================================================");
|
||||
}
|
||||
|
||||
}
|
||||
42
src/test/java/org/springblade/test/EncryptKeyGenerator.java
Normal file
42
src/test/java/org/springblade/test/EncryptKeyGenerator.java
Normal file
@@ -0,0 +1,42 @@
|
||||
package org.springblade.test;
|
||||
|
||||
import org.bouncycastle.crypto.AsymmetricCipherKeyPair;
|
||||
import org.springblade.core.tool.utils.*;
|
||||
|
||||
/**
|
||||
* 加密密钥生成器
|
||||
*
|
||||
* @author BladeX
|
||||
*/
|
||||
public class EncryptKeyGenerator {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// 生成对称加密密钥
|
||||
String aesKey = AesUtil.genAesKey();
|
||||
String desKey = DesUtil.genDesKey();
|
||||
String sm4Key = SM4Util.generateKey();
|
||||
|
||||
// 生成SM2非对称加密密钥对
|
||||
AsymmetricCipherKeyPair sm2KeyPair = SM2Util.generateKeyPair();
|
||||
String sm2PublicKey = SM2Util.getPublicKeyString(sm2KeyPair);
|
||||
String sm2PrivateKey = SM2Util.getPrivateKeyString(sm2KeyPair);
|
||||
|
||||
System.out.println("\n================== Encryption Keys Generated ==================\n");
|
||||
|
||||
System.out.println("[Symmetric Keys / 对称加密密钥]");
|
||||
System.out.println();
|
||||
System.out.println("AES-256-Key: " + aesKey);
|
||||
System.out.println("DES-Key: " + desKey);
|
||||
System.out.println("SM4-Key(国密): " + sm4Key);
|
||||
|
||||
System.out.println("\n----------------------------------------------------------------\n");
|
||||
|
||||
System.out.println("[Asymmetric Keys / 非对称加密密钥]");
|
||||
System.out.println();
|
||||
System.out.println("SM2-PublicKey(国密公钥): " + sm2PublicKey);
|
||||
System.out.println("SM2-PrivateKey(国密私钥): " + sm2PrivateKey);
|
||||
|
||||
System.out.println("\n================================================================\n");
|
||||
}
|
||||
|
||||
}
|
||||
22
src/test/java/org/springblade/test/SignKeyGenerator.java
Normal file
22
src/test/java/org/springblade/test/SignKeyGenerator.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package org.springblade.test;
|
||||
|
||||
import org.springblade.core.tool.utils.RandomType;
|
||||
import org.springblade.core.tool.utils.StringUtil;
|
||||
|
||||
/**
|
||||
* signKey生成器
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
public class SignKeyGenerator {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("=========== blade.token.sign-key 配置如下 ==============");
|
||||
System.out.println("#blade配置\n" +
|
||||
"blade:\n" +
|
||||
" token:\n" +
|
||||
" sign-key: " + StringUtil.random(32, RandomType.ALL) );
|
||||
System.out.println("=======================================================");
|
||||
}
|
||||
|
||||
}
|
||||
46
src/test/java/org/springblade/test/Sm2KeyGenerator.java
Normal file
46
src/test/java/org/springblade/test/Sm2KeyGenerator.java
Normal file
@@ -0,0 +1,46 @@
|
||||
package org.springblade.test;
|
||||
|
||||
import org.bouncycastle.crypto.AsymmetricCipherKeyPair;
|
||||
import org.bouncycastle.util.encoders.Hex;
|
||||
import org.springblade.core.tool.utils.SM2Util;
|
||||
import org.springblade.core.tool.utils.StringPool;
|
||||
|
||||
/**
|
||||
* 国密算法生成器
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
public class Sm2KeyGenerator {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("================ blade.oauth2 配置如下 =================");
|
||||
AsymmetricCipherKeyPair keyPair = SM2Util.generateKeyPair();
|
||||
String publicKey = SM2Util.getPublicKeyString(keyPair);
|
||||
String privateKey = SM2Util.getPrivateKeyString(keyPair);
|
||||
System.out.println("#blade配置 \n" +
|
||||
"blade:\n" +
|
||||
" oauth2:\n" +
|
||||
" enabled: true\n" +
|
||||
" public-key: " + publicKey + "\n" +
|
||||
" private-key: " + privateKey);
|
||||
System.out.println("=======================================================");
|
||||
System.out.println(StringPool.EMPTY);
|
||||
System.out.println("============== saber website.js 配置如下 ===============");
|
||||
System.out.println("//saber配置\n" +
|
||||
"oauth2: {\n" +
|
||||
" publicKey: '" + publicKey + "',\n" +
|
||||
"}");
|
||||
System.out.println("=======================================================");
|
||||
System.out.println(StringPool.EMPTY);
|
||||
System.out.println("============== 密码:[admin] 加密流程如下 ================");
|
||||
String password = "admin";
|
||||
byte[] encryptedData = SM2Util.encrypt(password, publicKey);
|
||||
String decryptedText = SM2Util.decrypt(encryptedData, privateKey);
|
||||
System.out.println("加密前: " + password);
|
||||
System.out.println("加密后: " + Hex.toHexString(encryptedData));
|
||||
System.out.println("解密后: " + decryptedText);
|
||||
System.out.println("请注意: 此密文为前端加密后调用token接口的密码参数");
|
||||
System.out.println("=======================================================");
|
||||
}
|
||||
|
||||
}
|
||||
93
src/test/java/org/springblade/test/code/CodeGenerator.java
Normal file
93
src/test/java/org/springblade/test/code/CodeGenerator.java
Normal file
@@ -0,0 +1,93 @@
|
||||
/**
|
||||
* BladeX Commercial License Agreement
|
||||
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||
* <p>
|
||||
* Use of this software is governed by the Commercial License Agreement
|
||||
* obtained after purchasing a license from BladeX.
|
||||
* <p>
|
||||
* 1. This software is for development use only under a valid license
|
||||
* from BladeX.
|
||||
* <p>
|
||||
* 2. Redistribution of this software's source code to any third party
|
||||
* without a commercial license is strictly prohibited.
|
||||
* <p>
|
||||
* 3. Licensees may copyright their own code but cannot use segments
|
||||
* from this software for such purposes. Copyright of this software
|
||||
* remains with BladeX.
|
||||
* <p>
|
||||
* Using this software signifies agreement to this License, and the software
|
||||
* must not be used for illegal purposes.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||
* not liable for any claims arising from secondary or illegal development.
|
||||
* <p>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
package org.springblade.test.code;
|
||||
|
||||
|
||||
import org.springblade.develop.constant.DevelopConstant;
|
||||
import org.springblade.develop.support.BladeFastCodeGenerator;
|
||||
|
||||
/**
|
||||
* 代码生成器
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
public class CodeGenerator {
|
||||
|
||||
/**
|
||||
* 代码生成的系统类型(Boot/Cloud)
|
||||
*/
|
||||
public static String SYSTEM_NAME = DevelopConstant.BOOT_NAME;
|
||||
/**
|
||||
* 代码生成的模块名
|
||||
*/
|
||||
public static String CODE_NAME = "自定义模块";
|
||||
/**
|
||||
* 代码所在服务名
|
||||
*/
|
||||
public static String SERVICE_NAME = "blade-desk";
|
||||
/**
|
||||
* 代码生成的包名
|
||||
*/
|
||||
public static String PACKAGE_NAME = "org.springblade.desk";
|
||||
/**
|
||||
* 需要去掉的表前缀
|
||||
*/
|
||||
public static String[] TABLE_PREFIX = {"blade_"};
|
||||
/**
|
||||
* 需要生成的表名(两者只能取其一)
|
||||
*/
|
||||
public static String[] INCLUDE_TABLES = {"blade_notice"};
|
||||
/**
|
||||
* 需要排除的表名(两者只能取其一)
|
||||
*/
|
||||
public static String[] EXCLUDE_TABLES = {};
|
||||
/**
|
||||
* 是否包含基础业务字段
|
||||
*/
|
||||
public static Boolean HAS_SUPER_ENTITY = Boolean.TRUE;
|
||||
/**
|
||||
* 基础业务字段
|
||||
*/
|
||||
public static String[] SUPER_ENTITY_COLUMNS = {"id", "create_time", "create_user", "create_dept", "update_time", "update_user", "status", "is_deleted"};
|
||||
|
||||
/**
|
||||
* RUN THIS
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
BladeFastCodeGenerator generator = new BladeFastCodeGenerator();
|
||||
generator.setSystemName(SYSTEM_NAME);
|
||||
generator.setCodeName(CODE_NAME);
|
||||
generator.setServiceName(SERVICE_NAME);
|
||||
generator.setPackageName(PACKAGE_NAME);
|
||||
generator.setTablePrefix(TABLE_PREFIX);
|
||||
generator.setIncludeTables(INCLUDE_TABLES);
|
||||
generator.setExcludeTables(EXCLUDE_TABLES);
|
||||
generator.setHasSuperEntity(HAS_SUPER_ENTITY);
|
||||
generator.setSuperEntityColumns(SUPER_ENTITY_COLUMNS);
|
||||
generator.run();
|
||||
}
|
||||
|
||||
}
|
||||
22
src/test/java/org/springblade/test/http/OsChina.java
Normal file
22
src/test/java/org/springblade/test/http/OsChina.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package org.springblade.test.http;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.springblade.core.http.CssQuery;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class OsChina {
|
||||
|
||||
@CssQuery(value = "head > title", attr = "text")
|
||||
private String title;
|
||||
|
||||
@CssQuery(value = "#v_news .page .news", inner = true)
|
||||
private List<VNews> vNews;
|
||||
|
||||
@CssQuery(value = ".blog-container .blog-list div", inner = true)
|
||||
private List<VBlog> vBlogList;
|
||||
|
||||
}
|
||||
38
src/test/java/org/springblade/test/http/OsChinaTest.java
Normal file
38
src/test/java/org/springblade/test/http/OsChinaTest.java
Normal file
@@ -0,0 +1,38 @@
|
||||
package org.springblade.test.http;
|
||||
|
||||
import org.springblade.core.http.HttpRequest;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class OsChinaTest {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// 同步,异常返回 null
|
||||
OsChina oschina = HttpRequest.get("https://www.oschina.net")
|
||||
.execute()
|
||||
.onSuccess(responseSpec -> responseSpec.asDomValue(OsChina.class));
|
||||
if (oschina == null) {
|
||||
return;
|
||||
}
|
||||
System.out.println(oschina.getTitle());
|
||||
|
||||
System.out.println("热门新闻");
|
||||
|
||||
List<VNews> vNews = oschina.getVNews();
|
||||
for (VNews vNew : vNews) {
|
||||
System.out.println("title:\t" + vNew.getTitle());
|
||||
System.out.println("href:\t" + vNew.getHref());
|
||||
System.out.println("时间:\t" + vNew.getDate());
|
||||
}
|
||||
|
||||
System.out.println("热门博客");
|
||||
List<VBlog> vBlogList = oschina.getVBlogList();
|
||||
for (VBlog vBlog : vBlogList) {
|
||||
System.out.println("title:\t" + vBlog.getTitle());
|
||||
System.out.println("href:\t" + vBlog.getHref());
|
||||
System.out.println("阅读数:\t" + vBlog.getRead());
|
||||
System.out.println("评价数:\t" + vBlog.getPing());
|
||||
System.out.println("点赞数:\t" + vBlog.getZhan());
|
||||
}
|
||||
}
|
||||
}
|
||||
30
src/test/java/org/springblade/test/http/VBlog.java
Normal file
30
src/test/java/org/springblade/test/http/VBlog.java
Normal file
@@ -0,0 +1,30 @@
|
||||
package org.springblade.test.http;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.springblade.core.http.CssQuery;
|
||||
|
||||
/**
|
||||
* 热门博客
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class VBlog {
|
||||
|
||||
@CssQuery(value = "a", attr = "title")
|
||||
private String title;
|
||||
|
||||
@CssQuery(value = "a", attr = "href")
|
||||
private String href;
|
||||
|
||||
//1341阅/9评/4赞
|
||||
@CssQuery(value = "span", attr = "text", regex = "^\\d+")
|
||||
private Integer read;
|
||||
|
||||
@CssQuery(value = "span", attr = "text", regex = "(\\d*).*/(\\d*).*/(\\d*).*", regexGroup = 2)
|
||||
private Integer ping;
|
||||
|
||||
@CssQuery(value = "span", attr = "text", regex = "(\\d*).*/(\\d*).*/(\\d*).*", regexGroup = 3)
|
||||
private Integer zhan;
|
||||
|
||||
}
|
||||
24
src/test/java/org/springblade/test/http/VNews.java
Normal file
24
src/test/java/org/springblade/test/http/VNews.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package org.springblade.test.http;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.springblade.core.http.CssQuery;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
public class VNews {
|
||||
|
||||
@CssQuery(value = "a", attr = "title")
|
||||
private String title;
|
||||
|
||||
@CssQuery(value = "a", attr = "href")
|
||||
private String href;
|
||||
|
||||
@CssQuery(value = ".news-date", attr = "text")
|
||||
@DateTimeFormat(pattern = "MM/dd")
|
||||
private Date date;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
* BladeX Commercial License Agreement
|
||||
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||
* <p>
|
||||
* Use of this software is governed by the Commercial License Agreement
|
||||
* obtained after purchasing a license from BladeX.
|
||||
* <p>
|
||||
* 1. This software is for development use only under a valid license
|
||||
* from BladeX.
|
||||
* <p>
|
||||
* 2. Redistribution of this software's source code to any third party
|
||||
* without a commercial license is strictly prohibited.
|
||||
* <p>
|
||||
* 3. Licensees may copyright their own code but cannot use segments
|
||||
* from this software for such purposes. Copyright of this software
|
||||
* remains with BladeX.
|
||||
* <p>
|
||||
* Using this software signifies agreement to this License, and the software
|
||||
* must not be used for illegal purposes.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||
* not liable for any claims arising from secondary or illegal development.
|
||||
* <p>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
package org.springblade.test.launch;
|
||||
|
||||
import org.springblade.core.auto.service.AutoService;
|
||||
import org.springblade.core.launch.service.LauncherService;
|
||||
import org.springblade.core.launch.utils.PropsUtil;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* 启动参数拓展
|
||||
*
|
||||
* @author smallchil
|
||||
*/
|
||||
@AutoService(LauncherService.class)
|
||||
public class LauncherTestServiceImpl implements LauncherService {
|
||||
|
||||
@Override
|
||||
public void launcher(SpringApplicationBuilder builder, String appName, String profile, boolean isLocalDev) {
|
||||
Properties props = System.getProperties();
|
||||
PropsUtil.setProperty(props, "spring.datasource.dynamic.enabled", "false");
|
||||
}
|
||||
|
||||
}
|
||||
160
src/test/java/org/springblade/test/literule/LiteRuleTest.java
Normal file
160
src/test/java/org/springblade/test/literule/LiteRuleTest.java
Normal file
@@ -0,0 +1,160 @@
|
||||
package org.springblade.test.literule;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springblade.core.literule.engine.RuleEngineExecutor;
|
||||
import org.springblade.core.literule.provider.RuleConfig;
|
||||
import org.springblade.core.literule.provider.LiteRuleResponse;
|
||||
import org.springblade.core.test.BladeBootTest;
|
||||
import org.springblade.core.test.BladeSpringExtension;
|
||||
import org.springblade.test.literule.context.Address;
|
||||
import org.springblade.test.literule.context.OrderContext;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
/**
|
||||
* 规则引擎测试类
|
||||
* 提供完整的使用示例
|
||||
*
|
||||
* @author BladeX
|
||||
*/
|
||||
@Slf4j
|
||||
@ExtendWith(BladeSpringExtension.class)
|
||||
@BladeBootTest(appName = "blade-runner", enableLoader = true)
|
||||
public class LiteRuleTest {
|
||||
|
||||
@Autowired
|
||||
private RuleEngineExecutor ruleEngine;
|
||||
|
||||
/**
|
||||
* 主测试方法
|
||||
*/
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
// 测试成功场景
|
||||
testSuccessCase(ruleEngine);
|
||||
|
||||
// 测试失败场景
|
||||
testFailureCase(ruleEngine);
|
||||
|
||||
// 测试异步执行
|
||||
testAsyncExecution(ruleEngine);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试成功场景
|
||||
*/
|
||||
private static void testSuccessCase(RuleEngineExecutor ruleEngine) {
|
||||
log.info("=== [1] 开始测试:正常场景 ===");
|
||||
|
||||
// 构建上下文
|
||||
OrderContext context = OrderContext.builder()
|
||||
.orderId("ORD-001")
|
||||
.amount(new BigDecimal("1200"))
|
||||
.paymentType("ALIPAY")
|
||||
.shippingAddress(Address.builder()
|
||||
.country("China")
|
||||
.province("Guangdong")
|
||||
.city("Shenzhen")
|
||||
.detail("Nanshan District")
|
||||
.build())
|
||||
.build();
|
||||
|
||||
// 构建配置
|
||||
RuleConfig config = RuleConfig.builder()
|
||||
.enableTimeMonitor(true)
|
||||
.printExecutionTime(true)
|
||||
.enableLogging(true)
|
||||
.build();
|
||||
|
||||
// 执行规则链
|
||||
LiteRuleResponse<OrderContext> response = ruleEngine.execute(
|
||||
"orderChain",
|
||||
context,
|
||||
config
|
||||
);
|
||||
|
||||
// 处理响应
|
||||
log.info("[1.1] 规则链执行结果:{}", response.isSuccess() ? "成功" : "失败");
|
||||
log.info("[1.2] 规则链执行耗时:{}毫秒", response.getExecutionTime());
|
||||
log.info("[1.3] 订单状态:{}", response.getContext().getStatus());
|
||||
log.info("[1.4] 最终金额:{}", response.getContext().getAmount());
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试失败场景
|
||||
*/
|
||||
private static void testFailureCase(RuleEngineExecutor ruleEngine) {
|
||||
log.info("=== [2] 开始测试:失败场景 ===");
|
||||
|
||||
// 构建上下文(缺少必要字段)
|
||||
OrderContext context = OrderContext.builder()
|
||||
.orderId("") // 空订单ID
|
||||
.amount(new BigDecimal("-100")) // 负数金额
|
||||
.paymentType("UNKNOWN") // 未知支付方式
|
||||
.shippingAddress(Address.builder()
|
||||
.country("USA")
|
||||
.province("California")
|
||||
.city("San Francisco")
|
||||
.detail("Silicon Valley")
|
||||
.build())
|
||||
.build();
|
||||
|
||||
// 执行规则链
|
||||
LiteRuleResponse<OrderContext> response = ruleEngine.execute(
|
||||
"orderChain",
|
||||
context
|
||||
);
|
||||
|
||||
// 处理响应
|
||||
log.info("[2.1] 规则链执行结果:{}", response.isSuccess() ? "成功" : "失败");
|
||||
log.info("[2.2] 错误信息:{}", response.getContext().getErrorMessages());
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试异步执行
|
||||
*/
|
||||
private static void testAsyncExecution(RuleEngineExecutor ruleEngine) {
|
||||
log.info("=== [3] 开始测试:异步执行 ===");
|
||||
|
||||
// 构建上下文
|
||||
OrderContext context = OrderContext.builder()
|
||||
.orderId("ORD-002")
|
||||
.amount(new BigDecimal("800"))
|
||||
.paymentType("WECHAT")
|
||||
.shippingAddress(Address.builder()
|
||||
.country("USA")
|
||||
.province("California")
|
||||
.city("San Francisco")
|
||||
.detail("Silicon Valley")
|
||||
.build())
|
||||
.build();
|
||||
|
||||
// 异步执行规则链
|
||||
ruleEngine.executeAsync(
|
||||
"orderChain",
|
||||
context,
|
||||
Executors.newSingleThreadExecutor()
|
||||
).thenAccept(response -> {
|
||||
log.info("[3.1] 异步规则链执行完成");
|
||||
log.info("[3.2] 规则链执行结果:{}", response.isSuccess() ? "成功" : "失败");
|
||||
log.info("[3.3] 规则链执行耗时:{}毫秒", response.getExecutionTime());
|
||||
log.info("[3.4] 订单状态:{}", response.getContext().getStatus());
|
||||
log.info("[3.5] 最终金额:{}", response.getContext().getAmount());
|
||||
});
|
||||
|
||||
// 等待异步执行完成
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package org.springblade.test.literule.builder;
|
||||
|
||||
import org.springblade.core.literule.annotation.RuleEngineComponent;
|
||||
import org.springblade.core.literule.builder.LiteRule;
|
||||
import org.springblade.core.literule.builder.RuleBuilder;
|
||||
import org.springblade.core.literule.builder.chain.RuleChain;
|
||||
|
||||
/**
|
||||
* 订单处理规则链构建器
|
||||
*/
|
||||
@RuleEngineComponent(id = "orderChain")
|
||||
public class OrderRuleBuilder implements RuleBuilder {
|
||||
@Override
|
||||
public RuleChain build() {
|
||||
// 创建支付处理分支规则
|
||||
RuleChain paymentRule = LiteRule.SWITCH("paymentSwitchRule")
|
||||
.TO("alipayRule", "wechatPayRule", "bankPayRule")
|
||||
.build();
|
||||
|
||||
// 创建完整规则链
|
||||
return LiteRule.THEN("orderValidateRule", "orderAmountRule")
|
||||
.THEN(paymentRule)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package org.springblade.test.literule.context;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 地址实体
|
||||
*
|
||||
* @author BladeX
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class Address {
|
||||
private String country;
|
||||
private String province;
|
||||
private String city;
|
||||
private String detail;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package org.springblade.test.literule.context;
|
||||
|
||||
import lombok.*;
|
||||
import org.springblade.core.literule.core.RuleContextComponent;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 订单上下文
|
||||
*
|
||||
* @author BladeX
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class OrderContext extends RuleContextComponent {
|
||||
private String orderId;
|
||||
private BigDecimal amount;
|
||||
private String paymentType;
|
||||
private String status;
|
||||
private Address shippingAddress;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package org.springblade.test.literule.rule;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springblade.core.literule.annotation.LiteRuleComponent;
|
||||
import org.springblade.core.literule.core.RuleComponent;
|
||||
import org.springblade.test.literule.context.OrderContext;
|
||||
|
||||
/**
|
||||
* AlipayRule
|
||||
*
|
||||
* @author BladeX
|
||||
*/
|
||||
@Slf4j
|
||||
@LiteRuleComponent(id = "alipayRule")
|
||||
public class AlipayRule extends RuleComponent {
|
||||
|
||||
@Override
|
||||
protected void process() {
|
||||
OrderContext context = getContextBean(OrderContext.class);
|
||||
log.info("[规则4-支付宝] 处理支付宝支付:订单号={}, 金额={}",
|
||||
context.getOrderId(), context.getAmount());
|
||||
|
||||
// 模拟支付处理
|
||||
context.setStatus("PAID");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package org.springblade.test.literule.rule;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springblade.core.literule.annotation.LiteRuleComponent;
|
||||
import org.springblade.core.literule.core.RuleComponent;
|
||||
import org.springblade.test.literule.context.OrderContext;
|
||||
|
||||
/**
|
||||
* BankPayRule
|
||||
*
|
||||
* @author BladeX
|
||||
*/
|
||||
@Slf4j
|
||||
@LiteRuleComponent(id = "bankPayRule")
|
||||
public class BankPayRule extends RuleComponent {
|
||||
|
||||
@Override
|
||||
protected void process() {
|
||||
OrderContext context = getContextBean(OrderContext.class);
|
||||
log.info("[规则4-银行] 处理银行卡支付:订单号={}, 金额={}",
|
||||
context.getOrderId(), context.getAmount());
|
||||
|
||||
// 模拟支付处理
|
||||
context.setStatus("PAID");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package org.springblade.test.literule.rule;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springblade.core.literule.annotation.LiteRuleComponent;
|
||||
import org.springblade.core.literule.core.RuleComponent;
|
||||
import org.springblade.test.literule.context.Address;
|
||||
import org.springblade.test.literule.context.OrderContext;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* OrderAmountRule
|
||||
*
|
||||
* @author BladeX
|
||||
*/
|
||||
@Slf4j
|
||||
@LiteRuleComponent(id = "orderAmountRule")
|
||||
public class OrderAmountRule extends RuleComponent {
|
||||
|
||||
@Override
|
||||
protected void process() {
|
||||
OrderContext context = getContextBean(OrderContext.class);
|
||||
BigDecimal amount = context.getAmount();
|
||||
|
||||
// 计算折扣
|
||||
BigDecimal discount = calculateDiscount(amount);
|
||||
|
||||
// 计算运费
|
||||
BigDecimal shipping = calculateShipping(context.getShippingAddress());
|
||||
|
||||
// 更新订单金额
|
||||
BigDecimal finalAmount = amount.subtract(discount).add(shipping);
|
||||
context.setAmount(finalAmount);
|
||||
|
||||
log.info("[规则2] 订单金额计算完成:{} = {} - {} + {}", finalAmount, amount, discount, shipping);
|
||||
}
|
||||
|
||||
private BigDecimal calculateDiscount(BigDecimal amount) {
|
||||
// 折扣计算逻辑:金额大于1000打9折
|
||||
if (amount.compareTo(new BigDecimal("1000")) > 0) {
|
||||
return amount.multiply(new BigDecimal("0.1"));
|
||||
}
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
private BigDecimal calculateShipping(Address address) {
|
||||
// 运费计算逻辑:根据地址计算
|
||||
if ("China".equals(address.getCountry())) {
|
||||
return new BigDecimal("10");
|
||||
}
|
||||
return new BigDecimal("50");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package org.springblade.test.literule.rule;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springblade.core.literule.annotation.LiteRuleComponent;
|
||||
import org.springblade.core.literule.core.RuleComponent;
|
||||
import org.springblade.test.literule.context.Address;
|
||||
import org.springblade.test.literule.context.OrderContext;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* OrderValidateRule
|
||||
*
|
||||
* @author BladeX
|
||||
*/
|
||||
@Slf4j
|
||||
@LiteRuleComponent(id = "orderValidateRule")
|
||||
public class OrderValidateRule extends RuleComponent {
|
||||
|
||||
@Override
|
||||
protected void process() {
|
||||
OrderContext context = getContextBean(OrderContext.class);
|
||||
|
||||
// 校验订单ID
|
||||
if (isEmpty(context.getOrderId())) {
|
||||
context.addError("订单ID不能为空");
|
||||
log.info("[规则1] 订单校验不通过:{}", context.getErrorMessages());
|
||||
return;
|
||||
}
|
||||
|
||||
// 校验金额
|
||||
if (context.getAmount() == null || context.getAmount().compareTo(BigDecimal.ZERO) <= 0) {
|
||||
context.addError("订单金额无效");
|
||||
log.info("[规则1] 订单校验不通过:{}", context.getErrorMessages());
|
||||
return;
|
||||
}
|
||||
|
||||
// 校验地址
|
||||
Address address = context.getShippingAddress();
|
||||
if (address == null) {
|
||||
context.addError("收货地址不能为空");
|
||||
log.info("[规则1] 订单校验不通过:{}", context.getErrorMessages());
|
||||
return;
|
||||
}
|
||||
|
||||
log.info("[规则1] 订单校验通过:{}", context.getOrderId());
|
||||
}
|
||||
|
||||
private boolean isEmpty(String str) {
|
||||
return str == null || str.trim().isEmpty();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package org.springblade.test.literule.rule;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springblade.core.literule.annotation.LiteRuleComponent;
|
||||
import org.springblade.core.literule.core.RuleSwitchComponent;
|
||||
import org.springblade.test.literule.context.OrderContext;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* PaymentRouteRule
|
||||
*
|
||||
* @author BladeX
|
||||
*/
|
||||
@Slf4j
|
||||
@LiteRuleComponent(id = "paymentSwitchRule")
|
||||
public class PaymentSwitchRule extends RuleSwitchComponent {
|
||||
|
||||
private static final Map<String, String> PAYMENT_RULE_MAP = new HashMap<>();
|
||||
|
||||
static {
|
||||
PAYMENT_RULE_MAP.put("ALIPAY", "alipayRule");
|
||||
PAYMENT_RULE_MAP.put("WECHAT", "wechatPayRule");
|
||||
PAYMENT_RULE_MAP.put("BANK", "bankPayRule");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> process() {
|
||||
OrderContext context = getContextBean(OrderContext.class);
|
||||
String paymentType = context.getPaymentType();
|
||||
|
||||
log.info("[规则3] 支付路由选择:{}", paymentType);
|
||||
|
||||
String payName = PAYMENT_RULE_MAP.get(paymentType);
|
||||
if (payName != null) {
|
||||
return Collections.singletonList(payName);
|
||||
} else {
|
||||
context.addError("不支持的支付方式:" + paymentType);
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package org.springblade.test.literule.rule;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springblade.core.literule.annotation.LiteRuleComponent;
|
||||
import org.springblade.core.literule.core.RuleComponent;
|
||||
import org.springblade.test.literule.context.OrderContext;
|
||||
|
||||
/**
|
||||
* WechatPayRule
|
||||
*
|
||||
* @author BladeX
|
||||
*/
|
||||
@Slf4j
|
||||
@LiteRuleComponent(id = "wechatPayRule")
|
||||
public class WechatPayRule extends RuleComponent {
|
||||
|
||||
@Override
|
||||
protected void process() {
|
||||
OrderContext context = getContextBean(OrderContext.class);
|
||||
log.info("[规则4-微信] 处理微信支付:订单号={}, 金额={}",
|
||||
context.getOrderId(), context.getAmount());
|
||||
|
||||
// 模拟支付处理
|
||||
context.setStatus("PAID");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
package org.springblade.test.secure;
|
||||
|
||||
import org.springblade.core.http.HttpRequest;
|
||||
import org.springblade.core.http.ResponseSpec;
|
||||
import org.springblade.core.tool.utils.StringUtil;
|
||||
|
||||
import java.util.Base64;
|
||||
|
||||
import static org.springblade.test.secure.SecureTestBuilder.*;
|
||||
|
||||
/**
|
||||
* Secure安全框架 - 基础认证测试类
|
||||
* 测试HTTP Basic Authentication
|
||||
*
|
||||
* @author BladeX
|
||||
*/
|
||||
public class SecureBasicTest {
|
||||
|
||||
/**
|
||||
* Basic认证用户名
|
||||
*/
|
||||
private static final String BASIC_USERNAME = "admin";
|
||||
|
||||
/**
|
||||
* Basic认证密码
|
||||
*/
|
||||
private static final String BASIC_PASSWORD = "admin123";
|
||||
|
||||
public static void main(String[] args) {
|
||||
// 设置日志级别,方便调试
|
||||
initHttpLog();
|
||||
|
||||
printHeader("Secure 基础认证测试");
|
||||
|
||||
// 测试1: 获取Token
|
||||
String accessToken = getToken();
|
||||
|
||||
// 测试2: 使用Token调用受保护API
|
||||
if (StringUtil.isNotBlank(accessToken)) {
|
||||
testCallApiWithToken(accessToken);
|
||||
}
|
||||
|
||||
// 测试3: Basic认证调用受保护API
|
||||
testBasicAuth();
|
||||
|
||||
printFooter();
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用Token调用受保护API
|
||||
*
|
||||
* @param accessToken 访问令牌
|
||||
*/
|
||||
private static void testCallApiWithToken(String accessToken) {
|
||||
printSection(2, "使用 Token 调用受保护 API");
|
||||
callApiWithToken("/blade-desk/notice/list", accessToken);
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试Basic认证调用受保护API
|
||||
* 认证原理: Authorization: Basic {Base64(username:password)}
|
||||
*/
|
||||
private static void testBasicAuth() {
|
||||
printSection(1, "Basic 认证调用受保护 API");
|
||||
|
||||
try {
|
||||
// 1. 生成Basic Auth凭证
|
||||
String credentials = BASIC_USERNAME + ":" + BASIC_PASSWORD;
|
||||
String encoded = Base64.getEncoder().encodeToString(credentials.getBytes());
|
||||
String basicAuth = "Basic " + encoded;
|
||||
|
||||
System.out.println();
|
||||
System.out.println(" Basic Auth Parameters:");
|
||||
printKeyValue(" username", BASIC_USERNAME);
|
||||
printKeyValue(" password", BASIC_PASSWORD);
|
||||
printKeyValue(" credentials", credentials);
|
||||
printKeyValue(" encoded", encoded);
|
||||
printKeyValue(" Authorization", basicAuth);
|
||||
|
||||
// 2. 发送带Basic认证的请求
|
||||
String response = HttpRequest.get(BASE_URL + "/blade-test/info/basic")
|
||||
.addHeader("Authorization", basicAuth)
|
||||
.addHeader("Blade-Requested-With", "BladeHttpRequest")
|
||||
.execute()
|
||||
.onSuccess(ResponseSpec::asString);
|
||||
|
||||
System.out.println();
|
||||
printKeyValue("Response", response);
|
||||
printSuccess("Basic 认证请求发送成功");
|
||||
} catch (Exception e) {
|
||||
printError("Basic 认证异常 - " + e.getMessage());
|
||||
printWarning("如果Basic认证接口未配置或不存在会报错,属于正常情况");
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
package org.springblade.test.secure;
|
||||
|
||||
import org.springblade.core.http.HttpRequest;
|
||||
import org.springblade.core.http.ResponseSpec;
|
||||
import org.springblade.core.tool.utils.DigestUtil;
|
||||
import org.springblade.core.tool.utils.StringUtil;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.springblade.test.secure.SecureTestBuilder.*;
|
||||
|
||||
/**
|
||||
* Secure安全框架 - 签名认证测试类
|
||||
* 测试获取Token以及签名认证(nonce+timestamp)
|
||||
*
|
||||
* @author BladeX
|
||||
*/
|
||||
public class SecureSignTest {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// 设置日志级别,方便调试
|
||||
initHttpLog();
|
||||
|
||||
printHeader("Secure 签名认证测试");
|
||||
|
||||
// 测试1: 获取Token
|
||||
String accessToken = getToken();
|
||||
|
||||
// 测试2: 使用Token调用受保护API
|
||||
if (StringUtil.isNotBlank(accessToken)) {
|
||||
testCallApiWithToken(accessToken);
|
||||
}
|
||||
|
||||
// 测试3: 签名认证(nonce+timestamp)
|
||||
testSignAuth();
|
||||
|
||||
printFooter();
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用Token调用受保护API
|
||||
*
|
||||
* @param accessToken 访问令牌
|
||||
*/
|
||||
private static void testCallApiWithToken(String accessToken) {
|
||||
printSection(2, "使用 Token 调用受保护 API");
|
||||
callApiWithToken("/blade-desk/notice/list", accessToken);
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试签名认证(nonce+timestamp)
|
||||
* 签名规则: signature = SHA1(timestamp + nonce)
|
||||
*/
|
||||
private static void testSignAuth() {
|
||||
printSection(3, "签名认证 (nonce + timestamp)");
|
||||
|
||||
try {
|
||||
// 1. 生成签名参数
|
||||
String timestamp = String.valueOf(System.currentTimeMillis());
|
||||
String nonce = UUID.randomUUID().toString().replace("-", "");
|
||||
String signature = DigestUtil.sha1Hex(timestamp + nonce);
|
||||
|
||||
System.out.println();
|
||||
System.out.println(" Signature Parameters:");
|
||||
printKeyValue(" timestamp", timestamp);
|
||||
printKeyValue(" nonce", nonce);
|
||||
printKeyValue(" signature", signature);
|
||||
printKeyValue(" algorithm", "SHA1(timestamp + nonce)");
|
||||
|
||||
// 2. 发送带签名的请求
|
||||
String response = HttpRequest.get(BASE_URL + "/blade-test/info/sign")
|
||||
.addHeader("Authorization", CLIENT_AUTH)
|
||||
.addHeader("Blade-Requested-With", "BladeHttpRequest")
|
||||
.addHeader("timestamp", timestamp)
|
||||
.addHeader("nonce", nonce)
|
||||
.addHeader("signature", signature)
|
||||
.execute()
|
||||
.onSuccess(ResponseSpec::asString);
|
||||
|
||||
System.out.println();
|
||||
printKeyValue("Response", response);
|
||||
printSuccess("签名认证请求发送成功");
|
||||
} catch (Exception e) {
|
||||
printError("签名认证异常 - " + e.getMessage());
|
||||
printWarning("如果签名认证接口未配置或不存在会报错,属于正常情况");
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
203
src/test/java/org/springblade/test/secure/SecureTestBuilder.java
Normal file
203
src/test/java/org/springblade/test/secure/SecureTestBuilder.java
Normal file
@@ -0,0 +1,203 @@
|
||||
package org.springblade.test.secure;
|
||||
|
||||
import org.springblade.core.http.HttpRequest;
|
||||
import org.springblade.core.http.LogLevel;
|
||||
import org.springblade.core.http.ResponseSpec;
|
||||
import org.springblade.core.tool.jackson.JsonUtil;
|
||||
import org.springblade.core.tool.utils.StringUtil;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Secure安全框架测试工具类
|
||||
* 提供通用的Token获取、API调用及打印辅助方法
|
||||
*
|
||||
* @author BladeX
|
||||
*/
|
||||
public class SecureTestBuilder {
|
||||
|
||||
/**
|
||||
* 分隔线
|
||||
*/
|
||||
public static final String LINE = "─".repeat(60);
|
||||
public static final String DOUBLE_LINE = "═".repeat(60);
|
||||
|
||||
/**
|
||||
* 服务地址
|
||||
*/
|
||||
public static final String BASE_URL = "http://localhost";
|
||||
|
||||
/**
|
||||
* 客户端认证信息 (saber3:saber3_secret 的 Base64 编码)
|
||||
*/
|
||||
public static final String CLIENT_AUTH = "Basic c2FiZXIzOnNhYmVyM19zZWNyZXQ=";
|
||||
|
||||
/**
|
||||
* 租户ID
|
||||
*/
|
||||
public static final String TENANT_ID = "000000";
|
||||
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
public static final String USERNAME = "admin";
|
||||
|
||||
/**
|
||||
* 密码(国密加密后的字符串,具体见 @org.springblade.test.sm.Sm2Test)
|
||||
*/
|
||||
public static final String PASSWORD = "";
|
||||
|
||||
/**
|
||||
* 初始化HTTP日志级别
|
||||
*/
|
||||
public static void initHttpLog() {
|
||||
HttpRequest.setGlobalLog(LogLevel.BODY);
|
||||
}
|
||||
|
||||
/**
|
||||
* 打印测试头部
|
||||
*
|
||||
* @param title 测试标题
|
||||
*/
|
||||
public static void printHeader(String title) {
|
||||
System.out.println();
|
||||
System.out.println(DOUBLE_LINE);
|
||||
System.out.println(" " + title);
|
||||
System.out.println(DOUBLE_LINE);
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
/**
|
||||
* 打印测试尾部
|
||||
*/
|
||||
public static void printFooter() {
|
||||
System.out.println(DOUBLE_LINE);
|
||||
System.out.println(" 测试执行完毕");
|
||||
System.out.println(DOUBLE_LINE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 打印测试章节
|
||||
*
|
||||
* @param testNo 测试编号
|
||||
* @param title 章节标题
|
||||
*/
|
||||
public static void printSection(int testNo, String title) {
|
||||
System.out.println(LINE);
|
||||
System.out.printf(" [TEST-%d] %s%n", testNo, title);
|
||||
System.out.println(LINE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 打印键值对
|
||||
*
|
||||
* @param key 键
|
||||
* @param value 值
|
||||
*/
|
||||
public static void printKeyValue(String key, Object value) {
|
||||
System.out.printf(" %-16s: %s%n", key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 打印成功消息
|
||||
*
|
||||
* @param message 消息内容
|
||||
*/
|
||||
public static void printSuccess(String message) {
|
||||
System.out.printf("%n [SUCCESS] %s%n%n", message);
|
||||
}
|
||||
|
||||
/**
|
||||
* 打印错误消息
|
||||
*
|
||||
* @param message 消息内容
|
||||
*/
|
||||
public static void printError(String message) {
|
||||
System.out.printf("%n [FAILED] %s%n%n", message);
|
||||
}
|
||||
|
||||
/**
|
||||
* 打印警告消息
|
||||
*
|
||||
* @param message 消息内容
|
||||
*/
|
||||
public static void printWarning(String message) {
|
||||
System.out.printf(" [WARN] %s%n", message);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Token
|
||||
* 通用方法,供签名认证等场景复用
|
||||
*
|
||||
* @return accessToken,获取失败返回null
|
||||
*/
|
||||
public static String getToken() {
|
||||
printSection(1, "获取 Token");
|
||||
|
||||
try {
|
||||
String response = HttpRequest.post(BASE_URL + "/blade-auth/oauth/token")
|
||||
.addHeader("Authorization", CLIENT_AUTH)
|
||||
.addHeader("Content-Type", "application/x-www-form-urlencoded")
|
||||
.formBuilder()
|
||||
.add("grant_type", "password")
|
||||
.add("tenant_id", TENANT_ID)
|
||||
.add("username", USERNAME)
|
||||
.add("password", PASSWORD)
|
||||
.execute()
|
||||
.onSuccess(ResponseSpec::asString);
|
||||
|
||||
System.out.println();
|
||||
printKeyValue("Response", response);
|
||||
|
||||
if (StringUtil.isNotBlank(response)) {
|
||||
Map<String, Object> result = JsonUtil.readMap(response, String.class, Object.class);
|
||||
if (result != null && result.containsKey("access_token")) {
|
||||
String accessToken = (String) result.get("access_token");
|
||||
String tokenType = (String) result.get("token_type");
|
||||
Object expiresIn = result.get("expires_in");
|
||||
|
||||
System.out.println();
|
||||
System.out.println(" Token Details:");
|
||||
printKeyValue(" token_type", tokenType);
|
||||
printKeyValue(" access_token", accessToken.substring(0, Math.min(50, accessToken.length())) + "...");
|
||||
printKeyValue(" expires_in", expiresIn + " seconds");
|
||||
|
||||
printSuccess("Token 获取成功");
|
||||
return accessToken;
|
||||
} else {
|
||||
printError("Token 获取失败 - " + result);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
printError("Token 获取异常 - " + e.getMessage());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用Token调用受保护API
|
||||
*
|
||||
* @param url API地址(相对路径,如 /blade-desk/notice/list)
|
||||
* @param accessToken 访问令牌
|
||||
*/
|
||||
public static void callApiWithToken(String url, String accessToken) {
|
||||
try {
|
||||
String response = HttpRequest.get(BASE_URL + url)
|
||||
.addHeader("Authorization", CLIENT_AUTH)
|
||||
.addHeader("Blade-Auth", "bearer " + accessToken)
|
||||
.addHeader("Blade-Requested-With", "BladeHttpRequest")
|
||||
.execute()
|
||||
.onSuccess(ResponseSpec::asString);
|
||||
|
||||
System.out.println();
|
||||
printKeyValue("Response", response);
|
||||
printSuccess("API 调用成功");
|
||||
} catch (Exception e) {
|
||||
printError("API 调用异常 - " + e.getMessage());
|
||||
printWarning("如果接口不存在会返回 404,属于正常情况");
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
295
src/test/java/org/springblade/test/sensitive/SensitiveTest.java
Normal file
295
src/test/java/org/springblade/test/sensitive/SensitiveTest.java
Normal file
@@ -0,0 +1,295 @@
|
||||
package org.springblade.test.sensitive;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springblade.core.tool.jackson.JsonUtil;
|
||||
import org.springblade.core.tool.jackson.Sensitive;
|
||||
import org.springblade.core.tool.sensitive.SensitiveConfig;
|
||||
import org.springblade.core.tool.sensitive.SensitiveType;
|
||||
import org.springblade.core.tool.sensitive.SensitiveUtil;
|
||||
import org.springblade.core.tool.sensitive.SensitiveWord;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* SensitiveUtil使用示例
|
||||
* 展示各种使用场景和数据脱敏效果
|
||||
*
|
||||
* @author BladeX
|
||||
*/
|
||||
public class SensitiveTest {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// 演示所有使用场景
|
||||
demonstrateBasicUsage();
|
||||
demonstrateCustomConfig();
|
||||
demonstrateSingleType();
|
||||
demonstrateMultipleTypes();
|
||||
demonstrateCustomRegex();
|
||||
demonstrateSensitiveWords();
|
||||
demonstrateComplexExample();
|
||||
demonstrateJacksonSerializer();
|
||||
}
|
||||
|
||||
/**
|
||||
* 1. 基础用法演示 - 使用默认配置
|
||||
*/
|
||||
private static void demonstrateBasicUsage() {
|
||||
System.out.println("\n=== 1.基础用法演示 ===");
|
||||
|
||||
String content = "客户信息:\n" +
|
||||
"手机号: 13812345678\n" +
|
||||
"邮箱: test@example.com\n" +
|
||||
"身份证: 310123199001011234\n" +
|
||||
"银行卡: 6222021234567890123";
|
||||
|
||||
String result = SensitiveUtil.process(content);
|
||||
System.out.println("原始内容:\n" + content);
|
||||
System.out.println("\n处理后:\n" + result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 2. 自定义配置演示
|
||||
*/
|
||||
private static void demonstrateCustomConfig() {
|
||||
System.out.println("\n=== 2.自定义配置演示 ===");
|
||||
|
||||
// 创建自定义配置
|
||||
SensitiveConfig config = SensitiveConfig.builder()
|
||||
.sensitiveTypes(EnumSet.of(
|
||||
SensitiveType.MOBILE,
|
||||
SensitiveType.EMAIL
|
||||
))
|
||||
.sensitiveWords(EnumSet.of(
|
||||
SensitiveWord.SECURE,
|
||||
SensitiveWord.AUTHENTICATION
|
||||
))
|
||||
.customPatterns(Map.of(
|
||||
"CustomerId", Pattern.compile("(?<=CustomerID:)\\s*\\w+"),
|
||||
"ProjectCode", Pattern.compile("(?<=ProjectCode:)\\s*\\w+")
|
||||
))
|
||||
.processLineByLine(true)
|
||||
.replacement("***已隐藏***")
|
||||
.build();
|
||||
|
||||
String content = "用户数据:\n" +
|
||||
"手机: 13812345678\n" +
|
||||
"CustomerID: USER123456\n" +
|
||||
"ProjectCode: PRJ789\n" +
|
||||
"password=admin123\n" +
|
||||
"token=abcdef";
|
||||
|
||||
// 转换为LogVO示例
|
||||
LogVO logVO = SensitiveUtil.process(content, config, data -> {
|
||||
LogVO dto = new LogVO();
|
||||
dto.setContent(data);
|
||||
dto.setTimestamp(System.currentTimeMillis());
|
||||
return dto;
|
||||
});
|
||||
|
||||
System.out.println("原始内容:\n" + content);
|
||||
System.out.println("\n处理后:\n" + logVO.getContent());
|
||||
}
|
||||
|
||||
/**
|
||||
* 3. 单个敏感类型处理演示
|
||||
*/
|
||||
private static void demonstrateSingleType() {
|
||||
System.out.println("\n=== 3.单个敏感类型处理演示 ===");
|
||||
|
||||
String content = "联系方式:13812345678,邮箱:test@example.com";
|
||||
String result = SensitiveUtil.process(content, SensitiveType.MOBILE);
|
||||
|
||||
System.out.println("原始内容:" + content);
|
||||
System.out.println("处理后:" + result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 4. 多个敏感类型处理演示
|
||||
*/
|
||||
private static void demonstrateMultipleTypes() {
|
||||
System.out.println("\n=== 4.多个敏感类型处理演示 ===");
|
||||
|
||||
String content = "用户资料:\n" +
|
||||
"手机:13812345678\n" +
|
||||
"银行卡:6222021234567890123";
|
||||
|
||||
UserVO userVO = SensitiveUtil.process(content, EnumSet.of(
|
||||
SensitiveType.MOBILE,
|
||||
SensitiveType.BANK_CARD
|
||||
), data -> {
|
||||
UserVO vo = new UserVO();
|
||||
vo.setUserInfo(data);
|
||||
return vo;
|
||||
});
|
||||
|
||||
System.out.println("原始内容:\n" + content);
|
||||
System.out.println("\n处理后:\n" + userVO.getUserInfo());
|
||||
}
|
||||
|
||||
/**
|
||||
* 5. 自定义正则处理演示
|
||||
*/
|
||||
private static void demonstrateCustomRegex() {
|
||||
System.out.println("\n=== 5.自定义正则处理演示 ===");
|
||||
|
||||
// 简单版本
|
||||
String simpleContent = "订单号:ORDER20250101001";
|
||||
String simpleResult = SensitiveUtil.processWithRegex(
|
||||
simpleContent,
|
||||
"ORDER\\d{8}\\d{3}"
|
||||
);
|
||||
|
||||
System.out.println("简单版本:");
|
||||
System.out.println("原始内容:" + simpleContent);
|
||||
System.out.println("处理后:" + simpleResult);
|
||||
|
||||
// 自定义替换符版本
|
||||
String customContent = "项目编号:PRJ20250101";
|
||||
String customResult = SensitiveUtil.processWithRegex(
|
||||
customContent,
|
||||
"PRJ\\d{8}",
|
||||
"PRJ********"
|
||||
);
|
||||
|
||||
System.out.println("\n自定义替换符版本:");
|
||||
System.out.println("原始内容:" + customContent);
|
||||
System.out.println("处理后:" + customResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* 6. 敏感词处理演示
|
||||
*/
|
||||
private static void demonstrateSensitiveWords() {
|
||||
System.out.println("\n=== 6.敏感词处理演示 ===");
|
||||
|
||||
String content = "系统配置:\n" +
|
||||
"password=admin123\n" +
|
||||
"api_key=sk_test_123456\n" +
|
||||
"secret=my_secret_key\n" +
|
||||
"test=my_test_key";
|
||||
|
||||
List<String> sensitiveWords = Arrays.asList("password", "api_key", "secret");
|
||||
|
||||
// 完整版本的敏感词处理
|
||||
String result = SensitiveUtil.processWithWords(
|
||||
content,
|
||||
sensitiveWords,
|
||||
"***",// 可不填
|
||||
true // 可不填
|
||||
);
|
||||
|
||||
System.out.println("原始内容:\n" + content);
|
||||
System.out.println("\n处理后:\n" + result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 7. 复杂场景示例
|
||||
*/
|
||||
private static void demonstrateComplexExample() {
|
||||
System.out.println("\n=== 7.复杂场景示例 ===");
|
||||
|
||||
String content = "API调用日志:\n" +
|
||||
"时间:2024-01-01 10:30:00\n" +
|
||||
"请求头:\n" +
|
||||
"Authorization: Bearer sk_test_123456\n" +
|
||||
"请求体:\n" +
|
||||
"{\n" +
|
||||
" \"user\": {\n" +
|
||||
" \"mobile\": \"13812345678\",\n" +
|
||||
" \"email\": \"test@example.com\",\n" +
|
||||
" \"idCard\": \"310123199001011234\",\n" +
|
||||
" \"test\": \"2333333333\"\n" +
|
||||
" },\n" +
|
||||
" \"payment\": {\n" +
|
||||
" \"cardNo\": \"6222021234567890123\",\n" +
|
||||
" \"secretKey\": \"payment_secret_123\"\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
|
||||
// 创建复杂配置
|
||||
SensitiveConfig complexConfig = SensitiveConfig.builder()
|
||||
.sensitiveTypes(EnumSet.of(
|
||||
SensitiveType.MOBILE,
|
||||
SensitiveType.EMAIL,
|
||||
SensitiveType.ID_CARD
|
||||
))
|
||||
.sensitiveWords(EnumSet.allOf(SensitiveWord.class))
|
||||
.customPatterns(Map.of(
|
||||
"Bearer", Pattern.compile("Bearer\\s+[\\w-]+"),
|
||||
"SecretKey", Pattern.compile("(?<=secretKey\":\\s*\")[^\"]+")
|
||||
))
|
||||
.processLineByLine(true)
|
||||
.replacement("***")
|
||||
.build();
|
||||
|
||||
ApiLogVO apiLogVO = SensitiveUtil.process(content, complexConfig, data -> {
|
||||
ApiLogVO vo = new ApiLogVO();
|
||||
vo.setRequestLog(data);
|
||||
vo.setTimestamp(System.currentTimeMillis());
|
||||
return vo;
|
||||
});
|
||||
|
||||
System.out.println("原始内容:\n" + content);
|
||||
System.out.println("\n处理后:\n" + apiLogVO.getRequestLog());
|
||||
}
|
||||
|
||||
/**
|
||||
* 8. jackson序列化场景
|
||||
*/
|
||||
private static void demonstrateJacksonSerializer() {
|
||||
System.out.println("\n=== 8.jackson序列化场景 ===");
|
||||
|
||||
AccountVO accountVO = new AccountVO();
|
||||
accountVO.setMobile("13812345678");
|
||||
accountVO.setEmail("test@example.com");
|
||||
accountVO.setCredential("系统配置:\n" +
|
||||
"password=admin123\n" +
|
||||
"api_key=sk_test_123456\n" +
|
||||
"secret=my_secret_key\n" +
|
||||
"test=my_test");
|
||||
accountVO.setToken("Bearer password 123456");
|
||||
accountVO.setOrderId("订单号:ORDER20250101001");
|
||||
|
||||
System.out.println("原始内容:\n" + accountVO);
|
||||
System.out.println("\n处理后:\n" + JsonUtil.toJson(accountVO));
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据传输对象
|
||||
*/
|
||||
@Data
|
||||
static class LogVO {
|
||||
private String content;
|
||||
private long timestamp;
|
||||
}
|
||||
|
||||
@Data
|
||||
static class UserVO {
|
||||
private String userInfo;
|
||||
}
|
||||
|
||||
@Data
|
||||
static class ApiLogVO {
|
||||
private String requestLog;
|
||||
private long timestamp;
|
||||
}
|
||||
|
||||
@Data
|
||||
static class AccountVO {
|
||||
@Sensitive(type = SensitiveType.MOBILE)
|
||||
private String mobile;
|
||||
|
||||
@Sensitive(type = SensitiveType.EMAIL)
|
||||
private String email;
|
||||
|
||||
@Sensitive(word = SensitiveWord.SECURE)
|
||||
private String credential;
|
||||
|
||||
@Sensitive(words = {"password", "secret"})
|
||||
private String token;
|
||||
|
||||
@Sensitive(regex = "ORDER(.{2}).*(.{2})", replacement = "ORDER$1****$2")
|
||||
private String orderId;
|
||||
}
|
||||
}
|
||||
120
src/test/java/org/springblade/test/sm/Sm2Test.java
Normal file
120
src/test/java/org/springblade/test/sm/Sm2Test.java
Normal file
@@ -0,0 +1,120 @@
|
||||
package org.springblade.test.sm;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
import org.bouncycastle.crypto.AsymmetricCipherKeyPair;
|
||||
import org.bouncycastle.crypto.params.ECPrivateKeyParameters;
|
||||
import org.bouncycastle.crypto.params.ECPublicKeyParameters;
|
||||
import org.bouncycastle.util.encoders.Hex;
|
||||
import org.springblade.core.tool.utils.SM2Util;
|
||||
import org.springblade.core.tool.utils.StringUtil;
|
||||
|
||||
/**
|
||||
* SM2Test
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
public class Sm2Test {
|
||||
|
||||
@SneakyThrows
|
||||
public static void main(String[] args) {
|
||||
System.out.println("================== SM2 加解密与签名测试 ==================");
|
||||
|
||||
// 1. 生成SM2密钥对
|
||||
AsymmetricCipherKeyPair keyPair = SM2Util.generateKeyPair();
|
||||
String publicKeyString = SM2Util.getPublicKeyString(keyPair);
|
||||
String privateKeyString = SM2Util.getPrivateKeyString(keyPair);
|
||||
System.out.println("1. 生成SM2密钥对:");
|
||||
System.out.println(" 公钥 (16进制): " + publicKeyString);
|
||||
System.out.println(" 公钥长度: " + publicKeyString.length());
|
||||
System.out.println(" 私钥 (16进制): " + privateKeyString);
|
||||
System.out.println(" 私钥长度: " + privateKeyString.length());
|
||||
|
||||
System.out.println("--------------------------------------------------");
|
||||
|
||||
// 2. 从字符串恢复密钥
|
||||
System.out.println("2. 从字符串恢复密钥...");
|
||||
ECPublicKeyParameters publicKey = SM2Util.stringToPublicKey(publicKeyString);
|
||||
ECPrivateKeyParameters privateKey = SM2Util.stringToPrivateKey(privateKeyString);
|
||||
System.out.println(" 密钥恢复成功!");
|
||||
|
||||
System.out.println("--------------------------------------------------");
|
||||
|
||||
// 3. 准备待加密的原文
|
||||
String originalText = "Hello BladeX! 这是一段需要被国密SM2算法加密和签名的敏感信息。1234567890";
|
||||
System.out.println("3. 待加密的原文: " + originalText);
|
||||
|
||||
System.out.println("--------------------------------------------------");
|
||||
|
||||
// 4. 执行加密
|
||||
System.out.println("4. 正在执行加密操作...");
|
||||
byte[] encryptedData = SM2Util.encrypt(originalText, publicKey);
|
||||
if (encryptedData != null && encryptedData.length > 0) {
|
||||
System.out.println(" 加密成功!");
|
||||
System.out.println(" 加密后的密文 (16进制): " + Hex.toHexString(encryptedData));
|
||||
System.out.println(" 密文长度: " + encryptedData.length + " 字节");
|
||||
} else {
|
||||
System.out.println(" 加密失败!");
|
||||
return;
|
||||
}
|
||||
|
||||
System.out.println("--------------------------------------------------");
|
||||
|
||||
// 5. 执行解密
|
||||
System.out.println("5. 正在执行解密操作...");
|
||||
String decryptedText = SM2Util.decrypt(encryptedData, privateKey);
|
||||
if (StringUtil.isNotBlank(decryptedText)) {
|
||||
System.out.println(" 解密成功!");
|
||||
System.out.println(" 解密后的明文: " + decryptedText);
|
||||
} else {
|
||||
System.out.println(" 解密失败!");
|
||||
return;
|
||||
}
|
||||
|
||||
System.out.println("--------------------------------------------------");
|
||||
|
||||
// 6. 执行数字签名
|
||||
System.out.println("6. 正在执行数字签名...");
|
||||
byte[] signature = SM2Util.sign(originalText, privateKey);
|
||||
if (signature != null && signature.length > 0) {
|
||||
System.out.println(" 签名成功!");
|
||||
System.out.println(" 数字签名 (16进制): " + Hex.toHexString(signature));
|
||||
System.out.println(" 签名长度: " + signature.length + " 字节");
|
||||
} else {
|
||||
System.out.println(" 签名失败!");
|
||||
return;
|
||||
}
|
||||
|
||||
System.out.println("--------------------------------------------------");
|
||||
|
||||
// 7. 验证签名
|
||||
System.out.println("7. 正在验证数字签名...");
|
||||
boolean isVerified = SM2Util.verify(originalText, signature, publicKey);
|
||||
System.out.println(" 签名验证结果: " + (isVerified ? "有效" : "无效"));
|
||||
|
||||
System.out.println("--------------------------------------------------");
|
||||
|
||||
// 8. 校验加解密结果
|
||||
System.out.println("8. 正在校验原文与解密后的明文是否一致...");
|
||||
boolean isDecryptMatch = originalText.equals(decryptedText);
|
||||
System.out.println(" 加解密校验结果: " + (isDecryptMatch ? "一致" : "不一致"));
|
||||
|
||||
System.out.println("==================================================");
|
||||
|
||||
// 9. 最终结果汇总
|
||||
if (isDecryptMatch && isVerified) {
|
||||
System.out.println("\n[成功] SM2加解密与签名流程验证通过!");
|
||||
System.out.println(" ✓ 密钥对生成成功");
|
||||
System.out.println(" ✓ 加解密功能正常");
|
||||
System.out.println(" ✓ 数字签名验证通过");
|
||||
} else {
|
||||
System.out.println("\n[失败] SM2加解密与签名流程验证失败!");
|
||||
if (!isDecryptMatch) {
|
||||
System.out.println(" ✗ 加解密校验失败");
|
||||
}
|
||||
if (!isVerified) {
|
||||
System.out.println(" ✗ 数字签名验证失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
71
src/test/java/org/springblade/test/sm/Sm4Test.java
Normal file
71
src/test/java/org/springblade/test/sm/Sm4Test.java
Normal file
@@ -0,0 +1,71 @@
|
||||
package org.springblade.test.sm;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
import org.springblade.core.tool.utils.SM4Util;
|
||||
import org.springblade.core.tool.utils.StringUtil;
|
||||
|
||||
/**
|
||||
* Sm4Test
|
||||
*
|
||||
* @author BladeX
|
||||
*/
|
||||
public class Sm4Test {
|
||||
|
||||
@SneakyThrows
|
||||
public static void main(String[] args) {
|
||||
System.out.println("================== SM4 加解密测试 ==================");
|
||||
|
||||
// 1. 生成SM4密钥
|
||||
String sm4Key = SM4Util.generateKey();
|
||||
System.out.println("1. 生成SM4密钥 (16进制): " + sm4Key);
|
||||
System.out.println(" 密钥长度 (Hex): " + sm4Key.length());
|
||||
|
||||
System.out.println("--------------------------------------------------");
|
||||
|
||||
// 2. 准备待加密的原文
|
||||
String originalText = "Hello BladeX! 这是一段需要被国密SM4算法加密的敏感信息。1234567890";
|
||||
System.out.println("2. 待加密的原文: " + originalText);
|
||||
|
||||
System.out.println("--------------------------------------------------");
|
||||
|
||||
// 3. 执行加密
|
||||
System.out.println("3. 正在执行加密操作...");
|
||||
String encryptedText = SM4Util.encrypt(originalText, sm4Key);
|
||||
if (StringUtil.isNotBlank(encryptedText)) {
|
||||
System.out.println(" 加密成功!");
|
||||
System.out.println(" 加密后的密文 (16进制): " + encryptedText);
|
||||
} else {
|
||||
System.out.println(" 加密失败!");
|
||||
return;
|
||||
}
|
||||
|
||||
System.out.println("--------------------------------------------------");
|
||||
|
||||
// 4. 执行解密
|
||||
System.out.println("4. 正在执行解密操作...");
|
||||
String decryptedText = SM4Util.decrypt(encryptedText, sm4Key);
|
||||
if (StringUtil.isNotBlank(decryptedText)) {
|
||||
System.out.println(" 解密成功!");
|
||||
System.out.println(" 解密后的明文: " + decryptedText);
|
||||
} else {
|
||||
System.out.println(" 解密失败!");
|
||||
return;
|
||||
}
|
||||
|
||||
System.out.println("--------------------------------------------------");
|
||||
|
||||
// 5. 校验结果
|
||||
System.out.println("5. 正在校验原文与解密后的明文是否一致...");
|
||||
boolean isMatch = originalText.equals(decryptedText);
|
||||
System.out.println(" 校验结果: " + (isMatch ? "一致" : "不一致"));
|
||||
|
||||
System.out.println("==================================================");
|
||||
|
||||
if (isMatch) {
|
||||
System.out.println("\n[成功] SM4加解密流程验证通过!");
|
||||
} else {
|
||||
System.out.println("\n[失败] SM4加解密流程验证失败!");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
60
src/test/resources/application-dev.yml
Normal file
60
src/test/resources/application-dev.yml
Normal file
@@ -0,0 +1,60 @@
|
||||
#数据源配置
|
||||
spring:
|
||||
data:
|
||||
redis:
|
||||
##redis 单机环境配置
|
||||
host: 127.0.0.1
|
||||
port: 6379
|
||||
password:
|
||||
database: 0
|
||||
ssl:
|
||||
enabled: false
|
||||
##redis 集群环境配置
|
||||
#cluster:
|
||||
# nodes: 127.0.0.1:7001,127.0.0.1:7002,127.0.0.1:7003
|
||||
# commandTimeout: 5000
|
||||
datasource:
|
||||
# MySql
|
||||
url: jdbc:mysql://localhost:3306/bladex_boot?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true&allowPublicKeyRetrieval=true
|
||||
username: root
|
||||
password: root
|
||||
# PostgreSQL
|
||||
#url: jdbc:postgresql://127.0.0.1:5432/bladex_boot
|
||||
#username: postgres
|
||||
#password: 123456
|
||||
# Oracle
|
||||
#url: jdbc:oracle:thin:@127.0.0.1:1521:orcl
|
||||
#username: BLADEX_BOOT
|
||||
#password: BLADEX_BOOT
|
||||
# SqlServer
|
||||
#url: jdbc:sqlserver://127.0.0.1:1433;DatabaseName=bladex_boot
|
||||
#username: bladex_boot
|
||||
#password: bladex_boot
|
||||
# DaMeng
|
||||
#url: jdbc:dm://127.0.0.1:5236/BLADEX_BOOT?zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=utf-8
|
||||
#username: BLADEX_BOOT
|
||||
#password: BLADEX_BOOT
|
||||
# YashanDB
|
||||
#url: jdbc:yasdb://127.0.0.1:1688/BLADEX_BOOT
|
||||
#username: BLADEX_BOOT
|
||||
#password: BLADEX_BOOT
|
||||
|
||||
#第三方登陆
|
||||
social:
|
||||
enabled: true
|
||||
domain: http://127.0.0.1:1888
|
||||
|
||||
#blade配置
|
||||
blade:
|
||||
#分布式锁配置
|
||||
lock:
|
||||
##是否启用分布式锁
|
||||
enabled: false
|
||||
##redis服务地址
|
||||
address: redis://127.0.0.1:6379
|
||||
#本地文件上传
|
||||
file:
|
||||
remote-mode: true
|
||||
upload-domain: http://localhost:8999
|
||||
remote-path: /usr/share/nginx/html
|
||||
|
||||
42
src/test/resources/application-prod.yml
Normal file
42
src/test/resources/application-prod.yml
Normal file
@@ -0,0 +1,42 @@
|
||||
#数据源配置
|
||||
spring:
|
||||
data:
|
||||
redis:
|
||||
##redis 单机环境配置
|
||||
##将docker脚本部署的redis服务映射为宿主机ip
|
||||
##生产环境推荐使用阿里云高可用redis服务并设置密码
|
||||
host: 127.0.0.1
|
||||
port: 6379
|
||||
password:
|
||||
database: 0
|
||||
ssl:
|
||||
enabled: false
|
||||
##redis 集群环境配置
|
||||
#cluster:
|
||||
# nodes: 127.0.0.1:7001,127.0.0.1:7002,127.0.0.1:7003
|
||||
# commandTimeout: 5000
|
||||
datasource:
|
||||
url: jdbc:mysql://localhost:3306/bladex_boot?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true&allowPublicKeyRetrieval=true
|
||||
username: root
|
||||
password: root
|
||||
|
||||
#第三方登陆
|
||||
social:
|
||||
enabled: true
|
||||
domain: http://127.0.0.1:1888
|
||||
|
||||
#blade配置
|
||||
blade:
|
||||
#分布式锁配置
|
||||
lock:
|
||||
##是否启用分布式锁
|
||||
enabled: false
|
||||
##将docker脚本部署的redis服务映射为宿主机ip
|
||||
##生产环境推荐使用阿里云高可用redis服务并设置密码
|
||||
address: redis://127.0.0.1:6379
|
||||
password: 123456
|
||||
#本地文件上传
|
||||
file:
|
||||
remote-mode: true
|
||||
upload-domain: http://localhost:8999
|
||||
remote-path: /usr/share/nginx/html
|
||||
42
src/test/resources/application-test.yml
Normal file
42
src/test/resources/application-test.yml
Normal file
@@ -0,0 +1,42 @@
|
||||
#数据源配置
|
||||
spring:
|
||||
data:
|
||||
redis:
|
||||
##redis 单机环境配置
|
||||
##将docker脚本部署的redis服务映射为宿主机ip
|
||||
##生产环境推荐使用阿里云高可用redis服务并设置密码
|
||||
host: 127.0.0.1
|
||||
port: 6379
|
||||
password:
|
||||
database: 0
|
||||
ssl:
|
||||
enabled: false
|
||||
##redis 集群环境配置
|
||||
#cluster:
|
||||
# nodes: 127.0.0.1:7001,127.0.0.1:7002,127.0.0.1:7003
|
||||
# commandTimeout: 5000
|
||||
datasource:
|
||||
url: jdbc:mysql://localhost:3306/bladex_boot?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true&allowPublicKeyRetrieval=true
|
||||
username: root
|
||||
password: root
|
||||
|
||||
#第三方登陆
|
||||
social:
|
||||
enabled: true
|
||||
domain: http://127.0.0.1:1888
|
||||
|
||||
#blade配置
|
||||
blade:
|
||||
#分布式锁配置
|
||||
lock:
|
||||
##是否启用分布式锁
|
||||
enabled: false
|
||||
##将docker脚本部署的redis服务映射为宿主机ip
|
||||
##生产环境推荐使用阿里云高可用redis服务并设置密码
|
||||
address: redis://127.0.0.1:6379
|
||||
password: 123456
|
||||
#本地文件上传
|
||||
file:
|
||||
remote-mode: true
|
||||
upload-domain: http://localhost:8999
|
||||
remote-path: /usr/share/nginx/html
|
||||
296
src/test/resources/application.yml
Normal file
296
src/test/resources/application.yml
Normal file
@@ -0,0 +1,296 @@
|
||||
#服务器配置
|
||||
server:
|
||||
port: 80
|
||||
undertow:
|
||||
threads:
|
||||
# 设置IO线程数, 它主要执行非阻塞的任务,它们会负责多个连接, 默认设置每个CPU核心一个线程
|
||||
io: 16
|
||||
# 阻塞任务线程池, 当执行类似servlet请求阻塞操作, undertow会从这个线程池中取得线程,它的值设置取决于系统的负载
|
||||
worker: 400
|
||||
# 以下的配置会影响buffer,这些buffer会用于服务器连接的IO操作,有点类似netty的池化内存管理
|
||||
buffer-size: 1024
|
||||
# 是否分配的直接内存
|
||||
direct-buffers: true
|
||||
|
||||
spring:
|
||||
datasource:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
#driver-class-name: org.postgresql.Driver
|
||||
#driver-class-name: oracle.jdbc.OracleDriver
|
||||
#driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
|
||||
#driver-class-name: dm.jdbc.driver.DmDriver
|
||||
#driver-class-name: com.yashandb.jdbc.Driver
|
||||
druid:
|
||||
# MySql、PostgreSQL、SqlServer、DaMeng校验
|
||||
validation-query: select 1
|
||||
# Oracle、YashanDB校验
|
||||
#oracle: true
|
||||
#validation-query: select 1 from dual
|
||||
validation-query-timeout: 2000
|
||||
initial-size: 5
|
||||
max-active: 20
|
||||
min-idle: 5
|
||||
max-wait: 60000
|
||||
test-on-borrow: false
|
||||
test-on-return: false
|
||||
test-while-idle: true
|
||||
time-between-eviction-runs-millis: 60000
|
||||
min-evictable-idle-time-millis: 300000
|
||||
stat-view-servlet:
|
||||
enabled: true
|
||||
login-username: blade
|
||||
login-password: 1qaz@WSX
|
||||
web-stat-filter:
|
||||
enabled: true
|
||||
url-pattern: /*
|
||||
exclusions: '*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*'
|
||||
session-stat-enable: true
|
||||
session-stat-max-count: 10
|
||||
|
||||
# mybatis
|
||||
mybatis-plus:
|
||||
mapper-locations: classpath:org/springblade/**/mapper/*Mapper.xml
|
||||
#实体扫描,多个package用逗号或者分号分隔
|
||||
typeAliasesPackage: org.springblade.**.entity
|
||||
#typeEnumsPackage: org.springblade.dashboard.entity.enums
|
||||
global-config:
|
||||
# 关闭MP3.0自带的banner
|
||||
banner: false
|
||||
db-config:
|
||||
#主键类型 0:"数据库ID自增", 1:"不操作", 2:"用户输入ID",3:"数字型snowflake", 4:"全局唯一ID UUID", 5:"字符串型snowflake";
|
||||
id-type: assign_id
|
||||
#字段策略
|
||||
insert-strategy: not_null
|
||||
update-strategy: not_null
|
||||
where-strategy: not_null
|
||||
#驼峰下划线转换
|
||||
table-underline: true
|
||||
# 逻辑删除配置
|
||||
# 逻辑删除全局值(1表示已删除,这也是Mybatis Plus的默认配置)
|
||||
logic-delete-value: 1
|
||||
# 逻辑未删除全局值(0表示未删除,这也是Mybatis Plus的默认配置)
|
||||
logic-not-delete-value: 0
|
||||
configuration:
|
||||
map-underscore-to-camel-case: true
|
||||
cache-enabled: false
|
||||
jdbc-type-for-null: 'null'
|
||||
|
||||
#knife4j配置
|
||||
knife4j:
|
||||
#启用
|
||||
enable: true
|
||||
#基础认证
|
||||
basic:
|
||||
enable: false
|
||||
username: blade
|
||||
password: blade
|
||||
#增强配置
|
||||
setting:
|
||||
enable-swagger-models: true
|
||||
enable-document-manage: true
|
||||
enable-host: false
|
||||
enable-host-text: http://localhost
|
||||
enable-request-cache: true
|
||||
enable-filter-multipart-apis: false
|
||||
enable-filter-multipart-api-method-type: POST
|
||||
enable-footer: false
|
||||
enable-footer-custom: true
|
||||
language: zh_cn
|
||||
footer-custom-content: Copyright © 2026 BladeX All Rights Reserved
|
||||
|
||||
#swagger公共信息
|
||||
swagger:
|
||||
title: BladeX 接口文档系统
|
||||
description: BladeX 接口文档系统
|
||||
version: 4.8.0.RELEASE
|
||||
license: Powered By BladeX
|
||||
license-url: https://license.bladex.cn
|
||||
contact:
|
||||
name: 翼宿
|
||||
email: bladejava@qq.com
|
||||
url: https://gitee.com/smallc
|
||||
|
||||
#oss默认配置
|
||||
oss:
|
||||
#开启oss配置
|
||||
enabled: true
|
||||
#开启oss类型
|
||||
#minio、s3、qiniu、alioss、huaweiobs、tencentcos
|
||||
name: minio
|
||||
#租户模式
|
||||
tenant-mode: true
|
||||
#oss服务地址
|
||||
endpoint: http://127.0.0.1:9000
|
||||
#oss转换服务地址,用于内网上传后将返回地址改为转换的外网地址
|
||||
transform-endpoint: http://localhost:9000
|
||||
#访问key
|
||||
access-key: bladexadmin
|
||||
#密钥key
|
||||
secret-key: bladexadmin
|
||||
#存储桶
|
||||
bucket-name: bladex
|
||||
|
||||
#第三方登陆配置
|
||||
social:
|
||||
oauth:
|
||||
GITHUB:
|
||||
client-id: 233************
|
||||
client-secret: 233************************************
|
||||
redirect-uri: ${social.domain}/oauth/redirect/github
|
||||
GITEE:
|
||||
client-id: 233************
|
||||
client-secret: 233************************************
|
||||
redirect-uri: ${social.domain}/oauth/redirect/gitee
|
||||
WECHAT_OPEN:
|
||||
client-id: 233************
|
||||
client-secret: 233************************************
|
||||
redirect-uri: ${social.domain}/oauth/redirect/wechat
|
||||
QQ:
|
||||
client-id: 233************
|
||||
client-secret: 233************************************
|
||||
redirect-uri: ${social.domain}/oauth/redirect/qq
|
||||
DINGTALK:
|
||||
client-id: 233************
|
||||
client-secret: 233************************************
|
||||
redirect-uri: ${social.domain}/oauth/redirect/dingtalk
|
||||
|
||||
#flowable配置
|
||||
flowable:
|
||||
activity-font-name: \u5B8B\u4F53
|
||||
label-font-name: \u5B8B\u4F53
|
||||
annotation-font-name: \u5B8B\u4F53
|
||||
check-process-definitions: false
|
||||
database-schema-update: true
|
||||
async-executor-activate: false
|
||||
async-history-executor-activate: false
|
||||
|
||||
#报表配置
|
||||
report:
|
||||
enabled: false
|
||||
database:
|
||||
provider:
|
||||
prefix: blade-
|
||||
|
||||
#job服务配置
|
||||
powerjob:
|
||||
worker:
|
||||
enabled: false
|
||||
app-name: blade-job
|
||||
port: 27777
|
||||
server-address: 127.0.0.1:7700
|
||||
|
||||
#blade配置
|
||||
blade:
|
||||
#oauth2配置
|
||||
oauth2:
|
||||
#启用 oauth2
|
||||
enabled: true
|
||||
#使用 @org.springblade.test.Sm2KeyGenerator 获取,用于国密sm2验签,需和前端保持一致
|
||||
public-key: ${BLADE_OAUTH2_PUBLIC_KEY}
|
||||
#使用 @org.springblade.test.Sm2KeyGenerator 获取,用于国密sm2解密,前端无需配置
|
||||
private-key: ${BLADE_OAUTH2_PRIVATE_KEY}
|
||||
#token配置
|
||||
token:
|
||||
#是否有状态
|
||||
state: false
|
||||
#是否单用户登录
|
||||
single: false
|
||||
#单用户登录范围
|
||||
single-level: all
|
||||
#token签名 使用 @org.springblade.test.SignKeyGenerator 获取
|
||||
sign-key: ${BLADE_TOKEN_SIGN_KEY}
|
||||
#token加密 使用 @org.springblade.test.CryptoKeyGenerator 获取
|
||||
crypto-key: ${BLADE_TOKEN_CRYPTO_KEY}
|
||||
#接口配置
|
||||
api:
|
||||
#报文加密配置
|
||||
crypto:
|
||||
#启用报文加密配置
|
||||
enabled: false
|
||||
#使用 @org.springblade.test.CryptoKeyGenerator 获取,需和前端保持一致
|
||||
aes-key: ${BLADE_API_CRYPTO_AES_KEY}
|
||||
#使用 @org.springblade.test.CryptoKeyGenerator 获取,需和前端保持一致
|
||||
des-key: ${BLADE_API_CRYPTO_DES_KEY}
|
||||
#jackson配置
|
||||
jackson:
|
||||
#null自动转空值
|
||||
null-to-empty: true
|
||||
#大数字自动转字符串
|
||||
big-num-to-string: true
|
||||
#支持text文本请求,与报文加密同时开启
|
||||
support-text-plain: false
|
||||
#redis序列化方式
|
||||
redis:
|
||||
serializer-type: protostuff
|
||||
#日志配置
|
||||
log:
|
||||
request:
|
||||
#开启控制台请求日志
|
||||
enabled: true
|
||||
#控制台请求日志忽略
|
||||
skip-url:
|
||||
- /blade-desk/notice/list
|
||||
- /blade-chat/weixin/**
|
||||
#开启错误日志入库
|
||||
error-log: true
|
||||
#xss配置
|
||||
xss:
|
||||
enabled: true
|
||||
skip-url:
|
||||
- /blade-chat/weixin
|
||||
- /blade-desk/notice/submit
|
||||
- /blade-flow/model/submit
|
||||
- /blade-develop/datasource/submit
|
||||
#安全框架配置
|
||||
secure:
|
||||
#接口放行
|
||||
skip-url:
|
||||
- /blade-test/**
|
||||
#授权认证配置
|
||||
auth:
|
||||
- method: ALL
|
||||
pattern: /blade-chat/weixin/**
|
||||
expression: "hasAuth()"
|
||||
- method: POST
|
||||
pattern: /blade-desk/dashboard/upload
|
||||
expression: "hasTimeAuth(9, 17)"
|
||||
- method: POST
|
||||
pattern: /blade-desk/dashboard/submit
|
||||
expression: "hasAnyRole('administrator', 'admin', 'user')"
|
||||
#基础认证配置
|
||||
basic:
|
||||
- method: ALL
|
||||
pattern: /blade-desk/dashboard/info
|
||||
username: "blade"
|
||||
password: "blade"
|
||||
#动态签名认证配置
|
||||
sign:
|
||||
- method: ALL
|
||||
pattern: /blade-desk/dashboard/sign
|
||||
crypto: "sha1"
|
||||
#多终端认证配置
|
||||
client:
|
||||
- client-id: sword
|
||||
path-patterns:
|
||||
- /blade-sword/**
|
||||
- client-id: saber
|
||||
path-patterns:
|
||||
- /blade-saber/**
|
||||
#多租户配置
|
||||
tenant:
|
||||
#多租户增强
|
||||
enhance: true
|
||||
#多租户授权保护
|
||||
license: false
|
||||
#动态数据库隔离功能
|
||||
dynamic-datasource: false
|
||||
#动态数据库隔离全局扫描
|
||||
dynamic-global: false
|
||||
#多租户字段名
|
||||
column: tenant_id
|
||||
#排除多租户逻辑
|
||||
exclude-tables:
|
||||
- blade_user
|
||||
#分库分表配置
|
||||
sharding:
|
||||
enabled: false
|
||||
212
src/test/resources/templates/api-fast/controller.java.btl
Normal file
212
src/test/resources/templates/api-fast/controller.java.btl
Normal file
@@ -0,0 +1,212 @@
|
||||
/**
|
||||
* BladeX Commercial License Agreement
|
||||
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||
* <p>
|
||||
* Use of this software is governed by the Commercial License Agreement
|
||||
* obtained after purchasing a license from BladeX.
|
||||
* <p>
|
||||
* 1. This software is for development use only under a valid license
|
||||
* from BladeX.
|
||||
* <p>
|
||||
* 2. Redistribution of this software's source code to any third party
|
||||
* without a commercial license is strictly prohibited.
|
||||
* <p>
|
||||
* 3. Licensees may copyright their own code but cannot use segments
|
||||
* from this software for such purposes. Copyright of this software
|
||||
* remains with BladeX.
|
||||
* <p>
|
||||
* Using this software signifies agreement to this License, and the software
|
||||
* must not be used for illegal purposes.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||
* not liable for any claims arising from secondary or illegal development.
|
||||
* <p>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
package ${package.Controller};
|
||||
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
||||
import lombok.AllArgsConstructor;
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
import org.springblade.core.secure.BladeUser;
|
||||
import org.springblade.core.secure.annotation.IsAdmin;
|
||||
import org.springblade.core.mp.support.Condition;
|
||||
import org.springblade.core.mp.support.Query;
|
||||
import org.springblade.core.tool.api.R;
|
||||
import org.springblade.core.tool.utils.Func;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import ${packageName!}.pojo.entity.${entityKey!}Entity;
|
||||
import ${packageName!}.pojo.vo.${entityKey!}VO;
|
||||
import ${packageName!}.excel.${entityKey!}Excel;
|
||||
#if(hasWrapper) {
|
||||
import ${packageName!}.wrapper.${entityKey!}Wrapper;
|
||||
#}
|
||||
import ${packageName!}.service.${table.serviceName!};
|
||||
#if(isNotEmpty(superControllerClassPackage)){
|
||||
import ${superControllerClassPackage!};
|
||||
#}
|
||||
import org.springblade.core.tool.utils.DateUtil;
|
||||
import org.springblade.core.excel.util.ExcelUtil;
|
||||
import org.springblade.core.tool.constant.BladeConstant;
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* ${table.comment!} 控制器
|
||||
*
|
||||
* @author ${author!}
|
||||
* @since ${date!}
|
||||
*/
|
||||
@RestController
|
||||
@AllArgsConstructor
|
||||
#if(hasServiceName) {
|
||||
@RequestMapping("${serviceName!}/${entityKeyPath!}")
|
||||
#}else{
|
||||
@RequestMapping("/${entityKeyPath!}")
|
||||
#}
|
||||
@Tag(name = "${table.comment!}", description = "${table.comment!}接口")
|
||||
#if(isNotEmpty(superControllerClass)){
|
||||
public class ${table.controllerName!} extends ${superControllerClass!} {
|
||||
#}
|
||||
#else{
|
||||
public class ${table.controllerName!} {
|
||||
#}
|
||||
|
||||
private final ${table.serviceName!} ${entityKeyPath!}Service;
|
||||
|
||||
#if(hasWrapper){
|
||||
/**
|
||||
* ${table.comment!} 详情
|
||||
*/
|
||||
@GetMapping("/detail")
|
||||
@ApiOperationSupport(order = 1)
|
||||
@Operation(summary = "详情", description = "传入${entityKeyPath!}")
|
||||
public R<${entityKey!}VO> detail(${entityKey!}Entity ${entityKeyPath!}) {
|
||||
${entityKey!}Entity detail = ${entityKeyPath!}Service.getOne(Condition.getQueryWrapper(${entityKeyPath!}));
|
||||
return R.data(${entityKey!}Wrapper.build().entityVO(detail));
|
||||
}
|
||||
|
||||
/**
|
||||
* ${table.comment!} 分页
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
@ApiOperationSupport(order = 2)
|
||||
@Operation(summary = "分页", description = "传入${entityKeyPath!}")
|
||||
public R<IPage<${entityKey!}VO>> list(@Parameter(hidden = true) @RequestParam Map<String, Object> ${entityKeyPath!}, Query query) {
|
||||
IPage<${entityKey!}Entity> pages = ${entityKeyPath!}Service.page(Condition.getPage(query), Condition.getQueryWrapper(${entityKeyPath!}, ${entityKey!}Entity.class));
|
||||
return R.data(${entityKey!}Wrapper.build().pageVO(pages));
|
||||
}
|
||||
|
||||
#}else{
|
||||
/**
|
||||
* ${table.comment!} 详情
|
||||
*/
|
||||
@GetMapping("/detail")
|
||||
@ApiOperationSupport(order = 1)
|
||||
@Operation(summary = "详情", description = "传入${entityKeyPath!}")
|
||||
public R<${entityKey!}Entity> detail(${entityKey!}Entity ${entityKeyPath!}) {
|
||||
${entityKey!}Entity detail = ${entityKeyPath!}Service.getOne(Condition.getQueryWrapper(${entityKeyPath!}));
|
||||
return R.data(detail);
|
||||
}
|
||||
|
||||
/**
|
||||
* ${table.comment!} 分页
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
@ApiOperationSupport(order = 2)
|
||||
@Operation(summary = "分页", description = "传入${entityKeyPath!}")
|
||||
public R<IPage<${entityKey!}Entity>> list(@Parameter(hidden = true) @RequestParam Map<String, Object> ${entityKeyPath!}, Query query) {
|
||||
IPage<${entityKey!}Entity> pages = ${entityKeyPath!}Service.page(Condition.getPage(query), Condition.getQueryWrapper(${entityKeyPath!}, ${entityKey!}Entity.class));
|
||||
return R.data(pages);
|
||||
}
|
||||
|
||||
#}
|
||||
|
||||
/**
|
||||
* ${table.comment!} 自定义分页
|
||||
*/
|
||||
@GetMapping("/page")
|
||||
@ApiOperationSupport(order = 3)
|
||||
@Operation(summary = "分页", description = "传入${entityKeyPath!}")
|
||||
public R<IPage<${entityKey!}VO>> page(${entityKey!}VO ${entityKeyPath!}, Query query) {
|
||||
IPage<${entityKey!}VO> pages = ${entityKeyPath!}Service.select${entityKey!}Page(Condition.getPage(query), ${entityKeyPath!});
|
||||
return R.data(pages);
|
||||
}
|
||||
|
||||
/**
|
||||
* ${table.comment!} 新增
|
||||
*/
|
||||
@PostMapping("/save")
|
||||
@ApiOperationSupport(order = 4)
|
||||
@Operation(summary = "新增", description = "传入${entityKeyPath!}")
|
||||
public R save(@Valid @RequestBody ${entityKey!}Entity ${entityKeyPath!}) {
|
||||
return R.status(${entityKeyPath!}Service.save(${entityKeyPath!}));
|
||||
}
|
||||
|
||||
/**
|
||||
* ${table.comment!} 修改
|
||||
*/
|
||||
@PostMapping("/update")
|
||||
@ApiOperationSupport(order = 5)
|
||||
@Operation(summary = "修改", description = "传入${entityKeyPath!}")
|
||||
public R update(@Valid @RequestBody ${entityKey!}Entity ${entityKeyPath!}) {
|
||||
return R.status(${entityKeyPath!}Service.updateById(${entityKeyPath!}));
|
||||
}
|
||||
|
||||
/**
|
||||
* ${table.comment!} 新增或修改
|
||||
*/
|
||||
@PostMapping("/submit")
|
||||
@ApiOperationSupport(order = 6)
|
||||
@Operation(summary = "新增或修改", description = "传入${entityKeyPath!}")
|
||||
public R submit(@Valid @RequestBody ${entityKey!}Entity ${entityKeyPath!}) {
|
||||
return R.status(${entityKeyPath!}Service.saveOrUpdate(${entityKeyPath!}));
|
||||
}
|
||||
|
||||
#if(hasSuperEntity){
|
||||
/**
|
||||
* ${table.comment!} 删除
|
||||
*/
|
||||
@PostMapping("/remove")
|
||||
@ApiOperationSupport(order = 7)
|
||||
@Operation(summary = "逻辑删除", description = "传入ids")
|
||||
public R remove(@Parameter(description = "主键集合", required = true) @RequestParam String ids) {
|
||||
return R.status(${entityKeyPath!}Service.deleteLogic(Func.toLongList(ids)));
|
||||
}
|
||||
#}else{
|
||||
/**
|
||||
* ${table.comment!} 删除
|
||||
*/
|
||||
@PostMapping("/remove")
|
||||
@ApiOperationSupport(order = 7)
|
||||
@Operation(summary = "删除", description = "传入ids")
|
||||
public R remove(@Parameter(description = "主键集合", required = true) @RequestParam String ids) {
|
||||
return R.status(${entityKeyPath!}Service.removeByIds(Func.toLongList(ids)));
|
||||
}
|
||||
#}
|
||||
|
||||
/**
|
||||
* 导出数据
|
||||
*/
|
||||
@IsAdmin
|
||||
@GetMapping("/export-${entityKeyPath!}")
|
||||
@ApiOperationSupport(order = 8)
|
||||
@Operation(summary = "导出数据", description = "传入${entityKeyPath!}")
|
||||
public void export${entityKey!}(@Parameter(hidden = true) @RequestParam Map<String, Object> ${entityKeyPath!}, BladeUser bladeUser, HttpServletResponse response) {
|
||||
QueryWrapper<${entityKey!}Entity> queryWrapper = Condition.getQueryWrapper(${entityKeyPath!}, ${entityKey!}Entity.class);
|
||||
//if (!AuthUtil.isAdministrator()) {
|
||||
// queryWrapper.lambda().eq(${entity!}::getTenantId, bladeUser.getTenantId());
|
||||
//}
|
||||
//queryWrapper.lambda().eq(${entityKey!}Entity::getIsDeleted, BladeConstant.DB_NOT_DELETED);
|
||||
List<${entityKey!}Excel> list = ${entityKeyPath!}Service.export${entityKey!}(queryWrapper);
|
||||
ExcelUtil.export(response, "${table.comment!}数据" + DateUtil.time(), "${table.comment!}数据表", list, ${entityKey!}Excel.class);
|
||||
}
|
||||
|
||||
}
|
||||
100
src/test/resources/templates/api-fast/entity.java.btl
Normal file
100
src/test/resources/templates/api-fast/entity.java.btl
Normal file
@@ -0,0 +1,100 @@
|
||||
/**
|
||||
* BladeX Commercial License Agreement
|
||||
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||
* <p>
|
||||
* Use of this software is governed by the Commercial License Agreement
|
||||
* obtained after purchasing a license from BladeX.
|
||||
* <p>
|
||||
* 1. This software is for development use only under a valid license
|
||||
* from BladeX.
|
||||
* <p>
|
||||
* 2. Redistribution of this software's source code to any third party
|
||||
* without a commercial license is strictly prohibited.
|
||||
* <p>
|
||||
* 3. Licensees may copyright their own code but cannot use segments
|
||||
* from this software for such purposes. Copyright of this software
|
||||
* remains with BladeX.
|
||||
* <p>
|
||||
* Using this software signifies agreement to this License, and the software
|
||||
* must not be used for illegal purposes.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||
* not liable for any claims arising from secondary or illegal development.
|
||||
* <p>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
package ${package.Entity!};
|
||||
|
||||
import lombok.Data;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
#for(x in table.importPackages){
|
||||
#if(isNotEmpty(x)){
|
||||
#if(hasSuperEntity&&!strutil.contain(x,"Serializable")){
|
||||
import ${x!};
|
||||
#}
|
||||
#if(!hasSuperEntity&&!strutil.contain(x,"TenantEntity")){
|
||||
import ${x!};
|
||||
#}
|
||||
#}
|
||||
#}
|
||||
#if(hasSuperEntity){
|
||||
import lombok.EqualsAndHashCode;
|
||||
#}else{
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||
#}
|
||||
import java.io.Serial;
|
||||
|
||||
/**
|
||||
* ${table.comment!} 实体类
|
||||
*
|
||||
* @author ${author!}
|
||||
* @since ${date!}
|
||||
*/
|
||||
@Data
|
||||
@TableName("${table.name!}")
|
||||
@Schema(description = "${entity!}对象")
|
||||
#if(hasSuperEntity){
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class ${entityKey!}Entity extends TenantEntity {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
#}else{
|
||||
public class ${entityKey!}Entity implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
@Schema(description = "主键")
|
||||
@TableId(value = "id", type = IdType.ASSIGN_ID)
|
||||
private Long id;
|
||||
#}
|
||||
|
||||
#for(x in table.fields) {
|
||||
#if(hasSuperEntity){
|
||||
#if(x.propertyName!="id"&&x.propertyName!="createUser"&&x.propertyName!="createDept"&&x.propertyName!="createTime"&&x.propertyName!="updateUser"&&x.propertyName!="updateTime"&&x.propertyName!="status"&&x.propertyName!="isDeleted"&&x.propertyName!="tenantId"){
|
||||
/**
|
||||
* ${x.comment!}
|
||||
*/
|
||||
@Schema(description = "${x.comment!}")
|
||||
private ${x.propertyType!} ${x.propertyName!};
|
||||
#}
|
||||
#}else{
|
||||
#if(x.propertyName!="id"){
|
||||
/**
|
||||
* ${x.comment!}
|
||||
*/
|
||||
@Schema(description = "${x.comment!}")
|
||||
private ${x.propertyType!} ${x.propertyName!};
|
||||
#}
|
||||
#}
|
||||
#}
|
||||
|
||||
}
|
||||
45
src/test/resources/templates/api-fast/entityDTO.java.btl
Normal file
45
src/test/resources/templates/api-fast/entityDTO.java.btl
Normal file
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* BladeX Commercial License Agreement
|
||||
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||
* <p>
|
||||
* Use of this software is governed by the Commercial License Agreement
|
||||
* obtained after purchasing a license from BladeX.
|
||||
* <p>
|
||||
* 1. This software is for development use only under a valid license
|
||||
* from BladeX.
|
||||
* <p>
|
||||
* 2. Redistribution of this software's source code to any third party
|
||||
* without a commercial license is strictly prohibited.
|
||||
* <p>
|
||||
* 3. Licensees may copyright their own code but cannot use segments
|
||||
* from this software for such purposes. Copyright of this software
|
||||
* remains with BladeX.
|
||||
* <p>
|
||||
* Using this software signifies agreement to this License, and the software
|
||||
* must not be used for illegal purposes.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||
* not liable for any claims arising from secondary or illegal development.
|
||||
* <p>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
package ${strutil.replace(package.Entity,"entity","dto")};
|
||||
|
||||
import ${packageName!}.pojo.entity.${entityKey!}Entity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import java.io.Serial;
|
||||
|
||||
/**
|
||||
* ${table.comment!} 数据传输对象实体类
|
||||
*
|
||||
* @author ${author!}
|
||||
* @since ${date!}
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class ${entityKey!}DTO extends ${entityKey!}Entity {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
}
|
||||
69
src/test/resources/templates/api-fast/entityExcel.java.btl
Normal file
69
src/test/resources/templates/api-fast/entityExcel.java.btl
Normal file
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
* BladeX Commercial License Agreement
|
||||
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||
* <p>
|
||||
* Use of this software is governed by the Commercial License Agreement
|
||||
* obtained after purchasing a license from BladeX.
|
||||
* <p>
|
||||
* 1. This software is for development use only under a valid license
|
||||
* from BladeX.
|
||||
* <p>
|
||||
* 2. Redistribution of this software's source code to any third party
|
||||
* without a commercial license is strictly prohibited.
|
||||
* <p>
|
||||
* 3. Licensees may copyright their own code but cannot use segments
|
||||
* from this software for such purposes. Copyright of this software
|
||||
* remains with BladeX.
|
||||
* <p>
|
||||
* Using this software signifies agreement to this License, and the software
|
||||
* must not be used for illegal purposes.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||
* not liable for any claims arising from secondary or illegal development.
|
||||
* <p>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
package ${strutil.replace(package.Entity,"pojo.entity","excel")};
|
||||
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
#for(x in table.importPackages){
|
||||
#if(isNotEmpty(x)&&!strutil.contain(x,"TableName")&&!strutil.contain(x,"TenantEntity")){
|
||||
import ${x!};
|
||||
#}
|
||||
#}
|
||||
import cn.idev.excel.annotation.ExcelProperty;
|
||||
import cn.idev.excel.annotation.write.style.ColumnWidth;
|
||||
import cn.idev.excel.annotation.write.style.ContentRowHeight;
|
||||
import cn.idev.excel.annotation.write.style.HeadRowHeight;
|
||||
import java.io.Serial;
|
||||
|
||||
|
||||
/**
|
||||
* ${table.comment!} Excel实体类
|
||||
*
|
||||
* @author ${author!}
|
||||
* @since ${date!}
|
||||
*/
|
||||
@Data
|
||||
@ColumnWidth(25)
|
||||
@HeadRowHeight(20)
|
||||
@ContentRowHeight(18)
|
||||
public class ${entityKey!}Excel implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
#for(x in table.fields) {
|
||||
#if(x.propertyName!="createUser"&&x.propertyName!="createDept"&&x.propertyName!="createTime"&&x.propertyName!="updateUser"&&x.propertyName!="updateTime"){
|
||||
/**
|
||||
* ${x.comment!}
|
||||
*/
|
||||
@ColumnWidth(20)
|
||||
@ExcelProperty("${x.comment!}")
|
||||
private ${x.propertyType!} ${x.propertyName!};
|
||||
#}
|
||||
#}
|
||||
|
||||
}
|
||||
45
src/test/resources/templates/api-fast/entityVO.java.btl
Normal file
45
src/test/resources/templates/api-fast/entityVO.java.btl
Normal file
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* BladeX Commercial License Agreement
|
||||
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||
* <p>
|
||||
* Use of this software is governed by the Commercial License Agreement
|
||||
* obtained after purchasing a license from BladeX.
|
||||
* <p>
|
||||
* 1. This software is for development use only under a valid license
|
||||
* from BladeX.
|
||||
* <p>
|
||||
* 2. Redistribution of this software's source code to any third party
|
||||
* without a commercial license is strictly prohibited.
|
||||
* <p>
|
||||
* 3. Licensees may copyright their own code but cannot use segments
|
||||
* from this software for such purposes. Copyright of this software
|
||||
* remains with BladeX.
|
||||
* <p>
|
||||
* Using this software signifies agreement to this License, and the software
|
||||
* must not be used for illegal purposes.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||
* not liable for any claims arising from secondary or illegal development.
|
||||
* <p>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
package ${strutil.replace(package.Entity,"entity","vo")};
|
||||
|
||||
import ${packageName!}.pojo.entity.${entityKey!}Entity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import java.io.Serial;
|
||||
|
||||
/**
|
||||
* ${table.comment!} 视图实体类
|
||||
*
|
||||
* @author ${author!}
|
||||
* @since ${date!}
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class ${entityKey!}VO extends ${entityKey!}Entity {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
}
|
||||
62
src/test/resources/templates/api-fast/mapper.java.btl
Normal file
62
src/test/resources/templates/api-fast/mapper.java.btl
Normal file
@@ -0,0 +1,62 @@
|
||||
/**
|
||||
* BladeX Commercial License Agreement
|
||||
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||
* <p>
|
||||
* Use of this software is governed by the Commercial License Agreement
|
||||
* obtained after purchasing a license from BladeX.
|
||||
* <p>
|
||||
* 1. This software is for development use only under a valid license
|
||||
* from BladeX.
|
||||
* <p>
|
||||
* 2. Redistribution of this software's source code to any third party
|
||||
* without a commercial license is strictly prohibited.
|
||||
* <p>
|
||||
* 3. Licensees may copyright their own code but cannot use segments
|
||||
* from this software for such purposes. Copyright of this software
|
||||
* remains with BladeX.
|
||||
* <p>
|
||||
* Using this software signifies agreement to this License, and the software
|
||||
* must not be used for illegal purposes.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||
* not liable for any claims arising from secondary or illegal development.
|
||||
* <p>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
package ${package.Mapper!};
|
||||
|
||||
import ${packageName!}.pojo.entity.${entityKey!}Entity;
|
||||
import ${packageName!}.pojo.vo.${entityKey!}VO;
|
||||
import ${packageName!}.excel.${entityKey!}Excel;
|
||||
import ${superMapperClassPackage!};
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* ${table.comment!} Mapper 接口
|
||||
*
|
||||
* @author ${author!}
|
||||
* @since ${date!}
|
||||
*/
|
||||
public interface ${table.mapperName!} extends ${superMapperClass!}<${entityKey!}Entity> {
|
||||
|
||||
/**
|
||||
* 自定义分页
|
||||
*
|
||||
* @param page 分页参数
|
||||
* @param ${entityKeyPath!} 查询参数
|
||||
* @return List<${entityKey!}VO>
|
||||
*/
|
||||
List<${entityKey!}VO> select${entityKey!}Page(IPage page, ${entityKey!}VO ${entityKeyPath!});
|
||||
|
||||
/**
|
||||
* 获取导出数据
|
||||
*
|
||||
* @param queryWrapper 查询条件
|
||||
* @return List<${entityKey!}Excel>
|
||||
*/
|
||||
List<${entityKey!}Excel> export${entityKey!}(@Param("ew") Wrapper<${entityKey!}Entity> queryWrapper);
|
||||
|
||||
}
|
||||
24
src/test/resources/templates/api-fast/mapper.xml.btl
Normal file
24
src/test/resources/templates/api-fast/mapper.xml.btl
Normal file
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="${package.Mapper!}.${table.mapperName!}">
|
||||
|
||||
#if(enableCache){
|
||||
<!-- 开启二级缓存 -->
|
||||
<cache type="org.mybatis.caches.ehcache.LoggingEhcache"/>
|
||||
#}
|
||||
<!-- 通用查询映射结果 -->
|
||||
<resultMap id="${entityKeyPath!}ResultMap" type="${package.Entity!}.${entityKey!}Entity">
|
||||
#for(x in table.fields) {
|
||||
<result column="${x.name!}" property="${x.propertyName!}"/>
|
||||
#}
|
||||
</resultMap>
|
||||
|
||||
<select id="select${entityKey!}Page" resultMap="${entityKeyPath!}ResultMap">
|
||||
select * from ${table.name} where is_deleted = 0
|
||||
</select>
|
||||
|
||||
<select id="export${entityKey!}" resultType="${packageName!}.excel.${entityKey!}Excel">
|
||||
SELECT * FROM ${table.name!} \${ew.customSqlSegment}
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
68
src/test/resources/templates/api-fast/service.java.btl
Normal file
68
src/test/resources/templates/api-fast/service.java.btl
Normal file
@@ -0,0 +1,68 @@
|
||||
/**
|
||||
* BladeX Commercial License Agreement
|
||||
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||
* <p>
|
||||
* Use of this software is governed by the Commercial License Agreement
|
||||
* obtained after purchasing a license from BladeX.
|
||||
* <p>
|
||||
* 1. This software is for development use only under a valid license
|
||||
* from BladeX.
|
||||
* <p>
|
||||
* 2. Redistribution of this software's source code to any third party
|
||||
* without a commercial license is strictly prohibited.
|
||||
* <p>
|
||||
* 3. Licensees may copyright their own code but cannot use segments
|
||||
* from this software for such purposes. Copyright of this software
|
||||
* remains with BladeX.
|
||||
* <p>
|
||||
* Using this software signifies agreement to this License, and the software
|
||||
* must not be used for illegal purposes.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||
* not liable for any claims arising from secondary or illegal development.
|
||||
* <p>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
package ${package.Service!};
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import ${packageName!}.pojo.entity.${entityKey!}Entity;
|
||||
import ${packageName!}.pojo.vo.${entityKey!}VO;
|
||||
import ${packageName!}.excel.${entityKey!}Excel;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
#if(hasSuperEntity){
|
||||
import ${superServiceClassPackage!};
|
||||
#}else{
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
#}
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* ${table.comment!} 服务类
|
||||
*
|
||||
* @author ${author!}
|
||||
* @since ${date!}
|
||||
*/
|
||||
#if(hasSuperEntity){
|
||||
public interface ${table.serviceName!} extends ${superServiceClass!}<${entity!}> {
|
||||
#}else{
|
||||
public interface ${table.serviceName!} extends IService<${entity!}> {
|
||||
#}
|
||||
/**
|
||||
* 自定义分页
|
||||
*
|
||||
* @param page 分页参数
|
||||
* @param ${entityKeyPath!} 查询参数
|
||||
* @return IPage<${entityKey!}VO>
|
||||
*/
|
||||
IPage<${entityKey!}VO> select${entityKey!}Page(IPage<${entityKey!}VO> page, ${entityKey!}VO ${entityKeyPath!});
|
||||
|
||||
/**
|
||||
* 导出数据
|
||||
*
|
||||
* @param queryWrapper 查询条件
|
||||
* @return List<${entityKey!}Excel>
|
||||
*/
|
||||
List<${entityKey!}Excel> export${entityKey!}(Wrapper<${entityKey!}Entity> queryWrapper);
|
||||
|
||||
}
|
||||
70
src/test/resources/templates/api-fast/serviceImpl.java.btl
Normal file
70
src/test/resources/templates/api-fast/serviceImpl.java.btl
Normal file
@@ -0,0 +1,70 @@
|
||||
/**
|
||||
* BladeX Commercial License Agreement
|
||||
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||
* <p>
|
||||
* Use of this software is governed by the Commercial License Agreement
|
||||
* obtained after purchasing a license from BladeX.
|
||||
* <p>
|
||||
* 1. This software is for development use only under a valid license
|
||||
* from BladeX.
|
||||
* <p>
|
||||
* 2. Redistribution of this software's source code to any third party
|
||||
* without a commercial license is strictly prohibited.
|
||||
* <p>
|
||||
* 3. Licensees may copyright their own code but cannot use segments
|
||||
* from this software for such purposes. Copyright of this software
|
||||
* remains with BladeX.
|
||||
* <p>
|
||||
* Using this software signifies agreement to this License, and the software
|
||||
* must not be used for illegal purposes.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||
* not liable for any claims arising from secondary or illegal development.
|
||||
* <p>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
package ${package.ServiceImpl!};
|
||||
|
||||
import ${packageName!}.pojo.entity.${entityKey!}Entity;
|
||||
import ${packageName!}.pojo.vo.${entityKey!}VO;
|
||||
import ${packageName!}.excel.${entityKey!}Excel;
|
||||
import ${packageName!}.mapper.${table.mapperName!};
|
||||
import ${packageName!}.service.${table.serviceName!};
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
#if(hasSuperEntity){
|
||||
import ${superServiceImplClassPackage!};
|
||||
#}else{
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
#}
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* ${table.comment!} 服务实现类
|
||||
*
|
||||
* @author ${author!}
|
||||
* @since ${date!}
|
||||
*/
|
||||
@Service
|
||||
#if(hasSuperEntity){
|
||||
public class ${table.serviceImplName!} extends ${superServiceImplClass!}<${table.mapperName!}, ${entity!}> implements ${table.serviceName!} {
|
||||
#}else{
|
||||
public class ${table.serviceImplName!} extends ServiceImpl<${table.mapperName!}, ${entity!}> implements ${table.serviceName!} {
|
||||
#}
|
||||
|
||||
@Override
|
||||
public IPage<${entityKey!}VO> select${entityKey!}Page(IPage<${entityKey!}VO> page, ${entityKey!}VO ${entityKeyPath!}) {
|
||||
return page.setRecords(baseMapper.select${entityKey!}Page(page, ${entityKeyPath!}));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<${entityKey!}Excel> export${entityKey!}(Wrapper<${entityKey!}Entity> queryWrapper) {
|
||||
List<${entityKey!}Excel> ${entityKeyPath!}List = baseMapper.export${entityKey!}(queryWrapper);
|
||||
//${entityKeyPath!}List.forEach(${entityKeyPath!} -> {
|
||||
// ${entityKeyPath!}.setTypeName(DictCache.getValue(DictEnum.YES_NO, ${entity!}.getType()));
|
||||
//});
|
||||
return ${entityKeyPath!}List;
|
||||
}
|
||||
|
||||
}
|
||||
58
src/test/resources/templates/api-fast/wrapper.java.btl
Normal file
58
src/test/resources/templates/api-fast/wrapper.java.btl
Normal file
@@ -0,0 +1,58 @@
|
||||
/**
|
||||
* BladeX Commercial License Agreement
|
||||
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||
* <p>
|
||||
* Use of this software is governed by the Commercial License Agreement
|
||||
* obtained after purchasing a license from BladeX.
|
||||
* <p>
|
||||
* 1. This software is for development use only under a valid license
|
||||
* from BladeX.
|
||||
* <p>
|
||||
* 2. Redistribution of this software's source code to any third party
|
||||
* without a commercial license is strictly prohibited.
|
||||
* <p>
|
||||
* 3. Licensees may copyright their own code but cannot use segments
|
||||
* from this software for such purposes. Copyright of this software
|
||||
* remains with BladeX.
|
||||
* <p>
|
||||
* Using this software signifies agreement to this License, and the software
|
||||
* must not be used for illegal purposes.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||
* not liable for any claims arising from secondary or illegal development.
|
||||
* <p>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
package ${strutil.replace(package.Entity,"pojo.entity","wrapper")};
|
||||
|
||||
import org.springblade.core.mp.support.BaseEntityWrapper;
|
||||
import org.springblade.core.tool.utils.BeanUtil;
|
||||
import ${packageName!}.pojo.entity.${entityKey!}Entity;
|
||||
import ${packageName!}.pojo.vo.${entityKey!}VO;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* ${table.comment!} 包装类,返回视图层所需的字段
|
||||
*
|
||||
* @author ${author!}
|
||||
* @since ${date!}
|
||||
*/
|
||||
public class ${entityKey!}Wrapper extends BaseEntityWrapper<${entityKey!}Entity, ${entityKey!}VO> {
|
||||
|
||||
public static ${entityKey!}Wrapper build() {
|
||||
return new ${entityKey!}Wrapper();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ${entityKey!}VO entityVO(${entityKey!}Entity ${entityKeyPath!}) {
|
||||
${entityKey!}VO ${entityKeyPath!}VO = Objects.requireNonNull(BeanUtil.copyProperties(${entityKeyPath!}, ${entityKey!}VO.class));
|
||||
|
||||
//User createUser = UserCache.getUser(${entityKeyPath!}.getCreateUser());
|
||||
//User updateUser = UserCache.getUser(${entityKeyPath!}.getUpdateUser());
|
||||
//${entityKeyPath!}VO.setCreateUserName(createUser.getName());
|
||||
//${entityKeyPath!}VO.setUpdateUserName(updateUser.getName());
|
||||
|
||||
return ${entityKeyPath!}VO;
|
||||
}
|
||||
|
||||
}
|
||||
5
src/test/resources/templates/code.properties
Normal file
5
src/test/resources/templates/code.properties
Normal file
@@ -0,0 +1,5 @@
|
||||
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
||||
spring.datasource.url=jdbc:mysql://localhost:3306/bladex?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&tinyInt1isBit=false&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true
|
||||
spring.datasource.username=root
|
||||
spring.datasource.password=root
|
||||
author=BladeX
|
||||
Reference in New Issue
Block a user