Skip to content

Commit

Permalink
✨ feat(工具类): 新增nextId方法生成ULID, 并调整依赖和配置文件
Browse files Browse the repository at this point in the history
  • Loading branch information
vnobo committed Jun 4, 2024
1 parent a43e324 commit 4d06da1
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 120 deletions.
1 change: 1 addition & 0 deletions boot/platform/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ tasks.named("bootBuildImage") {
dependencies {

implementation("com.google.guava:guava:33.+")
implementation("com.github.f4b6a3:ulid-creator:5.+")

implementation("org.springframework.boot:spring-boot-starter-security")
implementation("org.springframework.boot:spring-boot-starter-oauth2-client")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.platform.boot.commons.base;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.platform.boot.commons.utils.Ulid;
import com.platform.boot.commons.utils.ContextUtils;
import com.platform.boot.commons.utils.query.CriteriaUtils;
import org.springframework.data.domain.Persistable;
import org.springframework.data.relational.core.query.Criteria;
Expand Down Expand Up @@ -34,7 +34,7 @@ default void setCode(String code) {
default boolean isNew() {
boolean isNew = ObjectUtils.isEmpty(getId());
if (isNew) {
setCode(Ulid.random());
setCode(ContextUtils.nextId());
}
return isNew;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.f4b6a3.ulid.Ulid;
import com.github.f4b6a3.ulid.UlidCreator;
import com.platform.boot.commons.exception.JsonException;
import com.platform.boot.commons.exception.RestServerException;
import com.platform.boot.security.SecurityDetails;
Expand Down Expand Up @@ -116,6 +118,11 @@ private static <T> Mono<String> handlePropertyDescriptor(T object, PropertyDescr
}
}

public static String nextId() {
Ulid ulid = UlidCreator.getMonotonicUlid();
return ulid.toString();
}

@Override
public void afterPropertiesSet() {
log.info("Initializing utils [ContextUtils]...");
Expand Down
117 changes: 0 additions & 117 deletions boot/platform/src/main/java/com/platform/boot/commons/utils/Ulid.java

This file was deleted.

2 changes: 1 addition & 1 deletion boot/platform/src/main/resources/application-local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ spring:
max-idle-time: 10m
validation-query: select 1
sql.init:
mode: always
mode: never
platform: postgres
encoding: utf-8
data.redis:
Expand Down

0 comments on commit 4d06da1

Please sign in to comment.