记得上下班打卡 | git大法好,push需谨慎
Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
liquidnet-bus-v1
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
董敬伟
liquidnet-bus-v1
Commits
7fe9b9d3
Commit
7fe9b9d3
authored
Jan 18, 2022
by
胡佳晨
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
生成取货码
parent
357923cb
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
577 additions
and
535 deletions
+577
-535
IDGenerator.java
...ain/java/com/liquidnet/commons/lang/util/IDGenerator.java
+19
-9
StringUtil.java
...main/java/com/liquidnet/commons/lang/util/StringUtil.java
+558
-526
No files found.
liquidnet-bus-common/liquidnet-common-base/src/main/java/com/liquidnet/commons/lang/util/IDGenerator.java
View file @
7fe9b9d3
...
...
@@ -69,11 +69,27 @@ public class IDGenerator {
}
public
static
String
storeRefundCode
(
String
orderMasterCode
)
{
return
orderMasterCode
.
concat
(
"R"
).
concat
(
RandomUtil
.
getRandomInt
(
0
,
50
)
+
""
);
return
orderMasterCode
.
concat
(
"R"
).
concat
(
RandomUtil
.
getRandomInt
(
0
,
99
)
+
""
);
}
public
static
String
getWriteOffCode
()
{
return
""
;
LocalDateTime
now
=
LocalDateTime
.
now
();
String
year
=
(
now
.
getYear
()+
""
).
substring
(
2
);
String
day
=
now
.
getDayOfYear
()+
""
;
String
hour
=
now
.
getHour
()+
""
;
String
sec
=
now
.
getSecond
()+
""
;
String
random
=
RandomUtil
.
getRandomInt
(
0
,
100
)+
""
;
if
(
day
.
length
()==
1
){
day
=
"0"
+
day
;
}
if
(
hour
.
length
()==
1
){
hour
=
"0"
+
hour
;
}
if
(
sec
.
length
()==
1
){
sec
=
"0"
+
sec
;
}
String
code
=
year
+
day
+
hour
+
sec
+
random
;
return
StringUtil
.
switchPosition
(
StringUtil
.
switchPosition
(
code
,
1
,
4
),
3
,
6
);
}
/**
...
...
@@ -123,12 +139,6 @@ public class IDGenerator {
}
public
static
void
main
(
String
[]
args
)
{
System
.
out
.
println
(
""
+
IDGenerator
.
payCode
());
System
.
out
.
println
(
""
+
IDGenerator
.
refundCode
());
System
.
out
.
println
(
"nextTimeId==="
+
IDGenerator
.
nextTimeId
());
System
.
out
.
println
(
"nextMilliId==="
+
IDGenerator
.
nextMilliId
());
System
.
out
.
println
(
"nextMilliId2==="
+
IDGenerator
.
nextMilliId2
());
System
.
out
.
println
(
"nextSnowId==="
+
IDGenerator
.
nextSnowId
());
System
.
out
.
println
(
"get32UUID==="
+
IDGenerator
.
get32UUID
());
System
.
out
.
println
(
getWriteOffCode
());
}
}
liquidnet-bus-common/liquidnet-common-base/src/main/java/com/liquidnet/commons/lang/util/StringUtil.java
View file @
7fe9b9d3
...
...
@@ -14,17 +14,25 @@ import java.util.Random;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
import
java.util.stream.IntStream
;
/**
* 字符串工具类
*
* @author <a href="kowlone2006@163.com">kowlone</a>
* @version 1.0 2012-4-20 上午2:13:53
*/
public
abstract
class
StringUtil
{
/** 随机数对象 */
/**
* 随机数对象
*/
private
static
final
Random
random
=
new
Random
();
/** 数字与字母字典 */
/**
* 数字与字母字典
*/
private
static
final
char
[]
LETTER_AND_DIGIT
=
(
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
).
toCharArray
();
/** 数字与字母字典长度 */
/**
* 数字与字母字典长度
*/
private
static
final
int
LETTER_AND_DIGIT_LENGTH
=
LETTER_AND_DIGIT
.
length
;
/** 使用Log4j2的消息格式化工厂 */
...
...
@@ -32,9 +40,9 @@ public abstract class StringUtil {
/**
* 检测字符串是否为空字符串
* 字符串为空的标准:null或全部由空字符组成的字符串
*
* @param str 待检测字符串
* @return
* <li>true:字符串是空字符串</li>
* @return <li>true:字符串是空字符串</li>
* <li>false:字符串不是空字符串</li>
*/
public
static
boolean
isEmpty
(
String
str
)
{
...
...
@@ -45,9 +53,9 @@ public abstract class StringUtil {
/**
* 检测字符串是否为空字符串
* 字符串为空的标准:null或全部由空字符组成的字符串
*
* @param obj 待检测字符串
* @return
* <li>true:字符串是空字符串</li>
* @return <li>true:字符串是空字符串</li>
* <li>false:字符串不是空字符串</li>
*/
public
static
boolean
isEmpty
(
Object
obj
)
{
...
...
@@ -59,9 +67,9 @@ public abstract class StringUtil {
/**
* 检测字符串是否不为空字符串
* 字符串为空的标准:null或全部由空字符组成的字符串
*
* @param str 待检测字符串
* @return
* <li>true:字符串不是空字符串</li>
* @return <li>true:字符串不是空字符串</li>
* <li>false:字符串是空字符串</li>
* @see #isEmpty(String)
*/
...
...
@@ -71,6 +79,7 @@ public abstract class StringUtil {
/**
* 将对象转换为字符串
*
* @param input 待转换对象
* @return 转换后的字符串
* @see #getString(Object, String)
...
...
@@ -84,6 +93,7 @@ public abstract class StringUtil {
/**
* 将对象转换为字符串
*
* @param input 待转换对象
* @param defVal 对象转换为空字符串时的默认返回值
* @return 转换后的字符串
...
...
@@ -96,6 +106,7 @@ public abstract class StringUtil {
/**
* 转换字符串
*
* @param input 待转换字符串
* @return 转换后的字符串
* @see #getString(String, String)
...
...
@@ -106,6 +117,7 @@ public abstract class StringUtil {
/**
* 转换字符串
*
* @param input 待转换字符串
* @param defVal 默认转换值
* @return 转换后的字符串
...
...
@@ -118,6 +130,7 @@ public abstract class StringUtil {
/**
* 生成固定长度的随机字符串
*
* @param len 随机字符串长度
* @return 生成的随机字符串
*/
...
...
@@ -134,6 +147,7 @@ public abstract class StringUtil {
/**
* 生成固定长度的随机字符串
*
* @param len 随机字符串长度
* @param dictionary 字符串字典
* @return 生成的随机字符串
...
...
@@ -151,6 +165,7 @@ public abstract class StringUtil {
/**
* 创建一个新的字符串
*
* @param bytes 字符串内容字节数组(UTF-8编码)
* @return 新创建的字符串
* @see #newString(byte[], String)
...
...
@@ -161,6 +176,7 @@ public abstract class StringUtil {
/**
* 创建一个新的字符串
*
* @param bytes 字符串内容字节数组
* @param charset 字符串字节编码
* @return 新创建的字符串
...
...
@@ -175,6 +191,7 @@ public abstract class StringUtil {
/**
* 取得字符串字节数组
*
* @param str 字符串
* @return 字符串内容字节数组
* @see #getBytes(String, String)
...
...
@@ -185,6 +202,7 @@ public abstract class StringUtil {
/**
* 取得字符串字节数组
*
* @param str 字符串
* @param charset 字符串字节编码
* @return 字符串内容字节数组
...
...
@@ -202,21 +220,22 @@ public abstract class StringUtil {
/**
* 从右侧开始截取固定长度的字符串
*
* @param str 待截取字符串
* @param length 截取的长度
* @return
* <li>null:字符串为空或字符串长度小于截取的长度</li>
* @return <li>null:字符串为空或字符串长度小于截取的长度</li>
* <li>非null:截取字符串后的结果</li>
*/
public
static
String
right
(
String
str
,
int
length
)
{
return
(
str
==
null
||
str
.
length
()
<
length
)
?
null
:
str
.
substring
(
str
.
length
()
-
length
);
}
/**
* 从左侧开始截取固定长度的字符串
*
* @param str 待截取字符串
* @param length 截取的长度
* @return
* <li>null:字符串为空或字符串长度小于截取的长度</li>
* @return <li>null:字符串为空或字符串长度小于截取的长度</li>
* <li>非null:截取字符串后的结果</li>
*/
public
static
String
left
(
String
str
,
int
length
)
{
...
...
@@ -225,14 +244,15 @@ public abstract class StringUtil {
/**
* 截取定长字符串(中文、字符、字母、数字……)
*
* @param str
* @param fixedWidth
* @return
*/
public
static
String
subFixedWidthString
(
String
str
,
int
fixedWidth
)
{
if
(
str
.
length
()
<=
fixedWidth
)
{
if
(
str
.
length
()
<=
fixedWidth
)
{
return
str
;
}
else
{
}
else
{
StringBuilder
ret
=
new
StringBuilder
();
fixedWidth
=
fixedWidth
<<
1
;
int
currentWidth
=
0
;
...
...
@@ -252,6 +272,7 @@ public abstract class StringUtil {
/**
* 将数组中字符串按照分隔符连接成一个字符串
*
* @param seperator 分隔符
* @param params 待连接字符串数组
* @return 连接后的字符串
...
...
@@ -259,8 +280,10 @@ public abstract class StringUtil {
public
static
String
join
(
String
seperator
,
Object
...
params
)
{
return
joinArray
(
seperator
,
params
);
}
/**
* 将数组中字符串按照分隔符连接成一个字符串
*
* @param seperator 分隔符
* @param params 待连接字符串数组
* @return 连接后的字符串
...
...
@@ -272,14 +295,14 @@ public abstract class StringUtil {
StringBuilder
ret
=
new
StringBuilder
();
for
(
Object
param
:
params
)
{
if
(
param
==
null
)
{
if
(
param
==
null
)
{
continue
;
}
if
(
ret
.
length
()
>
0
)
{
ret
.
append
(
seperator
);
}
if
(
param
.
getClass
().
isArray
())
{
ret
.
append
(
joinArray
(
seperator
,
(
Object
[])
param
));
ret
.
append
(
joinArray
(
seperator
,
(
Object
[])
param
));
}
else
{
ret
.
append
(
param
);
}
...
...
@@ -289,10 +312,10 @@ public abstract class StringUtil {
/**
* 比较两个字符串大小
*
* @param str1 字符串1
* @param str2 字符串2
* @return
* <li>-1:str1小</li>
* @return <li>-1:str1小</li>
* <li>0:两字符串相等</li>
* <li>1:str2小</li>
*/
...
...
@@ -328,6 +351,7 @@ public abstract class StringUtil {
/**
* 根据参数填充占位符,构建字符串消息,例如:
* msg=我是{} params:小明 返回值为:我是小明
*
* @param message
* @param params
* @return
...
...
@@ -342,18 +366,19 @@ public abstract class StringUtil {
/**
* 过滤空格
*
* @param str 待过滤字符串
* @return 过滤结果
*/
public
static
String
trim
(
String
str
)
{
public
static
String
trim
(
String
str
)
{
return
str
==
null
?
null
:
str
.
trim
();
}
/**
* 将字符串指定索引位的字符转换为大写
*
* @param source
* @param index
*
* @return
*/
public
static
String
toUpperCase
(
String
source
,
int
index
)
{
...
...
@@ -399,7 +424,7 @@ public abstract class StringUtil {
}
public
static
final
boolean
isEmail
(
String
str
)
{
String
paString
=
"^([a-zA-Z0-9]*[-_]?[a-zA-Z0-9]+)*@([a-zA-Z0-9]*[-_]?[a-zA-Z0-9]+)+[\\.][A-Za-z]{2,3}([\\.][A-Za-z]{2})?$"
;
String
paString
=
"^([a-zA-Z0-9]*[-_]?[a-zA-Z0-9]+)*@([a-zA-Z0-9]*[-_]?[a-zA-Z0-9]+)+[\\.][A-Za-z]{2,3}([\\.][A-Za-z]{2})?$"
;
Pattern
pattern
=
Pattern
.
compile
(
paString
);
// 验证邮箱
Matcher
matcher
=
pattern
.
matcher
(
str
);
boolean
b
=
matcher
.
matches
();
...
...
@@ -437,8 +462,9 @@ public abstract class StringUtil {
return
left
(
idcardNumber
,
2
)
+
"****"
+
idcardNumber
.
substring
(
6
,
8
)
+
"******"
+
right
(
idcardNumber
,
4
);
}
}
public
static
String
hiddenBankId
(
String
bankId
){
if
(
isEmpty
(
bankId
)){
public
static
String
hiddenBankId
(
String
bankId
)
{
if
(
isEmpty
(
bankId
))
{
return
""
;
}
StringBuilder
sb
=
new
StringBuilder
();
...
...
@@ -451,9 +477,9 @@ public abstract class StringUtil {
public
static
boolean
isBlank
(
CharSequence
cs
)
{
int
strLen
;
if
(
cs
!=
null
&&
(
strLen
=
cs
.
length
())
!=
0
)
{
for
(
int
i
=
0
;
i
<
strLen
;
++
i
)
{
if
(!
Character
.
isWhitespace
(
cs
.
charAt
(
i
)))
{
if
(
cs
!=
null
&&
(
strLen
=
cs
.
length
())
!=
0
)
{
for
(
int
i
=
0
;
i
<
strLen
;
++
i
)
{
if
(!
Character
.
isWhitespace
(
cs
.
charAt
(
i
)))
{
return
false
;
}
}
...
...
@@ -468,12 +494,12 @@ public abstract class StringUtil {
return
!
isBlank
(
cs
);
}
public
static
String
andStartTime
(
String
start
){
return
start
+
" 00:00:00"
;
public
static
String
andStartTime
(
String
start
)
{
return
start
+
" 00:00:00"
;
}
public
static
String
andEndTime
(
String
end
){
return
end
+
" 23:59:59"
;
public
static
String
andEndTime
(
String
end
)
{
return
end
+
" 23:59:59"
;
}
...
...
@@ -491,8 +517,7 @@ public abstract class StringUtil {
* @param object Object
* @return true:为空 false:非空
*/
public
static
boolean
isNull
(
Object
object
)
{
public
static
boolean
isNull
(
Object
object
)
{
return
object
==
null
;
}
...
...
@@ -502,8 +527,7 @@ public abstract class StringUtil {
* @param object Object
* @return true:非空 false:空
*/
public
static
boolean
isNotNull
(
Object
object
)
{
public
static
boolean
isNotNull
(
Object
object
)
{
return
!
isNull
(
object
);
}
...
...
@@ -511,10 +535,9 @@ public abstract class StringUtil {
* * 判断一个对象数组是否为空
*
* @param objects 要判断的对象数组
*
* @return true:为空 false:非空
*
* @return true:为空 false:非空
*/
public
static
boolean
isEmpty
(
Object
[]
objects
)
{
public
static
boolean
isEmpty
(
Object
[]
objects
)
{
return
isNull
(
objects
)
||
(
objects
.
length
==
0
);
}
...
...
@@ -524,8 +547,7 @@ public abstract class StringUtil {
* @param objects 要判断的对象数组
* @return true:非空 false:空
*/
public
static
boolean
isNotEmpty
(
Object
[]
objects
)
{
public
static
boolean
isNotEmpty
(
Object
[]
objects
)
{
return
!
isEmpty
(
objects
);
}
...
...
@@ -535,8 +557,7 @@ public abstract class StringUtil {
* @param coll 要判断的Collection
* @return true:为空 false:非空
*/
public
static
boolean
isEmpty
(
Collection
<?>
coll
)
{
public
static
boolean
isEmpty
(
Collection
<?>
coll
)
{
return
isNull
(
coll
)
||
coll
.
isEmpty
();
}
...
...
@@ -546,8 +567,7 @@ public abstract class StringUtil {
* @param coll 要判断的Collection
* @return true:非空 false:空
*/
public
static
boolean
isNotEmpty
(
Collection
<?>
coll
)
{
public
static
boolean
isNotEmpty
(
Collection
<?>
coll
)
{
return
!
isEmpty
(
coll
);
}
...
...
@@ -557,8 +577,7 @@ public abstract class StringUtil {
* @param map 要判断的Map
* @return true:为空 false:非空
*/
public
static
boolean
isEmpty
(
Map
<?,
?>
map
)
{
public
static
boolean
isEmpty
(
Map
<?,
?>
map
)
{
return
isNull
(
map
)
||
map
.
isEmpty
();
}
...
...
@@ -568,8 +587,7 @@ public abstract class StringUtil {
* @param map 要判断的Map
* @return true:非空 false:空
*/
public
static
boolean
isNotEmpty
(
Map
<?,
?>
map
)
{
public
static
boolean
isNotEmpty
(
Map
<?,
?>
map
)
{
return
!
isEmpty
(
map
);
}
...
...
@@ -580,14 +598,10 @@ public abstract class StringUtil {
* @param strs 字符串组
* @return 包含返回true
*/
public
static
boolean
inStringIgnoreCase
(
String
str
,
String
...
strs
)
{
if
(
str
!=
null
&&
strs
!=
null
)
{
for
(
String
s
:
strs
)
{
if
(
str
.
equalsIgnoreCase
(
trim
(
s
)))
{
public
static
boolean
inStringIgnoreCase
(
String
str
,
String
...
strs
)
{
if
(
str
!=
null
&&
strs
!=
null
)
{
for
(
String
s
:
strs
)
{
if
(
str
.
equalsIgnoreCase
(
trim
(
s
)))
{
return
true
;
}
}
...
...
@@ -595,10 +609,28 @@ public abstract class StringUtil {
return
false
;
}
/**
* 字符串位置交换
*
* @param p1 位置1
* @param p2 位置2
* @return 交换位置大于字符长度返回原字符。小于返回交换后结果
*/
public
static
String
switchPosition
(
String
str
,
int
p1
,
int
p2
)
{
if
(
str
.
length
()
<
p1
+
1
||
str
.
length
()
<
p2
+
1
)
{
return
str
;
}
char
[]
charArray
=
str
.
toCharArray
();
char
temp
=
charArray
[
p1
];
charArray
[
p1
]
=
charArray
[
p2
];
charArray
[
p2
]
=
temp
;
return
String
.
valueOf
(
charArray
);
}
public
static
void
main
(
String
[]
args
)
{
System
.
out
.
println
(
isEmail
(
"123@qq.com#$%^&*()"
));
String
regEx
=
"[\n`~!@#$%^&*()+=|{}':;',\\[\\].<>/?~!@#¥%……&*()——+|{}【】‘;:”“’。, 、?]"
;
String
regEx
=
"[\n`~!@#$%^&*()+=|{}':;',\\[\\].<>/?~!@#¥%……&*()——+|{}【】‘;:”“’。, 、?]"
;
//可以在中括号内加上任何想要替换的字符,实际上是一个正则表达式
...
...
@@ -609,7 +641,7 @@ public abstract class StringUtil {
Matcher
m
=
p
.
matcher
(
"原字符串"
);
//这里把想要替换的字符串传进来
String
newString
=
m
.
replaceAll
(
aa
).
trim
();
System
.
out
.
println
(
"newString====="
+
newString
);
System
.
out
.
println
(
"newString====="
+
newString
);
//将替换后的字符串存在变量newString中
...
...
@@ -617,8 +649,8 @@ public abstract class StringUtil {
String
str
=
"#$%^&*()我的正确#$%^&*()原字符串#$%^&*()"
;
String
newString2
=
str
.
replaceAll
(
regEx
,
aa
).
trim
();
//不想保留原来的字符串可以直接写成 “str = str.replaceAll(regEX,aa);”
System
.
out
.
println
(
"newString2====="
+
newString2
);
String
newString2
=
str
.
replaceAll
(
regEx
,
aa
).
trim
();
//不想保留原来的字符串可以直接写成 “str = str.replaceAll(regEX,aa);”
System
.
out
.
println
(
"newString2====="
+
newString2
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment