node-red 积木集
一、文件解析1、对excel文件解析[ { id: 7a7144901cf961b7, type: inject, z: b70dc3c1a9523208, name: , props: [ { p: payload }, { p: topic, vt: str } ], repeat: , crontab: , once: false, onceDelay: 0.1, topic: , payload: , payloadType: date, x: 570, y: 140, wires: [ [ c96b453dd85c62f3 ] ] }, { id: c96b453dd85c62f3, type: file in, z: b70dc3c1a9523208, name: , filename: /data01.csv, filenameType: str, format: utf8, chunk: false, sendError: false, encoding: none, allProps: false, x: 730, y: 140, wires: [ [ 7eba9c7ec45ce36a ] ] }, { id: 7eba9c7ec45ce36a, type: csv, z: b70dc3c1a9523208, name: 解析, sep: ,, hdrin: false, hdrout: none, multi: mult, ret: \\n, temp: , skip: 0, strings: true, include_empty_strings: , include_null_values: , x: 890, y: 140, wires: [ [ 01438e29e6c6a93e ] ] }, { id: 01438e29e6c6a93e, type: function, z: b70dc3c1a9523208, name: BOM, func: //需要初始化的id\nmsg.bomDetailId 300; //BOM明细数据从200开始递增\nmsg.bomId 40;//BOM数据id从22递增\nmsg.bomCode 40;//BOM六位序号从30开始\n\nconst data msg.payload;\n//获取数据表中数据转换为BillNo-BOM工序链表形式\nmsg.bomData {};\n// const sz [00012305, 00012304, 00012308, 00012309, 00012310, 00012311, 00012312, 00012324, 00012325, 00012327, 00012328\n// , 00012331, 00012332, 00012333, 00013212, 00012731, 00012732, 00012739, 00012740, 00012741, 00012742,00012743,00012744,\n// 00012745, 00012746, 00012747, 00012748,00012749]\n\nconst sz []\nfor(let d of data){\n if (!d.col3 || d.col3 \BillNO\ || d.col3 \\){\n continue;\n }\n if (sz.includes(d.col3)){continue;}\n let bd msg.bomData[d.col3];\n if(bd undefined){\n bd [];\n msg.bomData[d.col3] bd;\n }\n if(d.col16 0){continue;};\n bd.push({\n id: d.col1,\n JProductTypeID: d.col2,\n BillNO: d.col3,\n JName: d.col4,\n Model: d.col5,\n Name: d.col6,\n JDeepLevel: d.col7,\n JParamValue: d.col8,\n JMaterialID: d.col9,\n JLevel: d.col10,\n MaterialName: d.col11,\n JStandard: d.col12,\n JModel: d.col13,\n ID: d.col14,\n ParentID: d.col15,\n // Plm_cate:711\n Plm_cate:d.col16\n });\n}\nmsg.bomNo Object.keys(msg.bomData);\nmsg.topic \SELECT x.id,x.name FROM jx_cloud_hy_plm.jx_plm_base_info_process x WHERE x.deleted 0\;\nmsg.payload {};\nreturn msg;, outputs: 1, timeout: 0, noerr: 0, initialize: , finalize: , libs: [], x: 1010, y: 140, wires: [ [ 83f7be26f45839d2, ace0f6e1f75854a5 ] ] } ]二、数据处理部分2.1、 手动loop循环遍历避免并发[ { id: 7fdc845085a4eda5, type: inject, z: df5a128aad8d31c5, name: , props: [ { p: payload }, { p: topic, vt: str } ], repeat: , crontab: , once: false, onceDelay: 0.1, topic: , payload: , payloadType: date, x: 150, y: 420, wires: [ [ 67c97f234acc0087 ] ] }, { id: 67c97f234acc0087, type: function, z: df5a128aad8d31c5, name: 手动loop避免并发, func: msg.data [1,2,3,4,5,6,7];//测试数组\nmsg.i 0; //初始化索引\nmsg.res []; //最后的结果\nreturn msg;, outputs: 1, timeout: 0, noerr: 0, initialize: , finalize: , libs: [], x: 380, y: 420, wires: [ [ db9592dc08f32b47 ] ] }, { id: db9592dc08f32b47, type: function, z: df5a128aad8d31c5, name: 处理逻辑, func: \nlet info msg.data[msg.i] \ 数据处理\;\nmsg.res.push(info);\nreturn msg;, outputs: 1, timeout: 0, noerr: 0, initialize: , finalize: , libs: [], x: 620, y: 420, wires: [ [ ab7fb074155986c9 ] ] }, { id: ab7fb074155986c9, type: function, z: df5a128aad8d31c5, name: idx, func: //判断是否执行循环\nmsg.isLoop false;\nif (msg.i msg.data.length - 1) {\n msg.i 1; //索引自增\n msg.isLoop true; //可继续循环\n}\nreturn msg;, outputs: 1, timeout: 0, noerr: 0, initialize: , finalize: , libs: [], x: 810, y: 420, wires: [ [ 574c0f28c54a0bbb ] ] }, { id: 574c0f28c54a0bbb, type: switch, z: df5a128aad8d31c5, name: isLoop, property: isLoop, propertyType: msg, rules: [ { t: true }, { t: false } ], checkall: true, repair: false, outputs: 2, x: 950, y: 420, wires: [ [ db9592dc08f32b47 ], [ 46ece8604ace768e ] ] }, { id: 46ece8604ace768e, type: function, z: df5a128aad8d31c5, name: end, func: node.warn(\------- 结束循环 -----------\);\nreturn msg;, outputs: 1, timeout: 0, noerr: 0, initialize: , finalize: , libs: [], x: 850, y: 500, wires: [ [ 9f1474969506fbca ] ] }, { id: 9f1474969506fbca, type: debug, z: df5a128aad8d31c5, name: res, active: true, tosidebar: true, console: false, tostatus: false, complete: res, targetType: msg, statusVal: , statusType: auto, x: 1050, y: 500, wires: [] } ]