fix(缺陷管理): 缺陷同步
This commit is contained in:
parent
ec1434964c
commit
b385953245
|
@ -1,6 +1,7 @@
|
|||
package io.metersphere.base.domain;
|
||||
|
||||
import io.metersphere.dto.CustomFieldDao;
|
||||
import io.metersphere.dto.CustomFieldItemDTO;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
|
@ -23,4 +24,15 @@ public class IssuesDao extends IssuesWithBLOBs {
|
|||
private String refType;
|
||||
private String refId;
|
||||
private List<CustomFieldDao> fields;
|
||||
|
||||
/**
|
||||
* 缺陷自定义字段相关
|
||||
*/
|
||||
private List<CustomFieldItemDTO> customFieldList;
|
||||
private String customData;
|
||||
private String issueId;
|
||||
private String fieldId;
|
||||
private String fieldName;
|
||||
private String fieldType;
|
||||
private String fieldValue;
|
||||
}
|
||||
|
|
|
@ -39,4 +39,8 @@ public interface ExtIssuesMapper {
|
|||
IssuesDao selectByPrimaryKey(String id);
|
||||
|
||||
List<CustomFieldItemDTO> getIssueCustomField(String id);
|
||||
|
||||
List<IssuesDao> getIssueCustomFields(List<String> ids);
|
||||
|
||||
List<IssuesDao> getPlatformIssueByIds(@Param("ids") List<String> ids);
|
||||
}
|
||||
|
|
|
@ -139,7 +139,33 @@
|
|||
from custom_field_issues cfi
|
||||
join custom_field_template cft on cfi.field_id = cft.field_id
|
||||
join custom_field cf on cf.id = cft.field_id
|
||||
where cfi.resource_id = #{id}
|
||||
join project on project.id = cf.project_id and project.issue_template_id = cft.template_id
|
||||
where cfi.resource_id = #{issueId}
|
||||
</select>
|
||||
<select id="getPlatformIssueByIds" resultType="io.metersphere.base.domain.IssuesDao">
|
||||
select * from issues where platform_id in
|
||||
<foreach collection="ids" item="value" separator="," open="(" close=")">
|
||||
#{value}
|
||||
</foreach>
|
||||
</select>
|
||||
<select id="getIssueCustomFields" resultType="io.metersphere.base.domain.IssuesDao">
|
||||
select cfi.field_id as fieldId,
|
||||
cf.type fieldType,
|
||||
cft.custom_data,
|
||||
cf.name as fieldName,
|
||||
cfi.resource_id as id,
|
||||
case cf.type
|
||||
when 'richText' then cfi.text_value
|
||||
when 'textarea' then cfi.text_value
|
||||
else cfi.value end as fieldValue
|
||||
from custom_field_issues cfi
|
||||
join custom_field_template cft on cfi.field_id = cft.field_id
|
||||
join custom_field cf on cf.id = cft.field_id
|
||||
join project on project.id = cf.project_id and project.issue_template_id = cft.template_id
|
||||
where cfi.resource_id in
|
||||
<foreach collection="ids" item="value" separator="," open="(" close=")">
|
||||
#{value}
|
||||
</foreach>
|
||||
</select>
|
||||
|
||||
<sql id="queryWhereCondition">
|
||||
|
|
|
@ -1,14 +1,10 @@
|
|||
package io.metersphere.service;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import io.metersphere.base.domain.CustomField;
|
||||
import io.metersphere.base.domain.CustomFieldIssues;
|
||||
import io.metersphere.base.domain.CustomFieldIssuesExample;
|
||||
import io.metersphere.base.domain.Project;
|
||||
import io.metersphere.base.domain.*;
|
||||
import io.metersphere.base.domain.ext.CustomFieldResource;
|
||||
import io.metersphere.base.mapper.CustomFieldIssuesMapper;
|
||||
import io.metersphere.base.mapper.CustomFieldMapper;
|
||||
import io.metersphere.base.mapper.ext.ExtBaseMapper;
|
||||
import io.metersphere.base.mapper.ext.ExtCustomFieldResourceMapper;
|
||||
import io.metersphere.base.mapper.ext.ExtIssuesMapper;
|
||||
import io.metersphere.base.mapper.ext.ExtTestCaseMapper;
|
||||
|
@ -49,10 +45,6 @@ public class CustomFieldResourceService {
|
|||
@Resource
|
||||
ProjectService projectService;
|
||||
|
||||
@Lazy
|
||||
@Resource
|
||||
WorkspaceService workspaceService;
|
||||
|
||||
@Resource
|
||||
ExtTestCaseMapper extTestCaseMapper;
|
||||
|
||||
|
@ -62,9 +54,6 @@ public class CustomFieldResourceService {
|
|||
@Resource
|
||||
CustomFieldService customFieldService;
|
||||
|
||||
@Resource
|
||||
ExtBaseMapper extBaseMapper;
|
||||
|
||||
@Resource
|
||||
ExtCustomFieldResourceMapper extCustomFieldResourceMapper;
|
||||
|
||||
|
@ -143,8 +132,8 @@ public class CustomFieldResourceService {
|
|||
}
|
||||
List<String> fieldIds = resourceFieldMap.get(resourceId);
|
||||
for (CustomFieldResource customFieldResource : list) {
|
||||
customFieldResource.setResourceId(resourceId);
|
||||
if (CollectionUtils.isEmpty(fieldIds) || !fieldIds.contains(customFieldResource.getFieldId())) {
|
||||
customFieldResource.setResourceId(resourceId);
|
||||
addList.add(customFieldResource);
|
||||
} else {
|
||||
updateList.add(customFieldResource);
|
||||
|
@ -417,4 +406,38 @@ public class CustomFieldResourceService {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<IssuesDao> getPlatformIssueByIds(List<String> platformIds) {
|
||||
List<IssuesDao> issues = extIssuesMapper.getPlatformIssueByIds(platformIds);
|
||||
if (CollectionUtils.isEmpty(issues)) {
|
||||
return issues;
|
||||
}
|
||||
List<String> issueIds = issues.stream().map(IssuesDao::getId).collect(Collectors.toList());
|
||||
List<IssuesDao> issuesList = extIssuesMapper.getIssueCustomFields(issueIds);
|
||||
Map<String, List<CustomFieldItemDTO>> map = new HashMap<>();
|
||||
issuesList.forEach(f -> {
|
||||
List<CustomFieldItemDTO> list = map.get(f.getId());
|
||||
if (list == null) {
|
||||
list = new ArrayList<>();
|
||||
CustomFieldItemDTO dto = new CustomFieldItemDTO();
|
||||
dto.setId(f.getFieldId());
|
||||
dto.setName(f.getFieldName());
|
||||
dto.setType(f.getFieldType());
|
||||
dto.setValue(f.getFieldValue());
|
||||
dto.setCustomData(f.getCustomData());
|
||||
list.add(dto);
|
||||
map.put(f.getId(), list);
|
||||
} else {
|
||||
CustomFieldItemDTO dto = new CustomFieldItemDTO();
|
||||
dto.setId(f.getFieldId());
|
||||
dto.setName(f.getFieldName());
|
||||
dto.setType(f.getFieldType());
|
||||
dto.setValue(f.getFieldValue());
|
||||
dto.setCustomData(f.getCustomData());
|
||||
list.add(dto);
|
||||
}
|
||||
});
|
||||
issues.forEach(i -> i.setCustomFieldList(map.getOrDefault(i.getId(), new ArrayList<>())));
|
||||
return issues;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -528,6 +528,27 @@ public abstract class AbstractIssuePlatform implements IssuesPlatform {
|
|||
}
|
||||
}
|
||||
|
||||
// 缺陷对象带有自定义字段数据
|
||||
protected void mergeIfIssueWithCustomField(IssuesWithBLOBs issue, String defaultCustomField) {
|
||||
if (StringUtils.isBlank(defaultCustomFields)) {
|
||||
return;
|
||||
}
|
||||
JSONArray fields = JSONArray.parseArray(issue.getCustomFields());
|
||||
Set<String> ids = fields.stream().map(i -> ((JSONObject) i).getString("id")).collect(Collectors.toSet());
|
||||
JSONArray defaultFields = JSONArray.parseArray(defaultCustomField);
|
||||
defaultFields.forEach(item -> { // 如果自定义字段里没有模板新加的字段,就把新字段加上
|
||||
String id = ((JSONObject) item).getString("id");
|
||||
if (StringUtils.isBlank(id)) {
|
||||
id = ((JSONObject) item).getString("key");
|
||||
((JSONObject) item).put("id", id);
|
||||
}
|
||||
if (!ids.contains(id)) {
|
||||
fields.add(item);
|
||||
}
|
||||
});
|
||||
issue.setCustomFields(fields.toJSONString());
|
||||
}
|
||||
|
||||
public <T> T getConfig(String platform, Class<T> clazz) {
|
||||
String config = getPlatformConfig(platform);
|
||||
if (StringUtils.isBlank(config)) {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
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.IssuesDao;
|
||||
|
@ -12,6 +13,7 @@ import io.metersphere.commons.exception.MSException;
|
|||
import io.metersphere.commons.utils.BeanUtils;
|
||||
import io.metersphere.commons.utils.CommonBeanFactory;
|
||||
import io.metersphere.commons.utils.SessionUtils;
|
||||
import io.metersphere.dto.CustomFieldItemDTO;
|
||||
import io.metersphere.dto.UserDTO;
|
||||
import io.metersphere.i18n.Translator;
|
||||
import io.metersphere.service.SystemParameterService;
|
||||
|
@ -254,6 +256,25 @@ public class TapdPlatform extends AbstractIssuePlatform {
|
|||
return issue;
|
||||
}
|
||||
|
||||
protected IssuesWithBLOBs getUpdateIssue(IssuesWithBLOBs issue, JSONObject bug, List<CustomFieldItemDTO> customField) {
|
||||
if (issue == null) {
|
||||
issue = new IssuesWithBLOBs();
|
||||
issue.setCustomFields(defaultCustomFields);
|
||||
} else {
|
||||
issue.setCustomFields(JSON.toJSONString(customField));
|
||||
mergeIfIssueWithCustomField(issue, defaultCustomFields);
|
||||
}
|
||||
TapdBug bugObj = JSONObject.parseObject(bug.toJSONString(), TapdBug.class);
|
||||
BeanUtils.copyBean(issue, bugObj);
|
||||
issue.setPlatformStatus(bugObj.getStatus());
|
||||
issue.setDescription(htmlDesc2MsDesc(issue.getDescription()));
|
||||
issue.setCustomFields(syncIssueCustomField(issue.getCustomFields(), bug));
|
||||
issue.setPlatform(key);
|
||||
issue.setCreateTime(bug.getLong("created"));
|
||||
issue.setUpdateTime(bug.getLong("modified"));
|
||||
return issue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProjectId(String projectId) {
|
||||
return getProjectId(projectId, Project::getTapdId);
|
||||
|
|
|
@ -8,10 +8,6 @@ import com.github.pagehelper.PageHelper;
|
|||
import io.metersphere.base.domain.*;
|
||||
import io.metersphere.base.domain.ext.CustomFieldResource;
|
||||
import io.metersphere.base.mapper.*;
|
||||
import io.metersphere.base.mapper.IssueFollowMapper;
|
||||
import io.metersphere.base.mapper.IssuesMapper;
|
||||
import io.metersphere.base.mapper.TestCaseIssuesMapper;
|
||||
import io.metersphere.base.mapper.TestPlanTestCaseMapper;
|
||||
import io.metersphere.base.mapper.ext.ExtIssuesMapper;
|
||||
import io.metersphere.commons.constants.AttachmentType;
|
||||
import io.metersphere.commons.constants.IssueRefType;
|
||||
|
@ -425,9 +421,11 @@ public class IssuesService {
|
|||
issueFileExample.createCriteria().andIssueIdEqualTo(id);
|
||||
List<IssueFile> issueFiles = issueFileMapper.selectByExample(issueFileExample);
|
||||
List<String> fileIds = issueFiles.stream().map(IssueFile::getFileId).collect(Collectors.toList());
|
||||
FileAttachmentMetadataExample fileAttachmentMetadataExample = new FileAttachmentMetadataExample();
|
||||
fileAttachmentMetadataExample.createCriteria().andIdIn(fileIds);
|
||||
fileAttachmentMetadataMapper.deleteByExample(fileAttachmentMetadataExample);
|
||||
if (CollectionUtils.isNotEmpty(fileIds)) {
|
||||
FileAttachmentMetadataExample fileAttachmentMetadataExample = new FileAttachmentMetadataExample();
|
||||
fileAttachmentMetadataExample.createCriteria().andIdIn(fileIds);
|
||||
fileAttachmentMetadataMapper.deleteByExample(fileAttachmentMetadataExample);
|
||||
}
|
||||
issueFileMapper.deleteByExample(issueFileExample);
|
||||
fileService.deleteAttachment(AttachmentType.ISSUE.type(), id);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue