2025-12-17 13:41:05 +07:00
|
|
|
package ru.soune.nocopy.entity.file;
|
2025-12-15 19:49:09 +07:00
|
|
|
|
|
|
|
|
import jakarta.persistence.*;
|
|
|
|
|
import lombok.*;
|
|
|
|
|
import org.springframework.data.annotation.CreatedDate;
|
|
|
|
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
@Data
|
|
|
|
|
@Builder
|
|
|
|
|
@NoArgsConstructor
|
|
|
|
|
@AllArgsConstructor
|
|
|
|
|
@Entity
|
|
|
|
|
@Table(name = "file_upload_sessions")
|
|
|
|
|
public class FileUploadSession {
|
|
|
|
|
|
|
|
|
|
@Id
|
|
|
|
|
@GeneratedValue(strategy = GenerationType.UUID)
|
|
|
|
|
@Column(name = "upload_id")
|
|
|
|
|
private String uploadId;
|
|
|
|
|
|
|
|
|
|
@Column(name = "user_id", nullable = false)
|
|
|
|
|
private Long userId;
|
|
|
|
|
|
|
|
|
|
@Column(name = "file_name", nullable = false)
|
|
|
|
|
private String fileName;
|
|
|
|
|
|
|
|
|
|
@Column(name = "file_type")
|
|
|
|
|
private String fileType;
|
|
|
|
|
|
|
|
|
|
@Column(name = "file_size")
|
|
|
|
|
private Long fileSize;
|
|
|
|
|
|
|
|
|
|
@Column(name = "total_chunks")
|
|
|
|
|
private Integer totalChunks;
|
|
|
|
|
|
|
|
|
|
@Column(name = "chunks_uploaded")
|
|
|
|
|
private Integer chunksUploaded;
|
|
|
|
|
|
|
|
|
|
@Column(name = "status")
|
|
|
|
|
@Enumerated(EnumType.STRING)
|
|
|
|
|
private UploadStatus status;
|
|
|
|
|
|
|
|
|
|
@Column(name = "file_path")
|
|
|
|
|
private String filePath;
|
|
|
|
|
|
|
|
|
|
@Column(name = "checksum")
|
|
|
|
|
private String checksum;
|
|
|
|
|
|
|
|
|
|
@CreatedDate
|
|
|
|
|
@Column(name = "created_at", updatable = false, nullable = false)
|
|
|
|
|
private LocalDateTime createdAt;
|
|
|
|
|
|
2025-12-16 03:44:59 +07:00
|
|
|
@Column(name = "expires_at")
|
|
|
|
|
private LocalDateTime expiresAt;
|
|
|
|
|
|
|
|
|
|
@Version
|
|
|
|
|
private Long version;
|
|
|
|
|
|
|
|
|
|
@Column(name = "last_error")
|
|
|
|
|
private String lastError;
|
|
|
|
|
|
2025-12-16 14:27:03 +07:00
|
|
|
@Column(name = "extension")
|
|
|
|
|
private String extension;
|
|
|
|
|
|
2025-12-16 03:44:59 +07:00
|
|
|
@Column(name = "retry_count")
|
|
|
|
|
private Integer retryCount = 0;
|
|
|
|
|
|
2025-12-15 19:49:09 +07:00
|
|
|
@Column(name = "completed_at")
|
|
|
|
|
private LocalDateTime completedAt;
|
|
|
|
|
|
|
|
|
|
@ElementCollection
|
|
|
|
|
@CollectionTable(
|
|
|
|
|
name = "uploaded_chunks",
|
|
|
|
|
joinColumns = @JoinColumn(name = "upload_id")
|
|
|
|
|
)
|
|
|
|
|
@MapKeyColumn(name = "chunk_number")
|
|
|
|
|
@Column(name = "chunk_path")
|
|
|
|
|
private Map<Integer, String> chunkPaths = new HashMap<>();
|
2025-12-16 03:44:59 +07:00
|
|
|
|
|
|
|
|
@PrePersist
|
|
|
|
|
public void prePersist() {
|
|
|
|
|
this.createdAt = LocalDateTime.now();
|
|
|
|
|
this.expiresAt = LocalDateTime.now().plusHours(24);
|
|
|
|
|
this.chunksUploaded = 0;
|
|
|
|
|
if (this.status == null) {
|
|
|
|
|
this.status = UploadStatus.INITIATED;
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-12-15 19:49:09 +07:00
|
|
|
}
|