Files
no-copy/src/main/java/ru/soune/nocopy/entity/file/FileEntity.java
T

84 lines
2.2 KiB
Java
Raw Normal View History

2025-12-17 22:37:46 +07:00
package ru.soune.nocopy.entity.file;
2025-12-17 01:19:48 +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;
@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;
}
if (this.createdAt == null) {
this.createdAt = LocalDateTime.now();
}
this.updatedAt = LocalDateTime.now();
}
}