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:
@@ -97,16 +97,15 @@ public class IdUtils {
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String pileSn = "13273881";
|
||||
String connectorCode = "09";
|
||||
String s = generateTransactionCode(pileSn, connectorCode);
|
||||
System.out.println(s);
|
||||
for (int i = 0; i < 20; i++) {
|
||||
System.out.println(getOrderCode());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成12位orderCode
|
||||
*/
|
||||
public static String getOrderCode() {
|
||||
public static String getOrderCodeOld() {
|
||||
long id = Long.parseLong(SnowflakeIdWorker.getSnowflakeId());
|
||||
StringBuilder sb = new StringBuilder(id + "");
|
||||
StringBuilder reverse = sb.reverse();// 将id翻转:我们发现id很长,且高位很长部分是一样的数
|
||||
@@ -117,6 +116,33 @@ public class IdUtils {
|
||||
return String.valueOf(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成12位orderCode(纯字符串操作版本)
|
||||
*/
|
||||
public static String getOrderCode() {
|
||||
String snowflakeId = SnowflakeIdWorker.getSnowflakeId();
|
||||
|
||||
// 反转字符串
|
||||
String reversed = new StringBuilder(snowflakeId).reverse().toString();
|
||||
|
||||
// 去掉最后3位(相当于除以1000)
|
||||
if (reversed.length() > 3) {
|
||||
reversed = reversed.substring(0, reversed.length() - 3);
|
||||
}
|
||||
|
||||
// 如果长度超过12位,取前12位
|
||||
if (reversed.length() > 12) {
|
||||
reversed = reversed.substring(0, 12);
|
||||
}
|
||||
|
||||
// 如果长度不足12位,前面补0
|
||||
while (reversed.length() < 12) {
|
||||
reversed = "0" + reversed;
|
||||
}
|
||||
|
||||
return reversed;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成八位会员id
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user