public class CodeBuilder {
static long increment = 0;
/**
* 生成测试流水号
*/
public static String generateAutoTestSerialNum(String prefix){
//生成时间戳
String timestamp = DateUtil.format(new Date(), "yyyyMMdd");
increment++;
return StrFormatter.format(prefix + "{}{}", timestamp, NumberUtil.decimalFormat("0000", increment));
}
}
雪花算法编号生成器
/**
* 主任务编号生成器
*/
public static String codeBuilderBySnow() {
SnowflakeIdUtil snowflakeIdUtil = SnowflakeIdUtil.newInstance();
long id = snowflakeIdUtil.nextId();
return "M" + id;
}