diff --git a/backend/src/main/java/io/metersphere/base/domain/FileStore.java b/backend/src/main/java/io/metersphere/base/domain/FileStore.java index 7ce1029f7c..484db7358d 100644 --- a/backend/src/main/java/io/metersphere/base/domain/FileStore.java +++ b/backend/src/main/java/io/metersphere/base/domain/FileStore.java @@ -17,7 +17,7 @@ public class FileStore implements Serializable { private Long updateTime; - private byte[] file; + private String file; private static final long serialVersionUID = 1L; @@ -77,11 +77,11 @@ public class FileStore implements Serializable { this.updateTime = updateTime; } - public byte[] getFile() { + public String getFile() { return file; } - public void setFile(byte[] file) { - this.file = file; + public void setFile(String file) { + this.file = file == null ? null : file.trim(); } } \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/domain/FileStoreResource.java b/backend/src/main/java/io/metersphere/base/domain/FileStoreResource.java new file mode 100644 index 0000000000..042e7952c7 --- /dev/null +++ b/backend/src/main/java/io/metersphere/base/domain/FileStoreResource.java @@ -0,0 +1,37 @@ +package io.metersphere.base.domain; + +import java.io.Serializable; + +public class FileStoreResource implements Serializable { + private String testId; + + private String fileId; + + private String fileType; + + private static final long serialVersionUID = 1L; + + public String getTestId() { + return testId; + } + + public void setTestId(String testId) { + this.testId = testId == null ? null : testId.trim(); + } + + public String getFileId() { + return fileId; + } + + public void setFileId(String fileId) { + this.fileId = fileId == null ? null : fileId.trim(); + } + + public String getFileType() { + return fileType; + } + + public void setFileType(String fileType) { + this.fileType = fileType == null ? null : fileType.trim(); + } +} \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/domain/FileStoreResourceExample.java b/backend/src/main/java/io/metersphere/base/domain/FileStoreResourceExample.java new file mode 100644 index 0000000000..329415dbb3 --- /dev/null +++ b/backend/src/main/java/io/metersphere/base/domain/FileStoreResourceExample.java @@ -0,0 +1,410 @@ +package io.metersphere.base.domain; + +import java.util.ArrayList; +import java.util.List; + +public class FileStoreResourceExample { + protected String orderByClause; + + protected boolean distinct; + + protected List oredCriteria; + + public FileStoreResourceExample() { + oredCriteria = new ArrayList(); + } + + public void setOrderByClause(String orderByClause) { + this.orderByClause = orderByClause; + } + + public String getOrderByClause() { + return orderByClause; + } + + public void setDistinct(boolean distinct) { + this.distinct = distinct; + } + + public boolean isDistinct() { + return distinct; + } + + public List getOredCriteria() { + return oredCriteria; + } + + public void or(Criteria criteria) { + oredCriteria.add(criteria); + } + + public Criteria or() { + Criteria criteria = createCriteriaInternal(); + oredCriteria.add(criteria); + return criteria; + } + + public Criteria createCriteria() { + Criteria criteria = createCriteriaInternal(); + if (oredCriteria.size() == 0) { + oredCriteria.add(criteria); + } + return criteria; + } + + protected Criteria createCriteriaInternal() { + Criteria criteria = new Criteria(); + return criteria; + } + + public void clear() { + oredCriteria.clear(); + orderByClause = null; + distinct = false; + } + + protected abstract static class GeneratedCriteria { + protected List criteria; + + protected GeneratedCriteria() { + super(); + criteria = new ArrayList(); + } + + public boolean isValid() { + return criteria.size() > 0; + } + + public List getAllCriteria() { + return criteria; + } + + public List getCriteria() { + return criteria; + } + + protected void addCriterion(String condition) { + if (condition == null) { + throw new RuntimeException("Value for condition cannot be null"); + } + criteria.add(new Criterion(condition)); + } + + protected void addCriterion(String condition, Object value, String property) { + if (value == null) { + throw new RuntimeException("Value for " + property + " cannot be null"); + } + criteria.add(new Criterion(condition, value)); + } + + protected void addCriterion(String condition, Object value1, Object value2, String property) { + if (value1 == null || value2 == null) { + throw new RuntimeException("Between values for " + property + " cannot be null"); + } + criteria.add(new Criterion(condition, value1, value2)); + } + + public Criteria andTestIdIsNull() { + addCriterion("test_id is null"); + return (Criteria) this; + } + + public Criteria andTestIdIsNotNull() { + addCriterion("test_id is not null"); + return (Criteria) this; + } + + public Criteria andTestIdEqualTo(String value) { + addCriterion("test_id =", value, "testId"); + return (Criteria) this; + } + + public Criteria andTestIdNotEqualTo(String value) { + addCriterion("test_id <>", value, "testId"); + return (Criteria) this; + } + + public Criteria andTestIdGreaterThan(String value) { + addCriterion("test_id >", value, "testId"); + return (Criteria) this; + } + + public Criteria andTestIdGreaterThanOrEqualTo(String value) { + addCriterion("test_id >=", value, "testId"); + return (Criteria) this; + } + + public Criteria andTestIdLessThan(String value) { + addCriterion("test_id <", value, "testId"); + return (Criteria) this; + } + + public Criteria andTestIdLessThanOrEqualTo(String value) { + addCriterion("test_id <=", value, "testId"); + return (Criteria) this; + } + + public Criteria andTestIdLike(String value) { + addCriterion("test_id like", value, "testId"); + return (Criteria) this; + } + + public Criteria andTestIdNotLike(String value) { + addCriterion("test_id not like", value, "testId"); + return (Criteria) this; + } + + public Criteria andTestIdIn(List values) { + addCriterion("test_id in", values, "testId"); + return (Criteria) this; + } + + public Criteria andTestIdNotIn(List values) { + addCriterion("test_id not in", values, "testId"); + return (Criteria) this; + } + + public Criteria andTestIdBetween(String value1, String value2) { + addCriterion("test_id between", value1, value2, "testId"); + return (Criteria) this; + } + + public Criteria andTestIdNotBetween(String value1, String value2) { + addCriterion("test_id not between", value1, value2, "testId"); + return (Criteria) this; + } + + public Criteria andFileIdIsNull() { + addCriterion("file_id is null"); + return (Criteria) this; + } + + public Criteria andFileIdIsNotNull() { + addCriterion("file_id is not null"); + return (Criteria) this; + } + + public Criteria andFileIdEqualTo(String value) { + addCriterion("file_id =", value, "fileId"); + return (Criteria) this; + } + + public Criteria andFileIdNotEqualTo(String value) { + addCriterion("file_id <>", value, "fileId"); + return (Criteria) this; + } + + public Criteria andFileIdGreaterThan(String value) { + addCriterion("file_id >", value, "fileId"); + return (Criteria) this; + } + + public Criteria andFileIdGreaterThanOrEqualTo(String value) { + addCriterion("file_id >=", value, "fileId"); + return (Criteria) this; + } + + public Criteria andFileIdLessThan(String value) { + addCriterion("file_id <", value, "fileId"); + return (Criteria) this; + } + + public Criteria andFileIdLessThanOrEqualTo(String value) { + addCriterion("file_id <=", value, "fileId"); + return (Criteria) this; + } + + public Criteria andFileIdLike(String value) { + addCriterion("file_id like", value, "fileId"); + return (Criteria) this; + } + + public Criteria andFileIdNotLike(String value) { + addCriterion("file_id not like", value, "fileId"); + return (Criteria) this; + } + + public Criteria andFileIdIn(List values) { + addCriterion("file_id in", values, "fileId"); + return (Criteria) this; + } + + public Criteria andFileIdNotIn(List values) { + addCriterion("file_id not in", values, "fileId"); + return (Criteria) this; + } + + public Criteria andFileIdBetween(String value1, String value2) { + addCriterion("file_id between", value1, value2, "fileId"); + return (Criteria) this; + } + + public Criteria andFileIdNotBetween(String value1, String value2) { + addCriterion("file_id not between", value1, value2, "fileId"); + return (Criteria) this; + } + + public Criteria andFileTypeIsNull() { + addCriterion("file_type is null"); + return (Criteria) this; + } + + public Criteria andFileTypeIsNotNull() { + addCriterion("file_type is not null"); + return (Criteria) this; + } + + public Criteria andFileTypeEqualTo(String value) { + addCriterion("file_type =", value, "fileType"); + return (Criteria) this; + } + + public Criteria andFileTypeNotEqualTo(String value) { + addCriterion("file_type <>", value, "fileType"); + return (Criteria) this; + } + + public Criteria andFileTypeGreaterThan(String value) { + addCriterion("file_type >", value, "fileType"); + return (Criteria) this; + } + + public Criteria andFileTypeGreaterThanOrEqualTo(String value) { + addCriterion("file_type >=", value, "fileType"); + return (Criteria) this; + } + + public Criteria andFileTypeLessThan(String value) { + addCriterion("file_type <", value, "fileType"); + return (Criteria) this; + } + + public Criteria andFileTypeLessThanOrEqualTo(String value) { + addCriterion("file_type <=", value, "fileType"); + return (Criteria) this; + } + + public Criteria andFileTypeLike(String value) { + addCriterion("file_type like", value, "fileType"); + return (Criteria) this; + } + + public Criteria andFileTypeNotLike(String value) { + addCriterion("file_type not like", value, "fileType"); + return (Criteria) this; + } + + public Criteria andFileTypeIn(List values) { + addCriterion("file_type in", values, "fileType"); + return (Criteria) this; + } + + public Criteria andFileTypeNotIn(List values) { + addCriterion("file_type not in", values, "fileType"); + return (Criteria) this; + } + + public Criteria andFileTypeBetween(String value1, String value2) { + addCriterion("file_type between", value1, value2, "fileType"); + return (Criteria) this; + } + + public Criteria andFileTypeNotBetween(String value1, String value2) { + addCriterion("file_type not between", value1, value2, "fileType"); + return (Criteria) this; + } + } + + public static class Criteria extends GeneratedCriteria { + + protected Criteria() { + super(); + } + } + + public static class Criterion { + private String condition; + + private Object value; + + private Object secondValue; + + private boolean noValue; + + private boolean singleValue; + + private boolean betweenValue; + + private boolean listValue; + + private String typeHandler; + + public String getCondition() { + return condition; + } + + public Object getValue() { + return value; + } + + public Object getSecondValue() { + return secondValue; + } + + public boolean isNoValue() { + return noValue; + } + + public boolean isSingleValue() { + return singleValue; + } + + public boolean isBetweenValue() { + return betweenValue; + } + + public boolean isListValue() { + return listValue; + } + + public String getTypeHandler() { + return typeHandler; + } + + protected Criterion(String condition) { + super(); + this.condition = condition; + this.typeHandler = null; + this.noValue = true; + } + + protected Criterion(String condition, Object value, String typeHandler) { + super(); + this.condition = condition; + this.value = value; + this.typeHandler = typeHandler; + if (value instanceof List) { + this.listValue = true; + } else { + this.singleValue = true; + } + } + + protected Criterion(String condition, Object value) { + this(condition, value, null); + } + + protected Criterion(String condition, Object value, Object secondValue, String typeHandler) { + super(); + this.condition = condition; + this.value = value; + this.secondValue = secondValue; + this.typeHandler = typeHandler; + this.betweenValue = true; + } + + protected Criterion(String condition, Object value, Object secondValue) { + this(condition, value, secondValue, null); + } + } +} \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/mapper/FileStoreMapper.java b/backend/src/main/java/io/metersphere/base/mapper/FileStoreMapper.java index e3dd3e5e8d..9ef1b79255 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/FileStoreMapper.java +++ b/backend/src/main/java/io/metersphere/base/mapper/FileStoreMapper.java @@ -2,9 +2,8 @@ package io.metersphere.base.mapper; import io.metersphere.base.domain.FileStore; import io.metersphere.base.domain.FileStoreExample; -import org.apache.ibatis.annotations.Param; - import java.util.List; +import org.apache.ibatis.annotations.Param; public interface FileStoreMapper { long countByExample(FileStoreExample example); diff --git a/backend/src/main/java/io/metersphere/base/mapper/FileStoreMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/FileStoreMapper.xml index ae7841775d..7b6692154d 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/FileStoreMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/FileStoreMapper.xml @@ -11,7 +11,7 @@ - + @@ -131,7 +131,7 @@ update_time, file) values (#{id,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{description,jdbcType=VARCHAR}, #{type,jdbcType=VARCHAR}, #{size,jdbcType=BIGINT}, #{createTime,jdbcType=BIGINT}, - #{updateTime,jdbcType=BIGINT}, #{file,jdbcType=LONGVARBINARY}) + #{updateTime,jdbcType=BIGINT}, #{file,jdbcType=LONGVARCHAR}) insert into file_store @@ -184,7 +184,7 @@ #{updateTime,jdbcType=BIGINT}, - #{file,jdbcType=LONGVARBINARY}, + #{file,jdbcType=LONGVARCHAR}, @@ -219,7 +219,7 @@ update_time = #{record.updateTime,jdbcType=BIGINT}, - file = #{record.file,jdbcType=LONGVARBINARY}, + file = #{record.file,jdbcType=LONGVARCHAR}, @@ -235,7 +235,7 @@ size = #{record.size,jdbcType=BIGINT}, create_time = #{record.createTime,jdbcType=BIGINT}, update_time = #{record.updateTime,jdbcType=BIGINT}, - file = #{record.file,jdbcType=LONGVARBINARY} + file = #{record.file,jdbcType=LONGVARCHAR} @@ -275,7 +275,7 @@ update_time = #{updateTime,jdbcType=BIGINT}, - file = #{file,jdbcType=LONGVARBINARY}, + file = #{file,jdbcType=LONGVARCHAR}, where id = #{id,jdbcType=VARCHAR} @@ -288,7 +288,7 @@ size = #{size,jdbcType=BIGINT}, create_time = #{createTime,jdbcType=BIGINT}, update_time = #{updateTime,jdbcType=BIGINT}, - file = #{file,jdbcType=LONGVARBINARY} + file = #{file,jdbcType=LONGVARCHAR} where id = #{id,jdbcType=VARCHAR} diff --git a/backend/src/main/java/io/metersphere/base/mapper/FileStoreResourceMapper.java b/backend/src/main/java/io/metersphere/base/mapper/FileStoreResourceMapper.java new file mode 100644 index 0000000000..dce429b1cf --- /dev/null +++ b/backend/src/main/java/io/metersphere/base/mapper/FileStoreResourceMapper.java @@ -0,0 +1,22 @@ +package io.metersphere.base.mapper; + +import io.metersphere.base.domain.FileStoreResource; +import io.metersphere.base.domain.FileStoreResourceExample; +import java.util.List; +import org.apache.ibatis.annotations.Param; + +public interface FileStoreResourceMapper { + long countByExample(FileStoreResourceExample example); + + int deleteByExample(FileStoreResourceExample example); + + int insert(FileStoreResource record); + + int insertSelective(FileStoreResource record); + + List selectByExample(FileStoreResourceExample example); + + int updateByExampleSelective(@Param("record") FileStoreResource record, @Param("example") FileStoreResourceExample example); + + int updateByExample(@Param("record") FileStoreResource record, @Param("example") FileStoreResourceExample example); +} \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/mapper/FileStoreResourceMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/FileStoreResourceMapper.xml new file mode 100644 index 0000000000..ae1f7646e0 --- /dev/null +++ b/backend/src/main/java/io/metersphere/base/mapper/FileStoreResourceMapper.xml @@ -0,0 +1,153 @@ + + + + + + + + + + + + + + + + + and ${criterion.condition} + + + and ${criterion.condition} #{criterion.value} + + + and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} + + + and ${criterion.condition} + + #{listItem} + + + + + + + + + + + + + + + + + + and ${criterion.condition} + + + and ${criterion.condition} #{criterion.value} + + + and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} + + + and ${criterion.condition} + + #{listItem} + + + + + + + + + + + test_id, file_id, file_type + + + + delete from file_store_resource + + + + + + insert into file_store_resource (test_id, file_id, file_type + ) + values (#{testId,jdbcType=VARCHAR}, #{fileId,jdbcType=VARCHAR}, #{fileType,jdbcType=VARCHAR} + ) + + + insert into file_store_resource + + + test_id, + + + file_id, + + + file_type, + + + + + #{testId,jdbcType=VARCHAR}, + + + #{fileId,jdbcType=VARCHAR}, + + + #{fileType,jdbcType=VARCHAR}, + + + + + + update file_store_resource + + + test_id = #{record.testId,jdbcType=VARCHAR}, + + + file_id = #{record.fileId,jdbcType=VARCHAR}, + + + file_type = #{record.fileType,jdbcType=VARCHAR}, + + + + + + + + update file_store_resource + set test_id = #{record.testId,jdbcType=VARCHAR}, + file_id = #{record.fileId,jdbcType=VARCHAR}, + file_type = #{record.fileType,jdbcType=VARCHAR} + + + + + \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/mapper/LoadTestMapper.java b/backend/src/main/java/io/metersphere/base/mapper/LoadTestMapper.java index dd0fb24910..f0c40abcf7 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/LoadTestMapper.java +++ b/backend/src/main/java/io/metersphere/base/mapper/LoadTestMapper.java @@ -3,9 +3,8 @@ package io.metersphere.base.mapper; import io.metersphere.base.domain.LoadTest; import io.metersphere.base.domain.LoadTestExample; import io.metersphere.base.domain.LoadTestWithBLOBs; -import org.apache.ibatis.annotations.Param; - import java.util.List; +import org.apache.ibatis.annotations.Param; public interface LoadTestMapper { long countByExample(LoadTestExample example); diff --git a/backend/src/main/java/io/metersphere/base/mapper/LoadTestReportMapper.java b/backend/src/main/java/io/metersphere/base/mapper/LoadTestReportMapper.java index 52458face4..0c58b41594 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/LoadTestReportMapper.java +++ b/backend/src/main/java/io/metersphere/base/mapper/LoadTestReportMapper.java @@ -2,9 +2,8 @@ package io.metersphere.base.mapper; import io.metersphere.base.domain.LoadTestReport; import io.metersphere.base.domain.LoadTestReportExample; -import org.apache.ibatis.annotations.Param; - import java.util.List; +import org.apache.ibatis.annotations.Param; public interface LoadTestReportMapper { long countByExample(LoadTestReportExample example); diff --git a/backend/src/main/java/io/metersphere/base/mapper/OrganizationMapper.java b/backend/src/main/java/io/metersphere/base/mapper/OrganizationMapper.java index 553bee1eaf..4d52328fa4 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/OrganizationMapper.java +++ b/backend/src/main/java/io/metersphere/base/mapper/OrganizationMapper.java @@ -2,9 +2,8 @@ package io.metersphere.base.mapper; import io.metersphere.base.domain.Organization; import io.metersphere.base.domain.OrganizationExample; -import org.apache.ibatis.annotations.Param; - import java.util.List; +import org.apache.ibatis.annotations.Param; public interface OrganizationMapper { long countByExample(OrganizationExample example); diff --git a/backend/src/main/java/io/metersphere/base/mapper/ProjectMapper.java b/backend/src/main/java/io/metersphere/base/mapper/ProjectMapper.java index fe7e62f2a6..fa96414ac9 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ProjectMapper.java +++ b/backend/src/main/java/io/metersphere/base/mapper/ProjectMapper.java @@ -2,9 +2,8 @@ package io.metersphere.base.mapper; import io.metersphere.base.domain.Project; import io.metersphere.base.domain.ProjectExample; -import org.apache.ibatis.annotations.Param; - import java.util.List; +import org.apache.ibatis.annotations.Param; public interface ProjectMapper { long countByExample(ProjectExample example); diff --git a/backend/src/main/java/io/metersphere/base/mapper/RoleMapper.java b/backend/src/main/java/io/metersphere/base/mapper/RoleMapper.java index 9867744784..bad3f29cb3 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/RoleMapper.java +++ b/backend/src/main/java/io/metersphere/base/mapper/RoleMapper.java @@ -2,9 +2,8 @@ package io.metersphere.base.mapper; import io.metersphere.base.domain.Role; import io.metersphere.base.domain.RoleExample; -import org.apache.ibatis.annotations.Param; - import java.util.List; +import org.apache.ibatis.annotations.Param; public interface RoleMapper { long countByExample(RoleExample example); diff --git a/backend/src/main/java/io/metersphere/base/mapper/SystemParameterMapper.java b/backend/src/main/java/io/metersphere/base/mapper/SystemParameterMapper.java index a28e33b549..24fb5ad968 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/SystemParameterMapper.java +++ b/backend/src/main/java/io/metersphere/base/mapper/SystemParameterMapper.java @@ -2,9 +2,8 @@ package io.metersphere.base.mapper; import io.metersphere.base.domain.SystemParameter; import io.metersphere.base.domain.SystemParameterExample; -import org.apache.ibatis.annotations.Param; - import java.util.List; +import org.apache.ibatis.annotations.Param; public interface SystemParameterMapper { long countByExample(SystemParameterExample example); diff --git a/backend/src/main/java/io/metersphere/base/mapper/TestResourceMapper.java b/backend/src/main/java/io/metersphere/base/mapper/TestResourceMapper.java index d9cdba0348..b9fa00aa1f 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/TestResourceMapper.java +++ b/backend/src/main/java/io/metersphere/base/mapper/TestResourceMapper.java @@ -2,9 +2,8 @@ package io.metersphere.base.mapper; import io.metersphere.base.domain.TestResource; import io.metersphere.base.domain.TestResourceExample; -import org.apache.ibatis.annotations.Param; - import java.util.List; +import org.apache.ibatis.annotations.Param; public interface TestResourceMapper { long countByExample(TestResourceExample example); diff --git a/backend/src/main/java/io/metersphere/base/mapper/TestResourcePoolMapper.java b/backend/src/main/java/io/metersphere/base/mapper/TestResourcePoolMapper.java index 341047fce0..eed05f4b3f 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/TestResourcePoolMapper.java +++ b/backend/src/main/java/io/metersphere/base/mapper/TestResourcePoolMapper.java @@ -2,9 +2,8 @@ package io.metersphere.base.mapper; import io.metersphere.base.domain.TestResourcePool; import io.metersphere.base.domain.TestResourcePoolExample; -import org.apache.ibatis.annotations.Param; - import java.util.List; +import org.apache.ibatis.annotations.Param; public interface TestResourcePoolMapper { long countByExample(TestResourcePoolExample example); diff --git a/backend/src/main/java/io/metersphere/base/mapper/WorkspaceMapper.java b/backend/src/main/java/io/metersphere/base/mapper/WorkspaceMapper.java index 7b69985bc4..997beb4fe7 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/WorkspaceMapper.java +++ b/backend/src/main/java/io/metersphere/base/mapper/WorkspaceMapper.java @@ -2,9 +2,8 @@ package io.metersphere.base.mapper; import io.metersphere.base.domain.Workspace; import io.metersphere.base.domain.WorkspaceExample; -import org.apache.ibatis.annotations.Param; - import java.util.List; +import org.apache.ibatis.annotations.Param; public interface WorkspaceMapper { long countByExample(WorkspaceExample example); diff --git a/backend/src/main/java/io/metersphere/commons/constants/LoadTestFileType.java b/backend/src/main/java/io/metersphere/commons/constants/LoadTestFileType.java new file mode 100644 index 0000000000..ffdce75b98 --- /dev/null +++ b/backend/src/main/java/io/metersphere/commons/constants/LoadTestFileType.java @@ -0,0 +1,5 @@ +package io.metersphere.commons.constants; + +public enum LoadTestFileType { + JMX +} diff --git a/backend/src/main/java/io/metersphere/commons/utils/IOUtils.java b/backend/src/main/java/io/metersphere/commons/utils/IOUtils.java new file mode 100644 index 0000000000..55cba0deb9 --- /dev/null +++ b/backend/src/main/java/io/metersphere/commons/utils/IOUtils.java @@ -0,0 +1,23 @@ +package io.metersphere.commons.utils; + +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.nio.charset.Charset; + +public class IOUtils { + public static String toString(InputStream inputStream, Charset charset) throws IOException { + final int bufferSize = 1024; + final char[] buffer = new char[bufferSize]; + final StringBuilder out = new StringBuilder(); + Reader in = new InputStreamReader(inputStream, charset); + + int charsRead; + while ((charsRead = in.read(buffer, 0, buffer.length)) > 0) { + out.append(buffer, 0, charsRead); + } + + return out.toString(); + } +} diff --git a/backend/src/main/java/io/metersphere/controller/LoadTestController.java b/backend/src/main/java/io/metersphere/controller/LoadTestController.java index ff11ad4ce0..7c1c4904f3 100644 --- a/backend/src/main/java/io/metersphere/controller/LoadTestController.java +++ b/backend/src/main/java/io/metersphere/controller/LoadTestController.java @@ -36,9 +36,12 @@ public class LoadTestController { return PageUtils.setPageInfo(page, loadTestService.list(request)); } - @PostMapping("/save") - public void save(@RequestBody SaveTestPlanRequest request) { - loadTestService.save(request); + @PostMapping(value = "/save", consumes = {"multipart/form-data"}) + public void save( + @RequestPart("request") SaveTestPlanRequest request, + @RequestPart("file") MultipartFile file + ) { + loadTestService.save(request, file); } @PostMapping("/delete") diff --git a/backend/src/main/java/io/metersphere/service/LoadTestService.java b/backend/src/main/java/io/metersphere/service/LoadTestService.java index 16ed409974..99f5a36153 100644 --- a/backend/src/main/java/io/metersphere/service/LoadTestService.java +++ b/backend/src/main/java/io/metersphere/service/LoadTestService.java @@ -1,10 +1,14 @@ package io.metersphere.service; import io.metersphere.base.domain.*; +import io.metersphere.base.mapper.FileStoreMapper; +import io.metersphere.base.mapper.FileStoreResourceMapper; import io.metersphere.base.mapper.LoadTestMapper; -import io.metersphere.base.mapper.OrganizationMapper; import io.metersphere.base.mapper.ProjectMapper; import io.metersphere.base.mapper.ext.ExtLoadTestMapper; +import io.metersphere.commons.constants.LoadTestFileType; +import io.metersphere.commons.exception.MSException; +import io.metersphere.commons.utils.IOUtils; import io.metersphere.controller.request.testplan.DeleteTestPlanRequest; import io.metersphere.controller.request.testplan.QueryTestPlanRequest; import io.metersphere.controller.request.testplan.SaveTestPlanRequest; @@ -13,11 +17,13 @@ import org.apache.commons.lang3.RandomUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; +import org.springframework.web.multipart.MultipartFile; import javax.annotation.PostConstruct; import javax.annotation.Resource; +import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.util.List; -import java.util.Random; import java.util.UUID; @Service @@ -29,6 +35,10 @@ public class LoadTestService { private ExtLoadTestMapper extLoadTestMapper; @Resource private ProjectMapper projectMapper; + @Resource + private FileStoreMapper fileStoreMapper; + @Resource + private FileStoreResourceMapper fileStoreResourceMapper; // 测试,模拟数据 @PostConstruct @@ -63,7 +73,23 @@ public class LoadTestService { loadTestMapper.deleteByExample(loadTestExample); } - public void save(SaveTestPlanRequest request) { + public void save(SaveTestPlanRequest request, MultipartFile file) { + if (file == null) { + throw new IllegalArgumentException("文件不能为空!"); + } + + final FileStore fileStore = saveFileStore(file); + + final LoadTestWithBLOBs loadTest = saveLoadTest(request); + + FileStoreResource fileStoreResource = new FileStoreResource(); + fileStoreResource.setTestId(loadTest.getId()); + fileStoreResource.setFileId(fileStore.getId()); + fileStoreResource.setFileType(fileStore.getType()); + fileStoreResourceMapper.insert(fileStoreResource); + } + + private LoadTestWithBLOBs saveLoadTest(SaveTestPlanRequest request) { final LoadTestWithBLOBs loadTest = new LoadTestWithBLOBs(); loadTest.setId(UUID.randomUUID().toString()); loadTest.setName(request.getName()); @@ -73,5 +99,23 @@ public class LoadTestService { loadTest.setScenarioDefinition("todo"); loadTest.setDescription("todo"); loadTestMapper.insert(loadTest); + return loadTest; + } + + private FileStore saveFileStore(MultipartFile file) { + final FileStore fileStore = new FileStore(); + fileStore.setId(UUID.randomUUID().toString()); + fileStore.setName(file.getOriginalFilename()); + fileStore.setSize(file.getSize()); + fileStore.setCreateTime(System.currentTimeMillis()); + fileStore.setUpdateTime(System.currentTimeMillis()); + fileStore.setType(LoadTestFileType.JMX.name()); + try { + fileStore.setFile(IOUtils.toString(file.getInputStream(), StandardCharsets.UTF_8)); + } catch (IOException e) { + MSException.throwException(e); + } + fileStoreMapper.insert(fileStore); + return fileStore; } } diff --git a/backend/src/main/resources/generatorConfig.xml b/backend/src/main/resources/generatorConfig.xml index 1e65d68aa5..16f1f93000 100644 --- a/backend/src/main/resources/generatorConfig.xml +++ b/backend/src/main/resources/generatorConfig.xml @@ -57,5 +57,6 @@
+
\ No newline at end of file diff --git a/frontend/src/common/ajax.js b/frontend/src/common/ajax.js index 270bd88c13..4ebb7bfae8 100644 --- a/frontend/src/common/ajax.js +++ b/frontend/src/common/ajax.js @@ -74,6 +74,27 @@ export default { } }; + Vue.prototype.$request = function (axiosRequestConfig, success) { + if (!success) { + return axios.request(axiosRequestConfig); + } else { + axios.request(axiosRequestConfig).then(response => { + if (!response.data) { + return success(response); + } + if (response.data.success) { + return success(response.data); + } else { + window.console.warn(response.data); + Message.warning(response.data.message); + } + }).catch(error => { + window.console.error(error.response || error.message); + Message.error({message: error.message, showClose: true}); + }) + } + }; + Vue.prototype.$all = function (array, callback) { if (array.length < 1) return; axios.all(array).then(axios.spread(callback)); diff --git a/frontend/src/performance/components/testPlan/CreateTestPlan.vue b/frontend/src/performance/components/testPlan/CreateTestPlan.vue index 84e6fb7000..a0762166e5 100644 --- a/frontend/src/performance/components/testPlan/CreateTestPlan.vue +++ b/frontend/src/performance/components/testPlan/CreateTestPlan.vue @@ -86,15 +86,31 @@ return; } - this.$post(this.savePath, this.testPlan).then(response => { + let formData = new FormData(); + + formData.append("file", this.testPlan.file); + // file属性不需要json化 + let requestJson = JSON.stringify(this.testPlan, function (key, value) {return key === "file" ? undefined : value}); + formData.append('request', new Blob([requestJson], { + type: "application/json" + })); + + let options = { + method: 'POST', + url: this.savePath, + data: formData, + headers: { + 'Content-Type': undefined + } + }; + + this.$request(options).then(response => { if (response) { this.$message({ message: '保存成功!', type: 'success' }); } - }).catch((response) => { - this.$message.error(response.message); }); }, saveAndRun() { @@ -134,7 +150,7 @@ return false; } - if (!this.testPlan.fileId) { + if (!this.testPlan.file) { this.$message({ message: 'jmx文件不能为空!', type: 'error' diff --git a/frontend/src/performance/components/testPlan/components/BasicConfig.vue b/frontend/src/performance/components/testPlan/components/BasicConfig.vue index 33a7b41c1c..8bae8d26d6 100644 --- a/frontend/src/performance/components/testPlan/components/BasicConfig.vue +++ b/frontend/src/performance/components/testPlan/components/BasicConfig.vue @@ -7,6 +7,7 @@ :show-file-list="false" :action="jmxUploadPath" :before-upload="beforeUpload" + :http-request="handleUpload" :file-list="fileList">
将文件拖到此处,或点击上传
@@ -64,13 +65,6 @@ }, methods: { beforeUpload(file) { - window.console.log(file); - - /// todo: 上传的文件需要绑定到当前testPlan,这里暂时使用文件名 - this._changeTestPlan(function (testPlan) { - testPlan.fileId = file.name; - }); - if (!this.fileValidator(file)) { /// todo: 显示错误信息 return false; @@ -86,6 +80,13 @@ return true; }, + handleUpload(uploadResources) { + window.console.log(uploadResources); + + this._changeTestPlan(function (testPlan) { + testPlan.file = uploadResources.file; + }); + }, handleDownload(file) { let data = { name: file.name