"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;"