2022-12-30 10:58:54 +08:00
|
|
|
|
package com.xaaef.molly;
|
|
|
|
|
|
|
2023-01-06 18:32:40 +08:00
|
|
|
|
import cn.hutool.core.io.FileUtil;
|
2023-03-06 16:43:38 +08:00
|
|
|
|
import cn.hutool.core.lang.tree.Tree;
|
|
|
|
|
|
import cn.hutool.core.lang.tree.TreeNode;
|
|
|
|
|
|
import cn.hutool.core.lang.tree.TreeUtil;
|
2023-02-06 18:32:22 +08:00
|
|
|
|
import cn.hutool.core.util.IdUtil;
|
2023-11-03 14:29:40 +08:00
|
|
|
|
import com.mysql.cj.jdbc.MysqlDataSource;
|
2023-05-16 21:44:15 +08:00
|
|
|
|
import com.xaaef.molly.auth.jwt.JwtSecurityUtils;
|
2023-11-10 18:06:53 +08:00
|
|
|
|
import com.xaaef.molly.common.consts.JwtConst;
|
2023-11-23 14:29:39 +08:00
|
|
|
|
import com.xaaef.molly.common.util.ExcelUtils;
|
2023-03-06 16:43:38 +08:00
|
|
|
|
import com.xaaef.molly.common.util.JsonUtils;
|
2023-11-29 18:37:54 +08:00
|
|
|
|
import com.xaaef.molly.internal.dto.OperateUserDTO;
|
|
|
|
|
|
import io.swagger.v3.oas.annotations.media.Schema;
|
2023-11-03 14:29:40 +08:00
|
|
|
|
import liquibase.integration.spring.MultiTenantSpringLiquibase;
|
2023-11-29 18:37:54 +08:00
|
|
|
|
import lombok.*;
|
|
|
|
|
|
import lombok.experimental.Accessors;
|
2022-12-30 10:58:54 +08:00
|
|
|
|
import org.junit.jupiter.api.Test;
|
2023-11-03 14:29:40 +08:00
|
|
|
|
import org.springframework.core.io.FileSystemResourceLoader;
|
2022-12-30 10:58:54 +08:00
|
|
|
|
|
2023-11-23 14:29:39 +08:00
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
import java.nio.file.Files;
|
|
|
|
|
|
import java.nio.file.Path;
|
2023-03-22 16:02:15 +08:00
|
|
|
|
import java.time.Duration;
|
2022-12-30 10:58:54 +08:00
|
|
|
|
import java.time.LocalDate;
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
|
|
import java.time.LocalTime;
|
2023-10-25 11:57:04 +08:00
|
|
|
|
import java.util.List;
|
2023-11-10 18:06:53 +08:00
|
|
|
|
import java.util.Map;
|
2023-02-04 17:20:41 +08:00
|
|
|
|
import java.util.regex.Pattern;
|
2023-11-10 18:06:53 +08:00
|
|
|
|
import java.util.stream.Stream;
|
2023-03-26 01:37:22 +08:00
|
|
|
|
|
|
|
|
|
|
import static com.xaaef.molly.common.util.IpUtils.getLocalIPS;
|
2022-12-30 10:58:54 +08:00
|
|
|
|
|
|
|
|
|
|
|
2023-10-26 11:33:48 +08:00
|
|
|
|
public class NoSpringTests {
|
2022-12-30 10:58:54 +08:00
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
public void test1() {
|
|
|
|
|
|
boolean after = LocalDateTime.now().isAfter(LocalDateTime.of(LocalDate.of(2023, 12, 28), LocalTime.MAX));
|
|
|
|
|
|
System.out.println(after);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-01-06 18:32:40 +08:00
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
public void test3() {
|
|
|
|
|
|
System.out.println(FileUtil.extName("https://images.xaaef.com/base/63b7df8b9e8581f5bff107e2.jpg"));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-02-04 17:20:41 +08:00
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
public void test4() {
|
|
|
|
|
|
boolean isMatch = Pattern.matches("\\w{4,12}$", "你好啊啊啊dwa541");
|
|
|
|
|
|
System.out.println(isMatch);
|
|
|
|
|
|
}
|
2023-03-06 16:43:38 +08:00
|
|
|
|
|
|
|
|
|
|
|
2023-02-06 18:32:22 +08:00
|
|
|
|
@Test
|
|
|
|
|
|
public void test5() {
|
|
|
|
|
|
byte[] bytes = IdUtil.getSnowflakeNextIdStr().getBytes();
|
|
|
|
|
|
System.out.println(new String(bytes));
|
|
|
|
|
|
System.out.println(bytes.length);
|
|
|
|
|
|
}
|
2023-02-04 17:20:41 +08:00
|
|
|
|
|
|
|
|
|
|
|
2023-03-06 16:43:38 +08:00
|
|
|
|
@Test
|
|
|
|
|
|
public void test6() {
|
|
|
|
|
|
var treeNodes = List.of(
|
|
|
|
|
|
new TreeNode<>(1001, 10, "部门1", 1),
|
|
|
|
|
|
new TreeNode<>(1002, 11, "部门2", 3),
|
|
|
|
|
|
new TreeNode<>(1003, 1002, "部门2", 4),
|
|
|
|
|
|
new TreeNode<>(1004, 1002, "部门2", 5),
|
|
|
|
|
|
new TreeNode<>(1005, 1001, "部门2", 6)
|
|
|
|
|
|
);
|
|
|
|
|
|
var first = treeNodes.stream().map(TreeNode::getParentId).sorted().findFirst().get();
|
|
|
|
|
|
List<Tree<Integer>> build = TreeUtil.build(treeNodes, first);
|
|
|
|
|
|
System.out.println(JsonUtils.toFormatJson(build));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-03-22 16:02:15 +08:00
|
|
|
|
@Test
|
|
|
|
|
|
public void test7() {
|
|
|
|
|
|
var l = Duration.ofMinutes(1).toMillis();
|
|
|
|
|
|
System.out.println(l);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-03-26 01:37:22 +08:00
|
|
|
|
@Test
|
|
|
|
|
|
public void test8() {
|
|
|
|
|
|
var port = 19222;
|
|
|
|
|
|
getLocalIPS().stream()
|
|
|
|
|
|
.map(ip -> String.format("http://%s:%d/doc.html", ip, port))
|
|
|
|
|
|
.forEach(System.out::println);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-05-16 21:44:15 +08:00
|
|
|
|
@Test
|
|
|
|
|
|
public void test9() {
|
|
|
|
|
|
System.out.println(JwtSecurityUtils.encryptPassword("test123456"));
|
|
|
|
|
|
System.out.println(JwtSecurityUtils.encryptPassword("test456789"));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-11-03 14:29:40 +08:00
|
|
|
|
@Test
|
|
|
|
|
|
public void test10() throws Exception {
|
|
|
|
|
|
var ds1 = new MysqlDataSource();
|
|
|
|
|
|
ds1.setURL("jdbc:mysql://192.168.0.188:3306/hello1?characterEncoding=utf8&useSSL=false");
|
|
|
|
|
|
ds1.setUser("test123");
|
|
|
|
|
|
ds1.setPassword("mht123456");
|
|
|
|
|
|
var liquibase1 = new MultiTenantSpringLiquibase();
|
|
|
|
|
|
liquibase1.setDataSource(ds1);
|
|
|
|
|
|
liquibase1.setResourceLoader(new FileSystemResourceLoader());
|
|
|
|
|
|
liquibase1.setChangeLog("C:\\Users\\demo\\code\\javaProjects\\molly-multi-tenant\\server\\molly-service\\src\\main\\resources\\db\\changelog-other.xml");
|
2023-11-08 17:20:45 +08:00
|
|
|
|
liquibase1.setSchemas(List.of("hello1", "hello2"));
|
2023-11-03 14:29:40 +08:00
|
|
|
|
liquibase1.afterPropertiesSet();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-11-10 18:06:53 +08:00
|
|
|
|
@Test
|
|
|
|
|
|
public void test11() throws Exception {
|
|
|
|
|
|
// 登录接口,也需要,添加租户ID
|
|
|
|
|
|
var whiteList = Stream.of(JwtConst.WHITE_LIST, JwtConst.TENANT_WHITE_LIST)
|
|
|
|
|
|
.flatMap(Stream::of)
|
|
|
|
|
|
.filter(s -> !JwtConst.LOGIN_URL.equals(s))
|
|
|
|
|
|
.distinct()
|
2023-11-23 14:29:39 +08:00
|
|
|
|
.toList();
|
2023-11-10 18:06:53 +08:00
|
|
|
|
String formatJson = JsonUtils.toFormatJson(Map.of(
|
|
|
|
|
|
"data", whiteList,
|
|
|
|
|
|
"time", LocalTime.now()
|
|
|
|
|
|
));
|
|
|
|
|
|
System.out.println(formatJson);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-11-29 18:37:54 +08:00
|
|
|
|
@Getter
|
|
|
|
|
|
@Setter
|
|
|
|
|
|
@Builder
|
|
|
|
|
|
@Accessors(chain = true)
|
|
|
|
|
|
@AllArgsConstructor
|
|
|
|
|
|
@NoArgsConstructor
|
|
|
|
|
|
public static class TestExportEntity implements java.io.Serializable {
|
|
|
|
|
|
|
|
|
|
|
|
@Schema(description = "ID")
|
|
|
|
|
|
private Long id;
|
|
|
|
|
|
|
|
|
|
|
|
@Schema(description = "名称")
|
|
|
|
|
|
private String name;
|
|
|
|
|
|
|
|
|
|
|
|
@Schema(description = "爱好")
|
|
|
|
|
|
protected List<String> hobby;
|
|
|
|
|
|
|
|
|
|
|
|
@Schema(description = "创建日期")
|
|
|
|
|
|
protected LocalDate createDate;
|
|
|
|
|
|
|
|
|
|
|
|
@Schema(description = "创建时间")
|
|
|
|
|
|
protected LocalTime createTime;
|
|
|
|
|
|
|
|
|
|
|
|
@Schema(description = "创建日期时间")
|
|
|
|
|
|
protected LocalDateTime createDateTime;
|
|
|
|
|
|
|
|
|
|
|
|
@Schema(description = "创建人信息")
|
|
|
|
|
|
protected OperateUserDTO createUserEntity;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-11-10 18:06:53 +08:00
|
|
|
|
|
2023-11-23 14:29:39 +08:00
|
|
|
|
@Test
|
|
|
|
|
|
public void test12() throws IOException {
|
|
|
|
|
|
var treeNodes = List.of(
|
2023-11-29 18:37:54 +08:00
|
|
|
|
new TestExportEntity(1001L, "角色1", List.of("A1", "B1"), LocalDate.now(), LocalTime.now(), LocalDateTime.now(), new OperateUserDTO(1L, "a", "张三")),
|
|
|
|
|
|
new TestExportEntity(1002L, "角色2", List.of("A2", "B2"), LocalDate.now(), LocalTime.now(), LocalDateTime.now(), new OperateUserDTO(2L, "b", "李四")),
|
|
|
|
|
|
new TestExportEntity(1003L, "角色3", List.of("A3", "B3"), LocalDate.now(), LocalTime.now(), LocalDateTime.now(), new OperateUserDTO(3L, "c", "王五")),
|
|
|
|
|
|
new TestExportEntity(1004L, "角色4", List.of("A4", "B4"), LocalDate.now(), LocalTime.now(), LocalDateTime.now(), new OperateUserDTO(4L, "d", "陈六")),
|
|
|
|
|
|
new TestExportEntity(1005L, "角色5", List.of("A5", "B5"), LocalDate.now(), LocalTime.now(), LocalDateTime.now(), new OperateUserDTO(5L, "e", "赵七"))
|
2023-11-23 14:29:39 +08:00
|
|
|
|
);
|
|
|
|
|
|
var entity = ExcelUtils.deviceExport("aa.xlsx", treeNodes);
|
|
|
|
|
|
var file = Files.createFile(Path.of("aa.xlsx")).toFile();
|
|
|
|
|
|
FileUtil.writeFromStream(entity.getBody().getInputStream(), file, true);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-12-30 10:58:54 +08:00
|
|
|
|
}
|