fix(插件定义): 插件脚本初始化问题修复

This commit is contained in:
fit2-zhao 2021-09-07 15:53:36 +08:00 committed by fit2-zhao
parent 99261a56c4
commit 9566b3b6f7
8 changed files with 110 additions and 18 deletions

View File

@ -1,8 +1,7 @@
package io.metersphere.base.domain; package io.metersphere.base.domain;
import lombok.Data;
import java.io.Serializable; import java.io.Serializable;
import lombok.Data;
@Data @Data
public class Plugin implements Serializable { public class Plugin implements Serializable {
@ -12,6 +11,8 @@ public class Plugin implements Serializable {
private String pluginId; private String pluginId;
private String scriptId;
private String clazzName; private String clazzName;
private String sourcePath; private String sourcePath;

View File

@ -314,6 +314,76 @@ public class PluginExample {
return (Criteria) this; return (Criteria) this;
} }
public Criteria andScriptIdIsNull() {
addCriterion("script_id is null");
return (Criteria) this;
}
public Criteria andScriptIdIsNotNull() {
addCriterion("script_id is not null");
return (Criteria) this;
}
public Criteria andScriptIdEqualTo(String value) {
addCriterion("script_id =", value, "scriptId");
return (Criteria) this;
}
public Criteria andScriptIdNotEqualTo(String value) {
addCriterion("script_id <>", value, "scriptId");
return (Criteria) this;
}
public Criteria andScriptIdGreaterThan(String value) {
addCriterion("script_id >", value, "scriptId");
return (Criteria) this;
}
public Criteria andScriptIdGreaterThanOrEqualTo(String value) {
addCriterion("script_id >=", value, "scriptId");
return (Criteria) this;
}
public Criteria andScriptIdLessThan(String value) {
addCriterion("script_id <", value, "scriptId");
return (Criteria) this;
}
public Criteria andScriptIdLessThanOrEqualTo(String value) {
addCriterion("script_id <=", value, "scriptId");
return (Criteria) this;
}
public Criteria andScriptIdLike(String value) {
addCriterion("script_id like", value, "scriptId");
return (Criteria) this;
}
public Criteria andScriptIdNotLike(String value) {
addCriterion("script_id not like", value, "scriptId");
return (Criteria) this;
}
public Criteria andScriptIdIn(List<String> values) {
addCriterion("script_id in", values, "scriptId");
return (Criteria) this;
}
public Criteria andScriptIdNotIn(List<String> values) {
addCriterion("script_id not in", values, "scriptId");
return (Criteria) this;
}
public Criteria andScriptIdBetween(String value1, String value2) {
addCriterion("script_id between", value1, value2, "scriptId");
return (Criteria) this;
}
public Criteria andScriptIdNotBetween(String value1, String value2) {
addCriterion("script_id not between", value1, value2, "scriptId");
return (Criteria) this;
}
public Criteria andClazzNameIsNull() { public Criteria andClazzNameIsNull() {
addCriterion("clazz_name is null"); addCriterion("clazz_name is null");
return (Criteria) this; return (Criteria) this;

View File

@ -1,11 +1,10 @@
package io.metersphere.base.domain; package io.metersphere.base.domain;
import java.io.Serializable;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.ToString; import lombok.ToString;
import java.io.Serializable;
@Data @Data
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true) @ToString(callSuper = true)

View File

@ -5,6 +5,7 @@
<id column="id" jdbcType="VARCHAR" property="id" /> <id column="id" jdbcType="VARCHAR" property="id" />
<result column="name" jdbcType="VARCHAR" property="name" /> <result column="name" jdbcType="VARCHAR" property="name" />
<result column="plugin_id" jdbcType="VARCHAR" property="pluginId" /> <result column="plugin_id" jdbcType="VARCHAR" property="pluginId" />
<result column="script_id" jdbcType="VARCHAR" property="scriptId" />
<result column="clazz_name" jdbcType="VARCHAR" property="clazzName" /> <result column="clazz_name" jdbcType="VARCHAR" property="clazzName" />
<result column="source_path" jdbcType="VARCHAR" property="sourcePath" /> <result column="source_path" jdbcType="VARCHAR" property="sourcePath" />
<result column="source_name" jdbcType="VARCHAR" property="sourceName" /> <result column="source_name" jdbcType="VARCHAR" property="sourceName" />
@ -76,8 +77,8 @@
</where> </where>
</sql> </sql>
<sql id="Base_Column_List"> <sql id="Base_Column_List">
id, `name`, plugin_id, clazz_name, source_path, source_name, exec_entry, create_time, id, `name`, plugin_id, script_id, clazz_name, source_path, source_name, exec_entry,
update_time, create_user_id create_time, update_time, create_user_id
</sql> </sql>
<sql id="Blob_Column_List"> <sql id="Blob_Column_List">
form_option, form_script form_option, form_script
@ -132,15 +133,15 @@
</delete> </delete>
<insert id="insert" parameterType="io.metersphere.base.domain.PluginWithBLOBs"> <insert id="insert" parameterType="io.metersphere.base.domain.PluginWithBLOBs">
insert into plugin (id, `name`, plugin_id, insert into plugin (id, `name`, plugin_id,
clazz_name, source_path, source_name, script_id, clazz_name, source_path,
exec_entry, create_time, update_time, source_name, exec_entry, create_time,
create_user_id, form_option, form_script update_time, create_user_id, form_option,
) form_script)
values (#{id,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{pluginId,jdbcType=VARCHAR}, values (#{id,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{pluginId,jdbcType=VARCHAR},
#{clazzName,jdbcType=VARCHAR}, #{sourcePath,jdbcType=VARCHAR}, #{sourceName,jdbcType=VARCHAR}, #{scriptId,jdbcType=VARCHAR}, #{clazzName,jdbcType=VARCHAR}, #{sourcePath,jdbcType=VARCHAR},
#{execEntry,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT}, #{updateTime,jdbcType=BIGINT}, #{sourceName,jdbcType=VARCHAR}, #{execEntry,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT},
#{createUserId,jdbcType=VARCHAR}, #{formOption,jdbcType=LONGVARCHAR}, #{formScript,jdbcType=LONGVARCHAR} #{updateTime,jdbcType=BIGINT}, #{createUserId,jdbcType=VARCHAR}, #{formOption,jdbcType=LONGVARCHAR},
) #{formScript,jdbcType=LONGVARCHAR})
</insert> </insert>
<insert id="insertSelective" parameterType="io.metersphere.base.domain.PluginWithBLOBs"> <insert id="insertSelective" parameterType="io.metersphere.base.domain.PluginWithBLOBs">
insert into plugin insert into plugin
@ -154,6 +155,9 @@
<if test="pluginId != null"> <if test="pluginId != null">
plugin_id, plugin_id,
</if> </if>
<if test="scriptId != null">
script_id,
</if>
<if test="clazzName != null"> <if test="clazzName != null">
clazz_name, clazz_name,
</if> </if>
@ -192,6 +196,9 @@
<if test="pluginId != null"> <if test="pluginId != null">
#{pluginId,jdbcType=VARCHAR}, #{pluginId,jdbcType=VARCHAR},
</if> </if>
<if test="scriptId != null">
#{scriptId,jdbcType=VARCHAR},
</if>
<if test="clazzName != null"> <if test="clazzName != null">
#{clazzName,jdbcType=VARCHAR}, #{clazzName,jdbcType=VARCHAR},
</if> </if>
@ -239,6 +246,9 @@
<if test="record.pluginId != null"> <if test="record.pluginId != null">
plugin_id = #{record.pluginId,jdbcType=VARCHAR}, plugin_id = #{record.pluginId,jdbcType=VARCHAR},
</if> </if>
<if test="record.scriptId != null">
script_id = #{record.scriptId,jdbcType=VARCHAR},
</if>
<if test="record.clazzName != null"> <if test="record.clazzName != null">
clazz_name = #{record.clazzName,jdbcType=VARCHAR}, clazz_name = #{record.clazzName,jdbcType=VARCHAR},
</if> </if>
@ -276,6 +286,7 @@
set id = #{record.id,jdbcType=VARCHAR}, set id = #{record.id,jdbcType=VARCHAR},
`name` = #{record.name,jdbcType=VARCHAR}, `name` = #{record.name,jdbcType=VARCHAR},
plugin_id = #{record.pluginId,jdbcType=VARCHAR}, plugin_id = #{record.pluginId,jdbcType=VARCHAR},
script_id = #{record.scriptId,jdbcType=VARCHAR},
clazz_name = #{record.clazzName,jdbcType=VARCHAR}, clazz_name = #{record.clazzName,jdbcType=VARCHAR},
source_path = #{record.sourcePath,jdbcType=VARCHAR}, source_path = #{record.sourcePath,jdbcType=VARCHAR},
source_name = #{record.sourceName,jdbcType=VARCHAR}, source_name = #{record.sourceName,jdbcType=VARCHAR},
@ -294,6 +305,7 @@
set id = #{record.id,jdbcType=VARCHAR}, set id = #{record.id,jdbcType=VARCHAR},
`name` = #{record.name,jdbcType=VARCHAR}, `name` = #{record.name,jdbcType=VARCHAR},
plugin_id = #{record.pluginId,jdbcType=VARCHAR}, plugin_id = #{record.pluginId,jdbcType=VARCHAR},
script_id = #{record.scriptId,jdbcType=VARCHAR},
clazz_name = #{record.clazzName,jdbcType=VARCHAR}, clazz_name = #{record.clazzName,jdbcType=VARCHAR},
source_path = #{record.sourcePath,jdbcType=VARCHAR}, source_path = #{record.sourcePath,jdbcType=VARCHAR},
source_name = #{record.sourceName,jdbcType=VARCHAR}, source_name = #{record.sourceName,jdbcType=VARCHAR},
@ -314,6 +326,9 @@
<if test="pluginId != null"> <if test="pluginId != null">
plugin_id = #{pluginId,jdbcType=VARCHAR}, plugin_id = #{pluginId,jdbcType=VARCHAR},
</if> </if>
<if test="scriptId != null">
script_id = #{scriptId,jdbcType=VARCHAR},
</if>
<if test="clazzName != null"> <if test="clazzName != null">
clazz_name = #{clazzName,jdbcType=VARCHAR}, clazz_name = #{clazzName,jdbcType=VARCHAR},
</if> </if>
@ -348,6 +363,7 @@
update plugin update plugin
set `name` = #{name,jdbcType=VARCHAR}, set `name` = #{name,jdbcType=VARCHAR},
plugin_id = #{pluginId,jdbcType=VARCHAR}, plugin_id = #{pluginId,jdbcType=VARCHAR},
script_id = #{scriptId,jdbcType=VARCHAR},
clazz_name = #{clazzName,jdbcType=VARCHAR}, clazz_name = #{clazzName,jdbcType=VARCHAR},
source_path = #{sourcePath,jdbcType=VARCHAR}, source_path = #{sourcePath,jdbcType=VARCHAR},
source_name = #{sourceName,jdbcType=VARCHAR}, source_name = #{sourceName,jdbcType=VARCHAR},
@ -363,6 +379,7 @@
update plugin update plugin
set `name` = #{name,jdbcType=VARCHAR}, set `name` = #{name,jdbcType=VARCHAR},
plugin_id = #{pluginId,jdbcType=VARCHAR}, plugin_id = #{pluginId,jdbcType=VARCHAR},
script_id = #{scriptId,jdbcType=VARCHAR},
clazz_name = #{clazzName,jdbcType=VARCHAR}, clazz_name = #{clazzName,jdbcType=VARCHAR},
source_path = #{sourcePath,jdbcType=VARCHAR}, source_path = #{sourcePath,jdbcType=VARCHAR},
source_name = #{sourceName,jdbcType=VARCHAR}, source_name = #{sourceName,jdbcType=VARCHAR},

View File

@ -64,6 +64,7 @@ public class PluginService {
plugin.setUpdateTime(System.currentTimeMillis()); plugin.setUpdateTime(System.currentTimeMillis());
plugin.setName(item.getName()); plugin.setName(item.getName());
plugin.setPluginId(resource.getPluginId()); plugin.setPluginId(resource.getPluginId());
plugin.setScriptId(item.getId());
plugin.setSourcePath(path); plugin.setSourcePath(path);
plugin.setFormOption(item.getFormOption()); plugin.setFormOption(item.getFormOption());
plugin.setFormScript(item.getFormScript()); plugin.setFormScript(item.getFormScript());
@ -156,9 +157,9 @@ public class PluginService {
return plugins; return plugins;
} }
public Plugin get(String pluginId) { public Plugin get(String scriptId) {
PluginExample example = new PluginExample(); PluginExample example = new PluginExample();
example.createCriteria().andPluginIdEqualTo(pluginId); example.createCriteria().andScriptIdEqualTo(scriptId);
List<PluginWithBLOBs> plugins = pluginMapper.selectByExampleWithBLOBs(example); List<PluginWithBLOBs> plugins = pluginMapper.selectByExampleWithBLOBs(example);
if (CollectionUtils.isNotEmpty(plugins)) { if (CollectionUtils.isNotEmpty(plugins)) {
return plugins.get(0); return plugins.get(0);

View File

@ -2,6 +2,7 @@ CREATE TABLE `plugin` (
`id` varchar(50) NOT NULL COMMENT 'ID', `id` varchar(50) NOT NULL COMMENT 'ID',
`name` varchar(300) DEFAULT NULL COMMENT 'plugin name', `name` varchar(300) DEFAULT NULL COMMENT 'plugin name',
`plugin_id` varchar(300) NOT NULL COMMENT 'Plugin id', `plugin_id` varchar(300) NOT NULL COMMENT 'Plugin id',
`script_id` varchar(300) NOT NULL COMMENT 'Ui script id',
`clazz_name` varchar(500) NOT NULL COMMENT 'Plugin clazzName', `clazz_name` varchar(500) NOT NULL COMMENT 'Plugin clazzName',
`source_path` varchar(300) NOT NULL COMMENT 'Plugin jar path', `source_path` varchar(300) NOT NULL COMMENT 'Plugin jar path',
`source_name` varchar(300) NOT NULL COMMENT 'Plugin jar name', `source_name` varchar(300) NOT NULL COMMENT 'Plugin jar name',

View File

@ -9,7 +9,7 @@
:is-max="isMax" :is-max="isMax"
:show-btn="showBtn" :show-btn="showBtn"
:background-color="defBackgroundColor" :background-color="defBackgroundColor"
:title="request.type"> :title="pluginName">
<template v-slot:request> <template v-slot:request>
<legend style="width: 100%"> <legend style="width: 100%">
@ -120,6 +120,7 @@ export default {
option: formCreate.parseJson( option: formCreate.parseJson(
'{"form":{"labelPosition":"right","size":"mini","labelWidth":"120px","hideRequiredAsterisk":false,"showMessage":false,"inlineMessage":false}}' '{"form":{"labelPosition":"right","size":"mini","labelWidth":"120px","hideRequiredAsterisk":false,"showMessage":false,"inlineMessage":false}}'
), ),
pluginName: "",
} }
}, },
computed: {}, computed: {},
@ -130,6 +131,7 @@ export default {
} }
this.data = this.request; this.data = this.request;
this.request.type = 'Sampler'; this.request.type = 'Sampler';
this.pluginName = this.request.type;
}, },
watch: { watch: {
message() { message() {
@ -178,6 +180,7 @@ export default {
if (id) { if (id) {
this.$get('/plugin/get/' + id, response => { this.$get('/plugin/get/' + id, response => {
let plugin = response.data; let plugin = response.data;
this.pluginName = plugin.name;
this.execEntry = plugin.execEntry; this.execEntry = plugin.execEntry;
if (plugin && plugin.formScript) { if (plugin && plugin.formScript) {
this.rules = formCreate.parseJson(plugin.formScript); this.rules = formCreate.parseJson(plugin.formScript);

View File

@ -200,7 +200,7 @@ export function setComponent(type, _this, plugin) {
_this.$refs.scenarioRelevance.open(); _this.$refs.scenarioRelevance.open();
break; break;
default: default:
_this.scenarioDefinition.push(new PluginController({type: plugin.name, pluginId: plugin.pluginId})); _this.scenarioDefinition.push(new PluginController({type: plugin.name, pluginId: plugin.scriptId}));
break; break;
} }
if (_this.selectedNode) { if (_this.selectedNode) {