clazz) {
29 | return new ArrayList<>(toBeanCollection(collection, clazz));
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/dunwu-tool/dunwu-tool-core/src/main/java/io/github/dunwu/tool/bean/TypeConvert.java:
--------------------------------------------------------------------------------
1 | package io.github.dunwu.tool.bean;
2 |
3 | /**
4 | * Bean 类型转换接口
5 | *
6 | * @author Zhang Peng
7 | * @since 2020-04-25
8 | */
9 | public interface TypeConvert {
10 |
11 | /**
12 | * 将类型 S 转换为 T
13 | *
14 | * @param origin 要转换的对象
15 | * @return /
16 | */
17 | T transform(S origin);
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/dunwu-tool/dunwu-tool-core/src/main/java/io/github/dunwu/tool/bean/support/NamingStrategy.java:
--------------------------------------------------------------------------------
1 | package io.github.dunwu.tool.bean.support;
2 |
3 | /**
4 | * 关键字命名策略枚举
5 | *
6 | * @author Zhang Peng
7 | * @since 2019-12-18
8 | */
9 | public enum NamingStrategy {
10 | /**
11 | * 默认命名。即不对命名做任何要求
12 | */
13 | DEFAULT,
14 | /**
15 | * 驼峰命名。例:namingStrategy
16 | */
17 | CAMEL,
18 | /**
19 | * 全小写字母用下划线拼接。例:naming_strategy
20 | */
21 | LOWER_UNDERLINE,
22 | /**
23 | * 全大写字母用下划线拼接。例:NAMING_STRATEGY
24 | */
25 | UPPER_UNDERLINE,
26 | /**
27 | * 全小写字母用分割线拼接。例:naming-strategy
28 | */
29 | LOWER_DASHED,
30 | /**
31 | * 全小写字母用分割线拼接。例:NAMING-STRATEGY
32 | */
33 | UPPER_DASHED
34 | }
35 |
--------------------------------------------------------------------------------
/dunwu-tool/dunwu-tool-core/src/main/java/io/github/dunwu/tool/codec/MessageDigestUtil.java:
--------------------------------------------------------------------------------
1 | package io.github.dunwu.tool.codec;
2 |
3 | import cn.hutool.core.codec.Base64;
4 |
5 | import java.security.MessageDigest;
6 | import java.security.NoSuchAlgorithmException;
7 |
8 | /**
9 | * @author Zhang Peng
10 | * @since 2020-03-11
11 | */
12 | public class MessageDigestUtil {
13 |
14 | private MessageDigestUtil() { }
15 |
16 | public static String encodeWithBase64(String type, byte[] input, byte[] salt) throws NoSuchAlgorithmException {
17 | return Base64.encodeUrlSafe(encode(type, input, salt));
18 | }
19 |
20 | public static byte[] encode(String type, byte[] input, byte[] salt) throws NoSuchAlgorithmException {
21 | // 根据类型,初始化消息摘要对象
22 | MessageDigest digest = MessageDigest.getInstance(type);
23 |
24 | // 更新要计算的内容
25 | if (salt != null) {
26 | digest.reset();
27 | digest.update(salt);
28 | }
29 |
30 | // 完成哈希计算,返回摘要
31 | return digest.digest(input);
32 | }
33 |
34 | public static String encodeWithBase64(Type type, byte[] input, byte[] salt) throws NoSuchAlgorithmException {
35 | return Base64.encodeUrlSafe(encode(type, input, salt));
36 | }
37 |
38 | public static byte[] encode(Type type, byte[] input, byte[] salt) throws NoSuchAlgorithmException {
39 | return encode(type.name, input, salt);
40 | }
41 |
42 | enum Type {
43 |
44 | MD2("MD2"),
45 | MD5("MD5"),
46 | SHA1("SHA1"),
47 | SHA256("SHA-256"),
48 | SHA384("SHA-384"),
49 | SHA512("SHA-512");
50 |
51 | private String name;
52 |
53 | Type(String name) {
54 | this.name = name;
55 | }
56 |
57 | public String getName() {
58 | return this.name;
59 | }
60 | }
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/dunwu-tool/dunwu-tool-core/src/main/java/io/github/dunwu/tool/codec/SymmetricEncode.java:
--------------------------------------------------------------------------------
1 | package io.github.dunwu.tool.codec;
2 |
3 | import java.security.GeneralSecurityException;
4 | import java.util.Base64;
5 |
6 | /**
7 | * 对称加密接口
8 | *
9 | * @author Zhang Peng
10 | * @since 2020-03-14
11 | */
12 | public interface SymmetricEncode extends Encode {
13 |
14 | /**
15 | * 对二进制密文解密,返回二进制
16 | *
17 | * @param ciphertext 密文
18 | * @return byte[] 明文
19 | * @throws GeneralSecurityException
20 | */
21 | byte[] decode(byte[] ciphertext) throws GeneralSecurityException;
22 |
23 | /**
24 | * 对二进制密文解密,返回字符串
25 | *
26 | * @param ciphertext 密文
27 | * @return String 明文
28 | * @throws GeneralSecurityException
29 | */
30 | default String decodeStr(byte[] ciphertext) throws GeneralSecurityException {
31 | return new String(decode(ciphertext));
32 | }
33 |
34 | /**
35 | * 对 Base64 二次编码后的密文进行解密
36 | *
37 | * @param ciphertext 密文
38 | * @return 明文
39 | * @throws GeneralSecurityException
40 | */
41 | default byte[] decodeFromBase64(String ciphertext) throws GeneralSecurityException {
42 | return decode(Base64.getUrlDecoder().decode(ciphertext));
43 | }
44 |
45 | /**
46 | * 对 Base64 二次编码后的密文进行解密
47 | *
48 | * @param ciphertext 密文
49 | * @return 明文
50 | * @throws GeneralSecurityException
51 | */
52 | default String decodeStrFromBase64(String ciphertext) throws GeneralSecurityException {
53 | return new String(decodeFromBase64(ciphertext));
54 | }
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/dunwu-tool/dunwu-tool-core/src/main/java/io/github/dunwu/tool/codec/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * BaseN以及BCD编码封装
3 | *
4 | * @author looly
5 | */
6 | package io.github.dunwu.tool.codec;
7 |
--------------------------------------------------------------------------------
/dunwu-tool/dunwu-tool-core/src/main/java/io/github/dunwu/tool/core/constant/CodeMsg.java:
--------------------------------------------------------------------------------
1 | package io.github.dunwu.tool.core.constant;
2 |
3 | /**
4 | * 请求 / 应答状态接口
5 | *
6 | * @author Zhang Peng
7 | * @since 2019-06-06
8 | */
9 | public interface CodeMsg {
10 |
11 | int getCode();
12 |
13 | String getMsg();
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/dunwu-tool/dunwu-tool-core/src/main/java/io/github/dunwu/tool/core/constant/DunwuConstant.java:
--------------------------------------------------------------------------------
1 | package io.github.dunwu.tool.core.constant;
2 |
3 | /**
4 | * 常量
5 | *
6 | * @author Zhang Peng
7 | * @since 2020-03-14
8 | */
9 | public class DunwuConstant {
10 |
11 | /**
12 | * 注册用户角色ID
13 | */
14 | public static final Long REGISTER_ROLE_ID = 2L;
15 |
16 | /**
17 | * 排序规则:降序
18 | */
19 | public static final String ORDER_DESC = "desc";
20 |
21 | /**
22 | * 排序规则:升序
23 | */
24 | public static final String ORDER_ASC = "asc";
25 |
26 | /**
27 | * 前端页面路径前缀
28 | */
29 | public static final String VIEW_PREFIX = "febs/views/";
30 |
31 | /**
32 | * 验证码 Session Key
33 | */
34 | public static final String CODE_PREFIX = "dunwu_captcha_";
35 |
36 | /**
37 | * 允许下载的文件类型,根据需求自己添加(小写)
38 | */
39 | public static final String[] VALID_FILE_TYPE = { "xlsx", "zip" };
40 |
41 | /**
42 | * 异步线程池名称
43 | */
44 | public static final String ASYNC_POOL = "dunwuAsyncThreadPool";
45 |
46 | /**
47 | * 开发环境
48 | */
49 | public static final String DEVELOP = "dev";
50 |
51 | /**
52 | * Windows 操作系统
53 | */
54 | public static final String SYSTEM_WINDOWS = "windows";
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/dunwu-tool/dunwu-tool-core/src/main/java/io/github/dunwu/tool/core/constant/GetDesc.java:
--------------------------------------------------------------------------------
1 | package io.github.dunwu.tool.core.constant;
2 |
3 | /**
4 | * @author peng.zhang
5 | * @date 2021-09-26
6 | */
7 | public interface GetDesc {
8 |
9 | String getDesc();
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/dunwu-tool/dunwu-tool-core/src/main/java/io/github/dunwu/tool/core/constant/GetIntCode.java:
--------------------------------------------------------------------------------
1 | package io.github.dunwu.tool.core.constant;
2 |
3 | /**
4 | * @author Zhang Peng
5 | * @since 2019-07-24
6 | */
7 | public interface GetIntCode {
8 |
9 | int getCode();
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/dunwu-tool/dunwu-tool-core/src/main/java/io/github/dunwu/tool/core/constant/GetIntValue.java:
--------------------------------------------------------------------------------
1 | package io.github.dunwu.tool.core.constant;
2 |
3 | /**
4 | * @author Zhang Peng
5 | * @since 2019-08-14
6 | */
7 | public interface GetIntValue {
8 |
9 | int getValue();
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/dunwu-tool/dunwu-tool-core/src/main/java/io/github/dunwu/tool/core/constant/GetStringCode.java:
--------------------------------------------------------------------------------
1 | package io.github.dunwu.tool.core.constant;
2 |
3 | /**
4 | * @author Zhang Peng
5 | * @since 2021-09-25
6 | */
7 | public interface GetStringCode {
8 |
9 | String getCode();
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/dunwu-tool/dunwu-tool-core/src/main/java/io/github/dunwu/tool/core/constant/GetStringValue.java:
--------------------------------------------------------------------------------
1 | package io.github.dunwu.tool.core.constant;
2 |
3 | /**
4 | * @author Zhang Peng
5 | * @since 2019-08-14
6 | */
7 | public interface GetStringValue {
8 |
9 | String getValue();
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/dunwu-tool/dunwu-tool-core/src/main/java/io/github/dunwu/tool/core/exception/AuthException.java:
--------------------------------------------------------------------------------
1 | package io.github.dunwu.tool.core.exception;
2 |
3 | import io.github.dunwu.tool.core.constant.CodeMsg;
4 | import io.github.dunwu.tool.core.constant.enums.ResultCode;
5 |
6 | /**
7 | * 认证异常
8 | * @author Zhang Peng
9 | * @since 2019-04-11
10 | */
11 | public class AuthException extends CodeMsgException {
12 |
13 | private static final long serialVersionUID = -7027578114976830416L;
14 |
15 | public AuthException() {
16 | this(ResultCode.AUTH_ERROR);
17 | }
18 |
19 | public AuthException(CodeMsg codeMsg) {
20 | this(codeMsg.getCode(), codeMsg.getMsg());
21 | }
22 |
23 | public AuthException(CodeMsg codeMsg, String msg) {
24 | this(codeMsg.getCode(), msg, null);
25 | }
26 |
27 | public AuthException(CodeMsg codeMsg, String msg, String toast) {
28 | this(codeMsg.getCode(), msg, toast);
29 | }
30 |
31 | public AuthException(String msg) {
32 | this(ResultCode.AUTH_ERROR, msg);
33 | }
34 |
35 | public AuthException(int code, String msg) {
36 | this(code, msg, msg);
37 | }
38 |
39 | public AuthException(int code, String msg, String toast) {
40 | super(code, msg, toast);
41 | }
42 |
43 | public AuthException(Throwable cause) {
44 | this(cause, ResultCode.AUTH_ERROR);
45 | }
46 |
47 | public AuthException(Throwable cause, String msg) {
48 | this(cause, ResultCode.AUTH_ERROR, msg);
49 | }
50 |
51 | public AuthException(Throwable cause, CodeMsg codeMsg) {
52 | this(cause, codeMsg.getCode(), codeMsg.getMsg());
53 | }
54 |
55 | public AuthException(Throwable cause, CodeMsg codeMsg, String msg) {
56 | this(cause, codeMsg.getCode(), msg, null);
57 | }
58 |
59 | public AuthException(Throwable cause, CodeMsg codeMsg, String msg, String toast) {
60 | this(cause, codeMsg.getCode(), msg, toast);
61 | }
62 |
63 | public AuthException(Throwable cause, int code, String msg) {
64 | this(cause, code, msg, null);
65 | }
66 |
67 | public AuthException(Throwable cause, int code, String msg, String toast) {
68 | super(cause, code, msg, toast);
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/dunwu-tool/dunwu-tool-core/src/main/java/io/github/dunwu/tool/core/function/CallFunction.java:
--------------------------------------------------------------------------------
1 | package io.github.dunwu.tool.core.function;
2 |
3 | import java.io.Serializable;
4 |
5 | @FunctionalInterface
6 | public interface CallFunction extends Serializable {
7 |
8 | R call(P var1) throws Exception;
9 |
10 | default R callWithRuntimeException(P parameter) {
11 | try {
12 | return this.call(parameter);
13 | } catch (Exception var3) {
14 | throw new RuntimeException(var3);
15 | }
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/dunwu-tool/dunwu-tool-core/src/main/java/io/github/dunwu/tool/io/ansi/AnsiBackground.java:
--------------------------------------------------------------------------------
1 | package io.github.dunwu.tool.io.ansi;
2 |
3 | /**
4 | * ANSI 背景显示颜色枚举
5 | *
6 | * @author Zhang Peng
7 | * @see ANSI Colors
8 | * @since 2019/10/30
9 | */
10 | public enum AnsiBackground implements AnsiElement {
11 |
12 | DEFAULT("49"),
13 |
14 | BLACK("40"),
15 |
16 | RED("41"),
17 |
18 | GREEN("42"),
19 |
20 | YELLOW("43"),
21 |
22 | BLUE("44"),
23 |
24 | MAGENTA("45"),
25 |
26 | CYAN("46"),
27 |
28 | WHITE("47"),
29 |
30 | BRIGHT_BLACK("100"),
31 |
32 | BRIGHT_RED("101"),
33 |
34 | BRIGHT_GREEN("102"),
35 |
36 | BRIGHT_YELLOW("103"),
37 |
38 | BRIGHT_BLUE("104"),
39 |
40 | BRIGHT_MAGENTA("105"),
41 |
42 | BRIGHT_CYAN("106"),
43 |
44 | BRIGHT_WHITE("107");
45 |
46 | private final String code;
47 |
48 | AnsiBackground(String code) {
49 | this.code = code;
50 | }
51 |
52 | @Override
53 | public String toString() {
54 | return code;
55 | }
56 |
57 | public String getCode() {
58 | return code;
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/dunwu-tool/dunwu-tool-core/src/main/java/io/github/dunwu/tool/io/ansi/AnsiColor.java:
--------------------------------------------------------------------------------
1 | package io.github.dunwu.tool.io.ansi;
2 |
3 | /**
4 | * ANSI 字体显示颜色枚举
5 | *
6 | * @author Zhang Peng
7 | * @see ANSI Colors
8 | * @since 2019/10/30
9 | */
10 | public enum AnsiColor implements AnsiElement {
11 |
12 | DEFAULT("39"),
13 | BLACK("30"),
14 | RED("31"),
15 | GREEN("32"),
16 | YELLOW("33"),
17 | BLUE("34"),
18 | MAGENTA("35"),
19 | CYAN("36"),
20 | WHITE("37"),
21 | BRIGHT_BLACK("90"),
22 | BRIGHT_RED("91"),
23 | BRIGHT_GREEN("92"),
24 | BRIGHT_YELLOW("99"),
25 | BRIGHT_BLUE("94"),
26 | BRIGHT_MAGENTA("95"),
27 | BRIGHT_CYAN("96"),
28 | BRIGHT_WHITE("97");
29 |
30 | private final String code;
31 |
32 | AnsiColor(String code) {
33 | this.code = code;
34 | }
35 |
36 | @Override
37 | public String toString() {
38 | return code;
39 | }
40 |
41 | public String getCode() {
42 | return code;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/dunwu-tool/dunwu-tool-core/src/main/java/io/github/dunwu/tool/io/ansi/AnsiElement.java:
--------------------------------------------------------------------------------
1 | package io.github.dunwu.tool.io.ansi;
2 |
3 | public interface AnsiElement {
4 |
5 | /**
6 | * @return the ANSI escape code
7 | */
8 | @Override
9 | String toString();
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/dunwu-tool/dunwu-tool-core/src/main/java/io/github/dunwu/tool/io/ansi/AnsiStyle.java:
--------------------------------------------------------------------------------
1 | package io.github.dunwu.tool.io.ansi;
2 |
3 | /**
4 | * Ansi SGR (Select Graphic Rendition) 设置显示属性。
5 | *
6 | * 可以按相同的顺序设置多个属性,并用分号隔开。
7 | *
8 | * 每个显示属性一直有效,直到随后发生SGR重置它为止。
9 | *
10 | * 如果未给出代码,则将 CSI m 视为 CSI 0m(重置/正常)。
11 | *
12 | * @author Zhang Peng
13 | * @see SGR
14 | * @since 2019/10/30
15 | */
16 | public enum AnsiStyle implements AnsiElement {
17 |
18 | NORMAL("0"),
19 | BOLD("1"),
20 | FAINT("2"),
21 | ITALIC("3"),
22 | UNDERLINE("4"),
23 | SLOW_BLINK("5"),
24 | RAPID_BLINK("6"),
25 | REVERSE_VIDEO("7"),
26 | CONCEAL("8");
27 |
28 | private final String code;
29 |
30 | AnsiStyle(String code) {
31 | this.code = code;
32 | }
33 |
34 | @Override
35 | public String toString() {
36 | return code;
37 | }
38 |
39 | public String getCode() {
40 | return code;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/dunwu-tool/dunwu-tool-core/src/main/java/io/github/dunwu/tool/io/ansi/ColorType.java:
--------------------------------------------------------------------------------
1 | package io.github.dunwu.tool.io.ansi;
2 |
3 | /**
4 | * 完全对应 {@link AnsiColor} 和 {@link AnsiBackground} 所有元素
5 | *
6 | * @author Zhang Peng
7 | * @since 2019/10/30
8 | */
9 | public enum ColorType {
10 |
11 | DEFAULT("默认"),
12 | BLACK("黑色"),
13 | RED("红色"),
14 | GREEN("绿色"),
15 | YELLOW("黄色"),
16 | BLUE("蓝色"),
17 | MAGENTA("紫色"),
18 | CYAN("青色"),
19 | WHITE("白色"),
20 | BRIGHT_BLACK("亮黑色"),
21 | BRIGHT_RED("亮红色"),
22 | BRIGHT_GREEN("亮绿色"),
23 | BRIGHT_YELLOW("亮黄色"),
24 | BRIGHT_BLUE("亮蓝色"),
25 | BRIGHT_MAGENTA("亮紫色"),
26 | BRIGHT_CYAN("亮青色"),
27 | BRIGHT_WHITE("亮白色");
28 |
29 | private String desc;
30 |
31 | ColorType(String desc) {
32 | this.desc = desc;
33 | }
34 |
35 | public String getDesc() {
36 | return desc;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/dunwu-tool/dunwu-tool-core/src/main/java/io/github/dunwu/tool/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Hutool核心方法及数据结构包
3 | *
4 | * @author looly
5 | */
6 | package io.github.dunwu.tool;
7 |
--------------------------------------------------------------------------------
/dunwu-tool/dunwu-tool-core/src/main/java/io/github/dunwu/tool/util/ClassUtil.java:
--------------------------------------------------------------------------------
1 | package io.github.dunwu.tool.util;
2 |
3 | import java.lang.reflect.Field;
4 | import java.util.Collections;
5 | import java.util.LinkedHashSet;
6 | import java.util.Set;
7 |
8 | /**
9 | * @author Zhang Peng
10 | * @since 2020-05-20
11 | */
12 | public class ClassUtil extends cn.hutool.core.util.ClassUtil {
13 |
14 | /**
15 | * @param clazz 指定类
16 | * @return 对象及其父类的所有字段
17 | */
18 | public static Field[] getAllFields(Class> clazz) {
19 | Set fieldSet = new LinkedHashSet<>();
20 | // 为了避免出现死循环,所以设定最大嵌套层数为 10 (正常情况,嵌套层数不会太深)
21 | int i = 0;
22 | while (clazz != null && i < 10) {
23 | i++;
24 | Collections.addAll(fieldSet, clazz.getDeclaredFields());
25 | clazz = clazz.getSuperclass();
26 | }
27 | Field[] fields = new Field[fieldSet.size()];
28 | fieldSet.toArray(fields);
29 | return fields;
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/dunwu-tool/dunwu-tool-core/src/main/java/io/github/dunwu/tool/util/SerializableUtil.java:
--------------------------------------------------------------------------------
1 | package io.github.dunwu.tool.util;
2 |
3 | import java.io.Serializable;
4 |
5 | /**
6 | * @author Zhang Peng
7 | * @since 2021-10-05
8 | */
9 | public class SerializableUtil {
10 |
11 | public static Long getLong(Serializable value) {
12 | if (value instanceof Long) {
13 | return (Long) value;
14 | } else if (value instanceof Integer) {
15 | Integer intValue = (Integer) value;
16 | return intValue.longValue();
17 | } else {
18 | return null;
19 | }
20 | }
21 |
22 | public static Integer getInteger(Serializable value) {
23 | if (value instanceof Long) {
24 | Long longValue = (Long) value;
25 | return longValue.intValue();
26 | } else if (value instanceof Integer) {
27 | return (Integer) value;
28 | } else {
29 | return null;
30 | }
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/dunwu-tool/dunwu-tool-core/src/main/java/io/github/dunwu/tool/util/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * 提供各种工具方法,按照归类入口为XXXUtil,如字符串工具StrUtil等
3 | *
4 | * @author looly
5 | */
6 | package io.github.dunwu.tool.util;
7 |
--------------------------------------------------------------------------------
/dunwu-tool/dunwu-tool-core/src/main/java/io/github/dunwu/tool/util/tree/parser/DefaultNodeParser.java:
--------------------------------------------------------------------------------
1 | package io.github.dunwu.tool.util.tree.parser;
2 |
3 | import cn.hutool.core.collection.CollUtil;
4 | import cn.hutool.core.map.MapUtil;
5 | import io.github.dunwu.tool.util.tree.Tree;
6 | import io.github.dunwu.tool.util.tree.TreeNode;
7 |
8 | import java.util.ArrayList;
9 | import java.util.Map;
10 |
11 | /**
12 | * 默认的简单转换器
13 | *
14 | * @author liangbaikai
15 | * @author Zhang Peng
16 | */
17 | public class DefaultNodeParser implements NodeParser {
18 |
19 | @Override
20 | public void parse(TreeNode treeNode, Tree tree) {
21 | if (MapUtil.isNotEmpty(treeNode.getFull())) {
22 | treeNode.getFull().forEach(tree::putExtra);
23 | if (CollUtil.isEmpty(tree.getChildren())) {
24 | tree.setChildren(new ArrayList<>());
25 | }
26 | return;
27 | }
28 |
29 | tree.setId(treeNode.getId());
30 | tree.setPid(treeNode.getPid());
31 | tree.setWeight(treeNode.getWeight());
32 | tree.setName(treeNode.getName());
33 | tree.setChildren(new ArrayList<>());
34 |
35 | //扩展字段
36 | final Map extra = treeNode.getExtra();
37 | if (MapUtil.isNotEmpty(extra)) {
38 | extra.forEach(tree::putExtra);
39 | }
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/dunwu-tool/dunwu-tool-core/src/main/java/io/github/dunwu/tool/util/tree/parser/NodeParser.java:
--------------------------------------------------------------------------------
1 | package io.github.dunwu.tool.util.tree.parser;
2 |
3 | import io.github.dunwu.tool.util.tree.Node;
4 |
5 | /**
6 | * 树节点解析器 可以参考{@link DefaultNodeParser}
7 | *
8 | * @param 转换的实体 为数据源里的对象类型
9 | * @author liangbaikai
10 | */
11 | @FunctionalInterface
12 | public interface NodeParser, T extends Node> {
13 |
14 | /**
15 | * @param object 源数据实体
16 | * @param treeNode 树节点实体
17 | */
18 | void parse(S object, T treeNode);
19 |
20 | }
21 |
22 |
--------------------------------------------------------------------------------
/dunwu-tool/dunwu-tool-core/src/test/java/io/github/dunwu/tool/codec/MessageDigestUtilTest.java:
--------------------------------------------------------------------------------
1 | package io.github.dunwu.tool.codec;
2 |
3 | import org.junit.jupiter.api.Assertions;
4 | import org.junit.jupiter.api.RepeatedTest;
5 |
6 | import java.security.NoSuchAlgorithmException;
7 |
8 | /**
9 | * @author Zhang Peng
10 | * @since 2020-03-14
11 | */
12 | public class MessageDigestUtilTest {
13 |
14 | @RepeatedTest(2)
15 | public void testSHA384() throws NoSuchAlgorithmException {
16 | String username = "root";
17 | String password = "root";
18 | String target = MessageDigestUtil.encodeWithBase64(MessageDigestUtil.Type.SHA384, username.getBytes(),
19 | password.getBytes());
20 | String result = String.format("%s摘要:%s", MessageDigestUtil.Type.SHA384.getName(), target);
21 | Assertions.assertEquals("ZApimbcDO6rAvpQyi9yFpOFxvIgvi5dXu6VKQPgUduIC22MwT3Wlli62MNn9m9d_", target);
22 | System.out.println(result);
23 | }
24 |
25 | @RepeatedTest(2)
26 | public void testMD5() throws NoSuchAlgorithmException {
27 | String username = "root";
28 | String password = "root";
29 | String target = MessageDigestUtil.encodeWithBase64(MessageDigestUtil.Type.MD5, username.getBytes(),
30 | password.getBytes());
31 | String result = String.format("%s摘要:%s", MessageDigestUtil.Type.MD5.getName(), target);
32 | Assertions.assertEquals("tLja9LjqnTlWhxnh4yAHbw", target);
33 | System.out.println(result);
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/dunwu-tool/dunwu-tool-core/src/test/java/io/github/dunwu/tool/io/AnsiColorUtilTest.java:
--------------------------------------------------------------------------------
1 | package io.github.dunwu.tool.io;
2 |
3 | import org.junit.jupiter.api.Test;
4 |
5 | /**
6 | * @author Zhang Peng
7 | * @since 2020-03-14
8 | */
9 | public class AnsiColorUtilTest {
10 |
11 | @Test
12 | public void test() {
13 | AnsiColorUtil.setEnabled(false);
14 | AnsiColorUtil.BOLD_RED.println("abc");
15 | System.out.println("abc");
16 |
17 | AnsiColorUtil.setEnabled(true);
18 | AnsiColorUtil.RED.print("A");
19 | AnsiColorUtil.GREEN.print("B");
20 | AnsiColorUtil.BLUE.print("C");
21 | System.out.println("D");
22 |
23 | AnsiColorUtil.RED.printf("HELLO \n%s", "World");
24 | AnsiColorUtil.BOLD_BLUE.printf("HELLO\n");
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/dunwu-tool/dunwu-tool-core/src/test/java/io/github/dunwu/tool/io/FileUtilTests.java:
--------------------------------------------------------------------------------
1 | package io.github.dunwu.tool.io;
2 |
3 | import cn.hutool.core.util.StrUtil;
4 | import org.junit.jupiter.api.Test;
5 |
6 | import java.io.File;
7 | import java.util.List;
8 |
9 | /**
10 | * @author Zhang Peng
11 | * @since 2023-05-01
12 | */
13 | public class FileUtilTests {
14 |
15 | String rootDir = "E:\\照片\\";
16 |
17 | @Test
18 | public void test() {
19 | File dir = new File(rootDir);
20 | File[] files = dir.listFiles();
21 | for (File file : files) {
22 | if (file.isDirectory()) {
23 | continue;
24 | }
25 |
26 | String fullFileName = FileUtil.getName(file);
27 | String filename = StrUtil.subBefore(fullFileName, ".jpg", true);
28 | if (!StrUtil.startWith(filename, "IMG_")) {
29 | continue;
30 | }
31 |
32 | List groups = StrUtil.split(filename, "_");
33 |
34 | String month = groups.get(1).substring(0, 6);
35 | String newFileName = rootDir + month + "\\" + fullFileName;
36 | FileUtil.move(file, new File(newFileName), false);
37 | // System.out.println(newFileName);
38 | }
39 | }
40 |
41 | @Test
42 | public void test2() {
43 | // for (int i = 1; i <= 4; i++) {
44 | // FileUtil.textToBinary(StrUtil.format("D:\\Temp\\temp{}.txt", i),
45 | // StrUtil.format("D:\\Temp\\backup.part0{}.rar", i));
46 | // }
47 | // FileUtil.binaryToText("D:\\Workspace\\知识图谱.xmind", "D:\\Workspace\\知识图谱.txt");
48 | FileUtil.textToBinary("D:\\Temp\\Output.txt", "D:\\Temp\\Output.rar");
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/dunwu-tool/dunwu-tool-core/src/test/java/io/github/dunwu/tool/util/DateUtilTest.java:
--------------------------------------------------------------------------------
1 | package io.github.dunwu.tool.util;
2 |
3 | import org.junit.jupiter.api.Test;
4 |
5 | import java.time.Duration;
6 |
7 | /**
8 | * @author Zhang Peng
9 | * @since 2020-04-13
10 | */
11 | public class DateUtilTest {
12 |
13 | @Test
14 | public void test() {
15 | Duration duration =
16 | Duration.ofDays(7).plusMinutes(32).plusSeconds(21).plusMillis(500).plusNanos(1000);
17 | String formatTime = DateUtil.formatDurationChineseString(duration);
18 | System.out.println("formatTime: " + formatTime);
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/dunwu-tool/dunwu-tool-core/src/test/resources/hutool.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dunwu/dunwu-framework/HEAD/dunwu-tool/dunwu-tool-core/src/test/resources/hutool.jpg
--------------------------------------------------------------------------------
/dunwu-tool/dunwu-tool-core/src/test/resources/test.csv:
--------------------------------------------------------------------------------
1 | 姓名,"性别",关注"对象",年龄
--------------------------------------------------------------------------------
/dunwu-tool/dunwu-tool-core/src/test/resources/test.properties:
--------------------------------------------------------------------------------
1 | #--------------------------------------------
2 | # 配置文件测试
3 | #--------------------------------------------
4 | a = 1
5 | b = 2
6 | dunwu.timezone = GMT+8
7 | dunwu.encoding = utf-8
8 | dunwu.min = 1
9 | dunwu.max = 10
10 | dunwu.enabled = true
11 | dunwu.nodes[0] = 1
12 | dunwu.nodes[1] = 2
13 | dunwu.nodes[2] = 3
14 |
--------------------------------------------------------------------------------
/dunwu-tool/dunwu-tool-core/src/test/resources/test.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Success(成功)
4 | ok
5 | 1490
6 | 885
7 | 1
8 |
9 |
--------------------------------------------------------------------------------
/dunwu-tool/dunwu-tool-data/src/main/java/io/github/dunwu/tool/data/annotation/ControllerEndpoint.java:
--------------------------------------------------------------------------------
1 | package io.github.dunwu.tool.data.annotation;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | /**
9 | * @author MrBird
10 | */
11 | @Target(ElementType.METHOD)
12 | @Retention(RetentionPolicy.RUNTIME)
13 | public @interface ControllerEndpoint {
14 |
15 | String operation() default "";
16 |
17 | String exceptionMessage() default "系统内部异常";
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/dunwu-tool/dunwu-tool-data/src/main/java/io/github/dunwu/tool/data/annotation/Dao.java:
--------------------------------------------------------------------------------
1 | package io.github.dunwu.tool.data.annotation;
2 |
3 | import org.springframework.core.annotation.AliasFor;
4 | import org.springframework.stereotype.Component;
5 |
6 | import java.lang.annotation.*;
7 |
8 | /**
9 | * Dao 标记注解
10 | *
11 | * @author Zhang Peng
12 | * @since 2019-07-23
13 | */
14 | @Component
15 | @Documented
16 | @Retention(RetentionPolicy.RUNTIME)
17 | @Target({ ElementType.TYPE })
18 | public @interface Dao {
19 |
20 | @AliasFor(annotation = Component.class)
21 | String value() default "";
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/dunwu-tool/dunwu-tool-data/src/main/java/io/github/dunwu/tool/data/annotation/FlowLimit.java:
--------------------------------------------------------------------------------
1 | package io.github.dunwu.tool.data.annotation;
2 |
3 | import io.github.dunwu.tool.data.constant.FlowLimitType;
4 |
5 | import java.lang.annotation.ElementType;
6 | import java.lang.annotation.Retention;
7 | import java.lang.annotation.RetentionPolicy;
8 | import java.lang.annotation.Target;
9 |
10 | /**
11 | * 流控注解
12 | *
13 | * @author Zhang Peng
14 | * @since 2020-03-15
15 | */
16 | @Target(ElementType.METHOD)
17 | @Retention(RetentionPolicy.RUNTIME)
18 | public @interface FlowLimit {
19 |
20 | /**
21 | * 资源名称,用于描述接口功能
22 | */
23 | String name() default "";
24 |
25 | /**
26 | * 资源 key
27 | */
28 | String key() default "";
29 |
30 | /**
31 | * key prefix
32 | */
33 | String prefix() default "";
34 |
35 | /**
36 | * 时间范围,单位秒
37 | */
38 | int period();
39 |
40 | /**
41 | * 限制访问次数
42 | */
43 | int count();
44 |
45 | /**
46 | * 限制类型
47 | */
48 | FlowLimitType limitType() default FlowLimitType.CUSTOMER;
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/dunwu-tool/dunwu-tool-data/src/main/java/io/github/dunwu/tool/data/annotation/JobHandler.java:
--------------------------------------------------------------------------------
1 | package io.github.dunwu.tool.data.annotation;
2 |
3 | import org.springframework.core.annotation.AliasFor;
4 | import org.springframework.stereotype.Component;
5 |
6 | import java.lang.annotation.*;
7 |
8 | @Target({ ElementType.TYPE })
9 | @Retention(RetentionPolicy.RUNTIME)
10 | @Documented
11 | @Component
12 | @Inherited
13 | public @interface JobHandler {
14 |
15 | @AliasFor("beanName")
16 | String value() default "";
17 |
18 | @AliasFor("value")
19 | String beanName() default "";
20 |
21 | String executeMethod() default "execute";
22 |
23 | Class>[] paramTypes() default {};
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/dunwu-tool/dunwu-tool-data/src/main/java/io/github/dunwu/tool/data/annotation/Manager.java:
--------------------------------------------------------------------------------
1 | package io.github.dunwu.tool.data.annotation;
2 |
3 | import org.springframework.core.annotation.AliasFor;
4 | import org.springframework.stereotype.Component;
5 |
6 | import java.lang.annotation.*;
7 |
8 | /**
9 | * Manager 标记注解
10 | *
11 | * 用于指示被修饰的类型是一个管理类。管理类通常由多个 Service 类组成,用于处理一些跨职能的服务。
12 | *
13 | * @author Zhang Peng
14 | * @since 2019-07-23
15 | */
16 | @Target({ ElementType.TYPE })
17 | @Retention(RetentionPolicy.RUNTIME)
18 | @Documented
19 | @Component
20 | public @interface Manager {
21 |
22 | @AliasFor(annotation = Component.class)
23 | String value() default "";
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/dunwu-tool/dunwu-tool-data/src/main/java/io/github/dunwu/tool/data/annotation/QueryField.java:
--------------------------------------------------------------------------------
1 | package io.github.dunwu.tool.data.annotation;
2 |
3 | import io.github.dunwu.tool.bean.support.NamingStrategy;
4 | import org.springframework.core.annotation.AliasFor;
5 |
6 | import java.lang.annotation.*;
7 |
8 | /**
9 | * 查询注解
10 | *
11 | * @author Zhang Peng
12 | * @since 2019-07-23
13 | */
14 | @Documented
15 | @Target(ElementType.FIELD)
16 | @Retention(RetentionPolicy.RUNTIME)
17 | public @interface QueryField {
18 |
19 | @AliasFor("name")
20 | String value() default "";
21 |
22 | @AliasFor("value")
23 | String name() default "";
24 |
25 | String[] blurry() default {};
26 |
27 | QueryType type() default QueryType.EQUALS;
28 |
29 | String joinName() default "";
30 |
31 | boolean nullable() default false;
32 |
33 | NamingStrategy namingStrategy() default NamingStrategy.LOWER_UNDERLINE;
34 |
35 | enum QueryType {
36 | EQUALS,
37 | LIKE,
38 | NOT_LIKE,
39 | LIKE_LEFT,
40 | LIKE_RIGHT,
41 | LT,
42 | LE,
43 | GT,
44 | GE,
45 | NE,
46 | IN,
47 | NOT_IN,
48 | BETWEEN,
49 | NOT_NULL
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/dunwu-tool/dunwu-tool-data/src/main/java/io/github/dunwu/tool/data/annotation/QueryTable.java:
--------------------------------------------------------------------------------
1 | package io.github.dunwu.tool.data.annotation;
2 |
3 | import org.springframework.core.annotation.AliasFor;
4 |
5 | import java.lang.annotation.*;
6 |
7 | /**
8 | * @author Zhang Peng
9 | * @since 2020-04-07
10 | */
11 | @Documented
12 | @Target(ElementType.TYPE)
13 | @Retention(RetentionPolicy.RUNTIME)
14 | public @interface QueryTable {
15 |
16 | @AliasFor("entity")
17 | Class> value() default Object.class;
18 |
19 | @AliasFor("value")
20 | Class> entity() default Object.class;
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/dunwu-tool/dunwu-tool-data/src/main/java/io/github/dunwu/tool/data/aop/BaseAop.java:
--------------------------------------------------------------------------------
1 | package io.github.dunwu.tool.data.aop;
2 |
3 | import org.aspectj.lang.ProceedingJoinPoint;
4 | import org.aspectj.lang.reflect.MethodSignature;
5 |
6 | import java.lang.reflect.Method;
7 |
8 | /**
9 | * @author Zhang Peng
10 | * @since 2020-03-15
11 | */
12 | public abstract class BaseAop {
13 |
14 | protected Method resolveMethod(ProceedingJoinPoint point) {
15 | MethodSignature signature = (MethodSignature) point.getSignature();
16 | Class> targetClass = point.getTarget().getClass();
17 | Method method = getDeclaredMethod(targetClass, signature.getName(),
18 | signature.getMethod().getParameterTypes());
19 | if (method == null) {
20 | throw new IllegalStateException("无法解析目标方法: " + signature.getMethod().getName());
21 | }
22 | return method;
23 | }
24 |
25 | private Method getDeclaredMethod(Class> clazz, String name, Class>... parameterTypes) {
26 | try {
27 | return clazz.getDeclaredMethod(name, parameterTypes);
28 | } catch (NoSuchMethodException e) {
29 | Class> superClass = clazz.getSuperclass();
30 | if (superClass != null) {
31 | return getDeclaredMethod(superClass, name, parameterTypes);
32 | }
33 | }
34 | return null;
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/dunwu-tool/dunwu-tool-data/src/main/java/io/github/dunwu/tool/data/constant/FlowLimitType.java:
--------------------------------------------------------------------------------
1 | package io.github.dunwu.tool.data.constant;
2 |
3 | /**
4 | * 流控类型枚举
5 | *
6 | * @author Zhang Peng
7 | * @since 2021-09-25
8 | */
9 | public enum FlowLimitType {
10 | /**
11 | * 传统类型
12 | */
13 | CUSTOMER,
14 | /**
15 | * 根据 IP地址限制
16 | */
17 | IP
18 | }
19 |
--------------------------------------------------------------------------------
/dunwu-tool/dunwu-tool-data/src/main/java/io/github/dunwu/tool/data/constant/OrderType.java:
--------------------------------------------------------------------------------
1 | package io.github.dunwu.tool.data.constant;
2 |
3 | import java.util.Locale;
4 | import java.util.Optional;
5 |
6 | /**
7 | * 排序类型枚举
8 | *
9 | * @author Zhang Peng
10 | * @since 2019-12-17
11 | */
12 | public enum OrderType {
13 |
14 | /** 升序 */
15 | ASC,
16 | /** 降序 */
17 | DESC;
18 |
19 | /**
20 | * Returns the {@link OrderType} enum for the given {@link String} or null if it cannot be parsed into an enum
21 | * value.
22 | *
23 | * @param value 字符串
24 | * @return 可选类型
25 | */
26 | public static Optional fromOptionalString(String value) {
27 |
28 | try {
29 | return Optional.of(fromString(value));
30 | } catch (IllegalArgumentException e) {
31 | return Optional.empty();
32 | }
33 | }
34 |
35 | /**
36 | * Returns the {@link OrderType} enum for the given {@link String} value.
37 | *
38 | * @param value 字符串
39 | * @return OrderType
40 | * @throws IllegalArgumentException in case the given value cannot be parsed into an enum value.
41 | */
42 | public static OrderType fromString(String value) {
43 |
44 | try {
45 | return OrderType.valueOf(value.toUpperCase(Locale.US));
46 | } catch (Exception e) {
47 | throw new IllegalArgumentException(String.format(
48 | "Invalid value '%s' for orders given! Has to be either 'desc' or 'asc' (case insensitive).", value), e);
49 | }
50 | }
51 |
52 | /**
53 | * Returns whether the direction is ascending.
54 | *
55 | * @return true/false
56 | * @since 1.13
57 | */
58 | public boolean isAscending() {
59 | return this.equals(ASC);
60 | }
61 |
62 | /**
63 | * Returns whether the direction is descending.
64 | *
65 | * @return true/false
66 | * @since 1.13
67 | */
68 | public boolean isDescending() {
69 | return this.equals(DESC);
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/dunwu-tool/dunwu-tool-data/src/main/java/io/github/dunwu/tool/data/constant/QueryJudgeType.java:
--------------------------------------------------------------------------------
1 | package io.github.dunwu.tool.data.constant;
2 |
3 | /**
4 | * 查询条件判断类型
5 | *
6 | * @author Zhang Peng
7 | * @since 2019-12-17
8 | */
9 | public enum QueryJudgeType {
10 | Equals,
11 | NotEquals,
12 | Like,
13 | NotLike,
14 | In,
15 | NotIn,
16 | IsNull,
17 | IsNotNull,
18 | }
19 |
--------------------------------------------------------------------------------
/dunwu-tool/dunwu-tool-data/src/main/java/io/github/dunwu/tool/data/constant/QueryLogicType.java:
--------------------------------------------------------------------------------
1 | package io.github.dunwu.tool.data.constant;
2 |
3 | /**
4 | * 查询条件逻辑类型
5 | *
6 | * @author Zhang Peng
7 | * @since 2019-12-17
8 | */
9 | public enum QueryLogicType {
10 | AND,
11 | OR
12 | }
13 |
--------------------------------------------------------------------------------
/dunwu-tool/dunwu-tool-data/src/main/java/io/github/dunwu/tool/data/desensitized/annotation/Desensitized.java:
--------------------------------------------------------------------------------
1 | package io.github.dunwu.tool.data.desensitized.annotation;
2 |
3 | import com.fasterxml.jackson.annotation.JacksonAnnotationsInside;
4 | import com.fasterxml.jackson.databind.annotation.JsonSerialize;
5 | import io.github.dunwu.tool.data.desensitized.DesensitizedSerializer;
6 | import io.github.dunwu.tool.data.desensitized.constant.SensitiveTypeEnum;
7 |
8 | import java.lang.annotation.ElementType;
9 | import java.lang.annotation.Inherited;
10 | import java.lang.annotation.Retention;
11 | import java.lang.annotation.RetentionPolicy;
12 | import java.lang.annotation.Target;
13 |
14 | /**
15 | * 数据脱敏注解
16 | *
17 | * 注:需要配合 {@link NeedDesensitized} 使用,只有被标记 {@link NeedDesensitized} 的类,脱敏工具 {@link DesensitizedSerializer}
18 | * 才会去扫描是否存在被标记为 {@link Desensitized} 的字段
19 | *
20 | * @author Zhang Peng
21 | * @date 2022-11-04
22 | */
23 | @Inherited
24 | @Target(ElementType.FIELD)
25 | @Retention(RetentionPolicy.RUNTIME)
26 | @JacksonAnnotationsInside // 表示自定义自己的注解PrivacyEncrypt
27 | @JsonSerialize(using = DesensitizedSerializer.class) // 该注解使用序列化的方式
28 | public @interface Desensitized {
29 |
30 | /**
31 | * 脱敏类型(规则)
32 | */
33 | SensitiveTypeEnum type() default SensitiveTypeEnum.NONE;
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/dunwu-tool/dunwu-tool-data/src/main/java/io/github/dunwu/tool/data/desensitized/annotation/NeedDesensitized.java:
--------------------------------------------------------------------------------
1 | package io.github.dunwu.tool.data.desensitized.annotation;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | /**
9 | * 脱敏标记注解
10 | *
11 | * @author Zhang Peng
12 | * @date 2022-11-04
13 | */
14 | @Target({ ElementType.TYPE, ElementType.METHOD })
15 | @Retention(RetentionPolicy.RUNTIME)
16 | public @interface NeedDesensitized {
17 | }
18 |
--------------------------------------------------------------------------------
/dunwu-tool/dunwu-tool-data/src/main/java/io/github/dunwu/tool/data/desensitized/constant/SensitiveTypeEnum.java:
--------------------------------------------------------------------------------
1 | package io.github.dunwu.tool.data.desensitized.constant;
2 |
3 | /**
4 | * 敏感数据脱敏类型
5 | *
6 | * @author Zhang Peng
7 | * @date 2022-11-04
8 | */
9 | public enum SensitiveTypeEnum {
10 | /**
11 | * 所有字符都脱敏
12 | */
13 | ALL,
14 | /**
15 | * 直接展示为 null
16 | */
17 | NONE,
18 | /**
19 | * 中文名
20 | */
21 | CHINESE_NAME,
22 | /**
23 | * 身份证号
24 | */
25 | ID_CARD,
26 | /**
27 | * 座机号
28 | */
29 | FIXED_PHONE,
30 | /**
31 | * 手机号
32 | */
33 | MOBILE_PHONE,
34 | /**
35 | * 地址
36 | */
37 | ADDRESS,
38 | /**
39 | * 电子邮件
40 | */
41 | EMAIL,
42 | /**
43 | * 密码
44 | */
45 | PASSWORD,
46 | /**
47 | * 车牌号
48 | */
49 | CAR_LICENSE,
50 | /**
51 | * 银行卡
52 | */
53 | BANK_CARD;
54 | }
55 |
--------------------------------------------------------------------------------
/dunwu-tool/dunwu-tool-data/src/main/java/io/github/dunwu/tool/data/elasticsearch/annotation/QueryDocument.java:
--------------------------------------------------------------------------------
1 | package io.github.dunwu.tool.data.elasticsearch.annotation;
2 |
3 | import io.github.dunwu.tool.bean.support.NamingStrategy;
4 | import io.github.dunwu.tool.data.constant.OrderType;
5 | import org.springframework.data.annotation.Persistent;
6 |
7 | import java.lang.annotation.ElementType;
8 | import java.lang.annotation.Inherited;
9 | import java.lang.annotation.Retention;
10 | import java.lang.annotation.RetentionPolicy;
11 | import java.lang.annotation.Target;
12 |
13 | /**
14 | * ElasticSearch 查询注解
15 | *
16 | * @author Zhang Peng
17 | * @since 2019-12-17
18 | */
19 | @Persistent
20 | @Inherited
21 | @Retention(RetentionPolicy.RUNTIME)
22 | @Target({ ElementType.TYPE })
23 | public @interface QueryDocument {
24 |
25 | NamingStrategy namingStrategy() default NamingStrategy.LOWER_UNDERLINE;
26 |
27 | String[] orderItem() default {};
28 |
29 | OrderType orderType() default OrderType.ASC;
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/dunwu-tool/dunwu-tool-data/src/main/java/io/github/dunwu/tool/data/elasticsearch/annotation/QueryField.java:
--------------------------------------------------------------------------------
1 | package io.github.dunwu.tool.data.elasticsearch.annotation;
2 |
3 | import io.github.dunwu.tool.data.constant.QueryJudgeType;
4 |
5 | import java.lang.annotation.Documented;
6 | import java.lang.annotation.ElementType;
7 | import java.lang.annotation.Inherited;
8 | import java.lang.annotation.Retention;
9 | import java.lang.annotation.RetentionPolicy;
10 | import java.lang.annotation.Target;
11 |
12 | /**
13 | * @author Zhang Peng
14 | * @since 2019-12-17
15 | */
16 | @Documented
17 | @Inherited
18 | @Retention(RetentionPolicy.RUNTIME)
19 | @Target(ElementType.FIELD)
20 | public @interface QueryField {
21 |
22 | String value() default "";
23 |
24 | QueryJudgeType judgeType() default QueryJudgeType.Equals;
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/dunwu-tool/dunwu-tool-data/src/main/java/io/github/dunwu/tool/data/entity/TableColumnInfo.java:
--------------------------------------------------------------------------------
1 | package io.github.dunwu.tool.data.entity;
2 |
3 | import com.fasterxml.jackson.annotation.JsonProperty;
4 | import lombok.AllArgsConstructor;
5 | import lombok.Builder;
6 | import lombok.Data;
7 | import lombok.NoArgsConstructor;
8 |
9 | /**
10 | * @author Zhang Peng
11 | * @date 2022-11-29
12 | */
13 | @Data
14 | @Builder
15 | @NoArgsConstructor
16 | @AllArgsConstructor
17 | public class TableColumnInfo {
18 |
19 | /** Schema 名称 */
20 | @JsonProperty("schemaName")
21 | private String tableSchema;
22 |
23 | /** 表名称 */
24 | private String tableName;
25 |
26 | /** 字段名称 */
27 | private String columnName;
28 |
29 | /** 字段备注 */
30 | private String columnComment;
31 |
32 | /** 字段数据类型 */
33 | private String dataType;
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/dunwu-tool/dunwu-tool-data/src/main/java/io/github/dunwu/tool/data/entity/TableInfo.java:
--------------------------------------------------------------------------------
1 | package io.github.dunwu.tool.data.entity;
2 |
3 | import com.fasterxml.jackson.annotation.JsonFormat;
4 | import com.fasterxml.jackson.annotation.JsonProperty;
5 | import lombok.AllArgsConstructor;
6 | import lombok.Builder;
7 | import lombok.Data;
8 | import lombok.NoArgsConstructor;
9 |
10 | import java.time.LocalDateTime;
11 |
12 | /**
13 | * 表的数据信息
14 | *
15 | * @author Zhang Peng
16 | * @since 2021-03-07
17 | */
18 | @Data
19 | @Builder
20 | @NoArgsConstructor
21 | @AllArgsConstructor
22 | public class TableInfo {
23 |
24 | /** Schema 名称 */
25 | @JsonProperty("schemaName")
26 | private String tableSchema;
27 |
28 | /** 表名称 */
29 | private String tableName;
30 |
31 | /** 数据库引擎 */
32 | private String engine;
33 |
34 | /** 编码集 */
35 | @JsonProperty("coding")
36 | private String tableCollation;
37 |
38 | /** 注释 */
39 | @JsonProperty("comment")
40 | private String tableComment;
41 |
42 | /** 创建日期 */
43 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
44 | private LocalDateTime createTime;
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/dunwu-tool/dunwu-tool-data/src/main/java/io/github/dunwu/tool/data/hdfs/HdfsConfig.java:
--------------------------------------------------------------------------------
1 | package io.github.dunwu.tool.data.hdfs;
2 |
3 | import lombok.Data;
4 | import lombok.ToString;
5 | import lombok.experimental.Accessors;
6 | import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
7 | import org.apache.hadoop.fs.FileSystem;
8 |
9 | import java.io.Serializable;
10 |
11 | /**
12 | * Hdfs 配置选项
13 | *
14 | * @author Zhang Peng
15 | * @since 2020-03-21
16 | */
17 | @Data
18 | @ToString
19 | @Accessors(chain = true)
20 | public class HdfsConfig implements Serializable {
21 |
22 | public static final String HDFS_DEFAULT_URL_KEY = "fs.defaultFS";
23 |
24 | public static final String HDFS_DEFAULT_URL = "hdfs://localhost:9000";
25 |
26 | public static final String HDFS_DEFAULT_USER_NAME = "hdfs";
27 |
28 | private static final long serialVersionUID = -5434086838792181903L;
29 |
30 | protected final Pool pool = new Pool();
31 |
32 | protected String url = HDFS_DEFAULT_URL;
33 |
34 | protected String user = HDFS_DEFAULT_USER_NAME;
35 |
36 | public static class Pool extends GenericObjectPoolConfig { }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/dunwu-tool/dunwu-tool-data/src/main/java/io/github/dunwu/tool/data/hdfs/HdfsPool.java:
--------------------------------------------------------------------------------
1 | package io.github.dunwu.tool.data.hdfs;
2 |
3 | import org.apache.commons.pool2.impl.AbandonedConfig;
4 | import org.apache.commons.pool2.impl.GenericObjectPool;
5 | import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
6 | import org.apache.hadoop.fs.FileSystem;
7 |
8 | /**
9 | * Hdfs 连接池工具,基于 common-pool2 的 {@link GenericObjectPool} 实现,需要配合 {@link HdfsFactory} 使用
10 | *
11 | * @author Zhang Peng
12 | * @since 2020-03-21
13 | */
14 | public class HdfsPool extends GenericObjectPool {
15 |
16 | public HdfsPool(final HdfsFactory factory) {
17 | super(factory);
18 | }
19 |
20 | public HdfsPool(final HdfsFactory factory, final GenericObjectPoolConfig config) {
21 | super(factory, config);
22 | }
23 |
24 | public HdfsPool(final HdfsFactory factory, final GenericObjectPoolConfig config,
25 | final AbandonedConfig abandonedConfig) {
26 | super(factory, config, abandonedConfig);
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/dunwu-tool/dunwu-tool-data/src/main/java/io/github/dunwu/tool/data/mybatis/BaseExtDaoImpl.java:
--------------------------------------------------------------------------------
1 | package io.github.dunwu.tool.data.mybatis;
2 |
3 | import com.baomidou.mybatisplus.core.conditions.Wrapper;
4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper;
5 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6 | import io.github.dunwu.tool.data.mybatis.util.MybatisPlusUtil;
7 | import org.springframework.data.domain.Pageable;
8 |
9 | import java.util.List;
10 |
11 | /**
12 | * {@link IExtDao} 基本实现类
13 | *
14 | * @author Zhang Peng
15 | * @since 2020-04-07
16 | */
17 | public abstract class BaseExtDaoImpl, E> extends DaoImpl
18 | implements IExtDao {
19 |
20 | @Override
21 | public Integer countByQuery(Object query) {
22 | return baseMapper.selectCount(MybatisPlusUtil.buildQueryWrapper(query));
23 | }
24 |
25 | @Override
26 | public E getByQuery(Object query) {
27 | return baseMapper.selectOne(MybatisPlusUtil.buildQueryWrapper(query));
28 | }
29 |
30 | @Override
31 | public List listByQuery(Object query) {
32 | return baseMapper.selectList(MybatisPlusUtil.buildQueryWrapper(query));
33 | }
34 |
35 | @Override
36 | public org.springframework.data.domain.Page springPage(Pageable pageable, Wrapper wrapper) {
37 | Page queryPage = MybatisPlusUtil.toMybatisPlusPage(pageable);
38 | Page page = page(queryPage, wrapper);
39 | return MybatisPlusUtil.toSpringPage(page);
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/dunwu-tool/dunwu-tool-data/src/main/java/io/github/dunwu/tool/data/mybatis/BaseRecordEntity.java:
--------------------------------------------------------------------------------
1 | package io.github.dunwu.tool.data.mybatis;
2 |
3 | import com.baomidou.mybatisplus.annotation.IdType;
4 | import com.baomidou.mybatisplus.annotation.TableId;
5 | import com.fasterxml.jackson.annotation.JsonFormat;
6 | import io.swagger.annotations.ApiModelProperty;
7 | import lombok.Data;
8 | import lombok.experimental.Accessors;
9 |
10 | import java.io.Serializable;
11 | import java.time.LocalDateTime;
12 |
13 | /**
14 | * 基础记录数据库实体类
15 | *
16 | * @author Zhang Peng
17 | * @since 2019-04-27
18 | */
19 | @Data
20 | @Accessors(chain = true)
21 | public abstract class BaseRecordEntity implements Serializable {
22 |
23 | private static final long serialVersionUID = 1L;
24 |
25 | @ApiModelProperty(value = "ID")
26 | @TableId(value = "id", type = IdType.AUTO)
27 | protected Long id;
28 |
29 | @ApiModelProperty(value = "是否禁用,1表示禁用,0表示启用")
30 | protected Boolean isDisabled;
31 |
32 | @ApiModelProperty(value = "备注")
33 | protected String note;
34 |
35 | @ApiModelProperty(value = "创建者")
36 | protected Long createBy;
37 |
38 | @ApiModelProperty(value = "更新者")
39 | protected Long updateBy;
40 |
41 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
42 | @ApiModelProperty(value = "创建时间")
43 | protected LocalDateTime createTime;
44 |
45 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
46 | @ApiModelProperty(value = "更新时间")
47 | protected LocalDateTime updateTime;
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/dunwu-tool/dunwu-tool-data/src/main/java/io/github/dunwu/tool/data/mybatis/DaoInfo.java:
--------------------------------------------------------------------------------
1 | package io.github.dunwu.tool.data.mybatis;
2 |
3 | import lombok.Data;
4 |
5 | /**
6 | * Dao 信息实体
7 | *
8 | * @author Zhang Peng
9 | * @date 2022-12-14
10 | */
11 | @Data
12 | public class DaoInfo {
13 |
14 | private String schemaName;
15 |
16 | private String tableName;
17 |
18 | private String description;
19 |
20 | private Class> entityClass;
21 |
22 | private String entityClassName;
23 |
24 | private Class> daoClass;
25 |
26 | private String daoClassName;
27 |
28 | private Class> mapperClass;
29 |
30 | private String mapperClassName;
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/dunwu-tool/dunwu-tool-data/src/main/java/io/github/dunwu/tool/data/mybatis/IService.java:
--------------------------------------------------------------------------------
1 | package io.github.dunwu.tool.data.mybatis;
2 |
3 | import io.github.dunwu.tool.data.request.PageQuery;
4 | import org.springframework.data.domain.PageRequest;
5 |
6 | public interface IService {
7 |
8 | PageRequest toPageRequest(PageQuery query);
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/dunwu-tool/dunwu-tool-data/src/main/java/io/github/dunwu/tool/data/mybatis/ServiceImpl.java:
--------------------------------------------------------------------------------
1 | package io.github.dunwu.tool.data.mybatis;
2 |
3 | import cn.hutool.core.collection.CollectionUtil;
4 | import io.github.dunwu.tool.data.request.PageQuery;
5 | import io.github.dunwu.tool.data.util.PageUtil;
6 | import org.springframework.data.domain.PageRequest;
7 | import org.springframework.data.domain.Sort;
8 |
9 | import java.util.ArrayList;
10 | import java.util.List;
11 |
12 | /**
13 | * {@link IService} 实现类( 泛型:M 是 mapper 对象,T 是实体 )
14 | *
15 | * @author Zhang Peng
16 | * @since 2020-04-26
17 | */
18 | public class ServiceImpl implements IService {
19 |
20 | @Override
21 | public PageRequest toPageRequest(PageQuery query) {
22 |
23 | if (query == null) {
24 | return null;
25 | }
26 |
27 | int page = 0;
28 | if (query.getPage() > 1) {
29 | page = query.getPage() - 1;
30 | }
31 |
32 | Sort sort = null;
33 | if (CollectionUtil.isNotEmpty(query.getSort())) {
34 | List list = query.getSort();
35 | if (list.get(0).contains(",")) {
36 | sort = PageUtil.getSort(list);
37 | } else {
38 | sort = getOrdersForOneSort(query.getSort());
39 | }
40 | }
41 |
42 | if (sort == null) {
43 | return PageRequest.of(page, query.getSize());
44 | }
45 | return PageRequest.of(page, query.getSize(), sort);
46 | }
47 |
48 | private Sort getOrdersForOneSort(List list) {
49 | if (CollectionUtil.isEmpty(list)) {
50 | return null;
51 | }
52 |
53 | int i = 0;
54 | List orders = new ArrayList<>();
55 | while (i + 1 < list.size()) {
56 | Sort.Direction direction = Sort.Direction.fromString(list.get(i + 1));
57 | Sort.Order order = new Sort.Order(direction, list.get(i));
58 | orders.add(order);
59 | i = i + 2;
60 | }
61 | return Sort.by(orders);
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/dunwu-tool/dunwu-tool-data/src/main/java/io/github/dunwu/tool/data/mybatis/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Mybatis 扩展工具
3 | *
4 | * 使用此 package 工具类,需要引入 mybatis-plus、等 jar
5 | *
6 | * @author Zhang Peng
7 | * @since 2019-12-18
8 | */
9 | package io.github.dunwu.tool.data.mybatis;
10 |
--------------------------------------------------------------------------------
/dunwu-tool/dunwu-tool-data/src/main/java/io/github/dunwu/tool/data/p6spy/P6spySlf4jLogger.java:
--------------------------------------------------------------------------------
1 | package io.github.dunwu.tool.data.p6spy;
2 |
3 | import com.p6spy.engine.logging.Category;
4 | import com.p6spy.engine.spy.appender.FormattedLogger;
5 | import org.slf4j.Logger;
6 | import org.slf4j.LoggerFactory;
7 |
8 | /**
9 | * 自定义 p6spy 日志输出器
10 | *
11 | * @author Zhang Peng
12 | * @since 2020-03-16
13 | */
14 | public class P6spySlf4jLogger extends FormattedLogger {
15 |
16 | private Logger log = LoggerFactory.getLogger("p6spy");
17 |
18 | public P6spySlf4jLogger() { }
19 |
20 | @Override
21 | public void logException(Exception e) {
22 | log.error("", e);
23 | }
24 |
25 | @Override
26 | public void logText(String text) {
27 | log.info(text);
28 | }
29 |
30 | @Override
31 | public boolean isCategoryEnabled(Category category) {
32 | return true;
33 | }
34 |
35 | @Override
36 | public void logSQL(int connectionId, String now, long elapsed, Category category, String prepared, String sql,
37 | String url) {
38 | String msg = this.strategy.formatMessage(connectionId, now, elapsed, category.toString(), prepared, sql, url);
39 | if (log.isDebugEnabled()) {
40 | log.debug(msg);
41 | }
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/dunwu-tool/dunwu-tool-data/src/main/java/io/github/dunwu/tool/data/p6spy/P6spySqlFormat.java:
--------------------------------------------------------------------------------
1 | package io.github.dunwu.tool.data.p6spy;
2 |
3 | import cn.hutool.core.util.StrUtil;
4 | import com.p6spy.engine.spy.appender.MessageFormattingStrategy;
5 |
6 | /**
7 | * 自定义 p6spy sql 输出格式
8 | *
9 | * @author Zhang Peng
10 | * @since 2020-03-16
11 | */
12 | public class P6spySqlFormat implements MessageFormattingStrategy {
13 |
14 | @Override
15 | public String formatMessage(int connectionId, String now, long elapsed, String category, String prepared,
16 | String sql, String url) {
17 | if (StrUtil.isNotBlank(sql)) {
18 | StringBuilder sb = new StringBuilder();
19 | sb.append(String.format("耗时:%s ms ", elapsed))
20 | .append(String.format("执行 SQL:\n%s\n", sql.replaceAll("[\\s]+", StrUtil.SPACE)));
21 | return sb.toString();
22 | } else {
23 | return StrUtil.EMPTY;
24 | }
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/dunwu-tool/dunwu-tool-data/src/main/java/io/github/dunwu/tool/data/util/ReflectionUtil.java:
--------------------------------------------------------------------------------
1 | package io.github.dunwu.tool.data.util;
2 |
3 | import cn.hutool.core.util.ReflectUtil;
4 | import org.reflections.Reflections;
5 |
6 | import java.util.Set;
7 |
8 | /**
9 | * @author Zhang Peng
10 | * @date 2022-12-14
11 | */
12 | public class ReflectionUtil extends ReflectUtil {
13 |
14 | private static final Reflections reflections = new Reflections();
15 |
16 | public static Set> getSubTypesOf(Class type) {
17 | return reflections.getSubTypesOf(type);
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/dunwu-tool/dunwu-tool-data/src/main/java/io/github/dunwu/tool/data/util/SpringContextHelper.java:
--------------------------------------------------------------------------------
1 | package io.github.dunwu.tool.data.util;
2 |
3 | import org.springframework.beans.BeansException;
4 | import org.springframework.context.ApplicationContext;
5 | import org.springframework.context.ApplicationContextAware;
6 | import org.springframework.stereotype.Component;
7 |
8 | /**
9 | * @author Zhang Peng
10 | * @since 2020-03-14
11 | */
12 | @Component
13 | public class SpringContextHelper implements ApplicationContextAware {
14 |
15 | private static ApplicationContext applicationContext;
16 |
17 | public static boolean containsBean(String name) {
18 | return applicationContext.containsBean(name);
19 | }
20 |
21 | public static T getBean(Class clazz) {
22 | return applicationContext.getBean(clazz);
23 | }
24 |
25 | public static T getBean(String name, Class requiredType) {
26 | return applicationContext.getBean(name, requiredType);
27 | }
28 |
29 | public static Object getBean(String name) {
30 | return applicationContext.getBean(name);
31 | }
32 |
33 | public static Class> getType(String name) {
34 | return applicationContext.getType(name);
35 | }
36 |
37 | public static boolean isSingleton(String name) {
38 | return applicationContext.isSingleton(name);
39 | }
40 |
41 | @Override
42 | public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
43 | SpringContextHelper.applicationContext = applicationContext;
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/dunwu-tool/dunwu-tool-data/src/main/java/io/github/dunwu/tool/data/util/SwaggerUtil.java:
--------------------------------------------------------------------------------
1 | package io.github.dunwu.tool.data.util;
2 |
3 | import cn.hutool.core.collection.CollectionUtil;
4 | import cn.hutool.core.util.ReflectUtil;
5 | import io.swagger.annotations.ApiModelProperty;
6 |
7 | import java.lang.reflect.Field;
8 | import java.util.ArrayList;
9 | import java.util.Collection;
10 | import java.util.LinkedHashMap;
11 | import java.util.List;
12 | import java.util.Map;
13 |
14 | /**
15 | * Swagger 工具类
16 | *
17 | * @author Zhang Peng
18 | * @date 2022-11-04
19 | */
20 | public class SwaggerUtil {
21 |
22 | public static List