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

import cn.estsh.i3plus.pojo.base.annotation.AnnoOutputColumn;
import cn.estsh.i3plus.pojo.base.bean.BaseBean;
import cn.estsh.i3plus.pojo.base.enumutil.BlockSoftSwitchEnumUtil;
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.ColumnDefault;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.*;
import java.util.List;
import java.util.Map;

/**
 * @Description : 适配记录
 * @Reference :
 * @Author : yunhao
 * @CreateDate : 2019-08-13 9:21
 * @Modify:
 */
@Data
@Entity
@DynamicInsert
@DynamicUpdate
@EqualsAndHashCode(callSuper = true)
@Table(name = "BS_SUIT_RECORD",indexes = {
        @Index(name="bs_suit_record_suit_case_name_rdd_idx",columnList = "SUIT_CASE_NAME_RDD"),
        @Index(name="bs_suit_record_suit_case_code_idx",columnList = "SUIT_CASE_CODE"),
        @Index(name="bs_suit_record_create_date_time_idx",columnList = "CREATE_DATE_TIME"),
        @Index(name="bs_suit_record_process_time_idx",columnList = "PROCESS_TIME"),
})
@ApiModel(value = "适配记录", description = "适配记录")
public class BsSuitRecord extends BaseBean {

    private static final long serialVersionUID = 174969165955420968L;
    @Column(name = "SUIT_CASE_NAME_RDD")
    @ApiParam(value = "适配套件名称")
    private String suitCaseNameRdd;

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

    @Column(name = "SUIT_CASE_ID")
    @ApiParam(value = "适配器套件id")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long suitCaseId;

    @Column(name = "CASE_TYPE_ID")
    @ApiParam(value = "套件类型id(枚举)")
    @AnnoOutputColumn(refClass = BlockSoftSwitchEnumUtil.CASE_TYPE.class)
    private Integer caseTypeId;

    @Column(name = "SUIT_CASE_DETAIL_ID")
    @ApiParam(value = "适配套件明细id")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long suitCaseDetailId;

    @Column(name = "SUIT_SID")
    @ApiParam(value = "适配记录SID")
    private String suitSid;

    @Column(name = "RETRY_RECORD_ID")
    @ApiParam(value = "重试记录id")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long retryRecordId;

    @Column(name = "SUIT_METHOD_ID")
    @ApiParam(value = "适配方式id枚举（定时适配，主动适配）")
    private Integer suitMethodId;

    @Column(name = "SUIT_METHOD_NAME_RDD")
    @ApiParam(value = "适配方式名称枚举")
    private Integer suitMethodNameRdd;

    @Column(name = "SUIT_TYPE_ID")
    @ApiParam(value = "适配类型id")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long suitTypeId;

    @Column(name = "SUIT_TYPE_NAME_RDD")
    @ApiParam(value = "适配类型名称")
    private String suitTypeNameRdd;

    @Column(name = "REQUEST_SOURCE")
    @ApiParam(value = "请求来源(枚举)")
    private Integer requestSource;

    @Column(name = "SSL_KEY_ID")
    @ApiParam(value = "证书id")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long sslKeyId;

    @Column(name = "SUIT_SSL_KEY_NAME_RDD")
    @ApiParam(value = "证书名称")
    private String suitSslKeyNameRdd;

    @Column(name = "SUIT_SSL_KEY_RESULT")
    @ApiParam(value = "认证结果")
    private Integer suitSslKeyResult;

    @Column(name = "SUIT_SSL_KEY_RESULT_MESSAGE")
    @ApiParam(value = "认证信息")
    private String suitSslKeyResultMessage;

    @Column(name = "SUIT_RESULT")
    @ApiParam(value = "适配结果")
    private Integer suitResult;

    @Column(name = "SUIT_START_DATE_TIME")
    @ApiParam(value = "适配开始时间")
    private String suitStartTime;

    @Column(name = "SUIT_END_DATE_TIME")
    @ApiParam(value = "适配结束时间")
    private String suitEndTime;

    @Column(name = "EXECUTE_TIME")
    @ApiParam(value = "执行耗时")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long executeTime;

    // 移动至记录数据表
    @Column(name = "SUIT_MESSAGE")
    @ApiParam(value = "适配信息 longDataId")
    private String suitMessage;

    // 移动至记录数据表
    @Column(name = "SUIT_SEND_MESSAGE")
    @ApiParam(value = "适配发送报文")
    private String suitSendMessage;

    @Column(name = "PROCESS_STATE")
    @ApiParam(value = "处理状态")
    @AnnoOutputColumn(refClass = BlockSoftSwitchEnumUtil.SUIT_PROCESS_STATUS.class)
    private Integer processState;

    public String getProcessStateTxt() {
        return processState == null ? BlockSoftSwitchEnumUtil.SUIT_PROCESS_STATUS.UNPROCESSED.getDescription() :
                BlockSoftSwitchEnumUtil.SUIT_PROCESS_STATUS.valueOfDescription(processState);
    }

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

    @Column(name = "SCRIPT_RESULT")
    @ApiParam(value = "脚本结果")
    private String scriptResult;

    @Column(name = "PROCESS_RESULT")
    @ApiParam(value = "处理结果")
    private String processResult;

    @ColumnDefault(value = "10")
    @Column(name = "RETRY_STATUS")
    @ApiParam(value = "重试状态")
    @AnnoOutputColumn(refClass = BlockSoftSwitchEnumUtil.BS_SUIT_RETRY_STATUS.class)
    private Integer retryStatus;

    public String getRetryStatusTxt() {
        return retryStatus == null ? BlockSoftSwitchEnumUtil.BS_SUIT_RETRY_STATUS.NOT_RETRY.getDescription() :
                BlockSoftSwitchEnumUtil.BS_SUIT_RETRY_STATUS.valueOfDescription(retryStatus);
    }

    @ColumnDefault(value = "0")
    @Column(name = "RETRY_NUM")
    @ApiParam(value = "重试状态")
    private Integer retryNum;

    public int getRetryNumVal() {
        return retryNum == null ? 0 : retryNum;
    }

    /************************************** 临时属性 ***************************************/

    @Transient
    @ApiParam(value = "适配记录参数")
    private List<BsSuitRecordParam> bsSuitRecordParamList;

    @Transient
    @ApiParam(value = "适配记录报文")
    private BsSuitDataDetail bsSuitDataDetail;

    @Transient
    @ApiParam(value = "适配请求记录")
    private BsSuitRequestRecord bsSuitRequestRecord;

    @Transient
    @ApiParam(value = "适配请求文件列表")
    private List<BsSuitFile> bsSuitFileList;

    @Transient
    @ApiParam(value = "日志长文本记录集合<关联类型，记录内容>")
    private Map<Integer ,BsLongData> bsLongDataMap;

    @Transient
    @ApiParam(value = "适配记录报文-查询条件")
    private String searchMessage;

    @Transient
    @ApiParam(value = "适配入参-查询条件")
    private String searchInputParam;

    @Transient
    @ApiParam(value = "id-查询条件")
    private List<Long> searchIdList;
}

