2025-12-17 22:37:46 +07:00
|
|
|
package ru.soune.nocopy.entity.file;
|
2025-12-17 01:19:48 +07:00
|
|
|
|
2026-01-16 14:30:45 +07:00
|
|
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
2025-12-17 01:19:48 +07:00
|
|
|
import jakarta.persistence.*;
|
|
|
|
|
import lombok.*;
|
2026-01-20 21:55:42 +07:00
|
|
|
import org.hibernate.annotations.GenerationTime;
|
2025-12-17 01:19:48 +07:00
|
|
|
import org.springframework.data.annotation.CreatedDate;
|
|
|
|
|
import org.springframework.data.annotation.LastModifiedDate;
|
|
|
|
|
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
|
|
|
|
|
2026-01-20 21:55:42 +07:00
|
|
|
import java.sql.DriverManager;
|
|
|
|
|
import java.sql.SQLException;
|
2025-12-17 01:19:48 +07:00
|
|
|
import java.time.LocalDateTime;
|
|
|
|
|
|
|
|
|
|
@Data
|
|
|
|
|
@Builder
|
|
|
|
|
@NoArgsConstructor
|
|
|
|
|
@AllArgsConstructor
|
|
|
|
|
@Entity
|
|
|
|
|
@Table(name = "file_entities")
|
|
|
|
|
@EntityListeners(AuditingEntityListener.class)
|
|
|
|
|
public class FileEntity {
|
|
|
|
|
@Id
|
|
|
|
|
@GeneratedValue(strategy = GenerationType.UUID)
|
|
|
|
|
private String id;
|
|
|
|
|
|
2026-01-20 21:55:42 +07:00
|
|
|
@Column(name = "support_id", unique = true, updatable = false)
|
|
|
|
|
private Integer supportId;
|
|
|
|
|
|
2025-12-17 01:19:48 +07:00
|
|
|
@Column(name = "user_id", nullable = false)
|
|
|
|
|
private Long userId;
|
|
|
|
|
|
|
|
|
|
@Column(name = "original_file_name", nullable = false)
|
|
|
|
|
private String originalFileName;
|
|
|
|
|
|
|
|
|
|
@Column(name = "stored_file_name", nullable = false)
|
|
|
|
|
private String storedFileName;
|
|
|
|
|
|
|
|
|
|
@Column(name = "file_path", nullable = false, unique = true)
|
|
|
|
|
private String filePath;
|
|
|
|
|
|
|
|
|
|
@Column(name = "file_size", nullable = false)
|
|
|
|
|
private Long fileSize;
|
|
|
|
|
|
|
|
|
|
@Column(name = "mime_type")
|
|
|
|
|
private String mimeType;
|
|
|
|
|
|
|
|
|
|
@Column(name = "file_extension")
|
|
|
|
|
private String fileExtension;
|
|
|
|
|
|
|
|
|
|
@Column(name = "checksum")
|
|
|
|
|
private String checksum;
|
|
|
|
|
|
|
|
|
|
@Column(name = "upload_session_id")
|
|
|
|
|
private String uploadSessionId;
|
|
|
|
|
|
|
|
|
|
@Enumerated(EnumType.STRING)
|
|
|
|
|
@Column(name = "status")
|
|
|
|
|
private FileStatus status;
|
|
|
|
|
|
|
|
|
|
@CreatedDate
|
|
|
|
|
@Column(name = "created_at", updatable = false)
|
|
|
|
|
private LocalDateTime createdAt;
|
|
|
|
|
|
|
|
|
|
@LastModifiedDate
|
|
|
|
|
@Column(name = "updated_at")
|
|
|
|
|
private LocalDateTime updatedAt;
|
|
|
|
|
|
2026-01-08 03:22:32 +07:00
|
|
|
@Column(name = "protected_file_path")
|
|
|
|
|
private String protectedFilePath;
|
|
|
|
|
|
|
|
|
|
@Column(name = "protection_status")
|
|
|
|
|
@Enumerated(EnumType.STRING)
|
|
|
|
|
private ProtectionStatus protectionStatus;
|
|
|
|
|
|
|
|
|
|
@Column(name = "protected_at")
|
|
|
|
|
private LocalDateTime protectedAt;
|
|
|
|
|
|
2026-01-16 14:30:45 +07:00
|
|
|
@OneToOne(mappedBy = "file", cascade = CascadeType.ALL, orphanRemoval = true)
|
|
|
|
|
@JsonIgnore
|
|
|
|
|
private ImageHashEntity imageHash;
|
|
|
|
|
|
2025-12-17 01:19:48 +07:00
|
|
|
@PrePersist
|
|
|
|
|
public void prePersist() {
|
|
|
|
|
if (this.status == null) {
|
|
|
|
|
this.status = FileStatus.ACTIVE;
|
|
|
|
|
}
|
2026-01-08 03:22:32 +07:00
|
|
|
|
|
|
|
|
if (this.protectionStatus == null) {
|
|
|
|
|
this.protectionStatus = ProtectionStatus.NOT_PROTECTED;
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-17 01:19:48 +07:00
|
|
|
if (this.createdAt == null) {
|
|
|
|
|
this.createdAt = LocalDateTime.now();
|
|
|
|
|
}
|
|
|
|
|
this.updatedAt = LocalDateTime.now();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@PreUpdate
|
|
|
|
|
public void preUpdate() {
|
|
|
|
|
this.updatedAt = LocalDateTime.now();
|
|
|
|
|
}
|
|
|
|
|
}
|