Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
gsc
/
gsc-vcp-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 5be74c7f
authored
Oct 29, 2025
by
林冲
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
生成车源号修改算法
1 parent
40019066
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
82 additions
and
0 deletions
pom.xml
src/main/java/com/gsc4cloud/gsc/vpc/api/util/CommonUtil.java
src/main/java/com/gsc4cloud/gsc/vpc/api/util/ShortLinkComponent.java
pom.xml
View file @
5be74c7
...
@@ -50,6 +50,12 @@
...
@@ -50,6 +50,12 @@
<artifactId>
hutool-all
</artifactId>
<artifactId>
hutool-all
</artifactId>
<version>
5.8.38
</version>
<version>
5.8.38
</version>
</dependency>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
<dependency>
<groupId>
com.google.guava
</groupId>
<artifactId>
guava
</artifactId>
<version>
33.5.0-jre
</version>
</dependency>
<!--feign 注解依赖-->
<!--feign 注解依赖-->
<dependency>
<dependency>
<groupId>
com.gsc4cloud
</groupId>
<groupId>
com.gsc4cloud
</groupId>
...
...
src/main/java/com/gsc4cloud/gsc/vpc/api/util/CommonUtil.java
0 → 100644
View file @
5be74c7
package
com
.
gsc4cloud
.
gsc
.
vpc
.
api
.
util
;
import
com.google.common.hash.Hashing
;
/**
* @BelongsProject: glsx-accounts-test
* @BelongsPackage: com.accounts.devtool.hashing.shorturi
* @Author: dell_xw
* @CreateTime: 2022-06-22 18:36
* @Description: TODO
* @Version: 1.0
*/
public
class
CommonUtil
{
/**
* murmurhash算法
* @param param
* @return
*/
public
static
long
murmurHash32
(
String
param
){
long
murmurHash32
=
Hashing
.
murmur3_32
().
hashUnencodedChars
(
param
).
padToLong
();
return
murmurHash32
;
}
}
src/main/java/com/gsc4cloud/gsc/vpc/api/util/ShortLinkComponent.java
0 → 100644
View file @
5be74c7
package
com
.
gsc4cloud
.
gsc
.
vpc
.
api
.
util
;
import
org.springframework.stereotype.Component
;
/**
* @BelongsProject: glsx-accounts-test
* @BelongsPackage: com.accounts.devtool.hashing.shorturi
* @Author: dell_xw
* @CreateTime: 2022-06-22 18:38
* @Description: TODO
* @Version: 1.0
*/
@Component
public
class
ShortLinkComponent
{
/**
* 62个字符
*/
private
static
final
String
CHARS
=
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
;
/**
* 生成短链码
* @param param
* @return
*/
public
String
createShortLinkCode
(
String
param
){
long
murmurhash
=
CommonUtil
.
murmurHash32
(
param
);
//进制转换
String
code
=
encodeToBase62
(
murmurhash
);
return
code
;
}
/**
* 10进制转62进制
* @param num
* @return
*/
private
String
encodeToBase62
(
long
num
){
// StringBuffer线程安全,StringBuilder线程不安全
StringBuffer
sb
=
new
StringBuffer
();
do
{
int
i
=
(
int
)(
num
%
62
);
sb
.
append
(
CHARS
.
charAt
(
i
));
num
=
num
/
62
;
}
while
(
num
>
0
);
String
value
=
sb
.
reverse
().
toString
();
return
value
;
}
}
Write
Preview
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