From 34de42f43fd75a31fe0c0d51adf30fb554ad5fa6 Mon Sep 17 00:00:00 2001
From: liyanqi <15181887205@163.com>
Date: 星期四, 15 九月 2022 12:45:26 +0800
Subject: [PATCH] 1:代码迁移
---
ycl-common/src/main/java/com/ycl/utils/common/RandomUtils.java | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 58 insertions(+), 0 deletions(-)
diff --git a/ycl-common/src/main/java/com/ycl/utils/common/RandomUtils.java b/ycl-common/src/main/java/com/ycl/utils/common/RandomUtils.java
index 34c3268..22a574e 100644
--- a/ycl-common/src/main/java/com/ycl/utils/common/RandomUtils.java
+++ b/ycl-common/src/main/java/com/ycl/utils/common/RandomUtils.java
@@ -6,4 +6,62 @@
* @date 2022/9/7
*/
public class RandomUtils {
+ /**
+ * 鐢ㄦ埛鍚�
+ */
+ private static final String NICK_NAME = "NK";
+
+ /**
+ * 鏍囪闀垮害
+ */
+ public static final int SIGN_LENGTH = 6;
+
+ /**
+ * 鏍囪鏍煎紡鍖栨牸寮忓寲瀛楃涓�
+ */
+ private static final String FORMT_STRING = "888888";
+
+ /**
+ * 鑾峰彇鐢ㄦ埛鍚�
+ *
+ * @param userId
+ * @return
+ */
+ public static String getUserId(long userId) {
+ return NICK_NAME + formatSign(userId)
+ + generateRandomInt(SIGN_LENGTH);
+
+ }
+
+ /**
+ * 鏍煎紡鍖栨爣璁�
+ *
+ * @return4
+ */
+ private static String formatSign(long param) {
+ String str = Long.toString(param);
+ int length = str.length() - SIGN_LENGTH;
+ if (length == 0) {
+ return str;
+ } else if (length < 0) {
+ str = "0" + str;
+ return FORMT_STRING.substring(0, Math.abs(length) - 1) + str;
+ } else {
+ return str.substring(length);
+ }
+ }
+
+ /**
+ * 鑾峰彇鎸囧畾闀垮害(1浣嶅埌9浣�)鐨勯殢鏈烘暟瀛楀瓧绗︿覆
+ *
+ * @param length 澶т簬1 灏忎簬9
+ * @return
+ */
+ public static String generateRandomInt(int length) {
+ length = length < 1 ? 1 : length;
+ length = length > 9 ? 9 : length;
+ int max = ((int) Math.pow(10, length)) - 1;
+ int min = (int) Math.pow(10, length - 1);
+ return String.valueOf((int) (Math.random() * (max - min) + min));
+ }
}
--
Gitblit v1.8.0