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 { ...@@ -44,9 +44,6 @@ public class TestRecords {
@ApiModelProperty("测试结果") @ApiModelProperty("测试结果")
private String testResult; private String testResult;
@ApiModelProperty("测试结果描述") @ApiModelProperty("修复建议")
private String testResultDescription; private String remediation;
@ApiModelProperty("漏洞危害")
private String loophole;
} }
...@@ -4,10 +4,15 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; ...@@ -4,10 +4,15 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.domain.ModelTestTask; import com.ruoyi.domain.ModelTestTask;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.List;
/** /**
* 车型试验Mapper层 * 车型试验Mapper层
* @author gxk * @author gxk
*/ */
@Repository @Repository
public interface ModelTestTaskMapper extends BaseMapper<ModelTestTask> { 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> { ...@@ -37,6 +37,8 @@ public interface TaskMapper extends BaseMapper<Task> {
Long findTaskName(@Param("taskName") String taskName); Long findTaskName(@Param("taskName") String taskName);
Task findByName(@Param("taskName") String taskName);
/** /**
* 通过总任务ID,获取企业文件数据 * 通过总任务ID,获取企业文件数据
* @param taskId * @param taskId
......
...@@ -2,8 +2,13 @@ package com.ruoyi.mapper; ...@@ -2,8 +2,13 @@ package com.ruoyi.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.domain.TestRecords; import com.ruoyi.domain.TestRecords;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.List;
@Repository @Repository
public interface TestRecordsMapper extends BaseMapper<TestRecords> { 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; ...@@ -3,5 +3,20 @@ package com.ruoyi.service;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.ruoyi.domain.TestRecords; import com.ruoyi.domain.TestRecords;
import java.util.List;
public interface TestRecordsService extends IService<TestRecords> { 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 ...@@ -100,6 +100,9 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task>implements Tas
@Autowired @Autowired
private TaskScenarioRelationMapper taskScenarioRelationMapper; private TaskScenarioRelationMapper taskScenarioRelationMapper;
@Autowired
private TaskFileRelationService taskFileRelationService;
@Override @Override
public List<Task> findList(TaskListRequest request) { public List<Task> findList(TaskListRequest request) {
return taskMapper.findList(request); return taskMapper.findList(request);
...@@ -108,13 +111,36 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task>implements Tas ...@@ -108,13 +111,36 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task>implements Tas
@Override @Override
public void createTask(TaskCreateRequest request) { 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()); Long sum = taskMapper.findTaskName(request.getTaskName());
if (sum > 0) { if (sum > 0) {
throw new ServiceException("任务名称重复,请检查", HttpStatus.ERROR); throw new ServiceException("任务名称重复,请检查", HttpStatus.ERROR);
} else { } else {
// 构建任务创建者
LoginUser loginUser = SecurityUtils.getLoginUser();
SysUser initiator = sysUserService.selectUserById(loginUser.getUserId()); SysUser initiator = sysUserService.selectUserById(loginUser.getUserId());
Standard standard = standardService.findListById(request.getStandardId()); Standard standard = standardService.findListById(request.getStandardId());
...@@ -172,12 +198,11 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task>implements Tas ...@@ -172,12 +198,11 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task>implements Tas
List<TaskSampleRelation> partRelations = request.getPartSample(); List<TaskSampleRelation> partRelations = request.getPartSample();
saveSampleRelation(relations,partRelations,task); saveSampleRelation(relations,partRelations,task);
// 保存任务关联的文件信息
saveFileList(request.getFileList(),task);
taskStateFacade.doCreate(task, request.getTaskList()); taskStateFacade.doCreate(task, request.getTaskList());
TaskGetInfoResponse temporaryStorageTask = taskService.getByUserId(loginUser.getUserId());
if(temporaryStorageTask != null) {
taskMapper.deleteById(temporaryStorageTask.getId());
}
} }
} }
...@@ -265,46 +290,56 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task>implements Tas ...@@ -265,46 +290,56 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task>implements Tas
@Override @Override
public void editTask(TaskEditRequest request) { public void editTask(TaskEditRequest request) {
// 构建任务创建者 Task oldTask = taskMapper.findByName(request.getTaskName());
LoginUser loginUser = SecurityUtils.getLoginUser();
SysUser initiator = sysUserService.selectUserById(loginUser.getUserId()); if (oldTask == null || Objects.equals(oldTask.getId(), request.getId())) {
Standard standard = standardService.findListById(request.getStandardId()); // 构建任务创建者
LoginUser loginUser = SecurityUtils.getLoginUser();
// 找到审查组长 SysUser initiator = sysUserService.selectUserById(loginUser.getUserId());
TaskUserRelation leader = null; Standard standard = standardService.findListById(request.getStandardId());
List<TaskUserRelation> auditors = request.getAuditors();
for(TaskUserRelation auditor : auditors) { // 找到审查组长
if(auditor.getIsLeader() == 1) { TaskUserRelation leader = null;
leader = auditor; List<TaskUserRelation> auditors = request.getAuditors();
break; for(TaskUserRelation auditor : auditors) {
if(auditor.getIsLeader() == 1) {
leader = auditor;
break;
}
} }
}
// 构建并保存任务信息 // 构建并保存任务信息
// 总任务 // 总任务
Task task = taskMapper.selectById(request.getId()); Task task = taskMapper.selectById(request.getId());
task.setLeaderId(leader.getUserId()); task.setLeaderId(leader.getUserId());
task.setLeader(leader.getName()); task.setLeader(leader.getName());
setTaskList(request.getTaskList(),task); setTaskList(request.getTaskList(),task);
BeanUtils.copyBeanProp(task, request); BeanUtils.copyBeanProp(task, request);
// 子任务发送变化 // 子任务发送变化
changeSubTask(request,task,initiator,standard,leader); changeSubTask(request,task,initiator,standard,leader);
task.setMaxPointer(request.getTaskList().size()); task.setMaxPointer(request.getTaskList().size());
taskService.updateById(task); taskService.updateById(task);
// 构建并保存该任务所关联的审核组信息 // 构建并保存该任务所关联的审核组信息
saveUserRelation(auditors,task); saveUserRelation(auditors,task);
// 判断第一个整车样品的生产企业是否变化 // 判断第一个整车样品的生产企业是否变化
judgmentSample(request); judgmentSample(request);
// 保存关联的整车样品信息和零部件样品信息
List<TaskSampleRelation> relations = request.getSample();
List<TaskSampleRelation> partRelations = request.getPartSample();
saveSampleRelation(relations,partRelations,task);
// 保存任务关联的文件信息
saveFileList(request.getFileList(),task);
} else {
throw new ServiceException("任务名称重复,请检查", HttpStatus.ERROR);
}
// 保存关联的整车样品信息和零部件样品信息
List<TaskSampleRelation> relations = request.getSample();
List<TaskSampleRelation> partRelations = request.getPartSample();
saveSampleRelation(relations,partRelations,task);
} }
...@@ -358,6 +393,11 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task>implements Tas ...@@ -358,6 +393,11 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task>implements Tas
if (task != null) { if (task != null) {
BeanUtils.copyBeanProp(response, task); BeanUtils.copyBeanProp(response, task);
if (response.getTaskList().startsWith(",")) {
String taskList = response.getTaskList().substring(1);
response.setTaskList(taskList);
}
// 测试场景 // 测试场景
response.setTestScenarioList(selectTestScenarioList(task)); response.setTestScenarioList(selectTestScenarioList(task));
...@@ -370,6 +410,9 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task>implements Tas ...@@ -370,6 +410,9 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task>implements Tas
// 零部件样品信息 // 零部件样品信息
response.setPartVehicleSample(setSampleList(request.getId(),TaskSampleRelation.PART_VEHICLE_SAMPLE)); response.setPartVehicleSample(setSampleList(request.getId(),TaskSampleRelation.PART_VEHICLE_SAMPLE));
// 上传的文件
response.setFileList(taskFileRelationService.findByTaskId(request.getId()));
return response; return response;
} else { } else {
return null; return null;
...@@ -405,111 +448,129 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task>implements Tas ...@@ -405,111 +448,129 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task>implements Tas
@Override @Override
public void temporaryStorageTask(TaskCreateRequest request) { public void temporaryStorageTask(TaskCreateRequest request) {
// 构建任务创建者 Long sum = taskMapper.findTaskName(request.getTaskName());
LoginUser loginUser = SecurityUtils.getLoginUser(); if (sum > 0) {
SysUser initiator = sysUserService.selectUserById(loginUser.getUserId()); throw new ServiceException("任务名称重复,请检查", HttpStatus.ERROR);
Standard standard = standardService.findListById(request.getStandardId()); } else {
// 构建任务创建者
LoginUser loginUser = SecurityUtils.getLoginUser();
SysUser initiator = sysUserService.selectUserById(loginUser.getUserId());
Standard standard = standardService.findListById(request.getStandardId());
// 构建并保存任务信息 // 构建并保存任务信息
// 总任务 // 总任务
Task task = new Task(); Task task = new Task();
task.setTaskInitiatorId(loginUser.getUserId()); task.setTaskInitiatorId(loginUser.getUserId());
task.setTaskInitiator(initiator.getNickName()); task.setTaskInitiator(initiator.getNickName());
if (initiator.getDept() != null) { if (initiator.getDept() != null) {
task.setTaskInitiatorDept(initiator.getDept().getDeptName()); task.setTaskInitiatorDept(initiator.getDept().getDeptName());
} }
task.setTaskStatus(Task.TASK_STATUS_TEMPORARILY); task.setTaskStatus(Task.TASK_STATUS_TEMPORARILY);
String joinTaskList = StringUtils.join(request.getTaskList(),","); String joinTaskList = StringUtils.join(request.getTaskList(),",");
task.setTaskList(joinTaskList); task.setTaskList(joinTaskList);
BeanUtils.copyBeanProp(task, request); BeanUtils.copyBeanProp(task, request);
if (standard != null) { if (standard != null) {
task.setName(standard.getName()); task.setName(standard.getName());
task.setStandardNo(standard.getStandardNo()); task.setStandardNo(standard.getStandardNo());
task.setFile(standard.getFile()); task.setFile(standard.getFile());
} }
// 找到审查组长 // 找到审查组长
TaskUserRelation leader = null; TaskUserRelation leader = null;
List<TaskUserRelation> auditors = request.getAuditors(); List<TaskUserRelation> auditors = request.getAuditors();
if (auditors.size() != 0 && auditors != null) { if (auditors.size() != 0 && auditors != null) {
for(TaskUserRelation auditor : auditors) { for(TaskUserRelation auditor : auditors) {
if(auditor.getIsLeader() == 1) { if(auditor.getIsLeader() == 1) {
leader = auditor; leader = auditor;
break; break;
}
} }
// 任务组长
task.setLeaderId(leader.getUserId());
task.setLeader(leader.getName());
} }
// 任务组长 // 暂存
task.setLeaderId(leader.getUserId()); taskService.save(task);
task.setLeader(leader.getName());
}
// 暂存 // 测试场景
taskService.save(task); saveTaskScenario(task.getId(), request.getTestScenarioList());
// 测试场景 // 保存任务与小组信息
saveTaskScenario(task.getId(), request.getTestScenarioList()); saveUserRelation(auditors,task);
// 保存任务与小组信息 // 保存关联的整车样品信息和零部件样品信息
saveUserRelation(auditors,task); List<TaskSampleRelation> relations = request.getSample();
List<TaskSampleRelation> partRelations = request.getPartSample();
saveSampleRelation(relations,partRelations,task);
// 保存关联的整车样品信息和零部件样品信息 // 保存任务关联的文件信息
List<TaskSampleRelation> relations = request.getSample(); saveFileList(request.getFileList(),task);
List<TaskSampleRelation> partRelations = request.getPartSample(); }
saveSampleRelation(relations,partRelations,task);
} }
@Override @Override
public void editTemporaryStorageTask(TaskEditRequest request) { public void editTemporaryStorageTask(TaskEditRequest request) {
// 构建任务创建者
LoginUser loginUser = SecurityUtils.getLoginUser();
SysUser initiator = sysUserService.selectUserById(loginUser.getUserId());
Standard standard = standardService.findListById(request.getStandardId());
// 构建并保存任务信息 Task oldTask = taskMapper.findByName(request.getTaskName());
// 总任务
Task task = new Task();
String joinTaskList = StringUtils.join(request.getTaskList(),",");
task.setTaskList(joinTaskList);
BeanUtils.copyBeanProp(task, request);
if (standard != null) { if (oldTask == null || Objects.equals(oldTask.getId(), request.getId())) {
task.setName(standard.getName()); // 构建任务创建者
task.setStandardNo(standard.getStandardNo()); LoginUser loginUser = SecurityUtils.getLoginUser();
task.setFile(standard.getFile()); SysUser initiator = sysUserService.selectUserById(loginUser.getUserId());
} Standard standard = standardService.findListById(request.getStandardId());
// 构建并保存任务信息
// 总任务
Task task = new Task();
String joinTaskList = StringUtils.join(request.getTaskList(),",");
task.setTaskList(joinTaskList);
BeanUtils.copyBeanProp(task, request);
taskScenarioRelationMapper.delete(new QueryWrapper<TaskScenarioRelation>().lambda().eq(TaskScenarioRelation::getTaskId, task.getId())); if (standard != null) {
saveTaskScenario(task.getId(), request.getTestScenarioList()); task.setName(standard.getName());
task.setStandardNo(standard.getStandardNo());
task.setFile(standard.getFile());
}
// 找到审查组长 taskScenarioRelationMapper.delete(new QueryWrapper<TaskScenarioRelation>().lambda().eq(TaskScenarioRelation::getTaskId, task.getId()));
TaskUserRelation leader = null; saveTaskScenario(task.getId(), request.getTestScenarioList());
List<TaskUserRelation> auditors = request.getAuditors();
if (auditors.size() != 0 && auditors != null) { // 找到审查组长
for(TaskUserRelation auditor : auditors) { TaskUserRelation leader = null;
if(auditor.getIsLeader() == 1) { List<TaskUserRelation> auditors = request.getAuditors();
leader = auditor; if (auditors.size() != 0 && auditors != null) {
break; for(TaskUserRelation auditor : auditors) {
if(auditor.getIsLeader() == 1) {
leader = auditor;
break;
}
} }
// 任务组长
task.setLeaderId(leader.getUserId());
task.setLeader(leader.getName());
} }
// 任务组长
task.setLeaderId(leader.getUserId());
task.setLeader(leader.getName());
}
// 更新暂存 // 更新暂存
taskService.updateById(task); taskService.updateById(task);
// 保存任务与小组信息 // 保存任务与小组信息
saveUserRelation(auditors,task); saveUserRelation(auditors,task);
// 保存关联的整车样品信息 // 保存关联的整车样品信息
List<TaskSampleRelation> relations = request.getSample(); List<TaskSampleRelation> relations = request.getSample();
List<TaskSampleRelation> partRelations = request.getPartSample(); List<TaskSampleRelation> partRelations = request.getPartSample();
saveSampleRelation(relations,partRelations,task); saveSampleRelation(relations,partRelations,task);
// 保存任务关联的文件信息
saveFileList(request.getFileList(),task);
} else {
throw new ServiceException("任务名称重复,请检查", HttpStatus.ERROR);
}
} }
...@@ -523,6 +584,11 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task>implements Tas ...@@ -523,6 +584,11 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task>implements Tas
BeanUtils.copyBeanProp(response, task); BeanUtils.copyBeanProp(response, task);
if (response.getTaskList().startsWith(",")) {
String taskList = response.getTaskList().substring(1);
response.setTaskList(taskList);
}
// 测试场景 // 测试场景
response.setTestScenarioList(selectTestScenarioList(task)); response.setTestScenarioList(selectTestScenarioList(task));
...@@ -535,6 +601,9 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task>implements Tas ...@@ -535,6 +601,9 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task>implements Tas
// 零部件样品信息 // 零部件样品信息
response.setPartVehicleSample(setSampleList(task.getId(), TaskSampleRelation.PART_VEHICLE_SAMPLE)); response.setPartVehicleSample(setSampleList(task.getId(), TaskSampleRelation.PART_VEHICLE_SAMPLE));
// 上传的文件
response.setFileList(taskFileRelationService.findByTaskId(task.getId()));
return response; return response;
} else { } else {
return null; return null;
...@@ -634,11 +703,11 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task>implements Tas ...@@ -634,11 +703,11 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task>implements Tas
private void saveUserRelation(List<TaskUserRelation> auditors,Task task) { private void saveUserRelation(List<TaskUserRelation> auditors,Task task) {
// 构建并保存该任务所关联的审核组信息 // 构建并保存该任务所关联的审核组信息
List<TaskUserRelation> list = taskUserRelationService.selectQTeamMembers(task.getId()); List<TaskUserRelation> list = taskUserRelationService.selectQTeamMembers(task.getId());
if (list.size() != 0 && list != null) { if (list != null && list.size() != 0) {
taskUserRelationService.removeBatchByIds(list); taskUserRelationService.removeBatchByIds(list);
} }
if (auditors.size() != 0 && auditors != null) { if (auditors != null && auditors.size() != 0) {
// 构建并保存该任务所关联的审核组信息 // 构建并保存该任务所关联的审核组信息
for(TaskUserRelation auditor : auditors) { for(TaskUserRelation auditor : auditors) {
auditor.setTaskId(task.getId()); auditor.setTaskId(task.getId());
...@@ -648,15 +717,33 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task>implements Tas ...@@ -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) { private void saveSampleRelation(List<TaskSampleRelation> relations,List<TaskSampleRelation> partRelations,Task task) {
// 整车 // 整车
List<TaskSampleRelation> relationList = taskSampleRelationService.selectByTaskId(task.getId(),TaskSampleRelation.COMPLETE_VEHICLE_SAMPLE); 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); taskSampleRelationService.removeBatchByIds(relationList);
} }
if (relations.size() != 0 && relations != null) { if (relations != null && relations.size() != 0) {
for (TaskSampleRelation sampleRelation : relations) { for (TaskSampleRelation sampleRelation : relations) {
sampleRelation.setTaskId(task.getId()); sampleRelation.setTaskId(task.getId());
} }
...@@ -666,11 +753,11 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task>implements Tas ...@@ -666,11 +753,11 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task>implements Tas
// 零件 // 零件
List<TaskSampleRelation> partRelationList = taskSampleRelationService.selectByTaskId(task.getId(),TaskSampleRelation.PART_VEHICLE_SAMPLE); 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); taskSampleRelationService.removeBatchByIds(partRelationList);
} }
if (partRelations.size() != 0 && partRelations != null) { if (partRelations != null && partRelations.size() != 0) {
for (TaskSampleRelation sampleRelation : partRelations) { for (TaskSampleRelation sampleRelation : partRelations) {
sampleRelation.setTaskId(task.getId()); sampleRelation.setTaskId(task.getId());
} }
...@@ -688,7 +775,7 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task>implements Tas ...@@ -688,7 +775,7 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task>implements Tas
// 任务与整车样品关系 // 任务与整车样品关系
List<TaskSampleRelation> sampleRelations = taskSampleRelationMapper.selectByTaskId(request.getId(),TaskSampleRelation.COMPLETE_VEHICLE_SAMPLE); 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); TaskSampleRelation taskSampleRelation = sampleRelations.get(0);
Sample oldSample = sampleManagementMapper.selectSampleManagementById(taskSampleRelation.getSampleId()); Sample oldSample = sampleManagementMapper.selectSampleManagementById(taskSampleRelation.getSampleId());
...@@ -704,7 +791,7 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task>implements Tas ...@@ -704,7 +791,7 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task>implements Tas
// 留档文件 // 留档文件
List<ReviewEnterpriseArchive> reviewEnterpriseArchiveList = reviewEnterpriseArchiveMapper.findList(request.getId()); List<ReviewEnterpriseArchive> reviewEnterpriseArchiveList = reviewEnterpriseArchiveMapper.findList(request.getId());
if (reviewEnterpriseArchiveList.size() != 0 && reviewEnterpriseArchiveList != null) { if (reviewEnterpriseArchiveList != null && reviewEnterpriseArchiveList.size() != 0) {
for (ReviewEnterpriseArchive reviewEnterpriseArchive : reviewEnterpriseArchiveList) { for (ReviewEnterpriseArchive reviewEnterpriseArchive : reviewEnterpriseArchiveList) {
reviewEnterpriseArchive.setEnterpriseName(newAutomobileEnterprise.getEnterpriseName()); reviewEnterpriseArchive.setEnterpriseName(newAutomobileEnterprise.getEnterpriseName());
} }
...@@ -831,7 +918,7 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task>implements Tas ...@@ -831,7 +918,7 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task>implements Tas
public List<Sample> setSampleList(Long id,String type) { public List<Sample> setSampleList(Long id,String type) {
// 样品信息 // 样品信息
List<TaskSampleRelation> relationList = taskSampleRelationService.selectByTaskId(id,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); List<Sample> SampleList = sampleManagementMapper.findByIdList(relationList,id);
return SampleList; return SampleList;
} else { } else {
......
package com.ruoyi.service.impl; package com.ruoyi.service.impl;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson2.JSONObject; import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.domain.TestRecords; 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.mapper.TestRecordsMapper;
import com.ruoyi.service.TestRecordsService; import com.ruoyi.service.TestRecordsService;
import okhttp3.Request; import org.springframework.beans.factory.annotation.Autowired;
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.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.io.*; import java.util.*;
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;
@Transactional @Transactional
@Service @Service
public class TestRecordsServiceImpl extends ServiceImpl<TestRecordsMapper, TestRecords> implements TestRecordsService { public class TestRecordsServiceImpl extends ServiceImpl<TestRecordsMapper, TestRecords> implements TestRecordsService {
@Autowired
private TestRecordsService testRecordsService;
public void getValue() throws IOException { @Autowired
JSONObject jsonObject = getInverseParamByUrl("http://10.12.48.78:8090/DescribeProjectTestResult"); private TestRecordsMapper testRecordsMapper;
}
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);
}
reader.close();
// 解析成JSON对象
String jsonResponseString = response.toString();
JSONObject jsonObject = JSONObject.parseObject(jsonResponseString);
return jsonObject;
}
public static String doPost(String url, JSONObject json){ @Override
try { public void sendPost(String id) {
CloseableHttpClient httpClient = HttpClientBuilder.create().build();
HttpPost post = new HttpPost(url); Map<String, Object> map = new HashMap<>();
map.put("id", id);
// 首先Header部分需要设定字符集为:uft-8 map.put("verbose", "ALL");
post.addHeader("Content-Type", "application/json;charset=utf-8");
// 此处也需要设定 //以post形式请求接口
post.setHeader("Accept", "*/*"); String result= HttpUtil.post("https://10.12.48.78:8090/DescribeProjectTestResult",JSONObject.toJSONString(map));
post.setHeader("Accept-Encoding", "gzip, deflate, br");
post.setHeader("Connection", "keep-alive"); JSONObject jsonObject = JSONObject.parseObject(result);
// 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"))); //设置请求参数 // 获取项目id
HttpResponse response = httpClient.execute(post); String projectId = (String) jsonObject.get("id");
int statusCode = response.getStatusLine().getStatusCode();
if (HttpStatus.SC_OK == statusCode){ // 获取项目用例结果列表
//返回String List<CaseResultVO> caseResultVOS = jsonObject.getList("case_result_list", CaseResultVO.class);
String res = EntityUtils.toString(response.getEntity());
System.out.println(res); // 获取本地存储的列表
return res; List<TestRecords> recordsList = testRecordsService.findByTaskId(id);
}else{
return "调用POST请求失败"; 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);
}
} }
} catch (Exception e) { testRecordsService.saveBatch(list);
e.printStackTrace();
return "调用POST请求失败";
} }
} }
// public static void main(String[] args) { @Override
// Map<String, Object> map = new HashMap<>(); public List<TestRecords> findByTaskId(String id) {
// map.put("id", "project_items;1"); return testRecordsMapper.findByTaskId(id);
// 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();
// }
// }
} }
...@@ -2,6 +2,7 @@ package com.ruoyi.web.request; ...@@ -2,6 +2,7 @@ package com.ruoyi.web.request;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.common.core.domain.entity.SysDictData; import com.ruoyi.common.core.domain.entity.SysDictData;
import com.ruoyi.domain.TaskFileRelation;
import com.ruoyi.domain.TaskSampleRelation; import com.ruoyi.domain.TaskSampleRelation;
import com.ruoyi.domain.TaskUserRelation; import com.ruoyi.domain.TaskUserRelation;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
...@@ -65,4 +66,7 @@ public class TaskCreateRequest { ...@@ -65,4 +66,7 @@ public class TaskCreateRequest {
@ApiModelProperty("选择的测试场景") @ApiModelProperty("选择的测试场景")
private List<Long> testScenarioList; private List<Long> testScenarioList;
@ApiModelProperty("上传的文件")
private List<TaskFileRelation> fileList;
} }
...@@ -3,6 +3,7 @@ package com.ruoyi.web.request; ...@@ -3,6 +3,7 @@ package com.ruoyi.web.request;
import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.domain.TaskFileRelation;
import com.ruoyi.domain.TaskSampleRelation; import com.ruoyi.domain.TaskSampleRelation;
import com.ruoyi.domain.TaskUserRelation; import com.ruoyi.domain.TaskUserRelation;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
...@@ -69,4 +70,7 @@ public class TaskEditRequest { ...@@ -69,4 +70,7 @@ public class TaskEditRequest {
@ApiModelProperty("选择的测试场景") @ApiModelProperty("选择的测试场景")
private List<Long> testScenarioList; private List<Long> testScenarioList;
@ApiModelProperty("上传的文件")
private List<TaskFileRelation> fileList;
} }
...@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.annotation.IdType; ...@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.domain.Sample; import com.ruoyi.domain.Sample;
import com.ruoyi.domain.TaskFileRelation;
import com.ruoyi.domain.TaskSampleRelation; import com.ruoyi.domain.TaskSampleRelation;
import com.ruoyi.domain.TaskUserRelation; import com.ruoyi.domain.TaskUserRelation;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
...@@ -130,4 +131,7 @@ public class TaskGetInfoResponse { ...@@ -130,4 +131,7 @@ public class TaskGetInfoResponse {
@ApiModelProperty("测试场景") @ApiModelProperty("测试场景")
private List<Long> testScenarioList; 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 @@ ...@@ -328,6 +328,19 @@
where t.id = #{taskId} where t.id = #{taskId}
group by t.id group by t.id
</select> </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> </mapper>
...@@ -10,13 +10,17 @@ ...@@ -10,13 +10,17 @@
<result property="usecase" column="usecase" jdbcType="VARCHAR"/> <result property="usecase" column="usecase" jdbcType="VARCHAR"/>
<result property="usecaseId" column="usecase_id" jdbcType="VARCHAR"/> <result property="usecaseId" column="usecase_id" jdbcType="VARCHAR"/>
<result property="testTime" column="test_time" jdbcType="TIMESTAMP"/> <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="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="testResult" column="test_result" jdbcType="VARCHAR"/>
<result property="testResultDescription" column="test_result_description" jdbcType="VARCHAR"/> <result property="remediation" column="remediation" jdbcType="VARCHAR"/>
<result property="loophole" column="loophole" jdbcType="VARCHAR"/>
</resultMap> </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> </mapper>
...@@ -147,4 +147,8 @@ minio: ...@@ -147,4 +147,8 @@ minio:
url: ${MINIO_URL} url: ${MINIO_URL}
accessKey: ${MINIO_ACCESSKEY} accessKey: ${MINIO_ACCESSKEY}
secretKey: ${MINIO_SECRETKEY} secretKey: ${MINIO_SECRETKEY}
bucketName: vehicle-quality-review-oss bucketName: vehicle-quality-review-oss
\ No newline at end of file
# 定时任务开启状态
task:
scheduling: true
\ No newline at end of file
...@@ -149,4 +149,9 @@ minio: ...@@ -149,4 +149,9 @@ minio:
url: http://49.232.167.247:22038 url: http://49.232.167.247:22038
accessKey: lB7WhZYiQwLzhHPutRGn accessKey: lB7WhZYiQwLzhHPutRGn
secretKey: 7XMWpLm6p4d20OFe9uXKifEyhF3cp4sTCowI2fhJ secretKey: 7XMWpLm6p4d20OFe9uXKifEyhF3cp4sTCowI2fhJ
bucketName: vehicle-quality-review-oss bucketName: vehicle-quality-review-oss
\ No newline at end of file
# 定时任务开启状态
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