diff --git a/backend/src/main/java/io/metersphere/api/controller/ApiTestCaseController.java b/backend/src/main/java/io/metersphere/api/controller/ApiTestCaseController.java index 67b356577e..5a96225a71 100644 --- a/backend/src/main/java/io/metersphere/api/controller/ApiTestCaseController.java +++ b/backend/src/main/java/io/metersphere/api/controller/ApiTestCaseController.java @@ -69,14 +69,7 @@ public class ApiTestCaseController { @PostMapping("/list/{goPage}/{pageSize}") public Pager> listSimple(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody ApiTestCaseRequest request) { - if (request.getToBeUpdated() != null && request.getToBeUpdated()) { - if (request.getProjectId() != null) { - Long toBeUpdatedTime = apiTestCaseService.getToBeUpdatedTime(request.getProjectId()); - if (toBeUpdatedTime != null) { - request.setToBeUpdateTime(toBeUpdatedTime); - } - } - } + apiTestCaseService.initRequestBySearch(request); Page page = PageHelper.startPage(goPage, pageSize, true); request.setSelectEnvironment(true); return PageUtils.setPageInfo(page, apiTestCaseService.listSimple(request)); diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/ApiTestCaseRequest.java b/backend/src/main/java/io/metersphere/api/dto/definition/ApiTestCaseRequest.java index be276cee08..0d95bdaf5a 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/ApiTestCaseRequest.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/ApiTestCaseRequest.java @@ -40,12 +40,17 @@ public class ApiTestCaseRequest extends BaseQueryRequest { /** * 是否进入待更新列表 */ - private Boolean toBeUpdated; + private boolean toBeUpdated; /** * 当前时间减去进入待更新的时间 */ private Long toBeUpdateTime; + + /** + * 进入待更新列表用例状态集合 + */ + private List statusList; /** * 是否需要查询环境字段 */ diff --git a/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java b/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java index 2b8d88692d..f9ad74a953 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java @@ -120,10 +120,14 @@ public class ApiTestCaseService { private ProjectApplicationMapper projectApplicationMapper; @Resource private ApiCaseBatchSyncService apiCaseSyncService; + @Resource + private ApiTestCaseSyncService apiTestCaseSyncService; private static final String BODY_FILE_DIR = FileUtils.BODY_FILE_DIR; + private static final String DEFAULT_TIME_DATE = "-3D"; + //查询测试用例详情 public ApiTestCaseWithBLOBs getInfoJenkins(String id) { ApiTestCaseWithBLOBs apiTest = apiTestCaseMapper.selectByPrimaryKey(id); @@ -162,20 +166,26 @@ public class ApiTestCaseService { example.createCriteria().andTypeEqualTo(ProjectApplicationType.OPEN_UPDATE_TIME.name()) .andProjectIdEqualTo(projectId); List projectApplications = projectApplicationMapper.selectByExample(example); - if (projectApplications == null || projectApplications.size() == 0) { - return null; + if (CollectionUtils.isEmpty(projectApplications)) { + return getTimeMills(System.currentTimeMillis(), DEFAULT_TIME_DATE); } + example = new ProjectApplicationExample(); + example.createCriteria().andTypeEqualTo(ProjectApplicationType.TRIGGER_UPDATE.name()) + .andProjectIdEqualTo(projectId); + List projectApplicationRules = projectApplicationMapper.selectByExample(example); ProjectApplication projectApplication = projectApplications.get(0); String typeValue = projectApplication.getTypeValue(); - if (typeValue.equals("false")) { + if (CollectionUtils.isEmpty(projectApplicationRules) && StringUtils.equals(typeValue, "false")) { + return getTimeMills(System.currentTimeMillis(), DEFAULT_TIME_DATE); + } else if (StringUtils.equals(typeValue, "false")) { return null; } example = new ProjectApplicationExample(); example.createCriteria().andTypeEqualTo(ProjectApplicationType.OPEN_UPDATE_RULE_TIME.name()) .andProjectIdEqualTo(projectId); List projectApplicationTimes = projectApplicationMapper.selectByExample(example); - if (projectApplicationTimes == null || projectApplicationTimes.size() == 0) { - return null; + if (CollectionUtils.isEmpty(projectApplications)) { + return getTimeMills(System.currentTimeMillis(), DEFAULT_TIME_DATE); } ProjectApplication projectApplicationTime = projectApplicationTimes.get(0); String time = projectApplicationTime.getTypeValue(); @@ -452,6 +462,7 @@ public class ApiTestCaseService { } else { test.setTags(request.getTags()); } + apiTestCaseSyncService.setCaseUpdateValue(test); apiTestCaseMapper.updateByPrimaryKeySelective(test); saveFollows(test.getId(), request.getFollows()); } @@ -1272,4 +1283,20 @@ public class ApiTestCaseService { public List selectExecuteResultByProjectId(String projectId) { return extApiTestCaseMapper.selectExecuteResultByProjectId(projectId); } + + public void initRequestBySearch(ApiTestCaseRequest request) { + if (!request.isToBeUpdated() || StringUtils.isBlank(request.getProjectId())) { + return; + } + + Long toBeUpdatedTime = this.getToBeUpdatedTime(request.getProjectId()); + if (toBeUpdatedTime != null) { + request.setToBeUpdateTime(toBeUpdatedTime); + } + List syncRuleCaseStatus = apiTestCaseSyncService.getSyncRuleCaseStatus(request.getProjectId()); + if (CollectionUtils.isEmpty(syncRuleCaseStatus)) { + syncRuleCaseStatus = new ArrayList<>(); + } + request.setStatusList(syncRuleCaseStatus); + } } diff --git a/backend/src/main/java/io/metersphere/api/service/ApiTestCaseSyncService.java b/backend/src/main/java/io/metersphere/api/service/ApiTestCaseSyncService.java index 796a71bf03..02765a30e4 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiTestCaseSyncService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiTestCaseSyncService.java @@ -2,9 +2,15 @@ package io.metersphere.api.service; import io.metersphere.base.domain.ApiTestCaseWithBLOBs; +import java.util.List; + public interface ApiTestCaseSyncService { void setApiCaseUpdate(ApiTestCaseWithBLOBs test); + void setCaseUpdateValue(ApiTestCaseWithBLOBs test); + + List getSyncRuleCaseStatus(String projectId); + } diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestCaseMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestCaseMapper.xml index 848f3b4a52..77429e4976 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestCaseMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestCaseMapper.xml @@ -502,11 +502,23 @@ and (t1.status is null or t1.status != 'Trash') - - and ( t1.to_be_updated = #{request.toBeUpdated} or t1.status = 'error') + + and ( t1.to_be_updated = #{request.toBeUpdated} or t1.status + in + #{value} + ) - - and (t1.to_be_update_time >= #{request.toBeUpdateTime} or t1.status = 'error') + + and ( t1.to_be_updated = #{request.toBeUpdated} + + + and (t1.to_be_update_time >= #{request.toBeUpdateTime} or t1.status in + + #{value} + ) + + + and (t1.to_be_update_time >= #{request.toBeUpdateTime} diff --git a/frontend/src/business/components/project/menu/appmanage/AppManage.vue b/frontend/src/business/components/project/menu/appmanage/AppManage.vue index 69a502b843..87db9f3fe9 100644 --- a/frontend/src/business/components/project/menu/appmanage/AppManage.vue +++ b/frontend/src/business/components/project/menu/appmanage/AppManage.vue @@ -462,8 +462,7 @@ export default { this.startSaveData(params) this.disabledRuleBtn = !this.disabledRuleBtn; }, - setSyncTime() { - let configs = []; + buildSyncTime(configs) { if (this.config.openUpdateTime) { if (!this.pastQuantity) { this.$message.error("请选择时间"); @@ -483,8 +482,13 @@ export default { }); } configs.push({projectId: this.projectId, typeValue: this.config.openUpdateTime, type: 'OPEN_UPDATE_TIME'}); + return configs; + }, + setSyncTime() { + let configs = []; + this.buildSyncTime(configs); let params = {configs}; - this.startSaveData(params) + this.startSaveData(params); }, saveSync() { let configs = []; @@ -493,9 +497,10 @@ export default { typeValue: JSON.stringify(this.apiSyncCaseRequest), type: 'TRIGGER_UPDATE' }); + this.buildSyncTime(configs); let params = {configs}; - this.startSaveData(params) - this.showRuleSetting = false + this.startSaveData(params); + this.showRuleSetting = false; } } };