fix: 勾选第三方模板报告人选不上

--bug=1009269 --user=陈建星 [ github#8862]对接jira填完了但是报“报告人不能为空” https://www.tapd.cn/55049933/s/1091095003
This commit is contained in:
chenjianxing 2022-01-20 21:29:19 +08:00 committed by zhangdahai112
parent ec9db0aed0
commit 622067d8d8
2 changed files with 32 additions and 27 deletions

View File

@ -177,37 +177,42 @@ public class JiraPlatform extends AbstractIssuePlatform {
private void setSpecialParam(JSONObject fields) {
String projectKey = getProjectId(this.projectId);
JiraConfig config = getConfig();
Map<String, JiraCreateMetadataResponse.Field> createMetadata = new HashMap<>();
try {
createMetadata = jiraClientV2.getCreateMetadata(projectKey, config.getIssuetype());
} catch (Exception e) {}
Map<String, JiraCreateMetadataResponse.Field> createMetadata = jiraClientV2.getCreateMetadata(projectKey, config.getIssuetype());
List<JiraUser> userOptions = jiraClientV2.getAssignableUser(projectKey);
Boolean isUserKey = false;
if (CollectionUtils.isNotEmpty(userOptions) && StringUtils.isBlank(userOptions.get(0).getAccountId())) {
isUserKey = true;
}
for (String name : createMetadata.keySet()) {
JiraCreateMetadataResponse.Field item = createMetadata.get(name);
JiraCreateMetadataResponse.Schema schema = item.getSchema();
String key = item.getKey();
if (StringUtils.isBlank(key)) {
if (StringUtils.isBlank(key) || schema == null) {
continue;
}
if (schema != null && schema.getCustom() != null && schema.getCustom().endsWith("sprint")) {
if (schema.getCustom() != null && schema.getCustom().endsWith("sprint")) {
try {
JSONObject field = fields.getJSONObject(key);
// sprint 传参数比较特殊需要要传数值
fields.put(key, field.getInteger("id"));
} catch (Exception e) {}
}
if (key.equals("reporter")) {
if (schema.getType() != null && schema.getType().endsWith("user")) {
JSONObject field = fields.getJSONObject(key);
try {
UUID.fromString(field.getString("id"));
} catch (Exception e) {
// 如果不是uuid则是用户的key参数调整为key
if (isUserKey) {
LogUtil.info("jira user field: " + field.toString());
// 如果不是用户ID则是用户的name参数调整为name
JSONObject newField = new JSONObject();
newField.put("key", field.getString("id"));
newField.put("name", field.getString("id"));
fields.put(key, newField);
}
}
}
} catch (Exception e) {
LogUtil.error(e);
}
}
@ -574,7 +579,7 @@ public class JiraPlatform extends AbstractIssuePlatform {
if (StringUtils.isNotBlank(val.getAccountId())) {
jsonObject.put("value", val.getAccountId());
} else {
jsonObject.put("value", val.getKey());
jsonObject.put("value", val.getName());
}
jsonObject.put("text", val.getDisplayName());
options.add(jsonObject);

View File

@ -7,7 +7,7 @@ import lombok.Setter;
@Getter
public class JiraUser {
private String accountId;
private String key;
private String name;
private String displayName;
private String emailAddress;
private Boolean active;