From 1f1b96fb52c99f343bb81b03e49e73cd5f5c04a0 Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Thu, 15 Sep 2022 18:56:53 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=B5=8B=E8=AF=95=E8=B7=9F=E8=B8=AA):=20?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92=E6=8A=A5=E5=91=8A=E7=BC=BA?= =?UTF-8?q?=E9=99=B7=E5=88=97=E8=A1=A8=E7=8A=B6=E6=80=81=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E6=9C=89=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1016730 --user=陈建星 【测试跟踪】github #17830,缺陷管理将缺陷变更状态之后,在测试计划报告中关联的缺陷状态未发生改变。 https://www.tapd.cn/55049933/s/1243631 --- .../service/CustomFieldService.java | 18 ++++++++++ .../track/service/IssuesService.java | 35 +++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/backend/src/main/java/io/metersphere/service/CustomFieldService.java b/backend/src/main/java/io/metersphere/service/CustomFieldService.java index bc7e080564..ed55e7174e 100644 --- a/backend/src/main/java/io/metersphere/service/CustomFieldService.java +++ b/backend/src/main/java/io/metersphere/service/CustomFieldService.java @@ -284,6 +284,24 @@ public class CustomFieldService { .collect(Collectors.toMap(i -> i.getName() + i.getScene(), i -> i)); } + public CustomField getCustomFieldByName(String projectId, String fieldName) { + CustomFieldExample example = new CustomFieldExample(); + example.createCriteria() + .andProjectIdEqualTo(projectId) + .andNameEqualTo(fieldName); + List customFields = customFieldMapper.selectByExample(example); + if (CollectionUtils.isNotEmpty(customFields)) { + return customFields.get(0); + } else { + example.clear(); + example.createCriteria() + .andGlobalEqualTo(true) + .andNameEqualTo(fieldName); + customFields = customFieldMapper.selectByExample(example); + return CollectionUtils.isNotEmpty(customFields) ? customFields.get(0) : null; + } + } + public Map getIssueSystemCustomFieldByName(String fieldName, String projectId, List resourceIds) { if (CollectionUtils.isEmpty(resourceIds)) { return null; 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 2f2ddbecfe..c7a74fe246 100644 --- a/backend/src/main/java/io/metersphere/track/service/IssuesService.java +++ b/backend/src/main/java/io/metersphere/track/service/IssuesService.java @@ -14,6 +14,7 @@ import io.metersphere.commons.exception.MSException; import io.metersphere.commons.utils.*; import io.metersphere.controller.request.IntegrationRequest; import io.metersphere.dto.CustomFieldDao; +import io.metersphere.dto.CustomFieldOption; import io.metersphere.dto.IssueTemplateDao; import io.metersphere.i18n.Translator; import io.metersphere.log.utils.ReflexObjectUtil; @@ -730,9 +731,43 @@ public class IssuesService { IssuesRequest issueRequest = new IssuesRequest(); issueRequest.setPlanId(planId); List planIssues = extIssuesMapper.getPlanIssues(issueRequest); + + buildCustomField(planIssues); + + replaceStatus(planIssues, planId); + return disconnectIssue(planIssues); } + private void replaceStatus(List planIssues, String planId) { + TestPlanWithBLOBs testPlan = testPlanService.get(planId); + CustomField customField = customFieldService.getCustomFieldByName(testPlan.getProjectId(), SystemCustomField.ISSUE_STATUS); + planIssues.forEach(issue -> { + List fields = issue.getFields(); + if (CollectionUtils.isNotEmpty(fields)) { + for (CustomFieldDao field : fields) { + if (field.getId().equals(customField.getId())) { + List options = JSONObject.parseArray(customField.getOptions(), CustomFieldOption.class); + for (CustomFieldOption option : options) { + String value = field.getValue(); + if (value != null) { + value = (String) JSONObject.parse(value); + } + if (StringUtils.equals(option.getValue(), value)) { + if (option.getSystem()) { + issue.setStatus(option.getValue()); + } else { + issue.setStatus(option.getText()); + } + } + } + break; + } + } + } + }); + } + public List disconnectIssue(List issues) { Set ids = new HashSet<>(issues.size()); Iterator iterator = issues.iterator();