文件格式修改

This commit is contained in:
Captain.B 2020-02-20 12:55:26 +08:00
parent 8239567c9e
commit 6dac23d291
6 changed files with 32 additions and 34 deletions

View File

@ -5,7 +5,7 @@ import java.io.Serializable;
public class FileContent implements Serializable { public class FileContent implements Serializable {
private String fileId; private String fileId;
private String file; private byte[] file;
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@ -17,11 +17,11 @@ public class FileContent implements Serializable {
this.fileId = fileId == null ? null : fileId.trim(); this.fileId = fileId == null ? null : fileId.trim();
} }
public String getFile() { public byte[] getFile() {
return file; return file;
} }
public void setFile(String file) { public void setFile(byte[] file) {
this.file = file == null ? null : file.trim(); this.file = file;
} }
} }

View File

@ -5,7 +5,7 @@
<id column="file_id" jdbcType="VARCHAR" property="fileId" /> <id column="file_id" jdbcType="VARCHAR" property="fileId" />
</resultMap> </resultMap>
<resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="io.metersphere.base.domain.FileContent"> <resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="io.metersphere.base.domain.FileContent">
<result column="file" jdbcType="LONGVARCHAR" property="file" /> <result column="file" jdbcType="LONGVARBINARY" property="file" />
</resultMap> </resultMap>
<sql id="Example_Where_Clause"> <sql id="Example_Where_Clause">
<where> <where>
@ -121,7 +121,7 @@
</delete> </delete>
<insert id="insert" parameterType="io.metersphere.base.domain.FileContent"> <insert id="insert" parameterType="io.metersphere.base.domain.FileContent">
insert into file_content (file_id, file) insert into file_content (file_id, file)
values (#{fileId,jdbcType=VARCHAR}, #{file,jdbcType=LONGVARCHAR}) values (#{fileId,jdbcType=VARCHAR}, #{file,jdbcType=LONGVARBINARY})
</insert> </insert>
<insert id="insertSelective" parameterType="io.metersphere.base.domain.FileContent"> <insert id="insertSelective" parameterType="io.metersphere.base.domain.FileContent">
insert into file_content insert into file_content
@ -138,7 +138,7 @@
#{fileId,jdbcType=VARCHAR}, #{fileId,jdbcType=VARCHAR},
</if> </if>
<if test="file != null"> <if test="file != null">
#{file,jdbcType=LONGVARCHAR}, #{file,jdbcType=LONGVARBINARY},
</if> </if>
</trim> </trim>
</insert> </insert>
@ -155,7 +155,7 @@
file_id = #{record.fileId,jdbcType=VARCHAR}, file_id = #{record.fileId,jdbcType=VARCHAR},
</if> </if>
<if test="record.file != null"> <if test="record.file != null">
file = #{record.file,jdbcType=LONGVARCHAR}, file = #{record.file,jdbcType=LONGVARBINARY},
</if> </if>
</set> </set>
<if test="_parameter != null"> <if test="_parameter != null">
@ -165,7 +165,7 @@
<update id="updateByExampleWithBLOBs" parameterType="map"> <update id="updateByExampleWithBLOBs" parameterType="map">
update file_content update file_content
set file_id = #{record.fileId,jdbcType=VARCHAR}, set file_id = #{record.fileId,jdbcType=VARCHAR},
file = #{record.file,jdbcType=LONGVARCHAR} file = #{record.file,jdbcType=LONGVARBINARY}
<if test="_parameter != null"> <if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" /> <include refid="Update_By_Example_Where_Clause" />
</if> </if>
@ -181,14 +181,14 @@
update file_content update file_content
<set> <set>
<if test="file != null"> <if test="file != null">
file = #{file,jdbcType=LONGVARCHAR}, file = #{file,jdbcType=LONGVARBINARY},
</if> </if>
</set> </set>
where file_id = #{fileId,jdbcType=VARCHAR} where file_id = #{fileId,jdbcType=VARCHAR}
</update> </update>
<update id="updateByPrimaryKeyWithBLOBs" parameterType="io.metersphere.base.domain.FileContent"> <update id="updateByPrimaryKeyWithBLOBs" parameterType="io.metersphere.base.domain.FileContent">
update file_content update file_content
set file = #{file,jdbcType=LONGVARCHAR} set file = #{file,jdbcType=LONGVARBINARY}
where file_id = #{fileId,jdbcType=VARCHAR} where file_id = #{fileId,jdbcType=VARCHAR}
</update> </update>
</mapper> </mapper>

View File

@ -1,18 +0,0 @@
package io.metersphere.commons.utils;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@Component
public class DBCompressConfig implements MybatisInterceptorConfigHolder {
@Override
public List<MybatisInterceptorConfig> interceptorConfig() {
// return Arrays.asList(
// new MybatisInterceptorConfig("io.metersphere.base.domain.FileContent", "file", "io.metersphere.commons.utils.CompressUtils", "zip", "unzip")
// );
return Collections.emptyList();
}
}

View File

@ -0,0 +1,19 @@
package io.metersphere.config;
import io.metersphere.commons.utils.MybatisInterceptorConfig;
import io.metersphere.commons.utils.MybatisInterceptorConfigHolder;
import org.springframework.context.annotation.Configuration;
import java.util.Arrays;
import java.util.List;
@Configuration
public class DBCompressConfig implements MybatisInterceptorConfigHolder {
@Override
public List<MybatisInterceptorConfig> interceptorConfig() {
return Arrays.asList(
new MybatisInterceptorConfig("io.metersphere.base.domain.FileContent", "file", "io.metersphere.commons.utils.CompressUtils", "zip", "unzip")
);
// return Collections.emptyList();
}
}

View File

@ -14,7 +14,6 @@ import org.apache.commons.lang3.StringUtils;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.InputStream; import java.io.InputStream;
import java.nio.charset.StandardCharsets;
public class EngineFactory { public class EngineFactory {
public static Engine createEngine(String engineType) { public static Engine createEngine(String engineType) {
@ -29,7 +28,7 @@ public class EngineFactory {
public static EngineContext createContext(LoadTestWithBLOBs loadTest, FileMetadata fileMetadata, FileContent fileContent) throws Exception { public static EngineContext createContext(LoadTestWithBLOBs loadTest, FileMetadata fileMetadata, FileContent fileContent) throws Exception {
final EngineContext engineContext = new EngineContext(); final EngineContext engineContext = new EngineContext();
engineContext.setEngineId(loadTest.getId()); engineContext.setEngineId(loadTest.getId());
engineContext.setInputStream(new ByteArrayInputStream(fileContent.getFile().getBytes(StandardCharsets.UTF_8))); engineContext.setInputStream(new ByteArrayInputStream(fileContent.getFile()));
engineContext.setEngineType(fileMetadata.getType()); engineContext.setEngineType(fileMetadata.getType());
if (!StringUtils.isEmpty(loadTest.getLoadConfiguration())) { if (!StringUtils.isEmpty(loadTest.getLoadConfiguration())) {

View File

@ -5,7 +5,6 @@ import io.metersphere.base.mapper.*;
import io.metersphere.base.mapper.ext.ExtLoadTestMapper; import io.metersphere.base.mapper.ext.ExtLoadTestMapper;
import io.metersphere.commons.constants.EngineType; import io.metersphere.commons.constants.EngineType;
import io.metersphere.commons.exception.MSException; import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.utils.IOUtils;
import io.metersphere.controller.request.testplan.*; import io.metersphere.controller.request.testplan.*;
import io.metersphere.dto.LoadTestDTO; import io.metersphere.dto.LoadTestDTO;
import io.metersphere.engine.Engine; import io.metersphere.engine.Engine;
@ -19,7 +18,6 @@ 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.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
@ -115,7 +113,7 @@ public class LoadTestService {
FileContent fileContent = new FileContent(); FileContent fileContent = new FileContent();
fileContent.setFileId(fileMetadata.getId()); fileContent.setFileId(fileMetadata.getId());
try { try {
fileContent.setFile(IOUtils.toString(file.getInputStream(), StandardCharsets.UTF_8)); fileContent.setFile(file.getBytes());
} catch (IOException e) { } catch (IOException e) {
MSException.throwException(e); MSException.throwException(e);
} }