8
n8n 中文网amn8n.com

房地产价格

中级

这是一个Lead Nurturing, Multimodal AI领域的自动化工作流,包含 10 个节点。主要使用 Code, Gmail, FormTrigger, MicrosoftSql, ConvertToFile 等节点。 SQL数据库和邮件发送的房地产物业搜索

前置要求
  • Google 账号和 Gmail API 凭证
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "id": "EdYQiWMiaUiLHaY5",
  "meta": {
    "instanceId": "5cee0adb1ef2b84ac8a86937fac5115d710898b6c70f9f7c3f3ca3ef70a11bf7",
    "templateCredsSetupCompleted": true
  },
  "name": "房地产价格",
  "tags": [],
  "nodes": [
    {
      "id": "cb598cd5-1145-4de8-adb7-50f88c9e2c13",
      "name": "房产搜索表单",
      "type": "n8n-nodes-base.formTrigger",
      "position": [
        120,
        240
      ],
      "webhookId": "property-search-webhook",
      "parameters": {
        "path": "property-search-form",
        "options": {},
        "formTitle": "🏠 Find Your Perfect Property",
        "formFields": {
          "values": [
            {
              "fieldType": "email",
              "fieldLabel": "Your Email Address",
              "requiredField": true
            },
            {
              "fieldType": "select",
              "fieldLabel": "Property Status"
            },
            {
              "fieldType": "number",
              "fieldLabel": "Minimum Price ($)"
            },
            {
              "fieldType": "number",
              "fieldLabel": "Maximum Price ($)"
            },
            {
              "fieldType": "number",
              "fieldLabel": "Minimum Bedrooms"
            },
            {
              "fieldType": "number",
              "fieldLabel": "Maximum Bedrooms"
            },
            {
              "fieldType": "number",
              "fieldLabel": "Minimum Bathrooms"
            },
            {
              "fieldType": "number",
              "fieldLabel": "Maximum Bathrooms"
            },
            {
              "fieldType": "number",
              "fieldLabel": "Minimum House Size (sqft)"
            },
            {
              "fieldType": "number",
              "fieldLabel": "Maximum House Size (sqft)"
            },
            {
              "fieldType": "number",
              "fieldLabel": "Minimum Lot Size (acres)"
            },
            {
              "fieldLabel": "State"
            },
            {
              "fieldLabel": "City"
            },
            {
              "fieldLabel": "ZIP Code"
            }
          ]
        },
        "formDescription": "Search through 1000+ real estate properties in our database"
      },
      "typeVersion": 2
    },
    {
      "id": "2498ced6-ab95-4967-a902-2ebf66361a54",
      "name": "构建SQL查询",
      "type": "n8n-nodes-base.code",
      "position": [
        340,
        240
      ],
      "parameters": {
        "jsCode": "// N8N JavaScript Code Tool for Property Search - Query Builder\n// This code builds the SQL query based on form criteria\n\n// Get form data from the previous node\nconst formData = $input.all()[0].json;\n\nconsole.log('Received form data:', JSON.stringify(formData, null, 2));\n\n// Initialize query components\nlet selectClause = `SELECT TOP (1000) [brokered_by]\n    ,[status]\n    ,[price]\n    ,[bed]\n    ,[bath]\n    ,[acre_lot]\n    ,[street]\n    ,[city]\n    ,[state]\n    ,[zip_code]\n    ,[house_size]\n    ,[prev_sold_date]`;\n\nlet fromClause = 'FROM [REALTOR].[dbo].[realtor_usa_price]';\nlet whereConditions = [];\n\n// Helper function to add numeric range conditions\nfunction addNumericRangeCondition(fieldName, minValue, maxValue, paramPrefix) {\n    const conditions = [];\n    \n    if (minValue !== undefined && minValue !== null && minValue !== '' && minValue !== 0) {\n        conditions.push(`[${fieldName}] >= ${minValue}`);\n    }\n    \n    if (maxValue !== undefined && maxValue !== null && maxValue !== '' && maxValue !== 0) {\n        conditions.push(`[${fieldName}] <= ${maxValue}`);\n    }\n    \n    return conditions;\n}\n\n// Helper function to add string conditions\nfunction addStringCondition(fieldName, value) {\n    if (value && value.trim() !== '') {\n        whereConditions.push(`[${fieldName}] = '${value.trim()}'`);\n    }\n}\n\n// Process form parameters\ntry {\n    // Price range\n    const priceConditions = addNumericRangeCondition(\n        'price', \n        formData['Minimum Price ($)'], \n        formData['Maximum Price ($)'], \n        'price'\n    );\n    whereConditions.push(...priceConditions);\n\n    // Bedroom range\n    const bedConditions = addNumericRangeCondition(\n        'bed', \n        formData['Minimum Bedrooms'], \n        formData['Maximum Bedrooms'], \n        'bed'\n    );\n    whereConditions.push(...bedConditions);\n\n    // Bathroom range\n    const bathConditions = addNumericRangeCondition(\n        'bath', \n        formData['Minimum Bathrooms'], \n        formData['Maximum Bathrooms'], \n        'bath'\n    );\n    whereConditions.push(...bathConditions);\n\n    // House size range (if provided)\n    const houseSizeConditions = addNumericRangeCondition(\n        'house_size', \n        formData['Minimum House Size (sqft)'], \n        formData['Maximum House Size (sqft)'], \n        'house_size'\n    );\n    whereConditions.push(...houseSizeConditions);\n\n    // Lot size range (if provided)\n    const lotSizeConditions = addNumericRangeCondition(\n        'acre_lot', \n        formData['Minimum Lot Size (acres)'], \n        formData['Maximum Lot Size (acres)'], \n        'lot_size'\n    );\n    whereConditions.push(...lotSizeConditions);\n\n    // String filters\n    addStringCondition('state', formData['State']);\n    addStringCondition('city', formData['City']);\n    \n    // ZIP Code (if provided)\n    if (formData['ZIP Code'] && formData['ZIP Code'] !== '') {\n        whereConditions.push(`[zip_code] = ${parseInt(formData['ZIP Code'])}`);\n    }\n\n    // Property Status (if provided and not empty)\n    addStringCondition('status', formData['Property Status']);\n\n} catch (error) {\n    console.error('Error processing form data:', error);\n    return [{\n        json: {\n            error: 'Failed to process form parameters',\n            details: error.message,\n            receivedData: formData\n        }\n    }];\n}\n\n// Build the complete query\nlet finalQuery = selectClause + '\\n' + fromClause;\n\nif (whereConditions.length > 0) {\n    finalQuery += '\\nWHERE ' + whereConditions.join('\\n  AND ');\n}\n\n// Add ordering\nfinalQuery += '\\nORDER BY [price] ASC';\n\nconsole.log('Generated SQL Query:', finalQuery);\n\n// Return the query for the SQL Server node to execute\nreturn [{\n    json: {\n        query: finalQuery,\n        searchCriteria: {\n            priceRange: {\n                min: formData['Minimum Price ($)'] || null,\n                max: formData['Maximum Price ($)'] || null\n            },\n            bedrooms: {\n                min: formData['Minimum Bedrooms'] || null,\n                max: formData['Maximum Bedrooms'] || null\n            },\n            bathrooms: {\n                min: formData['Minimum Bathrooms'] || null,\n                max: formData['Maximum Bathrooms'] || null\n            },\n            houseSizeRange: {\n                min: formData['Minimum House Size (sqft)'] || null,\n                max: formData['Maximum House Size (sqft)'] || null\n            },\n            lotSizeRange: {\n                min: formData['Minimum Lot Size (acres)'] || null,\n                max: formData['Maximum Lot Size (acres)'] || null\n            },\n            location: {\n                state: formData['State'] || null,\n                city: formData['City'] || null,\n                zipCode: formData['ZIP Code'] || null\n            },\n            status: formData['Property Status'] || null\n        },\n        formData: formData,\n        totalConditions: whereConditions.length,\n        userEmail: formData['Your Email Address'],\n        searchTimestamp: new Date().toISOString()\n    }\n}];"
      },
      "typeVersion": 2
    },
    {
      "id": "b846fe8e-e5bc-4b2b-8c38-3fe17102318b",
      "name": "Microsoft SQL",
      "type": "n8n-nodes-base.microsoftSql",
      "position": [
        520,
        240
      ],
      "parameters": {
        "query": "{{ $json.query }}",
        "operation": "executeQuery"
      },
      "typeVersion": 1.1
    },
    {
      "id": "9544305e-8b88-4c81-b471-7bb6bcab74b6",
      "name": "转换为文件",
      "type": "n8n-nodes-base.convertToFile",
      "position": [
        740,
        240
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 1.1
    },
    {
      "id": "254786a5-8d35-4978-918e-5bcaf2727b7a",
      "name": "发送消息",
      "type": "n8n-nodes-base.gmail",
      "position": [
        980,
        240
      ],
      "webhookId": "9b9033bc-5b75-4810-8097-3758bb96b970",
      "parameters": {
        "sendTo": "={{ $('Property Search Form').item.json['Your Email Address'] }}",
        "message": "=Hi there! 👋\n\nGreat news! We found {{ $('Microsoft SQL').all().length }} properties that match your search criteria.\n\n🏠 TOP MATCHES:\n{{ $('Microsoft SQL').all().slice(0, 3).map(property => \n`💰 $${property.json.price.toLocaleString()} - ${property.json.bed}bed/${property.json.bath}bath in ${property.json.city}, ${property.json.state}`\n).join('\\n') }}\n\n📎 COMPLETE RESULTS ATTACHED\nAll {{ $('Microsoft SQL').all().length }} properties are in the attached CSV file - perfect for Excel!\n\n🎯 YOUR SEARCH:\n- Price Range: ${{ $('Build SQL Query').first().json.searchCriteria.priceRange.min?.toLocaleString() || 'Any' }} - ${{ $('Build SQL Query').first().json.searchCriteria.priceRange.max?.toLocaleString() || 'Any' }}\n- Bedrooms: {{ $('Build SQL Query').first().json.searchCriteria.bedrooms.min || 'Any' }}+\n- Location: {{ $('Build SQL Query').first().json.searchCriteria.location.city || $('Build SQL Query').first().json.searchCriteria.location.state || 'Anywhere' }}\n\nHappy house hunting! 🏡✨\n\nYour Property Search Team",
        "options": {
          "attachmentsUi": {
            "attachmentsBinary": [
              {}
            ]
          }
        },
        "subject": "=🏠 Your Dream Home Search Results - {{ $('Microsoft SQL').all().length }} Properties Found!",
        "emailType": "text"
      },
      "typeVersion": 2.1
    },
    {
      "id": "37c6710a-8a1f-42f0-a286-a90d784b7824",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -40,
        60
      ],
      "parameters": {
        "width": 280,
        "height": 140,
        "content": "## 🎯 1. 从这里开始!"
      },
      "typeVersion": 1
    },
    {
      "id": "7c8fda0b-383c-453a-a2a7-0bf2be41e99d",
      "name": "便签 1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        200,
        400
      ],
      "parameters": {
        "color": 2,
        "width": 340,
        "content": "## 🧠 2. 智能查询构建器"
      },
      "typeVersion": 1
    },
    {
      "id": "4a132039-0d82-4d4f-a870-8f0d2a0143ab",
      "name": "便签 2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        420,
        80
      ],
      "parameters": {
        "color": 4,
        "width": 360,
        "height": 140,
        "content": "## 🔍 3. 数据库侦探"
      },
      "typeVersion": 1
    },
    {
      "id": "7f09df22-f034-4b8e-8405-1591ded23d6f",
      "name": "便签 3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        640,
        400
      ],
      "parameters": {
        "color": 5,
        "width": 320,
        "height": 140,
        "content": "## 📊 4. Excel魔法"
      },
      "typeVersion": 1
    },
    {
      "id": "55d26769-fc6e-4777-b556-6c2e3d668d21",
      "name": "便签 4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        900,
        80
      ],
      "parameters": {
        "color": 6,
        "width": 320,
        "height": 140,
        "content": "## 📧 5. 交付服务"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "c31c11a2-7b73-4c44-ac15-9ede8725fd7e",
  "connections": {
    "Microsoft SQL": {
      "main": [
        [
          {
            "node": "Convert to File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build SQL Query": {
      "main": [
        [
          {
            "node": "Microsoft SQL",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Convert to File": {
      "main": [
        [
          {
            "node": "Send a message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Property Search Form": {
      "main": [
        [
          {
            "node": "Build SQL Query",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。

这个工作流适合什么场景?

中级 - 客户培育, 多模态 AI

需要付费吗?

本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。

工作流信息
难度等级
中级
节点数量10
分类2
节点类型6
难度说明

适合有一定经验的用户,包含 6-15 个节点的中等复杂度工作流

作者
DataMinex

DataMinex

@dataminex

Smart Connection Analysis from Open Data, Globally at Scale

外部链接
在 n8n.io 查看

分享此工作流