上传的文件保存到数据库

This commit is contained in:
haifeng414 2020-02-17 15:00:13 +08:00
parent 1862341e94
commit 54ad67d899
24 changed files with 774 additions and 48 deletions

View File

@ -17,7 +17,7 @@ public class FileStore implements Serializable {
private Long updateTime; private Long updateTime;
private byte[] file; private String file;
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@ -77,11 +77,11 @@ public class FileStore implements Serializable {
this.updateTime = updateTime; this.updateTime = updateTime;
} }
public byte[] getFile() { public String getFile() {
return file; return file;
} }
public void setFile(byte[] file) { public void setFile(String file) {
this.file = file; this.file = file == null ? null : file.trim();
} }
} }

View File

@ -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();
}
}

View File

@ -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<Criteria> oredCriteria;
public FileStoreResourceExample() {
oredCriteria = new ArrayList<Criteria>();
}
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<Criteria> 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<Criterion> criteria;
protected GeneratedCriteria() {
super();
criteria = new ArrayList<Criterion>();
}
public boolean isValid() {
return criteria.size() > 0;
}
public List<Criterion> getAllCriteria() {
return criteria;
}
public List<Criterion> 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<String> values) {
addCriterion("test_id in", values, "testId");
return (Criteria) this;
}
public Criteria andTestIdNotIn(List<String> 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<String> values) {
addCriterion("file_id in", values, "fileId");
return (Criteria) this;
}
public Criteria andFileIdNotIn(List<String> 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<String> values) {
addCriterion("file_type in", values, "fileType");
return (Criteria) this;
}
public Criteria andFileTypeNotIn(List<String> 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);
}
}
}

View File

