245 lines
6.6 KiB
Java
245 lines
6.6 KiB
Java
package com.zeodao.reminder.model;
|
||
|
||
import com.fasterxml.jackson.databind.JsonNode;
|
||
import lombok.Data;
|
||
|
||
/**
|
||
* 禅道BUG实体类 - 使用JsonNode实现动态字段解析
|
||
*
|
||
* @author Zeodao
|
||
* @version 1.0.0
|
||
*/
|
||
@Data
|
||
public class ZentaoBug {
|
||
|
||
private String id;
|
||
|
||
private String title;
|
||
|
||
private String type;
|
||
|
||
private String status;
|
||
|
||
private String severity;
|
||
|
||
private String pri;
|
||
|
||
private String assignedTo;
|
||
|
||
private String assignedToRealName;
|
||
|
||
private String assignedDate;
|
||
|
||
private String deadline;
|
||
|
||
private String openedBy;
|
||
|
||
private String openedDate;
|
||
|
||
private String resolvedBy;
|
||
|
||
private String resolvedDate;
|
||
|
||
private String closedBy;
|
||
|
||
private String closedDate;
|
||
|
||
private String lastEditedBy;
|
||
|
||
private String lastEditedDate;
|
||
|
||
private String product;
|
||
|
||
private String project;
|
||
|
||
private String execution;
|
||
|
||
private String module;
|
||
|
||
private String keywords;
|
||
|
||
private String os;
|
||
|
||
private String browser;
|
||
|
||
private String steps;
|
||
|
||
private String confirmed;
|
||
|
||
private String activatedCount;
|
||
|
||
private String activatedDate;
|
||
|
||
private String deleted;
|
||
|
||
/**
|
||
* 从JsonNode创建ZentaoBug对象,安全地提取字段
|
||
*/
|
||
public static ZentaoBug fromJsonNode(JsonNode node) {
|
||
ZentaoBug bug = new ZentaoBug();
|
||
|
||
// 安全地提取字段,如果字段不存在或类型不匹配,使用默认值
|
||
bug.setId(getStringValue(node, "id"));
|
||
bug.setTitle(getStringValue(node, "title"));
|
||
bug.setType(getStringValue(node, "type"));
|
||
bug.setStatus(getStringValue(node, "status"));
|
||
bug.setSeverity(getStringValue(node, "severity"));
|
||
bug.setPri(getStringValue(node, "pri"));
|
||
bug.setAssignedTo(getStringValue(node, "assignedTo"));
|
||
bug.setAssignedToRealName(getStringValue(node, "assignedToRealName"));
|
||
bug.setAssignedDate(getStringValue(node, "assignedDate"));
|
||
bug.setDeadline(getStringValue(node, "deadline"));
|
||
bug.setOpenedBy(getStringValue(node, "openedBy"));
|
||
bug.setOpenedDate(getStringValue(node, "openedDate"));
|
||
bug.setResolvedBy(getStringValue(node, "resolvedBy"));
|
||
bug.setResolvedDate(getStringValue(node, "resolvedDate"));
|
||
bug.setClosedBy(getStringValue(node, "closedBy"));
|
||
bug.setClosedDate(getStringValue(node, "closedDate"));
|
||
bug.setLastEditedBy(getStringValue(node, "lastEditedBy"));
|
||
bug.setLastEditedDate(getStringValue(node, "lastEditedDate"));
|
||
bug.setProduct(getStringValue(node, "product"));
|
||
bug.setProject(getStringValue(node, "project"));
|
||
bug.setExecution(getStringValue(node, "execution"));
|
||
bug.setModule(getStringValue(node, "module"));
|
||
bug.setKeywords(getStringValue(node, "keywords"));
|
||
bug.setOs(getStringValue(node, "os"));
|
||
bug.setBrowser(getStringValue(node, "browser"));
|
||
bug.setSteps(getStringValue(node, "steps"));
|
||
bug.setConfirmed(getStringValue(node, "confirmed"));
|
||
bug.setActivatedCount(getStringValue(node, "activatedCount"));
|
||
bug.setActivatedDate(getStringValue(node, "activatedDate"));
|
||
bug.setDeleted(getStringValue(node, "deleted"));
|
||
|
||
return bug;
|
||
}
|
||
|
||
/**
|
||
* 安全地从JsonNode获取字符串值
|
||
*/
|
||
private static String getStringValue(JsonNode node, String fieldName) {
|
||
if (node == null || !node.has(fieldName)) {
|
||
return null;
|
||
}
|
||
|
||
JsonNode fieldNode = node.get(fieldName);
|
||
if (fieldNode.isNull()) {
|
||
return null;
|
||
}
|
||
|
||
// 处理嵌套对象(如status可能是对象)
|
||
if (fieldNode.isObject()) {
|
||
if (fieldNode.has("code")) {
|
||
return fieldNode.get("code").asText();
|
||
}
|
||
if (fieldNode.has("account")) {
|
||
return fieldNode.get("account").asText();
|
||
}
|
||
if (fieldNode.has("realname")) {
|
||
return fieldNode.get("realname").asText();
|
||
}
|
||
return fieldNode.toString();
|
||
}
|
||
|
||
// 对于基本类型,直接转换为字符串
|
||
return fieldNode.asText();
|
||
}
|
||
|
||
/**
|
||
* 判断BUG是否未解决
|
||
*/
|
||
public boolean isUnresolved() {
|
||
return !"resolved".equals(status) && !"closed".equals(status);
|
||
}
|
||
|
||
/**
|
||
* 判断BUG是否已过期
|
||
*/
|
||
public boolean isOverdue() {
|
||
if (deadline == null || deadline.isEmpty() || "0000-00-00".equals(deadline)) {
|
||
return false;
|
||
}
|
||
// 简单的日期比较,实际项目中应该使用更严格的日期处理
|
||
return deadline.compareTo(java.time.LocalDate.now().toString()) < 0;
|
||
}
|
||
|
||
/**
|
||
* 获取严重程度描述
|
||
*/
|
||
public String getSeverityDesc() {
|
||
switch (severity) {
|
||
case "1":
|
||
return "致命";
|
||
case "2":
|
||
return "严重";
|
||
case "3":
|
||
return "一般";
|
||
case "4":
|
||
return "轻微";
|
||
default:
|
||
return "未知";
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 获取优先级描述
|
||
*/
|
||
public String getPriorityDesc() {
|
||
switch (pri) {
|
||
case "1":
|
||
return "高";
|
||
case "2":
|
||
return "中";
|
||
case "3":
|
||
return "低";
|
||
case "4":
|
||
return "最低";
|
||
default:
|
||
return "普通";
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 获取BUG类型描述
|
||
*/
|
||
public String getTypeDesc() {
|
||
switch (type) {
|
||
case "codeerror":
|
||
return "代码错误";
|
||
case "config":
|
||
return "配置相关";
|
||
case "install":
|
||
return "安装部署";
|
||
case "security":
|
||
return "安全相关";
|
||
case "performance":
|
||
return "性能问题";
|
||
case "standard":
|
||
return "标准规范";
|
||
case "automation":
|
||
return "测试脚本";
|
||
case "designdefect":
|
||
return "设计缺陷";
|
||
case "others":
|
||
return "其他";
|
||
default:
|
||
return type != null ? type : "未知";
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 获取状态描述
|
||
*/
|
||
public String getStatusDesc() {
|
||
switch (status) {
|
||
case "active":
|
||
return "激活";
|
||
case "resolved":
|
||
return "已解决";
|
||
case "closed":
|
||
return "已关闭";
|
||
default:
|
||
return status != null ? status : "未知";
|
||
}
|
||
}
|
||
}
|