8
n8n 中文网amn8n.com

使用Gemini AI和Google Sheets的餐厅销售与库存预测系统

高级

这是一个Document Extraction, AI Summarization领域的自动化工作流,包含 17 个节点。主要使用 Code, Gmail, GoogleSheets, Agent, ScheduleTrigger 等节点。 使用Gemini AI和Google Sheets自动化餐厅销售与库存预测

前置要求
  • Google 账号和 Gmail API 凭证
  • Google Sheets API 凭证
  • Google Gemini API Key
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "id": "Y6Pn9PLNoMU7e8Xb",
  "meta": {
    "instanceId": "dd69efaf8212c74ad206700d104739d3329588a6f3f8381a46a481f34c9cc281",
    "templateCredsSetupCompleted": true
  },
  "name": "使用 Gemini AI 和 Google Sheets 的餐厅销售与库存预测系统",
  "tags": [],
  "nodes": [
    {
      "id": "80bda799-9bcd-41b5-a94e-ab32919b04e3",
      "name": "工作流说明",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        140,
        -200
      ],
      "parameters": {
        "color": 4,
        "width": 740,
        "height": 200,
        "content": "## 工作流概览"
      },
      "typeVersion": 1
    },
    {
      "id": "848c741c-7206-46cb-b10e-205feb126544",
      "name": "触发每周预测",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -340,
        460
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "weeks",
              "triggerAtHour": 20
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "75c05f50-aea8-48d7-ae9c-fc1e9af03179",
      "name": "加载历史销售数据",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -120,
        460
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1QZXX_gjNTTZ0vqPozNysjASQS3UcgwwWVpYvN7r-T_I/edit#gid=0",
          "cachedResultName": "current data"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1QZXX_gjNTTZ0vqPozNysjASQS3UcgwwWVpYvN7r-T_I",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1QZXX_gjNTTZ0vqPozNysjASQS3UcgwwWVpYvN7r-T_I/edit?usp=drivesdk",
          "cachedResultName": "Restaurant stock predictions"
        },
        "authentication": "serviceAccount"
      },
      "credentials": {
        "googleApi": {
          "id": "ScSS2KxGQULuPtdy",
          "name": "Google Sheets- test"
        }
      },
      "typeVersion": 4.6
    },
    {
      "id": "ecbf01be-4691-4a9e-b4dd-312a96ba73b2",
      "name": "为 AI Agent 格式化输入",
      "type": "n8n-nodes-base.code",
      "position": [
        100,
        460
      ],
      "parameters": {
        "jsCode": "// Fetch all incoming items\nconst items = $input.all();\n\n// Extract the raw row data (each item.json is one row)\nconst rawRows = items.map(item => item.json);\n\n// Bundle everything into a single field\nconst payload = { rows: rawRows };\n\n// Return a single output item whose json contains your full dataset\nreturn [{ json: { data: payload } }];\n"
      },
      "typeVersion": 2
    },
    {
      "id": "b83e66e4-2d98-47e0-9fb6-e5837863494e",
      "name": "使用 AI 生成预测",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        320,
        460
      ],
      "parameters": {
        "text": "={{ $json.data }}",
        "options": {
          "systemMessage": "You are a restaurant demand forecasting assistant.\n\nYou will be given a JSON object 'data' containing an array of historical weekly records. Each record includes:\n- row_number\n- Date (ISO format)\n- Sales for dishes (e.g. \"Neapolitan Pizza Sold\", \"Picanha Sold\", etc.)\n- Quantities of raw materials used that week (e.g. \"Flour (kg)\", \"Cheese (kg)\", etc.)\n\nYour task:\n1. Analyze trends across the historical weeks.\n2. Forecast next Monday’s sales (units sold for each dish).\n3. Calculate the required quantity of each raw material needed next week to match that forecast, based on per‑unit usage rates inferred from the data.\n4. Output exactly one JSON record, following the same structure as the input records. For example:\n\n```json\n{\n  \"row_number\": 7,\n  \"Date\": \"2025-07-14\",\n  \"Neapolitan Pizza Sold\": 58,\n  \"Picanha Sold\": 36,\n  \"Huevos Rancheros Sold\": 62,\n  \"Japanese Curry Sold\": 48,\n  \"Birria Ramen Sold\": 31,\n  \"Flour (kg)\": 11.5,\n  \"Cheese (kg)\": 5.8,\n  \"Tomato Sauce (L)\": 4.4,\n  \"Beef (kg)\": 18,\n  \"Pork (kg)\": 10,\n  \"Rice (kg)\": 5.8,\n  \"Tortillas (pcs)\": 62,\n  \"Eggs (pcs)\": 62,\n  \"Curry Powder (kg)\": 1.45,\n  \"Chili Powder (kg)\": 1.05\n}\n\nUse think tool if needed\n"
        },
        "promptType": "define"
      },
      "typeVersion": 1.9
    },
    {
      "id": "d0cc88f1-0bdb-48c0-9d6e-ff68e93517f0",
      "name": "AI 思考工具",
      "type": "@n8n/n8n-nodes-langchain.toolThink",
      "position": [
        468,
        680
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "c7df1137-e2b1-4ea9-9dd4-e4025e92480e",
      "name": "聊天模型",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        348,
        680
      ],
      "parameters": {
        "options": {},
        "modelName": "models/gemini-2.5-pro"
      },
      "credentials": {
        "googlePalmApi": {
          "id": "RvSkIBjP48ORJKhU",
          "name": "Google Gemini(PaLM) Api account - test"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "40dd2b9c-85b4-4e44-8e48-2972fb75645b",
      "name": "解析 AI 预测输出",
      "type": "n8n-nodes-base.code",
      "position": [
        696,
        460
      ],
      "parameters": {
        "jsCode": "// Run this in 'Run Once for All Items' mode\n\n// Assume AI agent returned a single item and that its output is in item.json.output\nconst items = $input.all();\nconst aiText = items[0].json.output;\n\n// Remove markdown fences and extract JSON\nconst jsonString = aiText\n  .replace(/```json\\s*([\\s\\S]*?)```/i, '$1') // strip markdown fences\n  .trim();\n\n// Parse it to a JS object\nlet parsed;\ntry {\n  parsed = JSON.parse(jsonString);\n} catch (e) {\n  throw new Error('Failed to parse JSON from AI output: ' + e.message);\n}\n\n// Ready to output\nreturn [{ json: parsed }];\n"
      },
      "typeVersion": 2
    },
    {
      "id": "537236ac-461a-416d-ada7-4e6be84cb790",
      "name": "将预测记录到 Google Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        916,
        460
      ],
      "parameters": {
        "columns": {
          "value": {},
          "schema": [
            {
              "id": "Date",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Date",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Neapolitan Pizza Sold",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Neapolitan Pizza Sold",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Picanha Sold",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Picanha Sold",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Huevos Rancheros Sold",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Huevos Rancheros Sold",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Japanese Curry Sold",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Japanese Curry Sold",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Birria Ramen Sold",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Birria Ramen Sold",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Flour (kg)",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Flour (kg)",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Cheese (kg)",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Cheese (kg)",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Tomato Sauce (L)",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Tomato Sauce (L)",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Beef (kg)",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Beef (kg)",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Pork (kg)",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Pork (kg)",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Rice (kg)",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Rice (kg)",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Tortillas (pcs)",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Tortillas (pcs)",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Eggs (pcs)",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Eggs (pcs)",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Curry Powder (kg)",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Curry Powder (kg)",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Chili Powder (kg)",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Chili Powder (kg)",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "autoMapInputData",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 370915330,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1QZXX_gjNTTZ0vqPozNysjASQS3UcgwwWVpYvN7r-T_I/edit#gid=370915330",
          "cachedResultName": "prediction data"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1QZXX_gjNTTZ0vqPozNysjASQS3UcgwwWVpYvN7r-T_I",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1QZXX_gjNTTZ0vqPozNysjASQS3UcgwwWVpYvN7r-T_I/edit?usp=drivesdk",
          "cachedResultName": "Restaurant stock predictions"
        },
        "authentication": "serviceAccount"
      },
      "credentials": {
        "googleApi": {
          "id": "ScSS2KxGQULuPtdy",
          "name": "Google Sheets- test"
        }
      },
      "typeVersion": 4.6
    },
    {
      "id": "0af7f39a-aa13-44fc-a653-71533d2851b6",
      "name": "邮件发送预测摘要",
      "type": "n8n-nodes-base.gmail",
      "position": [
        1136,
        460
      ],
      "webhookId": "64ff6f6e-2765-447c-b68c-352172b67174",
      "parameters": {
        "sendTo": "xyz@gmail.com",
        "message": "=Dear Manager,<br><br>  \nPlease find the details for the monday predicted data.<br><br>  \n\n\n\n<b>Scraping Date:</b>{{ $json.Date }}<br> \n<br>  \n\n\n<b>Sheet link with all data:</b><br> \n<a href=\"https://docs.google.com/spreadsheets/d/1QZXX_gjNTTZ0vqPozNysjASQS3UcgwwWVpYvN7r-T_I/edit?usp=sharing\">Click here to view the data</a><br>\n\n\n\n<br>  Thanks,<br> Ajay Mishra",
        "options": {},
        "subject": "Next monday prediction"
      },
      "credentials": {
        "gmailOAuth2": {
          "id": "PcTqvGU9uCunfltE",
          "name": "Gmail account - test"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "761f823d-4ba8-44d3-9ae7-c595de84cf9e",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -380,
        140
      ],
      "parameters": {
        "width": 180,
        "height": 480,
        "content": "按预定时间自动启动工作流。"
      },
      "typeVersion": 1
    },
    {
      "id": "aa031a03-5275-4aef-b1e9-a4e54b782a55",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -160,
        140
      ],
      "parameters": {
        "color": 3,
        "width": 180,
        "height": 480,
        "content": "从 Google Sheets 拉取每周销售额和材料使用量。"
      },
      "typeVersion": 1
    },
    {
      "id": "f87f5e45-590f-466e-8869-7d79216ee073",
      "name": "便签2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        656,
        140
      ],
      "parameters": {
        "color": 2,
        "width": 180,
        "height": 480,
        "content": "将 AI 响应解析为可读、可用的 JSON 格式。"
      },
      "typeVersion": 1
    },
    {
      "id": "d2dfb72b-056a-429c-b1b2-0fd95acea27d",
      "name": "便签3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        876,
        140
      ],
      "parameters": {
        "color": 5,
        "width": 180,
        "height": 480,
        "content": "将新预测数据存储回 Google Sheet。"
      },
      "typeVersion": 1
    },
    {
      "id": "c59672c3-2e43-4720-9952-1cca1af8b1ea",
      "name": "便签4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1096,
        140
      ],
      "parameters": {
        "color": 3,
        "width": 180,
        "height": 480,
        "content": "通过 Gmail 发送预测摘要。"
      },
      "typeVersion": 1
    },
    {
      "id": "265d61ce-6aad-46ee-a30d-81e291b91bed",
      "name": "便签5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        60,
        140
      ],
      "parameters": {
        "color": 4,
        "width": 180,
        "height": 480,
        "content": "将原始数据转换为适合 AI Agent 的结构化格式。"
      },
      "typeVersion": 1
    },
    {
      "id": "ee2932b4-96ec-464f-8b6c-0971a30740e3",
      "name": "便签6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        320,
        140
      ],
      "parameters": {
        "color": 6,
        "width": 260,
        "height": 480,
        "content": "使用 Gemini AI 分析趋势并预测未来需求。"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "01083ee7-6a3e-4dd5-92b3-13b38dbc019e",
  "connections": {
    "Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Generate Forecast with AI",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "AI Think Tool": {
      "ai_tool": [
        [
          {
            "node": "Generate Forecast with AI",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Trigger Weekly Forecast": {
      "main": [
        [
          {
            "node": "Load Historical Sales Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Input for AI Agent": {
      "main": [
        [
          {
            "node": "Generate Forecast with AI",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Forecast with AI": {
      "main": [
        [
          {
            "node": "Interpret AI Forecast Output",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Load Historical Sales Data": {
      "main": [
        [
          {
            "node": "Format Input for AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Interpret AI Forecast Output": {
      "main": [
        [
          {
            "node": "Log Forecast to Google Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log Forecast to Google Sheets": {
      "main": [
        [
          {
            "node": "Email Forecast Summary",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

高级 - 文档提取, AI 摘要总结

需要付费吗?

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

工作流信息
难度等级
高级
节点数量17
分类2
节点类型8
难度说明

适合高级用户,包含 16+ 个节点的复杂工作流

作者
Oneclick AI Squad

Oneclick AI Squad

@oneclick-ai

The AI Squad Initiative is a pioneering effort to build, automate and scale AI-powered workflows using n8n.io. Our mission is to help individuals and businesses integrate AI agents seamlessly into their daily operations from automating tasks and enhancing productivity to creating innovative, intelligent solutions. We design modular, reusable AI workflow templates that empower creators, developers and teams to supercharge their automation with minimal effort and maximum impact.

外部链接
在 n8n.io 查看

分享此工作流