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);