package cn.estsh.i3plus.pojo.softswitch.bean;

import cn.estsh.i3plus.pojo.base.bean.BaseBean;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiParam;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;

/**
 * @Description :
 * @Reference :
 * @Author : yunhao
 * @CreateDate : 2019-09-25 17:42
 * @Modify:
 **/
@Data
@Entity
@DynamicInsert
@DynamicUpdate
@EqualsAndHashCode(callSuper = true)
@Table(name = "BS_SUIT_FILE")
@ApiModel(value = "适配文件信息", description = "适配文件信息")
public class BsSuitFile extends BaseBean {

    private static final long serialVersionUID = -5476684791619434327L;
    @Column(name = "SUIT_CASE_ID")
    @ApiParam(value = "套件id")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long suitCaseId;

    @Column(name = "SUIT_RECORD_ID")
    @ApiParam(value = "适配记录id")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long suitRecordId;

    @Column(name = "SUIT_CASE_NAME_RDD")
    @ApiParam(value = "适配套件名称")
    private String suitCaseNameRdd;

    @Column(name = "SUIT_CASE_CODE")
    @ApiParam(value = "适配套件代码")
    private String suitCaseCode;

    @Column(name = "CASE_TYPE_ID")
    @ApiParam(value = "套件类型id(枚举)")
    private Integer caseTypeId;

    @Column(name = "FOLDER_PATH")
    @ApiParam(value = "文件夹路径")
    private String folderPath;

    @Column(name = "FILE_ID")
    @ApiParam(value = "文件id")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long fileId;

    @Column(name = "FILE_NAME")
    @ApiParam(value = "文件名称")
    private String fileName;

    @Column(name = "FILE_URL")
    @ApiParam(value = "文件URL")
    private String fileURL;

    @Column(name = "FILE_SIZE")
    @ApiParam(value = "文件大小")
    private int fileSize;

    @Column(name = "SUIT_DATE_TIME")
    @ApiParam(value = "适配时间")
    private String suitDateTime;

    @Column(name = "PROCESS_STATE")
    @ApiParam(value = "处理状态")
    private Integer processState;

    @Column(name = "PROCESS_TIME")
    @ApiParam(value = "处理时间")
    private String processTime;

    public void setFtpPathInfo(String ftpPathInfo){
        if(ftpPathInfo == null){
            return;
        }

        int pathIdx = ftpPathInfo.lastIndexOf("/");
        if (pathIdx == -1) {
            this.setFolderPath("/");
            this.setFileName(ftpPathInfo);
        }else{
            this.setFolderPath(ftpPathInfo.substring(0,pathIdx));
            this.setFileName(ftpPathInfo.substring(pathIdx + 1));
        }
    }

}
