{ "createdAt": "2025-02-13T05:16:29.165Z", "updatedAt": "2025-02-13T05:18:35.000Z", "id": "asu24td2qTGEEUwc", "name": "test-guidesafe", "active": true, "nodes": [ { "parameters": { "method": "POST", "url": "http://172.31.0.160/v1/completion-messages", "sendHeaders": true, "specifyHeaders": "json", "jsonHeaders": "{\n \"Authorization\": \"Bearer app-28NY8EgqFxFM3Sg8tkrD8puN\",\n \"Content-Type\": \"application/json\"\n}", "sendBody": true, "specifyBody": "json", "jsonBody": "={\n \"inputs\": {\"query\":\"{{$json.content.replaceAll(/[ \\t\\n\\r]+/g, '')}}\",\"json_schema\":\"{{JSON.stringify($json.json_str).replaceAll(/\"/g, '\\\\\"')}}\"},\n \"response_mode\": \"blocking\",\n \"user\": \"sl_backend_lsfww\"\n}", "options": {} }, "id": "fbf4724b-3dae-4ecd-9aeb-3f3ab0e7c988", "name": "dify", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [ 1140, 460 ] }, { "parameters": { "operation": "executeQuery", "query": "select location from schedule a where a.id = {{$json.body.schedule_id}};\n", "options": {} }, "id": "c726c979-7ae3-46d5-8d2a-acc035b98b77", "name": "get_location", "type": "n8n-nodes-base.mySql", "typeVersion": 2.4, "position": [ 400, 860 ], "credentials": { "mySql": { "id": "09oRI0DULmEzD9l8", "name": "SL-DB" } } }, { "parameters": { "operation": "executeQuery", "query": "select id,name_cn,COALESCE('$content$', '$content$') AS content from code a where group_id = '10' and status = '0' and id in (825,826,827,828,829,830);", "options": {} }, "id": "c2fca027-d086-45f7-91ef-6ef4261a4469", "name": "get_code", "type": "n8n-nodes-base.mySql", "typeVersion": 2.4, "position": [ 400, 340 ], "credentials": { "mySql": { "id": "09oRI0DULmEzD9l8", "name": "SL-DB" } } }, { "parameters": { "mode": "runOnceForEachItem", "jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nlet output_info = {};\nconsole.log($input.item.json.body);\ninfo = $input.item.json.body.info;\noutput_info['info'] = info;\nreturn output_info;" }, "id": "31d4c974-2c55-4ec6-8fec-6cf3da4a93e6", "name": "get_info", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 400, 620 ] }, { "parameters": { "mode": "runOnceForEachItem", "jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\n//answer = \"```json{\\\"test1\\\":\\\"test\\\"}```\";\nfunction findAllIndexes(str, charToFind) {\n const regex = new RegExp(charToFind, 'g');\n let indexes = [];\n let result;\n while ((result = regex.exec(str)) !== null) {\n indexes.push(result.index);\n }\n return indexes;\n}\nfunction isValidJSON(str) {\n try {\n JSON.parse(str);\n return true;\n } catch (e) {\n return false;\n }\n}\nfunction autoCompleteJSON(str) {\n if (isValidJSON(str)) {\n return str;\n }\n let missing = '';\n if (!str.endsWith('\"}]')) {\n missing += '\"}]'\n }\n str = str+missing;\n return str;\n}\nanswer = $input.item.json.answer;\nindexes = findAllIndexes(answer,\"```\");\nanswer_str = '';\nif(indexes.length>0){\n answer_str = answer.slice(indexes[0]+7, indexes[1]);\n}else{\n answer_str = answer;\n}\nconsole.log(answer_str);\nanswer_data_json = JSON.parse(autoCompleteJSON(answer_str));\nanswer_data = {};\nanswer_data[\"answer\"] = answer_data_json;\nreturn answer_data;" }, "id": "bf39b2a9-5b56-4835-a7c3-c039ef8f34ad", "name": "get_answer", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 1340, 460 ] }, { "parameters": { "jsCode": "// Add a new field called 'myNewField' to the JSON of the item\noutput_all = {};\ndata_list = $input.all();\n//console.log(data_list);\ncontent_all = [];\nfor(let item_index =0; item_index < data_list.length;item_index++){\n if(item_index != data_list.length-1){\n content_all.push(data_list[item_index].json);\n }\n}\noutput_all['content'] = data_list[(data_list).length-1].json.info;\noutput_all['json_str'] = content_all;\nreturn output_all;" }, "id": "12a60b22-2c36-4a1c-ae9c-9e56e98f8b19", "name": "get_query_info", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 940, 460 ] }, { "parameters": {}, "id": "e36e2bc3-405e-4911-b9db-c7b89182a5ed", "name": "get_code_info", "type": "n8n-nodes-base.merge", "typeVersion": 3, "position": [ 720, 460 ] }, { "parameters": { "jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nresult_data = $input.all();\ncontent_all = {};\nfor(let item_index =0; item_index < result_data.length;item_index++){\n item_data = result_data[item_index].json;\n if('answer' in item_data){\n content_all['answer'] = item_data['answer'];\n }else{\n content_all['location'] = item_data['location'];\n }\n}\nlocation_data_list = JSON.parse(content_all.location);\nanswer_data = content_all.answer;\noutput_all = [];\noutput_all_data = {};\noutput_all_data['answer'] = answer_data;\nlocation_data_arr = [];\nfor (let j = 0; j < location_data_list.length; j++) {\n location_data_arr.push(location_data_list[j].cityCode);\n}\noutput_all_data['city_code'] = location_data_arr;\noutput_all.push(output_all_data);\nreturn output_all;" }, "id": "1a8dc7e1-9082-4159-a5cb-3de54ecd7a5a", "name": "get_safe_guid_result", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 1160, 840 ] }, { "parameters": { "httpMethod": "POST", "path": "safeguide/test", "authentication": "headerAuth", "options": { "allowedOrigins": "*", "rawBody": false } }, "id": "a9f20048-fb0c-4a0f-a52f-b5329f9253b4", "name": "Webhook", "type": "n8n-nodes-base.webhook", "typeVersion": 2, "position": [ -140, 620 ], "webhookId": "e495a29c-8f43-4175-bdb8-277e03b60b07", "credentials": { "httpHeaderAuth": { "id": "1fHtEpWRIg2mFYBe", "name": "Header Auth account" } } }, { "parameters": { "operation": "executeQuery", "query": "CALL insert_safe_guide_source({{ JSON.stringify(JSON.stringify($json.answer)) }},{{ JSON.stringify(JSON.stringify($json.city_code)) }});", "options": {} }, "id": "70b5857d-2124-4350-8545-88a9ae3c9b44", "name": "insert_city_safe_guide", "type": "n8n-nodes-base.mySql", "typeVersion": 2.4, "position": [ 1360, 840 ], "credentials": { "mySql": { "id": "09oRI0DULmEzD9l8", "name": "SL-DB" } } }, { "parameters": {}, "id": "77d7c4ca-c397-47cf-96ef-4f8b4c457bf2", "name": "get_answer_location", "type": "n8n-nodes-base.merge", "typeVersion": 3, "position": [ 940, 840 ] } ], "connections": { "dify": { "main": [ [ { "node": "get_answer", "type": "main", "index": 0 } ] ] }, "get_location": { "main": [ [ { "node": "get_answer_location", "type": "main", "index": 1 } ] ] }, "get_code": { "main": [ [ { "node": "get_code_info", "type": "main", "index": 0 } ] ] }, "get_info": { "main": [ [ { "node": "get_code_info", "type": "main", "index": 1 } ] ] }, "get_answer": { "main": [ [ { "node": "get_answer_location", "type": "main", "index": 0 } ] ] }, "get_query_info": { "main": [ [ { "node": "dify", "type": "main", "index": 0 } ] ] }, "get_code_info": { "main": [ [ { "node": "get_query_info", "type": "main", "index": 0 } ] ] }, "get_safe_guid_result": { "main": [ [ { "node": "insert_city_safe_guide", "type": "main", "index": 0 } ] ] }, "Webhook": { "main": [ [ { "node": "get_info", "type": "main", "index": 0 }, { "node": "get_code", "type": "main", "index": 0 }, { "node": "get_location", "type": "main", "index": 0 } ] ] }, "get_answer_location": { "main": [ [ { "node": "get_safe_guid_result", "type": "main", "index": 0 } ] ] } }, "settings": { "executionOrder": "v1" }, "staticData": null, "meta": null, "pinData": null, "versionId": "711f7572-5d7e-4b35-a67a-629f713b9ee5", "triggerCount": 1, "shared": [ { "createdAt": "2025-02-13T05:16:29.172Z", "updatedAt": "2025-02-13T05:16:29.172Z", "role": "workflow:owner", "workflowId": "asu24td2qTGEEUwc", "projectId": "C7zKoCDdmGgzUqSW", "project": { "createdAt": "2024-08-23T06:31:21.275Z", "updatedAt": "2024-08-23T06:41:43.608Z", "id": "C7zKoCDdmGgzUqSW", "name": "周 卫 ", "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": [] }