mirror of
https://gitee.com/orangeform/orange-admin.git
synced 2026-01-17 10:36:31 +08:00
commit:升级到vue3,更新最近工作流技术栈,支持sa-token
This commit is contained in:
24
OrangeFormsOpen-MybatisPlus/common/common-sequence/pom.xml
Normal file
24
OrangeFormsOpen-MybatisPlus/common/common-sequence/pom.xml
Normal file
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>common</artifactId>
|
||||
<groupId>com.orangeforms</groupId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>common-sequence</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<name>common-sequence</name>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.orangeforms</groupId>
|
||||
<artifactId>common-core</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.orangeforms.common.sequence.config;
|
||||
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
|
||||
/**
|
||||
* common-sequence模块的自动配置引导类。
|
||||
*
|
||||
* @author Jerry
|
||||
* @date 2024-07-02
|
||||
*/
|
||||
@EnableConfigurationProperties({IdGeneratorProperties.class})
|
||||
public class IdGeneratorAutoConfig {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.orangeforms.common.sequence.config;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
/**
|
||||
* common-sequence模块的配置类。
|
||||
*
|
||||
* @author Jerry
|
||||
* @date 2024-07-02
|
||||
*/
|
||||
@Data
|
||||
@ConfigurationProperties(prefix = "common-sequence")
|
||||
public class IdGeneratorProperties {
|
||||
|
||||
/**
|
||||
* 基础版生成器所需的WorkNode参数值。仅当advanceIdGenerator为false时生效。
|
||||
*/
|
||||
private Integer snowflakeWorkNode = 1;
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.orangeforms.common.sequence.generator;
|
||||
|
||||
import cn.hutool.core.lang.Snowflake;
|
||||
|
||||
/**
|
||||
* 基础版snowflake计算工具类。
|
||||
* 和SnowflakeIdGenerator相比,相同点是均为基于Snowflake算法的生成器。不同点在于当前类的
|
||||
* WorkNodeId是通过配置文件静态指定的。而SnowflakeIdGenerator的WorkNodeId是由zk生成的。
|
||||
*
|
||||
* @author Jerry
|
||||
* @date 2024-07-02
|
||||
*/
|
||||
public class BasicIdGenerator implements MyIdGenerator {
|
||||
|
||||
private final Snowflake snowflake;
|
||||
|
||||
/**
|
||||
* 构造函数。
|
||||
*
|
||||
* @param workNode 工作节点。
|
||||
*/
|
||||
public BasicIdGenerator(Integer workNode) {
|
||||
snowflake = new Snowflake(workNode, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取基于Snowflake算法的数值型Id。
|
||||
* 由于底层实现为synchronized方法,因此计算过程串行化,且线程安全。
|
||||
*
|
||||
* @return 计算后的全局唯一Id。
|
||||
*/
|
||||
@Override
|
||||
public long nextLongId() {
|
||||
return this.snowflake.nextId();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取基于Snowflake算法的字符串Id。
|
||||
* 由于底层实现为synchronized方法,因此计算过程串行化,且线程安全。
|
||||
*
|
||||
* @return 计算后的全局唯一Id。
|
||||
*/
|
||||
@Override
|
||||
public String nextStringId() {
|
||||
return this.snowflake.nextIdStr();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.orangeforms.common.sequence.generator;
|
||||
|
||||
/**
|
||||
* 分布式Id生成器的统一接口。
|
||||
*
|
||||
* @author Jerry
|
||||
* @date 2024-07-02
|
||||
*/
|
||||
public interface MyIdGenerator {
|
||||
|
||||
/**
|
||||
* 获取数值型分布式Id。
|
||||
*
|
||||
* @return 生成后的Id。
|
||||
*/
|
||||
long nextLongId();
|
||||
|
||||
/**
|
||||
* 获取字符型分布式Id。
|
||||
*
|
||||
* @return 生成后的Id。
|
||||
*/
|
||||
String nextStringId();
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.orangeforms.common.sequence.wrapper;
|
||||
|
||||
import com.orangeforms.common.sequence.config.IdGeneratorProperties;
|
||||
import com.orangeforms.common.sequence.generator.BasicIdGenerator;
|
||||
import com.orangeforms.common.sequence.generator.MyIdGenerator;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import jakarta.annotation.PostConstruct;
|
||||
|
||||
/**
|
||||
* 分布式Id生成器的封装类。该对象可根据配置选择不同的生成器实现类。
|
||||
*
|
||||
* @author Jerry
|
||||
* @date 2024-07-02
|
||||
*/
|
||||
@Component
|
||||
public class IdGeneratorWrapper {
|
||||
|
||||
@Autowired
|
||||
private IdGeneratorProperties properties;
|
||||
/**
|
||||
* Id生成器接口对象。
|
||||
*/
|
||||
private MyIdGenerator idGenerator;
|
||||
|
||||
/**
|
||||
* 今后如果支持更多Id生成器时,可以在该函数内实现不同生成器的动态选择。
|
||||
*/
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
idGenerator = new BasicIdGenerator(properties.getSnowflakeWorkNode());
|
||||
}
|
||||
|
||||
/**
|
||||
* 由于底层实现为synchronized方法,因此计算过程串行化,且线程安全。
|
||||
*
|
||||
* @return 计算后的全局唯一Id。
|
||||
*/
|
||||
public long nextLongId() {
|
||||
return idGenerator.nextLongId();
|
||||
}
|
||||
|
||||
/**
|
||||
* 由于底层实现为synchronized方法,因此计算过程串行化,且线程安全。
|
||||
*
|
||||
* @return 计算后的全局唯一Id。
|
||||
*/
|
||||
public String nextStringId() {
|
||||
return idGenerator.nextStringId();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
com.orangeforms.common.sequence.config.IdGeneratorAutoConfig
|
||||
Reference in New Issue
Block a user