feat: 展示任务PDD店铺和客户端名称 (#158)
This commit is contained in:
+39
-5
@@ -130,12 +130,38 @@ func isTaskWarn(s model.TaskStatus) bool {
|
||||
// `[必须]` 无主任务显示 `—`,不是空白也不是 `<nil>`——#17 之后
|
||||
// 采集任务默认无主,这一列会大量为空,显示不出来会让人以为页面坏了。
|
||||
func clientText(assignedClient string) string {
|
||||
if assignedClient == "" {
|
||||
if strings.TrimSpace(assignedClient) == "" {
|
||||
return placeholder
|
||||
}
|
||||
return assignedClient
|
||||
}
|
||||
|
||||
// clientDisplayName 优先使用操作员看得懂的客户端名称。
|
||||
// 名称为空或客户端记录已删除时回退稳定 ID,不能把已分配任务显示成空白。
|
||||
func clientDisplayName(clientID, clientName string) string {
|
||||
if name := strings.TrimSpace(clientName); name != "" {
|
||||
return name
|
||||
}
|
||||
return clientText(clientID)
|
||||
}
|
||||
|
||||
// clientDisplayTitle 给列表截断单元格提供完整名称和稳定 ID。
|
||||
func clientDisplayTitle(clientID, clientName string) string {
|
||||
name := strings.TrimSpace(clientName)
|
||||
id := strings.TrimSpace(clientID)
|
||||
if name != "" && id != "" {
|
||||
return name + "(" + id + ")"
|
||||
}
|
||||
return clientDisplayName(id, name)
|
||||
}
|
||||
|
||||
func optionalDisplayText(value string) string {
|
||||
if value = strings.TrimSpace(value); value != "" {
|
||||
return value
|
||||
}
|
||||
return placeholder
|
||||
}
|
||||
|
||||
// ---------- 目标列 ----------
|
||||
|
||||
// buildTarget 把一行任务的业务字段拼成「目标」列要显示的一句话。
|
||||
@@ -236,9 +262,11 @@ type TaskView struct {
|
||||
TypeText string
|
||||
ExecutionModeText string
|
||||
Target string
|
||||
PddShopText string
|
||||
StatusText string
|
||||
IsWarn bool // 失败 / 需人工,标黄提醒
|
||||
ClientText string
|
||||
ClientTitle string
|
||||
CreatorText string
|
||||
UpdatedAt string
|
||||
}
|
||||
@@ -321,9 +349,11 @@ func ListTasksView(db *sql.DB, filter repository.TaskFilter, requestedPage int)
|
||||
TypeText: taskTypeText(r.TaskType),
|
||||
ExecutionModeText: taskExecutionModeText(r.TaskType, r.ExecutionMode),
|
||||
Target: buildTarget(r),
|
||||
PddShopText: optionalDisplayText(r.PddShopName),
|
||||
StatusText: taskStatusText(r.Status),
|
||||
IsWarn: isTaskWarn(r.Status),
|
||||
ClientText: clientText(r.AssignedClient),
|
||||
ClientText: clientDisplayName(r.AssignedClient, r.ClientName),
|
||||
ClientTitle: clientDisplayTitle(r.AssignedClient, r.ClientName),
|
||||
CreatorText: taskCreatorText(r.CreatedByUsername),
|
||||
UpdatedAt: formatLocalTime(r.UpdatedAt),
|
||||
})
|
||||
@@ -421,11 +451,13 @@ type TaskDetailView struct {
|
||||
ExecutionModeText string
|
||||
StatusText string
|
||||
ClientText string
|
||||
ClientIDText string
|
||||
CreatorText string
|
||||
ClaimedAt string
|
||||
FinishedAt string
|
||||
|
||||
PddGoodsURL string
|
||||
PddShopText string
|
||||
|
||||
// IsPurchase 为 false 时,模板要把下面四个采购专有字段整段隐藏,
|
||||
// 不能显示空行——见 #19。
|
||||
@@ -458,7 +490,7 @@ func GetTaskDetail(db *sql.DB, taskID string) (*TaskDetailView, error) {
|
||||
if err != nil || t == nil {
|
||||
return nil, err
|
||||
}
|
||||
creatorUsername, err := repository.GetTaskCreatorUsername(db, taskID)
|
||||
displayContext, err := repository.GetTaskDisplayContext(db, taskID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -468,11 +500,13 @@ func GetTaskDetail(db *sql.DB, taskID string) (*TaskDetailView, error) {
|
||||
TypeText: taskTypeText(t.TaskType),
|
||||
ExecutionModeText: taskExecutionModeText(t.TaskType, t.ExecutionMode),
|
||||
StatusText: taskStatusText(t.Status),
|
||||
ClientText: clientText(t.AssignedClient),
|
||||
CreatorText: taskCreatorText(creatorUsername),
|
||||
ClientText: clientDisplayName(t.AssignedClient, displayContext.ClientName),
|
||||
ClientIDText: clientText(t.AssignedClient),
|
||||
CreatorText: taskCreatorText(displayContext.CreatorUsername),
|
||||
ClaimedAt: formatLocalTime(t.ClaimedAt),
|
||||
FinishedAt: formatLocalTime(t.FinishedAt),
|
||||
PddGoodsURL: t.PddGoodsURL,
|
||||
PddShopText: optionalDisplayText(displayContext.PddShopName),
|
||||
IsPurchase: t.TaskType == model.TaskPurchase,
|
||||
}
|
||||
if v.IsPurchase {
|
||||
|
||||
Reference in New Issue
Block a user