Commit b848f47d authored by wdy's avatar wdy

Merge branch 'wangdingyi' into 'dev'

单个任务调用第三方接口

See merge request !223
parents 1dc673a7 f25b0ce5
......@@ -19,4 +19,11 @@ public interface TestRecordsService extends IService<TestRecords> {
* @param id
*/
void sendPost(String id,Long taskId);
/**
* 单个任务发送请求
* @param id
* @param taskId
*/
void singleSendPost(String id,Long taskId);
}
......@@ -49,12 +49,12 @@ public class TestRecordsServiceImpl extends ServiceImpl<TestRecordsMapper, TestR
List<TestRecords> recordsList = testRecordsService.findByTaskId(id);
List<TestRecords> list = new ArrayList<>();
if (caseResultVOS.size() != 0 && caseResultVOS != null) {
if (caseResultVOS != null && caseResultVOS.size() != 0) {
for (CaseResultVO caseResultVO : caseResultVOS) {
// 检查 usecaseId 是否在 recordsList 中存在
boolean exists = false;
if (recordsList.size() != 0 && recordsList != null) {
if (recordsList != null && recordsList.size() != 0) {
for (TestRecords records : recordsList) {
if (Objects.equals(caseResultVO.getId(), records.getUsecaseId())) {
......@@ -78,7 +78,68 @@ public class TestRecordsServiceImpl extends ServiceImpl<TestRecordsMapper, TestR
// 用例步骤
List<StepResultVO> stepResultVOS = caseResultVO.getStep_result_list();
if (stepResultVOS.size() != 0 && stepResultVOS != null) {
if (stepResultVOS != null && stepResultVOS.size() != 0) {
List<String> stepList = new ArrayList<>();
for (StepResultVO stepResultVO :stepResultVOS) {
String stepName = stepResultVO.getName();
stepList.add(stepName);
}
testRecords.setTestMethod(StringUtils.join(stepList,","));
}
list.add(testRecords);
}
}
testRecordsService.saveBatch(list);
}
}
@Override
public void singleSendPost(String id, Long taskId) {
Map<String, Object> map = new HashMap<>();
map.put("id", id);
map.put("verbose", "ALL");
//以post形式请求接口
String result= HttpUtil.post("https://10.12.48.78:8090/DescribeProjectTestResult",JSONObject.toJSONString(map));
JSONObject jsonObject = JSONObject.parseObject(result);
// 获取项目id
String projectId = (String) jsonObject.get("id");
// 获取项目用例结果列表
List<CaseResultVO> caseResultVOS = jsonObject.getList("case_result_list", CaseResultVO.class);
// 获取当前任务本地存储的列表
List<TestRecords> recordsList = testRecordsService.findByTaskId(id);
if (recordsList != null && recordsList.size() != 0) {
testRecordsService.removeBatchByIds(recordsList);
}
List<TestRecords> list = new ArrayList<>();
if (caseResultVOS != null && caseResultVOS.size() != 0) {
for (CaseResultVO caseResultVO : caseResultVOS) {
if (Objects.equals(caseResultVO.getStatus(), "PASSED") || Objects.equals(caseResultVO.getStatus(), "FAILED")) {
TestRecords testRecords = new TestRecords();
testRecords.setProjectId(projectId);
testRecords.setTaskId(taskId);
testRecords.setUsecase(caseResultVO.getName());
testRecords.setUsecaseId(caseResultVO.getId());
testRecords.setDescription(caseResultVO.getDescription());
testRecords.setRiskLevel(caseResultVO.getRisk_level());
testRecords.setTestResult(caseResultVO.getStatus());
testRecords.setRemediation(caseResultVO.getRemediation());
// 用例步骤
List<StepResultVO> stepResultVOS = caseResultVO.getStep_result_list();
if (stepResultVOS != null && stepResultVOS.size() != 0) {
List<String> stepList = new ArrayList<>();
for (StepResultVO stepResultVO :stepResultVOS) {
String stepName = stepResultVO.getName();
......
......@@ -20,7 +20,7 @@
<select id="findByTaskId" resultType="com.ruoyi.domain.TestRecords">
SELECT id, project_id, task_id, usecase, usecase_id, test_time, description, risk_level, test_method, test_result, remediation
FROM t_test_records
WHERE task_id = #{id}
WHERE project_id = #{id}
</select>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment