fix(缺陷管理): 处理同步时缺陷的自定义字段
This commit is contained in:
parent
e391fd2f90
commit
5c97b750fc
|
@ -5,6 +5,7 @@ import io.metersphere.dto.CustomFieldDao;
|
|||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -26,6 +27,10 @@ public class CustomFieldIssuesService extends CustomFieldResourceService {
|
|||
super.batchEditFields(TABLE_NAME, resourceId, fields);
|
||||
}
|
||||
|
||||
public void batchEditFields(HashMap<String, List<CustomFieldResource>> customFieldMap) {
|
||||
super.batchEditFields(TABLE_NAME, customFieldMap);
|
||||
}
|
||||
|
||||
public int updateByPrimaryKeySelective(CustomFieldResource field) {
|
||||
return super.updateByPrimaryKeySelective(TABLE_NAME, field);
|
||||
}
|
||||
|
|
|
@ -2,8 +2,11 @@ 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.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;
|
||||
|
@ -33,6 +36,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
|
@ -68,6 +72,9 @@ public class CustomFieldResourceService {
|
|||
@Resource
|
||||
SystemParameterService systemParameterService;
|
||||
|
||||
@Resource
|
||||
CustomFieldIssuesMapper customFieldIssuesMapper;
|
||||
|
||||
private int initCount = 0;
|
||||
|
||||
protected void addFields(String tableName, String resourceId, List<CustomFieldResource> addFields) {
|
||||
|
@ -108,6 +115,50 @@ public class CustomFieldResourceService {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
protected void batchEditFields(String tableName, HashMap<String, List<CustomFieldResource>> customFieldMap) {
|
||||
if (customFieldMap == null || customFieldMap.size() == 0) {
|
||||
return;
|
||||
}
|
||||
this.checkInit();
|
||||
SqlSession sqlSession = ServiceUtils.getBatchSqlSession();
|
||||
ExtCustomFieldResourceMapper batchMapper = sqlSession.getMapper(ExtCustomFieldResourceMapper.class);
|
||||
List<CustomFieldResource> addList = new ArrayList<>();
|
||||
List<CustomFieldResource> updateList = new ArrayList<>();
|
||||
|
||||
Set<String> set = customFieldMap.keySet();
|
||||
if (CollectionUtils.isEmpty(set)) {
|
||||
return;
|
||||
}
|
||||
CustomFieldIssuesExample example = new CustomFieldIssuesExample();
|
||||
example.createCriteria().andResourceIdIn(new ArrayList<>(set));
|
||||
List<CustomFieldIssues> customFieldIssues = customFieldIssuesMapper.selectByExample(example);
|
||||
Map<String, List<String>> resourceFieldMap = customFieldIssues.stream()
|
||||
.collect(Collectors.groupingBy(CustomFieldIssues::getResourceId, Collectors.mapping(CustomFieldIssues::getFieldId, Collectors.toList())));
|
||||
|
||||
for (String resourceId : customFieldMap.keySet()) {
|
||||
List<CustomFieldResource> list = customFieldMap.get(resourceId);
|
||||
if (CollectionUtils.isEmpty(list)) {
|
||||
continue;
|
||||
}
|
||||
List<String> fieldIds = resourceFieldMap.get(resourceId);
|
||||
for (CustomFieldResource customFieldResource : list) {
|
||||
if (CollectionUtils.isEmpty(fieldIds) || !fieldIds.contains(customFieldResource.getFieldId())) {
|
||||
customFieldResource.setResourceId(resourceId);
|
||||
addList.add(customFieldResource);
|
||||
} else {
|
||||
updateList.add(customFieldResource);
|
||||
}
|
||||
}
|
||||
}
|
||||
addList.forEach(l -> batchMapper.insert(tableName, l));
|
||||
updateList.forEach(l -> batchMapper.updateByPrimaryKeySelective(tableName, l));
|
||||
sqlSession.flushStatements();
|
||||
if (sqlSession != null && sqlSessionFactory != null) {
|
||||
SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory);
|
||||
}
|
||||
}
|
||||
|
||||
private void createOrUpdateFields(String tableName, String resourceId, CustomFieldResource field) {
|
||||
long count = extCustomFieldResourceMapper.countFieldResource(tableName, resourceId, field.getFieldId());
|
||||
field.setResourceId(resourceId);
|
||||
|
|
|
@ -539,6 +539,7 @@ public class JiraPlatform extends AbstractIssuePlatform {
|
|||
@Override
|
||||
public void syncIssues(Project project, List<IssuesDao> issues) {
|
||||
super.isThirdPartTemplate = isThirdPartTemplate();
|
||||
HashMap<String, List<CustomFieldResource>> customFieldMap = new HashMap<>();
|
||||
|
||||
IssuesService issuesService = CommonBeanFactory.getBean(IssuesService.class);
|
||||
if (project.getThirdPartTemplate()) {
|
||||
|
@ -551,7 +552,7 @@ public class JiraPlatform extends AbstractIssuePlatform {
|
|||
String customFields = item.getCustomFields();
|
||||
// 把自定义字段存入新表
|
||||
List<CustomFieldResource> customFieldResource = customFieldService.getCustomFieldResource(customFields);
|
||||
customFieldIssuesService.addFields(item.getId(), customFieldResource);
|
||||
customFieldMap.put(item.getId(), customFieldResource);
|
||||
issuesMapper.updateByPrimaryKeySelective(item);
|
||||
} catch (HttpClientErrorException e) {
|
||||
if (e.getRawStatusCode() == 404) {
|
||||
|
@ -563,6 +564,7 @@ public class JiraPlatform extends AbstractIssuePlatform {
|
|||
LogUtil.error(e);
|
||||
}
|
||||
});
|
||||
customFieldIssuesService.batchEditFields(customFieldMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject;
|
|||
import io.metersphere.base.domain.IssuesDao;
|
||||
import io.metersphere.base.domain.IssuesWithBLOBs;
|
||||
import io.metersphere.base.domain.Project;
|
||||
import io.metersphere.base.domain.ext.CustomFieldResource;
|
||||
import io.metersphere.commons.constants.IssuesManagePlatform;
|
||||
import io.metersphere.commons.constants.IssuesStatus;
|
||||
import io.metersphere.commons.exception.MSException;
|
||||
|
@ -28,10 +29,7 @@ import org.apache.commons.lang3.StringUtils;
|
|||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class TapdPlatform extends AbstractIssuePlatform {
|
||||
|
@ -201,6 +199,7 @@ public class TapdPlatform extends AbstractIssuePlatform {
|
|||
.collect(Collectors.toList());
|
||||
|
||||
if (CollectionUtils.isEmpty(ids)) return;
|
||||
HashMap<String, List<CustomFieldResource>> customFieldMap = new HashMap<>();
|
||||
|
||||
Map<String, String> statusMap = tapdClient.getStatusMap(project.getTapdId());
|
||||
|
||||
|
@ -218,7 +217,7 @@ public class TapdPlatform extends AbstractIssuePlatform {
|
|||
IssuesWithBLOBs updateIssue = getUpdateIssue(issuesMapper.selectByPrimaryKey(id), bug, statusMap);
|
||||
updateIssue.setId(id);
|
||||
updateIssue.setCustomFields(syncIssueCustomField(updateIssue.getCustomFields(), bug));
|
||||
customFieldIssuesService.addFields(id, customFieldService.getCustomFieldResource(updateIssue.getCustomFields()));
|
||||
customFieldMap.put(id, customFieldService.getCustomFieldResource(updateIssue.getCustomFields()));
|
||||
issuesMapper.updateByPrimaryKeySelective(updateIssue);
|
||||
ids.remove(platformId);
|
||||
});
|
||||
|
@ -233,6 +232,7 @@ public class TapdPlatform extends AbstractIssuePlatform {
|
|||
issuesMapper.updateByPrimaryKeySelective(issuesDao);
|
||||
}
|
||||
});
|
||||
customFieldIssuesService.batchEditFields(customFieldMap);
|
||||
}
|
||||
|
||||
protected IssuesWithBLOBs getUpdateIssue(IssuesWithBLOBs issue, JSONObject bug, Map<String, String> statusMap) {
|
||||
|
|
|
@ -8,6 +8,7 @@ import io.metersphere.base.domain.IssuesDao;
|
|||
import io.metersphere.base.domain.IssuesExample;
|
||||
import io.metersphere.base.domain.IssuesWithBLOBs;
|
||||
import io.metersphere.base.domain.Project;
|
||||
import io.metersphere.base.domain.ext.CustomFieldResource;
|
||||
import io.metersphere.commons.constants.IssuesManagePlatform;
|
||||
import io.metersphere.commons.constants.IssuesStatus;
|
||||
import io.metersphere.commons.constants.ZentaoIssuePlatformStatus;
|
||||
|
@ -377,14 +378,17 @@ public class ZentaoPlatform extends AbstractIssuePlatform {
|
|||
|
||||
@Override
|
||||
public void syncIssues(Project project, List<IssuesDao> issues) {
|
||||
HashMap<String, List<CustomFieldResource>> customFieldMap = new HashMap<>();
|
||||
|
||||
issues.forEach(item -> {
|
||||
IssuesWithBLOBs issue = issuesMapper.selectByPrimaryKey(item.getId());
|
||||
JSONObject bug = zentaoClient.getBugById(item.getPlatformId());
|
||||
issue = getUpdateIssues(issue, bug);
|
||||
customFieldIssuesService.addFields(item.getId(), customFieldService.getCustomFieldResource(issue.getCustomFields()));
|
||||
customFieldMap.put(item.getId(), customFieldService.getCustomFieldResource(issue.getCustomFields()));
|
||||
issue.setId(item.getId());
|
||||
issuesMapper.updateByPrimaryKeySelective(issue);
|
||||
});
|
||||
customFieldIssuesService.batchEditFields(customFieldMap);
|
||||
}
|
||||
|
||||
public List<ZentaoBuild> getBuilds() {
|
||||
|
|
Loading…
Reference in New Issue