fix(缺陷管理): 缺陷中自定义字段的处理
This commit is contained in:
parent
6f431de67b
commit
b0979e27fd
|
@ -22,7 +22,7 @@
|
|||
<select id="lisSimple" resultType="io.metersphere.dto.CustomFieldDao">
|
||||
select
|
||||
template_id, required, default_value, custom_data,
|
||||
cft.id as id,
|
||||
cf.id as id,
|
||||
cf.name as name, cf.type as type
|
||||
from custom_field_template cft
|
||||
inner join custom_field cf
|
||||
|
|
|
@ -2,6 +2,7 @@ package io.metersphere.base.mapper.ext;
|
|||
|
||||
import io.metersphere.base.domain.Issues;
|
||||
import io.metersphere.base.domain.IssuesDao;
|
||||
import io.metersphere.dto.CustomFieldItemDTO;
|
||||
import io.metersphere.track.dto.CustomFieldResourceCompatibleDTO;
|
||||
import io.metersphere.track.dto.PlanReportIssueDTO;
|
||||
import io.metersphere.track.request.testcase.IssuesRequest;
|
||||
|
@ -36,4 +37,6 @@ public interface ExtIssuesMapper {
|
|||
List<CustomFieldResourceCompatibleDTO> getForCompatibleCustomField(String projectId, int offset, int pageSize);
|
||||
|
||||
IssuesDao selectByPrimaryKey(String id);
|
||||
|
||||
List<CustomFieldItemDTO> getIssueCustomField(String id);
|
||||
}
|
||||
|
|
|
@ -127,6 +127,20 @@
|
|||
from issues
|
||||
where id = #{id,jdbcType=VARCHAR}
|
||||
</select>
|
||||
<select id="getIssueCustomField" resultType="io.metersphere.dto.CustomFieldItemDTO">
|
||||
select cfi.field_id as id,
|
||||
cf.type,
|
||||
cft.custom_data,
|
||||
cf.name,
|
||||
case cf.type
|
||||
when 'richText' then cfi.text_value
|
||||
when 'textarea' then cfi.text_value
|
||||
else cfi.value end as value
|
||||
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}
|
||||
</select>
|
||||
|
||||
<sql id="queryWhereCondition">
|
||||
<where>
|
||||
|
|
|
@ -12,5 +12,6 @@ import java.io.Serializable;
|
|||
@ToString(callSuper = true)
|
||||
public class CustomFieldResourceDTO extends CustomFieldResource implements Serializable {
|
||||
private String name;
|
||||
private String type;
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
||||
|
|
|
@ -237,23 +237,9 @@ public class CustomFieldService {
|
|||
List<CustomFieldResource> list = new ArrayList<>();
|
||||
if (StringUtils.isNotBlank(customFieldsStr)) {
|
||||
if (JSONObject.parse(customFieldsStr) instanceof JSONArray) {
|
||||
List<CustomFieldItemDTO> fieldItems = JSONArray.parseArray(customFieldsStr, CustomFieldItemDTO.class);
|
||||
for (CustomFieldItemDTO dto : fieldItems) {
|
||||
// customFieldItemDTO里的id是模版ID
|
||||
CustomFieldResource resource = new CustomFieldResource();
|
||||
CustomFieldTemplate customFieldTemplate = customFieldTemplateMapper.selectByPrimaryKey(dto.getId());
|
||||
if (customFieldTemplate == null) {
|
||||
continue;
|
||||
} else {
|
||||
resource.setFieldId(customFieldTemplate.getFieldId());
|
||||
}
|
||||
if (StringUtils.isNotBlank(dto.getType())
|
||||
&& StringUtils.equalsAny(CustomFieldType.RICH_TEXT.getValue(), CustomFieldType.TEXTAREA.getValue())) {
|
||||
resource.setTextValue(dto.getValue().toString());
|
||||
} else {
|
||||
resource.setValue(JSONObject.toJSONString(dto.getValue()));
|
||||
}
|
||||
list.add(resource);
|
||||
List<CustomFieldItemDTO> items = JSONArray.parseArray(customFieldsStr, CustomFieldItemDTO.class);
|
||||
for (CustomFieldItemDTO item : items) {
|
||||
list.add(constructorCustomFieldResource(item));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
@ -261,50 +247,15 @@ public class CustomFieldService {
|
|||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
public List<CustomFieldResource> getJiraCustomFieldResource(String customFieldsStr, String projectId) {
|
||||
List<CustomFieldResource> list = new ArrayList<>();
|
||||
if (StringUtils.isNotBlank(customFieldsStr)) {
|
||||
if (JSONObject.parse(customFieldsStr) instanceof JSONArray) {
|
||||
List<CustomFieldItemDTO> fieldItems = JSONArray.parseArray(customFieldsStr, CustomFieldItemDTO.class);
|
||||
for (CustomFieldItemDTO dto : fieldItems) {
|
||||
private CustomFieldResource constructorCustomFieldResource(CustomFieldItemDTO dto) {
|
||||
CustomFieldResource resource = new CustomFieldResource();
|
||||
// customFieldItemDTO里的id是模版ID
|
||||
CustomFieldTemplate customFieldTemplate = customFieldTemplateMapper.selectByPrimaryKey(dto.getId());
|
||||
if (customFieldTemplate == null) {
|
||||
CustomField customField = customFieldMapper.selectByPrimaryKey(dto.getId());
|
||||
if (customField == null) {
|
||||
CustomField field = new CustomField();
|
||||
field.setId(dto.getId());
|
||||
field.setUpdateTime(System.currentTimeMillis());
|
||||
field.setCreateTime(System.currentTimeMillis());
|
||||
field.setGlobal(false);
|
||||
field.setSystem(false);
|
||||
field.setName(dto.getName());
|
||||
field.setScene(TemplateConstants.FieldTemplateScene.ISSUE.name());
|
||||
field.setThirdPart(true);
|
||||
field.setType(dto.getType());
|
||||
field.setProjectId(projectId);
|
||||
if (StringUtils.isNotBlank(SessionUtils.getUserId())) {
|
||||
field.setCreateUser(SessionUtils.getUserId());
|
||||
}
|
||||
customFieldMapper.insert(field);
|
||||
}
|
||||
resource.setFieldId(dto.getId());
|
||||
} else {
|
||||
resource.setFieldId(customFieldTemplate.getFieldId());
|
||||
}
|
||||
if (StringUtils.isNotBlank(dto.getType())
|
||||
&& StringUtils.equalsAny(CustomFieldType.RICH_TEXT.getValue(), CustomFieldType.TEXTAREA.getValue())) {
|
||||
if (StringUtils.isNotBlank(dto.getType()) && StringUtils.equalsAny(CustomFieldType.RICH_TEXT.getValue(), CustomFieldType.TEXTAREA.getValue())) {
|
||||
resource.setTextValue(dto.getValue().toString());
|
||||
} else {
|
||||
resource.setValue(JSONObject.toJSONString(dto.getValue()));
|
||||
}
|
||||
list.add(resource);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
return new ArrayList<>();
|
||||
return resource;
|
||||
}
|
||||
|
||||
public List<CustomField> getByProjectId(String projectId) {
|
||||
|
|
|
@ -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.*;
|
||||
|
@ -372,7 +373,7 @@ public abstract class AbstractIssuePlatform implements IssuesPlatform {
|
|||
}
|
||||
|
||||
protected void addCustomFields(IssuesUpdateRequest issuesRequest, MultiValueMap<String, Object> paramMap) {
|
||||
List<CustomFieldItemDTO> customFields = CustomFieldService.getCustomFields(issuesRequest.getCustomFields());
|
||||
List<CustomFieldItemDTO> customFields = issuesRequest.getRequestFields();
|
||||
customFields.forEach(item -> {
|
||||
if (StringUtils.isNotBlank(item.getCustomData())) {
|
||||
if (item.getValue() instanceof String) {
|
||||
|
@ -420,8 +421,17 @@ public abstract class AbstractIssuePlatform implements IssuesPlatform {
|
|||
if (value instanceof JSONObject) {
|
||||
item.setValue(getSyncJsonParamValue(value));
|
||||
} else if (value instanceof JSONArray) {
|
||||
// Sprint 是单选 同步回来是 JSONArray
|
||||
if (StringUtils.equals(item.getType(), "select")) {
|
||||
if (((JSONArray) value).size() > 0) {
|
||||
Object o = ((JSONArray) value).get(0);
|
||||
if (o instanceof JSONObject) {
|
||||
item.setValue(getSyncJsonParamValue(o));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
List<Object> values = new ArrayList<>();
|
||||
((JSONArray)value).forEach(attr -> {
|
||||
((JSONArray) value).forEach(attr -> {
|
||||
if (attr instanceof JSONObject) {
|
||||
values.add(getSyncJsonParamValue(attr));
|
||||
} else {
|
||||
|
@ -429,6 +439,7 @@ public abstract class AbstractIssuePlatform implements IssuesPlatform {
|
|||
}
|
||||
});
|
||||
item.setValue(values);
|
||||
}
|
||||
} else {
|
||||
item.setValue(value);
|
||||
}
|
||||
|
@ -487,9 +498,8 @@ public abstract class AbstractIssuePlatform implements IssuesPlatform {
|
|||
|
||||
protected void mergeCustomField(IssuesWithBLOBs issues, String defaultCustomField) {
|
||||
if (StringUtils.isNotBlank(defaultCustomField)) {
|
||||
String issuesCustomFields = issues.getCustomFields();
|
||||
if (StringUtils.isBlank(issuesCustomFields) || issuesCustomFields.startsWith("{")) issuesCustomFields = "[]";
|
||||
JSONArray issueFields = JSONArray.parseArray(issuesCustomFields);
|
||||
List<CustomFieldItemDTO> customFields = extIssuesMapper.getIssueCustomField(issues.getId());
|
||||
JSONArray issueFields = JSONArray.parseArray(JSON.toJSONString(customFields));
|
||||
Set<String> ids = issueFields.stream().map(i -> ((JSONObject) i).getString("id")).collect(Collectors.toSet());
|
||||
JSONArray defaultFields = JSONArray.parseArray(defaultCustomField);
|
||||
defaultFields.forEach(item -> { // 如果自定义字段里没有模板新加的字段,就把新字段加上
|
||||
|
|
|
@ -368,7 +368,7 @@ public class JiraPlatform extends AbstractIssuePlatform {
|
|||
}
|
||||
|
||||
private void parseCustomFiled(IssuesUpdateRequest issuesRequest, JSONObject fields) {
|
||||
List<CustomFieldItemDTO> customFields = CustomFieldService.getCustomFields(issuesRequest.getCustomFields());
|
||||
List<CustomFieldItemDTO> customFields = issuesRequest.getRequestFields();
|
||||
|
||||
customFields.forEach(item -> {
|
||||
String fieldName = item.getCustomData();
|
||||
|
@ -390,7 +390,7 @@ public class JiraPlatform extends AbstractIssuePlatform {
|
|||
} else if (StringUtils.equalsAny(item.getType(), "multipleSelect", "checkbox", "multipleMember")) {
|
||||
JSONArray attrs = new JSONArray();
|
||||
if (item.getValue() != null) {
|
||||
JSONArray values = (JSONArray)item.getValue();
|
||||
JSONArray values = JSONArray.parseArray((String) item.getValue());
|
||||
values.forEach(v -> {
|
||||
JSONObject param = new JSONObject();
|
||||
param.put("id", v);
|
||||
|
@ -402,7 +402,7 @@ public class JiraPlatform extends AbstractIssuePlatform {
|
|||
if (item.getValue() != null) {
|
||||
JSONObject attr = new JSONObject();
|
||||
if (item.getValue() instanceof JSONArray) {
|
||||
JSONArray values = (JSONArray) item.getValue();
|
||||
JSONArray values = JSONArray.parseArray((String) item.getValue());
|
||||
if (CollectionUtils.isNotEmpty(values)) {
|
||||
if (values.size() > 0) {
|
||||
attr.put("id", values.get(0));
|
||||
|
@ -521,7 +521,7 @@ public class JiraPlatform extends AbstractIssuePlatform {
|
|||
getUpdateIssue(item, jiraClientV2.getIssues(item.getPlatformId()));
|
||||
String customFields = item.getCustomFields();
|
||||
// 把自定义字段存入新表
|
||||
List<CustomFieldResource> customFieldResource = customFieldService.getJiraCustomFieldResource(customFields, project.getId());
|
||||
List<CustomFieldResource> customFieldResource = customFieldService.getCustomFieldResource(customFields);
|
||||
customFieldIssuesService.addFields(item.getId(), customFieldResource);
|
||||
issuesMapper.updateByPrimaryKeySelective(item);
|
||||
} catch (HttpClientErrorException e) {
|
||||
|
|
|
@ -7,6 +7,7 @@ import io.metersphere.commons.constants.IssuesManagePlatform;
|
|||
import io.metersphere.commons.user.SessionUser;
|
||||
import io.metersphere.commons.utils.BeanUtils;
|
||||
import io.metersphere.commons.utils.SessionUtils;
|
||||
import io.metersphere.dto.CustomFieldItemDTO;
|
||||
import io.metersphere.track.dto.DemandDTO;
|
||||
import io.metersphere.track.request.testcase.IssuesRequest;
|
||||
import io.metersphere.track.request.testcase.IssuesUpdateRequest;
|
||||
|
@ -43,7 +44,9 @@ public class LocalPlatform extends LocalAbstractPlatform {
|
|||
public IssuesWithBLOBs addIssue(IssuesUpdateRequest issuesRequest) {
|
||||
String issueStatus = "new";
|
||||
if (StringUtils.isNotBlank(issuesRequest.getCustomFields())) {
|
||||
List<TestCaseBatchRequest.CustomFiledRequest> fields = JSONObject.parseArray(issuesRequest.getCustomFields(), TestCaseBatchRequest.CustomFiledRequest.class);
|
||||
List<CustomFieldItemDTO> customFields = issuesRequest.getRequestFields();
|
||||
String customFieldStr = JSONObject.toJSONString(customFields);
|
||||
List<TestCaseBatchRequest.CustomFiledRequest> fields = JSONObject.parseArray(customFieldStr, TestCaseBatchRequest.CustomFiledRequest.class);
|
||||
for (TestCaseBatchRequest.CustomFiledRequest field : fields) {
|
||||
if (StringUtils.equals("状态", field.getName())) {
|
||||
issueStatus = (String) field.getValue();
|
||||
|
|
|
@ -3,6 +3,7 @@ package io.metersphere.track.request.testcase;
|
|||
import io.metersphere.base.domain.FileMetadata;
|
||||
import io.metersphere.base.domain.IssuesWithBLOBs;
|
||||
import io.metersphere.base.domain.ext.CustomFieldResource;
|
||||
import io.metersphere.dto.CustomFieldItemDTO;
|
||||
import io.metersphere.track.dto.PlatformStatusDTO;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
@ -18,6 +19,7 @@ public class IssuesUpdateRequest extends IssuesWithBLOBs {
|
|||
private List<String> tapdUsers;
|
||||
private List<CustomFieldResource> addFields;
|
||||
private List<CustomFieldResource> editFields;
|
||||
private List<CustomFieldItemDTO> requestFields;
|
||||
/**
|
||||
* zentao bug 处理人
|
||||
*/
|
||||
|
|
|
@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSONObject;
|
|||
import com.github.pagehelper.Page;
|
||||
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.ext.ExtIssuesMapper;
|
||||
import io.metersphere.commons.constants.AttachmentType;
|
||||
|
@ -116,7 +117,9 @@ public class IssuesService {
|
|||
});
|
||||
}
|
||||
saveFollows(issuesRequest.getId(), issuesRequest.getFollows());
|
||||
customFieldIssuesService.addFields(issuesRequest.getId(), issuesRequest.getAddFields());
|
||||
List<CustomFieldResource> addFields = issuesRequest.getAddFields();
|
||||
addFields.addAll(issuesRequest.getEditFields());
|
||||
customFieldIssuesService.addFields(issuesRequest.getId(), addFields);
|
||||
return issues;
|
||||
}
|
||||
|
||||
|
|
|
@ -105,6 +105,7 @@ export function buildCustomFields(data, param, template) {
|
|||
|
||||
let addFields = [];
|
||||
let editFields = [];
|
||||
let requestFields = [];
|
||||
|
||||
template.customFields.forEach(item => {
|
||||
let customField = {fieldId: item.id};
|
||||
|
@ -118,9 +119,20 @@ export function buildCustomFields(data, param, template) {
|
|||
} else {
|
||||
addFields.push(customField);
|
||||
}
|
||||
let fieldValue = (item.defaultValue instanceof Array && item.type !== 'multipleInput') ?
|
||||
JSON.stringify(item.defaultValue) : (item.defaultValue || "");
|
||||
let requestField = {
|
||||
id: item.id,
|
||||
name: item.name,
|
||||
customData: item.customData,
|
||||
type: item.type,
|
||||
value: fieldValue
|
||||
}
|
||||
requestFields.push(requestField);
|
||||
});
|
||||
param.addFields = addFields;
|
||||
param.editFields = editFields;
|
||||
param.requestFields = requestFields;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue