Commit f3e00e7c by 张富康

EvalNoGenerator工具类

1 parent 069cc8fe
package com.gsc4cloud.gsc.vpc.api.util;
import com.gsc4cloud.gsc.common.snowflake.core.SnowflakeWorker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.UUID;
/**
* 评估单号生成工具类
* 生成规则:er + 雪花算法
*
* @author zhangfk
*/
@Component
public class EvalNoGenerator {
/**
* 评估单号前缀
*/
private static final String EVAL_ORDER_PREFIX = "er";
private static final String EVAL_CONTRACT_NO_PREFIX = "ec";
/**
* 雪花算法实例
*/
private final SnowflakeWorker snowflake;
@Autowired
private ShortLinkComponent shortLinkComponent;
public EvalNoGenerator() {
// 使用 Hutool 的雪花算法,workerId 和 datacenterId 可以根据实际情况配置
this.snowflake = new SnowflakeWorker(1, 1);
}
/**
* 生成评估单号
* 格式:er + 雪花算法生成的ID
*
* @return 评估单号
*/
public String generateEvalOrderNo() {
long id = snowflake.nextId();
return EVAL_ORDER_PREFIX + id;
}
/**
* 生成合同编号
*
* @return 合同编号
*/
public String generateContractNo() {
long id = snowflake.nextId();
return EVAL_CONTRACT_NO_PREFIX + id;
}
/**
* 生成车源号
* @return 车源号
*/
public String generateSourceNo() {
String prefix = java.time.format.DateTimeFormatter.ofPattern("yyMM").format(java.time.LocalDate.now());
String code = shortLinkComponent.createShortLinkCode(UUID.randomUUID().toString());
return prefix + code;
}
}
\ No newline at end of file \ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!