package com.keyware.shandan.system.entity;

import com.baomidou.mybatisplus.annotation.OrderBy;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.keyware.shandan.common.entity.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.ibatis.type.JdbcType;

@Data
@EqualsAndHashCode(callSuper = true)
@TableName("SYS_FILE_CHUNK")
public class SysFileChunk extends BaseEntity {
    private static final long serialVersionUID = -8732733147355105081L;

    /**
     * 分片ID
     */
    @TableId(value = "ID")
    private String id;
    /**
     * 分片名称
     */
    @TableField("CHUNK_NAME")
    private String chunkName;
    /**
     * 分片的文件路径
     */
    @TableField("CHUNK_PATH")
    private String chunkPath;
    /**
     * 分片MD5
     */
    @TableField("CHUNK_MD5")
    private String chunkMd5;
    /**
     * 分片文件后缀
     */
    @TableField("CHUNK_SUFFIX")
    private String chunkSuffix;
    /**
     * 总的分片数
     */
    @TableField(value = "CHUNK_TOTAL", jdbcType = JdbcType.BIGINT)
    private Long chunkTotal;
    /**
     * 当前分片索引
     */
    @TableField(value = "CHUNK_INDEX", jdbcType = JdbcType.BIGINT)
    @OrderBy(isDesc = false)
    private Long chunkIndex;
    /**
     * 文件开始位置
     */
    @TableField(value = "START_OFFSET", jdbcType = JdbcType.BIGINT)
    private Long startOffset;
    /**
     * 文件结束位置
     */
    @TableField(value = "END_OFFSET", jdbcType = JdbcType.BIGINT)
    private Long endOffset;
    /**
     * 文件ID
     */
    @TableField("FILE_ID")
    private String fileId;
    /**
     * 总文件的MD5值
     */
    @TableField("FILE_MD5")
    private String fileMd5;
    /**
     * 文件总大小
     */
    @TableField(value = "FILE_SIZE", jdbcType = JdbcType.BIGINT)
    private Long fileSize;

    /**
     * 是否最后一片分片
     *
     * @return 是否最后一片分片
     */
    public boolean isLast() {
        return chunkIndex == chunkTotal - 1;
    }
}
