Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
csbr-daop
/
ms-data-circulation-portal-service
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
20188200
authored
2025-09-04 18:05:51 +0800
by
xu
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
可信空间修改
1 parent
7388987d
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
171 additions
and
0 deletions
src/main/java/com/csbr/qingcloud/portal/util/CheckDigitUtil.java
src/main/java/com/csbr/qingcloud/portal/util/IdentificationCodeUtil.java
src/main/java/com/csbr/qingcloud/portal/util/CheckDigitUtil.java
0 → 100644
View file @
2018820
package
com
.
csbr
.
qingcloud
.
portal
.
util
;
import
java.util.HashMap
;
import
java.util.Map
;
public
class
CheckDigitUtil
{
private
static
final
String
VALID_CHARS
=
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ$*+-./:"
;
private
static
final
Map
<
Character
,
Integer
>
CHAR_TO_VALUE_MAP
=
new
HashMap
<>();
static
{
for
(
int
i
=
0
;
i
<
VALID_CHARS
.
length
();
i
++)
{
CHAR_TO_VALUE_MAP
.
put
(
VALID_CHARS
.
charAt
(
i
),
i
);
}
}
public
static
char
calculateCheckDigit
(
String
code
)
{
int
weight
=
1
;
int
total
=
0
;
for
(
int
i
=
code
.
length
()
-
1
;
i
>=
0
;
i
--)
{
char
c
=
code
.
charAt
(
i
);
if
(!
CHAR_TO_VALUE_MAP
.
containsKey
(
c
))
{
throw
new
IllegalArgumentException
(
"Invalid character in code: "
+
c
);
}
int
value
=
CHAR_TO_VALUE_MAP
.
get
(
c
);
total
+=
value
*
weight
;
weight
=
(
weight
+
1
)
%
37
;
if
(
weight
==
0
)
{
weight
=
1
;
}
}
int
remainder
=
total
%
37
;
int
checksum
=
(
37
-
remainder
)
%
37
;
return
VALID_CHARS
.
charAt
(
checksum
);
}
public
static
void
main
(
String
[]
args
)
{
String
code
=
"1234567890L"
;
System
.
out
.
println
(
calculateCheckDigit
(
code
));
}
}
src/main/java/com/csbr/qingcloud/portal/util/IdentificationCodeUtil.java
0 → 100644
View file @
2018820
package
com
.
csbr
.
qingcloud
.
portal
.
util
;
import
org.apache.commons.lang3.StringUtils
;
import
java.security.SecureRandom
;
/**
* 标识码生成工具类
* 1、平台、接入连接器编码
* 2、数据产品、数据资源编码
*/
public
class
IdentificationCodeUtil
{
private
static
final
String
CHARACTERS
=
"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
;
private
static
SecureRandom
random
=
new
SecureRandom
();
/**
* 全域功能节点编码。类型码为“1”、主体标识码(18 位)、区域代码(4 位)、随机码(8 位)、
* 校验码(1 位)。
* @param mainIdentification
* @param areaCode
* @return
*/
public
static
String
genGlobalFunctionNodeCode
(
String
mainIdentification
,
String
areaCode
){
String
identificationCode
=
String
.
format
(
"1%s%s%s"
,
mainIdentification
,
areaCode
,
generateRandomString
(
8
));
return
identificationCode
+
CheckDigitUtil
.
calculateCheckDigit
(
identificationCode
);
}
/**
* 区域功能节点编码。类型码为“2”、主体标识码(18 位)、区域代码(4 位)、随机码(8 位)、
* 校验码(1 位)。
* @param mainIdentification
* @param areaCode
* @return
*/
public
static
String
genRegionalFunctionNodeCode
(
String
mainIdentification
,
String
areaCode
){
String
identificationCode
=
String
.
format
(
"2%s%s%s"
,
mainIdentification
,
areaCode
,
generateRandomString
(
8
));
return
identificationCode
+
CheckDigitUtil
.
calculateCheckDigit
(
identificationCode
);
}
/**
* 行业功能节点编码。类型码为“3”、主体标识码(18 位)、行业代码(4 位)、随机码(8 位)、
* 校验码(1 位)
* @param mainIdentification
* @param industryCode
* @return
*/
public
static
String
genIndustryFunctionNodeCode
(
String
mainIdentification
,
String
industryCode
){
String
identificationCode
=
String
.
format
(
"3%s%s%s"
,
mainIdentification
,
industryCode
,
generateRandomString
(
8
));
return
identificationCode
+
CheckDigitUtil
.
calculateCheckDigit
(
identificationCode
);
}
/**
* 业务节点编码。类型码为“4”、主体标识码(18 位)、区域/行业代码(4 位,业务节点编码由
* 区域功能节点分配时用区域功能节点的区域代码,业务节点编码由行业功能节点分配时用行
* 业功能节点的行业代码)、随机码(8 位)、校验码(1 位)。
* @param mainIdentification
* @param industryCode
* @return
*/
public
static
String
genBusinessNodeCode
(
String
mainIdentification
,
String
industryCode
){
String
identificationCode
=
String
.
format
(
"4%s%s%s"
,
mainIdentification
,
industryCode
,
generateRandomString
(
8
));
return
identificationCode
+
CheckDigitUtil
.
calculateCheckDigit
(
identificationCode
);
}
/**
* 接入连接器编码。类型码为“5”、主体标识码(18 位)、区域/行业代码(4 位,接入连接器编
* 码由区域功能节点分配时用区域功能节点的区域代码,接入连接器编码由行业功能节点分配
* 时用行业功能节点的行业代码)、随机码(8 位)、校验码(1 位)。
* @param mainIdentification
* @param industryCode
* @return
*/
public
static
String
genConnectorCode
(
String
mainIdentification
,
String
industryCode
){
String
identificationCode
=
String
.
format
(
"5%s%s%s"
,
mainIdentification
,
industryCode
,
generateRandomString
(
8
));
return
identificationCode
+
CheckDigitUtil
.
calculateCheckDigit
(
identificationCode
);
}
/**
* 数据产品、由类型码(1位)、主体标识码(18位)、平台区域/行业代
* 码段(4位)、随机码(8位)、校验码(1位)
* @param mainIdentification
* @param industryCode
* @return
*/
public
static
String
genDataProductCode
(
String
mainIdentification
,
String
industryCode
){
String
identificationCode
=
String
.
format
(
"6%s%s%s"
,
mainIdentification
,
industryCode
,
generateRandomString
(
8
));
return
identificationCode
+
CheckDigitUtil
.
calculateCheckDigit
(
identificationCode
);
}
/**
* 数据资源编码、由类型码(1位)、主体标识码(18位)、平台区域/行业代
* 码段(4位)、随机码(8位)、校验码(1位)、扩展码(最多32位)组成
* @param mainIdentification
* @param industryCode
* @return
*/
public
static
String
genDataResourceCode
(
String
mainIdentification
,
String
industryCode
,
String
extensionCode
){
String
identificationCode
=
String
.
format
(
"7%s%s%s"
,
mainIdentification
,
industryCode
,
generateRandomString
(
8
));
identificationCode
=
identificationCode
+
CheckDigitUtil
.
calculateCheckDigit
(
identificationCode
);
if
(
StringUtils
.
isNotBlank
(
extensionCode
))
{
return
identificationCode
+
"."
+
extensionCode
;
}
return
identificationCode
;
}
public
static
void
main
(
String
[]
args
)
{
System
.
out
.
println
(
IdentificationCodeUtil
.
genGlobalFunctionNodeCode
(
"420821199101126765"
,
"1100"
));
}
// 步骤2:生成一个随机字符串
public
static
String
generateRandomString
(
int
length
)
{
StringBuilder
sb
=
new
StringBuilder
(
length
);
for
(
int
i
=
0
;
i
<
length
;
i
++)
{
sb
.
append
(
CHARACTERS
.
charAt
(
random
.
nextInt
(
CHARACTERS
.
length
())));
}
return
sb
.
toString
();
}
}
Write
Preview
Styling with
Markdown
is supported
Attach a file
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 post a comment