Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jiedao-api-boot-master
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
lanbaoming
jiedao-api-boot-master
Commits
25df501c
Commit
25df501c
authored
Feb 26, 2025
by
wux
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bug275:订单编号取值算费存在漏洞,不支持多位国家编码
parent
82d1a216
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
86 additions
and
28 deletions
+86
-28
CodeUtils.java
...n/iocoder/yudao/framework/common/util/code/CodeUtils.java
+86
-28
No files found.
yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/code/CodeUtils.java
View file @
25df501c
...
...
@@ -406,11 +406,16 @@ public class CodeUtils {
* * ➢ 海空联运:22年发往莫桑比克的城市Maputo—JMSA2200001M——(国家+运输方式+年份+4位数字+城市)
* @return java.lang.String
*/
public
static
String
getOddOrderNumbers
(
String
maxOddOrderNumbers
,
String
countryShort
,
String
countryAirShort
,
String
transportShort
,
String
cityShort
,
Boolean
isExternalWarehouse
,
Boolean
isConcentrateTransport
)
{
//定义变量(最新的单号)
public
static
String
getOddOrderNumbers
(
String
maxOddOrderNumbers
,
String
countryShort
,
String
countryAirShort
,
String
transportShort
,
String
cityShort
,
Boolean
isExternalWarehouse
,
Boolean
isConcentrateTransport
)
{
// 定义变量(最新的单号)
String
newOddOrderNO
=
""
;
//获取当前日期并将其进行格式化
//
获取当前日期并将其进行格式化
String
formatDate
=
getDateTime
(
"yy"
);
if
(
isExternalWarehouse
==
null
)
{
isExternalWarehouse
=
false
;
...
...
@@ -421,38 +426,91 @@ public class CodeUtils {
if
(
countryAirShort
==
null
)
{
countryAirShort
=
""
;
}
//订单前缀(非空运和整柜订单)
StringBuilder
orderPrefix
=
new
StringBuilder
();
orderPrefix
.
append
(
countryShort
).
append
(
transportShort
).
append
(
formatDate
);
// 海运拼柜结尾参数是目的地城市代码,专线空运结尾参数是始发地城市代码
// TODO 整柜订单编号结尾参数暂时不存在,海空联运的结尾暂时同海运拼柜
int
endIndex
=
(
StringUtils
.
equals
(
transportShort
,
"A"
)
?
0
:
cityShort
.
length
());
//判断数据中的最大单号是否存在,是否包含当前日期
// 判断数据中的最大单号是否存在,是否包含当前日期
if
(
StringUtils
.
isNotEmpty
(
maxOddOrderNumbers
)
&&
maxOddOrderNumbers
.
contains
(
formatDate
))
{
//截取后四位数
String
endNum
=
StringUtils
.
equals
(
transportShort
,
"F"
)
?
maxOddOrderNumbers
.
substring
(
5
)
:
(
StringUtils
.
equals
(
transportShort
,
"SA"
)
?
maxOddOrderNumbers
.
substring
(
isExternalWarehouse
&&
isConcentrateTransport
?
6
:
(
isExternalWarehouse
||
isConcentrateTransport
?
5
:
4
),
maxOddOrderNumbers
.
length
()
-
endIndex
)
:
(
StringUtils
.
equals
(
transportShort
,
"A"
)
?
maxOddOrderNumbers
.
substring
(
isExternalWarehouse
&&
isConcentrateTransport
?
5
:
(
isExternalWarehouse
||
isConcentrateTransport
?
4
:
3
),
maxOddOrderNumbers
.
length
()
-
endIndex
)
:
maxOddOrderNumbers
.
substring
(
isExternalWarehouse
&&
isConcentrateTransport
?
6
:
(
isExternalWarehouse
||
isConcentrateTransport
?
5
:
4
),
maxOddOrderNumbers
.
length
()
-
endIndex
)));
//把截取的最后四位数解析为int
long
endIntNum
=
Long
.
parseLong
(
endNum
);
//在将其加1(自增1)
long
newEndIntNum
=
(
StringUtils
.
equals
(
transportShort
,
"SA"
)
?
10000
:
100000
)
+
endIntNum
+
1
;
//把10000或100000的1去掉,获取到最新的后5位
String
endNum
;
switch
(
transportShort
)
{
case
"F"
:
endNum
=
maxOddOrderNumbers
.
substring
(
5
);
break
;
case
"A"
:
int
startIndexA
=
isExternalWarehouse
&&
isConcentrateTransport
?
5
:
(
isExternalWarehouse
||
isConcentrateTransport
?
4
:
3
);
endNum
=
maxOddOrderNumbers
.
substring
(
startIndexA
,
maxOddOrderNumbers
.
length
()
-
endIndex
);
break
;
default
:
int
startIndexDefault
;
if
(
isExternalWarehouse
&&
isConcentrateTransport
)
{
startIndexDefault
=
2
+
orderPrefix
.
length
();
}
else
if
(
isExternalWarehouse
||
isConcentrateTransport
)
{
startIndexDefault
=
1
+
orderPrefix
.
length
();;
}
else
{
startIndexDefault
=
orderPrefix
.
length
();;
}
endNum
=
maxOddOrderNumbers
.
substring
(
startIndexDefault
,
maxOddOrderNumbers
.
length
()
-
endIndex
);
break
;
}
// 检查是否成功截取
if
(
endNum
==
null
||
endNum
.
isEmpty
())
{
throw
new
IllegalArgumentException
(
"Invalid maxOddOrderNumbers format"
);
}
// 把截取的最后四位数解析为int
int
endIntNum
=
Integer
.
parseInt
(
endNum
);
// 在将其加1(自增1)
int
base
=
100000
;
int
newEndIntNum
=
base
+
endIntNum
+
1
;
// 把10000或100000的1去掉,获取到最新的后5位
String
newEndNum
=
String
.
valueOf
(
newEndIntNum
).
substring
(
1
);
//生成单号
newOddOrderNO
=
StringUtils
.
equals
(
transportShort
,
"F"
)
?
"ECF"
+
formatDate
+
newEndNum
:
(
isExternalWarehouse
?
"X"
:
""
)
+
(
isConcentrateTransport
?
"J"
:
""
)
+
(
StringUtils
.
equals
(
transportShort
,
"A"
)
?
transportShort
+
formatDate
+
newEndNum
+
countryAirShort
:
countryShort
+
transportShort
+
formatDate
+
newEndNum
+
cityShort
);
//将单号返回
return
newOddOrderNO
;
// 生成单号
StringBuilder
newOddOrderNOBuilder
=
new
StringBuilder
();
if
(
StringUtils
.
equals
(
transportShort
,
"F"
))
{
newOddOrderNOBuilder
.
append
(
"ECF"
).
append
(
formatDate
).
append
(
newEndNum
);
}
else
{
if
(
isExternalWarehouse
)
{
newOddOrderNOBuilder
.
append
(
"X"
);
}
if
(
isConcentrateTransport
)
{
newOddOrderNOBuilder
.
append
(
"J"
);
}
if
(
StringUtils
.
equals
(
transportShort
,
"A"
))
{
newOddOrderNOBuilder
.
append
(
transportShort
).
append
(
formatDate
).
append
(
newEndNum
).
append
(
countryAirShort
);
}
else
{
newOddOrderNOBuilder
.
append
(
countryShort
).
append
(
transportShort
).
append
(
formatDate
).
append
(
newEndNum
).
append
(
cityShort
);
}
}
newOddOrderNO
=
newOddOrderNOBuilder
.
toString
();
}
else
{
//如果为空(第一次生成)或者当前最大订单号的日期与当前日期不一致说明需要重新计数生成单号
newOddOrderNO
=
StringUtils
.
equals
(
transportShort
,
"F"
)
?
"ECF"
+
formatDate
+
"00001"
:
(
isExternalWarehouse
?
"X"
:
""
)
+
(
isConcentrateTransport
?
"J"
:
""
)
+
(
StringUtils
.
equals
(
transportShort
,
"A"
)
?
transportShort
+
formatDate
+
"00001"
+
countryAirShort
:
countryShort
+
transportShort
+
formatDate
+
"00001"
+
cityShort
);
//将单号返回
return
newOddOrderNO
;
// 如果为空(第一次生成)或者当前最大订单号的日期与当前日期不一致说明需要重新计数生成单号
StringBuilder
newOddOrderNOBuilder
=
new
StringBuilder
();
if
(
StringUtils
.
equals
(
transportShort
,
"F"
))
{
newOddOrderNOBuilder
.
append
(
"ECF"
).
append
(
formatDate
).
append
(
"00001"
);
}
else
{
if
(
isExternalWarehouse
)
{
newOddOrderNOBuilder
.
append
(
"X"
);
}
if
(
isConcentrateTransport
)
{
newOddOrderNOBuilder
.
append
(
"J"
);
}
if
(
StringUtils
.
equals
(
transportShort
,
"A"
))
{
newOddOrderNOBuilder
.
append
(
transportShort
).
append
(
formatDate
).
append
(
"00001"
).
append
(
countryAirShort
);
}
else
{
newOddOrderNOBuilder
.
append
(
countryShort
).
append
(
transportShort
).
append
(
formatDate
).
append
(
"00001"
).
append
(
cityShort
);
}
}
newOddOrderNO
=
newOddOrderNOBuilder
.
toString
();
}
return
newOddOrderNO
;
}
/**
* 根据订单编号生成条纹编码
*
...
...
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