refactor: 缺陷添加platform_id

This commit is contained in:
chenjianxing 2021-10-26 19:02:26 +08:00 committed by jianxing
parent 99e6d2c6eb
commit c0daa6018d
11 changed files with 149 additions and 43 deletions

View File

@ -31,5 +31,7 @@ public class Issues implements Serializable {
private String platformStatus;
private String platformId;
private static final long serialVersionUID = 1L;
}

View File

@ -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<String> values) {
addCriterion("platform_id in", values, "platformId");
return (Criteria) this;
}
public Criteria andPlatformIdNotIn(List<String> 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 {

View File

@ -15,6 +15,7 @@
<result column="resource_id" jdbcType="VARCHAR" property="resourceId" />
<result column="num" jdbcType="INTEGER" property="num" />
<result column="platform_status" jdbcType="VARCHAR" property="platformStatus" />
<result column="platform_id" jdbcType="VARCHAR" property="platformId" />
</resultMap>
<resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="io.metersphere.base.domain.IssuesWithBLOBs">
<result column="description" jdbcType="LONGVARCHAR" property="description" />
@ -80,7 +81,7 @@
</sql>
<sql id="Base_Column_List">
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
</sql>
<sql id="Blob_Column_List">
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>
<insert id="insertSelective" parameterType="io.metersphere.base.domain.IssuesWithBLOBs">
insert into issues
@ -189,6 +190,9 @@
<if test="platformStatus != null">
platform_status,
</if>
<if test="platformId != null">
platform_id,
</if>
<if test="description != null">
description,
</if>
@ -236,6 +240,9 @@
<if test="platformStatus != null">
#{platformStatus,jdbcType=VARCHAR},
</if>
<if test="platformId != null">
#{platformId,jdbcType=VARCHAR},
</if>
<if test="description != null">
#{description,jdbcType=LONGVARCHAR},
</if>
@ -292,6 +299,9 @@
<if test="record.platformStatus != null">
platform_status = #{record.platformStatus,jdbcType=VARCHAR},
</if>
<if test="record.platformId != null">
platform_id = #{record.platformId,jdbcType=VARCHAR},
</if>
<if test="record.description != null">
description = #{record.description,jdbcType=LONGVARCHAR},
</if>
@ -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}
<if test="_parameter != null">
@ -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}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
@ -382,6 +394,9 @@
<if test="platformStatus != null">
platform_status = #{platformStatus,jdbcType=VARCHAR},
</if>
<if test="platformId != null">
platform_id = #{platformId,jdbcType=VARCHAR},
</if>
<if test="description != null">
description = #{description,jdbcType=LONGVARCHAR},
</if>
@ -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}
</update>
</mapper>

View File

@ -13,7 +13,7 @@
</select>
<select id="getIssues" resultType="io.metersphere.base.domain.IssuesDao">
select issues.id, issues.num, ifnull(issues.title, '') as title, issues.project_id, issues.create_time, issues.update_time,
select issues.id, issues.platform_id, issues.num, ifnull(issues.title, '') as title, issues.project_id, issues.create_time, issues.update_time,
ifnull(issues.description, '') as description, issues.status, issues.platform, issues.custom_fields, issues.reporter,
issues.creator,issues.resource_id,issues.platform_status,
issues.lastmodify
@ -43,7 +43,7 @@
<include refid="io.metersphere.base.mapper.ext.ExtBaseMapper.orders"/>
</select>
<select id="getIssueForSync" resultType="io.metersphere.base.domain.IssuesDao">
select id,platform
select id,platform, platform_id
from issues
where project_id = #{projectId} and platform != 'Local';
</select>

View File

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

View File

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

View File

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

View File

@ -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<String, String> 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<String, Object> 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<String, String> idMap = tapdIssues.stream()
.collect(Collectors.toMap(IssuesDao::getPlatformId, IssuesDao::getId));
List<String> 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<String, String> statusMap = tapdClient.getStatusMap(project.getTapdId());
while (count == limit) {
count = 0;
TapdGetIssueResponse result = tapdClient.getIssueForPageByIds(project.getTapdId(), pageNum, limit, ids);
List<TapdGetIssueResponse.Data> 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) -> {
if (StringUtils.isNotBlank(idMap.get(id))) {
IssuesDao issuesDao = new IssuesDao();
issuesDao.setId(id);
issuesDao.setId(idMap.get(id));
issuesDao.setPlatformStatus(IssuesStatus.DELETE.toString());
issuesMapper.updateByPrimaryKeySelective(issuesDao);
}
});
}

View File

@ -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<String, Object> param = buildUpdateParam(request);
handleIssueUpdate(request);
zentaoClient.setConfig(getUserConfig());
zentaoClient.updateIssue(request.getId(), param);
zentaoClient.updateIssue(request.getPlatformId(), param);
}
private MultiValueMap<String, Object> 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<IssuesDao> issues) {
issues.forEach(item -> {
setConfig();
IssuesDao issuesDao = getZentaoIssues(item.getId());
IssuesDao issuesDao = getZentaoIssues(item.getPlatformId());
issuesDao.setId(item.getId());
issuesMapper.updateByPrimaryKeySelective(issuesDao);
});
}

@ -1 +1 @@
Subproject commit d9804d8c3d0496423403794f0997b3b596871a27
Subproject commit ec08189a4f2c3aebf0688f4b9798af2993002d25

View File

@ -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;