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_MERGE_REPORT_TITLE = '任务路径模板合并报表'
|
export const TASK_PATH_TEMPLATE_MERGE_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
|
}
|
|
function normalizeStringList(value) {
|
if (Array.isArray(value)) {
|
return value.map((item) => normalizeText(item)).filter(Boolean)
|
}
|
if (value === null || value === undefined || value === '') {
|
return []
|
}
|
if (typeof value === 'string') {
|
const text = value.trim()
|
if (!text) {
|
return []
|
}
|
if (text.startsWith('[')) {
|
try {
|
const parsed = JSON.parse(text)
|
if (Array.isArray(parsed)) {
|
return parsed.map((item) => normalizeText(item)).filter(Boolean)
|
}
|
} catch {
|
return [text]
|
}
|
}
|
return text.split(/[;,,\n\r]+/g).map((item) => item.trim()).filter(Boolean)
|
}
|
return [normalizeText(value)].filter(Boolean)
|
}
|
|
function normalizeIntegerList(value) {
|
if (Array.isArray(value)) {
|
return value
|
.map((item) => {
|
if (item === null || item === undefined || item === '') {
|
return null
|
}
|
const numberValue = Number(item)
|
return Number.isNaN(numberValue) ? null : numberValue
|
})
|
.filter((item) => item !== null)
|
}
|
if (value === null || value === undefined || value === '') {
|
return []
|
}
|
if (typeof value === 'string') {
|
const text = value.trim()
|
if (!text) {
|
return []
|
}
|
if (text.startsWith('[')) {
|
try {
|
const parsed = JSON.parse(text)
|
if (Array.isArray(parsed)) {
|
return parsed
|
.map((item) => {
|
const numberValue = Number(item)
|
return Number.isNaN(numberValue) ? null : numberValue
|
})
|
.filter((item) => item !== null)
|
}
|
} catch {
|
return text
|
.split(/[;,,\n\r]+/g)
|
.map((item) => Number(item.trim()))
|
.filter((item) => !Number.isNaN(item))
|
}
|
}
|
const numberValue = Number(text)
|
return Number.isNaN(numberValue) ? [] : [numberValue]
|
}
|
const numberValue = Number(value)
|
return Number.isNaN(numberValue) ? [] : [numberValue]
|
}
|
|
export function createTaskPathTemplateMergeSearchState() {
|
return {
|
condition: '',
|
templateCode: '',
|
templateName: '',
|
sourceType: '',
|
targetType: '',
|
conditionExpression: '',
|
conditionDesc: '',
|
version: '',
|
isCurrent: '',
|
effectiveTime: '',
|
expireTime: '',
|
priority: '',
|
timeoutMinutes: '',
|
maxRetryTimes: '',
|
retryIntervalSeconds: '',
|
stepSize: '',
|
status: '',
|
timeStart: '',
|
timeEnd: ''
|
}
|
}
|
|
export function createTaskPathTemplateMergeFormState() {
|
return {
|
id: void 0,
|
templateCode: '',
|
templateName: '',
|
sourceTypeR: [],
|
targetTypeR: [],
|
sourceType: '',
|
targetType: '',
|
conditionExpression: '',
|
conditionDesc: '',
|
version: 1,
|
isCurrent: 1,
|
effectiveTime: '',
|
expireTime: '',
|
priority: 1,
|
timeoutMinutes: '',
|
maxRetryTimes: 3,
|
retryIntervalSeconds: 60,
|
stepSize: '',
|
status: 1
|
}
|
}
|
|
export function getTaskPathTemplateMergePaginationKey() {
|
return {
|
current: 'current',
|
size: 'pageSize'
|
}
|
}
|
|
export function getTaskPathTemplateMergeStatusOptions() {
|
return [
|
{ label: '启用', value: 1 },
|
{ label: '禁用', value: 0 }
|
]
|
}
|
|
export function getTaskPathTemplateMergeCurrentOptions() {
|
return [
|
{ label: '当前版本', value: 1 },
|
{ label: '历史版本', value: 0 }
|
]
|
}
|
|
export function getTaskPathTemplateMergeStatusMeta(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 getTaskPathTemplateMergeCurrentMeta(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 buildTaskPathTemplateMergeTypeOptions(records = []) {
|
if (!Array.isArray(records)) {
|
return []
|
}
|
|
return records
|
.map((item) => {
|
if (!item || typeof item !== 'object') {
|
return null
|
}
|
const value = item.id ?? item.value
|
if (value === void 0 || value === null || value === '') {
|
return null
|
}
|
return {
|
value: String(value),
|
label: normalizeText(item.name || item.label || `类型 ${value}`)
|
}
|
})
|
.filter(Boolean)
|
}
|
|
export function buildTaskPathTemplateMergeConditionOptions(records = []) {
|
if (!Array.isArray(records)) {
|
return []
|
}
|
|
return records
|
.map((item) => {
|
if (!item || typeof item !== 'object') {
|
return null
|
}
|
const value = item.id ?? item.value
|
if (value === void 0 || value === null || value === '') {
|
return null
|
}
|
return {
|
value: Number(value),
|
label: normalizeText(item.templateName || item.templateCode || item.name || `模板 ${value}`)
|
}
|
})
|
.filter(Boolean)
|
}
|
|
export function buildTaskPathTemplateMergeSearchParams(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:
|
params.version !== undefined && params.version !== null && params.version !== ''
|
? Number(params.version)
|
: void 0,
|
isCurrent:
|
params.isCurrent !== undefined && params.isCurrent !== null && params.isCurrent !== ''
|
? Number(params.isCurrent)
|
: void 0,
|
priority:
|
params.priority !== undefined && params.priority !== null && params.priority !== ''
|
? Number(params.priority)
|
: void 0,
|
timeoutMinutes:
|
params.timeoutMinutes !== undefined && params.timeoutMinutes !== null && params.timeoutMinutes !== ''
|
? Number(params.timeoutMinutes)
|
: void 0,
|
maxRetryTimes:
|
params.maxRetryTimes !== undefined && params.maxRetryTimes !== null && params.maxRetryTimes !== ''
|
? Number(params.maxRetryTimes)
|
: void 0,
|
retryIntervalSeconds:
|
params.retryIntervalSeconds !== undefined && params.retryIntervalSeconds !== null && params.retryIntervalSeconds !== ''
|
? Number(params.retryIntervalSeconds)
|
: void 0,
|
stepSize:
|
params.stepSize !== undefined && params.stepSize !== null && params.stepSize !== ''
|
? Number(params.stepSize)
|
: void 0,
|
status:
|
params.status !== undefined && params.status !== null && params.status !== ''
|
? Number(params.status)
|
: void 0,
|
effectiveTime: normalizeText(params.effectiveTime),
|
expireTime: normalizeText(params.expireTime),
|
timeStart: normalizeText(params.timeStart),
|
timeEnd: normalizeText(params.timeEnd)
|
}
|
|
return Object.fromEntries(
|
Object.entries(searchParams).filter(([, value]) => value !== '' && value !== void 0 && value !== null)
|
)
|
}
|
|
export function buildTaskPathTemplateMergePageQueryParams(params = {}) {
|
return {
|
current: params.current || 1,
|
pageSize: params.pageSize || params.size || 20,
|
...buildTaskPathTemplateMergeSearchParams(params)
|
}
|
}
|
|
export function buildTaskPathTemplateMergeSavePayload(formData = {}) {
|
const isEditMode = formData.id !== void 0 && formData.id !== null && formData.id !== ''
|
const sourceTypeR = normalizeStringList(formData.sourceTypeR)
|
const targetTypeR = normalizeStringList(formData.targetTypeR)
|
const sourceType = normalizeText(formData.sourceType || '')
|
const targetType = normalizeText(formData.targetType || '')
|
const conditionExpression = normalizeIntegerList(formData.conditionExpression)
|
const derivedSource = sourceType || sourceTypeR[0] || ''
|
const derivedTarget = targetType || targetTypeR[0] || ''
|
const templateName =
|
normalizeText(formData.templateName || '') || (derivedSource && derivedTarget ? `${derivedSource}==>${derivedTarget}` : '')
|
const templateCode = normalizeText(formData.templateCode || '') || templateName
|
|
const payload = {
|
...(isEditMode ? { id: Number(formData.id) } : {}),
|
templateCode,
|
templateName,
|
conditionExpression,
|
conditionDesc: normalizeText(formData.conditionDesc || ''),
|
version:
|
formData.version !== void 0 && formData.version !== null && formData.version !== ''
|
? Number(formData.version)
|
: 1,
|
isCurrent:
|
formData.isCurrent !== void 0 && formData.isCurrent !== null && formData.isCurrent !== ''
|
? Number(formData.isCurrent)
|
: 1,
|
effectiveTime: normalizeText(formData.effectiveTime || ''),
|
expireTime: normalizeText(formData.expireTime || ''),
|
priority:
|
formData.priority !== void 0 && formData.priority !== null && formData.priority !== ''
|
? Number(formData.priority)
|
: 1,
|
...(formData.timeoutMinutes !== void 0 && formData.timeoutMinutes !== null && formData.timeoutMinutes !== ''
|
? { timeoutMinutes: Number(formData.timeoutMinutes) }
|
: {}),
|
maxRetryTimes:
|
formData.maxRetryTimes !== void 0 && formData.maxRetryTimes !== null && formData.maxRetryTimes !== ''
|
? Number(formData.maxRetryTimes)
|
: 3,
|
retryIntervalSeconds:
|
formData.retryIntervalSeconds !== void 0 &&
|
formData.retryIntervalSeconds !== null &&
|
formData.retryIntervalSeconds !== ''
|
? Number(formData.retryIntervalSeconds)
|
: 60,
|
status:
|
formData.status !== void 0 && formData.status !== null && formData.status !== ''
|
? Number(formData.status)
|
: 1,
|
...(formData.stepSize !== void 0 && formData.stepSize !== null && formData.stepSize !== ''
|
? { stepSize: Number(formData.stepSize) }
|
: {})
|
}
|
|
if (isEditMode) {
|
payload.sourceType = sourceType
|
payload.targetType = targetType
|
} else {
|
payload.sourceTypeR = sourceTypeR
|
payload.targetTypeR = targetTypeR
|
}
|
|
return payload
|
}
|
|
export function buildTaskPathTemplateMergeDialogModel(record = {}) {
|
const sourceTypeR = normalizeStringList(record.sourceTypeR)
|
const targetTypeR = normalizeStringList(record.targetTypeR)
|
const conditionExpression = normalizeIntegerList(record.conditionExpression)
|
|
return {
|
...createTaskPathTemplateMergeFormState(),
|
...(record.id !== void 0 && record.id !== null && record.id !== '' ? { id: Number(record.id) } : {}),
|
templateCode: normalizeText(record.templateCode || ''),
|
templateName: normalizeText(record.templateName || ''),
|
sourceTypeR,
|
targetTypeR,
|
sourceType: normalizeText(record.sourceType || ''),
|
targetType: normalizeText(record.targetType || ''),
|
conditionExpression: conditionExpression.length ? conditionExpression[0] : '',
|
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, ''),
|
maxRetryTimes: normalizeNumber(record.maxRetryTimes, 3),
|
retryIntervalSeconds: normalizeNumber(record.retryIntervalSeconds, 60),
|
stepSize: normalizeNumber(record.stepSize, ''),
|
status: normalizeNumber(record.status, 1)
|
}
|
}
|
|
function resolveConditionExpressionText(value, templateOptionsMap) {
|
const list = normalizeIntegerList(value)
|
if (!list.length) {
|
return ''
|
}
|
return list
|
.map((item) => templateOptionsMap?.get(String(item)) || templateOptionsMap?.get(Number(item)) || String(item))
|
.filter(Boolean)
|
.join('、')
|
}
|
|
export function normalizeTaskPathTemplateMergeDetailRecord(
|
record = {},
|
resolveTypeLabel,
|
templateOptionsMap
|
) {
|
const sourceType = normalizeText(record.sourceType || '')
|
const targetType = normalizeText(record.targetType || '')
|
const conditionExpression = normalizeIntegerList(record.conditionExpression)
|
const statusMeta = getTaskPathTemplateMergeStatusMeta(record.statusBool ?? record.status)
|
const currentMeta = getTaskPathTemplateMergeCurrentMeta(record.isCurrent)
|
const sourceTypeText =
|
normalizeText(record.sourceType$ || record.sourceTypeText || '') ||
|
(typeof resolveTypeLabel === 'function' ? normalizeText(resolveTypeLabel(sourceType)) : '')
|
const targetTypeText =
|
normalizeText(record.targetType$ || record.targetTypeText || '') ||
|
(typeof resolveTypeLabel === 'function' ? normalizeText(resolveTypeLabel(targetType)) : '')
|
const conditionExpressionText =
|
normalizeText(record.conditionExpressionText || '') ||
|
resolveConditionExpressionText(conditionExpression, templateOptionsMap)
|
|
return {
|
...record,
|
templateCode: normalizeText(record.templateCode || ''),
|
templateName: normalizeText(record.templateName || ''),
|
sourceType,
|
targetType,
|
sourceTypeText: sourceTypeText || sourceType || '--',
|
targetTypeText: targetTypeText || targetType || '--',
|
conditionExpression,
|
conditionExpressionText: conditionExpressionText || '--',
|
conditionDesc: normalizeText(record.conditionDesc || ''),
|
version: normalizeNumber(record.version, void 0),
|
isCurrent: normalizeNumber(record.isCurrent, void 0),
|
priority: normalizeNumber(record.priority, void 0),
|
timeoutMinutes: normalizeNumber(record.timeoutMinutes, void 0),
|
maxRetryTimes: normalizeNumber(record.maxRetryTimes, void 0),
|
retryIntervalSeconds: normalizeNumber(record.retryIntervalSeconds, void 0),
|
stepSize: normalizeNumber(record.stepSize, void 0),
|
status: normalizeNumber(record.status, void 0),
|
statusText: statusMeta.text,
|
statusType: statusMeta.type,
|
statusBool: record.statusBool !== void 0 ? Boolean(record.statusBool) : statusMeta.bool,
|
isCurrentText: currentMeta.text,
|
isCurrentType: currentMeta.type,
|
isCurrentBool: record.isCurrentBool !== void 0 ? Boolean(record.isCurrentBool) : 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 normalizeTaskPathTemplateMergeListRow(record = {}, resolveTypeLabel, templateOptionsMap) {
|
return normalizeTaskPathTemplateMergeDetailRecord(record, resolveTypeLabel, templateOptionsMap)
|
}
|
|
export function buildTaskPathTemplateMergePrintRows(records = [], resolveTypeLabel, templateOptionsMap) {
|
if (!Array.isArray(records)) {
|
return []
|
}
|
return records.map((record) => normalizeTaskPathTemplateMergeListRow(record, resolveTypeLabel, templateOptionsMap))
|
}
|
|
export function buildTaskPathTemplateMergeReportMeta({
|
previewMeta = {},
|
count = 0,
|
orientation = TASK_PATH_TEMPLATE_MERGE_REPORT_STYLE.orientation
|
} = {}) {
|
return {
|
reportTitle: TASK_PATH_TEMPLATE_MERGE_REPORT_TITLE,
|
reportDate: previewMeta.reportDate,
|
printedAt: previewMeta.printedAt,
|
operator: previewMeta.operator,
|
count,
|
reportStyle: {
|
...TASK_PATH_TEMPLATE_MERGE_REPORT_STYLE,
|
orientation
|
}
|
}
|
}
|