生成11位编号,可以用作订单号,有很小几率出现重复,需要做异常处理
+ *左边第一位为正负标识:正数1 负数0
+ *剩余位数为UUID的hashcode值
+ *可以再生成的编号基础上嵌入其他标识编码
* * @return */ From c9863373fe4ef02c6f9b08c007a0d747af3bb490 Mon Sep 17 00:00:00 2001 From: maxf <1107047387@qq.com> Date: Mon, 7 Jan 2019 17:18:52 +0800 Subject: [PATCH 02/23] =?UTF-8?q?=E6=94=AF=E4=BB=98=E8=B7=91=E9=80=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/yexuejc/base/util/ObjUtil.java | 41 ++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/yexuejc/base/util/ObjUtil.java b/src/main/java/com/yexuejc/base/util/ObjUtil.java index cc90419..1c180fd 100644 --- a/src/main/java/com/yexuejc/base/util/ObjUtil.java +++ b/src/main/java/com/yexuejc/base/util/ObjUtil.java @@ -2,6 +2,7 @@ package com.yexuejc.base.util; import java.io.*; import java.lang.reflect.Field; +import java.sql.Timestamp; import java.util.*; /** @@ -116,7 +117,7 @@ public class ObjUtil { } } Object o = f.get(obj); - if (null == o || o.getClass().isPrimitive() || o instanceof String || o instanceof Enum) { + if (null == o || isPrimitive(o) || o instanceof String || o instanceof Enum) { if (null == o && !putNull) { continue; } @@ -133,6 +134,23 @@ public class ObjUtil { if (bodyList.size() > 0) { objMap.put(fName, bodyList); } + } else if (o instanceof Map) { + Map map = (Map) o; + if (map.size() > 0) { + objMap.put(fName, map); + } + } else if (o instanceof Set) { + Set list = (Set) o; + Set bodyList = new HashSet(); + list.forEach(it -> { + if (null != it) { + Map
diff --git a/src/main/java/com/yexuejc/base/util/ToUeProperty.java b/src/main/java/com/yexuejc/base/util/ToUeProperty.java
index 4398c63..63d7fdd 100644
--- a/src/main/java/com/yexuejc/base/util/ToUeProperty.java
+++ b/src/main/java/com/yexuejc/base/util/ToUeProperty.java
@@ -11,4 +11,10 @@ public @interface ToUeProperty {
* @return
*/
String value() default "";
+
+ /**
+ * 是否忽略该字段,默认false
+ * @return
+ */
+ boolean ignore() default false;
}
\ No newline at end of file
From f1aa91c81d2ed11512e66e4d5d136f7e47f26768 Mon Sep 17 00:00:00 2001
From: maxf <1107047387@qq.com>
Date: Fri, 11 Jan 2019 16:49:34 +0800
Subject: [PATCH 09/23] =?UTF-8?q?=E5=85=AC=E7=A7=81=E9=92=A5=E9=85=8D?=
=?UTF-8?q?=E7=BD=AE?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../java/com/yexuejc/base/encrypt/RSA.java | 12 +-
.../java/com/yexuejc/base/encrypt/RSA2.java | 128 ++++++++++++++++--
2 files changed, 123 insertions(+), 17 deletions(-)
diff --git a/src/main/java/com/yexuejc/base/encrypt/RSA.java b/src/main/java/com/yexuejc/base/encrypt/RSA.java
index 6fc9010..14b322d 100644
--- a/src/main/java/com/yexuejc/base/encrypt/RSA.java
+++ b/src/main/java/com/yexuejc/base/encrypt/RSA.java
@@ -1,24 +1,22 @@
package com.yexuejc.base.encrypt;
-
import org.apache.commons.codec.binary.Base64;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import javax.crypto.Cipher;
import javax.crypto.NoSuchPaddingException;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
+import java.io.*;
import java.security.*;
+import java.security.cert.Certificate;
import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
+import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
-
/**
* RSA加解密 配置模式
*
@@ -71,7 +69,6 @@ public class RSA {
*/
public static SignAlgorithm signAlgorithm = SignAlgorithm.SHA1withRSA;
-
/**
* 生成密钥对
*
@@ -123,7 +120,6 @@ public class RSA {
return keyPairMap;
}
-
/**
* 得到公钥
*
@@ -203,7 +199,6 @@ public class RSA {
}
}
-
/**
* 私钥加密
*
@@ -310,7 +305,6 @@ public class RSA {
private static Signature signature;
-
/**
* /**
* 私钥签名:默认算法SHA1withRSA
diff --git a/src/main/java/com/yexuejc/base/encrypt/RSA2.java b/src/main/java/com/yexuejc/base/encrypt/RSA2.java
index 2e86afd..68e7099 100644
--- a/src/main/java/com/yexuejc/base/encrypt/RSA2.java
+++ b/src/main/java/com/yexuejc/base/encrypt/RSA2.java
@@ -2,14 +2,8 @@ package com.yexuejc.base.encrypt;
import com.yexuejc.base.util.StrUtil;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.security.KeyStore;
-import java.security.KeyStoreException;
-import java.security.NoSuchAlgorithmException;
-import java.security.UnrecoverableKeyException;
+import java.io.*;
+import java.security.*;
import java.security.cert.Certificate;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
@@ -192,4 +186,122 @@ public class RSA2 {
return (RSAPrivateKey) ks.getKey(alias, password.toCharArray());
}
+ /**
+ * 证书格式转换 JKS(xx.keystore) 转 PKCS12(xx.pfx)
+ *
+ * @param inPath 证书输入文件路径
+ * @param outPath 证书输出文件路径
+ * @param oPwd 原证书密码
+ * @param nPwd 新证书密码(为空同原证书密码一致)
+ */
+ public static void cover2Pfx(String inPath, String outPath, String oPwd, String nPwd) {
+ try {
+ FileInputStream fis = new FileInputStream(inPath);
+ FileOutputStream out = new FileOutputStream(outPath);
+ if (nPwd == null) {
+ nPwd = oPwd;
+ }
+ cover2Pfx(fis, out, oPwd.toCharArray(), nPwd.toCharArray());
+ out.close();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * 证书格式转换 JKS(xx.keystore) 转 PKCS12(xx.pfx)
+ *
+ * @param fis 证书输入文件流
+ * @param out 证书输出文件流[自行关闭->out.close()]
+ * @param oPwd 原证书密码
+ * @param nPwd 新证书密码(为空同原证书密码一致)
+ */
+ public static void cover2Pfx(FileInputStream fis, FileOutputStream out, char[] oPwd, char[] nPwd) {
+ try {
+ KeyStore inputKeyStore = KeyStore.getInstance("JKS");
+ cover(fis, out, oPwd, nPwd, inputKeyStore, "PKCS12");
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * 证书格式转换 PKCS12(xx.pfx) 转 JKS(xx.keystore)
+ *
+ * @param inPath 证书输入文件路径
+ * @param outPath 证书输出文件路径
+ * @param oPwd 原证书密码
+ * @param nPwd 新证书密码(为空同原证书密码一致)
+ */
+ public static void cover2keyStore(String inPath, String outPath, String oPwd, String nPwd) {
+ try {
+ FileInputStream fis = new FileInputStream(inPath);
+ FileOutputStream out = new FileOutputStream(outPath);
+ if (nPwd == null) {
+ nPwd = oPwd;
+ }
+ cover2keyStore(fis, out, oPwd.toCharArray(), nPwd.toCharArray());
+ out.close();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ }
+
+ /**
+ * 证书格式转换 PKCS12(xx.pfx) 转 JKS(xx.keystore)
+ *
+ * @param fis 证书输入文件流
+ * @param out 证书输出文件流[自行关闭->out.close()]
+ * @param oPwd 原证书密码
+ * @param nPwd 新证书密码(为空同原证书密码一致)
+ */
+ public static void cover2keyStore(FileInputStream fis, FileOutputStream out, char[] oPwd, char[] nPwd) {
+ try {
+ KeyStore inputKeyStore = KeyStore.getInstance("PKCS12");
+ cover(fis, out, oPwd, nPwd, inputKeyStore, "JKS");
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * 证书转换操作
+ *
+ * @param fis 证书输入文件流
+ * @param out 证书输出文件流[自行关闭->out.close()]
+ * @param oPwd 原证书密码
+ * @param nPwd 新证书密码(为空同原证书密码一致)
+ * @param inputKeyStore 输入格式
+ * @param type 目标类型
+ * @throws IOException
+ * @throws NoSuchAlgorithmException
+ * @throws CertificateException
+ * @throws KeyStoreException
+ * @throws UnrecoverableKeyException
+ */
+ public static void cover(FileInputStream fis, FileOutputStream out, char[] oPwd, char[] nPwd, KeyStore inputKeyStore, String type) throws IOException, NoSuchAlgorithmException, CertificateException, KeyStoreException, UnrecoverableKeyException {
+ inputKeyStore.load(fis, oPwd);
+ fis.close();
+ if (nPwd == null) {
+ nPwd = oPwd;
+ }
+ KeyStore outputKeyStore = KeyStore.getInstance(type);
+ outputKeyStore.load(null, nPwd);
+ Enumeration
* 签名算法 {@link SignAlgorithm}
diff --git a/src/main/java/com/yexuejc/base/util/JsonUtil.java b/src/main/java/com/yexuejc/base/util/JsonUtil.java
index 99522e3..b7a4c6d 100644
--- a/src/main/java/com/yexuejc/base/util/JsonUtil.java
+++ b/src/main/java/com/yexuejc/base/util/JsonUtil.java
@@ -98,7 +98,6 @@ public class JsonUtil {
*/
public static
+**branch:** master
+**update:**
+>1. RSA2 增加证书格式转换 JKS(xx.keystore) 、 PKCS12(xx.pfx)相互转换
+#
+
#### version :1.3.8
**time:2019-1-11 13:28:12**
**branch:** master
diff --git a/pom.xml b/pom.xml
index 9d26ffd..c6ad955 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
@@ -283,56 +258,4 @@ public class ObjUtil {
return outer;
}
-// public static void main(String[] args) {
-//// test1();
-//// test2();
-//
-// }
-//
-// private static void test2() {
-// B t = new B();
-// t.sex = "男";
-// t.age = 18;
-// A test = new A();
-// test.name = "张三";
-// t.test = test;
-// B b = depthClone(t);
-// System.out.println(JsonUtil.obj2Json(b));
-// }
-//
-// static class A implements Serializable {
-// private static final long serialVersionUID = -8462118058721865488L;
-// public String name;
-// }
-//
-// static class B implements Serializable {
-// private static final long serialVersionUID = 3297717505428005316L;
-// public int age;
-// public String sex;
-// public A test;
-// }
-//
-// static class C implements Serializable {
-// private static final long serialVersionUID = 3297717505428005316L;
-// public int age;
-// public String sex;
-// public A test;
-// }
-//
-// private static void test1() {
-// ApiVO apiVO = new ApiVO(ApiVO.STATUS.S);
-// apiVO.setMsg("asdsadsad");
-// apiVO.setObject1("sadsadsad");
-//
-// Resps 目前只支持 {@link java.util.Date}、{@link java.time.LocalDate}、{@link java.time.LocalDateTime}
+ * 转{@link Integer}(10位长度)、{@link Long}(13位长度)
+ * this in out
+ */
+ Class> type() default ObjUtil.class;
+
}
\ No newline at end of file
diff --git a/src/test/java/com/yexuejc/base/util/ObjUtilTest.java b/src/test/java/com/yexuejc/base/util/ObjUtilTest.java
new file mode 100644
index 0000000..5a8a22f
--- /dev/null
+++ b/src/test/java/com/yexuejc/base/util/ObjUtilTest.java
@@ -0,0 +1,154 @@
+package com.yexuejc.base.util;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.time.LocalDateTime;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * json化输出,改变属性名称,输出类型 {@link ObjUtil} + {@link ToUeProperty} 测试类
+ *
+ * @author: yexuejc
+ * @date: 2021-02-03 10:02:55
+ */
+class ObjUtilTest {
+
+ public static void main(String[] args) {
+ start();
+ }
+
+ public static void start(){
+ B a = new B();
+ a.nameFirst = "张三";
+ a.ageInt = "5165458";
+ a.testAss = "asdasdsad";
+ a.setaM1("method1");
+ a.setbM1("b1Mthod1");
+ a.protectedStr = "protectedStr";
+ a.amount=new BigDecimal("3");
+ a.time = LocalDateTime.now();
+ a.dateTime=new Date();
+ C c = new C();
+ c.ageInt = "test";
+ a.c = c;
+ a.list = new ArrayList<>();
+ a.list.add(c);
+ Map
+ * {@link java.util.Date} {@link Integer} {@link Integer}10位长度时间戳
+ * {@link java.util.Date} {@link Long} {@link Long}13位长度时间戳
+ * {@link java.time.LocalDate} {@link Integer} {@link Integer}10位长度时间戳
+ * {@link java.time.LocalDate} {@link Long} {@link Long}13位长度时间戳(后三位为000)
+ * {@link java.time.LocalDateTime} {@link Integer} {@link Integer}10位长度时间戳
+ * {@link java.time.LocalDateTime} {@link Long} {@link Long}13位长度时间戳
+ *
+ *
+**branch:** master
+**update:**
+>1. DateTimeUtil类增加时间格式
+#
+#### version :1.4.2
+**time:2021-2-3 11:40:11**
+**branch:** master
+**update:**
+>1. 优化时间转换格式
+>2. 增加注解 ToUeProperty 转换时间为时间戳的功能
+#
#### version :1.4.1
**time:2021-1-31 12:59:24**
**branch:** master
From d602d4370ed5a83090559ac577861cf8c436302e Mon Sep 17 00:00:00 2001
From: yexuejc <1107047387@qq.com>
Date: Sat, 6 Feb 2021 11:44:54 +0800
Subject: [PATCH 21/23] pom 1.4.3
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 7b5bb77..1163c67 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
+**branch:** master
+**update:**
+>1. JsonUtil类修复格式化出现的时区差:现使用TimeZone.getDefault()时区
+#
#### version :1.4.3
**time:2021-2-6 11:42:49**
**branch:** master
diff --git a/pom.xml b/pom.xml
index 1163c67..fb9b02a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@