From fff4e782e768c287eb51d48257127bb15b327413 Mon Sep 17 00:00:00 2001 From: "Captain.B" Date: Tue, 6 Jul 2021 10:09:51 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92,?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B):=20=E5=90=8E=E5=8F=B0?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E5=A2=9E=E5=8A=A0=E9=94=99=E8=AF=AF=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/metersphere/job/sechedule/IssuesJob.java | 10 ++++++++-- .../io/metersphere/track/service/IssuesService.java | 13 ++++++++++--- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/backend/src/main/java/io/metersphere/job/sechedule/IssuesJob.java b/backend/src/main/java/io/metersphere/job/sechedule/IssuesJob.java index 96bef9feee..8de0acc191 100644 --- a/backend/src/main/java/io/metersphere/job/sechedule/IssuesJob.java +++ b/backend/src/main/java/io/metersphere/job/sechedule/IssuesJob.java @@ -10,6 +10,7 @@ import io.metersphere.base.domain.TestPlanTestCaseWithBLOBs; import io.metersphere.commons.utils.LogUtil; import io.metersphere.track.service.IssuesService; import io.metersphere.track.service.TestPlanTestCaseService; +import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.exception.ExceptionUtils; import org.springframework.stereotype.Component; @@ -24,8 +25,9 @@ public class IssuesJob { private TestPlanTestCaseService testPlanTestCaseService; @QuartzScheduled(fixedDelay = 3600 * 1000) - //@Scheduled(fixedDelay = 120 * 1000) +// @Scheduled(fixedDelay = 120 * 1000) public void issuesCount() { + LogUtil.info("测试计划-测试用例同步缺陷信息开始"); int pageSize = 100; int pages = 1; for (int i = 0; i < pages; i++) { @@ -35,13 +37,17 @@ public class IssuesJob { list.forEach(l -> { try { List issues = issuesService.getIssues(l.getCaseId()); + if (CollectionUtils.isEmpty(issues)) { + return; + } int issuesCount = issues.size(); testPlanTestCaseService.updateIssues(issuesCount, l.getPlanId(), l.getCaseId(), JSON.toJSONString(issues)); } catch (Exception e) { - LogUtil.error("定时任务处理bug数量报错planId: " + l.getPlanId(), ExceptionUtils.getStackTrace(e)); + LogUtil.error("定时任务处理bug数量报错planId: {}, message: {}", l.getPlanId(), ExceptionUtils.getStackTrace(e)); } }); } + LogUtil.info("测试计划-测试用例同步缺陷信息开始"); } } diff --git a/backend/src/main/java/io/metersphere/track/service/IssuesService.java b/backend/src/main/java/io/metersphere/track/service/IssuesService.java index 562c7de721..dd7777cc9b 100644 --- a/backend/src/main/java/io/metersphere/track/service/IssuesService.java +++ b/backend/src/main/java/io/metersphere/track/service/IssuesService.java @@ -145,6 +145,10 @@ public class IssuesService { issueRequest.setTestCaseId(caseId); ServiceUtils.getDefaultOrder(issueRequest.getOrders()); Project project = getProjectByCaseId(caseId); + // project 不存在 + if (project == null) { + return null; + } String workspaceId = project.getWorkspaceId(); Workspace workspace = workspaceMapper.selectByPrimaryKey(workspaceId); TestCase testCase = testCaseMapper.selectByPrimaryKey(caseId); @@ -229,8 +233,11 @@ public class IssuesService { private Project getProjectByCaseId(String testCaseId) { TestCaseWithBLOBs testCase = testCaseService.getTestCase(testCaseId); - Project project = projectService.getProjectById(testCase.getProjectId()); - return project; + // testCase 不存在 + if (testCase == null) { + return null; + } + return projectService.getProjectById(testCase.getProjectId()); } private String getTapdProjectId(String testCaseId) { @@ -454,7 +461,7 @@ public class IssuesService { } public List relateList(IssuesRequest request) { - return extIssuesMapper.getRelateIssues(request); + return extIssuesMapper.getRelateIssues(request); } public void userAuth(AuthUserIssueRequest authUserIssueRequest) {