Commit 2787d0c3 authored by 盖献康's avatar 盖献康

车型试验(第三个子任务): 查看、开始

parent e6ae0ce3
...@@ -32,7 +32,7 @@ public class ModelTestTask { ...@@ -32,7 +32,7 @@ public class ModelTestTask {
* 任务类型 * 任务类型
*/ */
@TableField(exist = false) @TableField(exist = false)
public static final String TYPE = "car"; public static final String TYPE = "test";
/** /**
* 任务状态 * 任务状态
...@@ -75,7 +75,7 @@ public class ModelTestTask { ...@@ -75,7 +75,7 @@ public class ModelTestTask {
private Date taskEndTime; private Date taskEndTime;
@ApiModelProperty("测试用例") @ApiModelProperty("测试用例")
@TableField(value="testCase", typeHandler = StandardJsonTypeHandler. class) @TableField(value="test_case", typeHandler = StandardJsonTypeHandler. class)
private List<ReviewStandard> testCase; private List<ReviewStandard> testCase;
@ApiModelProperty("创建时间") @ApiModelProperty("创建时间")
......
package com.ruoyi.domain.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* 用于返回的测试用例VO类
* @author gxk
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@ApiModel("测试用例VO类")
public class TestCaseVO {
@ApiModelProperty("测试场景")
private String testScenario;
@ApiModelProperty("测试类型")
private String testType;
@ApiModelProperty("用例编号")
private String usecaseNo;
@ApiModelProperty("用例名称")
private String name;
@ApiModelProperty("工具")
private String tools;
@ApiModelProperty("对应输入")
private String input;
@ApiModelProperty("用例描述")
private String description;
}
package com.ruoyi.domain.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* 测试用例VO(t_test_usecase)
* @author gxk
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@ApiModel("测试用例VO(t_test_usecase)")
public class TestUsecaseVO {
@ApiModelProperty("测试场景")
private String testScenario;
@ApiModelProperty("测试类型")
private String testType;
@ApiModelProperty("用例编号")
private String usecaseNo;
@ApiModelProperty("用例名称")
private String name;
@ApiModelProperty("工具")
private String tools;
@ApiModelProperty("对应输入")
private String input;
@ApiModelProperty("用例描述")
private String description;
@ApiModelProperty("用例条款ID")
private Long reviewStandardId;
@ApiModelProperty("章节号")
private String chapter;
@ApiModelProperty("标准技术要求")
private String text;
@ApiModelProperty("标准测试方法")
private String testMethod;
}
...@@ -2,6 +2,7 @@ package com.ruoyi.mapper; ...@@ -2,6 +2,7 @@ package com.ruoyi.mapper;
import com.ruoyi.domain.TestUseCase; import com.ruoyi.domain.TestUseCase;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.domain.vo.TestUsecaseVO;
import com.ruoyi.web.request.TestUserCaseRequest; import com.ruoyi.web.request.TestUserCaseRequest;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
...@@ -23,6 +24,13 @@ public interface TestUseCaseMapper extends BaseMapper<TestUseCase> { ...@@ -23,6 +24,13 @@ public interface TestUseCaseMapper extends BaseMapper<TestUseCase> {
* @return 测试用例集合 * @return 测试用例集合
*/ */
public List<TestUseCase> selectseCaseList(TestUserCaseRequest testUserCaseRequest); public List<TestUseCase> selectseCaseList(TestUserCaseRequest testUserCaseRequest);
/**
* 查询测试用例列表
* @param id
* @return
*/
List<TestUsecaseVO> selectListByTaskId(Long id);
} }
......
...@@ -2,11 +2,27 @@ package com.ruoyi.service; ...@@ -2,11 +2,27 @@ package com.ruoyi.service;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.ruoyi.domain.ModelTestTask; import com.ruoyi.domain.ModelTestTask;
import org.springframework.stereotype.Service; import com.ruoyi.web.response.ModelTestTaskViewResponse;
import java.util.List;
/** /**
* 车型试验任务Service接口 * 车型试验任务Service接口
* @author gxk * @author gxk
*/ */
public interface ModelTestTaskService extends IService<ModelTestTask> { public interface ModelTestTaskService extends IService<ModelTestTask> {
/**
* 查看车型试验任务详情
*
* @param taskId
* @return
*/
List<ModelTestTaskViewResponse> viewModelTestTask(Long taskId);
/**
* 开始车型试验任务
* @param taskId
*/
void startModelTestTask(Long taskId);
} }
package com.ruoyi.service;
import com.ruoyi.domain.ModelTestTask;
import com.ruoyi.web.response.ModelTestTaskViewResponse;
import java.util.List;
/**
* @author gxk
*/
public interface StrategyModelTestTask {
/**
* 查看
* @param modelTestTask
* @return
*/
List<ModelTestTaskViewResponse> doView(ModelTestTask modelTestTask);
/**
* 开始测试
* @param modelTestTask
*/
void doStartTest(ModelTestTask modelTestTask);
/**
* 确认测试
* @param modelTestTask
*/
void doConfirmTest(ModelTestTask modelTestTask);
/**
* 提交测试
* @param modelTestTask
* @param imagesUrl
* @param testScenarioList
*/
void doSubmitTest(ModelTestTask modelTestTask, List<String> imagesUrl, List<Long> testScenarioList);
}
...@@ -4,9 +4,13 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; ...@@ -4,9 +4,13 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.domain.ModelTestTask; import com.ruoyi.domain.ModelTestTask;
import com.ruoyi.mapper.ModelTestTaskMapper; import com.ruoyi.mapper.ModelTestTaskMapper;
import com.ruoyi.service.ModelTestTaskService; import com.ruoyi.service.ModelTestTaskService;
import com.ruoyi.web.response.ModelTestTaskViewResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.List;
/** /**
* 车型试验Service业务层处理 * 车型试验Service业务层处理
* @author gxk * @author gxk
...@@ -14,4 +18,32 @@ import org.springframework.transaction.annotation.Transactional; ...@@ -14,4 +18,32 @@ import org.springframework.transaction.annotation.Transactional;
@Service @Service
@Transactional @Transactional
public class ModelTestTaskServiceImpl extends ServiceImpl<ModelTestTaskMapper, ModelTestTask> implements ModelTestTaskService { public class ModelTestTaskServiceImpl extends ServiceImpl<ModelTestTaskMapper, ModelTestTask> implements ModelTestTaskService {
@Autowired
private ModelTestTaskMapper modelTestTaskMapper;
@Autowired
private StrategyModelTestTaskContext strategyModelTestTaskContext;
/**
* 查看车型试验任务详情
*
* @param taskId
* @return
*/
@Override
public List<ModelTestTaskViewResponse> viewModelTestTask(Long taskId) {
ModelTestTask modelTestTask = modelTestTaskMapper.selectById(taskId);
return strategyModelTestTaskContext.getResource(modelTestTask.getTaskStatus()).doView(modelTestTask);
}
/**
* 开始车型试验任务
* @param taskId
*/
@Override
public void startModelTestTask(Long taskId) {
ModelTestTask modelTestTask = modelTestTaskMapper.selectById(taskId);
strategyModelTestTaskContext.getResource(modelTestTask.getTaskStatus()).doStartTest(modelTestTask);
}
} }
package com.ruoyi.service.impl;
import com.ruoyi.service.StrategyModelTestTask;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* @author gxk
*/
@Service
@Transactional
public class StrategyModelTestTaskContext {
private Map<String, StrategyModelTestTask> resourceMap = new ConcurrentHashMap<>();
public void putResource(String key, StrategyModelTestTask strategyModelTestTask) {
resourceMap.put(key, strategyModelTestTask);
}
public StrategyModelTestTask getResource(String operation){
return resourceMap.get(operation);
}
}
package com.ruoyi.service.impl;
import com.ruoyi.common.constant.HttpStatus;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.domain.ModelTestTask;
import com.ruoyi.service.StrategyModelTestTask;
import com.ruoyi.web.response.ModelTestTaskViewResponse;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Service
@Transactional
public class StrategyModelTestTaskFinish implements StrategyModelTestTask, InitializingBean {
@Autowired
private ApplicationContext applicationContext;
@Autowired
private StrategyModelTestTaskContext strategyModelTestTaskContext;
@Override
public List<ModelTestTaskViewResponse> doView(ModelTestTask modelTestTask) {
throw new ServiceException("不能开始一个结束的任务", HttpStatus.ERROR);
}
@Override
public void doStartTest(ModelTestTask modelTestTask) {
throw new ServiceException("不能开始一个结束的任务", HttpStatus.ERROR);
}
@Override
public void doConfirmTest(ModelTestTask modelTestTask) {
throw new ServiceException("不能确认一个结束的任务", HttpStatus.ERROR);
}
@Override
public void doSubmitTest(ModelTestTask modelTestTask, List<String> imagesUrl, List<Long> testScenarioList) {
throw new ServiceException("不能提交一个结束的任务", HttpStatus.ERROR);
}
@Override
public void afterPropertiesSet() throws Exception {
strategyModelTestTaskContext.putResource(ModelTestTask.TASK_STATUS_FINISH, applicationContext.getBean(this.getClass()));
}
}
package com.ruoyi.service.impl;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.ruoyi.common.constant.HttpStatus;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.domain.*;
import com.ruoyi.domain.vo.TestCaseVO;
import com.ruoyi.domain.vo.TestUsecaseVO;
import com.ruoyi.mapper.ModelTestTaskMapper;
import com.ruoyi.mapper.TestUseCaseMapper;
import com.ruoyi.service.StrategyModelTestTask;
import com.ruoyi.web.response.ModelTestTaskViewResponse;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* 车型试验开始状态
* @author gxk
*/
@Service
@Transactional
public class StrategyModelTestTaskNew implements StrategyModelTestTask, InitializingBean {
@Autowired
private ApplicationContext applicationContext;
@Autowired
private StrategyModelTestTaskContext strategyModelTestTaskContext;
@Autowired
private TestUseCaseMapper testUseCaseMapper;
@Autowired
private ModelTestTaskMapper modelTestTaskMapper;
/**
* 状态为NEW时的查看车型试验任务
* @param modelTestTask
* @return
*/
@Override
public List<ModelTestTaskViewResponse> doView(ModelTestTask modelTestTask) {
// 查询出本子任务所包含的测试场景集合
List<TestUsecaseVO> testCaseList = testUseCaseMapper.selectListByTaskId(modelTestTask.getId());
// 创建一个空List, 用于返回数据
List<ModelTestTaskViewResponse> list = new ArrayList<>();
// 创建一个HashMap, 用于存放数据。用例条款ID作为key
HashMap<Long, List<TestCaseVO>> map = new HashMap<>();
for (TestUsecaseVO testUsecaseVO : testCaseList) {
// map不存在此key,添加; 则,存数据
if (!map.containsKey(testUsecaseVO.getReviewStandardId())) {
TestCaseVO caseVO = new TestCaseVO();
BeanUtils.copyProperties(testUsecaseVO, caseVO);
List<TestCaseVO> caseList = new ArrayList<>();
caseList.add(caseVO);
map.put(testUsecaseVO.getReviewStandardId(), caseList);
} else {
TestCaseVO caseVO = new TestCaseVO();
BeanUtils.copyProperties(testUsecaseVO, caseVO);
map.get(testUsecaseVO.getReviewStandardId()).add(caseVO);
}
}
// 循环map, 给list赋值
for (Map.Entry<Long, List<TestCaseVO>> entry : map.entrySet()) {
List<TestUsecaseVO> collect = testCaseList.stream().filter(testCaseVO -> entry.getKey().equals(testCaseVO.getReviewStandardId())).collect(Collectors.toList());
if (collect.size() > 0){
TestUsecaseVO testUsecaseVO = collect.get(0);
ModelTestTaskViewResponse modelTestTaskViewResponse = ModelTestTaskViewResponse.builder()
.chapter(testUsecaseVO.getChapter())
.text(testUsecaseVO.getText())
.testMethod(testUsecaseVO.getTestMethod())
.testCaseList(entry.getValue())
.build();
list.add(modelTestTaskViewResponse);
}
}
return list;
}
/**
* 状态为NEW时的开始车型试验任务
* @param modelTestTask
*/
@Override
public void doStartTest(ModelTestTask modelTestTask) {
modelTestTaskMapper.update(new ModelTestTask(),
new LambdaUpdateWrapper<ModelTestTask>()
.set(ModelTestTask::getTaskStatus, ModelTestTask.TASK_STATUS_PENDING)
.eq(ModelTestTask::getId, modelTestTask.getId()));
}
/**
* 状态为NEW时的确认车型试验任务
* @param modelTestTask
*/
@Override
public void doConfirmTest(ModelTestTask modelTestTask) {
throw new ServiceException("不能确认一个尚未开始的任务", HttpStatus.ERROR);
}
/**
* 状态为NEW时的提交车型试验任务
* @param modelTestTask
* @param imagesUrl
* @param testScenarioList
*/
@Override
public void doSubmitTest(ModelTestTask modelTestTask, List<String> imagesUrl, List<Long> testScenarioList) {
throw new ServiceException("不能提交一个尚未开始的任务", HttpStatus.ERROR);
}
/**
* 根据任务状态获取对应的策略
* @throws Exception
*/
@Override
public void afterPropertiesSet() throws Exception {
strategyModelTestTaskContext.putResource(ModelTestTask.TASK_STATUS_NEW, applicationContext.getBean(this.getClass()));
}
}
package com.ruoyi.service.impl;
import com.ruoyi.common.constant.HttpStatus;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.domain.ModelTestTask;
import com.ruoyi.service.StrategyModelTestTask;
import com.ruoyi.web.response.ModelTestTaskViewResponse;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Service
@Transactional
public class StrategyModelTestTaskPending implements StrategyModelTestTask, InitializingBean {
@Autowired
private ApplicationContext applicationContext;
@Autowired
private StrategyModelTestTaskContext strategyModelTestTaskContext;
@Override
public List<ModelTestTaskViewResponse> doView(ModelTestTask modelTestTask) {
throw new ServiceException("能查看一个进行中的任务", HttpStatus.ERROR);
}
@Override
public void doStartTest(ModelTestTask modelTestTask) {
throw new ServiceException("不能开始一个进行中的任务", HttpStatus.ERROR);
}
@Override
public void doConfirmTest(ModelTestTask modelTestTask) {
throw new ServiceException("能确认一个进行中的任务", HttpStatus.ERROR);
}
@Override
public void doSubmitTest(ModelTestTask modelTestTask, List<String> imagesUrl, List<Long> testScenarioList) {
throw new ServiceException("不能提交一个进行中的任务", HttpStatus.ERROR);
}
@Override
public void afterPropertiesSet() throws Exception {
strategyModelTestTaskContext.putResource(ModelTestTask.TASK_STATUS_PENDING, applicationContext.getBean(this.getClass()));
}
}
package com.ruoyi.service.impl;
import com.ruoyi.common.constant.HttpStatus;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.domain.ModelTestTask;
import com.ruoyi.service.StrategyModelTestTask;
import com.ruoyi.web.response.ModelTestTaskViewResponse;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Service
@Transactional
public class StrategyModelTestTaskSigned implements StrategyModelTestTask, InitializingBean {
@Autowired
private ApplicationContext applicationContext;
@Autowired
private StrategyModelTestTaskContext strategyModelTestTaskContext;
@Override
public List<ModelTestTaskViewResponse> doView(ModelTestTask modelTestTask) {
throw new ServiceException("能查看一个已确认的任务", HttpStatus.ERROR);
}
@Override
public void doStartTest(ModelTestTask modelTestTask) {
throw new ServiceException("不能开始一个已确认的任务", HttpStatus.ERROR);
}
@Override
public void doConfirmTest(ModelTestTask modelTestTask) {
throw new ServiceException("不能确认一个已确认的任务", HttpStatus.ERROR);
}
@Override
public void doSubmitTest(ModelTestTask modelTestTask, List<String> imagesUrl, List<Long> testScenarioList) {
throw new ServiceException("能提交一个已确认的任务", HttpStatus.ERROR);
}
@Override
public void afterPropertiesSet() throws Exception {
strategyModelTestTaskContext.putResource(ModelTestTask.TASK_STATUS_SIGNED, applicationContext.getBean(this.getClass()));
}
}
package com.ruoyi.web; package com.ruoyi.web;
import org.springframework.web.bind.annotation.RequestMapping; import com.ruoyi.common.annotation.Anonymous;
import org.springframework.web.bind.annotation.RestController; import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.service.ModelTestTaskService;
import com.ruoyi.web.request.CarReviewTaskViewRequest;
import com.ruoyi.web.response.ModelTestTaskViewResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/** /**
* 车型测试任务Controller * 车型试验任务Controller
* @author gxk * @author gxk
*/ */
@Api(tags = "车型试验子任务")
@RestController @RestController
@RequestMapping("/car/test/task") @RequestMapping("/car/test/task")
public class ModelTestTaskController { public class ModelTestTaskController extends BaseController {
@Autowired
private ModelTestTaskService modelTestTaskService;
/**
* 查看车型试验任务详情
* @param request
* @return
*/
@Anonymous
@ApiOperation("查看车型试验任务详情")
@PostMapping("/getById")
public R<List<ModelTestTaskViewResponse>> view(@Validated @RequestBody CarReviewTaskViewRequest request) {
List<ModelTestTaskViewResponse> modelTestTaskList = modelTestTaskService.viewModelTestTask(request.getTaskId());
return R.ok(modelTestTaskList);
}
/**
* 开始车型试验任务
* @param request
* @return
*/
@Anonymous
@ApiOperation("开始车型试验任务")
@PostMapping("/start")
public R<String> startReview(@Validated @RequestBody CarReviewTaskViewRequest request) {
modelTestTaskService.startModelTestTask(request.getTaskId());
return R.ok();
}
} }
package com.ruoyi.web.response;
import com.ruoyi.domain.vo.TestCaseVO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
/**
* 车型试验任务查看返回VO类
* @author gxk
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@ApiModel("车型试验任务查看返回VO类")
public class ModelTestTaskViewResponse {
@ApiModelProperty("章节号")
private String chapter;
@ApiModelProperty("标准技术要求")
private String text;
@ApiModelProperty("标准测试方法")
private String testMethod;
private List<TestCaseVO> testCaseList;
}
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
<sql id="Base_Column_List"> <sql id="Base_Column_List">
id,test_scenario_id,test_type_id, id,test_scenario_id,test_type_id,
usecase_no,name,tools, usecase_no,`name`,tools,
input,description input,description
</sql> </sql>
...@@ -47,4 +47,29 @@ ...@@ -47,4 +47,29 @@
<if test="searchKeywords != null and searchKeywords != ''"> and tu.usecase_no like concat('%', #{searchKeywords}, '%') or tu.name like concat('%', #{searchKeywords}, '%')</if> <if test="searchKeywords != null and searchKeywords != ''"> and tu.usecase_no like concat('%', #{searchKeywords}, '%') or tu.name like concat('%', #{searchKeywords}, '%')</if>
</where> </where>
</select> </select>
<select id="selectListByTaskId" resultType="com.ruoyi.domain.vo.TestUsecaseVO">
select
ts.test_scenario testScenario,
tt.test_type testType,
tu.usecase_no usecaseNo,
tu.name,
tu.tools,
tu.input,
tu.description,
tu.review_standard_id,
rs.chapter,
rs.text,
rs.test_method testMethod
from
t_test_usecase tu
left join t_test_scenario ts on tu.test_scenario_id = ts.id
left join t_test_type tt on tu.test_type_id = tt.id
left join t_review_standard rs on tu.review_standard_id = rs.id
left join t_task_scenario_relation tsr on tsr.test_scenario_id = ts.id
left join t_task t on tsr.task_id = t.id
left join t_model_test_task mtt on mtt.id = t.model_test_task_id
where
mtt.id = #{id}
</select>
</mapper> </mapper>
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