自定义脚本开发

yun-zuoyi
Silliter 6 years ago
parent bb811306ff
commit b3f4ccbb78

@ -2102,4 +2102,88 @@ public class WmsEnumUtil {
return tmp; return tmp;
} }
} }
/**
*
* 10=20=30=40=JOB50=
*/
public enum SCRIPT_TYPE {
MODUAL(10,"Modual","组件脚本"),
FORM(20,"Form","表单脚本"),
REPORT(30,"Report","报表脚本"),
JOB(40,"Job","JOB脚本"),
OTHER(50,"Other","其他脚本");
private String description;
private int value;
private String code;
SCRIPT_TYPE(int value, String code, String description) {
this.description = description;
this.value = value;
this.code = code;
}
public String getCode() {
return this.code;
}
public int getIndex() {
return this.value;
}
public int getValue() {
return value;
}
public String getDescription() {
return description;
}
}
/**
*
* 10=Groovy, 20=Jython, 30=JavaScript, 40=Scala, 50=JRuby
*/
public enum LANGUAGE_TYPE {
GROOVY(1,"Groovy", 10),
PYTHON(2,"Python", 20),
JS(3,"JavaScript", 30);
// 下面这2种语言没人会写暂不支持
//SCALA(40,"scala"),
//JRUBY(50,"jruby");
private int index;
private String description;
private int value;
private LANGUAGE_TYPE(int index, String description, int value) {
this.index = index;
this.description = description;
this.value = value;
}
public String getDescription() {
return description;
}
public int getIndex() {
return this.index;
}
public int getValue() {
return value;
}
// 根据枚举编号获取语言代码
public static String getCodeByIndex(int index) {
for (LANGUAGE_TYPE languageType : LANGUAGE_TYPE.values()) {
if (languageType.getIndex() == index) {
return languageType.getDescription();
}
}
return null;
}
}
} }

@ -4,11 +4,15 @@ import cn.estsh.i3plus.pojo.base.bean.BaseBean;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.DynamicInsert; import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate; import org.hibernate.annotations.DynamicUpdate;
import javax.persistence.*; import javax.persistence.*;
import javax.script.CompiledScript; import javax.script.CompiledScript;
import javax.script.ScriptContext;
import javax.script.ScriptEngine;
import javax.script.ScriptException;
/** /**
* *
@ -20,6 +24,7 @@ import javax.script.CompiledScript;
@Entity @Entity
@DynamicInsert @DynamicInsert
@DynamicUpdate @DynamicUpdate
@NoArgsConstructor
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@Table(name = "SCRIPT_PERSISTENCE") @Table(name = "SCRIPT_PERSISTENCE")
@Api("系统动态脚本") @Api("系统动态脚本")
@ -27,30 +32,34 @@ public class EngineScriptPersistence extends BaseBean {
// 脚本调用的唯一编号例如WMS_PDA_0001 // 脚本调用的唯一编号例如WMS_PDA_0001
@Column(name = "SCRIPT_NO", length = 50) @Column(name = "SCRIPT_NO", length = 50)
private String scriptNo; private String scriptNo;
// 脚本的中文名称 // 脚本的中文名称
@Column(name = "SCRIPT_NAME", length = 50) @Column(name = "SCRIPT_NAME", length = 50)
private String scriptName; private String scriptName;
// 10=组件脚本20=表单脚本30=报表脚本40=JOB脚本50=其他脚本 // 10=组件脚本20=表单脚本30=报表脚本40=JOB脚本50=其他脚本
@Column(name = "SCRIPT_TYPE") @Column(name = "SCRIPT_TYPE")
private int scriptType; private Integer scriptType;
// 脚本编写的语言 // 脚本编写的语言
// 10=Groovy, 20=Jython, 30=JavaScript, 40=Scala, 50=JRuby // 10=Groovy, 20=Jython, 30=JavaScript, 40=Scala, 50=JRuby
@Column(name = "LANGUAGE_TYPE") @Column(name = "LANGUAGE_TYPE")
private int languageType; private Integer languageType;
// 脚本的具体内容 // 脚本的具体内容
@Column(name = "SCRIPT_CONTENT", columnDefinition = "TEXT") @Column(name = "SCRIPT_CONTENT", columnDefinition = "TEXT")
private String scriptContent; private String scriptContent;
// 脚本的描述,包含脚本的用法,参数说明等 // 脚本的描述,包含脚本的用法,参数说明等
@Column(name = "SCRIPT_REMARK", length = 2000) @Column(name = "SCRIPT_REMARK", length = 2000)
private String scriptRemark; private String scriptRemark;
// 编译后的脚本内容,通过预编译加快脚本的运行速度 // 编译后的脚本内容,通过预编译加快脚本的运行速度
@Transient @Transient
private CompiledScript compiledScript; private Object compiledScript;
public EngineScriptPersistence() {}
// 构造方法,便于批量创建数据 // 构造方法,便于批量创建数据
public EngineScriptPersistence(long id, String scriptNo, String scriptName, int scriptType, int languageType, public EngineScriptPersistence(Long id, String scriptNo, String scriptName, Integer scriptType, Integer languageType,
String scriptContent, String scriptRemark) { String scriptContent, String scriptRemark) {
this.id = id; this.id = id;
this.scriptNo = scriptNo; this.scriptNo = scriptNo;

Loading…
Cancel
Save