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.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.lang3.math.NumberUtils;
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 : 2020-07-28 14:35
 * @Modify:
 **/
@Data
@Entity
@DynamicInsert
@DynamicUpdate
@EqualsAndHashCode(callSuper = true)
@Table(name = "BS_BUSI_SCRIPT")
@ApiModel(value = "业务脚本", description = "业务脚本")
public class BsBusiScript extends BaseBean {

    private static final long serialVersionUID = 1419277265159912600L;

    @Column(name = "SCRIPT_NAME")
    @ApiModelProperty(value = "脚本名称")
    private String scriptName;

    @Column(name = "SCRIPT_CODE")
    @ApiModelProperty(value = "脚本代码")
    private String scriptCode;

    @Column(name = "SCRIPT_TYPE")
    @ApiModelProperty(value = "脚本类型")
    @AnnoOutputColumn(refClass = BlockSoftSwitchEnumUtil.BS_SCRIPT_TYPE.class)
    private Integer scriptType;

    public String getScriptTypeTxt() {
        return scriptType == null ? "无" : BlockSoftSwitchEnumUtil.BS_SCRIPT_TYPE.valueOfDescription(scriptType);
    }

    @Column(name = "SCRIPT_LANGUAGE")
    @ApiModelProperty(value = "脚本语言")
    @AnnoOutputColumn(refClass = BlockSoftSwitchEnumUtil.BS_SCRIPT_LANGUAGE.class)
    private Integer scriptLanguage;

    public String getScriptLanguageTxt() {
        return scriptLanguage == null ? "无" : BlockSoftSwitchEnumUtil.BS_SCRIPT_LANGUAGE.valueOfDescription(scriptLanguage);
    }

    @Column(name = "SCRIPT_EXECUTE_METHOD")
    @ApiModelProperty(value = "脚本执行方式")
    @AnnoOutputColumn(refClass = BlockSoftSwitchEnumUtil.BS_SCRIPT_EXECUTE_METHOD.class)
    private Integer scriptExecuteMethod;

    public String getScriptExecuteMethodTxt() {
        return scriptExecuteMethod == null ? "无" : BlockSoftSwitchEnumUtil.BS_SCRIPT_EXECUTE_METHOD.valueOfDescription(scriptExecuteMethod);
    }

    @Column(name = "SCRIPT_OBJ_NAME")
    @ApiModelProperty(value = "脚本对象名称")
    private String scriptObjName;

    @Column(name = "SCRIPT_METHOD_NAME")
    @ApiModelProperty(value = "脚本方法名称")
    private String scriptMethodName;

    @Column(name = "SCRIPT_CONTENT")
    @ApiModelProperty(value = "脚本内容")
    private String scriptContent;

    @Column(name = "SCRIPT_DESC")
    @ApiModelProperty(value = "脚本描述")
    private String scriptDesc;

    @Column(name = "REF_ID")
    @ApiModelProperty(value = "关联id")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long refId;

    @Column(name = "SCRIPT_VERSION")
    @ApiModelProperty(value = "脚本版本")
    private Integer scriptVersion;

    public int getScriptVersion(){
        return scriptVersion == null ? NumberUtils.INTEGER_ONE : scriptVersion;
    }

    public BsBusiScript nextVersion() {
        setScriptVersion(getScriptVersion() + 1);
        return this;
    }

}
