public class xxxGenerator {
private char[] arr = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','J','K','L','M','N',
'P','Q','R','S','T','U','V','W','X','Y','Z'};
private Integer bitCount = 8;
/**
* @desc : 生成规则:Q+年后两位+月+日卡券类型+八位字母和数字随机
**/
public String generator(xxTypeEnum type){
LocalDateTime nowTime = LocalDateTime.now();
StringBuffer sb = new StringBuffer();
sb.append("Q");
sb.append(String.valueOf(nowTime.getYear()).substring(2,4));
sb.append(String.format("%02d",nowTime.getMonthValue()));
sb.append(String.format("%02d",nowTime.getDayOfMonth()));
sb.append(type.getValue());
Random random = new Random();
for(int i=0;i<bitCount;i++){
sb.append(arr[random.nextInt(arr.length)]);
}
log.info("生成xx:{}",sb.toString());
return sb.toString();
}
public Set<String> next(TypeEnum type, int quantity){
Set<String> codes = Sets.newHashSet();
for (;codes.size() < quantity;){
// String uuid = UUID.randomUUID().toString().replace("-", "");
String code = generator(type);
codes.add(code);
}
return codes;
}
}