Compare commits
2 Commits
3615ed9eec
...
32d3de7550
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
32d3de7550 | ||
|
|
bb2ddfc34a |
32
README.md
32
README.md
@@ -10,7 +10,7 @@
|
||||
|
||||
使用方法:
|
||||
|
||||
+ 在项目中放置jar包的地方把seq-1.8.2.jar、seq-1.8.2-sources.jar、seq-1.8.2-pom.xml复制过去
|
||||
+ 在项目中放置jar包的地方把seq-1.9.2.jar、seq-1.9.2-sources.jar、seq-1.9.2-pom.xml复制过去
|
||||
+ 在pom.xml中增加以下内容,然后执行maven命令:mvn clean
|
||||
|
||||
```xml
|
||||
@@ -20,7 +20,7 @@
|
||||
<dependency>
|
||||
<groupId>com.yanghuanglin</groupId>
|
||||
<artifactId>seq</artifactId>
|
||||
<version>1.8.2</version>
|
||||
<version>1.9.2</version>
|
||||
<exclusions>
|
||||
<!-- 如若你项目中有引用spring-jdbc,则需要排除seq的jdbc依赖 -->
|
||||
<exclusion>
|
||||
@@ -52,13 +52,13 @@
|
||||
</goals>
|
||||
<configuration>
|
||||
<!-- ${project.basedir}表示当前项目的根目录 -->
|
||||
<file>${project.basedir}/lib/seq-1.8.2.jar</file>
|
||||
<pomFile>${project.basedir}/lib/seq-1.8.2-pom.xml</pomFile>
|
||||
<sources>${project.basedir}/lib/seq-1.8.2-sources.jar</sources>
|
||||
<file>${project.basedir}/lib/seq-1.9.2.jar</file>
|
||||
<pomFile>${project.basedir}/lib/seq-1.9.2-pom.xml</pomFile>
|
||||
<sources>${project.basedir}/lib/seq-1.9.2-sources.jar</sources>
|
||||
<repositoryLayout>default</repositoryLayout>
|
||||
<groupId>com.yanghuanglin</groupId>
|
||||
<artifactId>seq</artifactId>
|
||||
<version>1.8.2</version>
|
||||
<version>1.9.2</version>
|
||||
<packaging>jar</packaging>
|
||||
<generatePom>true</generatePom>
|
||||
</configuration>
|
||||
@@ -383,6 +383,26 @@ public interface Generator {
|
||||
*/
|
||||
String format(Long seq, String start, Integer minLength, String pattern);
|
||||
|
||||
/**
|
||||
* 将生成的序号对象格式化为指定格式
|
||||
* <p/>
|
||||
* pattern支持:{@link FormatPlaceholder#YEAR}(当前年份)、{@link FormatPlaceholder#MONTH}}(当前月份)、{@link FormatPlaceholder#DAY}}(当前日期)、{@link FormatPlaceholder#SEQ}}(生成的字符串序号)几个枚举值通过{@link FormatPlaceholder#getPlaceholder()}得到的字符串
|
||||
* <p/>
|
||||
* seq为1,start为6,minLength为4,pattern为#year##month##day##seq#,则会格式化为2022013060001。此序号含义如下:
|
||||
* <p/>
|
||||
* 序号格式:[年][月][日][固定6开头][序号1,最小位数为4位,不足4位则补零]
|
||||
*
|
||||
* @param seq 需要格式化的序号
|
||||
* @param start 序号格式化后以什么字符串开头
|
||||
* @param minLength 序号最小长度,不足的会补零
|
||||
* @param pattern 序号格式
|
||||
* @param year 格式化时使用的年
|
||||
* @param month 格式化时使用的月
|
||||
* @param day 格式化时使用的日
|
||||
* @return 格式化后的序号字符串
|
||||
*/
|
||||
String format(Long seq, String start, Integer minLength, String pattern, Integer year, Integer month, Integer day);
|
||||
|
||||
/**
|
||||
* 将已格式化的序号解析为序号对象
|
||||
* <p/>
|
||||
|
||||
2
pom.xml
2
pom.xml
@@ -4,7 +4,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.yanghuanglin</groupId>
|
||||
<artifactId>seq</artifactId>
|
||||
<version>1.8.2</version>
|
||||
<version>1.9.2</version>
|
||||
<name>seq</name>
|
||||
<description>seq</description>
|
||||
<properties>
|
||||
|
||||
@@ -162,6 +162,26 @@ public interface Generator {
|
||||
*/
|
||||
String format(Long seq, String start, Integer minLength, String pattern);
|
||||
|
||||
/**
|
||||
* 将生成的序号对象格式化为指定格式
|
||||
* <p/>
|
||||
* pattern支持:{@link FormatPlaceholder#YEAR}(当前年份)、{@link FormatPlaceholder#MONTH}}(当前月份)、{@link FormatPlaceholder#DAY}}(当前日期)、{@link FormatPlaceholder#SEQ}}(生成的字符串序号)几个枚举值通过{@link FormatPlaceholder#getPlaceholder()}得到的字符串
|
||||
* <p/>
|
||||
* seq为1,start为6,minLength为4,pattern为#year##month##day##seq#,则会格式化为2022013060001。此序号含义如下:
|
||||
* <p/>
|
||||
* 序号格式:[年][月][日][固定6开头][序号1,最小位数为4位,不足4位则补零]
|
||||
*
|
||||
* @param seq 需要格式化的序号
|
||||
* @param start 序号格式化后以什么字符串开头
|
||||
* @param minLength 序号最小长度,不足的会补零
|
||||
* @param pattern 序号格式
|
||||
* @param year 格式化时使用的年
|
||||
* @param month 格式化时使用的月
|
||||
* @param day 格式化时使用的日
|
||||
* @return 格式化后的序号字符串
|
||||
*/
|
||||
String format(Long seq, String start, Integer minLength, String pattern, Integer year, Integer month, Integer day);
|
||||
|
||||
/**
|
||||
* 将已格式化的序号解析为序号对象
|
||||
* <p/>
|
||||
|
||||
@@ -176,13 +176,21 @@ public class SequencesGenerator implements Generator {
|
||||
|
||||
@Override
|
||||
public String format(Long seq, String start, Integer minLength, String pattern) {
|
||||
return format(seq, start, minLength, pattern, null, null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String format(Long seq, String start, Integer minLength, String pattern, Integer year, Integer month, Integer day) {
|
||||
if (start == null)
|
||||
start = "";
|
||||
String seqString = start + new Sequences(seq).format(minLength);
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
int year = calendar.get(Calendar.YEAR);
|
||||
int month = calendar.get(Calendar.MONTH) + 1;
|
||||
int day = calendar.get(Calendar.DAY_OF_MONTH);
|
||||
if (year == null)
|
||||
year = calendar.get(Calendar.YEAR);
|
||||
if (month == null)
|
||||
month = calendar.get(Calendar.MONTH) + 1;
|
||||
if (day == null)
|
||||
day = calendar.get(Calendar.DAY_OF_MONTH);
|
||||
pattern = pattern.replaceAll(YEAR.getPlaceholder(), String.valueOf(year));
|
||||
pattern = pattern.replaceAll(MONTH.getPlaceholder(), monthZeroFilling ? String.format("%02d", month) : String.valueOf(month));
|
||||
pattern = pattern.replaceAll(DAY.getPlaceholder(), dayZeroFilling ? String.format("%02d", day) : String.valueOf(day));
|
||||
|
||||
Reference in New Issue
Block a user