文件格式修改

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

View File

@ -5,7 +5,7 @@
<id column="file_id" jdbcType="VARCHAR" property="fileId" />
</resultMap>
<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>
<sql id="Example_Where_Clause">
<where>
@ -121,7 +121,7 @@
</delete>
<insert id="insert" parameterType="io.metersphere.base.domain.FileContent">
insert into file_content (file_id, file)
values (#{fileId,jdbcType=VARCHAR}, #{file,jdbcType=LONGVARCHAR})
values (#{fileId,jdbcType=VARCHAR}, #{file,jdbcType=LONGVARBINARY})
</insert>
<insert id="insertSelective" parameterType="io.metersphere.base.domain.FileContent">
insert into file_content
@ -138,7 +138,7 @@
#{fileId,jdbcType=VARCHAR},
</if>
<if test="file != null">
#{file,jdbcType=LONGVARCHAR},
#{file,jdbcType=LONGVARBINARY},
</if>
</trim>
</insert>
@ -155,7 +155,7 @@
file_id = #{record.fileId,jdbcType=VARCHAR},
</if>
<if test="record.file != null">
file = #{record.file,jdbcType=LONGVARCHAR},
file = #{record.file,jdbcType=LONGVARBINARY},
</if>
</set>
<if test="_parameter != null">
@ -165,7 +165,7 @@
<update id="updateByExampleWithBLOBs" parameterType="map">
update file_content
set file_id = #{record.fileId,jdbcType=VARCHAR},
file = #{record.file,jdbcType=LONGVARCHAR}
file = #{record.file,jdbcType=LONGVARBINARY}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
@ -181,14 +181,14 @@
update file_content
<set>
<if test="file != null">
file = #{file,jdbcType=LONGVARCHAR},
file = #{file,jdbcType=LONGVARBINARY},
</if>
</set>
where file_id = #{fileId,jdbcType=VARCHAR}
</update>
<update id="updateByPrimaryKeyWithBLOBs" parameterType="io.metersphere.base.domain.FileContent">
update file_content
set file = #{file,jdbcType=LONGVARCHAR}
set file = #{file,jdbcType=LONGVARBINARY}
where file_id = #{fileId,jdbcType=VARCHAR}
</update>
</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.InputStream;
import java.nio.charset.StandardCharsets;
public class EngineFactory {
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 {
final EngineContext engineContext = new EngineContext();
engineContext.setEngineId(loadTest.getId());
engineContext.setInputStream(new ByteArrayInputStream(fileContent.getFile().getBytes(StandardCharsets.UTF_8)));
engineContext.setInputStream(new ByteArrayInputStream(fileContent.getFile()));
engineContext.setEngineType(fileMetadata.getType());
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.commons.constants.EngineType;
import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.utils.IOUtils;
import io.metersphere.controller.request.testplan.*;
import io.metersphere.dto.LoadTestDTO;
import io.metersphere.engine.Engine;
@ -19,7 +18,6 @@ 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.UUID;
@ -115,7 +113,7 @@ public class LoadTestService {
FileContent fileContent = new FileContent();
fileContent.setFileId(fileMetadata.getId());
try {
fileContent.setFile(IOUtils.toString(file.getInputStream(), StandardCharsets.UTF_8));
fileContent.setFile(file.getBytes());
} catch (IOException e) {
MSException.throwException(e);
}