调整 增加固定字符串占位符
调整 解析序列号时,增加根据固定字符串长度解析 Sequences parse(String formatted, String pattern, Integer fixLength);
This commit is contained in:
@@ -1,14 +1,10 @@
|
||||
import com.mysql.cj.jdbc.MysqlDataSource;
|
||||
import com.yanghuanglin.seq.config.BaseConfig;
|
||||
import com.yanghuanglin.seq.config.GeneratorConfig;
|
||||
import com.yanghuanglin.seq.config.TableConfig;
|
||||
import com.yanghuanglin.seq.generator.Generator;
|
||||
import com.yanghuanglin.seq.generator.impl.SequencesGenerator;
|
||||
import com.yanghuanglin.seq.po.Sequences;
|
||||
import org.junit.Test;
|
||||
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.transaction.support.TransactionTemplate;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
@@ -51,12 +47,17 @@ public class SeqTest {
|
||||
Set<String> set = new HashSet<>();
|
||||
ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(10, 10, 1, TimeUnit.MINUTES, new ArrayBlockingQueue<>(100));
|
||||
for (int i = 0; i < 5; i++) {
|
||||
final int finalI = i;
|
||||
threadPoolExecutor.execute(() -> {
|
||||
Sequences sequences = generator.generate("SNT", "MISSION");
|
||||
String formattedSeq = generator.format(sequences.getSeq(), "处〔#year#〕10801#seq#");
|
||||
String pattern = "处〔#year#〕#fix##seq#";
|
||||
String fix = "10801" + finalI;
|
||||
String formattedSeq = generator.format(sequences.getSeq(), fix, pattern);
|
||||
generator.lock(sequences);
|
||||
set.add(formattedSeq);
|
||||
System.out.println(formattedSeq);
|
||||
Sequences parse = generator.parse(formattedSeq, pattern, fix.length());
|
||||
System.out.println(parse);
|
||||
});
|
||||
}
|
||||
threadPoolExecutor.shutdown();
|
||||
@@ -80,10 +81,11 @@ public class SeqTest {
|
||||
|
||||
@Test
|
||||
public void parseTest() {
|
||||
String seqPattern = "ZZF#year##month##seq#";
|
||||
String formatted = "ZZF20220200008";
|
||||
String seqPattern = "ZZF#year##month##fix##seq#";
|
||||
String formatted = "ZZF202202A18";
|
||||
|
||||
Sequences sequences = generator.parse(formatted, seqPattern);
|
||||
//A1视为固定字符串,其长度为2
|
||||
Sequences sequences = generator.parse(formatted, seqPattern, 2);
|
||||
|
||||
String key = "zzfCode" + sequences.getYear();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user