Skip to content

Commit

Permalink
feat: add step disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhouYixun committed Mar 17, 2023
1 parent 2506a30 commit 224a658
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public RespModel<List<TestCases>> deleteCheck(@RequestParam(name = "id") int id)
@Parameter(name = "id", description = "公共步骤id")
@GetMapping
public RespModel<?> findById(@RequestParam(name = "id") int id) {
PublicStepsDTO publicStepsDTO = publicStepsService.findById(id);
PublicStepsDTO publicStepsDTO = publicStepsService.findById(id, false);
if (publicStepsDTO != null) {
return new RespModel<>(RespEnum.SEARCH_OK, publicStepsDTO);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public RespModel<CommentPage<StepsDTO>> findAll(@RequestParam(name = "projectId"
@Parameter(name = "caseId", description = "测试用例id")
@GetMapping("/listAll")
public RespModel<List<StepsDTO>> findByCaseIdOrderBySort(@RequestParam(name = "caseId") int caseId) {
return new RespModel<>(RespEnum.SEARCH_OK, stepsService.findByCaseIdOrderBySort(caseId));
return new RespModel<>(RespEnum.SEARCH_OK, stepsService.findByCaseIdOrderBySort(caseId, false));
}

@WebAspect
Expand Down Expand Up @@ -169,4 +169,19 @@ public RespModel<String> copyStepsIdByCase(@RequestParam(name = "id") int stepId
return new RespModel<>(RespEnum.COPY_OK);
}

@WebAspect
@Operation(summary = "开关步骤", description = "设置步骤的启用状态")
@Parameters(value = {
@Parameter(name = "id", description = "用例id"),
@Parameter(name = "type", description = "状态"),
})
@GetMapping("/switchStep")
public RespModel switchStep(@RequestParam(name = "id") int id, @RequestParam(name = "type") int type) {
if (stepsService.switchStep(id, type)) {
return new RespModel(RespEnum.HANDLE_OK);
} else {
return new RespModel(RespEnum.SEARCH_FAIL);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public interface PublicStepsService extends IService<PublicSteps> {

boolean delete(int id);

PublicStepsDTO findById(int id);
PublicStepsDTO findById(int id, boolean hiddenDisabled);

boolean deleteByProjectId(int projectId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
* @date 2021/8/20 17:51
*/
public interface StepsService extends IService<Steps> {
List<StepsDTO> findByCaseIdOrderBySort(int caseId);
List<StepsDTO> findByCaseIdOrderBySort(int caseId, boolean hiddenDisabled);

List<StepsDTO> handleSteps(List<StepsDTO> stepsDTOS);
List<StepsDTO> handleSteps(List<StepsDTO> stepsDTOS, boolean hiddenDisabled);

/**
* 获取每个step下的childSteps 组装成一个list返回
Expand All @@ -29,11 +29,11 @@ public interface StepsService extends IService<Steps> {
List<StepsDTO> getChildSteps(List<StepsDTO> stepsDTOS);

/**
* 如果步骤是条件步骤,且子条件也可能是条件步骤,则递归填充条件步骤的子步骤,且所有步骤都会填充 {@link StepsDTO#elements} 属性
* 如果步骤是条件步骤,且子条件也可能是条件步骤,则递归填充条件步骤的子步骤,且所有步骤都会填充
*
* @param stepsDTO 步骤对象(不需要填充)
*/
StepsDTO handleStep(StepsDTO stepsDTO);
StepsDTO handleStep(StepsDTO stepsDTO, boolean hiddenDisabled);

boolean resetCaseId(int id);

Expand Down Expand Up @@ -71,5 +71,7 @@ CommentPage<StepsDTO> searchFindByProjectIdAndPlatform(int projectId, int platfo

Boolean copyStepsIdByCase(Integer stepId);

Boolean switchStep(int id, int type);

List<PublicStepsAndStepsIdDTO> stepAndIndex(List<StepsDTO> needAllCopySteps);
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public CommentPage<PublicStepsDTO> findByProjectId(int projectId, Page<PublicSte

// 将step填充到public step
publicStepsDTOList.forEach(
e -> e.setSteps(stepsService.handleSteps(stepsDTOMap.get(e.getId())))
e -> e.setSteps(stepsService.handleSteps(stepsDTOMap.get(e.getId()), false))
);

return CommentPage.convertFrom(page, publicStepsDTOList);
Expand Down Expand Up @@ -136,7 +136,7 @@ public boolean delete(int id) {

@Override
@Transactional
public PublicStepsDTO findById(int id) {
public PublicStepsDTO findById(int id, boolean hiddenDisabled) {
PublicSteps publicSteps = lambdaQuery().eq(PublicSteps::getId, id)
.orderByDesc(PublicSteps::getId)
.one();
Expand All @@ -145,7 +145,7 @@ public PublicStepsDTO findById(int id) {
List<StepsDTO> steps = stepsMapper.listByPublicStepsId(publicSteps.getId())
.stream().map(TypeConverter::convertTo).collect(Collectors.toList());

stepsService.handleSteps(steps);
stepsService.handleSteps(steps, hiddenDisabled);

PublicStepsDTO publicStepsDTO = publicSteps.convertTo().setSteps(steps);
return publicStepsDTO.setSteps(steps);
Expand Down Expand Up @@ -195,7 +195,7 @@ public void copyPublicSetpsIds(int id) {
oldStepsDtoList.add(steps.convertTo());
}
//递归关联所有步骤,然后取出
List<StepsDTO> stepsDTOS = stepsService.handleSteps(oldStepsDtoList);
List<StepsDTO> stepsDTOS = stepsService.handleSteps(oldStepsDtoList, false);
List<StepsDTO> needAllCopySteps = stepsService.getChildSteps(stepsDTOS);

List<PublicStepsAndStepsIdDTO> oldStepDto = stepsService.stepAndIndex(needAllCopySteps);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,31 +70,32 @@ public class StepsServiceImpl extends SonicServiceImpl<StepsMapper, Steps> imple

@Transactional
@Override
public List<StepsDTO> findByCaseIdOrderBySort(int caseId) {
public List<StepsDTO> findByCaseIdOrderBySort(int caseId, boolean hiddenDisabled) {

// 取出用例下所有无父级的步骤
List<StepsDTO> stepsDTOList = lambdaQuery()
.eq(Steps::getCaseId, caseId)
.eq(Steps::getParentId, 0)
.eq(hiddenDisabled, Steps::getDisabled, 0)
.orderByAsc(Steps::getSort)
.list()
// 转换成DTO
.stream().map(TypeConverter::convertTo).collect(Collectors.toList());

// 遍历父级步骤,如果是条件步骤,则取出子步骤集合
handleSteps(stepsDTOList);
handleSteps(stepsDTOList, hiddenDisabled);

return stepsDTOList;
}

@Transactional
@Override
public List<StepsDTO> handleSteps(List<StepsDTO> stepsDTOS) {
public List<StepsDTO> handleSteps(List<StepsDTO> stepsDTOS, boolean hiddenDisabled) {
if (CollectionUtils.isEmpty(stepsDTOS)) {
return stepsDTOS;
}
for (StepsDTO stepsDTO : stepsDTOS) {
handleStep(stepsDTO);
handleStep(stepsDTO, hiddenDisabled);
}
return stepsDTOS;
}
Expand Down Expand Up @@ -140,7 +141,7 @@ public List<StepsDTO> getChildSteps(List<StepsDTO> stepsDTOS) {

@Transactional
@Override
public StepsDTO handleStep(StepsDTO stepsDTO) {
public StepsDTO handleStep(StepsDTO stepsDTO, boolean hiddenDisabled) {
if (stepsDTO == null) {
return null;
}
Expand All @@ -161,7 +162,7 @@ public StepsDTO handleStep(StepsDTO stepsDTO) {
.list()
// 转换成DTO
.stream().map(TypeConverter::convertTo).collect(Collectors.toList());
stepsDTO.setChildSteps(handleSteps(childSteps));
stepsDTO.setChildSteps(handleSteps(childSteps, hiddenDisabled));
}
return stepsDTO;
}
Expand Down Expand Up @@ -242,7 +243,7 @@ public void saveStep(StepsDTO stepsDTO) {
@Override
public StepsDTO findById(int id) {
StepsDTO stepsDTO = baseMapper.selectById(id).convertTo();
handleStep(stepsDTO);
handleStep(stepsDTO, false);
return stepsDTO;
}

Expand Down Expand Up @@ -285,7 +286,7 @@ public CommentPage<StepsDTO> findByProjectIdAndPlatform(int projectId, int platf

List<StepsDTO> stepsDTOList = page.getRecords()
.stream().map(TypeConverter::convertTo).collect(Collectors.toList());
handleSteps(stepsDTOList);
handleSteps(stepsDTOList,false);

return CommentPage.convertFrom(page, stepsDTOList);
}
Expand Down Expand Up @@ -332,7 +333,7 @@ public CommentPage<StepsDTO> searchFindByProjectIdAndPlatform(int projectId, int
List<StepsDTO> stepsDTOList = steps.getRecords()
.stream().map(TypeConverter::convertTo).collect(Collectors.toList());

handleSteps(stepsDTOList);
handleSteps(stepsDTOList,false);

return CommentPage.convertFrom(pageList, stepsDTOList);
}
Expand All @@ -341,7 +342,7 @@ public CommentPage<StepsDTO> searchFindByProjectIdAndPlatform(int projectId, int
@Transactional(rollbackFor = Exception.class)
public Boolean copyStepsIdByCase(Integer stepId) {
Steps steps = stepsMapper.selectById(stepId);
StepsDTO stepsCopyDTO = stepsService.handleStep(steps.convertTo());
StepsDTO stepsCopyDTO = stepsService.handleStep(steps.convertTo(),false);

save(steps.setId(null).setSort(stepsMapper.findMaxSort() + 1));
//关联ele
Expand Down Expand Up @@ -401,6 +402,18 @@ public Boolean copyStepsIdByCase(Integer stepId) {
return true;
}

@Override
public Boolean switchStep(int id, int type) {
Steps steps = baseMapper.selectById(id);
if (steps != null) {
steps.setDisabled(type);
save(steps);
return true;
} else {
return false;
}
}


/**
* 记录一组步骤中他们所在的位置;ma
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public boolean delete(int id) {
.eq(TestSuitesTestCases::getTestCasesId, id)
);

List<StepsDTO> stepsList = stepsService.findByCaseIdOrderBySort(id);
List<StepsDTO> stepsList = stepsService.findByCaseIdOrderBySort(id, false);
for (StepsDTO steps : stepsList) {
steps.setCaseId(0);
stepsService.updateById(steps.convertTo());
Expand Down Expand Up @@ -146,7 +146,7 @@ public JSONObject findSteps(int id) {
jsonDebug.put("pf", runStepCase.getPlatform());

JSONArray array = new JSONArray();
List<StepsDTO> stepsList = stepsService.findByCaseIdOrderBySort(id);
List<StepsDTO> stepsList = stepsService.findByCaseIdOrderBySort(id, true);
for (StepsDTO steps : stepsList) {
array.add(testSuitesService.getStep(steps));
}
Expand Down Expand Up @@ -223,7 +223,7 @@ public boolean copyTestById(int oldId) {
stepsDTO.add(steps.convertTo());

}
List<StepsDTO> stepsCopyDTOS = stepsService.handleSteps(stepsDTO);
List<StepsDTO> stepsCopyDTOS = stepsService.handleSteps(stepsDTO, false);

//需要插入的步骤记录
List<PublicStepsAndStepsIdDTO> needCopySteps = stepsService.stepAndIndex(stepsCopyDTOS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,10 +283,13 @@ public JSONObject getStep(StepsDTO steps) {
}

if (steps.getStepType().equals("publicStep")) {
PublicStepsDTO publicStepsDTO = publicStepsService.findById(Integer.parseInt(steps.getText()));
PublicStepsDTO publicStepsDTO = publicStepsService.findById(Integer.parseInt(steps.getText()), true);
if (publicStepsDTO != null) {
JSONArray publicStepsJson = new JSONArray();
for (StepsDTO pubStep : publicStepsDTO.getSteps()) {
if (pubStep.getDisabled() == 1) {
continue;
}
publicStepsJson.add(getStep(pubStep));
}
step.put("pubSteps", publicStepsJson);
Expand All @@ -300,18 +303,24 @@ public JSONObject getStep(StepsDTO steps) {
if (!ConditionEnum.NONE.getValue().equals(steps.getConditionType())) {
List<StepsDTO> childSteps = steps.getChildSteps();
for (StepsDTO childStep : childSteps) {
if (childStep.getDisabled() == 1) {
continue;
}
// 如果子步骤是公共步骤,则再递归处理;如果不是,则不用处理
if (childStep.getStepType().equals("publicStep")) {
PublicStepsDTO publicStepsDTO = publicStepsService.findById(Integer.parseInt(childStep.getText()));
PublicStepsDTO publicStepsDTO = publicStepsService.findById(Integer.parseInt(childStep.getText()), true);
if (publicStepsDTO != null) {
JSONArray publicStepsJson = new JSONArray();
for (StepsDTO pubStep : publicStepsDTO.getSteps()) {
if (pubStep.getDisabled() == 1) {
continue;
}
publicStepsJson.add(getStep(pubStep));
}
JSONObject childStepJsonObj = new JSONObject() {
{
put("pubSteps", publicStepsJson);
put("step", stepsService.handleStep(childStep));
put("step", stepsService.handleStep(childStep, true));
}
};
// 添加转换后的公共步骤
Expand Down Expand Up @@ -435,18 +444,16 @@ public void setApplicationContext(ApplicationContext applicationContext) throws
private void initCoverHandlerMap() {
Map<String, CoverHandler> coverHandlerBeans = applicationContext.getBeansOfType(CoverHandler.class);
coverHandlerMap = new HashMap<>();
if (coverHandlerBeans != null) {
for (CoverHandler coverHandler : coverHandlerBeans.values()) {
coverHandlerMap.put(coverHandler.cover(), coverHandler);
}
for (CoverHandler coverHandler : coverHandlerBeans.values()) {
coverHandlerMap.put(coverHandler.cover(), coverHandler);
}
}

private JSONObject packageTestCase(Devices devices, int isOpenPerfmon, int perfmonInterval, TestCasesDTO testCases,
JSONObject gp, Results results, StepsService stepsService) {
JSONObject testCase = new JSONObject();
List<JSONObject> steps = new ArrayList<>();
List<StepsDTO> stepsList = stepsService.findByCaseIdOrderBySort(testCases.getId());
List<StepsDTO> stepsList = stepsService.findByCaseIdOrderBySort(testCases.getId(), true);
for (StepsDTO s : stepsList) {
steps.add(getStep(s));
}
Expand Down

0 comments on commit 224a658

Please sign in to comment.