package cn.estsh.i3plus.ext.mes.pcn.pojo.bean;

import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtConstWords;
import cn.estsh.i3plus.pojo.base.bean.BaseBean;
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
import io.swagger.annotations.Api;
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.io.Serializable;

/**
 * @Author: wangjie
 * @CreateDate: 2019/7/30 9:30 AM
 * @Description:
 **/
@Data
@Entity
@DynamicInsert
@DynamicUpdate
@EqualsAndHashCode(callSuper = true)
@Inheritance(strategy = InheritanceType.JOINED)
@Table(name = "MES_THIRD_PARTY_Db_COLLECT_DATA_RECORD", indexes = {
        @Index(columnList = "SYSTEM_SYNC_STATUS"),
        @Index(columnList = "CFG_CODE"),
        @Index(columnList = "OBJECT_CODE")
})
@Api("第三方DB数据采集定时任务执行记录")
public class MesThirdPartyDbCollectDataRecord extends BaseBean implements Serializable {

    private static final long serialVersionUID = -5811666058929378534L;

    @Column(name = "SYSTEM_SYNC_STATUS")
    @ColumnDefault("2")
    @ApiParam(value = "系统同步标志")
    public Integer systemSyncStatus = 2;

    @Column(name = "CFG_CODE")
    @ApiParam("配置代码")
    private String cfgCode;

    @Column(name = "OBJECT_CODE")
    @ApiParam("对象代码")
    private String objectCode;

    @Lob
    @Column(name = "CFG_VALUE")
    @ApiParam("配置值")
    private String cfgValue;

    @Column(name = "RESULT")
    @ApiParam("结果")
    private Integer result;

    @Column(name = "QTY")
    @ApiParam("执行数量")
    private Integer qty;

    @Lob
    @Column(name = "MESSAGE")
    @ApiParam("信息")
    private String message;

    public MesThirdPartyDbCollectDataRecord() {}

    public MesThirdPartyDbCollectDataRecord(String cfgCode, String objectCode, String cfgValue, Integer result, Integer qty, String message) {
        this.cfgCode = cfgCode;
        this.objectCode = objectCode;
        this.cfgValue = cfgValue;
        this.result = result;
        this.qty = qty;
        this.message = message;
    }

    public MesThirdPartyDbCollectDataRecord(String cfgCode, String objectCode, String cfgValue) {
        this.cfgCode = cfgCode;
        this.objectCode = objectCode;
        this.cfgValue = cfgValue;
    }

    public MesThirdPartyDbCollectDataRecord(String cfgCode) {
        this.cfgCode = cfgCode;
    }

    public String message(String message) {
        this.result = CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue();
        this.qty = MesPcnExtConstWords.ZERO;
        this.message = message;
        return message;
    }
}
