@@ -8,6 +8,7 @@ import org.springframework.data.annotation.LastModifiedDate;
|
||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@@ -17,6 +18,9 @@ import java.time.LocalDateTime;
|
||||
@Table(name = "file_entities")
|
||||
@EntityListeners(AuditingEntityListener.class)
|
||||
public class FileEntity {
|
||||
|
||||
private static AtomicInteger supportIdCounter = new AtomicInteger(0);
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.UUID)
|
||||
private String id;
|
||||
@@ -83,6 +87,10 @@ public class FileEntity {
|
||||
|
||||
@PrePersist
|
||||
public void prePersist() {
|
||||
if (this.supportId == null) {
|
||||
this.supportId = supportIdCounter.incrementAndGet();
|
||||
}
|
||||
|
||||
if (this.status == null) {
|
||||
this.status = FileStatus.ACTIVE;
|
||||
}
|
||||
@@ -101,4 +109,8 @@ public class FileEntity {
|
||||
public void preUpdate() {
|
||||
this.updatedAt = LocalDateTime.now();
|
||||
}
|
||||
|
||||
public static void initializeCounter(int maxId) {
|
||||
supportIdCounter = new AtomicInteger(maxId);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user