@ -2,9 +2,8 @@ package io.metersphere.base.mapper;
import io.metersphere.base.domain.FileStore; import io.metersphere.base.domain.FileStore;
import io.metersphere.base.domain.FileStoreExample; import io.metersphere.base.domain.FileStoreExample;
import org.apache.ibatis.annotations.Param;
import java.util.List; import java.util.List;
import org.apache.ibatis.annotations.Param;
public interface FileStoreMapper { public interface FileStoreMapper {
long countByExample(FileStoreExample example); long countByExample(FileStoreExample example);

View File

@ -11,7 +11,7 @@
<result column="update_time" jdbcType="BIGINT" property="updateTime" /> <result column="update_time" jdbcType="BIGINT" property="updateTime" />
</resultMap> </resultMap>
<resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="io.metersphere.base.domain.FileStore"> <resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="io.metersphere.base.domain.FileStore">
<result column="file" jdbcType="LONGVARBINARY" property="file" /> <result column="file" jdbcType="LONGVARCHAR" property="file" />
</resultMap> </resultMap>
<sql id="Example_Where_Clause"> <sql id="Example_Where_Clause">
<where> <where>
@ -131,7 +131,7 @@
update_time, file) update_time, file)
values (#{id,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{description,jdbcType=VARCHAR}, values (#{id,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{description,jdbcType=VARCHAR},
#{type,jdbcType=VARCHAR}, #{size,jdbcType=BIGINT}, #{createTime,jdbcType=BIGINT}, #{type,jdbcType=VARCHAR}, #{size,jdbcType=BIGINT}, #{createTime,jdbcType=BIGINT},
#{updateTime,jdbcType=BIGINT}, #{file,jdbcType=LONGVARBINARY}) #{updateTime,jdbcType=BIGINT}, #{file,jdbcType=LONGVARCHAR})
</insert> </insert>
<insert id="insertSelective" parameterType="io.metersphere.base.domain.FileStore"> <insert id="insertSelective" parameterType="io.metersphere.base.domain.FileStore">
insert into file_store insert into file_store
@ -184,7 +184,7 @@
#{updateTime,jdbcType=BIGINT}, #{updateTime,jdbcType=BIGINT},
</if> </if>
<if test="file != null"> <if test="file != null">
#{file,jdbcType=LONGVARBINARY}, #{file,jdbcType=LONGVARCHAR},
</if> </if>
</trim> </trim>
</insert> </insert>
@ -219,7 +219,7 @@
update_time = #{record.updateTime,jdbcType=BIGINT}, update_time = #{record.updateTime,jdbcType=BIGINT},
</if> </if>
<if test="record.file != null"> <if test="record.file != null">
file = #{record.file,jdbcType=LONGVARBINARY}, file = #{record.file,jdbcType=LONGVARCHAR},
</if> </if>
</set> </set>
<if test="_parameter != null"> <if test="_parameter != null">
@ -235,7 +235,7 @@
size = #{record.size,jdbcType=BIGINT}, size = #{record.size,jdbcType=BIGINT},
create_time = #{record.createTime,jdbcType=BIGINT}, create_time = #{record.createTime,jdbcType=BIGINT},
update_time = #{record.updateTime,jdbcType=BIGINT}, update_time = #{record.updateTime,jdbcType=BIGINT},
file = #{record.file,jdbcType=LONGVARBINARY} file = #{record.file,jdbcType=LONGVARCHAR}
<if test="_parameter != null"> <if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" /> <include refid="Update_By_Example_Where_Clause" />
</if> </if>
@ -275,7 +275,7 @@
update_time = #{updateTime,jdbcType=BIGINT}, update_time = #{updateTime,jdbcType=BIGINT},
</if> </if>
<if test="file != null"> <if test="file != null">
file = #{file,jdbcType=LONGVARBINARY}, file = #{file,jdbcType=LONGVARCHAR},
</if> </if>
</set> </set>
where id = #{id,jdbcType=VARCHAR} where id = #{id,jdbcType=VARCHAR}
@ -288,7 +288,7 @@
size = #{size,jdbcType=BIGINT}, size = #{size,jdbcType=BIGINT},
create_time = #{createTime,jdbcType=BIGINT}, create_time = #{createTime,jdbcType=BIGINT},
update_time = #{updateTime,jdbcType=BIGINT}, update_time = #{updateTime,jdbcType=BIGINT},
file = #{file,jdbcType=LONGVARBINARY} file = #{file,jdbcType=LONGVARCHAR}
where id = #{id,jdbcType=VARCHAR} where id = #{id,jdbcType=VARCHAR}
</update> </update>
<update id="updateByPrimaryKey" parameterType="io.metersphere.base.domain.FileStore"> <update id="updateByPrimaryKey" parameterType="io.metersphere.base.domain.FileStore">

View File

@ -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<FileStoreResource> selectByExample(FileStoreResourceExample example);
int updateByExampleSelective(@Param("record") FileStoreResource record, @Param("example") FileStoreResourceExample example);
int updateByExample(@Param("record") FileStoreResource record, @Param("example") FileStoreResourceExample example);
}

View File

