Commit 45e185d9 by songxiang

错题本二期相关代码

parent 0a9981a5
...@@ -344,4 +344,8 @@ public class MQTopicProducer { ...@@ -344,4 +344,8 @@ public class MQTopicProducer {
* 微信群用户绑定TOPIC * 微信群用户绑定TOPIC
*/ */
public static final String WXGROUP_USER_BIND = "topic.wXGroupUserBind"; public static final String WXGROUP_USER_BIND = "topic.wXGroupUserBind";
/**
* 商品创建
*/
public static final String PRODUCT_CREATE = "topic.productCreate";
} }
...@@ -6,201 +6,218 @@ import java.util.UUID; ...@@ -6,201 +6,218 @@ import java.util.UUID;
/** /**
* @描述:生成随机数 * @描述:生成随机数
* @作者:DiSeng.H * @作者:DiSeng.H
* @创建时间:2016年3月10日,下午1:17:02 * @创建时间:2016年3月10日,下午1:17:02 @版本:1.0
* @版本:1.0
*/ */
public class UUIDUitl { public class UUIDUitl {
public static final String allCharStr = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()_+";
public static final String allChar = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; public static final String allCharStr = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()_+";
public static final String letterChar = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; public static final String allChar = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
public static final String numberChar = "0123456789"; public static final String letterChar = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
public static final String specialChar = "!@#$%^&*()_+"; public static final String numberChar = "0123456789";
/** public static final String specialChar = "!@#$%^&*()_+";
* 生成的token /**
*/ * 生成的token
public static final String someCharStr="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@$%^&*()_+"; */
public static final String someCharStr = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@$%^&*()_+";
/**
* 返回一个定长的随机字符串(只包含大小写字母、数字) 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",
* @param length "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",
* @return 随机字符串 "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V",
*/ "W", "X", "Y", "Z"};
public static String generateInteger(int length) {
StringBuffer sb = new StringBuffer(); /**
Random random = new Random(); * 生成8位不重复的随机码
for (int i = 0; i < length; i++) { *
sb.append(numberChar.charAt(random.nextInt(numberChar.length()))); * @return
} */
return sb.toString(); public static String generateShort() {
} 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);
* @param length shortBuffer.append(chars[x % 0x3E]);
* 随机字符串长度 }
* @return 随机字符串 return shortBuffer.toString();
*/ }
public static String generateString(int length) {
StringBuffer sb = new StringBuffer(); public static void main(String[] args) {
Random random = new Random(); System.out.println(generateShort());
for (int i = 0; i < length; i++) { }
sb.append(allChar.charAt(random.nextInt(allChar.length())));
} /**
return sb.toString(); * 返回一个定长的随机字符串(只包含大小写字母、数字)
} *
* @param length 随机字符串长度
/** * @return 随机字符串
* 返回一个定长的随机字符串(只包含大小写字母、数字) */
* public static String generateInteger(int length) {
* @param length StringBuffer sb = new StringBuffer();
* 随机字符串长度 Random random = new Random();
* @return 随机字符串 for (int i = 0; i < length; i++) {
*/ sb.append(numberChar.charAt(random.nextInt(numberChar.length())));
public static String generateAllString(int length) { }
StringBuffer sb = new StringBuffer(); return sb.toString();
Random random = new Random(); }
for (int i = 0; i < length; i++) {
sb.append(allCharStr.charAt(random.nextInt(allCharStr.length()))); /**
} * 返回一个定长的随机字符串(只包含大小写字母、数字)
return sb.toString(); *
} * @param length 随机字符串长度
/** * @return 随机字符串
* 返回一个定长的随机字符串(只包含大小写字母、数字),不包含# */
* public static String generateString(int length) {
* @param length StringBuffer sb = new StringBuffer();
* 随机字符串长度 Random random = new Random();
* @return 随机字符串 for (int i = 0; i < length; i++) {
*/ sb.append(allChar.charAt(random.nextInt(allChar.length())));
public static String generateSomeString(int length) { }
StringBuffer sb = new StringBuffer(); return sb.toString();
Random random = new Random(); }
for (int i = 0; i < length; i++) {
sb.append(someCharStr.charAt(random.nextInt(someCharStr.length()))); /**
} * 返回一个定长的随机字符串(只包含大小写字母、数字)
return sb.toString(); *
} * @param length 随机字符串长度
/** * @return 随机字符串
* 返回一个定长的随机纯字母字符串(只包含大小写字母) */
* public static String generateAllString(int length) {
* @param length StringBuffer sb = new StringBuffer();
* 随机字符串长度 Random random = new Random();
* @return 随机字符串 for (int i = 0; i < length; i++) {
*/ sb.append(allCharStr.charAt(random.nextInt(allCharStr.length())));
public static String generateMixString(int length) { }
StringBuffer sb = new StringBuffer(); return sb.toString();
Random random = new Random(); }
for (int i = 0; i < length; i++) {
sb.append(allChar.charAt(random.nextInt(letterChar.length()))); /**
} * 返回一个定长的随机字符串(只包含大小写字母、数字),不包含#
return sb.toString(); *
} * @param length 随机字符串长度
* @return 随机字符串
/** */
* 返回一个定长的随机纯大写字母字符串(只包含大小写字母) public static String generateSomeString(int length) {
* StringBuffer sb = new StringBuffer();
* @param length Random random = new Random();
* 随机字符串长度 for (int i = 0; i < length; i++) {
* @return 随机字符串 sb.append(someCharStr.charAt(random.nextInt(someCharStr.length())));
*/ }
public static String generateLowerString(int length) { return sb.toString();
return generateMixString(length).toLowerCase(); }
}
/**
/** * 返回一个定长的随机纯字母字符串(只包含大小写字母)
* 返回一个定长的随机纯小写字母字符串(只包含大小写字母) *
* * @param length 随机字符串长度
* @param length * @return 随机字符串
* 随机字符串长度 */
* @return 随机字符串 public static String generateMixString(int length) {
*/ StringBuffer sb = new StringBuffer();
public static String generateUpperString(int length) { Random random = new Random();
return generateMixString(length).toUpperCase(); for (int i = 0; i < length; i++) {
} sb.append(allChar.charAt(random.nextInt(letterChar.length())));
}
/** return sb.toString();
* 生成一个定长的纯0字符串 }
*
* @param length /**
* 字符串长度 * 返回一个定长的随机纯大写字母字符串(只包含大小写字母)
* @return 纯0字符串 *
*/ * @param length 随机字符串长度
public static String generateZeroString(int length) { * @return 随机字符串
StringBuffer sb = new StringBuffer(); */
for (int i = 0; i < length; i++) { public static String generateLowerString(int length) {
sb.append('0'); return generateMixString(length).toLowerCase();
} }
return sb.toString();
} /**
* 返回一个定长的随机纯小写字母字符串(只包含大小写字母)
/** *
* 根据数字生成一个定长的字符串,长度不够前面补0 * @param length 随机字符串长度
* * @return 随机字符串
* @param num */
* 数字 public static String generateUpperString(int length) {
* @param fixdlenth return generateMixString(length).toUpperCase();
* 字符串长度 }
* @return 定长的字符串
*/ /**
public static String toFixdLengthString(long num, int fixdlenth) { * 生成一个定长的纯0字符串
StringBuffer sb = new StringBuffer(); *
String strNum = String.valueOf(num); * @param length 字符串长度
if (fixdlenth - strNum.length() >= 0) { * @return 纯0字符串
sb.append(generateZeroString(fixdlenth - strNum.length())); */
} else { public static String generateZeroString(int length) {
throw new RuntimeException("将数字" + num + "转化为长度为" + fixdlenth + "的字符串发生异常!"); StringBuffer sb = new StringBuffer();
} for (int i = 0; i < length; i++) {
sb.append(strNum); sb.append('0');
return sb.toString(); }
} return sb.toString();
}
/**
* 根据数字生成一个定长的字符串,长度不够前面补0 /**
* * 根据数字生成一个定长的字符串,长度不够前面补0
* @param num *
* 数字 * @param num 数字
* @param fixdlenth * @param fixdlenth 字符串长度
* 字符串长度 * @return 定长的字符串
* @return 定长的字符串 */
*/ public static String toFixdLengthString(long num, int fixdlenth) {
public static String toFixdLengthString(int num, int fixdlenth) { StringBuffer sb = new StringBuffer();
StringBuffer sb = new StringBuffer(); String strNum = String.valueOf(num);
String strNum = String.valueOf(num); if (fixdlenth - strNum.length() >= 0) {
if (fixdlenth - strNum.length() >= 0) { sb.append(generateZeroString(fixdlenth - strNum.length()));
sb.append(generateZeroString(fixdlenth - strNum.length())); } else {
} else { throw new RuntimeException("将数字" + num + "转化为长度为" + fixdlenth + "的字符串发生异常!");
throw new RuntimeException("将数字" + num + "转化为长度为" + fixdlenth + "的字符串发生异常!"); }
} sb.append(strNum);
sb.append(strNum); return sb.toString();
return sb.toString(); }
}
/**
/** * 根据数字生成一个定长的字符串,长度不够前面补0
* 八位数字+字母+特殊字符随机密码生成 *
* * @param num 数字
* @return * @param fixdlenth 字符串长度
*/ * @return 定长的字符串
public static String generatePwdStr() { */
StringBuffer sb = new StringBuffer(); public static String toFixdLengthString(int num, int fixdlenth) {
Random random = new Random(); StringBuffer sb = new StringBuffer();
for (int i = 0; i < 3; i++) { String strNum = String.valueOf(num);
sb.append(allChar.charAt(random.nextInt(letterChar.length()))); if (fixdlenth - strNum.length() >= 0) {
sb.append(numberChar.charAt(random.nextInt(numberChar.length()))); sb.append(generateZeroString(fixdlenth - strNum.length()));
} } else {
for (int i = 0; i < 2; i++) { throw new RuntimeException("将数字" + num + "转化为长度为" + fixdlenth + "的字符串发生异常!");
sb.append(specialChar.charAt(random.nextInt(specialChar.length()))); }
} sb.append(strNum);
return sb.toString(); return sb.toString();
} }
/** /**
* 生成随机任务名称 * 八位数字+字母+特殊字符随机密码生成
* *
* @return * @return
*/ */
public static String taskName() { public static String generatePwdStr() {
return UUID.randomUUID().toString().replace("-", ""); StringBuffer sb = new StringBuffer();
} Random random = new Random();
for (int i = 0; i < 3; i++) {
sb.append(allChar.charAt(random.nextInt(letterChar.length())));
sb.append(numberChar.charAt(random.nextInt(numberChar.length())));
}
for (int i = 0; i < 2; i++) {
sb.append(specialChar.charAt(random.nextInt(specialChar.length())));
}
return sb.toString();
}
/**
* 生成随机任务名称
*
* @return
*/
public static String taskName() {
return UUID.randomUUID().toString().replace("-", "");
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment