Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
amos-boot-biz
Project
Project
Details
Activity
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
项目统一框架
amos-boot-biz
Commits
1e2ef8ca
Commit
1e2ef8ca
authored
Apr 10, 2023
by
tangwei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加雪花id
parent
1c70dada
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
62 additions
and
0 deletions
+62
-0
pom.xml
.../amos-boot-module-api/amos-boot-module-patrol-api/pom.xml
+7
-0
MyIdGeneratorConfig.java
.../amos/patrol/core/common/request/MyIdGeneratorConfig.java
+55
-0
No files found.
amos-boot-module/amos-boot-module-api/amos-boot-module-patrol-api/pom.xml
View file @
1e2ef8ca
...
@@ -12,6 +12,13 @@
...
@@ -12,6 +12,13 @@
<artifactId>
amos-boot-module-patrol-api
</artifactId>
<artifactId>
amos-boot-module-patrol-api
</artifactId>
<dependencies>
<dependencies>
<dependency>
<groupId>
cn.hutool
</groupId>
<artifactId>
hutool-all
</artifactId>
<version>
5.3.10
</version>
</dependency>
<dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-data-jpa
</artifactId>
<artifactId>
spring-boot-starter-data-jpa
</artifactId>
...
...
amos-boot-module/amos-boot-module-api/amos-boot-module-patrol-api/src/main/java/com/yeejoin/amos/patrol/core/common/request/MyIdGeneratorConfig.java
0 → 100644
View file @
1e2ef8ca
package
com
.
yeejoin
.
amos
.
patrol
.
core
.
common
.
request
;
import
cn.hutool.core.lang.Snowflake
;
import
cn.hutool.core.net.NetUtil
;
import
cn.hutool.core.util.IdUtil
;
import
org.hibernate.HibernateException
;
import
org.hibernate.engine.spi.SharedSessionContractImplementor
;
import
org.hibernate.id.IdentifierGenerator
;
import
javax.annotation.PostConstruct
;
import
java.io.Serializable
;
/**
* @description:
* @author: tw
* @createDate: 2023/4/10
*/
public
class
MyIdGeneratorConfig
implements
IdentifierGenerator
{
/**
* 终端ID
*/
public
static
long
WORKER_ID
=
1
;
/**
* 数据中心id
*/
public
static
long
DATACENTER_ID
=
1
;
private
Snowflake
snowflake
=
IdUtil
.
createSnowflake
(
WORKER_ID
,
DATACENTER_ID
);
@PostConstruct
public
void
init
()
{
WORKER_ID
=
NetUtil
.
ipv4ToLong
(
NetUtil
.
getLocalhostStr
());
}
public
synchronized
long
snowflakeId
()
{
return
snowflake
.
nextId
();
}
public
synchronized
long
snowflakeId
(
long
workerId
,
long
datacenterId
)
{
Snowflake
snowflake
=
IdUtil
.
createSnowflake
(
workerId
,
datacenterId
);
return
snowflake
.
nextId
();
}
@Override
public
Serializable
generate
(
SharedSessionContractImplementor
session
,
Object
object
)
throws
HibernateException
{
return
snowflakeId
(
WORKER_ID
,
DATACENTER_ID
);
}
}
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