Commit c2b6649f authored by wdy's avatar wdy

每5秒调用第三方接口&总任务文件列表

parent db1d1f2f
package com.ruoyi.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
@ApiModel
@TableName(value ="t_task_file_relation")
@Data
@Accessors(chain = true)
public class TaskFileRelation {
@ApiModelProperty("任务id")
@TableId(type = IdType.ASSIGN_ID)
@JsonFormat(shape = JsonFormat.Shape.STRING)
private Long taskId;
@ApiModelProperty("路径")
private String url;
@ApiModelProperty("文件名称")
private String name;
}
......@@ -44,9 +44,6 @@ public class TestRecords {
@ApiModelProperty("测试结果")
private String testResult;
@ApiModelProperty("测试结果描述")
private String testResultDescription;
@ApiModelProperty("漏洞危害")
private String loophole;
@ApiModelProperty("修复建议")
private String remediation;
}
......@@ -4,10 +4,15 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.domain.ModelTestTask;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* 车型试验Mapper层
* @author gxk
*/
@Repository
public interface ModelTestTaskMapper extends BaseMapper<ModelTestTask> {
// 查询pending状态下的所有任务
List<ModelTestTask> findByStatus();
}
package com.ruoyi.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.domain.TaskFileRelation;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface TaskFileRelationMapper extends BaseMapper<TaskFileRelation> {
List<TaskFileRelation> findByTaskId(@Param("taskId") Long taskId);
}
......@@ -37,6 +37,8 @@ public interface TaskMapper extends BaseMapper<Task> {
Long findTaskName(@Param("taskName") String taskName);
Task findByName(@Param("taskName") String taskName);
/**
* 通过总任务ID,获取企业文件数据
* @param taskId
......
......@@ -2,8 +2,13 @@ package com.ruoyi.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.domain.TestRecords;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface TestRecordsMapper extends BaseMapper<TestRecords> {
List<TestRecords> findByTaskId(@Param("id") String id);
}
package com.ruoyi.scheduledTask;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
public class Main {
public static void main(String[] args) {
ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
scheduledExecutorService.scheduleAtFixedRate(new ScheduledTask(),0,5, TimeUnit.SECONDS);
}
}
package com.ruoyi.scheduledTask;
import com.ruoyi.domain.ModelTestTask;
import com.ruoyi.mapper.ModelTestTaskMapper;
import com.ruoyi.service.TestRecordsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.stereotype.Component;
import org.springframework.scheduling.annotation.Scheduled;
import java.util.*;
@Component
@EnableAsync
public class ScheduledTask implements Runnable{
@Autowired
private TestRecordsService testRecordsService;
@Autowired
private ModelTestTaskMapper modelTestTaskMapper;
@Scheduled(fixedDelay = 5000)
@Override
public void run() {
List<ModelTestTask> modelList = modelTestTaskMapper.findByStatus();
for (ModelTestTask testTask : modelList) {
if (testTask.getTestSchemeId() != null) {
testRecordsService.sendPost(testTask.getTestSchemeId());
}
}
}
}
package com.ruoyi.scheduledTask;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.scheduling.annotation.SchedulingConfiguration;
@Configuration
@ConditionalOnExpression(value = "${task.scheduling}")
@Import(SchedulingConfiguration.class)
public class TaskEnableSchedulingConfig {
}
package com.ruoyi.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.ruoyi.domain.TaskFileRelation;
import java.util.List;
public interface TaskFileRelationService extends IService<TaskFileRelation> {
List<TaskFileRelation> findByTaskId(Long taskId);
}
......@@ -3,5 +3,20 @@ package com.ruoyi.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.ruoyi.domain.TestRecords;
import java.util.List;
public interface TestRecordsService extends IService<TestRecords> {
/**
* 根据项目id获取用例
* @param id
* @return
*/
List<TestRecords> findByTaskId(String id);
/**
* 发送请求
* @param id
*/
void sendPost(String id);
}
package com.ruoyi.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.domain.ResultFileRelation;
import com.ruoyi.domain.TaskFileRelation;
import com.ruoyi.mapper.ResultFileRelationMapper;
import com.ruoyi.mapper.TaskFileRelationMapper;
import com.ruoyi.service.ResultFileRelationService;
import com.ruoyi.service.TaskFileRelationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Transactional
@Service
public class TaskFileRelationServiceImpl extends ServiceImpl<TaskFileRelationMapper, TaskFileRelation> implements TaskFileRelationService {
@Autowired
private TaskFileRelationMapper taskFileRelationMapper;
@Override
public List<TaskFileRelation> findByTaskId(Long taskId) {
return taskFileRelationMapper.findByTaskId(taskId);
}
}
......@@ -100,6 +100,9 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task>implements Tas
@Autowired
private TaskScenarioRelationMapper taskScenarioRelationMapper;
@Autowired
private TaskFileRelationService taskFileRelationService;
@Override
public List<Task> findList(TaskListRequest request) {
return taskMapper.findList(request);
......@@ -108,13 +111,36 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task>implements Tas
@Override
public void createTask(TaskCreateRequest request) {
// 构建任务创建者
LoginUser loginUser = SecurityUtils.getLoginUser();
TaskGetInfoResponse temporaryStorageTask = taskService.getByUserId(loginUser.getUserId());
if(temporaryStorageTask != null) {
taskMapper.deleteById(temporaryStorageTask.getId());
// 删除暂存任务与整车样品的信息
List<TaskSampleRelation> sampleRelations = taskSampleRelationService.selectByTaskId(temporaryStorageTask.getId(),TaskSampleRelation.COMPLETE_VEHICLE_SAMPLE);
taskSampleRelationService.removeBatchByIds(sampleRelations);
// 删除暂存任务与零件样品的信息
List<TaskSampleRelation> partRelationList = taskSampleRelationService.selectByTaskId(temporaryStorageTask.getId(),TaskSampleRelation.PART_VEHICLE_SAMPLE);
taskSampleRelationService.removeBatchByIds(partRelationList);
// 删除暂存任务与小组的信息
List<TaskUserRelation> list = taskUserRelationService.selectQTeamMembers(temporaryStorageTask.getId());
taskUserRelationService.removeBatchByIds(list);
// 删除暂存任务与文件的信息
List<TaskFileRelation> fileRelations = taskFileRelationService.findByTaskId(temporaryStorageTask.getId());
taskFileRelationService.removeBatchByIds(fileRelations);
}
Long sum = taskMapper.findTaskName(request.getTaskName());
if (sum > 0) {
throw new ServiceException("任务名称重复,请检查", HttpStatus.ERROR);
} else {
// 构建任务创建者
LoginUser loginUser = SecurityUtils.getLoginUser();
SysUser initiator = sysUserService.selectUserById(loginUser.getUserId());
Standard standard = standardService.findListById(request.getStandardId());
......@@ -172,12 +198,11 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task>implements Tas
List<TaskSampleRelation> partRelations = request.getPartSample();
saveSampleRelation(relations,partRelations,task);
// 保存任务关联的文件信息
saveFileList(request.getFileList(),task);
taskStateFacade.doCreate(task, request.getTaskList());
TaskGetInfoResponse temporaryStorageTask = taskService.getByUserId(loginUser.getUserId());
if(temporaryStorageTask != null) {
taskMapper.deleteById(temporaryStorageTask.getId());
}
}
}
......@@ -265,6 +290,9 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task>implements Tas
@Override
public void editTask(TaskEditRequest request) {
Task oldTask = taskMapper.findByName(request.getTaskName());
if (oldTask == null || Objects.equals(oldTask.getId(), request.getId())) {
// 构建任务创建者
LoginUser loginUser = SecurityUtils.getLoginUser();
SysUser initiator = sysUserService.selectUserById(loginUser.getUserId());
......@@ -306,6 +334,13 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task>implements Tas
List<TaskSampleRelation> partRelations = request.getPartSample();
saveSampleRelation(relations,partRelations,task);
// 保存任务关联的文件信息
saveFileList(request.getFileList(),task);
} else {
throw new ServiceException("任务名称重复,请检查", HttpStatus.ERROR);
}
}
@Override
......@@ -358,6 +393,11 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task>implements Tas
if (task != null) {
BeanUtils.copyBeanProp(response, task);
if (response.getTaskList().startsWith(",")) {
String taskList = response.getTaskList().substring(1);
response.setTaskList(taskList);
}
// 测试场景
response.setTestScenarioList(selectTestScenarioList(task));
......@@ -370,6 +410,9 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task>implements Tas
// 零部件样品信息
response.setPartVehicleSample(setSampleList(request.getId(),TaskSampleRelation.PART_VEHICLE_SAMPLE));
// 上传的文件
response.setFileList(taskFileRelationService.findByTaskId(request.getId()));
return response;
} else {
return null;
......@@ -405,6 +448,10 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task>implements Tas
@Override
public void temporaryStorageTask(TaskCreateRequest request) {
Long sum = taskMapper.findTaskName(request.getTaskName());
if (sum > 0) {
throw new ServiceException("任务名称重复,请检查", HttpStatus.ERROR);
} else {
// 构建任务创建者
LoginUser loginUser = SecurityUtils.getLoginUser();
SysUser initiator = sysUserService.selectUserById(loginUser.getUserId());
......@@ -459,10 +506,18 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task>implements Tas
List<TaskSampleRelation> partRelations = request.getPartSample();
saveSampleRelation(relations,partRelations,task);
// 保存任务关联的文件信息
saveFileList(request.getFileList(),task);
}
}
@Override
public void editTemporaryStorageTask(TaskEditRequest request) {
Task oldTask = taskMapper.findByName(request.getTaskName());
if (oldTask == null || Objects.equals(oldTask.getId(), request.getId())) {
// 构建任务创建者
LoginUser loginUser = SecurityUtils.getLoginUser();
SysUser initiator = sysUserService.selectUserById(loginUser.getUserId());
......@@ -511,6 +566,12 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task>implements Tas
List<TaskSampleRelation> partRelations = request.getPartSample();
saveSampleRelation(relations,partRelations,task);
// 保存任务关联的文件信息
saveFileList(request.getFileList(),task);
} else {
throw new ServiceException("任务名称重复,请检查", HttpStatus.ERROR);
}
}
@Override
......@@ -523,6 +584,11 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task>implements Tas
BeanUtils.copyBeanProp(response, task);
if (response.getTaskList().startsWith(",")) {
String taskList = response.getTaskList().substring(1);
response.setTaskList(taskList);
}
// 测试场景
response.setTestScenarioList(selectTestScenarioList(task));
......@@ -535,6 +601,9 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task>implements Tas
// 零部件样品信息
response.setPartVehicleSample(setSampleList(task.getId(), TaskSampleRelation.PART_VEHICLE_SAMPLE));
// 上传的文件
response.setFileList(taskFileRelationService.findByTaskId(task.getId()));
return response;
} else {
return null;
......@@ -634,11 +703,11 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task>implements Tas
private void saveUserRelation(List<TaskUserRelation> auditors,Task task) {
// 构建并保存该任务所关联的审核组信息
List<TaskUserRelation> list = taskUserRelationService.selectQTeamMembers(task.getId());
if (list.size() != 0 && list != null) {
if (list != null && list.size() != 0) {
taskUserRelationService.removeBatchByIds(list);
}
if (auditors.size() != 0 && auditors != null) {
if (auditors != null && auditors.size() != 0) {
// 构建并保存该任务所关联的审核组信息
for(TaskUserRelation auditor : auditors) {
auditor.setTaskId(task.getId());
......@@ -648,15 +717,33 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task>implements Tas
}
}
private void saveFileList(List<TaskFileRelation> fileList,Task task) {
List<TaskFileRelation> list = taskFileRelationService.findByTaskId(task.getId());
if (list != null&& list.size() != 0) {
taskFileRelationService.removeBatchByIds(list);
}
if (fileList != null && fileList.size() != 0 ) {
for (TaskFileRelation relation : fileList) {
relation.setTaskId(task.getId());
}
taskFileRelationService.saveBatch(fileList);
}
}
// 保存任务与样品信息
private void saveSampleRelation(List<TaskSampleRelation> relations,List<TaskSampleRelation> partRelations,Task task) {
// 整车
List<TaskSampleRelation> relationList = taskSampleRelationService.selectByTaskId(task.getId(),TaskSampleRelation.COMPLETE_VEHICLE_SAMPLE);
if (relationList.size() != 0 && relationList != null) {
if (relationList != null && relationList.size() != 0) {
taskSampleRelationService.removeBatchByIds(relationList);
}
if (relations.size() != 0 && relations != null) {
if (relations != null && relations.size() != 0) {
for (TaskSampleRelation sampleRelation : relations) {
sampleRelation.setTaskId(task.getId());
}
......@@ -666,11 +753,11 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task>implements Tas
// 零件
List<TaskSampleRelation> partRelationList = taskSampleRelationService.selectByTaskId(task.getId(),TaskSampleRelation.PART_VEHICLE_SAMPLE);
if (partRelationList.size() != 0 && partRelationList != null) {
if (partRelationList != null && partRelationList.size() != 0) {
taskSampleRelationService.removeBatchByIds(partRelationList);
}
if (partRelations.size() != 0 && partRelations != null) {
if (partRelations != null && partRelations.size() != 0) {
for (TaskSampleRelation sampleRelation : partRelations) {
sampleRelation.setTaskId(task.getId());
}
......@@ -688,7 +775,7 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task>implements Tas
// 任务与整车样品关系
List<TaskSampleRelation> sampleRelations = taskSampleRelationMapper.selectByTaskId(request.getId(),TaskSampleRelation.COMPLETE_VEHICLE_SAMPLE);
if (sampleRelations.size() != 0 && sampleRelations != null) {
if (sampleRelations != null && sampleRelations.size() != 0) {
// 获取之前的第一个企业名称
TaskSampleRelation taskSampleRelation = sampleRelations.get(0);
Sample oldSample = sampleManagementMapper.selectSampleManagementById(taskSampleRelation.getSampleId());
......@@ -704,7 +791,7 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task>implements Tas
// 留档文件
List<ReviewEnterpriseArchive> reviewEnterpriseArchiveList = reviewEnterpriseArchiveMapper.findList(request.getId());
if (reviewEnterpriseArchiveList.size() != 0 && reviewEnterpriseArchiveList != null) {
if (reviewEnterpriseArchiveList != null && reviewEnterpriseArchiveList.size() != 0) {
for (ReviewEnterpriseArchive reviewEnterpriseArchive : reviewEnterpriseArchiveList) {
reviewEnterpriseArchive.setEnterpriseName(newAutomobileEnterprise.getEnterpriseName());
}
......@@ -831,7 +918,7 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task>implements Tas
public List<Sample> setSampleList(Long id,String type) {
// 样品信息
List<TaskSampleRelation> relationList = taskSampleRelationService.selectByTaskId(id,type);
if (relationList.size() != 0 && relationList != null) {
if (relationList != null && relationList.size() != 0) {
List<Sample> SampleList = sampleManagementMapper.findByIdList(relationList,id);
return SampleList;
} else {
......
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.StringUtils;
import com.ruoyi.domain.TestRecords;
import com.ruoyi.domain.vo.CaseResultVO;
import com.ruoyi.domain.vo.StepResultVO;
import com.ruoyi.mapper.TestRecordsMapper;
import com.ruoyi.service.TestRecordsService;
import okhttp3.Request;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.Map;
import java.util.*;
@Transactional
@Service
public class TestRecordsServiceImpl extends ServiceImpl<TestRecordsMapper, TestRecords> implements TestRecordsService {
@Autowired
private TestRecordsService testRecordsService;
public void getValue() throws IOException {
JSONObject jsonObject = getInverseParamByUrl("http://10.12.48.78:8090/DescribeProjectTestResult");
}
@Autowired
private TestRecordsMapper testRecordsMapper;
@Override
public void sendPost(String id) {
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);
public static JSONObject getInverseParamByUrl(String apiUrl) throws IOException {
// 调用请求
URL url = new URL(apiUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
StringBuilder response = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
response.append(line);
List<TestRecords> list = new ArrayList<>();
if (caseResultVOS.size() != 0 && caseResultVOS != null) {
for (CaseResultVO caseResultVO : caseResultVOS) {
// 检查 usecaseId 是否在 recordsList 中存在
boolean exists = false;
if (recordsList.size() != 0 && recordsList != null) {
for (TestRecords records : recordsList) {
if (Objects.equals(caseResultVO.getId(), records.getUsecaseId())) {
exists = true;
break;
}
}
reader.close();
// 解析成JSON对象
String jsonResponseString = response.toString();
JSONObject jsonObject = JSONObject.parseObject(jsonResponseString);
return jsonObject;
}
public static String doPost(String url, JSONObject json){
try {
CloseableHttpClient httpClient = HttpClientBuilder.create().build();
HttpPost post = new HttpPost(url);
// 首先Header部分需要设定字符集为:uft-8
post.addHeader("Content-Type", "application/json;charset=utf-8");
// 此处也需要设定
post.setHeader("Accept", "*/*");
post.setHeader("Accept-Encoding", "gzip, deflate, br");
post.setHeader("Connection", "keep-alive");
// post.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Safari/537.36");
post.setEntity(new StringEntity(json.toString(), Charset.forName("UTF-8"))); //设置请求参数
HttpResponse response = httpClient.execute(post);
int statusCode = response.getStatusLine().getStatusCode();
if (HttpStatus.SC_OK == statusCode){
//返回String
String res = EntityUtils.toString(response.getEntity());
System.out.println(res);
return res;
}else{
return "调用POST请求失败";
if ((Objects.equals(caseResultVO.getStatus(), "PASSED") || Objects.equals(caseResultVO.getStatus(), "FAILED")) && !exists) {
TestRecords testRecords = new TestRecords();
testRecords.setTaskId(projectId);
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.size() != 0 && stepResultVOS != null) {
List<String> stepList = new ArrayList<>();
for (StepResultVO stepResultVO :stepResultVOS) {
String stepName = stepResultVO.getName();
stepList.add(stepName);
}
testRecords.setTestMethod(StringUtils.join(stepList,","));
}
list.add(testRecords);
} catch (Exception e) {
e.printStackTrace();
return "调用POST请求失败";
}
}
// public static void main(String[] args) {
// Map<String, Object> map = new HashMap<>();
// map.put("id", "project_items;1");
// map.put("verbose", "ALL");
// JSONObject json = new JSONObject(map);
//
// //以post形式请求接口
// String result = doPost("http://10.12.48.78:8090/DescribeProjectTestResult", json);
// JSONObject jsonObject = JSONObject.parseObject(result);
// String data = jsonObject.get("data").toString();
//
// System.out.println("data = " + data);
// }
// public static void main(String[] args) {
//
// try {
// String apiUrl = "http://10.12.48.78:8090/DescribeProjectTestResult"; // 第三方URL
//
//
// URL url = new URL(apiUrl);
// HttpURLConnection conn = (HttpURLConnection) url.openConnection();
// conn.setRequestMethod("POST");
// conn.setDoInput(true);
// conn.setDoOutput(true);
//
// // 参数设置 ||
// conn.setRequestProperty("Content-Type","application/json");
// conn.connect();
//
// // 设置请求体
// OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream(),"UTF-8");
// JSONObject parm = new JSONObject();
// parm.put("id","project_items;1");
// parm.put("verbose","ALL");
// writer.write(URLEncoder.encode(parm.toString(),"UTF-8"));
// writer.flush();
//
//
// int responseCode = conn.getResponseCode();
// if (responseCode == HttpURLConnection.HTTP_OK) {
// BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream(),"UTF-8"));
// String inputLine;
// StringBuilder response = new StringBuilder();
//// StringBuffer response = new StringBuffer();
//
// while ((inputLine = in.readLine()) != null) {
// response.append(inputLine);
// }
// in.close();
// conn.disconnect();
//
// String result = response.toString();
// System.out.println("result = " + result);
//
//// String responseBody = response.toString();
//// JSONObject jsonObject = JSONObject.parseObject(responseBody);
//// System.out.println("Response body: " + responseBody);
//// System.out.println("jsonObject = " + jsonObject);
// } else {
// System.out.println("Request failed. Response code: " + responseCode);
// }
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
testRecordsService.saveBatch(list);
}
}
@Override
public List<TestRecords> findByTaskId(String id) {
return testRecordsMapper.findByTaskId(id);
}
}
......@@ -2,6 +2,7 @@ package com.ruoyi.web.request;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.common.core.domain.entity.SysDictData;
import com.ruoyi.domain.TaskFileRelation;
import com.ruoyi.domain.TaskSampleRelation;
import com.ruoyi.domain.TaskUserRelation;
import io.swagger.annotations.Api;
......@@ -65,4 +66,7 @@ public class TaskCreateRequest {
@ApiModelProperty("选择的测试场景")
private List<Long> testScenarioList;
@ApiModelProperty("上传的文件")
private List<TaskFileRelation> fileList;
}
......@@ -3,6 +3,7 @@ package com.ruoyi.web.request;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.domain.TaskFileRelation;
import com.ruoyi.domain.TaskSampleRelation;
import com.ruoyi.domain.TaskUserRelation;
import io.swagger.annotations.ApiModel;
......@@ -69,4 +70,7 @@ public class TaskEditRequest {
@ApiModelProperty("选择的测试场景")
private List<Long> testScenarioList;
@ApiModelProperty("上传的文件")
private List<TaskFileRelation> fileList;
}
......@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.domain.Sample;
import com.ruoyi.domain.TaskFileRelation;
import com.ruoyi.domain.TaskSampleRelation;
import com.ruoyi.domain.TaskUserRelation;
import io.swagger.annotations.ApiModel;
......@@ -130,4 +131,7 @@ public class TaskGetInfoResponse {
@ApiModelProperty("测试场景")
private List<Long> testScenarioList;
@ApiModelProperty("上传的文件")
private List<TaskFileRelation> fileList;
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.mapper.ModelTestTaskMapper">
<resultMap id="BaseResultMap" type="com.ruoyi.domain.ModelTestTask">
<id property="id" column="id" jdbcType="BIGINT"/>
<result property="taskNo" column="task_no" jdbcType="VARCHAR"/>
<result property="taskStatus" column="task_status" jdbcType="VARCHAR"/>
<result property="taskInitiator" column="task_initiator" jdbcType="VARCHAR"/>
<result property="taskInitiatorDept" column="task_initiator_dept" jdbcType="VARCHAR"/>
<result property="taskResult" column="task_result" jdbcType="VARCHAR"/>
<result property="taskBeginTime" column="task_begin_time" jdbcType="TIMESTAMP"/>
<result property="taskEndTime" column="task_end_time" jdbcType="TIMESTAMP"/>
<result property="testCase" column="test_case" typeHandler="com.ruoyi.common.StandardJsonTypeHandler"/>
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
<result property="leaderId" column="leader_id" jdbcType="BIGINT"/>
<result property="leader" column="leader" jdbcType="VARCHAR"/>
<result property="standardId" column="standard_id" jdbcType="BIGINT"/>
<result property="name" column="name" jdbcType="VARCHAR"/>
<result property="standardNo" column="standard_no" jdbcType="VARCHAR"/>
<result property="submitId" column="submit_id" jdbcType="BIGINT"/>
<result property="submitName" column="submit_name" jdbcType="VARCHAR"/>
<result property="imagesUrl" column="images_url" jdbcType="VARCHAR"/>
<result property="details" column="details" jdbcType="INTEGER"/>
<result property="standards" column="standards" jdbcType="INTEGER"/>
<result property="testSchemeId" column="test_scheme_id" jdbcType="VARCHAR"/>
</resultMap>
<select id="findByStatus" resultType="com.ruoyi.domain.ModelTestTask">
SELECT id,task_no,task_status,task_initiator,task_initiator_dept,task_result,task_begin_time,task_end_time,test_case,create_time,leader_id,leader,standard_id,name,standard_no,submit_id,submit_name,images_url,details,standards,test_scheme_id
FROM t_model_test_task WHERE task_status = 'PENDING'
</select>
</mapper>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.mapper.TaskFileRelationMapper">
<resultMap id="BaseResultMap" type="com.ruoyi.domain.TaskFileRelation">
<result property="taskId" column="task_id" jdbcType="BIGINT"/>
<result property="url" column="url" jdbcType="VARCHAR"/>
<result property="name" column="name" jdbcType="VARCHAR"/>
</resultMap>
<select id="findByTaskId" resultType="com.ruoyi.domain.TaskFileRelation">
select task_id,url,name from t_task_file_relation
where task_id = #{taskId}
</select>
</mapper>
......@@ -328,6 +328,19 @@
where t.id = #{taskId}
group by t.id
</select>
<select id="findByName" resultType="com.ruoyi.domain.Task">
SELECT id, system_review_task_id, car_review_task_id,model_test_task_id,
task_status,run_status,task_no,task_name,confidentiality_level,
product_name,product_model,
entrusted_unit,entrusted_unit_address,entrusted_unit_phone,
entrusted_unit_code,vehicle_sample_information,part_sample_information,
task_initiator_id,task_initiator,task_initiator_dept,
task_begin_time,task_end_time,create_time,
leader_id,leader,standard_id,name,
standard_no,file,task_list
FROM t_task
WHERE task_name = #{taskName}
</select>
</mapper>
......@@ -10,13 +10,17 @@
<result property="usecase" column="usecase" jdbcType="VARCHAR"/>
<result property="usecaseId" column="usecase_id" jdbcType="VARCHAR"/>
<result property="testTime" column="test_time" jdbcType="TIMESTAMP"/>
<result property="description" column="description" jdbcType="VARCHAR"/>
<result property="description" column="description" jdbcType="LONGNVARCHAR"/>
<result property="riskLevel" column="risk_level" jdbcType="VARCHAR"/>
<result property="testMethod" column="test_method" jdbcType="VARCHAR"/>
<result property="testMethod" column="test_method" jdbcType="LONGNVARCHAR"/>
<result property="testResult" column="test_result" jdbcType="VARCHAR"/>
<result property="testResultDescription" column="test_result_description" jdbcType="VARCHAR"/>
<result property="loophole" column="loophole" jdbcType="VARCHAR"/>
<result property="remediation" column="remediation" jdbcType="VARCHAR"/>
</resultMap>
<select id="findByTaskId" resultType="com.ruoyi.domain.TestRecords">
SELECT id, task_id, usecase, usecase_id, test_time, description, risk_level, test_method, test_result, remediation
FROM t_test_records
WHERE task_id = #{id}
</select>
</mapper>
......@@ -148,3 +148,7 @@ minio:
accessKey: ${MINIO_ACCESSKEY}
secretKey: ${MINIO_SECRETKEY}
bucketName: vehicle-quality-review-oss
# 定时任务开启状态
task:
scheduling: true
\ No newline at end of file
......@@ -150,3 +150,8 @@ minio:
accessKey: lB7WhZYiQwLzhHPutRGn
secretKey: 7XMWpLm6p4d20OFe9uXKifEyhF3cp4sTCowI2fhJ
bucketName: vehicle-quality-review-oss
# 定时任务开启状态
task:
scheduling: true
\ No newline at end of file
package com.ruoyi;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.domain.TestRecords;
import com.ruoyi.domain.vo.CaseResultVO;
import com.ruoyi.domain.vo.StepResultVO;
import com.ruoyi.mapper.TestRecordsMapper;
import com.ruoyi.service.TestRecordsService;
import com.ruoyi.service.impl.TestRecordsServiceImpl;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import java.util.*;
@SpringBootTest
public class TestRecordsTest {
@Autowired
private TestRecordsService testRecordsService;
@Autowired
private TestRecordsMapper testRecordsMapper;
@Test
public void test() {
Map<String, Object> map = new HashMap<>();
map.put("id", "project_items;27");
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("project_items;29");
List<TestRecords> list = new ArrayList<>();
if (caseResultVOS.size() != 0 && caseResultVOS != null) {
for (CaseResultVO caseResultVO : caseResultVOS) {
// 检查 usecaseId 是否在 recordsList 中存在
boolean exists = false;
if (recordsList.size() != 0 && recordsList != null) {
for (TestRecords records : recordsList) {
if (Objects.equals(caseResultVO.getId(), records.getUsecaseId())) {
exists = true;
break;
}
}
}
if ((Objects.equals(caseResultVO.getStatus(), "PASSED") || Objects.equals(caseResultVO.getStatus(), "FAILED")) && !exists) {
TestRecords testRecords = new TestRecords();
testRecords.setTaskId(projectId);
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.size() != 0 && stepResultVOS != null) {
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);
}
}
}
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