{
  "createdAt": "2025-02-13T05:05:55.413Z",
  "updatedAt": "2025-02-13T05:08:22.000Z",
  "id": "PK5biCTHj6VOkCXB",
  "name": "test_crimemap",
  "active": true,
  "nodes": [
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "select IFNULL(count(id), 0) as source_num from safe_guide_source cag where cag.source_id ={{JSON.stringify(JSON.parse($json.body.info).Incident)}};\n\n",
        "options": {}
      },
      "id": "a4a5d4c7-0083-41f2-b87c-5593451cc4c5",
      "name": "is_safe_exist",
      "type": "n8n-nodes-base.mySql",
      "typeVersion": 2.4,
      "position": [
        -100,
        400
      ],
      "credentials": {
        "mySql": {
          "id": "09oRI0DULmEzD9l8",
          "name": "SL-DB"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nfunction isEmptyString(value) {\n  // 方法1: 直接检查是否为空字符串或null\n  if (!value || value.trim() === '') {\n    return true;\n  }\n  return false;\n};\ninfo_data_list = JSON.parse($('Webhook').item.json.body.info);\noutput_all = [];\noutput_all_data = {};\noutput_news_data_str = \"\";\nnews_item_data = \"\";\nzone_data = {};\nzone_data['lat'] = info_data_list.lat;\nzone_data['lon'] = info_data_list.lng;\nzone_data_str = JSON.stringify(zone_data);\nnews_item_data = news_item_data+\"(\";\nnews_item_data += \"'\"+zone_data_str+\"'\";\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.Description+'\"';\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.Type_url+'\"';\n// news_item_data += ',';\n// news_item_data += '\"0\"';\nnews_item_data += ',';\nnews_item_data += '\"zh_cn\"';\nnews_item_data += ',';\nif(!isEmptyString(info_data_list.Date)){\n  news_item_data += 'STR_TO_DATE(\"'+info_data_list.Date+'\",\"%Y-%m-%d %H:%i:%s\")';\n  news_item_data += ',';\n}else{\n  news_item_data += 'NOW()';\n  news_item_data += ',';\n};\nnews_item_data += '\"'+info_data_list.Type+'\"';\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.Location+'\"';\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.Incident+'\"';\nnews_item_data += ')';\ncity_code = info_data_list.city_code;\nitem_data = \"(\";\nitem_data += '\"'+city_code+'\"';\nitem_data += ',';\nitem_data += '@last_insert_id';\nitem_data += ')';\noutput_news_data_str += item_data;\noutput_all_data['city_data'] = output_news_data_str.slice(0,output_news_data_str.length);\noutput_all_data['safe_data'] = news_item_data;\noutput_all.push(output_all_data);\nreturn output_all;"
      },
      "id": "8405a230-d68c-45ed-a9b5-3118a73677e0",
      "name": "get_safe_sql",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        400,
        300
      ]
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "START TRANSACTION;\n\nINSERT INTO crime_mapping (zone,content,icon,lang_code,event_time,event,address,source_id) VALUES {{ $json.safe_data }};\n\nSET @last_insert_id = LAST_INSERT_ID();\n\nINSERT INTO city_guide (city_code, source_id)\nVALUES {{ $json.city_data }};\n\nCOMMIT;",
        "options": {}
      },
      "id": "0046b23f-fc91-4c02-b4a7-96bdf23711c6",
      "name": "insert_safe",
      "type": "n8n-nodes-base.mySql",
      "typeVersion": 2.4,
      "position": [
        640,
        300
      ],
      "credentials": {
        "mySql": {
          "id": "09oRI0DULmEzD9l8",
          "name": "SL-DB"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nfunction isEmptyString(value) {\n  // 方法1: 直接检查是否为空字符串或null\n  if (!value || value.trim() === '') {\n    return true;\n  }\n  return false;\n};\ninfo_data_list = JSON.parse($('Webhook').item.json.body.info);\noutput_all = [];\noutput_all_data = {};\noutput_news_data_str = \"\";\nnews_item_data = \"\";\nzone_data = {};\nzone_data['lat'] = info_data_list.lat;\nzone_data['lon'] = info_data_list.lng;\nzone_data_str = JSON.stringify(zone_data);\nnews_item_data = news_item_data+\"(\";\nnews_item_data += \"'\"+zone_data_str+\"'\";\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.Description+'\"';\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.Type_url+'\"';\n// news_item_data += ',';\n// news_item_data += '\"0\"';\nnews_item_data += ',';\nnews_item_data += '\"zh_cn\"';\nnews_item_data += ',';\nif(!isEmptyString(info_data_list.Date)){\n  news_item_data += 'STR_TO_DATE(\"'+info_data_list.Date+'\",\"%Y-%m-%d %H:%i:%s\")';\n  news_item_data += ',';\n}else{\n  news_item_data += 'NOW()';\n  news_item_data += ',';\n};\nnews_item_data += '\"'+info_data_list.Type+'\"';\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.Location+'\"';\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.Incident+'\"';\nnews_item_data += ')';\n// city_code = info_data_list.city_code;\n// item_data = \"(\";\n// item_data += '\"'+city_code+'\"';\n// item_data += ',';\n// item_data += '@last_insert_id';\n// item_data += ')';\n// output_news_data_str += item_data;\n// output_all_data['city_data'] = output_news_data_str.slice(0,output_news_data_str.length);\noutput_all_data['safe_data'] = news_item_data;\noutput_all.push(output_all_data);\nreturn output_all;"
      },
      "id": "b3d3442a-9a13-4589-9cca-0eefaf8d29d0",
      "name": "get_safe_sql1",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        640,
        540
      ]
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "START TRANSACTION;\n\nINSERT INTO crime_mapping (zone,content,icon,lang_code,event_time,event,address,source_id) VALUES {{ $json.safe_data }};\n\n-- SET @last_insert_id = LAST_INSERT_ID();\n\n-- INSERT INTO city_guide (city_code, source_id)\n-- VALUES {{ $json.city_data }};\n\nCOMMIT;",
        "options": {}
      },
      "id": "4ca8f797-0732-4d32-b43f-19f22b9b707c",
      "name": "insert_safe1",
      "type": "n8n-nodes-base.mySql",
      "typeVersion": 2.4,
      "position": [
        840,
        540
      ],
      "credentials": {
        "mySql": {
          "id": "09oRI0DULmEzD9l8",
          "name": "SL-DB"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict"
          },
          "conditions": [
            {
              "id": "37fd1a36-8c69-4438-8fdc-6181956dfae3",
              "leftValue": "={{ $json.source_num.toString()}}",
              "rightValue": "0",
              "operator": {
                "type": "string",
                "operation": "equals",
                "name": "filter.operator.equals"
              }
            },
            {
              "id": "e8a93e70-faee-4ad7-865b-c76ee1fc6270",
              "leftValue": "={{ JSON.parse($('Webhook').item.json.body.info).city_code }}",
              "rightValue": "",
              "operator": {
                "type": "string",
                "operation": "notEmpty",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "35ba4cb0-4259-4d21-af57-d60ca5d9f444",
      "name": "If_1",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        100,
        400
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict"
          },
          "conditions": [
            {
              "id": "37fd1a36-8c69-4438-8fdc-6181956dfae3",
              "leftValue": "={{ $json.source_num.toString()}}",
              "rightValue": "0",
              "operator": {
                "type": "string",
                "operation": "equals",
                "name": "filter.operator.equals"
              }
            },
            {
              "id": "e8a93e70-faee-4ad7-865b-c76ee1fc6270",
              "leftValue": "={{ JSON.parse($('Webhook').item.json.body.info).city_code }}",
              "rightValue": "",
              "operator": {
                "type": "string",
                "operation": "empty",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "47c3f791-1a9a-4ce0-a55c-473d85d4bfb3",
      "name": "If_2",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        400,
        560
      ]
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "crime/save/test",
        "authentication": "headerAuth",
        "options": {
          "allowedOrigins": "*",
          "rawBody": false
        }
      },
      "id": "57520468-4c74-49b0-8254-a2595710ab47",
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        -320,
        400
      ],
      "webhookId": "e495a29c-8f43-4175-bdb8-277e03b60b07",
      "credentials": {
        "httpHeaderAuth": {
          "id": "1fHtEpWRIg2mFYBe",
          "name": "Header Auth account"
        }
      }
    }
  ],
  "connections": {
    "is_safe_exist": {
      "main": [
        [
          {
            "node": "If_1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "get_safe_sql": {
      "main": [
        [
          {
            "node": "insert_safe",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "get_safe_sql1": {
      "main": [
        [
          {
            "node": "insert_safe1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If_1": {
      "main": [
        [
          {
            "node": "get_safe_sql",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "If_2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If_2": {
      "main": [
        [
          {
            "node": "get_safe_sql1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Webhook": {
      "main": [
        [
          {
            "node": "is_safe_exist",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null,
  "meta": null,
  "pinData": null,
  "versionId": "06876946-2c2e-479c-976b-d1acb0928094",
  "triggerCount": 1,
  "shared": [
    {
      "createdAt": "2025-02-13T05:05:55.421Z",
      "updatedAt": "2025-02-13T05:05:55.421Z",
      "role": "workflow:owner",
      "workflowId": "PK5biCTHj6VOkCXB",
      "projectId": "C7zKoCDdmGgzUqSW",
      "project": {
        "createdAt": "2024-08-23T06:31:21.275Z",
        "updatedAt": "2024-08-23T06:41:43.608Z",
        "id": "C7zKoCDdmGgzUqSW",
        "name": "周 卫 <zhouwei@ssish.com>",
        "type": "personal",
        "projectRelations": [
          {
            "createdAt": "2024-08-23T06:31:21.275Z",
            "updatedAt": "2024-08-23T06:31:21.275Z",
            "role": "project:personalOwner",
            "userId": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
            "projectId": "C7zKoCDdmGgzUqSW",
            "user": {
              "createdAt": "2024-08-23T06:31:16.119Z",
              "updatedAt": "2025-03-19T06:19:26.514Z",
              "id": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
              "email": "zhouwei@ssish.com",
              "firstName": "周",
              "lastName": "卫",
              "personalizationAnswers": {
                "companyType": "education",
                "role": "business-owner",
                "automationBeneficiary": "my-team",
                "companySize": "20-99",
                "reportedSource": "friend",
                "version": "v4",
                "personalization_survey_submitted_at": "2024-08-23T06:57:52.856Z",
                "personalization_survey_n8n_version": "1.55.3"
              },
              "settings": {
                "userActivated": true,
                "firstSuccessfulWorkflowId": "s6zsznwVs6N4L2Hx",
                "userActivatedAt": 1725957335278,
                "npsSurvey": {
                  "responded": true,
                  "lastShownAt": 1742365155724
                },
                "isOnboarded": true
              },
              "role": "global:owner",
              "disabled": false,
              "mfaEnabled": false,
              "isPending": false,
              "isOwner": true
            }
          }
        ]
      }
    }
  ],
  "tags": []
}