import request from '@/utils/http' function normalizeText(value) { return typeof value === 'string' ? value.trim() : value } function normalizeIds(ids) { if (Array.isArray(ids)) { return ids .map((id) => String(id).trim()) .filter(Boolean) .join(',') } if (ids === null || ids === undefined) { return '' } return String(ids).trim() } function filterParams(params = {}, ignoredKeys = []) { return Object.fromEntries( Object.entries(params) .filter(([key, value]) => { if (ignoredKeys.includes(key)) return false if (value === undefined || value === null) return false if (typeof value === 'string' && value.trim() === '') return false return true }) .map(([key, value]) => [key, normalizeText(value)]) ) } export function buildTaskPathTemplatePageParams(params = {}) { return { current: params.current || 1, pageSize: params.pageSize || params.size || 20, ...filterParams(params, ['current', 'pageSize', 'size']) } } 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: 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, stepSize: params.stepSize !== undefined && params.stepSize !== null && params.stepSize !== '' ? Number(params.stepSize) : 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, status: params.status !== undefined && params.status !== null && params.status !== '' ? Number(params.status) : void 0, 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 buildTaskPathTemplateSavePayload(formData = {}) { return { ...(formData.id !== undefined && 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) || '', ...(formData.version !== undefined && formData.version !== null && formData.version !== '' ? { version: Number(formData.version) } : {}), ...(formData.isCurrent !== undefined && formData.isCurrent !== null && formData.isCurrent !== '' ? { isCurrent: Number(formData.isCurrent) } : {}), effectiveTime: normalizeText(formData.effectiveTime) || '', expireTime: normalizeText(formData.expireTime) || '', ...(formData.priority !== undefined && formData.priority !== null && formData.priority !== '' ? { priority: Number(formData.priority) } : {}), ...(formData.timeoutMinutes !== undefined && formData.timeoutMinutes !== null && formData.timeoutMinutes !== '' ? { timeoutMinutes: Number(formData.timeoutMinutes) } : {}), ...(formData.stepSize !== undefined && formData.stepSize !== null && formData.stepSize !== '' ? { stepSize: Number(formData.stepSize) } : {}), ...(formData.maxRetryTimes !== undefined && formData.maxRetryTimes !== null && formData.maxRetryTimes !== '' ? { maxRetryTimes: Number(formData.maxRetryTimes) } : {}), ...(formData.retryIntervalSeconds !== undefined && formData.retryIntervalSeconds !== null && formData.retryIntervalSeconds !== '' ? { retryIntervalSeconds: Number(formData.retryIntervalSeconds) } : {}), ...(formData.status !== undefined && formData.status !== null && formData.status !== '' ? { status: Number(formData.status) } : {}), remark: normalizeText(formData.remark) || '' } } export function fetchTaskPathTemplatePage(params = {}) { return request.post({ url: '/taskPathTemplate/page', params: buildTaskPathTemplatePageParams(params) }) } export function fetchTaskPathTemplateList(params = {}) { return request.post({ url: '/taskPathTemplate/list', params: filterParams(params) }) } export function fetchGetTaskPathTemplateDetail(id) { return request.get({ url: `/taskPathTemplate/${id}` }) } export function fetchGetTaskPathTemplateMany(ids) { return request.post({ url: `/taskPathTemplate/many/${normalizeIds(ids)}` }) } export function fetchSaveTaskPathTemplate(params = {}) { return request.post({ url: '/taskPathTemplate/save', params: buildTaskPathTemplateSavePayload(params) }) } export function fetchUpdateTaskPathTemplate(params = {}) { return request.post({ url: '/taskPathTemplate/update', params: buildTaskPathTemplateSavePayload(params) }) } export function fetchDeleteTaskPathTemplate(ids) { return request.post({ url: `/taskPathTemplate/remove/${normalizeIds(ids)}` }) } export function fetchTaskPathTemplateQuery(condition = '') { return request.post({ url: '/taskPathTemplate/query', params: { condition: normalizeText(condition) } }) } export async function fetchExportTaskPathTemplateReport(payload = {}, options = {}) { return fetch(`${import.meta.env.VITE_API_URL}/taskPathTemplate/export`, { method: 'POST', headers: { 'Content-Type': 'application/json', ...(options.headers || {}) }, body: JSON.stringify(payload) }) }