zhou zhou
2 天以前 5d31cb5f1fb32a478d5b751ebfe97d47db890778
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
const TASK_TYPE_META = {
  1: { text: '入库', type: 'success' }
}
 
const TASK_STATUS_META = {
  98: { text: '入库完成', type: 'success' },
  99: { text: '上报完成', type: 'warning' },
  100: { text: '库存更新完成', type: 'success' },
  101: { text: '创建出库任务', type: 'info' }
}
 
export const IN_STATISTIC_PAGE_TITLE = '入库统计'
 
function normalizeText(value) {
  return String(value ?? '').trim()
}
 
function normalizeNumber(value, fallback = void 0) {
  if (value === '' || value === null || value === undefined) {
    return fallback
  }
  const numericValue = Number(value)
  return Number.isFinite(numericValue) ? numericValue : fallback
}
 
export function createInStatisticSearchState() {
  return {
    condition: '',
    dayTime: '',
    maktx: '',
    matnrCode: '',
    batch: ''
  }
}
 
export function getInStatisticPaginationKey() {
  return {
    current: 'current',
    size: 'pageSize'
  }
}
 
export function buildInStatisticSearchParams(params = {}) {
  const searchParams = {
    condition: normalizeText(params.condition),
    dayTime: normalizeText(params.dayTime),
    maktx: normalizeText(params.maktx),
    matnrCode: normalizeText(params.matnrCode),
    batch: normalizeText(params.batch),
    taskType: normalizeNumber(params.taskType, 1),
    taskStatus: normalizeNumber(params.taskStatus, 100)
  }
 
  return Object.fromEntries(
    Object.entries(searchParams).filter(([, value]) => value !== '' && value !== void 0 && value !== null)
  )
}
 
export function buildInStatisticPageQueryParams(params = {}) {
  return {
    current: params.current || 1,
    pageSize: params.pageSize || params.size || 20,
    ...buildInStatisticSearchParams(params)
  }
}
 
export function getInStatisticTaskTypeMeta(taskType) {
  if (taskType === null || taskType === undefined || taskType === '') {
    return { text: '入库', type: 'success' }
  }
  return TASK_TYPE_META[Number(taskType)] || { text: String(taskType), type: 'info' }
}
 
export function getInStatisticTaskStatusMeta(taskStatus) {
  if (taskStatus === null || taskStatus === undefined || taskStatus === '') {
    return { text: '-', type: 'info' }
  }
  return TASK_STATUS_META[Number(taskStatus)] || { text: String(taskStatus), type: 'info' }
}
 
export function normalizeInStatisticRow(record = {}) {
  const taskTypeMeta = getInStatisticTaskTypeMeta(record.taskType ?? record.task_type)
  const taskStatusMeta = getInStatisticTaskStatusMeta(record.taskStatus ?? record.task_status)
 
  return {
    ...record,
    id: record.id ?? '--',
    dayTimeText: normalizeText(record.dayTime || record.day_time || ''),
    taskTypeText: normalizeText(record.taskTypeText || record['taskType$'] || taskTypeMeta.text),
    taskTypeTagType: normalizeText(record.taskTypeTagType || taskTypeMeta.type) || 'info',
    taskStatusText: normalizeText(record.taskStatusText || record['taskStatus$'] || taskStatusMeta.text),
    taskStatusTagType: normalizeText(record.taskStatusTagType || taskStatusMeta.type) || 'info',
    locCode: normalizeText(record.locCode || record.loc_code || ''),
    barcode: normalizeText(record.barcode || ''),
    matnrCode: normalizeText(record.matnrCode || record.matnr_code || ''),
    maktx: normalizeText(record.maktx || ''),
    batch: normalizeText(record.batch || ''),
    unit: normalizeText(record.unit || ''),
    anfme: record.anfme ?? '--',
    fieldsIndex: normalizeText(record.fieldsIndex || record.fields_index || ''),
    createByText: normalizeText(record.createBy$ || record.createByText || record.createBy || ''),
    createTimeText: normalizeText(record.createTime$ || record.createTime || ''),
    updateByText: normalizeText(record.updateBy$ || record.updateByText || record.updateBy || ''),
    updateTimeText: normalizeText(record.updateTime$ || record.updateTime || ''),
    memo: normalizeText(record.memo || '')
  }
}