From 8b6db872dbf7c1214e363d81850da1aeeae19e82 Mon Sep 17 00:00:00 2001 From: metersphere-bot <78466014+metersphere-bot@users.noreply.github.com> Date: Wed, 7 Jul 2021 18:16:18 +0800 Subject: [PATCH] =?UTF-8?q?fix:2.=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92?= =?UTF-8?q?=E5=85=B3=E8=81=94=E5=AE=8C=E7=BC=BA=E9=99=B7=EF=BC=8C=E7=BC=BA?= =?UTF-8?q?=E9=99=B7=E6=95=B0=E9=87=8F=E6=B2=A1=E6=9B=B4=E6=96=B0=EF=BC=8C?= =?UTF-8?q?=E5=9B=BE2=20(#4467)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix:2.测试计划关联完缺陷,缺陷数量没更新,图2 * fix:删掉无用引入 Co-authored-by: wenyann --- .../mapper/ext/ExtTestPlanTestCaseMapper.xml | 7 +++- .../listener/AppStartListener.java | 1 + .../controller/TestCaseIssuesController.java | 24 +++++++++++ .../track/service/IssuesService.java | 41 +++++++++++++++++++ .../track/service/TestCaseIssueService.java | 1 + 5 files changed, 73 insertions(+), 1 deletion(-) diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanTestCaseMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanTestCaseMapper.xml index 09dddaa0df..1d0bafcc08 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanTestCaseMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanTestCaseMapper.xml @@ -481,10 +481,15 @@ issues_count=#{count}, issues = #{issues} + where + case_id=#{caseId,jdbcType=VARCHAR} + + and plan_id=#{id,jdbcType=VARCHAR} + - where plan_id=#{id,jdbcType=VARCHAR} and case_id=#{caseId,jdbcType=VARCHAR} + delete from test_plan_api_case diff --git a/backend/src/main/java/io/metersphere/listener/AppStartListener.java b/backend/src/main/java/io/metersphere/listener/AppStartListener.java index c2835512a6..5f2b96d61e 100644 --- a/backend/src/main/java/io/metersphere/listener/AppStartListener.java +++ b/backend/src/main/java/io/metersphere/listener/AppStartListener.java @@ -52,6 +52,7 @@ public class AppStartListener implements ApplicationListener list(@RequestBody IssuesRelevanceRequest request) { @@ -29,5 +39,19 @@ public class TestCaseIssuesController { @MsAuditLog(module = "track_test_case", type = OperLogConstants.ASSOCIATE_ISSUE, content = "#msClass.getLogDetails(#request)", msClass = TestCaseIssueService.class) public void relate(@RequestBody IssuesRelevanceRequest request) { testCaseIssueService.relate(request); + try { + List issues = issuesService.getIssues(request.getCaseId()); + if (org.apache.commons.collections4.CollectionUtils.isEmpty(issues)) { + LogUtil.error(request.getCaseId() + "下的缺陷为空"); + } + int issuesCount = issues.size(); + this.updateIssues(issuesCount, "", request.getCaseId(), JSON.toJSONString(issues)); + } catch (Exception e) { + LogUtil.error("处理bug数量报错caseId: {}, message: {}", request.getCaseId(), ExceptionUtils.getStackTrace(e)); + } + } + + public void updateIssues(int issuesCount, String id, String caseId, String issues) { + extTestPlanTestCaseMapper.update(issuesCount, id, caseId, issues); } } 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 6895e4215b..450b720a8f 100644 --- a/backend/src/main/java/io/metersphere/track/service/IssuesService.java +++ b/backend/src/main/java/io/metersphere/track/service/IssuesService.java @@ -1,6 +1,8 @@ package io.metersphere.track.service; import com.alibaba.fastjson.JSON; +import com.github.pagehelper.Page; +import com.github.pagehelper.PageHelper; import io.metersphere.base.domain.*; import io.metersphere.base.mapper.*; import io.metersphere.base.mapper.ext.ExtIssuesMapper; @@ -32,6 +34,7 @@ import io.metersphere.track.request.testcase.IssuesRequest; import io.metersphere.track.request.testcase.IssuesUpdateRequest; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.exception.ExceptionUtils; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -75,6 +78,8 @@ public class IssuesService { private TestCaseMapper testCaseMapper; @Resource private SystemParameterService systemParameterService; + @Resource + private TestPlanTestCaseService testPlanTestCaseService; public void testAuth(String orgId, String platform) { IssuesRequest issuesRequest = new IssuesRequest(); @@ -88,6 +93,18 @@ public class IssuesService { platformList.forEach(platform -> { platform.addIssue(issuesRequest); }); + issuesRequest.getTestCaseIds().forEach(l -> { + try { + List issues = this.getIssues(l); + if (org.apache.commons.collections4.CollectionUtils.isEmpty(issues)) { + LogUtil.error(l + "下的缺陷为空"); + } + int issuesCount = issues.size(); + testPlanTestCaseService.updateIssues(issuesCount, "", l, JSON.toJSONString(issues)); + } catch (Exception e) { + LogUtil.error("处理bug数量报错caseId: {}, message: {}", l, ExceptionUtils.getStackTrace(e)); + } + }); noticeIssueEven(issuesRequest, "IssuesCreate"); } @@ -388,6 +405,30 @@ public class IssuesService { }); } + public void issuesCount() { + LogUtil.info("测试计划-测试用例同步缺陷信息开始"); + int pageSize = 100; + int pages = 1; + for (int i = 0; i < pages; i++) { + Page> page = PageHelper.startPage(i, pageSize, true); + List list = testPlanTestCaseService.listAll(); + pages = page.getPages();// 替换成真实的值 + list.forEach(l -> { + try { + List issues = this.getIssues(l.getCaseId()); + if (org.apache.commons.collections4.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: {}, message: {}", l.getPlanId(), ExceptionUtils.getStackTrace(e)); + } + }); + } + LogUtil.info("测试计划-测试用例同步缺陷信息结束"); + } + public void syncThirdPartyIssues(String projectId) { if (StringUtils.isNotBlank(projectId)) { Project project = projectService.getProjectById(projectId); diff --git a/backend/src/main/java/io/metersphere/track/service/TestCaseIssueService.java b/backend/src/main/java/io/metersphere/track/service/TestCaseIssueService.java index 639eb8f47a..fd005ef304 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestCaseIssueService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestCaseIssueService.java @@ -31,6 +31,7 @@ public class TestCaseIssueService { @Resource private IssuesMapper issuesMapper; + public void delTestCaseIssues(String testCaseId) { TestCaseIssuesExample example = new TestCaseIssuesExample(); example.createCriteria().andTestCaseIdEqualTo(testCaseId);