Pārlūkot izejas kodu

新增获取默认账号

赵冬冬 4 gadi atpakaļ
vecāks
revīzija
c80a7059c0

+ 1 - 1
carbon-admin/carbon-admin-service/src/main/java/com/hcloud/microserver/system/bank/service/impl/CompanyServiceImpl.java

@@ -28,7 +28,7 @@ public class CompanyServiceImpl implements CompanyService {
         int result = 0;
 
         String customerGuid = UUIDUtils.randomUUID();
-        customerInfo.setAccount(TracedCodeUtils.getCommonRandomCode());
+        customerInfo.setAccount(TracedCodeUtils.generateShortUuid());
         customerInfo.setPasswd(Md5Util.toMD5("000000"));
         customerInfo.setState(1);
         customerInfo.setIsEnable(1);

+ 1 - 1
carbon-back/carbon-back-service/src/main/java/com/hcloud/microserver/system/bank/service/impl/CompanyServiceImpl.java

@@ -28,7 +28,7 @@ public class CompanyServiceImpl implements CompanyService {
         int result = 0;
 
         String customerGuid = UUIDUtils.randomUUID();
-        customerInfo.setAccount(TracedCodeUtils.getCommonRandomCode());
+        customerInfo.setAccount(TracedCodeUtils.generateShortUuid());
         customerInfo.setPasswd(Md5Util.toMD5("000000"));
         customerInfo.setState(1);
         customerInfo.setIsEnable(1);

+ 1 - 1
carbon-h5/carbon-h5-service/src/main/java/com/hcloud/microserver/h5/biz/WechatManagerComponent.java

@@ -139,7 +139,7 @@ public class WechatManagerComponent{
                 customerForm.setState(1);
                 customerForm.setCreateTime(new Date());
                 customerForm.setModifiedTime(new Date());
-                customerInfoForm.setAccount(TracedCodeUtils.getCommonRandomCode());
+                customerInfoForm.setAccount(TracedCodeUtils.generateShortUuid());
                 //customerInfoForm.setPasswd(Md5Util.toMD5(CodeUtil.getSearchId()));
                 customerInfoForm.setPasswd(Md5Util.toMD5("000000"));
                 int i = customerInfoService.saveCustomerInfoByChannelInfo(customerInfoForm);

+ 1 - 1
carbon-h5/carbon-h5-service/src/main/java/com/hcloud/microserver/h5/service/impl/CompanyServiceImpl.java

@@ -28,7 +28,7 @@ public class CompanyServiceImpl implements CompanyService {
         int result = 0;
 
         String customerGuid = UUIDUtils.randomUUID();
-        customerInfo.setAccount(TracedCodeUtils.getCommonRandomCode());
+        customerInfo.setAccount(TracedCodeUtils.generateShortUuid());
         customerInfo.setPasswd(Md5Util.toMD5("000000"));
         customerInfo.setState(1);
         customerInfo.setIsEnable(1);

+ 2 - 2
carbon-h5/carbon-h5-service/src/main/java/com/hcloud/microserver/h5/service/impl/CustomerInfoServiceImpl.java

@@ -374,8 +374,8 @@ public class CustomerInfoServiceImpl implements CustomerInfoService {
             //默认密码
             String s = Md5Util.toMD5("000000");
             customerInfo.setPasswd(s);
-            //设置登陆账号
-            String commonRandomCode = TracedCodeUtils.getCommonRandomCode();
+            //设置登陆账号 默认给一个
+            String commonRandomCode = TracedCodeUtils.generateShortUuid();
             customerInfo.setAccount(commonRandomCode);
             customerInfoMapper.insertSelective(customerInfo);
         } else {

+ 62 - 33
common-core/src/main/java/com/hcloud/microserver/commoncore/util/TracedCodeUtils.java

@@ -3,8 +3,8 @@ package com.hcloud.microserver.commoncore.util;
 import com.hcloud.microserver.commoncore.util.string.StrUtil;
 import lombok.extern.slf4j.Slf4j;
 
-import java.util.Arrays;
-import java.util.List;
+import java.util.*;
+import java.util.concurrent.TimeUnit;
 
 /**
  * @author JYJ
@@ -12,6 +12,57 @@ import java.util.List;
 @Slf4j
 public class TracedCodeUtils {
 
+    public static void main(String[] args) throws InterruptedException {
+        Map<String, Long> map = new HashMap<>();
+        long starttime = new Date().getTime();
+        System.err.println();
+        for (int i = 0; i < 10000000; i++) {
+            String commonRandomCode = generateShortUuid();
+            Long count = map.get(commonRandomCode);
+            if (null != count) {
+                count = count + 1L;
+                map.put(commonRandomCode, count);
+            } else {
+                map.put(commonRandomCode, 1L);
+            }
+            System.err.println(commonRandomCode);
+
+        }
+
+        for (String s : map.keySet()) {
+            Long count = map.get(s);
+            if (count > 1) {
+                System.err.println(s + "---" + count);
+            }else {
+                //System.err.println(s + "---" + count);
+            }
+        }
+        long endtime = new Date().getTime();
+        long diff = endtime - starttime;
+        long time = diff / 1000;
+        System.err.println(time+":秒");
+    }
+
+    public static String[] chars = new String[]{"a", "b", "c", "d", "e", "f",
+            "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s",
+            "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5",
+            "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I",
+            "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V",
+            "W", "X", "Y", "Z"};
+
+
+    public static String generateShortUuid() {
+        StringBuffer shortBuffer = new StringBuffer();
+        String uuid = UUID.randomUUID().toString().replace("-", "");
+        for (int i = 0; i < 8; i++) {
+            String str = uuid.substring(i * 4, i * 4 + 4);
+            int x = Integer.parseInt(str, 16);
+            shortBuffer.append(chars[x % 0x3E]);
+        }
+        return shortBuffer.toString();
+
+    }
+
     private static final Integer[] ASCII_NUM = {65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77,
             78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90};
     private static final String[] ASCII_WORD = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J",
@@ -58,49 +109,27 @@ public class TracedCodeUtils {
 
     /**
      * 生成不重复的用户账号
+     *
      * @return
      */
-    public static String getCommonRandomCode(){
+    public static String getCommonRandomCode() {
         long nowDate = System.currentTimeMillis();
         StringBuffer ssb = new StringBuffer();
-        String sid = Integer.toHexString((int)nowDate);
+        String sid = Integer.toHexString((int) nowDate);
         List<String> arrayList = Arrays.asList(sid.split(""));
-        for(int i = 0; i < arrayList.size(); i++){
+        for (int i = 0; i < arrayList.size(); i++) {
             String tmp = arrayList.get(i);
-            if(!StrUtil.isNumeric(tmp)){
-                for (int j = 0; j <ASCII_WORD.length ; j++) {
+            if (!StrUtil.isNumeric(tmp)) {
+                for (int j = 0; j < ASCII_WORD.length; j++) {
                     String inner = ASCII_WORD[j];
-                    if(tmp.equalsIgnoreCase(inner)){
-                        ssb.append(ASCII_NUM[j]/10);
+                    if (tmp.equalsIgnoreCase(inner)) {
+                        ssb.append(ASCII_NUM[j] / 10);
                     }
                 }
-            }else{
+            } else {
                 ssb.append(tmp);
             }
         }
         return ssb.toString();
     }
-
-//    public static void main(String[] args) {
-//        long nowDate = System.currentTimeMillis();
-//        StringBuffer ssb = new StringBuffer();
-//        String sid = Integer.toHexString((int)nowDate);
-//        List<String> arrayList = Arrays.asList(sid.split(""));
-//        for(int i = 0; i < arrayList.size(); i++){
-//            String tmp = arrayList.get(i);
-//            if(!StrUtil.isNumeric(tmp)){
-//                for (int j = 0; j <ASCII_WORD.length ; j++) {
-//                    String inner = ASCII_WORD[j];
-//                    if(tmp.equalsIgnoreCase(inner)){
-//                        ssb.append(ASCII_NUM[j]/10);
-//                    }
-//                }
-//            }else{
-//                ssb.append(tmp);
-//            }
-//
-//        }
-//        System.out.println(ssb.toString());
-//
-//    }
 }