zhou zhou
1 天以前 c579731e0c206d6062f8442ec9df70ca781b26f6
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
const STATUS_META = {
  1: { text: '启用', type: 'success', bool: true },
  0: { text: '禁用', type: 'danger', bool: false }
}
 
const CURRENT_META = {
  1: { text: '当前版本', type: 'success', bool: true },
  0: { text: '历史版本', type: 'info', bool: false }
}
 
export const TASK_PATH_TEMPLATE_REPORT_TITLE = '任务路径模板报表'
export const TASK_PATH_TEMPLATE_REPORT_STYLE = {
  titleAlign: 'center',
  titleLevel: 'strong',
  orientation: 'portrait',
  density: 'compact',
  showSequence: true
}
 
function normalizeText(value) {
  return String(value ?? '').trim()
}
 
function normalizeNumber(value, fallback = void 0) {
  if (value === '' || value === null || value === undefined) {
    return fallback
  }
  const numberValue = Number(value)
  return Number.isNaN(numberValue) ? fallback : numberValue
}
 
export function createTaskPathTemplateSearchState() {
  return {
    condition: '',
    templateCode: '',
    templateName: '',
    sourceType: '',
    targetType: '',
    conditionExpression: '',
    conditionDesc: '',
    version: '',
    isCurrent: '',
    effectiveTime: '',
    expireTime: '',
    priority: '',
    timeoutMinutes: '',
    stepSize: '',
    maxRetryTimes: '',
    retryIntervalSeconds: '',
    status: '',
    remark: '',
    timeStart: '',
    timeEnd: ''
  }
}
 
export function createTaskPathTemplateFormState() {
  return {
    id: void 0,
    templateCode: '',
    templateName: '',
    sourceType: '',
    targetType: '',
    conditionExpression: '',
    conditionDesc: '',
    version: 1,
    isCurrent: 1,
    effectiveTime: '',
    expireTime: '',
    priority: 1,
    timeoutMinutes: '',
    stepSize: '',
    maxRetryTimes: 3,
    retryIntervalSeconds: 60,
    status: 1,
    remark: ''
  }
}
 
export function getTaskPathTemplateStatusOptions() {
  return [
    { label: '启用', value: 1 },
    { label: '禁用', value: 0 }
  ]
}
 
export function getTaskPathTemplateCurrentOptions() {
  return [
    { label: '当前版本', value: 1 },
    { label: '历史版本', value: 0 }
  ]
}
 
export function getTaskPathTemplatePaginationKey() {
  return {
    current: 'current',
    size: 'pageSize'
  }
}
 
export function getTaskPathTemplateStatusMeta(status) {
  if (status === true || Number(status) === 1) {
    return STATUS_META[1]
  }
  if (status === false || Number(status) === 0) {
    return STATUS_META[0]
  }
  return { text: '未知', type: 'info', bool: false }
}
 
export function getTaskPathTemplateCurrentMeta(isCurrent) {
  if (isCurrent === true || Number(isCurrent) === 1) {
    return CURRENT_META[1]
  }
  if (isCurrent === false || Number(isCurrent) === 0) {
    return CURRENT_META[0]
  }
  return { text: '未知', type: 'info', bool: false }
}
 
export function buildTaskPathTemplateSearchParams(params = {}) {
  const searchParams = {
    condition: normalizeText(params.condition),
    templateCode: normalizeText(params.templateCode),
    templateName: normalizeText(params.templateName),
    sourceType: normalizeText(params.sourceType),
    targetType: normalizeText(params.targetType),
    conditionExpression: normalizeText(params.conditionExpression),
    conditionDesc: normalizeText(params.conditionDesc),
    version: normalizeNumber(params.version),
    isCurrent: normalizeNumber(params.isCurrent),
    effectiveTime: normalizeText(params.effectiveTime),
    expireTime: normalizeText(params.expireTime),
    priority: normalizeNumber(params.priority),
    timeoutMinutes: normalizeNumber(params.timeoutMinutes),
    stepSize: normalizeNumber(params.stepSize),
    maxRetryTimes: normalizeNumber(params.maxRetryTimes),
    retryIntervalSeconds: normalizeNumber(params.retryIntervalSeconds),
    status: normalizeNumber(params.status),
    remark: normalizeText(params.remark),
    timeStart: normalizeText(params.timeStart),
    timeEnd: normalizeText(params.timeEnd)
  }
 
  return Object.fromEntries(
    Object.entries(searchParams).filter(([, value]) => value !== '' && value !== void 0 && value !== null)
  )
}
 
export function buildTaskPathTemplatePageQueryParams(params = {}) {
  return {
    current: params.current || 1,
    pageSize: params.pageSize || params.size || 20,
    ...buildTaskPathTemplateSearchParams(params)
  }
}
 
