diff --git a/backend/src/main/java/io/metersphere/service/CustomFieldService.java b/backend/src/main/java/io/metersphere/service/CustomFieldService.java index 483bcddb7e..3e344dcd72 100644 --- a/backend/src/main/java/io/metersphere/service/CustomFieldService.java +++ b/backend/src/main/java/io/metersphere/service/CustomFieldService.java @@ -123,13 +123,15 @@ public class CustomFieldService { .collect(Collectors.toMap(CustomField::getId, item -> item)); List result = new ArrayList<>(); - customFields.forEach((item) -> { - CustomFieldDao customFieldDao = new CustomFieldDao(); - CustomField customField = fieldMap.get(item.getFieldId()); - BeanUtils.copyBean(customFieldDao, customField); - BeanUtils.copyBean(customFieldDao, item); - result.add(customFieldDao); - }); + if (CollectionUtils.isNotEmpty(customFields)) { + customFields.forEach((item) -> { + CustomFieldDao customFieldDao = new CustomFieldDao(); + CustomField customField = fieldMap.get(item.getFieldId()); + BeanUtils.copyBean(customFieldDao, customField); + BeanUtils.copyBean(customFieldDao, item); + result.add(customFieldDao); + }); + } return result; } diff --git a/backend/src/main/java/io/metersphere/track/issue/JiraPlatform.java b/backend/src/main/java/io/metersphere/track/issue/JiraPlatform.java index 8cb7724087..bea53cc54a 100644 --- a/backend/src/main/java/io/metersphere/track/issue/JiraPlatform.java +++ b/backend/src/main/java/io/metersphere/track/issue/JiraPlatform.java @@ -65,9 +65,10 @@ public class JiraPlatform extends AbstractIssuePlatform { JiraConfig config = getConfig(); JiraClient.setConfig(config); List issuesIds = issues.stream().map(Issues::getId).collect(Collectors.toList()); - issuesIds.forEach(issuesId -> { - IssuesDao dto = parseIssue(JiraClient.getIssues(issuesId)); - if (StringUtils.isBlank(dto.getId())) { + issues.forEach(item -> { + String issuesId = item.getId(); + parseIssue(item, JiraClient.getIssues(issuesId)); + if (StringUtils.isBlank(item.getId())) { // 缺陷不存在,解除用例和缺陷的关联 TestCaseIssuesExample issuesExample = new TestCaseIssuesExample(); issuesExample.createCriteria() @@ -77,15 +78,15 @@ public class JiraPlatform extends AbstractIssuePlatform { issuesMapper.deleteByPrimaryKey(issuesId); } else { // 缺陷状态为 完成,则不显示 - if (!StringUtils.equals("done", dto.getStatus())) { - list.add(dto); + if (!StringUtils.equals("done", item.getStatus())) { + list.add(item); } } }); return list; } - public IssuesDao parseIssue(JiraIssue jiraIssue) { + public void parseIssue(IssuesDao item, JiraIssue jiraIssue) { String lastmodify = ""; String status = ""; JSONObject fields = jiraIssue.getFields(); @@ -106,15 +107,13 @@ public class JiraPlatform extends AbstractIssuePlatform { if (assignee != null) { lastmodify = assignee.getString("displayName"); } - IssuesDao issues = new IssuesDao(); - issues.setId(jiraIssue.getKey()); - issues.setTitle(fields.getString("summary")); - issues.setCreateTime(fields.getLong("created")); - issues.setLastmodify(lastmodify); - issues.setDescription(description); - issues.setStatus(status); - issues.setPlatform(IssuesManagePlatform.Jira.toString()); - return issues; + item.setId(jiraIssue.getKey()); + item.setTitle(fields.getString("summary")); + item.setCreateTime(fields.getLong("created")); + item.setLastmodify(lastmodify); + item.setDescription(description); + item.setStatus(status); + item.setPlatform(IssuesManagePlatform.Jira.toString()); } public HttpHeaders getAuthHeader(JSONObject object) { diff --git a/backend/src/main/java/io/metersphere/track/issue/TapdPlatform.java b/backend/src/main/java/io/metersphere/track/issue/TapdPlatform.java index b86441d3ee..9568c61372 100644 --- a/backend/src/main/java/io/metersphere/track/issue/TapdPlatform.java +++ b/backend/src/main/java/io/metersphere/track/issue/TapdPlatform.java @@ -42,9 +42,6 @@ public class TapdPlatform extends AbstractIssuePlatform { List list = new ArrayList<>(); String tapdId = getProjectId(issuesRequest.getProjectId()); -// TestCaseIssuesExample example = new TestCaseIssuesExample(); -// example.createCriteria().andTestCaseIdEqualTo(testCaseId); - issuesRequest.setPlatform(IssuesManagePlatform.Tapd.toString()); List issues; if (StringUtils.isNotBlank(issuesRequest.getProjectId())) { @@ -53,9 +50,10 @@ public class TapdPlatform extends AbstractIssuePlatform { issues = extIssuesMapper.getIssuesByCaseId(issuesRequest); } - List issuesIds = issues.stream().map(Issues::getId).collect(Collectors.toList()); - issuesIds.forEach(issuesId -> { + issues.forEach(item -> { + String issuesId = item.getId(); IssuesDao dto = getTapdIssues(tapdId, issuesId); + dto.setNum(item.getNum()); if (StringUtils.isBlank(dto.getId())) { // 缺陷不存在,解除用例和缺陷的关联 TestCaseIssuesExample issuesExample = new TestCaseIssuesExample(); diff --git a/backend/src/main/java/io/metersphere/track/issue/ZentaoPlatform.java b/backend/src/main/java/io/metersphere/track/issue/ZentaoPlatform.java index d9b5247e2a..e015fd6dc1 100644 --- a/backend/src/main/java/io/metersphere/track/issue/ZentaoPlatform.java +++ b/backend/src/main/java/io/metersphere/track/issue/ZentaoPlatform.java @@ -23,8 +23,10 @@ import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.web.client.RestTemplate; -import java.util.*; -import java.util.stream.Collectors; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Map; public class ZentaoPlatform extends AbstractIssuePlatform { /** @@ -72,9 +74,6 @@ public class ZentaoPlatform extends AbstractIssuePlatform { public List getIssue(IssuesRequest issuesRequest) { List list = new ArrayList<>(); -// TestCaseIssuesExample example = new TestCaseIssuesExample(); -// example.createCriteria().andTestCaseIdEqualTo(testCaseId); - issuesRequest.setPlatform(IssuesManagePlatform.Zentao.toString()); @@ -85,9 +84,10 @@ public class ZentaoPlatform extends AbstractIssuePlatform { issues = extIssuesMapper.getIssuesByCaseId(issuesRequest); } - List issuesIds = issues.stream().map(Issues::getId).collect(Collectors.toList()); - issuesIds.forEach(issuesId -> { + issues.forEach(item -> { + String issuesId = item.getId(); IssuesDao dto = getZentaoIssues(issuesId); + dto.setNum(item.getNum()); if (StringUtils.isBlank(dto.getId())) { // 缺陷不存在,解除用例和缺陷的关联 TestCaseIssuesExample issuesExample = new TestCaseIssuesExample(); diff --git a/frontend/src/business/components/track/case/components/TestCaseIssueRelate.vue b/frontend/src/business/components/track/case/components/TestCaseIssueRelate.vue index 7e56baf337..813076ac21 100644 --- a/frontend/src/business/components/track/case/components/TestCaseIssueRelate.vue +++ b/frontend/src/business/components/track/case/components/TestCaseIssueRelate.vue @@ -9,9 +9,9 @@ @@ -49,14 +49,14 @@ @@ -77,13 +77,16 @@ import MsTableColumn from "@/business/components/common/components/table/Ms-tabl import IssueDescriptionTableItem from "@/business/components/track/issue/IssueDescriptionTableItem"; import {ISSUE_STATUS_MAP} from "@/common/js/table-constants"; import IssueRelateList from "@/business/components/track/case/components/IssueRelateList"; +import {getIssuesByCaseId} from "@/network/Issue"; export default { name: "TestCaseIssueRelate", components: {IssueRelateList, IssueDescriptionTableItem, MsTableColumn, MsTable, TestPlanIssueEdit}, data() { return { - issues: [], - result: {}, + page: { + data: [], + result: {}, + }, } }, props: ['caseId', 'readOnly','planId'], @@ -94,11 +97,7 @@ export default { }, methods: { getIssues() { - if (this.caseId) { - this.result = this.$get("/issues/get/" + this.caseId, (response) => { - this.issues = response.data; - }); - } + this.page.result = getIssuesByCaseId(this.caseId, this.page); }, appIssue() { if (!this.caseId) { @@ -118,14 +117,14 @@ export default { if (row.status === 'closed') { this.$success(this.$t('test_track.issue.close_success')); } else { - this.result = this.$get("/issues/close/" + row.id, () => { + this.page.result = this.$get("/issues/close/" + row.id, () => { this.getIssues(); this.$success(this.$t('test_track.issue.close_success')); }); } }, deleteIssue(row) { - this.result = this.$post("/issues/delete", {id: row.id, caseId: this.caseId}, () => { + this.page.result = this.$post("/issues/delete", {id: row.id, caseId: this.caseId}, () => { this.getIssues(); this.$success(this.$t('commons.delete_success')); }) diff --git a/frontend/src/network/Issue.js b/frontend/src/network/Issue.js index fa237eb81c..2ab4046638 100644 --- a/frontend/src/network/Issue.js +++ b/frontend/src/network/Issue.js @@ -1,4 +1,4 @@ -import {post} from "@/common/js/ajax"; +import {post, get} from "@/common/js/ajax"; import {getPageDate} from "@/common/js/tableUtils"; export function buildIssues(page) { @@ -19,6 +19,15 @@ export function getIssues(page) { }); } +export function getIssuesByCaseId(caseId, page) { + if (caseId) { + return get('issues/get/' + caseId, (response) => { + page.data = response.data; + buildIssues(page); + }); + } +} + export function buildPlatformIssue(data) { return post("issues/get/platform/issue", data).then(response => { let issues = response.data.data;