@ -0,0 +1,153 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="io.metersphere.base.mapper.FileStoreResourceMapper">
<resultMap id="BaseResultMap" type="io.metersphere.base.domain.FileStoreResource">
<result column="test_id" jdbcType="VARCHAR" property="testId" />
<result column="file_id" jdbcType="VARCHAR" property="fileId" />
<result column="file_type" jdbcType="VARCHAR" property="fileType" />
</resultMap>
<sql id="Example_Where_Clause">
<where>
<foreach collection="oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Update_By_Example_Where_Clause">
<where>
<foreach collection="example.oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Base_Column_List">
test_id, file_id, file_type
</sql>
<select id="selectByExample" parameterType="io.metersphere.base.domain.FileStoreResourceExample" resultMap="BaseResultMap">
select
<if test="distinct">
distinct
</if>
<include refid="Base_Column_List" />
from file_store_resource
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
<if test="orderByClause != null">
order by ${orderByClause}
</if>
</select>
<delete id="deleteByExample" parameterType="io.metersphere.base.domain.FileStoreResourceExample">
delete from file_store_resource
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
</delete>
<insert id="insert" parameterType="io.metersphere.base.domain.FileStoreResource">
insert into file_store_resource (test_id, file_id, file_type
)
values (#{testId,jdbcType=VARCHAR}, #{fileId,jdbcType=VARCHAR}, #{fileType,jdbcType=VARCHAR}
)
</insert>
<insert id="insertSelective" parameterType="io.metersphere.base.domain.FileStoreResource">
insert into file_store_resource
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="testId != null">
test_id,
</if>
<if test="fileId != null">
file_id,
</if>
<if test="fileType != null">
file_type,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="testId != null">
#{testId,jdbcType=VARCHAR},
</if>
<if test="fileId != null">
#{fileId,jdbcType=VARCHAR},
</if>
<if test="fileType != null">
#{fileType,jdbcType=VARCHAR},
</if>
</trim>
</insert>
<select id="countByExample" parameterType="io.metersphere.base.domain.FileStoreResourceExample" resultType="java.lang.Long">
select count(*) from file_store_resource
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
</select>
<update id="updateByExampleSelective" parameterType="map">
update file_store_resource
<set>
<if test="record.testId != null">
test_id = #{record.testId,jdbcType=VARCHAR},
</if>
<if test="record.fileId != null">
file_id = #{record.fileId,jdbcType=VARCHAR},
</if>
<if test="record.fileType != null">
file_type = #{record.fileType,jdbcType=VARCHAR},
</if>
</set>
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByExample" parameterType="map">
update file_store_resource
set test_id = #{record.testId,jdbcType=VARCHAR},
file_id = #{record.fileId,jdbcType=VARCHAR},
file_type = #{record.fileType,jdbcType=VARCHAR}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
</mapper>

View File

