mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-20 02:55:04 +08:00
新增 用户反馈信息表
This commit is contained in:
@@ -3,6 +3,8 @@ package com.jsowell.common.util.id;
|
||||
import com.jsowell.common.util.DateUtils;
|
||||
import com.jsowell.common.util.RandomUtil;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* ID生成器工具类
|
||||
*
|
||||
@@ -130,5 +132,47 @@ public class IdUtils {
|
||||
return String.valueOf(num);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成以FB开头的流水号
|
||||
* @param length 流水号总长度(必须大于14,因为FB+年月日时分秒(14位)已经占用了16位)
|
||||
* @return 生成的流水号
|
||||
* @throws IllegalArgumentException 如果length小于16时抛出异常
|
||||
*/
|
||||
public static String generateFBSerialNumber(int length) {
|
||||
if (length < 16) {
|
||||
throw new IllegalArgumentException("长度至少为16位数!");
|
||||
}
|
||||
|
||||
// 获取当前时间并格式化为yyyyMMddHHmmss
|
||||
String timePart = DateUtils.dateTimeNow(DateUtils.YYMMDDHHMMSS);
|
||||
|
||||
// 计算需要的随机数长度
|
||||
int randomLength = length - 2 - 14; // 2(FB) + 14(时间部分)
|
||||
|
||||
// 生成随机数部分
|
||||
String randomPart = generateRandomNumber(randomLength);
|
||||
|
||||
// 组合所有部分
|
||||
return "FB" + timePart + randomPart;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成指定长度的随机数字字符串
|
||||
* @param length 随机数长度
|
||||
* @return 随机数字字符串
|
||||
*/
|
||||
private static String generateRandomNumber(int length) {
|
||||
if (length <= 0) {
|
||||
return "";
|
||||
}
|
||||
|
||||
Random random = new Random();
|
||||
StringBuilder sb = new StringBuilder(length);
|
||||
|
||||
for (int i = 0; i < length; i++) {
|
||||
sb.append(random.nextInt(10));
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user