优化任务账号名称展示

This commit is contained in:
yml2213
2026-05-26 13:14:31 +08:00
parent 569d6a6e3d
commit 677d7fab46
5 changed files with 101 additions and 10 deletions
@@ -9,6 +9,11 @@ import type { AdminViewerSessionInput } from '../../types/admin/read-inputs.js'
import type { OrderItemRow, TaskRow } from '../../types/repository/rows.js'
type JsonRecord = Record<string, any>
type CloudSourceLabelMap = Map<string, string> | Record<string, string>
type KuaishouCloudFulfillmentMapOptions = {
cloudSourceLabelMap?: CloudSourceLabelMap
}
type TaskLike = Partial<TaskRow> & {
state_json?: string | JsonRecord
@@ -55,7 +60,10 @@ export function mapManualDispatchContext(
}
}
export function mapKuaishouCloudFulfillmentContext(value: unknown): JsonRecord | null {
export function mapKuaishouCloudFulfillmentContext(
value: unknown,
options: KuaishouCloudFulfillmentMapOptions = {},
): JsonRecord | null {
if (!value || typeof value !== 'object') {
return null
}
@@ -68,6 +76,10 @@ export function mapKuaishouCloudFulfillmentContext(value: unknown): JsonRecord |
const dispatch = record.dispatch && typeof record.dispatch === 'object' ? record.dispatch : {}
const returnNumber = record.returnNumber && typeof record.returnNumber === 'object' ? record.returnNumber : {}
const consume = record.consume && typeof record.consume === 'object' ? record.consume : {}
const cloudSourceKeys = Array.isArray(binding.cloudSourceKeys)
? binding.cloudSourceKeys.map((value: unknown) => String(value || '').trim()).filter(Boolean)
: []
const resolvedSourceKey = String(binding.resolvedSourceKey || '').trim()
return {
flowType: String(record.flowType || '').trim(),
@@ -84,10 +96,14 @@ export function mapKuaishouCloudFulfillmentContext(value: unknown): JsonRecord |
},
binding: {
prepareStatus: String(binding.prepareStatus || 'pending').trim() || 'pending',
cloudSourceKeys: Array.isArray(binding.cloudSourceKeys)
? binding.cloudSourceKeys.map((value: unknown) => String(value || '').trim()).filter(Boolean)
: [],
resolvedSourceKey: String(binding.resolvedSourceKey || '').trim(),
cloudSourceKeys,
cloudSourceLabels: cloudSourceKeys.map((sourceKey: string) =>
resolveCloudSourceLabel(sourceKey, options.cloudSourceLabelMap),
),
resolvedSourceKey,
resolvedSourceLabel: resolvedSourceKey
? resolveCloudSourceLabel(resolvedSourceKey, options.cloudSourceLabelMap)
: '',
skuId: Number(binding.skuId || 0) || 0,
skuName: String(binding.skuName || '').trim(),
vnKey: String(binding.vnKey || '').trim(),
@@ -140,6 +156,17 @@ export function mapKuaishouCloudFulfillmentContext(value: unknown): JsonRecord |
}
}
function resolveCloudSourceLabel(sourceKey: string, labelMap: CloudSourceLabelMap | undefined) {
const key = String(sourceKey || '').trim()
if (!key) return ''
const label = labelMap instanceof Map
? labelMap.get(key)
: labelMap?.[key]
return String(label || key).trim() || key
}
export function mapRedeemResolutionContext(value: unknown): JsonRecord | null {
if (!value || typeof value !== 'object') {
return null