Commit 0a311179 authored by wdy's avatar wdy

根据场景查询用例&快速创建检测项目

parent 0fda6c45
......@@ -7,6 +7,7 @@ import com.ruoyi.web.response.DataStatisticsResponse;
import com.ruoyi.web.response.TaskFindResponse;
import com.ruoyi.web.response.TaskGetInfoResponse;
import java.io.IOException;
import java.util.List;
public interface TaskService extends IService<Task> {
......@@ -65,4 +66,6 @@ public interface TaskService extends IService<Task> {
TaskGetInfoResponse getBySubtaskId(TaskSubGetInfoRequest request);
DataStatisticsResponse dataStatistics(TaskGetInfoRequest request);
String createProject(String request) throws IOException;
}
......@@ -73,4 +73,12 @@ public interface TestUseCaseService extends IService<TestUseCase> {
* @throws IOException
*/
List<UseCaseUrlVO> getUseCaseByChapter(String request) throws IOException;
/**
* 根据场景查询测试用例集合
* @param request
* @return
* @throws IOException
*/
List<String> selectCaseListByScenario(String request) throws IOException;
}
......@@ -21,10 +21,12 @@ import com.ruoyi.service.*;
import com.ruoyi.system.service.ISysUserService;
import com.ruoyi.web.request.*;
import com.ruoyi.web.response.*;
import okhttp3.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.*;
import java.util.function.Function;
......@@ -783,6 +785,38 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task>implements Tas
}
@Override
public String createProject(String request) throws IOException {
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\"query\":\"mutation quickCreateProjct($name:String$description:String$useCaseList:[ID!]!){project{quickCreateProject(input:{name:$name description:$description useCaseIDList:$useCaseList}){id name status description createTime}}}\",\"variables\":"+ request +"}");
Request requestKE = new Request.Builder()
.url("http://10.12.48.80:8089/api/query")
.method("POST", body)
.addHeader("Content-Type", "application/json")
// TODO 连接
.addHeader("Authorization", "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjAsInRva2VuaWQiOjYxLCJ0eXBlIjoiYXBpIiwidXNlcm5hbWUiOiJhZG1pbiJ9.48Ggjx-FtOcecf73vAHn0XglwgLXZlfXxhXiLDHWWQE")
// .addHeader("Host", "10.12.48.80:8089")
// .addHeader("Origin", "http://10.12.48.80:8089")
// .addHeader("Referer", "http://10.12.48.80:8089/api/graphql/playground")
// .addHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36")
.build();
Response response = client.newCall(requestKE).execute();
String string = response.body().string();
JSONObject jsonObject = JSONObject.parseObject(string);
// 获取id
String testSchemeId = "";
if (jsonObject.getJSONObject("data").getJSONObject("project") != null) {
testSchemeId = (String) jsonObject.getJSONObject("data").getJSONObject("project").getJSONObject("quickCreateProject").get("id");
}
return testSchemeId;
}
private void carTestStatistics(DataStatisticsResponse response, Task task) {
if (task.getModelTestTaskId() != null) {
......
......@@ -3,7 +3,6 @@ package com.ruoyi.service.impl;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.utils.bean.BeanUtils;
import com.ruoyi.domain.TestUseCase;
import com.ruoyi.domain.vo.*;
import com.ruoyi.service.TestUseCaseService;
......@@ -13,6 +12,7 @@ import com.ruoyi.web.request.TestUseCaseIdListRequest;
import com.ruoyi.web.request.TestUserCaseRequest;
import com.ruoyi.web.response.TestUserCaseListResponse;
import com.ruoyi.web.response.UseCaseResponse;
import lombok.Data;
import okhttp3.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -233,6 +233,39 @@ public class TestUseCaseServiceImpl extends ServiceImpl<TestUseCaseMapper, TestU
return list;
}
@Override
public List<String> selectCaseListByScenario(String request) throws IOException {
OkHttpClient client = new OkHttpClient().newBuilder().build();
MediaType mediaType = MediaType.parse("application/json");
// 创建请求体
RequestBody body = RequestBody.create(mediaType, "{\"query\":\"query useCases($offset:OffsetConnectionInput$orderBy:OrderByInput$filter:Map$search:String$searchFields:Map){useCases(offset:$offset orderBy:$orderBy filterFields:$filter search:$search searchFields:$searchFields){nodes{id displayID class name description remediation requirements riskLevel method{name}scenario{name}}totalCount}}\",\"variables\":"+ request +"}");
Request requestKE = new Request.Builder()
.url("http://10.12.48.80:8089/api/query")
.method("POST", body)
.addHeader("Content-Type", "application/json")
// TODO 连接
// .addHeader("Host", "10.12.48.80:8089")
// .addHeader("Origin", "http://10.12.48.80:8089")
// .addHeader("Referer", "http://10.12.48.80:8089/api/graphql/playground")
// .addHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36")
.build();
Response response = client.newCall(requestKE).execute();
String string = response.body().string();
JSONObject jsonObject = JSONObject.parseObject(string);
// 获取测试用例
return jsonObject.getJSONObject("data").getJSONObject("useCases").getJSONArray("nodes")
.stream()
.map(node -> ((JSONObject) node).getString("id"))
.distinct() // 去除重复项
.collect(Collectors.toList());
}
}
......
......@@ -27,6 +27,8 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.io.IOException;
import java.util.List;
@Api(tags = "总任务")
......@@ -190,4 +192,16 @@ public class TaskController extends BaseController {
return R.ok(response);
}
/**
* 快速创建检测项目
* @param request
* @return
* @throws IOException
*/
@ApiOperation("快速创建检测项目(科恩)")
@RequestMapping(method = RequestMethod.POST, value = "/createProject", produces="application/json;charset=UTF-8")
public R<String> createProject(@Validated @RequestBody String request) throws IOException {
return R.ok(taskService.createProject(request));
}
}
......@@ -62,6 +62,18 @@ public class TestUserCaseController extends BaseController{
return R.ok(testUseCaseService.selectCaseByScenario(request));
}
/**
* 根据场景查询测试用例集合
* @param request
* @return
* @throws IOException
*/
@ApiOperation("根据场景查询测试用例集合")
@RequestMapping(method = RequestMethod.POST, value = "/getUseCaseListByScenario", produces="application/json;charset=UTF-8")
public R<List<String>> getUseCaseListByScenario(@Validated @RequestBody String request) throws IOException {
return R.ok(testUseCaseService.selectCaseListByScenario(request));
}
/**
* 科恩获取测试用例
* @param request
......
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