package com.wms.entity.table;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.wms.entity.app.vo.FileVo;
import lombok.Data;

import java.time.LocalDateTime;

import static com.wms.utils.WmsUtils.generateId;

/**
 * 上传历史
 */
@Data
@TableName(value = "tbl_app_upload_record", autoResultMap = true)
public class UploadRecord {
    /**
     * 上传id
     */
    @TableId("upload_id")
    private String uploadId;
    /**
     * 文件id
     */
    @TableField("file_id")
    private String fileId;
    /**
     * 文件哈希值
     */
    @TableField("file_hash")
    private String hash;
    /**
     * 文件名
     */
    @TableField("file_name")
    private String fileName;
    /**
     * 文件描述
     */
    @TableField("file_description")
    private String fileDescription;
    /**
     * 文件类型
     */
    @TableField("file_type")
    private String fileType;
    /**
     * 上传时间
     */
    @TableField("upload_time")
    private LocalDateTime uploadTime;
    /**
     * 上传人员
     */
    @TableField("upload_user")
    private String uploadUser;

    /**
     * 将fileVo转换为上传记录实体类
     * @param fileVo 文件Vo
     * @param fileDescription 文件描述
     * @return 上传记录实体类
     */
    public static UploadRecord ofFileVo(FileVo fileVo, String fileDescription) {
        UploadRecord uploadRecord = new UploadRecord();
        uploadRecord.setUploadId(generateId("UPLOAD_"));
        uploadRecord.setFileId(fileVo.getFileId());
        uploadRecord.setHash(fileVo.getHash());
        uploadRecord.setFileType(fileVo.getType());
        uploadRecord.setFileName(fileVo.getName());
        uploadRecord.setUploadTime(LocalDateTime.now());
        uploadRecord.setUploadUser(fileVo.getUserName());
        uploadRecord.setFileDescription(fileDescription);
        return uploadRecord;
    }
}
