|
|
@ -28,6 +28,16 @@ public class CodeGenUtil { |
|
|
|
private String code; |
|
|
|
} |
|
|
|
|
|
|
|
@Getter |
|
|
|
@AllArgsConstructor |
|
|
|
public enum SourceDataKey{ |
|
|
|
SaleRegion("S","SaleRegion"), |
|
|
|
BizRegion("B","BizRegion"); |
|
|
|
private String prefix; |
|
|
|
private String code; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static final int split_num = 1000; |
|
|
|
|
|
|
|
|
|
|
@ -39,6 +49,19 @@ public class CodeGenUtil { |
|
|
|
"X" , "Y" |
|
|
|
}; |
|
|
|
|
|
|
|
public static Long getIdx(String key){ |
|
|
|
RedisService redisService = SpringUtils.getBean(RedisService.class); |
|
|
|
Long value = redisService.getLong(key); |
|
|
|
if(value==null){ |
|
|
|
redisService.set(key,1); |
|
|
|
value = 1L; |
|
|
|
}else { |
|
|
|
value++; |
|
|
|
} |
|
|
|
redisService.set(key,value); |
|
|
|
return value; |
|
|
|
} |
|
|
|
|
|
|
|
public static String generate(SourceKey sourceKey){ |
|
|
|
try { |
|
|
|
LocalDate localDateTime = LocalDate.now(); |
|
|
@ -46,38 +69,33 @@ public class CodeGenUtil { |
|
|
|
String localTime = df.format(localDateTime); |
|
|
|
localTime = localTime.substring(2); |
|
|
|
String key = "code_index:"+sourceKey.getCode()+":"+localTime; |
|
|
|
RedisService redisService = SpringUtils.getBean(RedisService.class); |
|
|
|
Long value = redisService.getLong(key); |
|
|
|
if(value==null){ |
|
|
|
redisService.set(key,1); |
|
|
|
value = 1L; |
|
|
|
}else { |
|
|
|
value++; |
|
|
|
} |
|
|
|
redisService.set(key,value); |
|
|
|
String digitsNum = ""; |
|
|
|
String appendStr = value+""; |
|
|
|
if(value>split_num){ |
|
|
|
appendStr = (value%100)+""; |
|
|
|
Long d = value/split_num; |
|
|
|
digitsNum = digits2[d.intValue()]; |
|
|
|
} |
|
|
|
StringBuilder appendZeros = new StringBuilder(); |
|
|
|
for (int i = (appendStr+digitsNum).length(); i < 3; i++) { |
|
|
|
appendZeros.append("0"); |
|
|
|
} |
|
|
|
return localTime + digitsNum + appendZeros + appendStr; |
|
|
|
return localTime + getCommonValue(key); |
|
|
|
} catch (BeansException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
return IdUtil.getSnowflakeNextIdStr(); |
|
|
|
} |
|
|
|
|
|
|
|
public static void main(String[] args) { |
|
|
|
long value = 99; |
|
|
|
long v2 = value/1000; |
|
|
|
System.out.println(v2); |
|
|
|
System.out.println(value%1000); |
|
|
|
public static String getCommonValue(String key){ |
|
|
|
Long value = getIdx(key); |
|
|
|
String digitsNum = ""; |
|
|
|
String appendStr = value+""; |
|
|
|
if(value>split_num){ |
|
|
|
appendStr = (value%100)+""; |
|
|
|
Long d = value/split_num; |
|
|
|
digitsNum = digits2[d.intValue()]; |
|
|
|
} |
|
|
|
StringBuilder appendZeros = new StringBuilder(); |
|
|
|
for (int i = (appendStr+digitsNum).length(); i < 3; i++) { |
|
|
|
appendZeros.append("0"); |
|
|
|
} |
|
|
|
return digitsNum + appendZeros + appendStr; |
|
|
|
} |
|
|
|
|
|
|
|
public static String getDataCode(SourceDataKey dataKey){ |
|
|
|
String key = "code_data_index:"+dataKey.getCode(); |
|
|
|
String commonVal = getCommonValue(key); |
|
|
|
return dataKey.getPrefix() + commonVal; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|