refactor(接口测试): 报告详情查询优化
This commit is contained in:
parent
18ce79c281
commit
9abac8e0fa
|
@ -1,37 +0,0 @@
|
|||
package io.metersphere.api.dto.scenario;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class ApiScenarioReportDetailBlobDTO implements Serializable {
|
||||
private String id;
|
||||
|
||||
private String reportId;
|
||||
|
||||
private String stepId;
|
||||
|
||||
private String status;
|
||||
|
||||
private String fakeCode;
|
||||
|
||||
private String requestName;
|
||||
|
||||
private Long requestTime;
|
||||
|
||||
private String code;
|
||||
|
||||
private Long responseSize;
|
||||
|
||||
private String scriptIdentifier;
|
||||
|
||||
private Long sort;
|
||||
|
||||
private byte[] content;
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
}
|
|
@ -67,6 +67,8 @@ public class ApiScenarioReportDetailDTO {
|
|||
@Schema(description = "脚本标识")
|
||||
private String scriptIdentifier;
|
||||
|
||||
private Long sort;
|
||||
|
||||
/**
|
||||
* 结果内容详情
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
package io.metersphere.api.handler;
|
||||
|
||||
|
||||
import io.metersphere.api.utils.ApiDataUtils;
|
||||
import io.metersphere.handler.BaseTypeHandler;
|
||||
import io.metersphere.sdk.dto.api.result.RequestResult;
|
||||
import io.metersphere.sdk.util.JSON;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.apache.ibatis.type.JdbcType;
|
||||
|
||||
import java.sql.CallableStatement;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class ResultTypeHandler extends BaseTypeHandler<RequestResult> {
|
||||
|
||||
@Override
|
||||
public void setNonNullParameter(PreparedStatement ps, int i, RequestResult parameter, JdbcType jdbcType) throws SQLException {
|
||||
byte[] d = JSON.toJSONBytes(parameter);
|
||||
ps.setBytes(i, d);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestResult getNullableResult(ResultSet rs, String columnName) throws SQLException {
|
||||
byte[] values = rs.getBytes(columnName);
|
||||
return getResults(values);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestResult getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
|
||||
byte[] values = rs.getBytes(columnIndex);
|
||||
return getResults(values);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestResult getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
|
||||
byte[] values = cs.getBytes(columnIndex);
|
||||
return getResults(values);
|
||||
}
|
||||
|
||||
private RequestResult getResults(byte[] values) {
|
||||
if (ArrayUtils.isNotEmpty(values)) {
|
||||
return ApiDataUtils.parseObject(new String(values), RequestResult.class);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,12 +1,12 @@
|
|||
package io.metersphere.api.mapper;
|
||||
|
||||
import io.metersphere.api.dto.scenario.ApiScenarioReportDetailBlobDTO;
|
||||
import io.metersphere.api.dto.scenario.ApiScenarioReportDetailDTO;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ExtApiScenarioReportDetailBlobMapper {
|
||||
|
||||
List<ApiScenarioReportDetailBlobDTO> selectByExampleWithBLOBs(@Param("stepId") String stepId, @Param("reportId") String reportId);
|
||||
List<ApiScenarioReportDetailDTO> selectByExampleWithBLOBs(@Param("stepId") String stepId, @Param("reportId") String reportId);
|
||||
|
||||
}
|
|
@ -2,7 +2,11 @@
|
|||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="io.metersphere.api.mapper.ExtApiScenarioReportDetailBlobMapper">
|
||||
|
||||
<select id="selectByExampleWithBLOBs" resultType="io.metersphere.api.dto.scenario.ApiScenarioReportDetailBlobDTO">
|
||||
<resultMap id="apiScenarioReportDetailDTO" type="io.metersphere.api.dto.scenario.ApiScenarioReportDetailDTO">
|
||||
<result column="content" javaType="byte[]" jdbcType="BLOB" property="content" typeHandler="io.metersphere.api.handler.ResultTypeHandler" />
|
||||
</resultMap>
|
||||
|
||||
<select id="selectByExampleWithBLOBs" resultMap="apiScenarioReportDetailDTO">
|
||||
SELECT
|
||||
detail.*,
|
||||
detail_blob.content
|
||||
|
@ -11,5 +15,5 @@
|
|||
INNER JOIN api_scenario_report_detail_blob detail_blob ON detail.id = detail_blob.id
|
||||
WHERE
|
||||
detail.step_id = #{stepId} AND detail.report_id = #{reportId}
|
||||
</select>
|
||||
</select>
|
||||
</mapper>
|
|
@ -6,15 +6,12 @@ import io.metersphere.api.dto.definition.ApiReportBatchRequest;
|
|||
import io.metersphere.api.dto.definition.ApiReportPageRequest;
|
||||
import io.metersphere.api.dto.report.ApiScenarioReportListDTO;
|
||||
import io.metersphere.api.dto.scenario.ApiScenarioReportDTO;
|
||||
import io.metersphere.api.dto.scenario.ApiScenarioReportDetailBlobDTO;
|
||||
import io.metersphere.api.dto.scenario.ApiScenarioReportDetailDTO;
|
||||
import io.metersphere.api.dto.scenario.ApiScenarioReportStepDTO;
|
||||
import io.metersphere.api.mapper.*;
|
||||
import io.metersphere.api.utils.ApiDataUtils;
|
||||
import io.metersphere.sdk.constants.ApiReportStatus;
|
||||
import io.metersphere.sdk.domain.Environment;
|
||||
import io.metersphere.sdk.domain.EnvironmentGroup;
|
||||
import io.metersphere.sdk.dto.api.result.RequestResult;
|
||||
import io.metersphere.sdk.mapper.EnvironmentGroupMapper;
|
||||
import io.metersphere.sdk.mapper.EnvironmentMapper;
|
||||
import io.metersphere.sdk.util.BeanUtils;
|
||||
|
@ -201,7 +198,7 @@ public class ApiScenarioReportService {
|
|||
|
||||
//将scenarioReportSteps按照parentId进行分组 值为list 然后根据sort进行排序
|
||||
Map<String, List<ApiScenarioReportStepDTO>> scenarioReportStepMap = scenarioReportSteps.stream().collect(Collectors.groupingBy(ApiScenarioReportStepDTO::getParentId));
|
||||
|
||||
|
||||
List<ApiScenarioReportStepDTO> steps = Optional.ofNullable(scenarioReportStepMap.get("NONE")).orElse(new ArrayList<>(0));
|
||||
steps.sort(Comparator.comparingLong(ApiScenarioReportStepDTO::getSort));
|
||||
|
||||
|
@ -347,25 +344,18 @@ public class ApiScenarioReportService {
|
|||
index = StringUtils.substringAfter(stepId, SPLITTER);
|
||||
stepId = StringUtils.substringBefore(stepId, SPLITTER);
|
||||
}
|
||||
List<ApiScenarioReportDetailBlobDTO> apiReportDetails = checkResourceStep(stepId, reportId);
|
||||
apiReportDetails.sort(Comparator.comparingLong(ApiScenarioReportDetailBlobDTO::getSort));
|
||||
List<ApiScenarioReportDetailDTO> apiReportDetails = checkResourceStep(stepId, reportId);
|
||||
apiReportDetails.sort(Comparator.comparingLong(ApiScenarioReportDetailDTO::getSort));
|
||||
|
||||
if (StringUtils.isNotBlank(index)) {
|
||||
ApiScenarioReportDetailBlobDTO apiScenarioReportDetail = apiReportDetails.get(Integer.parseInt(index) - 1);
|
||||
ApiScenarioReportDetailDTO apiScenarioReportDetail = apiReportDetails.get(Integer.parseInt(index) - 1);
|
||||
apiReportDetails = Collections.singletonList(apiScenarioReportDetail);
|
||||
}
|
||||
List<ApiScenarioReportDetailDTO> results = new ArrayList<>();
|
||||
apiReportDetails.forEach(apiReportDetail -> {
|
||||
ApiScenarioReportDetailDTO apiReportDetailDTO = new ApiScenarioReportDetailDTO();
|
||||
BeanUtils.copyBean(apiReportDetailDTO, apiReportDetail);
|
||||
apiReportDetailDTO.setContent(apiReportDetail.getContent() != null ? ApiDataUtils.parseObject(new String(apiReportDetail.getContent()), RequestResult.class) : null);
|
||||
results.add(apiReportDetailDTO);
|
||||
});
|
||||
return results;
|
||||
return apiReportDetails;
|
||||
}
|
||||
|
||||
private List<ApiScenarioReportDetailBlobDTO> checkResourceStep(String stepId, String reportId) {
|
||||
List<ApiScenarioReportDetailBlobDTO> apiReportDetails = extApiScenarioReportDetailBlobMapper.selectByExampleWithBLOBs(stepId, reportId);
|
||||
private List<ApiScenarioReportDetailDTO> checkResourceStep(String stepId, String reportId) {
|
||||
List<ApiScenarioReportDetailDTO> apiReportDetails = extApiScenarioReportDetailBlobMapper.selectByExampleWithBLOBs(stepId, reportId);
|
||||
if (CollectionUtils.isEmpty(apiReportDetails)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue