refactor(接口测试): 优化接口代码

This commit is contained in:
wxg0103 2024-05-16 11:31:54 +08:00 committed by Craftsman
parent 2e08868d98
commit d7257ddee8
6 changed files with 10 additions and 18 deletions

View File

@ -27,7 +27,7 @@ public interface ExtApiReportMapper {
List<String> selectApiReportByProjectIdAndTime(@Param("time") long time, @Param("projectId") String projectId);
int selectApiReportByTime(@Param("time") long time, @Param("projectId") String projectId);
int countApiReportByTime(@Param("time") long time, @Param("projectId") String projectId);
List<TaskCenterDTO> taskCenterlist(@Param("request") TaskCenterPageRequest request, @Param("projectIds") List<String> projectIds,
@Param("startTime") long startTime, @Param("endTime") long endTime);

View File

@ -91,7 +91,7 @@
where api_report.project_id = #{projectId}
limit 500
</select>
<select id="selectApiReportByTime" resultType="java.lang.Integer">
<select id="countApiReportByTime" resultType="java.lang.Integer">
select
count(api_report.id)
from api_report inner join api_report_step on

View File

@ -26,9 +26,8 @@ public interface ExtApiScenarioReportMapper {
List<String> selectApiScenarioReportByProjectId(String projectId);
int selectReportByTime(@Param("time") long time, @Param("projectId") String projectId);
int selectScenarioReportByTime(@Param("time") long time, @Param("projectId") String projectId);
int countScenarioReportByTime(@Param("time") long time, @Param("projectId") String projectId);
List<String> selectApiReportByProjectIdAndTime(@Param("time") long time, @Param("projectId") String projectId);

View File

@ -84,15 +84,7 @@
api_scenario_report.id
from api_scenario_report where api_scenario_report.project_id = #{projectId} limit 500
</select>
<select id="selectReportByTime" resultType="java.lang.Integer">
select
api_scenario_report.id
from api_scenario_report inner join api_scenario_report_step on
api_scenario_report.id = api_scenario_report_step.report_id
where api_scenario_report.start_time &gt;= #{startTime}
and api_scenario_report.start_time &lt;= #{endTime}
</select>
<select id="selectScenarioReportByTime" resultType="java.lang.Integer">
<select id="countScenarioReportByTime" resultType="java.lang.Integer">
select
count(api_scenario_report.id)
from api_scenario_report inner join api_scenario_report_step on

View File

@ -44,7 +44,7 @@ public class CleanupApiReportServiceImpl implements BaseCleanUpReport {
LogUtils.info("清理当前项目[" + projectId + "]相关接口测试报告");
String expr = map.get(ProjectApplicationType.API.API_CLEAN_REPORT.name());
long timeMills = getCleanDate(expr);
int apiReportCount = extApiReportMapper.selectApiReportByTime(timeMills, projectId);
int apiReportCount = extApiReportMapper.countApiReportByTime(timeMills, projectId);
while (apiReportCount > 0) {
List<String> ids = extApiReportMapper.selectApiReportByProjectIdAndTime(timeMills, projectId);
ApiReportExample reportExample = new ApiReportExample();
@ -53,9 +53,9 @@ public class CleanupApiReportServiceImpl implements BaseCleanUpReport {
report.setDeleted(true);
apiReportMapper.updateByExampleSelective(report, reportExample);
deleteApiReport(ids);
apiReportCount = extApiReportMapper.selectApiReportByTime(timeMills, projectId);
apiReportCount = extApiReportMapper.countApiReportByTime(timeMills, projectId);
}
int scenarioReportCount = extApiScenarioReportMapper.selectScenarioReportByTime(timeMills, projectId);
int scenarioReportCount = extApiScenarioReportMapper.countScenarioReportByTime(timeMills, projectId);
while (scenarioReportCount > 0) {
List<String> ids = extApiScenarioReportMapper.selectApiReportByProjectIdAndTime(timeMills, projectId);
ApiScenarioReportExample reportExample = new ApiScenarioReportExample();
@ -64,7 +64,7 @@ public class CleanupApiReportServiceImpl implements BaseCleanUpReport {
report.setDeleted(true);
apiScenarioReportMapper.updateByExampleSelective(report, reportExample);
deleteScenarioReport(ids);
scenarioReportCount = extApiScenarioReportMapper.selectScenarioReportByTime(timeMills, projectId);
scenarioReportCount = extApiScenarioReportMapper.countScenarioReportByTime(timeMills, projectId);
}
}

View File

@ -30,6 +30,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@ -175,7 +176,7 @@ public class MockServerService {
}
}
}
return StringUtils.equals(new String(binaryFile), new String(bytes));
return Arrays.equals(bytes, binaryFile);
}
}
return false;