package cn.estsh.i3plus.pojo.mes.engine.script;

import cn.estsh.i3plus.pojo.base.bean.BaseBean;
import io.swagger.annotations.Api;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.*;

/**
 * 脚本持久化实体类
 *
 * @author Rock.Yu
 * @since 2019-03-18 14:22
 */
@Data
@Entity
@DynamicInsert
@DynamicUpdate
@NoArgsConstructor
@EqualsAndHashCode(callSuper = true)
@Table(name = "MES_SCRIPT_PERSISTENCE", indexes = {
        @Index(columnList = "SCRIPT_NO"),
        @Index(columnList = "ORGANIZE_CODE")
})
@Api("系统动态脚本")
public class EngineScriptPersistence extends BaseBean {
    private static final long serialVersionUID = 7893111140559759490L;
    // 脚本调用的唯一编号，例如：WMS_PDA_0001
    @Column(name = "SCRIPT_NO", length = 50)
    private String scriptNo;

    // 脚本的中文名称
    @Column(name = "SCRIPT_NAME", length = 50)
    private String scriptName;

    // 10=组件脚本，20=表单脚本，30=报表脚本，40=JOB脚本，50=其他脚本
    @Column(name = "SCRIPT_TYPE")
    private Integer scriptType;

    // 脚本编写的语言
    // 10=Groovy, 20=Jython, 30=JavaScript, 40=Scala, 50=JRuby
    @Column(name = "LANGUAGE_TYPE")
    private Integer languageType;

    // 脚本的具体内容
    @Lob
    @Column(name = "SCRIPT_CONTENT", columnDefinition = "TEXT")
    private String scriptContent;

    // 脚本的描述，包含脚本的用法，参数说明等
    @Column(name = "SCRIPT_REMARK", length = 2000)
    private String scriptRemark;

    // 编译后的脚本内容，通过预编译加快脚本的运行速度
    @Transient
    private Object compiledScript;

    // 构造方法，便于批量创建数据
    public EngineScriptPersistence(Long id, String scriptNo, String scriptName, Integer scriptType, Integer languageType,
                                   String scriptContent, String scriptRemark) {
        this.id = id;
        this.scriptNo = scriptNo;
        this.scriptName = scriptName;
        this.scriptType = scriptType;
        this.languageType = languageType;
        this.scriptContent = scriptContent;
        this.scriptRemark = scriptRemark;
    }
}
