diff --git a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/pom.xml b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/pom.xml index 3c815101..123dcf65 100644 --- a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/pom.xml +++ b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/pom.xml @@ -31,6 +31,10 @@ com.querydsl querydsl-jpa + + com.github.yitter + yitter-idgenerator + com.h2database diff --git a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/config/id/SnowflakeIdGenerator.java b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/config/id/SnowflakeIdGenerator.java index e9bfcb3d..5d47fbde 100644 --- a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/config/id/SnowflakeIdGenerator.java +++ b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/config/id/SnowflakeIdGenerator.java @@ -5,11 +5,16 @@ import java.io.Serializable; import java.lang.reflect.Field; import java.util.Objects; +import com.github.yitter.contract.IdGeneratorOptions; +import com.github.yitter.idgen.YitIdHelper; import org.hibernate.HibernateException; import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.id.IdentifierGenerator; +import org.springframework.context.annotation.Bean; import org.springframework.stereotype.Component; +import javax.annotation.PostConstruct; + /** * @author: Longjun.Tu * @description: @@ -19,6 +24,13 @@ import org.springframework.stereotype.Component; @Component public class SnowflakeIdGenerator implements IdentifierGenerator { + @PostConstruct + public void snowflakeIdGenerator() { + // TODO: 2023/6/12 从配置文件中读取 + IdGeneratorOptions options = new IdGeneratorOptions((short) 1); + YitIdHelper.setIdGenerator(options); + } + @Override public Serializable generate(SharedSessionContractImplementor sharedSessionContractImplementor, Object o) throws HibernateException { Field id = null; @@ -32,6 +44,6 @@ public class SnowflakeIdGenerator implements IdentifierGenerator { } catch (NoSuchFieldException | IllegalAccessException e) { } - return SnowflakeIdGeneratorUtil.getInstanceSnowflake().nextId(); + return YitIdHelper.nextId(); } } diff --git a/pom.xml b/pom.xml index 49eb11f8..21db180f 100755 --- a/pom.xml +++ b/pom.xml @@ -46,6 +46,7 @@ 2.0.9 1.1.0.Final 1.18.26 + 1.0.6 @@ -74,7 +75,11 @@ commons-beanutils ${beanutils.version} - + + com.github.yitter + yitter-idgenerator + ${yitter.version} + com.fasterxml.jackson.core