diff --git a/sonic-server-controller/src/main/java/org/cloud/sonic/controller/controller/PublicStepsController.java b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/controller/PublicStepsController.java index f68a3d0d..017613d6 100644 --- a/sonic-server-controller/src/main/java/org/cloud/sonic/controller/controller/PublicStepsController.java +++ b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/controller/PublicStepsController.java @@ -111,7 +111,7 @@ public RespModel> 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 { diff --git a/sonic-server-controller/src/main/java/org/cloud/sonic/controller/controller/StepsController.java b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/controller/StepsController.java index 6918f79e..ebdc556b 100644 --- a/sonic-server-controller/src/main/java/org/cloud/sonic/controller/controller/StepsController.java +++ b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/controller/StepsController.java @@ -74,7 +74,7 @@ public RespModel> findAll(@RequestParam(name = "projectId" @Parameter(name = "caseId", description = "测试用例id") @GetMapping("/listAll") public RespModel> 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 @@ -169,4 +169,19 @@ public RespModel 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); + } + } + } diff --git a/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/PublicStepsService.java b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/PublicStepsService.java index 507b2b04..0d634d12 100644 --- a/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/PublicStepsService.java +++ b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/PublicStepsService.java @@ -23,7 +23,7 @@ public interface PublicStepsService extends IService { boolean delete(int id); - PublicStepsDTO findById(int id); + PublicStepsDTO findById(int id, boolean hiddenDisabled); boolean deleteByProjectId(int projectId); diff --git a/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/StepsService.java b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/StepsService.java index f382f146..d9872b0a 100644 --- a/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/StepsService.java +++ b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/StepsService.java @@ -16,9 +16,9 @@ * @date 2021/8/20 17:51 */ public interface StepsService extends IService { - List findByCaseIdOrderBySort(int caseId); + List findByCaseIdOrderBySort(int caseId, boolean hiddenDisabled); - List handleSteps(List stepsDTOS); + List handleSteps(List stepsDTOS, boolean hiddenDisabled); /** * 获取每个step下的childSteps 组装成一个list返回 @@ -29,11 +29,11 @@ public interface StepsService extends IService { List getChildSteps(List stepsDTOS); /** - * 如果步骤是条件步骤,且子条件也可能是条件步骤,则递归填充条件步骤的子步骤,且所有步骤都会填充 {@link StepsDTO#elements} 属性 + * 如果步骤是条件步骤,且子条件也可能是条件步骤,则递归填充条件步骤的子步骤,且所有步骤都会填充 * * @param stepsDTO 步骤对象(不需要填充) */ - StepsDTO handleStep(StepsDTO stepsDTO); + StepsDTO handleStep(StepsDTO stepsDTO, boolean hiddenDisabled); boolean resetCaseId(int id); @@ -71,5 +71,7 @@ CommentPage searchFindByProjectIdAndPlatform(int projectId, int platfo Boolean copyStepsIdByCase(Integer stepId); + Boolean switchStep(int id, int type); + List stepAndIndex(List needAllCopySteps); } diff --git a/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/impl/PublicStepsServiceImpl.java b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/impl/PublicStepsServiceImpl.java index 51a12048..bf6edcf3 100644 --- a/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/impl/PublicStepsServiceImpl.java +++ b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/impl/PublicStepsServiceImpl.java @@ -86,7 +86,7 @@ public CommentPage findByProjectId(int projectId, Page e.setSteps(stepsService.handleSteps(stepsDTOMap.get(e.getId()))) + e -> e.setSteps(stepsService.handleSteps(stepsDTOMap.get(e.getId()), false)) ); return CommentPage.convertFrom(page, publicStepsDTOList); @@ -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(); @@ -145,7 +145,7 @@ public PublicStepsDTO findById(int id) { List 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); @@ -195,7 +195,7 @@ public void copyPublicSetpsIds(int id) { oldStepsDtoList.add(steps.convertTo()); } //递归关联所有步骤,然后取出 - List stepsDTOS = stepsService.handleSteps(oldStepsDtoList); + List stepsDTOS = stepsService.handleSteps(oldStepsDtoList, false); List needAllCopySteps = stepsService.getChildSteps(stepsDTOS); List oldStepDto = stepsService.stepAndIndex(needAllCopySteps); diff --git a/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/impl/StepsServiceImpl.java b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/impl/StepsServiceImpl.java index 256edae4..469e1d11 100644 --- a/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/impl/StepsServiceImpl.java +++ b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/impl/StepsServiceImpl.java @@ -70,31 +70,32 @@ public class StepsServiceImpl extends SonicServiceImpl imple @Transactional @Override - public List findByCaseIdOrderBySort(int caseId) { + public List findByCaseIdOrderBySort(int caseId, boolean hiddenDisabled) { // 取出用例下所有无父级的步骤 List 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 handleSteps(List stepsDTOS) { + public List handleSteps(List stepsDTOS, boolean hiddenDisabled) { if (CollectionUtils.isEmpty(stepsDTOS)) { return stepsDTOS; } for (StepsDTO stepsDTO : stepsDTOS) { - handleStep(stepsDTO); + handleStep(stepsDTO, hiddenDisabled); } return stepsDTOS; } @@ -140,7 +141,7 @@ public List getChildSteps(List stepsDTOS) { @Transactional @Override - public StepsDTO handleStep(StepsDTO stepsDTO) { + public StepsDTO handleStep(StepsDTO stepsDTO, boolean hiddenDisabled) { if (stepsDTO == null) { return null; } @@ -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; } @@ -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; } @@ -285,7 +286,7 @@ public CommentPage findByProjectIdAndPlatform(int projectId, int platf List stepsDTOList = page.getRecords() .stream().map(TypeConverter::convertTo).collect(Collectors.toList()); - handleSteps(stepsDTOList); + handleSteps(stepsDTOList,false); return CommentPage.convertFrom(page, stepsDTOList); } @@ -332,7 +333,7 @@ public CommentPage searchFindByProjectIdAndPlatform(int projectId, int List stepsDTOList = steps.getRecords() .stream().map(TypeConverter::convertTo).collect(Collectors.toList()); - handleSteps(stepsDTOList); + handleSteps(stepsDTOList,false); return CommentPage.convertFrom(pageList, stepsDTOList); } @@ -341,7 +342,7 @@ public CommentPage 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 @@ -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 diff --git a/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/impl/TestCasesServiceImpl.java b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/impl/TestCasesServiceImpl.java index 0d133f4b..ed94ba99 100644 --- a/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/impl/TestCasesServiceImpl.java +++ b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/impl/TestCasesServiceImpl.java @@ -118,7 +118,7 @@ public boolean delete(int id) { .eq(TestSuitesTestCases::getTestCasesId, id) ); - List stepsList = stepsService.findByCaseIdOrderBySort(id); + List stepsList = stepsService.findByCaseIdOrderBySort(id, false); for (StepsDTO steps : stepsList) { steps.setCaseId(0); stepsService.updateById(steps.convertTo()); @@ -146,7 +146,7 @@ public JSONObject findSteps(int id) { jsonDebug.put("pf", runStepCase.getPlatform()); JSONArray array = new JSONArray(); - List stepsList = stepsService.findByCaseIdOrderBySort(id); + List stepsList = stepsService.findByCaseIdOrderBySort(id, true); for (StepsDTO steps : stepsList) { array.add(testSuitesService.getStep(steps)); } @@ -223,7 +223,7 @@ public boolean copyTestById(int oldId) { stepsDTO.add(steps.convertTo()); } - List stepsCopyDTOS = stepsService.handleSteps(stepsDTO); + List stepsCopyDTOS = stepsService.handleSteps(stepsDTO, false); //需要插入的步骤记录 List needCopySteps = stepsService.stepAndIndex(stepsCopyDTOS); diff --git a/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/impl/TestSuitesServiceImpl.java b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/impl/TestSuitesServiceImpl.java index da45eab3..fb8ebe2d 100644 --- a/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/impl/TestSuitesServiceImpl.java +++ b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/impl/TestSuitesServiceImpl.java @@ -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); @@ -300,18 +303,24 @@ public JSONObject getStep(StepsDTO steps) { if (!ConditionEnum.NONE.getValue().equals(steps.getConditionType())) { List 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)); } }; // 添加转换后的公共步骤 @@ -435,10 +444,8 @@ public void setApplicationContext(ApplicationContext applicationContext) throws private void initCoverHandlerMap() { Map 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); } } @@ -446,7 +453,7 @@ private JSONObject packageTestCase(Devices devices, int isOpenPerfmon, int perfm JSONObject gp, Results results, StepsService stepsService) { JSONObject testCase = new JSONObject(); List steps = new ArrayList<>(); - List stepsList = stepsService.findByCaseIdOrderBySort(testCases.getId()); + List stepsList = stepsService.findByCaseIdOrderBySort(testCases.getId(), true); for (StepsDTO s : stepsList) { steps.add(getStep(s)); }