@ -3,9 +3,8 @@ package io.metersphere.base.mapper;
import io.metersphere.base.domain.LoadTest; import io.metersphere.base.domain.LoadTest;
import io.metersphere.base.domain.LoadTestExample; import io.metersphere.base.domain.LoadTestExample;
import io.metersphere.base.domain.LoadTestWithBLOBs; import io.metersphere.base.domain.LoadTestWithBLOBs;
import org.apache.ibatis.annotations.Param;
import java.util.List; import java.util.List;
import org.apache.ibatis.annotations.Param;
public interface LoadTestMapper { public interface LoadTestMapper {
long countByExample(LoadTestExample example); long countByExample(LoadTestExample example);

View File

@ -2,9 +2,8 @@ package io.metersphere.base.mapper;
import io.metersphere.base.domain.LoadTestReport; import io.metersphere.base.domain.LoadTestReport;
import io.metersphere.base.domain.LoadTestReportExample; import io.metersphere.base.domain.LoadTestReportExample;
import org.apache.ibatis.annotations.Param;
import java.util.List; import java.util.List;
import org.apache.ibatis.annotations.Param;
public interface LoadTestReportMapper { public interface LoadTestReportMapper {
long countByExample(LoadTestReportExample example); long countByExample(LoadTestReportExample example);

View File

@ -2,9 +2,8 @@ package io.metersphere.base.mapper;
import io.metersphere.base.domain.Organization; import io.metersphere.base.domain.Organization;
import io.metersphere.base.domain.OrganizationExample; import io.metersphere.base.domain.OrganizationExample;
import org.apache.ibatis.annotations.Param;
import java.util.List; import java.util.List;
import org.apache.ibatis.annotations.Param;
public interface OrganizationMapper { public interface OrganizationMapper {
long countByExample(OrganizationExample example); long countByExample(OrganizationExample example);

View File

@ -2,9 +2,8 @@ package io.metersphere.base.mapper;
import io.metersphere.base.domain.Project; import io.metersphere.base.domain.Project;
import io.metersphere.base.domain.ProjectExample; import io.metersphere.base.domain.ProjectExample;
import org.apache.ibatis.annotations.Param;
import java.util.List; import java.util.List;
import org.apache.ibatis.annotations.Param;
public interface ProjectMapper { public interface ProjectMapper {
long countByExample(ProjectExample example); long countByExample(ProjectExample example);

View File

@ -2,9 +2,8 @@ package io.metersphere.base.mapper;
import io.metersphere.base.domain.Role; import io.metersphere.base.domain.Role;
import io.metersphere.base.domain.RoleExample; import io.metersphere.base.domain.RoleExample;
import org.apache.ibatis.annotations.Param;
import java.util.List; import java.util.List;
import org.apache.ibatis.annotations.Param;
public interface RoleMapper { public interface RoleMapper {
long countByExample(RoleExample example); long countByExample(RoleExample example);

View File

@ -2,9 +2,8 @@ package io.metersphere.base.mapper;
import io.metersphere.base.domain.SystemParameter; import io.metersphere.base.domain.SystemParameter;
import io.metersphere.base.domain.SystemParameterExample; import io.metersphere.base.domain.SystemParameterExample;
import org.apache.ibatis.annotations.Param;
import java.util.List; import java.util.List;
import org.apache.ibatis.annotations.Param;
public interface SystemParameterMapper { public interface SystemParameterMapper {
long countByExample(SystemParameterExample example); long countByExample(SystemParameterExample example);

View File

@ -2,9 +2,8 @@ package io.metersphere.base.mapper;
import io.metersphere.base.domain.TestResource; import io.metersphere.base.domain.TestResource;
import io.metersphere.base.domain.TestResourceExample; import io.metersphere.base.domain.TestResourceExample;
import org.apache.ibatis.annotations.Param;
import java.util.List; import java.util.List;
import org.apache.ibatis.annotations.Param;
public interface TestResourceMapper { public interface TestResourceMapper {
long countByExample(TestResourceExample example); long countByExample(TestResourceExample example);

View File

@ -2,9 +2,8 @@ package io.metersphere.base.mapper;
import io.metersphere.base.domain.TestResourcePool; import io.metersphere.base.domain.TestResourcePool;
import io.metersphere.base.domain.TestResourcePoolExample; import io.metersphere.base.domain.TestResourcePoolExample;
import org.apache.ibatis.annotations.Param;
import java.util.List; import java.util.List;
import org.apache.ibatis.annotations.Param;
public interface TestResourcePoolMapper { public interface TestResourcePoolMapper {
long countByExample(TestResourcePoolExample example); long countByExample(TestResourcePoolExample example);

View File

@ -2,9 +2,8 @@ package io.metersphere.base.mapper;
import io.metersphere.base.domain.Workspace; import io.metersphere.base.domain.Workspace;
import io.metersphere.base.domain.WorkspaceExample; import io.metersphere.base.domain.WorkspaceExample;
import org.apache.ibatis.annotations.Param;
import java.util.List; import java.util.List;
import org.apache.ibatis.annotations.Param;
public interface WorkspaceMapper { public interface WorkspaceMapper {
long countByExample(WorkspaceExample example); long countByExample(WorkspaceExample example);

View File

@ -0,0 +1,5 @@
package io.metersphere.commons.constants;
public enum LoadTestFileType {
JMX
}

View File

@ -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();
}
}

View File

@ -36,9 +36,12 @@ public class LoadTestController {
return PageUtils.setPageInfo(page, loadTestService.list(request)); return PageUtils.setPageInfo(page, loadTestService.list(request));
} }
@PostMapping("/save") @PostMapping(value = "/save", consumes = {"multipart/form-data"})
public void save(@RequestBody SaveTestPlanRequest request) { public void save(
loadTestService.save(request); @RequestPart("request") SaveTestPlanRequest request,
@RequestPart("file") MultipartFile file
) {
loadTestService.save(request, file);
} }
@PostMapping("/delete") @PostMapping("/delete")

View File

@ -1,10 +1,14 @@
package io.metersphere.service; package io.metersphere.service;
import io.metersphere.base.domain.*; 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.LoadTestMapper;
import io.metersphere.base.mapper.OrganizationMapper;
import io.metersphere.base.mapper.ProjectMapper; import io.metersphere.base.mapper.ProjectMapper;
import io.metersphere.base.mapper.ext.ExtLoadTestMapper; 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.DeleteTestPlanRequest;
import io.metersphere.controller.request.testplan.QueryTestPlanRequest; import io.metersphere.controller.request.testplan.QueryTestPlanRequest;
import io.metersphere.controller.request.testplan.SaveTestPlanRequest; 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.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.List; import java.util.List;
import java.util.Random;
import java.util.UUID; import java.util.UUID;
@Service @Service
@ -29,6 +35,10 @@ public class LoadTestService {
private ExtLoadTestMapper extLoadTestMapper; private ExtLoadTestMapper extLoadTestMapper;
@Resource @Resource
private ProjectMapper projectMapper; private ProjectMapper projectMapper;
@Resource
private FileStoreMapper fileStoreMapper;
@Resource
private FileStoreResourceMapper fileStoreResourceMapper;
// 测试模拟数据 // 测试模拟数据
@PostConstruct @PostConstruct
@ -63,7 +73,23 @@ public class LoadTestService {
loadTestMapper.deleteByExample(loadTestExample); 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(); final LoadTestWithBLOBs loadTest = new LoadTestWithBLOBs();
loadTest.setId(UUID.randomUUID().toString()); loadTest.setId(UUID.randomUUID().toString());
loadTest.setName(request.getName()); loadTest.setName(request.getName());
@ -73,5 +99,23 @@ public class LoadTestService {
loadTest.setScenarioDefinition("todo"); loadTest.setScenarioDefinition("todo");
loadTest.setDescription("todo"); loadTest.setDescription("todo");
loadTestMapper.insert(loadTest); 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;
} }
} }

View File

@ -57,5 +57,6 @@
<table tableName="load_test_report"/> <table tableName="load_test_report"/>
<table tableName="load_test"/> <table tableName="load_test"/>
<table tableName="file_store"/> <table tableName="file_store"/>
<table tableName="file_store_resource"/>
</context> </context>
</generatorConfiguration> </generatorConfiguration>

View File

@ -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) { Vue.prototype.$all = function (array, callback) {
if (array.length < 1) return; if (array.length < 1) return;
axios.all(array).then(axios.spread(callback)); axios.all(array).then(axios.spread(callback));

View File

@ -86,15 +86,31 @@
return; return;
} }
this.$post(this.savePath, this.testPlan).then(response => { let formData = new FormData();
formData.append("file", this.testPlan.file);
// filejson
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) { if (response) {
this.$message({ this.$message({
message: '保存成功!', message: '保存成功!',
type: 'success' type: 'success'
}); });
} }
}).catch((response) => {
this.$message.error(response.message);
}); });
}, },
saveAndRun() { saveAndRun() {
@ -134,7 +150,7 @@
return false; return false;
} }
if (!this.testPlan.fileId) { if (!this.testPlan.file) {
this.$message({ this.$message({
message: 'jmx文件不能为空', message: 'jmx文件不能为空',
type: 'error' type: 'error'

View File

@ -7,6 +7,7 @@
:show-file-list="false" :show-file-list="false"
:action="jmxUploadPath" :action="jmxUploadPath"
:before-upload="beforeUpload" :before-upload="beforeUpload"
:http-request="handleUpload"
:file-list="fileList"> :file-list="fileList">
<i class="el-icon-upload"/> <i class="el-icon-upload"/>
<div class="el-upload__text">将文件拖到此处<em>点击上传</em></div> <div class="el-upload__text">将文件拖到此处<em>点击上传</em></div>
@ -64,13 +65,6 @@
}, },
methods: { methods: {
beforeUpload(file) { beforeUpload(file) {
window.console.log(file);
/// todo: testPlan使
this._changeTestPlan(function (testPlan) {
testPlan.fileId = file.name;
});
if (!this.fileValidator(file)) { if (!this.fileValidator(file)) {
/// todo: /// todo:
return false; return false;
@ -86,6 +80,13 @@
return true; return true;
}, },
handleUpload(uploadResources) {
window.console.log(uploadResources);
this._changeTestPlan(function (testPlan) {
testPlan.file = uploadResources.file;
});
},
handleDownload(file) { handleDownload(file) {
let data = { let data = {
name: file.name name: file.name