"jsCode":"// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nlet output_info = {};\ninfo = (JSON.parse($input.item.json.content)).实用信息;\noutput_info['info'] = info;\nreturn output_info;"
},
"id":"b1159cc1-1d2e-4ddb-b999-87c816c6405c",
"name":"content",
"type":"n8n-nodes-base.code",
"typeVersion":2,
"position":[
280,
80
]
},
{
"parameters":{
"jsCode":"// Loop over input items and add a new field called 'myNewField' to the JSON of each one\noutput_all = {};\noutput_data = {};\noutput_name_id = {};\nfor (const item of $input.all()) {\n output_data[item.json.name_cn] = \"xxx\";\n output_name_id[item.json.name_cn] = item.json.id;\n}\noutput_all['attr'] = output_data;\noutput_all['attr_id'] = output_name_id;\nreturn output_all;"
},
"id":"8833489f-a3d3-4fdf-a249-2912b818416a",
"name":"attribute",
"type":"n8n-nodes-base.code",
"typeVersion":2,
"position":[
40,
-120
]
},
{
"parameters":{
"operation":"executeQuery",
"query":"select id,name_cn from code a where group_id = '10' and status = '0';",
"options":{}
},
"id":"194726be-688f-448c-b5f2-d28952258be8",
"name":"attribute_sql",
"type":"n8n-nodes-base.mySql",
"typeVersion":2.4,
"position":[
-120,
-120
],
"credentials":{
"mySql":{
"id":"09oRI0DULmEzD9l8",
"name":"MySQL account"
}
}
},
{
"parameters":{
"operation":"executeQuery",
"query":"select location from schedule a where a.id = {{$json.schedule_id}}\n",
"options":{}
},
"id":"74d2db72-a3c9-434f-94ba-d5098f83756b",
"name":"location_sql",
"type":"n8n-nodes-base.mySql",
"typeVersion":2.4,
"position":[
60,
320
],
"credentials":{
"mySql":{
"id":"09oRI0DULmEzD9l8",
"name":"MySQL account"
}
}
},
{
"parameters":{
"mode":"runOnceForEachItem",
"jsCode":"// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nresult_data = $input.item.json;\nlocation_data_list = JSON.parse(result_data.location);\nanswer_data = JSON.parse(result_data.answer);\nattr_id_data = JSON.parse(result_data.attr_id);\n_output_all = [];\nfor (let i = 0; i < location_data_list.length; i++) {\n cityCode = location_data_list[i].cityCode;\n for (let key in answer_data) {\n if (jsonData.hasOwnProperty(key)) { // 确保key是对象自身的属性\n console.log(key + \":\" + answer_data[key]);\n data_item = {};\n data_item['city_code'] = cityCode;\n data_item['recommend'] = JSON.stringify(answer_data[key]);\n data_item['classification_id'] = attr_id_data[key];\n _output_all.append(data_item);\n }\n }\n}\nreturn _output_all;"
"jsCode":"// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nresult_data_json = {\n \"meta\":{\n\"instanceId\":\"ece0f5d11a08367ce2b9a54872effc3097e741a5f11c32cdaf18af6d780d6a56\"\n },\n \"nodes\":[\n{\n\"parameters\":{\n\"mode\":\"runOnceForEachItem\",\n \"jsCode\":\"// Loop over input items and add a new field called 'myNewField' to the JSON of each one\\nlocation_data_list = $input.item.json;\\nfor (let i = 0; i < location_data_list.length; i++) {\\n cityCode = location_data_list[i].cityCode;\\n \\n}\"\n },\n \"id\":\"c737a69f-0163-47bd-b863-70d7501187e7\",\n \"name\":\"result\",\n \"type\":\"n8n-nodes-base.code\",\n \"typeVersion\":2,\n\"position\":[\n900,\n260\n]\n}\n],\n\"connections\":{},\n\"pinData\":{}\n}\nresult_data={};\nresult_data['answer']=result_data_json;\nreturnresult_data;"
},
"id": "aa3a70a6-8194-49fb-bece-3ca78ce03807",
"name": "result1",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
640,
-260
]
},
{
"parameters": {
"mode": "combineBySql",
"numberInputs": 3
},
"id": "56ead3e5-fd33-4d83-b469-5d749f646602",
"name": "Merge2",
"type": "n8n-nodes-base.merge",
"typeVersion": 3,
"position": [
1060,
-40
]
},
{
"parameters": {
"mode": "combineBySql"
},
"id": "b67162e6-cc85-4519-8d9c-ac8edefa9f33",
"name": "Merge",
"type": "n8n-nodes-base.merge",
"typeVersion": 3,
"position": [
280,
-100
]
},
{
"parameters": {
"mode": "runOnceForEachItem",
"jsCode": "//Loopoverinputitemsandaddanewfieldcalled'myNewField'totheJSONofeachone\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}\nanswer = $input.item.json.answer;\nindexes = findAllIndexes(answer,\"```\");\nconsole.log(indexes[0]);\nanswer_data_json = JSON.parse(answer.slice(indexes[0]+7, indexes[1]));\nconsole.log(answer_data);\nanswer_data = {\"answer\":answer_data_json};\nreturn answer_data;"
},
"id":"debaa6fe-dfcc-479b-9297-0482ec381f2b",
"name":"answer",
"type":"n8n-nodes-base.code",
"typeVersion":2,
"position":[
740,
-100
]
},
{
"parameters":{
"mode":"combineBySql",
"numberInputs":3,
"query":"SELECT * FROM (SELECT * FROM input1 LEFT JOIN input2 ON input1.name = input2.id) as input1_1 LEFT JOIN input3 ON input1_1.name = input3.id"