zhou zhou
6 天以前 34d36a15f339d331d668d4063cfdff50cffa5800
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
const STATUS_META = {
  0: { text: '待执行', type: 'info' },
  1: { text: '处理中', type: 'warning' },
  2: { text: '已完成', type: 'success' },
  3: { text: '失败', type: 'danger' }
}
 
const RESOURCE_LABEL_MAP = {
  loc: '库位',
  warehouseAreasItem: '收货库存'
}
 
function normalizeText(value) {
  return String(value ?? '').trim()
}
 
function normalizeNumber(value) {
  if (value === '' || value === null || value === undefined) {
    return undefined
  }
  const numericValue = Number(value)
  return Number.isFinite(numericValue) ? numericValue : undefined
}
 
function normalizeDateTime(value) {
  return normalizeText(value) || '--'
}
 
export function createExportTaskSearchState() {
  return {
    condition: '',
    resourceKey: '',
    status: '',
    timeStart: '',
    timeEnd: '',
    orderBy: 'createTime desc'
  }
}
 
export function getExportTaskPaginationKey() {
  return {
    current: 'current',
    size: 'pageSize'
  }
}
 
export function getExportTaskStatusOptions() {
  return Object.entries(STATUS_META).map(([value, meta]) => ({
    label: meta.text,
    value: Number(value)
  }))
}
 
export function getExportTaskResourceOptions() {
  return Object.entries(RESOURCE_LABEL_MAP).map(([value, label]) => ({
    label,
    value
  }))
}
 
export function buildExportTaskSearchParams(params = {}) {
  return {
    ...(normalizeText(params.condition) ? { condition: normalizeText(params.condition) } : {}),
    ...(normalizeText(params.resourceKey)
      ? { resourceKey: normalizeText(params.resourceKey) }
      : {}),
    ...(normalizeNumber(params.status) !== undefined
      ? { status: normalizeNumber(params.status) }
      : {}),
    ...(params.timeStart ? { timeStart: params.timeStart } : {}),
    ...(params.timeEnd ? { timeEnd: params.timeEnd } : {}),
    orderBy: 'createTime desc'
  }
}
 
export function buildExportTaskPageQueryParams(params = {}) {
  return {
    current: params.current || 1,
    pageSize: params.pageSize || params.size || 20,
    ...buildExportTaskSearchParams(params)
  }
}
 
export function resolveExportTaskResourceLabel(resourceKey) {
  return RESOURCE_LABEL_MAP[normalizeText(resourceKey)] || normalizeText(resourceKey) || '--'
}
 
export function normalizeExportTaskRow(record = {}) {
  const statusValue = Number(record.status)
  const statusMeta = STATUS_META[statusValue] || STATUS_META[0]
 
  return {
    ...record,
    id: record.id ?? '--',
    taskCode: normalizeText(record.taskCode) || '--',
    resourceKey: normalizeText(record.resourceKey),
    resourceKeyText: resolveExportTaskResourceLabel(record.resourceKey),
    reportTitle: normalizeText(record.reportTitle) || '--',
    fileName: normalizeText(record.fileName) || '--',
    rowCount: record.rowCount ?? '--',
    statusText: record['status$'] || statusMeta.text,
    statusType: statusMeta.type,
    errorMsg: normalizeText(record.errorMsg) || '--',
    createTimeText: normalizeDateTime(record['createTime$'] || record.createTime),
    updateTimeText: normalizeDateTime(record['updateTime$'] || record.updateTime),
    expireTimeText: normalizeDateTime(record['expireTime$'] || record.expireTime),
    canDownload: statusValue === 2
  }
}