fix:2.测试计划关联完缺陷,缺陷数量没更新,图2 (#4467)

* fix:2.测试计划关联完缺陷,缺陷数量没更新,图2

* fix:删掉无用引入

Co-authored-by: wenyann <wenyan.yang@fit2cloud.com>
This commit is contained in:
metersphere-bot 2021-07-07 18:16:18 +08:00 committed by GitHub
parent a03431e6f2
commit 8b6db872db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 73 additions and 1 deletions

View File

@ -481,10 +481,15 @@
issues_count=#{count},
issues = #{issues}
</set>
where
case_id=#{caseId,jdbcType=VARCHAR}
<if test="id != null and id != ''">
and plan_id=#{id,jdbcType=VARCHAR}
</if>
where plan_id=#{id,jdbcType=VARCHAR} and case_id=#{caseId,jdbcType=VARCHAR}
</update>
<delete id="deleteByTestCaseID" parameterType="java.lang.String">
delete
from test_plan_api_case

View File

@ -52,6 +52,7 @@ public class AppStartListener implements ApplicationListener<ApplicationReadyEve
initOperate(apiAutomationService::checkApiScenarioUseUrl, "init.scenario.url");
initOperate(issuesService::syncThirdPartyIssues, "init.issue");
initOperate(issuesService::issuesCount, "init.issueCount");
try {
Thread.sleep(1 * 60 * 1000);

View File

@ -1,10 +1,16 @@
package io.metersphere.track.controller;
import com.alibaba.fastjson.JSON;
import io.metersphere.base.domain.IssuesDao;
import io.metersphere.base.mapper.ext.ExtTestPlanTestCaseMapper;
import io.metersphere.commons.constants.OperLogConstants;
import io.metersphere.commons.utils.LogUtil;
import io.metersphere.log.annotation.MsAuditLog;
import io.metersphere.track.dto.TestCaseDTO;
import io.metersphere.track.request.issues.IssuesRelevanceRequest;
import io.metersphere.track.service.IssuesService;
import io.metersphere.track.service.TestCaseIssueService;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
@ -19,6 +25,10 @@ public class TestCaseIssuesController {
@Resource
private TestCaseIssueService testCaseIssueService;
@Resource
private IssuesService issuesService;
@Resource
private ExtTestPlanTestCaseMapper extTestPlanTestCaseMapper;
@PostMapping("/list")
public List<TestCaseDTO> 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<IssuesDao> 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);
}
}

View File

@ -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<IssuesDao> 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<List<TestPlanTestCase>> page = PageHelper.startPage(i, pageSize, true);
List<TestPlanTestCaseWithBLOBs> list = testPlanTestCaseService.listAll();
pages = page.getPages();// 替换成真实的值
list.forEach(l -> {
try {
List<IssuesDao> 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);

View File

@ -31,6 +31,7 @@ public class TestCaseIssueService {
@Resource
private IssuesMapper issuesMapper;
public void delTestCaseIssues(String testCaseId) {
TestCaseIssuesExample example = new TestCaseIssuesExample();
example.createCriteria().andTestCaseIdEqualTo(testCaseId);