const normalizeText = (value) => String(value == null ? '' : value) .replace(/\r/g, ' ') .replace(/\n/g, ' ') .replace(/\s+/g, ' ') .trim() const PUBLIC_ASSET_ASSIGNABLE_EXISTING_STATUSES = ['可用'] const isSheet2PublicEquipmentDescription = (description) => { const normalized = normalizeText(description) if (!normalized) { return false } return ( normalized.includes('source_workbook=docs/总表待导入.xlsx') && normalized.includes('source_sheet=Sheet2') ) } const buildPublicAssetBorrowState = (unitPrice) => { const normalizedUnitPrice = Number(unitPrice || 0) return { equipmentStatus: '已借出', remainingQuantity: 0, totalValue: normalizedUnitPrice, borrowedValue: normalizedUnitPrice, availableValue: 0 } } const buildAssignableExistingSheet2PublicEquipmentWhere = ( assignableStatuses = PUBLIC_ASSET_ASSIGNABLE_EXISTING_STATUSES ) => ({ AND: [ { description: { contains: 'source_workbook=docs/总表待导入.xlsx' } }, { description: { contains: 'source_sheet=Sheet2' } } ], status: { in: assignableStatuses }, borrow_records: { none: { status: '已借出' } } }) module.exports = { buildAssignableExistingSheet2PublicEquipmentWhere, PUBLIC_ASSET_ASSIGNABLE_EXISTING_STATUSES, buildPublicAssetBorrowState, isSheet2PublicEquipmentDescription, normalizeText }