diff --git a/backend/src/main/java/io/metersphere/base/domain/Issues.java b/backend/src/main/java/io/metersphere/base/domain/Issues.java index 03499fc1b6..1339f9ccb5 100644 --- a/backend/src/main/java/io/metersphere/base/domain/Issues.java +++ b/backend/src/main/java/io/metersphere/base/domain/Issues.java @@ -31,5 +31,7 @@ public class Issues implements Serializable { private String platformStatus; + private String platformId; + private static final long serialVersionUID = 1L; } \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/domain/IssuesExample.java b/backend/src/main/java/io/metersphere/base/domain/IssuesExample.java index 89f871331f..483d9a1205 100644 --- a/backend/src/main/java/io/metersphere/base/domain/IssuesExample.java +++ b/backend/src/main/java/io/metersphere/base/domain/IssuesExample.java @@ -983,6 +983,76 @@ public class IssuesExample { addCriterion("platform_status not between", value1, value2, "platformStatus"); return (Criteria) this; } + + public Criteria andPlatformIdIsNull() { + addCriterion("platform_id is null"); + return (Criteria) this; + } + + public Criteria andPlatformIdIsNotNull() { + addCriterion("platform_id is not null"); + return (Criteria) this; + } + + public Criteria andPlatformIdEqualTo(String value) { + addCriterion("platform_id =", value, "platformId"); + return (Criteria) this; + } + + public Criteria andPlatformIdNotEqualTo(String value) { + addCriterion("platform_id <>", value, "platformId"); + return (Criteria) this; + } + + public Criteria andPlatformIdGreaterThan(String value) { + addCriterion("platform_id >", value, "platformId"); + return (Criteria) this; + } + + public Criteria andPlatformIdGreaterThanOrEqualTo(String value) { + addCriterion("platform_id >=", value, "platformId"); + return (Criteria) this; + } + + public Criteria andPlatformIdLessThan(String value) { + addCriterion("platform_id <", value, "platformId"); + return (Criteria) this; + } + + public Criteria andPlatformIdLessThanOrEqualTo(String value) { + addCriterion("platform_id <=", value, "platformId"); + return (Criteria) this; + } + + public Criteria andPlatformIdLike(String value) { + addCriterion("platform_id like", value, "platformId"); + return (Criteria) this; + } + + public Criteria andPlatformIdNotLike(String value) { + addCriterion("platform_id not like", value, "platformId"); + return (Criteria) this; + } + + public Criteria andPlatformIdIn(List values) { + addCriterion("platform_id in", values, "platformId"); + return (Criteria) this; + } + + public Criteria andPlatformIdNotIn(List values) { + addCriterion("platform_id not in", values, "platformId"); + return (Criteria) this; + } + + public Criteria andPlatformIdBetween(String value1, String value2) { + addCriterion("platform_id between", value1, value2, "platformId"); + return (Criteria) this; + } + + public Criteria andPlatformIdNotBetween(String value1, String value2) { + addCriterion("platform_id not between", value1, value2, "platformId"); + return (Criteria) this; + } } public static class Criteria extends GeneratedCriteria { diff --git a/backend/src/main/java/io/metersphere/base/mapper/IssuesMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/IssuesMapper.xml index 7418f4ddcb..bb22b76848 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/IssuesMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/IssuesMapper.xml @@ -15,6 +15,7 @@ + @@ -80,7 +81,7 @@ id, title, `status`, create_time, update_time, reporter, lastmodify, platform, project_id, - creator, resource_id, num, platform_status + creator, resource_id, num, platform_status, platform_id description, custom_fields @@ -138,14 +139,14 @@ create_time, update_time, reporter, lastmodify, platform, project_id, creator, resource_id, num, - platform_status, description, custom_fields - ) + platform_status, platform_id, description, + custom_fields) values (#{id,jdbcType=VARCHAR}, #{title,jdbcType=VARCHAR}, #{status,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT}, #{updateTime,jdbcType=BIGINT}, #{reporter,jdbcType=VARCHAR}, #{lastmodify,jdbcType=VARCHAR}, #{platform,jdbcType=VARCHAR}, #{projectId,jdbcType=VARCHAR}, #{creator,jdbcType=VARCHAR}, #{resourceId,jdbcType=VARCHAR}, #{num,jdbcType=INTEGER}, - #{platformStatus,jdbcType=VARCHAR}, #{description,jdbcType=LONGVARCHAR}, #{customFields,jdbcType=LONGVARCHAR} - ) + #{platformStatus,jdbcType=VARCHAR}, #{platformId,jdbcType=VARCHAR}, #{description,jdbcType=LONGVARCHAR}, + #{customFields,jdbcType=LONGVARCHAR}) insert into issues @@ -189,6 +190,9 @@ platform_status, + + platform_id, + description, @@ -236,6 +240,9 @@ #{platformStatus,jdbcType=VARCHAR}, + + #{platformId,jdbcType=VARCHAR}, + #{description,jdbcType=LONGVARCHAR}, @@ -292,6 +299,9 @@ platform_status = #{record.platformStatus,jdbcType=VARCHAR}, + + platform_id = #{record.platformId,jdbcType=VARCHAR}, + description = #{record.description,jdbcType=LONGVARCHAR}, @@ -318,6 +328,7 @@ resource_id = #{record.resourceId,jdbcType=VARCHAR}, num = #{record.num,jdbcType=INTEGER}, platform_status = #{record.platformStatus,jdbcType=VARCHAR}, + platform_id = #{record.platformId,jdbcType=VARCHAR}, description = #{record.description,jdbcType=LONGVARCHAR}, custom_fields = #{record.customFields,jdbcType=LONGVARCHAR} @@ -338,7 +349,8 @@ creator = #{record.creator,jdbcType=VARCHAR}, resource_id = #{record.resourceId,jdbcType=VARCHAR}, num = #{record.num,jdbcType=INTEGER}, - platform_status = #{record.platformStatus,jdbcType=VARCHAR} + platform_status = #{record.platformStatus,jdbcType=VARCHAR}, + platform_id = #{record.platformId,jdbcType=VARCHAR} @@ -382,6 +394,9 @@ platform_status = #{platformStatus,jdbcType=VARCHAR}, + + platform_id = #{platformId,jdbcType=VARCHAR}, + description = #{description,jdbcType=LONGVARCHAR}, @@ -405,6 +420,7 @@ resource_id = #{resourceId,jdbcType=VARCHAR}, num = #{num,jdbcType=INTEGER}, platform_status = #{platformStatus,jdbcType=VARCHAR}, + platform_id = #{platformId,jdbcType=VARCHAR}, description = #{description,jdbcType=LONGVARCHAR}, custom_fields = #{customFields,jdbcType=LONGVARCHAR} where id = #{id,jdbcType=VARCHAR} @@ -422,7 +438,8 @@ creator = #{creator,jdbcType=VARCHAR}, resource_id = #{resourceId,jdbcType=VARCHAR}, num = #{num,jdbcType=INTEGER}, - platform_status = #{platformStatus,jdbcType=VARCHAR} + platform_status = #{platformStatus,jdbcType=VARCHAR}, + platform_id = #{platformId,jdbcType=VARCHAR} where id = #{id,jdbcType=VARCHAR} \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtIssuesMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtIssuesMapper.xml index b39efdfd94..fcb3dd2944 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtIssuesMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtIssuesMapper.xml @@ -13,7 +13,7 @@ diff --git a/backend/src/main/java/io/metersphere/track/issue/AbstractIssuePlatform.java b/backend/src/main/java/io/metersphere/track/issue/AbstractIssuePlatform.java index b70db57935..d446a1168c 100644 --- a/backend/src/main/java/io/metersphere/track/issue/AbstractIssuePlatform.java +++ b/backend/src/main/java/io/metersphere/track/issue/AbstractIssuePlatform.java @@ -194,10 +194,11 @@ public abstract class AbstractIssuePlatform implements IssuesPlatform { issuesMapper.insert(issues); } - protected void insertIssues(String id, IssuesUpdateRequest issuesRequest) { + protected void insertIssues(IssuesUpdateRequest issuesRequest) { IssuesWithBLOBs issues = new IssuesWithBLOBs(); BeanUtils.copyBean(issues, issuesRequest); - issues.setId(id); + issues.setId(issuesRequest.getId()); + issues.setPlatformId(issuesRequest.getPlatformId()); issues.setCreateTime(System.currentTimeMillis()); issues.setUpdateTime(System.currentTimeMillis()); issues.setNum(getNextNum(issuesRequest.getProjectId())); 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 37fb421def..df9254d3f8 100644 --- a/backend/src/main/java/io/metersphere/track/issue/JiraPlatform.java +++ b/backend/src/main/java/io/metersphere/track/issue/JiraPlatform.java @@ -34,6 +34,7 @@ import org.springframework.web.client.RestTemplate; import java.io.File; import java.util.ArrayList; import java.util.List; +import java.util.UUID; public class JiraPlatform extends AbstractIssuePlatform { @@ -99,7 +100,6 @@ public class JiraPlatform extends AbstractIssuePlatform { if (assignee != null) { lastmodify = assignee.getString("displayName"); } - item.setId(jiraIssue.getKey()); item.setTitle(fields.getString("summary")); item.setCreateTime(fields.getLong("created")); item.setLastmodify(lastmodify); @@ -247,15 +247,18 @@ public class JiraPlatform extends AbstractIssuePlatform { imageFiles.forEach(img -> { jiraClientV2.uploadAttachment(result.getKey(), img); }); + String status = getStatus(issues.getFields()); issuesRequest.setPlatformStatus(status); - issuesRequest.setId(result.getKey()); - // 用例与第三方缺陷平台中的缺陷关联 - handleTestCaseIssues(issuesRequest); + issuesRequest.setPlatformId(result.getKey()); + issuesRequest.setId(UUID.randomUUID().toString()); // 插入缺陷表 - insertIssues(result.getKey(), issuesRequest); + insertIssues(issuesRequest); + + // 用例与第三方缺陷平台中的缺陷关联 + handleTestCaseIssues(issuesRequest); } private JSONObject buildUpdateParam(IssuesUpdateRequest issuesRequest) { @@ -329,14 +332,15 @@ public class JiraPlatform extends AbstractIssuePlatform { public void updateIssue(IssuesUpdateRequest request) { JSONObject param = buildUpdateParam(request); handleIssueUpdate(request); - jiraClientV2.updateIssue(request.getId(), JSONObject.toJSONString(param)); + jiraClientV2.updateIssue(request.getPlatformId(), JSONObject.toJSONString(param)); } @Override public void deleteIssue(String id) { + IssuesWithBLOBs issuesWithBLOBs = issuesMapper.selectByPrimaryKey(id); super.deleteIssue(id); setConfig(); - jiraClientV2.deleteIssue(id); + jiraClientV2.deleteIssue(issuesWithBLOBs.getPlatformId()); } @Override @@ -367,7 +371,7 @@ public class JiraPlatform extends AbstractIssuePlatform { setConfig(); try { IssuesWithBLOBs issuesWithBLOBs = issuesMapper.selectByPrimaryKey(item.getId()); - parseIssue(item, jiraClientV2.getIssues(item.getId()), issuesWithBLOBs.getCustomFields()); + parseIssue(item, jiraClientV2.getIssues(item.getPlatformId()), issuesWithBLOBs.getCustomFields()); String desc = htmlDesc2MsDesc(item.getDescription()); // 保留之前上传的图片 String images = getImages(issuesWithBLOBs.getDescription()); diff --git a/backend/src/main/java/io/metersphere/track/issue/LocalPlatform.java b/backend/src/main/java/io/metersphere/track/issue/LocalPlatform.java index b544f5ac6f..4a4d22895a 100644 --- a/backend/src/main/java/io/metersphere/track/issue/LocalPlatform.java +++ b/backend/src/main/java/io/metersphere/track/issue/LocalPlatform.java @@ -44,6 +44,7 @@ public class LocalPlatform extends LocalAbstractPlatform { IssuesWithBLOBs issues = new IssuesWithBLOBs(); BeanUtils.copyBean(issues, issuesRequest); issues.setId(id); + issues.setPlatformId(id); issues.setStatus("new"); issues.setReporter(user.getId()); issues.setCreateTime(System.currentTimeMillis()); 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 60f94f70bd..0d4bed5de7 100644 --- a/backend/src/main/java/io/metersphere/track/issue/TapdPlatform.java +++ b/backend/src/main/java/io/metersphere/track/issue/TapdPlatform.java @@ -3,10 +3,7 @@ package io.metersphere.track.issue; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; -import io.metersphere.base.domain.Issues; -import io.metersphere.base.domain.IssuesDao; -import io.metersphere.base.domain.Project; -import io.metersphere.base.domain.TestCaseWithBLOBs; +import io.metersphere.base.domain.*; import io.metersphere.commons.constants.IssuesManagePlatform; import io.metersphere.commons.constants.IssuesStatus; import io.metersphere.commons.exception.MSException; @@ -37,6 +34,7 @@ import org.springframework.web.client.RestTemplate; import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.UUID; import java.util.stream.Collectors; public class TapdPlatform extends AbstractIssuePlatform { @@ -91,18 +89,20 @@ public class TapdPlatform extends AbstractIssuePlatform { Map statusMap = tapdClient.getStatusMap(getProjectId(this.projectId)); issuesRequest.setPlatformStatus(statusMap.get(bug.getStatus())); - issuesRequest.setId(bug.getId()); - // 用例与第三方缺陷平台中的缺陷关联 - handleTestCaseIssues(issuesRequest); + issuesRequest.setPlatformId(bug.getId()); + issuesRequest.setId(UUID.randomUUID().toString()); // 插入缺陷表 - insertIssues(bug.getId(), issuesRequest); + insertIssues(issuesRequest); + + // 用例与第三方缺陷平台中的缺陷关联 + handleTestCaseIssues(issuesRequest); } @Override public void updateIssue(IssuesUpdateRequest request) { MultiValueMap param = buildUpdateParam(request); - param.add("id", request.getId()); + param.add("id", request.getPlatformId()); handleIssueUpdate(request); tapdClient.updateIssue(param); } @@ -199,8 +199,11 @@ public class TapdPlatform extends AbstractIssuePlatform { int limit = 50; int count = 50; + Map idMap = tapdIssues.stream() + .collect(Collectors.toMap(IssuesDao::getPlatformId, IssuesDao::getId)); + List ids = tapdIssues.stream() - .map(Issues::getId) + .map(IssuesDao::getPlatformId) .collect(Collectors.toList()); LogUtil.info("ids: " + ids); @@ -214,7 +217,6 @@ public class TapdPlatform extends AbstractIssuePlatform { Map statusMap = tapdClient.getStatusMap(project.getTapdId()); while (count == limit) { - count = 0; TapdGetIssueResponse result = tapdClient.getIssueForPageByIds(project.getTapdId(), pageNum, limit, ids); List data = result.getData(); count = data.size(); @@ -223,6 +225,7 @@ public class TapdPlatform extends AbstractIssuePlatform { TapdBug bug = issue.getBug(); IssuesDao issuesDao = new IssuesDao(); BeanUtils.copyBean(issuesDao, bug); + issuesDao.setId(idMap.get(issuesDao.getId())); issuesDao.setPlatformStatus(statusMap.get(bug.getStatus())); issuesDao.setDescription(htmlDesc2MsDesc(issuesDao.getDescription())); issuesMapper.updateByPrimaryKeySelective(issuesDao); @@ -231,10 +234,12 @@ public class TapdPlatform extends AbstractIssuePlatform { } // 查不到的就置为删除 ids.forEach((id) -> { - IssuesDao issuesDao = new IssuesDao(); - issuesDao.setId(id); - issuesDao.setPlatformStatus(IssuesStatus.DELETE.toString()); - issuesMapper.updateByPrimaryKeySelective(issuesDao); + if (StringUtils.isNotBlank(idMap.get(id))) { + IssuesDao issuesDao = new IssuesDao(); + issuesDao.setId(idMap.get(id)); + issuesDao.setPlatformStatus(IssuesStatus.DELETE.toString()); + issuesMapper.updateByPrimaryKeySelective(issuesDao); + } }); } 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 98263d92b3..7e50a0560b 100644 --- a/backend/src/main/java/io/metersphere/track/issue/ZentaoPlatform.java +++ b/backend/src/main/java/io/metersphere/track/issue/ZentaoPlatform.java @@ -158,7 +158,6 @@ public class ZentaoPlatform extends AbstractIssuePlatform { LogUtil.error(e.getMessage(), e); } IssuesDao issues = new IssuesDao(); - issues.setId(bug.getId()); issues.setPlatformStatus(bug.getStatus()); if (StringUtils.equals(bug.getDeleted(),"1")) { issues.setPlatformStatus(IssuesStatus.DELETE.toString()); @@ -179,17 +178,19 @@ public class ZentaoPlatform extends AbstractIssuePlatform { String id = issue.getId(); if (StringUtils.isNotBlank(id)) { - issuesRequest.setId(id); - // 用例与第三方缺陷平台中的缺陷关联 - handleTestCaseIssues(issuesRequest); + issuesRequest.setPlatformId(id); + issuesRequest.setId(UUID.randomUUID().toString()); IssuesExample issuesExample = new IssuesExample(); issuesExample.createCriteria().andIdEqualTo(id) .andPlatformEqualTo(IssuesManagePlatform.Zentao.toString()); if (issuesMapper.selectByExample(issuesExample).size() <= 0) { // 插入缺陷表 - insertIssues(id, issuesRequest); + insertIssues(issuesRequest); } + + // 用例与第三方缺陷平台中的缺陷关联 + handleTestCaseIssues(issuesRequest); } } @@ -198,7 +199,7 @@ public class ZentaoPlatform extends AbstractIssuePlatform { MultiValueMap param = buildUpdateParam(request); handleIssueUpdate(request); zentaoClient.setConfig(getUserConfig()); - zentaoClient.updateIssue(request.getId(), param); + zentaoClient.updateIssue(request.getPlatformId(), param); } private MultiValueMap buildUpdateParam(IssuesUpdateRequest issuesRequest) { @@ -242,9 +243,10 @@ public class ZentaoPlatform extends AbstractIssuePlatform { @Override public void deleteIssue(String id) { + IssuesWithBLOBs issuesWithBLOBs = issuesMapper.selectByPrimaryKey(id); super.deleteIssue(id); zentaoClient.setConfig(getUserConfig()); - zentaoClient.deleteIssue(id); + zentaoClient.deleteIssue(issuesWithBLOBs.getPlatformId()); } @Override @@ -327,7 +329,8 @@ public class ZentaoPlatform extends AbstractIssuePlatform { public void syncIssues(Project project, List issues) { issues.forEach(item -> { setConfig(); - IssuesDao issuesDao = getZentaoIssues(item.getId()); + IssuesDao issuesDao = getZentaoIssues(item.getPlatformId()); + issuesDao.setId(item.getId()); issuesMapper.updateByPrimaryKeySelective(issuesDao); }); } diff --git a/backend/src/main/java/io/metersphere/xpack b/backend/src/main/java/io/metersphere/xpack index d9804d8c3d..ec08189a4f 160000 --- a/backend/src/main/java/io/metersphere/xpack +++ b/backend/src/main/java/io/metersphere/xpack @@ -1 +1 @@ -Subproject commit d9804d8c3d0496423403794f0997b3b596871a27 +Subproject commit ec08189a4f2c3aebf0688f4b9798af2993002d25 diff --git a/backend/src/main/resources/db/migration/V97__v1.14_release.sql b/backend/src/main/resources/db/migration/V97__v1.14_release.sql index 7b014e689f..35d4edce62 100644 --- a/backend/src/main/resources/db/migration/V97__v1.14_release.sql +++ b/backend/src/main/resources/db/migration/V97__v1.14_release.sql @@ -453,3 +453,6 @@ WHERE follow_people IS NOT NULL AND follow_people != ''; ALTER TABLE test_case DROP COLUMN follow_people; -- 操作日志类型增加普通索引 ALTER TABLE `operating_log` ADD INDEX oper_module_index ( `oper_module` ); + +ALTER TABLE issues ADD platform_id varchar(50) NOT NULL; +UPDATE issues SET platform_id = id WHERE 1;