export function buildTaskPathTemplateSavePayload(formData = {}) {
  return {
    ...(formData.id !== void 0 && formData.id !== null && formData.id !== ''
      ? { id: Number(formData.id) }
      : {}),
    templateCode: normalizeText(formData.templateCode),
    templateName: normalizeText(formData.templateName),
    sourceType: normalizeText(formData.sourceType),
    targetType: normalizeText(formData.targetType),
    conditionExpression: normalizeText(formData.conditionExpression),
    conditionDesc: normalizeText(formData.conditionDesc),
    version: normalizeNumber(formData.version, 1),
    isCurrent: normalizeNumber(formData.isCurrent, 1),
    effectiveTime: normalizeText(formData.effectiveTime),
    expireTime: normalizeText(formData.expireTime),
    priority: normalizeNumber(formData.priority, 1),
    ...(formData.timeoutMinutes !== void 0 &&
    formData.timeoutMinutes !== null &&
    formData.timeoutMinutes !== ''
      ? { timeoutMinutes: Number(formData.timeoutMinutes) }
      : {}),
    ...(formData.stepSize !== void 0 && formData.stepSize !== null && formData.stepSize !== ''
      ? { stepSize: Number(formData.stepSize) }
      : {}),
    maxRetryTimes: normalizeNumber(formData.maxRetryTimes, 3),
    retryIntervalSeconds: normalizeNumber(formData.retryIntervalSeconds, 60),
    status: normalizeNumber(formData.status, 1),
    remark: normalizeText(formData.remark)
  }
}
 
export function buildTaskPathTemplateDialogModel(record = {}) {
  return {
    ...createTaskPathTemplateFormState(),
    ...(record.id !== void 0 && record.id !== null && record.id !== ''
      ? { id: Number(record.id) }
      : {}),
    templateCode: normalizeText(record.templateCode || ''),
    templateName: normalizeText(record.templateName || ''),
    sourceType: normalizeText(record.sourceType || ''),
    targetType: normalizeText(record.targetType || ''),
    conditionExpression: normalizeText(record.conditionExpression || ''),
    conditionDesc: normalizeText(record.conditionDesc || ''),
    version: normalizeNumber(record.version, 1),
    isCurrent: normalizeNumber(record.isCurrent, 1),
    effectiveTime: normalizeText(record.effectiveTime$ || record.effectiveTime || ''),
    expireTime: normalizeText(record.expireTime$ || record.expireTime || ''),
    priority: normalizeNumber(record.priority, 1),
    timeoutMinutes: normalizeNumber(record.timeoutMinutes, ''),
    stepSize: normalizeNumber(record.stepSize, ''),
    maxRetryTimes: normalizeNumber(record.maxRetryTimes, 3),
    retryIntervalSeconds: normalizeNumber(record.retryIntervalSeconds, 60),
    status: normalizeNumber(record.status, 1),
    remark: normalizeText(record.remark || '')
  }
}
 
export function normalizeTaskPathTemplateDetailRecord(record = {}) {
  const statusMeta = getTaskPathTemplateStatusMeta(record.statusBool ?? record.status)
  const currentMeta = getTaskPathTemplateCurrentMeta(record.isCurrent)
  return {
    ...record,
    templateCode: normalizeText(record.templateCode || ''),
    templateName: normalizeText(record.templateName || ''),
    sourceType: normalizeText(record.sourceType || ''),
    targetType: normalizeText(record.targetType || ''),
    conditionExpression: normalizeText(record.conditionExpression || ''),
    conditionDesc: normalizeText(record.conditionDesc || ''),
    remark: normalizeText(record.remark || ''),
    statusText: statusMeta.text,
    statusType: statusMeta.type,
    statusBool: record.statusBool !== void 0 ? Boolean(record.statusBool) : statusMeta.bool,
    isCurrentText: currentMeta.text,
    isCurrentType: currentMeta.type,
    isCurrentBool: record.isCurrent !== void 0 ? Boolean(record.isCurrent) : currentMeta.bool,
    createByText: normalizeText(record.createBy$ || record.createByText || ''),
    updateByText: normalizeText(record.updateBy$ || record.updateByText || ''),
    createTimeText: normalizeText(record.createTime$ || record.createTime || ''),
    updateTimeText: normalizeText(record.updateTime$ || record.updateTime || ''),
    effectiveTimeText: normalizeText(record.effectiveTime$ || record.effectiveTime || ''),
    expireTimeText: normalizeText(record.expireTime$ || record.expireTime || '')
  }
}
 
export function normalizeTaskPathTemplateListRow(record = {}) {
  return normalizeTaskPathTemplateDetailRecord(record)
}
 
export function buildTaskPathTemplatePrintRows(records = []) {
  if (!Array.isArray(records)) {
    return []
  }
  return records.map((record) => normalizeTaskPathTemplateListRow(record))
}
 
export function buildTaskPathTemplateReportMeta({
  previewMeta = {},
  count = 0,
  orientation = TASK_PATH_TEMPLATE_REPORT_STYLE.orientation
} = {}) {
  return {
    reportTitle: TASK_PATH_TEMPLATE_REPORT_TITLE,
    reportDate: previewMeta.reportDate,
    printedAt: previewMeta.printedAt,
    operator: previewMeta.operator,
    count,
    reportStyle: {
      ...TASK_PATH_TEMPLATE_REPORT_STYLE,
      orientation
    }
  }
}
 
export function buildTaskPathTemplateFlowSnapshot(record = {}) {
  const sourceType = normalizeText(record.sourceType || '')
  const targetType = normalizeText(record.targetType || '')
  const stepSize = normalizeText(record.stepSize || '')
  const templateCode = normalizeText(record.templateCode || '')
  return [
    { key: 'source', title: '起点类型', value: sourceType || '--' },
    { key: 'step', title: '步序长度', value: stepSize || '--' },
    { key: 'target', title: '终点类型', value: targetType || '--' },
    { key: 'code', title: '模板编码', value: templateCode || '--' }
  ]
}