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

View File

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