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