From 48d0096ed6e11cc367e6bb062e1512f53d16d976 Mon Sep 17 00:00:00 2001
From: chenhaozhe <cgz@hz-kingdee.com>
Date: 星期五, 30 十月 2026 09:58:18 +0800
Subject: [PATCH] 乔一 数采流程初始化
---
flows.json | 810 +++++++++++++++++++++++++++++---------------------------
flows_cred.json | 5
package.json | 10
README.md | 2
4 files changed, 428 insertions(+), 399 deletions(-)
diff --git a/README.md b/README.md
index 5b275f9..9f8c412 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,7 @@
node-red-data-collection
========================
-node-red 鏁版嵁閲囬泦骞冲彴
+node-red 鏁版嵁閲囬泦骞冲彴 涔斾竴浣跨敤
### About
diff --git a/flows.json b/flows.json
index 4140a30..512cde1 100644
--- a/flows.json
+++ b/flows.json
@@ -1,6 +1,6 @@
[
{
- "id": "cee834492540f06e",
+ "id": "e50e36e69b1c47f6",
"type": "tab",
"label": "MSSQL 鏁版嵁鍚屾",
"disabled": false,
@@ -8,22 +8,22 @@
"env": []
},
{
- "id": "tab_collector_mqtt",
+ "id": "7f2f4359c1fe45f9",
"type": "tab",
"label": "閲囬泦鍣� MQTT 鎺ュ叆",
"disabled": false,
"info": "閲囬泦鍣ㄥ鎺ワ細/cmd 鎸囦护涓嬪彂涓庡洖鎵х‘璁ゃ�俓n\n娉ㄦ剰锛歁QTT 閲囬泦涓庡啓搴撳凡鎷嗗垎鍒扮嫭绔嬮〉绛俱�孧QTT 路 閲囬泦鍏ュ簱锛堢嫭绔嬶級銆嶁�斺�旀湰椤电涓嶅啀鎶� signal_msg 杞彂鍒颁富娴佺▼锛屼篃涓嶅啀鍙備笌鍐欏簱銆�"
},
{
- "id": "yy_multi_collect",
+ "id": "c28cda1b8a90e5a0",
"type": "tab",
- "label": "鐢ㄥ弸 路 澶氳〃閲囬泦鏁村悎",
+ "label": "鎮犳壃 路 澶氳〃閲囬泦鏁村悎",
"disabled": false,
- "info": "鐢ㄥ弸澶氳〃閲囬泦锛氬垎琛ㄦ竻鍗曠紦瀛�5鍒嗛挓锛岄泦鍚堝垎椤垫煡璇紱淇濈暀(time,SourceTable,id)澧為噺姘翠綅銆傚瓧娈垫槧灏勭粡铏氭嫙閾炬帴杩涘叆MSSQL鏁版嵁鍚屾椤祍ync_rows鍐呭瓨缂撳啿锛�5绉�/鏈�澶�5000琛屽叡鐢˙ulk鍐欏叆HX_LMESsys.dbo.Sb_EquipMentCollectionTechParam_Temp銆傚彧鏈夋暣鎵规彃鍏�/闃查噸璺宠繃鍏ㄩ儴纭鍚庢墠鎻愪氦姘翠綅銆傛殏鍋滀笉娓呯┖缂撳啿锛屽け璐ュ師鎵瑰洖濉��",
+ "info": "鎮犳壃澶氳〃閲囬泦锛氬垎琛ㄦ竻鍗曠紦瀛�5鍒嗛挓锛岄泦鍚堝垎椤垫煡璇紱淇濈暀(time,SourceTable,id)澧為噺姘翠綅銆傚瓧娈垫槧灏勭粡铏氭嫙閾炬帴杩涘叆MSSQL鏁版嵁鍚屾椤祍ync_rows鍐呭瓨缂撳啿锛�5绉�/鏈�澶�5000琛屽叡鐢˙ulk鍐欏叆HX_LMESsys.dbo.Sb_EquipMentCollectionTechParam_Temp銆傚彧鏈夋暣鎵规彃鍏�/闃查噸璺宠繃鍏ㄩ儴纭鍚庢墠鎻愪氦姘翠綅銆傛殏鍋滀笉娓呯┖缂撳啿锛屽け璐ュ師鎵瑰洖濉��",
"env": []
},
{
- "id": "tab_mqtt_pipeline",
+ "id": "3df84dbf3ac69e5e",
"type": "tab",
"label": "MQTT 路 閲囬泦鍏ュ簱锛堢嫭绔嬶級",
"disabled": false,
@@ -37,9 +37,9 @@
"server": "192.168.0.62",
"port": "49855",
"encyption": false,
- "trustServerCertificate": true,
+ "trustServerCertificate": false,
"database": "JYPM_wuyang",
- "useUTC": true,
+ "useUTC": false,
"connectTimeout": "",
"requestTimeout": "",
"cancelTimeout": "",
@@ -58,7 +58,7 @@
"encyption": false,
"trustServerCertificate": true,
"database": "HX_LMESsys",
- "useUTC": true,
+ "useUTC": false,
"connectTimeout": "",
"requestTimeout": "",
"cancelTimeout": "",
@@ -71,13 +71,13 @@
"id": "04dfbd6bd2067336",
"type": "MSSQL-CN",
"tdsVersion": "7_4",
- "name": "yongyouSync",
+ "name": "yoyongSync",
"server": "192.168.0.62",
"port": "49855",
"encyption": false,
"trustServerCertificate": true,
"database": "StandBussDB",
- "useUTC": true,
+ "useUTC": false,
"connectTimeout": "",
"requestTimeout": "",
"cancelTimeout": "",
@@ -92,7 +92,7 @@
"name": "鑷湁璁惧 MQTT Broker",
"broker": "127.0.0.1",
"port": "1883",
- "clientid": "",
+ "clientid": "node-red mqtt connect",
"autoConnect": true,
"usetls": false,
"verifyservercert": true,
@@ -119,9 +119,9 @@
"sessionExpiry": ""
},
{
- "id": "4e0d058caa7afc4e",
+ "id": "8726fa75773cc322",
"type": "MSSQL",
- "z": "cee834492540f06e",
+ "z": "e50e36e69b1c47f6",
"mssqlCN": "d082727f8d89ba41",
"name": "浜旀磱 鏁版嵁搴�",
"outField": "payload",
@@ -142,14 +142,14 @@
"y": 320,
"wires": [
[
- "c53aa63e531b7e6d"
+ "96ed6b8768424c7c"
]
]
},
{
- "id": "e20ef8063f6ae7d6",
+ "id": "3d9cf9eaba8ec509",
"type": "debug",
- "z": "cee834492540f06e",
+ "z": "e50e36e69b1c47f6",
"name": "鍚屾 路 鏍囧噯鍖栫粨鏋�",
"active": false,
"tosidebar": true,
@@ -164,9 +164,9 @@
"wires": []
},
{
- "id": "c48718bed4c3dfa7",
+ "id": "9d3fc363c90e772f",
"type": "inject",
- "z": "cee834492540f06e",
+ "z": "e50e36e69b1c47f6",
"name": "浜旀磱 路 姣�1s瀹炴椂蹇収 鈫� 缂撳啿",
"props": [],
"repeat": "1",
@@ -178,14 +178,14 @@
"y": 320,
"wires": [
[
- "fn_wy_q"
+ "2b63186a3aacf513"
]
]
},
{
- "id": "c53aa63e531b7e6d",
+ "id": "96ed6b8768424c7c",
"type": "function",
- "z": "cee834492540f06e",
+ "z": "e50e36e69b1c47f6",
"name": "浜旀磱 路 鏍囧噯鍖栦负鏁版嵁搴撳瓧娈�",
"func": "/**\n * 浜旀磱瀹炴椂蹇収鏍囧噯鍖朶n * 杈撳叆锛歮sg.payload=BaseMachine璁板綍锛宮sg.wySampleTime=鏈閲囨牱姣\n * 杈撳嚭锛歮sg.collectionRows=鏁版嵁搴撳瓧娈垫暟缁勶紱payload鍚屾暟缁刓n * 涓婁笅鏂囷細wy_snapshot_stats锛泈y_poll_inflight\n */\nfunction canonicalParameterName(parameterName) {\n const aliases = {\n '杞��': '鏈哄櫒杞��',\n '鐝骞冲潎杞﹂��': '鐝骞冲潎杞��',\n '鏈彮浜ч噺': '鐝浜ч噺(婧愬崟浣�)',\n '鏈彮鏁堢巼': '鐝鏁堢巼(%)',\n '鏈彮鍋滄満娆℃暟': '鐝鍋滄満娆℃暟',\n '鏈彮鍋滄満鏃堕棿(绉�)': '鐝鍋滄満鏃堕棿(绉�)',\n '鏈尮浜ч噺': '鏈尮浜ч噺(婧愬崟浣�)'\n };\n const name = String(parameterName);\n // 鐢ㄥ弸浜嬩欢閲岀殑鏈彮浜ч噺闄勬湁瀹為檯鍗曚綅锛屾部鐢ㄥ悓涓�鐝浜ч噺鍚嶇О銆俓n const withUnit = /^鏈彮浜ч噺\\((.+)\\)$/.exec(name);\n if (withUnit) return '鐝浜ч噺(' + withUnit[1] + ')';\n return aliases[name] || name;\n}\nfunction createCollectionRow(source, deviceCode, parameterName, value, collectedAt, createdAt) {\n const amount = Math.round(Number(value) * 100) / 100;\n return {\n HItemID: null,\n // SQL Server 鑷锛孊ulk 涓嶄紶姝ゅ垪\n HDate: new Date(collectedAt),\n // 閲囨牱鏃堕棿/婧愯澶囨椂闂碶n HSourceCode: String(deviceCode).slice(0, 50),\n HTechParamID: 0,\n // 娌跨敤鐜版湁鐩爣琛ㄧ害瀹歕n HTechParamName: canonicalParameterName(parameterName).slice(0, 500),\n HCount: amount,\n // SQL decimal(18,2)\n HCreateTime: new Date(createdAt),\n // 鏍囧噯鍖栧垱寤烘椂闂达紱閲嶈瘯淇濇寔涓嶅彉\n HResult: String(amount).slice(0, 50),\n HProcNumber: String(source).slice(0, 50),\n // WY / YY / MQTT\n HFlag: 0\n };\n}\nfunction normalizeWuyangSnapshot(msg, flow, global, node) {\n // 姣忕鍏ㄩ噺蹇収锛氱浉鍚屾暟鍊间篃鍏ラ槦锛孒Date鐢ㄦ湰娆¢噰鏍锋椂闂淬�俓n flow.set('wy_poll_inflight', false);\n if (global.get('collection_paused') !== false) {\n node.status({\n fill: 'yellow',\n shape: 'ring',\n text: '閲囬泦宸叉殏鍋�'\n });\n return null;\n }\n const sourceRows = Array.isArray(msg.payload) ? msg.payload : [];\n if (!sourceRows.length) {\n node.status({\n fill: 'grey',\n shape: 'ring',\n text: 'BaseMachine 0鍙拌澶�'\n });\n return null;\n }\n const sampleTimestamp = Number(msg.wySampleTime);\n if (!Number.isFinite(sampleTimestamp)) {\n node.error('缂哄皯浜旀磱閲囨牱鏃堕棿锛屾嫆缁濆悎骞跺埌鏃ф椂闂寸偣', msg);\n return null;\n }\n\n // 瀛楁鍚嶇О鐩存帴浣跨敤浜旀磱BaseMachine瀛楀吀锛涚姸鎬佽浆鎹负缁熶竴鏁板�肩紪鐮併�俓n const stateCodes = {\n '杩愯': 1,\n '寰呮満': 2,\n '鍋滄満': 3,\n '鎶ヨ': 4,\n '绂荤嚎': 5\n };\n const parameterNames = ['鏈哄櫒杞��', '鐢熶骇閫熷害', '绱浜ч噺', '璁㈠崟鍖规暟', '宸茬敓浜у尮鏁�', '褰撳墠鍖瑰凡鐢熶骇闀垮害'];\n for (let axisNumber = 1; axisNumber <= 8; axisNumber++) parameterNames.push('缁忚酱閫佺粡閲�' + axisNumber);\n const collectedAt = new Date(sampleTimestamp);\n const createdAt = new Date();\n const collectionRows = [];\n const sourceTimes = [];\n let deviceCount = 0;\n let latestSourceTime = null;\n for (const sourceRow of sourceRows) {\n const machineCode = String(sourceRow.MachineNo || sourceRow.BaseMachineID || '').trim();\n if (!machineCode) continue;\n const deviceCode = ('WY-' + machineCode).slice(0, 50);\n const firstRowIndex = collectionRows.length;\n for (const parameterName of parameterNames) {\n const rawValue = sourceRow[parameterName];\n if (rawValue === null || rawValue === undefined || String(rawValue).trim() === '') continue;\n // 浜旀磱鏈変簺varchar鍊煎甫鍗曚綅锛涗繚鐣欏師娴佺▼鍘诲崟浣嶇殑鏁板�艰В鏋愯鍒欍�俓n const value = parseFloat(String(rawValue).replace(/[^0-9.\\-]/g, ''));\n if (Number.isFinite(value)) {\n collectionRows.push(createCollectionRow('WY', deviceCode, parameterName, value, collectedAt, createdAt));\n }\n }\n const stateCode = stateCodes[String(sourceRow['鐘舵��'] || '').trim()];\n if (stateCode !== undefined) {\n collectionRows.push(createCollectionRow('WY', deviceCode, '杩愯鐘舵��', stateCode, collectedAt, createdAt));\n }\n if (collectionRows.length === firstRowIndex) continue;\n deviceCount += 1;\n const sourceTime = sourceRow.MachineCollectionTime ? new Date(sourceRow.MachineCollectionTime) : null;\n if (sourceTime && Number.isFinite(sourceTime.getTime())) {\n sourceTimes.push({\n HSourceCode: deviceCode,\n sourceCollectionTime: sourceTime\n });\n if (!latestSourceTime || sourceTime > latestSourceTime) latestSourceTime = sourceTime;\n }\n }\n if (!collectionRows.length) {\n node.status({\n fill: 'grey',\n shape: 'ring',\n text: '鏃犳湁鏁堣澶囧弬鏁�'\n });\n return null;\n }\n const previousStats = flow.get('wy_snapshot_stats') || {};\n const snapshotStats = {\n polls: (previousStats.polls || 0) + 1,\n snapshots: (previousStats.snapshots || 0) + deviceCount,\n parameters: (previousStats.parameters || 0) + collectionRows.length,\n devices: deviceCount,\n lastSampleTime: collectedAt.toISOString(),\n latestSourceTime: latestSourceTime ? latestSourceTime.toISOString() : null\n };\n flow.set('wy_snapshot_stats', snapshotStats);\n delete msg.collect;\n msg.collectionRows = collectionRows;\n msg.collectionSourceTimes = sourceTimes; // 瀹¤淇℃伅锛屼笌鐩爣琛ㄥ垪鍒嗗紑淇濆瓨\n msg.collectionSummary = {\n source: 'WY',\n devices: deviceCount,\n parameters: collectionRows.length,\n sampleTime: snapshotStats.lastSampleTime\n };\n msg.payload = collectionRows;\n node.status({\n fill: 'green',\n shape: 'dot',\n text: deviceCount + '鍙� / ' + collectionRows.length + '椤� / 姣忕瀹屾暣蹇収'\n });\n return msg;\n}\nreturn normalizeWuyangSnapshot(msg, flow, global, node);\n",
"outputs": 1,
@@ -201,9 +201,9 @@
]
},
{
- "id": "fe88ac9fe19141be",
+ "id": "2b7f27474a8814a8",
"type": "MSSQL",
- "z": "cee834492540f06e",
+ "z": "e50e36e69b1c47f6",
"mssqlCN": "9bb47eb9867c4772",
"name": "鐩爣搴� 路 bulk 鍐欑紦瀛樹复鏃惰〃",
"outField": "payload",
@@ -224,14 +224,14 @@
"y": 500,
"wires": [
[
- "fn_sync_success"
+ "c62baf870846ef7b"
]
]
},
{
- "id": "08c95ee2bd3a9073",
+ "id": "b5e431fb3fde0ed3",
"type": "function",
- "z": "cee834492540f06e",
+ "z": "e50e36e69b1c47f6",
"name": "鏁版嵁搴撴爣鍑嗚 鈫� 鍏叡缂撳啿",
"func": "/**\n * 缁熶竴鏁版嵁搴撹鍏ョ紦鍐瞈n * 杈撳叆锛歮sg.collectionRows锛涚敤鍙嬪彟甯sg.yySync\n * 杈撳嚭锛氳緭鍑�1=鍏ラ槦鎽樿/鏁版嵁搴撳瓧娈甸瑙堬紱杈撳嚭2=鐢ㄥ弸鍥炴墽\n * 涓婁笅鏂囷細sync_rows锛泂ync_yy_batches锛泂ync_yy_completed\n */\nfunction collectionRowKey(row) {\n // 淇濈暀鍘熸湁鑷劧閿紪鐮侊紝鍏煎鏃у緟纭鎵规鐨� doneKeys銆俓n return row.HProcNumber + '|' + row.HSourceCode + '|' + row.HTechParamName + '|' + new Date(row.HDate).getTime();\n}\nfunction convertLegacyBufferRow(row, createdAt) {\n if (row.HDate !== undefined && row.HSourceCode !== undefined) {\n // 宸叉槸鏂版牸寮忥細淇濈暀鏃㈡湁瀛楁鍜屾壒娆″紩鐢紝鍙仮澶� Date 绫诲瀷銆俓n return {\n ...row,\n HDate: new Date(row.HDate),\n HCreateTime: row.HCreateTime ? new Date(row.HCreateTime) : new Date(createdAt)\n };\n }\n // 閮ㄧ讲鍏煎锛氭棫 sync_rows 浣跨敤 s/d/p/v/t锛屽師鎵硅涔夊強鍘熷弬鏁板悕淇濇寔涓嶅彉銆俓n const converted = {\n HItemID: null,\n HDate: new Date(row.t),\n HSourceCode: row.d,\n HTechParamID: 0,\n HTechParamName: row.p,\n HCount: row.v,\n HCreateTime: new Date(createdAt),\n HResult: String(row.v).slice(0, 50),\n HProcNumber: row.s,\n HFlag: 0\n };\n if (row.yyRefs?.length) converted._sync = {\n yyBatchIds: [...row.yyRefs]\n };\n return converted;\n}\nfunction legacyCollectToRows(collect, createdAt) {\n // 鍙敤浜庡崌绾у墠缂撳瓨鐨� pending.write锛涗笁璺柊娑堟伅閮界洿鎺ヨ緭鍑� collectionRows銆俓n const rows = [];\n for (const item of collect || []) {\n const collectedAt = new Date(item.ts);\n if (!Number.isFinite(collectedAt.getTime())) continue;\n for (const [parameterName, value] of Object.entries(item.data || {})) {\n if (value === null || value === undefined || value === '') continue;\n if (!Number.isFinite(Number(value))) continue;\n // 宸茬瓑寰呯‘璁ょ殑鏃ф壒涓嶆敼鍚嶏紝淇濊瘉涓庝箣鍓嶅凡钀藉簱閮ㄥ垎鐨勯槻閲嶉敭涓�鑷淬�俓n rows.push({\n HItemID: null,\n HDate: collectedAt,\n HSourceCode: String(item.device).slice(0, 50),\n HTechParamID: 0,\n HTechParamName: parameterName.slice(0, 500),\n HCount: Math.round(Number(value) * 100) / 100,\n HCreateTime: new Date(createdAt),\n HResult: String(Math.round(Number(value) * 100) / 100).slice(0, 50),\n HProcNumber: item.src,\n HFlag: 0\n });\n }\n }\n return rows;\n}\nfunction enqueueCollectionRows(msg, flow, global, node) {\n const batchMeta = msg.yySync;\n const isYouyangBatch = Boolean(batchMeta?.batchId && batchMeta?.stream);\n const makeAck = (kind, details = {}) => ({\n yySync: batchMeta,\n yyAck: {\n kind,\n ...details\n },\n payload: {\n stream: batchMeta?.stream,\n ...details\n }\n });\n\n // 1. 鏆傚仠鍙仠姝㈡柊澧烇紝涓嶆竻绌哄師缂撳啿锛屼篃涓嶆彁浜ょ敤鍙嬫按浣嶃�俓n if (global.get('collection_paused') !== false) {\n node.status({\n fill: 'yellow',\n shape: 'ring',\n text: '閲囬泦宸叉殏鍋滐紝缂撳啿淇濈暀'\n });\n return isYouyangBatch ? [null, makeAck('deferred', {\n reason: '閲囬泦宸叉殏鍋�'\n })] : null;\n }\n const completedBatches = flow.get('sync_yy_completed') || {};\n const pendingBatches = flow.get('sync_yy_batches') || {};\n if (isYouyangBatch && completedBatches[batchMeta.batchId]) {\n return [null, completedBatches[batchMeta.batchId]];\n }\n if (isYouyangBatch && pendingBatches[batchMeta.batchId]) {\n return [null, makeAck('queued', {\n expected: pendingBatches[batchMeta.batchId].expected,\n duplicateRequest: true\n })];\n }\n\n // 2. 涓夎矾鏂拌緭鍏ュ潎涓烘暟鎹簱瀛楁瀵硅薄銆俢ollect 浠呭吋瀹归儴缃插墠鐨勫緟纭娑堟伅銆俓n const createdAt = new Date();\n const inputRows = Array.isArray(msg.collectionRows) ? msg.collectionRows : legacyCollectToRows(msg.collect, createdAt);\n const validRows = [];\n const uniqueYouyangRows = new Map();\n for (const input of inputRows) {\n const row = convertLegacyBufferRow(input, createdAt);\n const valid = row.HSourceCode && row.HTechParamName && Number.isFinite(row.HDate.getTime()) && Number.isFinite(row.HCreateTime.getTime()) && typeof row.HCount === 'number' && Number.isFinite(row.HCount);\n if (!valid) {\n // 涓嶆妸鈥滄牸寮忛敊璇�濅吉瑁呮垚鍐欏簱鎴愬姛锛涚敤鍙嬪繀椤讳繚鐣欏師鎵瑰拰姘翠綅銆俓n if (isYouyangBatch) return [null, makeAck('deferred', {\n reason: '鏍囧噯琛屾棤鏁堬紝妫�鏌ユ暟鎹簱瀛楁'\n })];\n node.warn('蹇界暐鏃犳晥閲囬泦鍙傛暟琛�');\n continue;\n }\n if (isYouyangBatch) {\n if (row.HProcNumber !== 'YY') return [null, makeAck('deferred', {\n reason: '鐢ㄥ弸鎵规鏉ユ簮蹇呴』涓篩Y'\n })];\n row._sync = {\n yyBatchIds: [batchMeta.batchId]\n }; // 浠呯敤浜庣‘璁わ紝涓嶆槸鏁版嵁搴撳垪\n uniqueYouyangRows.set(collectionRowKey(row), row);\n } else {\n validRows.push(row);\n }\n }\n if (isYouyangBatch) validRows.push(...uniqueYouyangRows.values());\n const bufferRows = flow.get('sync_rows') || [];\n if (isYouyangBatch && bufferRows.length + validRows.length > 20000) {\n node.status({\n fill: 'yellow',\n shape: 'ring',\n text: '缂撳啿绉帇锛岀敤鍙嬪師鎵圭瓑寰�'\n });\n return [null, makeAck('deferred', {\n reason: '缂撳啿杈惧埌20000琛岄檺娴�'\n })];\n }\n if (!validRows.length) {\n return isYouyangBatch ? [null, makeAck('committed', {\n inserted: 0,\n skipped: 0,\n expected: 0\n })] : null;\n }\n\n // 3. 鍏ラ槦鍥炴墽浠呰〃绀哄凡鎺ユ敹銆傛暣鎵瑰啓鍏�/璺宠繃瀹屾垚鍚庯紝鎵嶄細鍙戦�� committed銆俓n if (isYouyangBatch) {\n pendingBatches[batchMeta.batchId] = {\n meta: {\n ...batchMeta,\n phase: 'buffer'\n },\n expected: validRows.length,\n done: 0,\n inserted: 0,\n skipped: 0,\n doneKeys: {},\n queuedAt: new Date().toISOString()\n };\n }\n bufferRows.push(...validRows);\n flow.set('sync_rows', bufferRows);\n flow.set('sync_yy_batches', pendingBatches);\n node.status({\n fill: 'blue',\n shape: 'dot',\n text: '+' + validRows.length + ' / 缂撳啿 ' + bufferRows.length\n });\n\n // 璋冭瘯鍙瑙堝墠3琛岋紝渚夸簬瀵圭収鏁版嵁搴撳瓧娈碉紝涔熼伩鍏嶆瘡绉掓墦鍗板ぇ閲忓弬鏁般�俓n const preview = validRows.slice(0, 3).map(row => {\n const {\n _sync,\n ...databaseFields\n } = row;\n return databaseFields;\n });\n const diagnostic = {\n payload: {\n source: validRows[0].HProcNumber,\n buffered: validRows.length,\n pending: bufferRows.length,\n records: preview\n }\n };\n const ack = isYouyangBatch ? makeAck('queued', {\n expected: validRows.length,\n pending: bufferRows.length\n }) : null;\n return [diagnostic, ack];\n}\nreturn enqueueCollectionRows(msg, flow, global, node);\n",
"outputs": 2,
@@ -244,17 +244,17 @@
"y": 420,
"wires": [
[
- "e20ef8063f6ae7d6"
+ "3d9cf9eaba8ec509"
],
[
- "yy_ack_out"
+ "8cd53de2a6cf935d"
]
]
},
{
- "id": "fn_wy_q",
+ "id": "2b63186a3aacf513",
"type": "function",
- "z": "cee834492540f06e",
+ "z": "e50e36e69b1c47f6",
"name": "浜旀磱 路 璇诲彇鍏ㄩ儴瀹炴椂璁惧",
"func": "/**\n * 浜旀磱瀹炴椂鏌ヨ\n * 杈撳叆锛氭瘡绉掑畾鏃惰Е鍙慭n * 杈撳嚭锛歮sg.query/queryParams锛沵sg.wySampleTime\n * 涓婁笅鏂囷細wy_poll_inflight锛泈y_last_scheduled_second锛泂ync_rows鑳屽帇\n */\nfunction readWuyangDevices(msg, flow, global, node) {\n if (global.get('collection_paused') !== false) {\n node.status({\n fill: 'yellow',\n shape: 'ring',\n text: '閲囬泦宸叉殏鍋�'\n });\n return null;\n }\n if ((flow.get('sync_rows') || []).length >= 20000) {\n node.status({\n fill: 'yellow',\n shape: 'ring',\n text: '鍐欏簱绉帇锛屾殏鍋滃揩鐓ч噰鏍�'\n });\n return null;\n }\n if (flow.get('wy_poll_inflight')) {\n node.status({\n fill: 'yellow',\n shape: 'ring',\n text: '绛夊緟涓婃鏌ヨ瀹屾垚'\n });\n return null;\n }\n const sampleTimestamp = Math.floor(Date.now() / 1000) * 1000;\n if (flow.get('wy_last_scheduled_second') === sampleTimestamp) return null;\n flow.set('wy_last_scheduled_second', sampleTimestamp);\n flow.set('wy_poll_inflight', true);\n const parameterNames = ['鏈哄櫒杞��', '鐢熶骇閫熷害', '绱浜ч噺', '璁㈠崟鍖规暟', '宸茬敓浜у尮鏁�', '褰撳墠鍖瑰凡鐢熶骇闀垮害'];\n for (let axisNumber = 1; axisNumber <= 8; axisNumber++) parameterNames.push('缁忚酱閫佺粡閲�' + axisNumber);\n msg.wySampleTime = sampleTimestamp;\n msg.query = `SELECT BaseMachineID, MachineNo, MachineName, 鐘舵��, MachineCollectionTime,\n ${parameterNames.map(name => '[' + name + ']').join(', ')}\nFROM JYPM_wuyang.dbo.BaseMachine\nORDER BY BaseMachineID;`;\n msg.queryParams = [];\n delete msg.wmFrom;\n node.status({\n fill: 'blue',\n shape: 'dot',\n text: '姣忕鍏ㄨ澶囧揩鐓�'\n });\n return msg;\n}\nreturn readWuyangDevices(msg, flow, global, node);\n",
"outputs": 1,
@@ -267,14 +267,14 @@
"y": 320,
"wires": [
[
- "4e0d058caa7afc4e"
+ "8726fa75773cc322"
]
]
},
{
- "id": "fn_sync_flush",
+ "id": "1450efa6b7c145ae",
"type": "function",
- "z": "cee834492540f06e",
+ "z": "e50e36e69b1c47f6",
"name": "缂撳啿鏁版嵁搴撹 鈫� Bulk鍒楁暟缁�",
"func": "/**\n * 缂撳啿杞珺ulk璇锋眰\n * 杈撳叆锛氭瘡5绉掕Е鍙慭n * 杈撳嚭锛歮sg.rows=鎸夊垪瀹氫箟鎺掑垪鐨勪簩缁存暟缁勶紱retryBuf=鍘熸暟鎹簱琛孿n * 涓婁笅鏂囷細sync_rows锛泂ync_inflight\n */\nfunction collectionRowKey(row) {\n // 淇濈暀鍘熸湁鑷劧閿紪鐮侊紝鍏煎鏃у緟纭鎵规鐨� doneKeys銆俓n return row.HProcNumber + '|' + row.HSourceCode + '|' + row.HTechParamName + '|' + new Date(row.HDate).getTime();\n}\nfunction convertLegacyBufferRow(row, createdAt) {\n if (row.HDate !== undefined && row.HSourceCode !== undefined) {\n // 宸叉槸鏂版牸寮忥細淇濈暀鏃㈡湁瀛楁鍜屾壒娆″紩鐢紝鍙仮澶� Date 绫诲瀷銆俓n return {\n ...row,\n HDate: new Date(row.HDate),\n HCreateTime: row.HCreateTime ? new Date(row.HCreateTime) : new Date(createdAt)\n };\n }\n // 閮ㄧ讲鍏煎锛氭棫 sync_rows 浣跨敤 s/d/p/v/t锛屽師鎵硅涔夊強鍘熷弬鏁板悕淇濇寔涓嶅彉銆俓n const converted = {\n HItemID: null,\n HDate: new Date(row.t),\n HSourceCode: row.d,\n HTechParamID: 0,\n HTechParamName: row.p,\n HCount: row.v,\n HCreateTime: new Date(createdAt),\n HResult: String(row.v).slice(0, 50),\n HProcNumber: row.s,\n HFlag: 0\n };\n if (row.yyRefs?.length) converted._sync = {\n yyBatchIds: [...row.yyRefs]\n };\n return converted;\n}\nfunction flushCollectionBuffer(msg, flow, global, node) {\n if (global.get('collection_paused') !== false) {\n node.status({\n fill: 'yellow',\n shape: 'ring',\n text: '閲囬泦宸叉殏鍋�'\n });\n return null;\n }\n if (flow.get('sync_inflight')) return null;\n const bufferRows = flow.get('sync_rows') || [];\n if (!bufferRows.length) return null;\n\n // 1. 鏈�澶氬彇5000琛屻�傚悓閿彧鍐欎竴娆★紝浣嗗悎骞舵墍鏈夌敤鍙嬫壒娆″紩鐢ㄣ�俓n const selectedRows = bufferRows.slice(0, 5000);\n const uniqueRows = new Map();\n const createdAt = new Date();\n for (const input of selectedRows) {\n const row = convertLegacyBufferRow(input, createdAt);\n const key = collectionRowKey(row);\n const previous = uniqueRows.get(key);\n const batchIds = new Set([...(previous?._sync?.yyBatchIds || []), ...(row._sync?.yyBatchIds || [])]);\n if (batchIds.size) row._sync = {\n yyBatchIds: Array.from(batchIds)\n };\n uniqueRows.set(key, row);\n }\n const selectedRecords = Array.from(uniqueRows.values());\n\n // 2. 鍙湁Bulk杈圭晫闇�瑕佷簩缁存暟缁勶紝鍒楅『搴忛泦涓畾涔夛紝涓嶅啀浣跨敤r.s/r.d/r.p绛夌缉鍐欍�俓n const bulkColumns = [{\n name: 'HDate',\n type: 'datetime'\n }, {\n name: 'HSourceCode',\n type: 'varchar(50)'\n }, {\n name: 'HTechParamID',\n type: 'int'\n }, {\n name: 'HTechParamName',\n type: 'varchar(500)'\n }, {\n name: 'HCount',\n type: 'decimal(18,2)'\n }, {\n name: 'HCreateTime',\n type: 'datetime'\n }, {\n name: 'HResult',\n type: 'varchar(50)'\n }, {\n name: 'HProcNumber',\n type: 'varchar(50)'\n }, {\n name: 'HFlag',\n type: 'bit'\n }].map(column => ({\n ...column,\n options: {\n nullable: false\n }\n }));\n flow.set('sync_rows', bufferRows.slice(selectedRows.length));\n flow.set('sync_inflight', true);\n msg.retryBuf = selectedRecords;\n msg.bulkColumns = bulkColumns;\n msg.rows = selectedRecords.map(record => bulkColumns.map(column => record[column.name]));\n msg.queryParams = bulkColumns.map(column => ({\n ...column\n }));\n msg.query = 'dbo.Sb_EquipMentCollectionTechParam_Temp';\n msg.queryMode = 'bulk';\n msg.syncWrittenRows = selectedRecords;\n msg.syncSkippedRows = [];\n msg.payload = {\n table: msg.query,\n rows: selectedRecords.length\n };\n return msg;\n}\nreturn flushCollectionBuffer(msg, flow, global, node);\n",
"outputs": 1,
@@ -287,14 +287,14 @@
"y": 500,
"wires": [
[
- "sync_bulk_prepare"
+ "03d29299a23f920e"
]
]
},
{
- "id": "fn_sync_retry",
+ "id": "30385c6e9458d04c",
"type": "function",
- "z": "cee834492540f06e",
+ "z": "e50e36e69b1c47f6",
"name": "澶辫触鍥炲~缂撳啿",
"func": "/**\n * 澶辫触鍘熸壒鍥炲~\n * 杈撳叆锛氬け璐ヨ姹傦紝msg.retryBuf鍜宮sg.error\n * 杈撳嚭锛氳緭鍑�1=閿欒鎽樿锛涜緭鍑�2=鐢ㄥ弸閲嶈瘯閫氱煡\n * 涓婁笅鏂囷細sync_rows锛泂ync_inflight\n */\nfunction requeueFailedBulk(msg, flow, global, node) {\n const retryRecords = Array.isArray(msg.retryBuf) ? msg.retryBuf : [];\n if (retryRecords.length) flow.set('sync_rows', retryRecords.concat(flow.get('sync_rows') || []));\n flow.set('sync_inflight', false);\n const errorMessage = typeof msg.error === 'string' ? msg.error : msg.error?.details || msg.error?.message || 'Bulk鎴栭槻閲嶉鏌ュけ璐�';\n const pendingBatches = flow.get('sync_yy_batches') || {};\n const affectedBatchIds = new Set(retryRecords.flatMap(row => row._sync?.yyBatchIds || []));\n const acknowledgements = Array.from(affectedBatchIds).filter(batchId => pendingBatches[batchId]).map(batchId => ({\n yySync: pendingBatches[batchId].meta,\n yyAck: {\n kind: 'retrying',\n reason: errorMessage\n }\n }));\n node.status({\n fill: 'red',\n shape: 'ring',\n text: '澶辫触鍥炲~ ' + retryRecords.length + ' 琛岋紝姘翠綅鏈帹杩�'\n });\n return [{\n payload: {\n error: errorMessage,\n requeued: retryRecords.length\n }\n }, acknowledgements];\n}\nreturn requeueFailedBulk(msg, flow, global, node);\n",
"outputs": 2,
@@ -307,17 +307,17 @@
"y": 560,
"wires": [
[
- "sync_err_dbg"
+ "c76fc1bf5ff15ce0"
],
[
- "yy_ack_out"
+ "8cd53de2a6cf935d"
]
]
},
{
- "id": "sync_flush",
+ "id": "d545f7671093bcb3",
"type": "inject",
- "z": "cee834492540f06e",
+ "z": "e50e36e69b1c47f6",
"name": "姣� 5s 鎵归噺鍏ュ簱",
"props": [],
"repeat": "5",
@@ -331,14 +331,14 @@
"y": 500,
"wires": [
[
- "fn_sync_flush"
+ "1450efa6b7c145ae"
]
]
},
{
- "id": "sync_out_dbg",
+ "id": "7a0f60ce7357e856",
"type": "debug",
- "z": "cee834492540f06e",
+ "z": "e50e36e69b1c47f6",
"name": "鍏ュ簱缁撴灉",
"active": false,
"tosidebar": true,
@@ -353,29 +353,29 @@
"wires": []
},
{
- "id": "sync_catch",
+ "id": "7dfce956c77625fd",
"type": "catch",
- "z": "cee834492540f06e",
+ "z": "e50e36e69b1c47f6",
"name": "鍚屾寮傚父",
"scope": [
- "fe88ac9fe19141be",
- "yy_idempotent_write",
- "sync_bulk_prepare",
- "sync_bulk_filter"
+ "2b7f27474a8814a8",
+ "09a91e72d23014a0",
+ "03d29299a23f920e",
+ "12d35b8de66d86c6"
],
"uncaught": false,
"x": 100,
"y": 560,
"wires": [
[
- "fn_sync_retry"
+ "30385c6e9458d04c"
]
]
},
{
- "id": "sync_err_dbg",
+ "id": "c76fc1bf5ff15ce0",
"type": "debug",
- "z": "cee834492540f06e",
+ "z": "e50e36e69b1c47f6",
"name": "寮傚父璇︽儏",
"active": true,
"tosidebar": true,
@@ -390,9 +390,9 @@
"wires": []
},
{
- "id": "fn_reset_wm",
+ "id": "c289168baec932e2",
"type": "function",
- "z": "cee834492540f06e",
+ "z": "e50e36e69b1c47f6",
"name": "閲嶇疆姘翠綅 鈫� 褰撳墠鏃跺埢",
"func": "/**\n * 璁剧疆鍥炶ˉ璧风偣\n * 杈撳叆锛歱ayload=澶╂暟/鏃ユ湡/绌篭n * 杈撳嚭锛氳緭鍑�1=缁存姢鏃ュ織锛涜緭鍑�2=鐢ㄥ弸鍥炶ˉ鎺у埗\n * 涓婁笅鏂囷細鏃ф按浣嶅吋瀹归敭锛汳QTT鍙樺寲缂撳瓨\n */\nfunction localTime(date) {\n const d = new Date(date);\n if (!Number.isFinite(d.getTime())) return null;\n const p = n => String(n).padStart(2, '0');\n return d.getFullYear() + '-' + p(d.getMonth() + 1) + '-' + p(d.getDate()) + ' ' + p(d.getHours()) + ':' + p(d.getMinutes()) + ':' + p(d.getSeconds()) + '.' + String(d.getMilliseconds()).padStart(3, '0');\n}\nfunction resetCollectionWatermark(msg, flow, global, node) {\n const input = msg.payload;\n let fromTime = localTime(new Date()).slice(0, 19);\n let description = '褰撳墠鏃跺埢';\n const numericDays = typeof input === 'number' || typeof input === 'string' && /^\\d+$/.test(input.trim());\n if (numericDays && Number.isFinite(Number(input))) {\n fromTime = localTime(new Date(Date.now() - Number(input) * 86400000)).slice(0, 19);\n description = '鍥炶ˉ ' + Number(input) + ' 澶�';\n } else if (typeof input === 'string' && /^\\d{4}-\\d{2}-\\d{2}/.test(input.trim())) {\n fromTime = input.trim();\n description = '鎸囧畾 ' + fromTime;\n }\n flow.set('wy_wm', fromTime);\n flow.set('yy_wm', fromTime);\n flow.set('wy_seen', {});\n flow.set('mqtt_seen', {});\n flow.set('mqtt_seen_n', 0);\n msg.payload = '姘翠綅 鈫� ' + fromTime + '锛�' + description + '锛�';\n return [msg, {\n yyControl: {\n from: fromTime\n }\n }];\n}\nreturn resetCollectionWatermark(msg, flow, global, node);\n",
"outputs": 2,
@@ -405,17 +405,17 @@
"y": 700,
"wires": [
[
- "reset_dbg"
+ "1f2f4c596aad4e94"
],
[
- "yy_control_out"
+ "2d3cdf62e602bda6"
]
]
},
{
- "id": "reset_btn",
+ "id": "bc5618933ba294ad",
"type": "inject",
- "z": "cee834492540f06e",
+ "z": "e50e36e69b1c47f6",
"name": "閲嶇疆姘翠綅锛堢淮鎶わ級",
"props": [],
"repeat": "",
@@ -427,14 +427,14 @@
"y": 700,
"wires": [
[
- "fn_reset_wm"
+ "c289168baec932e2"
]
]
},
{
- "id": "reset_dbg",
+ "id": "1f2f4c596aad4e94",
"type": "debug",
- "z": "cee834492540f06e",
+ "z": "e50e36e69b1c47f6",
"name": "姘翠綅鏃ュ織",
"active": false,
"tosidebar": true,
@@ -449,9 +449,9 @@
"wires": []
},
{
- "id": "bf10",
+ "id": "6031ab273e42cfee",
"type": "inject",
- "z": "cee834492540f06e",
+ "z": "e50e36e69b1c47f6",
"name": "鍥炶ˉ鏈�杩� 10 澶�",
"props": [
{
@@ -471,14 +471,14 @@
"y": 780,
"wires": [
[
- "fn_reset_wm"
+ "c289168baec932e2"
]
]
},
{
- "id": "bf30",
+ "id": "39a5a2ba53fbb058",
"type": "inject",
- "z": "cee834492540f06e",
+ "z": "e50e36e69b1c47f6",
"name": "鍥炶ˉ鏈�杩� 30 澶�",
"props": [
{
@@ -498,14 +498,14 @@
"y": 860,
"wires": [
[
- "fn_reset_wm"
+ "c289168baec932e2"
]
]
},
{
- "id": "fn_sync_success",
+ "id": "c62baf870846ef7b",
"type": "function",
- "z": "cee834492540f06e",
+ "z": "e50e36e69b1c47f6",
"name": "鍐欏簱鎴愬姛 鈫� 纭鎵规",
"func": "/**\n * Bulk鎴愬姛鍙婃壒娆$‘璁n * 杈撳叆锛歳etryBuf锛泂yncWrittenRows锛泂yncSkippedRows\n * 杈撳嚭锛氳緭鍑�1=鍐欏簱缁熻锛涜緭鍑�2=鏁存壒瀹屾垚鍥炴墽\n * 涓婁笅鏂囷細sync_inflight锛泂ync_yy_batches锛泂ync_written\n */\nfunction collectionRowKey(row) {\n // 淇濈暀鍘熸湁鑷劧閿紪鐮侊紝鍏煎鏃у緟纭鎵规鐨� doneKeys銆俓n return row.HProcNumber + '|' + row.HSourceCode + '|' + row.HTechParamName + '|' + new Date(row.HDate).getTime();\n}\nfunction confirmBulkSuccess(msg, flow, global, node) {\n flow.set('sync_inflight', false);\n const originalRecords = Array.isArray(msg.retryBuf) ? msg.retryBuf : [];\n const writtenRecords = Array.isArray(msg.syncWrittenRows) ? msg.syncWrittenRows : originalRecords;\n const skippedRecords = Array.isArray(msg.syncSkippedRows) ? msg.syncSkippedRows : [];\n const skippedKeys = new Set(skippedRecords.map(collectionRowKey));\n const pendingBatches = flow.get('sync_yy_batches') || {};\n const completedBatches = flow.get('sync_yy_completed') || {};\n const acknowledgements = [];\n\n // 涓�涓狟ulk鍙互鍖呭惈澶氫釜婧愭壒娆★紝涔熷彲浠ュ彧鏄竴涓簮鎵规鐨勪竴閮ㄥ垎銆俓n for (const record of originalRecords) {\n const rowKey = collectionRowKey(record);\n for (const batchId of new Set(record._sync?.yyBatchIds || [])) {\n const batch = pendingBatches[batchId];\n if (!batch || batch.doneKeys[rowKey]) continue;\n batch.doneKeys[rowKey] = true;\n batch.done += 1;\n if (skippedKeys.has(rowKey)) batch.skipped += 1;else batch.inserted += 1;\n }\n }\n for (const [batchId, batch] of Object.entries(pendingBatches)) {\n if (batch.done < batch.expected) continue;\n const ack = {\n yySync: batch.meta,\n yyAck: {\n kind: 'committed',\n expected: batch.expected,\n inserted: batch.inserted,\n skipped: batch.skipped\n },\n payload: {\n stream: batch.meta.stream,\n inserted: batch.inserted,\n skipped: batch.skipped\n }\n };\n acknowledgements.push(ack);\n completedBatches[batchId] = ack;\n delete pendingBatches[batchId];\n }\n const completedIds = Object.keys(completedBatches);\n for (const batchId of completedIds.slice(0, Math.max(0, completedIds.length - 256))) delete completedBatches[batchId];\n flow.set('sync_yy_batches', pendingBatches);\n flow.set('sync_yy_completed', completedBatches);\n const totalWritten = (flow.get('sync_written') || 0) + writtenRecords.length;\n flow.set('sync_written', totalWritten);\n flow.set('sync_last_success', new Date().toISOString());\n node.status({\n fill: 'green',\n shape: 'dot',\n text: 'Bulk鍐欏叆 ' + writtenRecords.length + ' / 宸叉湁 ' + skippedRecords.length\n });\n return [{\n payload: {\n written: writtenRecords.length,\n skipped: skippedRecords.length,\n total: totalWritten,\n pending: (flow.get('sync_rows') || []).length,\n yyPendingBatches: Object.keys(pendingBatches).length\n }\n }, acknowledgements];\n}\nreturn confirmBulkSuccess(msg, flow, global, node);\n",
"outputs": 2,
@@ -518,39 +518,39 @@
"y": 500,
"wires": [
[
- "sync_out_dbg"
+ "7a0f60ce7357e856"
],
[
- "yy_ack_out"
+ "8cd53de2a6cf935d"
]
]
},
{
- "id": "sync_source_catch",
+ "id": "36e46ebcce964603",
"type": "catch",
- "z": "cee834492540f06e",
+ "z": "e50e36e69b1c47f6",
"name": "浜旀磱瀹炴椂鏌ヨ/鏄犲皠寮傚父",
"scope": [
- "fn_wy_q",
- "4e0d058caa7afc4e",
- "c53aa63e531b7e6d"
+ "2b63186a3aacf513",
+ "8726fa75773cc322",
+ "96ed6b8768424c7c"
],
"uncaught": false,
"x": 110,
"y": 620,
"wires": [
[
- "wy_read_error"
+ "6cf8822e0943c308"
]
]
},
{
- "id": "yy_write_in",
+ "id": "f7cc1e3161399854",
"type": "link in",
- "z": "cee834492540f06e",
+ "z": "e50e36e69b1c47f6",
"name": "鐢ㄥ弸 鈫� 鍏辩敤缂撳啿",
"links": [
- "yy_data_out"
+ "a98e74f1e5a11dde"
],
"x": 645,
"y": 380,
@@ -559,9 +559,9 @@
]
},
{
- "id": "yy_idempotent_write",
+ "id": "09a91e72d23014a0",
"type": "MSSQL",
- "z": "cee834492540f06e",
+ "z": "e50e36e69b1c47f6",
"mssqlCN": "9bb47eb9867c4772",
"name": "鐢ㄥ弸 路 Bulk鍓嶉泦鍚堥槻閲嶉鏌�",
"outField": "payload",
@@ -582,40 +582,40 @@
"y": 720,
"wires": [
[
- "sync_bulk_filter"
+ "12d35b8de66d86c6"
]
]
},
{
- "id": "yy_ack_out",
+ "id": "8cd53de2a6cf935d",
"type": "link out",
- "z": "cee834492540f06e",
+ "z": "e50e36e69b1c47f6",
"name": "缂撳啿/Bulk鍥炴墽 鈫� 鐢ㄥ弸姘翠綅",
"mode": "link",
"links": [
- "yy_ack_in"
+ "36e0130220d85ae0"
],
"x": 1575,
"y": 600,
"wires": []
},
{
- "id": "yy_control_out",
+ "id": "2d3cdf62e602bda6",
"type": "link out",
- "z": "cee834492540f06e",
+ "z": "e50e36e69b1c47f6",
"name": "鈫� 鎮犳壃鍥炶ˉ璧风偣鎺у埗",
"mode": "link",
"links": [
- "yy_control_in"
+ "aafd6d7e2e7385f5"
],
"x": 585,
"y": 740,
"wires": []
},
{
- "id": "wy_read_error",
+ "id": "6cf8822e0943c308",
"type": "function",
- "z": "cee834492540f06e",
+ "z": "e50e36e69b1c47f6",
"name": "浜旀磱 路 瑙i櫎鏌ヨ閿�/涓嬬閲嶈瘯",
"func": "/**\n * 浜旀磱鏌ヨ閿欒鎭㈠\n * 杈撳叆锛歮sg.error\n * 杈撳嚭锛氶敊璇憳瑕侊紝涓嬬鍙噸璇昞n * 涓婁笅鏂囷細wy_poll_inflight锛泈y_last_read_error\n */\nfunction handleWuyangReadError(msg, flow, global, node) {\n flow.set('wy_poll_inflight', false);\n const errorMessage = typeof msg.error === 'string' ? msg.error : msg.error?.message || '浜旀磱鏌ヨ澶辫触';\n flow.set('wy_last_read_error', {\n time: new Date().toISOString(),\n error: errorMessage\n });\n node.status({\n fill: 'red',\n shape: 'ring',\n text: '鏌ヨ澶辫触锛屼笅绉掗噸璇�'\n });\n msg.payload = {\n source: 'WY',\n error: errorMessage\n };\n return msg;\n}\nreturn handleWuyangReadError(msg, flow, global, node);\n",
"outputs": 1,
@@ -628,14 +628,14 @@
"y": 620,
"wires": [
[
- "sync_err_dbg"
+ "c76fc1bf5ff15ce0"
]
]
},
{
- "id": "collection_control",
+ "id": "a8dc3547b310431f",
"type": "function",
- "z": "cee834492540f06e",
+ "z": "e50e36e69b1c47f6",
"name": "閲囬泦鎬诲紑鍏� 路 鏆傚仠/鎭㈠",
"func": "/**\n * 閲囬泦鏆傚仠/鎭㈠\n * 杈撳叆锛歱ayload=true鏆傚仠锛沠alse鎭㈠\n * 杈撳嚭锛氳緭鍑�1=鐘舵�侊紱杈撳嚭2=鎭㈠鏃惰Е鍙戦噰闆�/鍐欏簱\n * 涓婁笅鏂囷細global.collection_paused锛汳QTT鍙樺寲缂撳瓨\n */\nfunction controlCollection(msg, flow, global, node) {\n if (typeof msg.payload !== 'boolean') {\n node.error('閲囬泦寮�鍏冲弬鏁板繀椤绘槸 true锛堟殏鍋滐級鎴� false锛堟仮澶嶏級', msg);\n return null;\n }\n const paused = msg.payload;\n global.set('collection_paused', paused);\n global.set('collection_control_state', {\n paused,\n changedAt: new Date().toISOString()\n });\n if (!paused) {\n flow.set('mqtt_seen', {});\n flow.set('mqtt_seen_n', 0);\n }\n node.status({\n fill: paused ? 'yellow' : 'green',\n shape: paused ? 'ring' : 'dot',\n text: paused ? '宸叉殏鍋滈噰闆嗗拰鍐欏簱' : '姝e湪閲囬泦鍜屽啓搴�'\n });\n msg.payload = {\n paused,\n message: paused ? '宸叉殏鍋滄柊閲囬泦鍜屽悗缁啓搴擄紱宸叉彁浜ょ殑鏁版嵁搴撹姹備細瀹屾垚锛岀紦鍐蹭繚鐣�' : '宸叉仮澶嶉噰闆嗗拰鍐欏簱',\n buffered: (flow.get('sync_rows') || []).length\n };\n return [msg, paused ? null : {}];\n}\nreturn controlCollection(msg, flow, global, node);\n",
"outputs": 2,
@@ -648,18 +648,18 @@
"y": 60,
"wires": [
[
- "collection_control_debug"
+ "b3f7a825284446f2"
],
[
- "fn_sync_flush",
- "fn_wy_q"
+ "1450efa6b7c145ae",
+ "2b63186a3aacf513"
]
]
},
{
- "id": "collection_pause",
+ "id": "287fedb2a5998ab2",
"type": "inject",
- "z": "cee834492540f06e",
+ "z": "e50e36e69b1c47f6",
"name": "鈴� 鏆傚仠鍏ㄩ儴閲囬泦/鍐欏簱",
"props": [
{
@@ -677,14 +677,14 @@
"y": 60,
"wires": [
[
- "collection_control"
+ "a8dc3547b310431f"
]
]
},
{
- "id": "collection_resume",
+ "id": "7daa53df81cf8dec",
"type": "inject",
- "z": "cee834492540f06e",
+ "z": "e50e36e69b1c47f6",
"name": "鈻� 鎭㈠鍏ㄩ儴閲囬泦/鍐欏簱",
"props": [
{
@@ -702,14 +702,14 @@
"y": 110,
"wires": [
[
- "collection_control"
+ "a8dc3547b310431f"
]
]
},
{
- "id": "collection_control_debug",
+ "id": "b3f7a825284446f2",
"type": "debug",
- "z": "cee834492540f06e",
+ "z": "e50e36e69b1c47f6",
"name": "閲囬泦鎬诲紑鍏崇姸鎬�",
"active": false,
"tosidebar": true,
@@ -722,36 +722,36 @@
"wires": []
},
{
- "id": "collection_pause_note",
+ "id": "b9ee4efccee8e5ef",
"type": "comment",
- "z": "cee834492540f06e",
- "name": "鎬诲紑鍏虫帶鍒朵簲娲嬨�佺敤鍙嬨�丮QTT閲囬泦鍜屽悗缁啓搴擄紱鍚姩榛樿鏆傚仠锛岀紦鍐蹭繚鐣�",
+ "z": "e50e36e69b1c47f6",
+ "name": "鎬诲紑鍏虫帶鍒朵簲娲嬨�佹偁鎵�丮QTT閲囬泦鍜屽悗缁啓搴擄紱鍚姩榛樿鏆傚仠锛岀紦鍐蹭繚鐣�",
"info": "鐐瑰嚮宸︿晶娉ㄥ叆鎸夐挳鏆傚仠/鎭㈠銆備笉娓呯┖缂撳啿锛屼笉涓㈠純鎮犳壃寰呯‘璁ゆ壒娆★紱宸叉彁浜ょ殑鏁版嵁搴撹姹傚厑璁稿畬鎴愩�侻QTT杩炴帴鍜屼笟鍔$‘璁ゅ洖鎵х户缁搷搴旓紝閲囬泦鏁版嵁鍦ㄦ殏鍋滄湡闂翠笉鍏ョ紦鍐层�佷笉鍐欏簱銆�",
"x": 300,
"y": 20,
"wires": []
},
{
- "id": "collection_control_link_in",
+ "id": "603d604846aecbe1",
"type": "link in",
- "z": "cee834492540f06e",
+ "z": "e50e36e69b1c47f6",
"name": "鈫� 鍏朵粬椤电閲囬泦鎬诲紑鍏�",
"links": [
- "collection_yy_control_out",
- "collection_mqtt_control_out"
+ "79639b13a1a5d1f8",
+ "82a08ca67d2a3afb"
],
"x": 255,
"y": 160,
"wires": [
[
- "collection_control"
+ "a8dc3547b310431f"
]
]
},
{
- "id": "fn_clear_buffer",
+ "id": "345f785e9993e91a",
"type": "function",
- "z": "cee834492540f06e",
+ "z": "e50e36e69b1c47f6",
"name": "鈿狅笍 寮哄埗娓呯┖澶辫触缂撳啿",
"func": "/**\n * 浜哄伐娓呯┖缂撳啿\n * 杈撳叆锛氭墜鍔ㄨЕ鍙慭n * 杈撳嚭锛氭竻鐞嗙粨鏋滐紱瀛樺湪鍦ㄩ��/鐢ㄥ弸鎵规鏃舵嫆缁漒n * 涓婁笅鏂囷細sync_rows锛泂ync_inflight锛涚淮鎶ゆ棩蹇梊n */\nfunction canMaintainBuffer(flow) {\n return !flow.get('sync_inflight') && Object.keys(flow.get('sync_yy_batches') || {}).length === 0;\n}\nfunction clearCollectionBuffer(msg, flow, global, node) {\n if (!canMaintainBuffer(flow)) {\n msg.payload = {\n action: 'blocked',\n reason: '瀛樺湪Bulk鍦ㄩ�旇姹傛垨鐢ㄥ弸寰呯‘璁ゆ壒娆★紝鏆備笉娓呯悊'\n };\n node.status({\n fill: 'yellow',\n shape: 'ring',\n text: '鏈竻鐞嗭細鍦ㄩ��/鐢ㄥ弸寰呯‘璁�'\n });\n return msg;\n }\n const clearedCount = (flow.get('sync_rows') || []).length;\n flow.set('sync_rows', []);\n flow.set('sync_inflight', false);\n flow.set('wy_poll_inflight', false);\n const result = {\n cleared: clearedCount,\n clearedAt: new Date().toISOString(),\n reason: '鎵嬪姩娓呯┖澶辫触缂撳啿'\n };\n flow.set('buffer_emergency_clear', result);\n msg.payload = result;\n node.status({\n fill: 'orange',\n shape: 'ring',\n text: '宸叉竻绌� ' + clearedCount + ' 琛岀紦鍐�'\n });\n return msg;\n}\nreturn clearCollectionBuffer(msg, flow, global, node);\n",
"outputs": 1,
@@ -764,14 +764,14 @@
"y": 940,
"wires": [
[
- "buffer_control_debug"
+ "9c158719f489c6e7"
]
]
},
{
- "id": "fn_view_buffer",
+ "id": "f4f14575035a0432",
"type": "function",
- "z": "cee834492540f06e",
+ "z": "e50e36e69b1c47f6",
"name": "鏌ョ湅褰撳墠缂撳啿鐘舵��",
"func": "/**\n * 鏌ョ湅缂撳啿\n * 杈撳叆锛氭墜鍔ㄨЕ鍙慭n * 杈撳嚭锛氬畬鏁存潵婧愮粺璁°�佹暟鎹簱瀛楁棰勮銆佺敤鍙嬬‘璁よ繘搴n * 涓婁笅鏂囷細鍙sync_rows鍙婄浉鍏崇粺璁n */\nfunction convertLegacyBufferRow(row, createdAt) {\n if (row.HDate !== undefined && row.HSourceCode !== undefined) {\n // 宸叉槸鏂版牸寮忥細淇濈暀鏃㈡湁瀛楁鍜屾壒娆″紩鐢紝鍙仮澶� Date 绫诲瀷銆俓n return {\n ...row,\n HDate: new Date(row.HDate),\n HCreateTime: row.HCreateTime ? new Date(row.HCreateTime) : new Date(createdAt)\n };\n }\n // 閮ㄧ讲鍏煎锛氭棫 sync_rows 浣跨敤 s/d/p/v/t锛屽師鎵硅涔夊強鍘熷弬鏁板悕淇濇寔涓嶅彉銆俓n const converted = {\n HItemID: null,\n HDate: new Date(row.t),\n HSourceCode: row.d,\n HTechParamID: 0,\n HTechParamName: row.p,\n HCount: row.v,\n HCreateTime: new Date(createdAt),\n HResult: String(row.v).slice(0, 50),\n HProcNumber: row.s,\n HFlag: 0\n };\n if (row.yyRefs?.length) converted._sync = {\n yyBatchIds: [...row.yyRefs]\n };\n return converted;\n}\nfunction viewCollectionBuffer(msg, flow, global, node) {\n const bufferRows = flow.get('sync_rows') || [];\n const sourceCounts = {};\n const deviceCodes = new Set();\n let oldestTimestamp = null;\n let newestTimestamp = null;\n for (const input of bufferRows) {\n const row = convertLegacyBufferRow(input, new Date());\n const source = row.HProcNumber || 'UNKNOWN';\n sourceCounts[source] = (sourceCounts[source] || 0) + 1;\n if (row.HSourceCode) deviceCodes.add(row.HSourceCode);\n const timestamp = row.HDate.getTime();\n if (!Number.isFinite(timestamp)) continue;\n if (oldestTimestamp === null || timestamp < oldestTimestamp) oldestTimestamp = timestamp;\n if (newestTimestamp === null || timestamp > newestTimestamp) newestTimestamp = timestamp;\n }\n const preview = bufferRows.slice(0, 3).map(input => {\n const {\n _sync,\n ...databaseFields\n } = convertLegacyBufferRow(input, new Date());\n return databaseFields;\n });\n msg.payload = {\n bufferSize: bufferRows.length,\n inflight: Boolean(flow.get('sync_inflight')),\n wyPolling: Boolean(flow.get('wy_poll_inflight')),\n paused: global.get('collection_paused') !== false,\n totalWritten: flow.get('sync_written') || 0,\n lastSuccess: flow.get('sync_last_success'),\n sources: sourceCounts,\n uniqueDevices: deviceCodes.size,\n oldestData: oldestTimestamp === null ? null : new Date(oldestTimestamp).toISOString(),\n newestData: newestTimestamp === null ? null : new Date(newestTimestamp).toISOString(),\n records: preview,\n youyangPendingBatches: Object.values(flow.get('sync_yy_batches') || {}).map(batch => ({\n stream: batch.meta.stream,\n expected: batch.expected,\n confirmed: batch.done,\n inserted: batch.inserted,\n skipped: batch.skipped,\n queuedAt: batch.queuedAt\n })),\n timestamp: new Date().toISOString()\n };\n node.status({\n fill: bufferRows.length >= 20000 ? 'red' : 'blue',\n shape: 'dot',\n text: bufferRows.length + ' 琛�'\n });\n return msg;\n}\nreturn viewCollectionBuffer(msg, flow, global, node);\n",
"outputs": 1,
@@ -784,14 +784,14 @@
"y": 1020,
"wires": [
[
- "buffer_control_debug"
+ "9c158719f489c6e7"
]
]
},
{
- "id": "fn_trim_buffer",
+ "id": "1834604fa31e6c43",
"type": "function",
- "z": "cee834492540f06e",
+ "z": "e50e36e69b1c47f6",
"name": "淇濈暀鏈�鏂� 5000 鏉�",
"func": "/**\n * 浜哄伐瑁佸壀缂撳啿\n * 杈撳叆锛氭墜鍔ㄨЕ鍙慭n * 杈撳嚭锛氭寜HDate淇濈暀鏈�鏂�5000琛岋紱鏈畬鎴愭壒娆℃湡闂存嫆缁漒n * 涓婁笅鏂囷細sync_rows锛沚uffer_trim_history\n */\nfunction canMaintainBuffer(flow) {\n return !flow.get('sync_inflight') && Object.keys(flow.get('sync_yy_batches') || {}).length === 0;\n}\nfunction trimCollectionBuffer(msg, flow, global, node) {\n if (!canMaintainBuffer(flow)) {\n msg.payload = {\n action: 'blocked',\n reason: '瀛樺湪Bulk鍦ㄩ�旇姹傛垨鐢ㄥ弸寰呯‘璁ゆ壒娆★紝鏆備笉瑁佸壀'\n };\n node.status({\n fill: 'yellow',\n shape: 'ring',\n text: '鏈竻鐞嗭細鍦ㄩ��/鐢ㄥ弸寰呯‘璁�'\n });\n return msg;\n }\n const bufferRows = flow.get('sync_rows') || [];\n const keepCount = 5000;\n if (bufferRows.length <= keepCount) {\n msg.payload = {\n action: 'skip',\n current: bufferRows.length,\n message: '缂撳啿鏈秴杩囬檺鍒�'\n };\n node.status({\n fill: 'green',\n shape: 'dot',\n text: '缂撳啿姝e父锛屾棤闇�瑁佸壀'\n });\n return msg;\n }\n const timestampOf = row => new Date(row.HDate !== undefined ? row.HDate : row.t).getTime();\n const keptRows = [...bufferRows].sort((left, right) => timestampOf(right) - timestampOf(left)).slice(0, keepCount);\n flow.set('sync_rows', keptRows);\n const result = {\n action: 'trim',\n before: bufferRows.length,\n kept: keptRows.length,\n dropped: bufferRows.length - keptRows.length,\n trimmedAt: new Date().toISOString()\n };\n flow.set('buffer_trim_history', result);\n msg.payload = result;\n node.status({\n fill: 'yellow',\n shape: 'dot',\n text: '淇濈暀 ' + result.kept + ' / 涓㈠純 ' + result.dropped\n });\n return msg;\n}\nreturn trimCollectionBuffer(msg, flow, global, node);\n",
"outputs": 1,
@@ -804,14 +804,14 @@
"y": 1100,
"wires": [
[
- "buffer_control_debug"
+ "9c158719f489c6e7"
]
]
},
{
- "id": "btn_clear_buffer",
+ "id": "7b54b693a26ac372",
"type": "inject",
- "z": "cee834492540f06e",
+ "z": "e50e36e69b1c47f6",
"name": "馃毃 绱ф�ユ竻绌虹紦鍐�",
"props": [],
"repeat": "",
@@ -823,14 +823,14 @@
"y": 940,
"wires": [
[
- "fn_clear_buffer"
+ "345f785e9993e91a"
]
]
},
{
- "id": "btn_view_buffer",
+ "id": "b480a22a8044968e",
"type": "inject",
- "z": "cee834492540f06e",
+ "z": "e50e36e69b1c47f6",
"name": "馃搳 鏌ョ湅缂撳啿鐘舵��",
"props": [],
"repeat": "",
@@ -842,14 +842,14 @@
"y": 1020,
"wires": [
[
- "fn_view_buffer"
+ "f4f14575035a0432"
]
]
},
{
- "id": "btn_trim_buffer",
+ "id": "469292a0bc0bcb14",
"type": "inject",
- "z": "cee834492540f06e",
+ "z": "e50e36e69b1c47f6",
"name": "鉁傦笍 瑁佸壀缂撳啿",
"props": [],
"repeat": "",
@@ -861,14 +861,14 @@
"y": 1100,
"wires": [
[
- "fn_trim_buffer"
+ "1834604fa31e6c43"
]
]
},
{
- "id": "buffer_control_debug",
+ "id": "9c158719f489c6e7",
"type": "debug",
- "z": "cee834492540f06e",
+ "z": "e50e36e69b1c47f6",
"name": "缂撳啿鎺у埗鏃ュ織",
"active": false,
"tosidebar": true,
@@ -883,9 +883,9 @@
"wires": []
},
{
- "id": "buffer_control_note",
+ "id": "5d1b40816d7e2910",
"type": "comment",
- "z": "cee834492540f06e",
+ "z": "e50e36e69b1c47f6",
"name": "缂撳啿缁存姢锛氬湪閫�/Bulk寰呯‘璁ゆ湡闂寸姝㈡竻绌哄拰瑁佸壀",
"info": "褰撳啓搴撴寔缁け璐ュ鑷寸紦鍐插爢绉椂浣跨敤杩欎簺鎺у埗锛歕n1. 馃搳 鏌ョ湅缂撳啿鐘舵�� - 浜嗚В褰撳墠缂撳啿澶у皬銆佹暟鎹潵婧愬垎甯僜n2. 鉁傦笍 瑁佸壀缂撳啿 - 淇濈暀鏈�鏂�5000鏉★紝涓㈠純鏃ф暟鎹紙鎺ㄨ崘锛塡n3. 馃毃 绱ф�ユ竻绌虹紦鍐� - 瀹屽叏娓呯┖缂撳啿闃熷垪锛堟厧鐢紝浼氫涪澶辨墍鏈夊緟鍐欏叆鏁版嵁锛塡n\n浣跨敤鍦烘櫙锛歕n- 缂撳啿瓒呰繃 20000 鏉″鑷存柊鏁版嵁鏃犳硶杩涘叆\n- 鏁版嵁搴撹繛鎺ラ暱鏈熷紓甯搁渶瑕佹竻鐞嗙Н鍘媆n- 娴嬭瘯鐜闇�瑕侀噸缃姸鎬乗n2026-10-25锛氬瓨鍦˙ulk鍦ㄩ�旇姹傛垨鐢ㄥ弸寰呯‘璁ゆ壒娆℃椂锛屾竻绌�/瑁佸壀鑷姩鎷掔粷锛岄槻姝涪澶卞緟纭琛屻�傚厛鎭㈠鍐欏簱璁╂壒娆″畬鎴愶紝鍐嶆墽琛岀淮鎶ゃ��",
"x": 220,
@@ -893,9 +893,9 @@
"wires": []
},
{
- "id": "sync_bulk_prepare",
+ "id": "03d29299a23f920e",
"type": "function",
- "z": "cee834492540f06e",
+ "z": "e50e36e69b1c47f6",
"name": "Bulk鍒嗘祦 路 鐢ㄥ弸闆嗗悎闃查噸",
"func": "/**\n * Bulk鍓嶉泦鍚堥槻閲嶅垎娴乗n * 杈撳叆锛歮sg.retryBuf=鏁版嵁搴撹\n * 杈撳嚭锛氳緭鍑�1=鐩存帴Bulk锛涜緭鍑�2=鐢ㄥ弸闃查噸SELECT璇锋眰\n * 涓婁笅鏂囷細鏃犳柊澧炵姸鎬侊紱鏈�澶�1900涓猄QL鍙傛暟\n */\nfunction canonicalParameterName(parameterName) {\n const aliases = {\n '杞��': '鏈哄櫒杞��',\n '鐝骞冲潎杞﹂��': '鐝骞冲潎杞��',\n '鏈彮浜ч噺': '鐝浜ч噺(婧愬崟浣�)',\n '鏈彮鏁堢巼': '鐝鏁堢巼(%)',\n '鏈彮鍋滄満娆℃暟': '鐝鍋滄満娆℃暟',\n '鏈彮鍋滄満鏃堕棿(绉�)': '鐝鍋滄満鏃堕棿(绉�)',\n '鏈尮浜ч噺': '鏈尮浜ч噺(婧愬崟浣�)'\n };\n const name = String(parameterName);\n // 鐢ㄥ弸浜嬩欢閲岀殑鏈彮浜ч噺闄勬湁瀹為檯鍗曚綅锛屾部鐢ㄥ悓涓�鐝浜ч噺鍚嶇О銆俓n const withUnit = /^鏈彮浜ч噺\\((.+)\\)$/.exec(name);\n if (withUnit) return '鐝浜ч噺(' + withUnit[1] + ')';\n return aliases[name] || name;\n}\nfunction equivalentParameterNames(parameterName) {\n const canonicalName = canonicalParameterName(parameterName);\n const historicalNames = ['杞��', '鐝骞冲潎杞﹂��', '鏈彮浜ч噺', '鏈彮鏁堢巼', '鏈彮鍋滄満娆℃暟', '鏈彮鍋滄満鏃堕棿(绉�)', '鏈尮浜ч噺'];\n const names = new Set([parameterName, canonicalName]);\n for (const historicalName of historicalNames) {\n if (canonicalParameterName(historicalName) === canonicalName) names.add(historicalName);\n }\n const withUnit = /^鐝浜ч噺\\((.+)\\)$/.exec(canonicalName);\n if (withUnit) names.add('鏈彮浜ч噺(' + withUnit[1] + ')');\n return Array.from(names);\n}\nfunction prepareYouyangDuplicateCheck(msg, flow, global, node) {\n const youyangRows = (msg.retryBuf || []).filter(row => row.HProcNumber === 'YY');\n if (!youyangRows.length) return [msg, null];\n\n // 鎸夋簮鎵规鏀剁獎鏃堕棿銆佽澶囧拰鍙傛暟鑼冨洿锛屼竴娆℃煡璇㈡暣涓狟ulk鎵规銆俓n const groupsByBatch = new Map();\n for (const row of youyangRows) {\n const batchId = row._sync?.yyBatchIds?.[0] || 'untracked';\n const timestamp = new Date(row.HDate).getTime();\n if (!groupsByBatch.has(batchId)) {\n groupsByBatch.set(batchId, {\n minTime: timestamp,\n maxTime: timestamp,\n devices: new Set(),\n parameters: new Set()\n });\n }\n const group = groupsByBatch.get(batchId);\n group.minTime = Math.min(group.minTime, timestamp);\n group.maxTime = Math.max(group.maxTime, timestamp);\n group.devices.add(row.HSourceCode);\n for (const name of equivalentParameterNames(row.HTechParamName)) group.parameters.add(name);\n }\n let groups = Array.from(groupsByBatch.values());\n if (groups.length > 128) {\n const times = youyangRows.map(row => new Date(row.HDate).getTime());\n groups = [{\n minTime: Math.min(...times),\n maxTime: Math.max(...times),\n devices: new Set(youyangRows.map(row => row.HSourceCode)),\n parameters: new Set(youyangRows.flatMap(row => equivalentParameterNames(row.HTechParamName)))\n }];\n }\n\n // SQL Server鏈�澶�2100涓弬鏁帮紱棰勭暀浣欓噺銆傛潯浠舵敹缂╁彧浼氬鏌ワ紝涓嶄細婕忔煡銆俓n const queryParams = [];\n const predicates = [];\n const groupBudget = Math.floor(1900 / groups.length) - 2;\n groups.forEach((group, index) => {\n const prefix = 'group' + index;\n queryParams.push({\n name: prefix + 'MinTime',\n type: 'datetime',\n value: new Date(group.minTime)\n }, {\n name: prefix + 'MaxTime',\n type: 'datetime',\n value: new Date(group.maxTime)\n });\n const filters = ['HDate >= @' + prefix + 'MinTime', 'HDate <= @' + prefix + 'MaxTime'];\n let remainingBudget = groupBudget;\n for (const filter of [{\n values: group.parameters,\n column: 'HTechParamName',\n type: 'varchar(500)'\n }, {\n values: group.devices,\n column: 'HSourceCode',\n type: 'varchar(50)'\n }]) {\n if (filter.values.size > remainingBudget) continue;\n const names = Array.from(filter.values).map((value, valueIndex) => {\n const name = prefix + filter.column + valueIndex;\n queryParams.push({\n name,\n type: filter.type,\n value\n });\n return '@' + name;\n });\n filters.push(filter.column + ' IN (' + names.join(', ') + ')');\n remainingBudget -= filter.values.size;\n }\n predicates.push('(' + filters.join(' AND ') + ')');\n });\n msg.query = `SET NOCOUNT ON;\nSELECT HDate, HSourceCode, HTechParamName\nFROM dbo.Sb_EquipMentCollectionTechParam_Temp\nWHERE HProcNumber = 'YY'\n AND (${predicates.join('\\n OR ')});`;\n msg.queryParams = queryParams;\n msg.queryMode = 'query';\n msg.payload = null;\n return [null, msg];\n}\nreturn prepareYouyangDuplicateCheck(msg, flow, global, node);\n",
"outputs": 2,
@@ -908,17 +908,17 @@
"y": 500,
"wires": [
[
- "fe88ac9fe19141be"
+ "2b7f27474a8814a8"
],
[
- "yy_idempotent_write"
+ "09a91e72d23014a0"
]
]
},
{
- "id": "sync_bulk_filter",
+ "id": "12d35b8de66d86c6",
"type": "function",
- "z": "cee834492540f06e",
+ "z": "e50e36e69b1c47f6",
"name": "宸叉湁璺宠繃 鈫� Bulk寰呭啓琛�",
"func": "/**\n * 杩囨护宸叉湁鐢ㄥ弸璁板綍\n * 杈撳叆锛歱ayload=鐩爣宸叉湁閿紱retryBuf/rows淇濈暀鍘熸壒\n * 杈撳嚭锛氳緭鍑�1=鍓╀綑琛孊ulk锛涜緭鍑�2=鍏ㄨ烦杩囩洿鎺ョ‘璁n * 涓婁笅鏂囷細涓嶄慨鏀规簮姘翠綅\n */\nfunction canonicalParameterName(parameterName) {\n const aliases = {\n '杞��': '鏈哄櫒杞��',\n '鐝骞冲潎杞﹂��': '鐝骞冲潎杞��',\n '鏈彮浜ч噺': '鐝浜ч噺(婧愬崟浣�)',\n '鏈彮鏁堢巼': '鐝鏁堢巼(%)',\n '鏈彮鍋滄満娆℃暟': '鐝鍋滄満娆℃暟',\n '鏈彮鍋滄満鏃堕棿(绉�)': '鐝鍋滄満鏃堕棿(绉�)',\n '鏈尮浜ч噺': '鏈尮浜ч噺(婧愬崟浣�)'\n };\n const name = String(parameterName);\n // 鐢ㄥ弸浜嬩欢閲岀殑鏈彮浜ч噺闄勬湁瀹為檯鍗曚綅锛屾部鐢ㄥ悓涓�鐝浜ч噺鍚嶇О銆俓n const withUnit = /^鏈彮浜ч噺\\((.+)\\)$/.exec(name);\n if (withUnit) return '鐝浜ч噺(' + withUnit[1] + ')';\n return aliases[name] || name;\n}\nfunction collectionRowKey(row) {\n // 淇濈暀鍘熸湁鑷劧閿紪鐮侊紝鍏煎鏃у緟纭鎵规鐨� doneKeys銆俓n return row.HProcNumber + '|' + row.HSourceCode + '|' + row.HTechParamName + '|' + new Date(row.HDate).getTime();\n}\nfunction canonicalRowKey(row) {\n // 闃查噸鍙瘑鍒巻鍙插悓涔夊弬鏁帮紱鍘熸壒纭浠嶄娇鐢ㄥ師閿紝閬垮厤鍗囩骇鐮村潖doneKeys銆俓n return collectionRowKey({\n ...row,\n HTechParamName: canonicalParameterName(row.HTechParamName)\n });\n}\nfunction filterExistingYouyangRows(msg, flow, global, node) {\n if (!Array.isArray(msg.retryBuf) || !Array.isArray(msg.rows) || !Array.isArray(msg.bulkColumns)) {\n node.error('Bulk棰勬煡缂哄皯鍘熸壒鏁版嵁', msg);\n return null;\n }\n const existingRows = Array.isArray(msg.payload) ? msg.payload : [];\n const existingKeys = new Set(existingRows.map(row => canonicalRowKey({\n ...row,\n HProcNumber: 'YY'\n })));\n const rowsToWrite = [];\n const writtenRecords = [];\n const skippedRecords = [];\n msg.retryBuf.forEach((record, index) => {\n if (record.HProcNumber === 'YY' && existingKeys.has(canonicalRowKey(record))) {\n skippedRecords.push(record);\n } else {\n writtenRecords.push(record);\n rowsToWrite.push(msg.rows[index]);\n }\n });\n msg.rows = rowsToWrite;\n msg.syncWrittenRows = writtenRecords;\n msg.syncSkippedRows = skippedRecords;\n // MSSQL棰勬煡浼氭敼鍙榪ueryParams鐨則ype瀵硅薄锛岄噸鏂颁娇鐢ㄥ師Bulk鍒楀畾涔夈�俓n msg.queryParams = msg.bulkColumns.map(column => ({\n ...column\n }));\n msg.query = 'dbo.Sb_EquipMentCollectionTechParam_Temp';\n msg.queryMode = 'bulk';\n msg.payload = {\n table: msg.query,\n rows: rowsToWrite.length,\n skipped: skippedRecords.length\n };\n return rowsToWrite.length ? [msg, null] : [null, msg];\n}\nreturn filterExistingYouyangRows(msg, flow, global, node);\n",
"outputs": 2,
@@ -931,33 +931,33 @@
"y": 720,
"wires": [
[
- "fe88ac9fe19141be"
+ "2b7f27474a8814a8"
],
[
- "fn_sync_success"
+ "c62baf870846ef7b"
]
]
},
{
- "id": "c06152e6ab227d0b",
+ "id": "55dfd316772445bf",
"type": "link in",
- "z": "cee834492540f06e",
+ "z": "e50e36e69b1c47f6",
"name": "link in 1",
"links": [
- "223b29559f4a36ae"
+ "bbeb11d3b16af342"
],
"x": 645,
"y": 420,
"wires": [
[
- "91f3df9e5a0d8a92"
+ "f9c96682dbcd8a7b"
]
]
},
{
- "id": "91f3df9e5a0d8a92",
+ "id": "f9c96682dbcd8a7b",
"type": "function",
- "z": "cee834492540f06e",
+ "z": "e50e36e69b1c47f6",
"name": "MQTT 路 鏍囧噯鍖栦负鏁版嵁搴撳瓧娈�",
"func": "/**\n * MQTT閲囬泦鏍囧噯鍖朶n * 杈撳叆锛歮sg.dev鎴栧師濮婮SON/Buffer\n * 杈撳嚭锛氳緭鍑�1=msg.collectionRows锛涜緭鍑�2=璇婃柇/鏆傚仠棰勮\n * 涓婁笅鏂囷細mqtt_seen锛沵qtt_seen_n锛沵qtt_adapter_stats\n */\nfunction canonicalParameterName(parameterName) {\n const aliases = {\n '杞��': '鏈哄櫒杞��',\n '鐝骞冲潎杞﹂��': '鐝骞冲潎杞��',\n '鏈彮浜ч噺': '鐝浜ч噺(婧愬崟浣�)',\n '鏈彮鏁堢巼': '鐝鏁堢巼(%)',\n '鏈彮鍋滄満娆℃暟': '鐝鍋滄満娆℃暟',\n '鏈彮鍋滄満鏃堕棿(绉�)': '鐝鍋滄満鏃堕棿(绉�)',\n '鏈尮浜ч噺': '鏈尮浜ч噺(婧愬崟浣�)'\n };\n const name = String(parameterName);\n // 鐢ㄥ弸浜嬩欢閲岀殑鏈彮浜ч噺闄勬湁瀹為檯鍗曚綅锛屾部鐢ㄥ悓涓�鐝浜ч噺鍚嶇О銆俓n const withUnit = /^鏈彮浜ч噺\\((.+)\\)$/.exec(name);\n if (withUnit) return '鐝浜ч噺(' + withUnit[1] + ')';\n return aliases[name] || name;\n}\nfunction createCollectionRow(source, deviceCode, parameterName, value, collectedAt, createdAt) {\n // 閲囬泦鍊兼寜鏂囨湰淇濆瓨锛汬Count鍙綔鍥哄畾鍗犱綅銆俓n return {\n HItemID: null,\n // SQL Server 鑷锛孊ulk 涓嶄紶姝ゅ垪\n HDate: new Date(collectedAt),\n // 閲囨牱鏃堕棿/婧愯澶囨椂闂碶n HSourceCode: String(deviceCode).slice(0, 50),\n HTechParamID: 0,\n // 娌跨敤鐜版湁鐩爣琛ㄧ害瀹歕n HTechParamName: canonicalParameterName(parameterName).slice(0, 500),\n HCount: 1,\n // SQL decimal(18,2)\n HCreateTime: new Date(createdAt),\n // 鏍囧噯鍖栧垱寤烘椂闂达紱閲嶈瘯淇濇寔涓嶅彉\n HResult: String(value).slice(0, 50),\n HProcNumber: String(source).slice(0, 50),\n // WY / YY / MQTT\n HFlag: 0\n };\n}\nfunction normalizeMqttReport(msg, flow, global, node) {\n // 1. MQTT鍘熷瓧娈� -> 缁熶竴鍙傛暟鍚嶃�傛棤鏄庣‘鍗曚綅/缁熻鍛ㄦ湡鐨勫瓧娈典笉寮鸿鍐掑厖绱鎴栫彮娆″�笺�俓n const fieldMappings = [{\n sourceField: 'rpm',\n parameterName: '鏈哄櫒杞��'\n }, {\n sourceField: 'rpm_avr',\n parameterName: '鐝骞冲潎杞��'\n }, {\n sourceField: 'produce',\n parameterName: '鐝浜ч噺(婧愬崟浣�)'\n }, {\n sourceField: 'effect',\n parameterName: '鐝鏁堢巼(%)'\n }, {\n sourceField: 'beat',\n parameterName: '鎵撶含鏁�'\n }, {\n sourceField: 'boot_time',\n parameterName: '寮�鏈烘椂闂�(绉�)'\n }, {\n sourceField: 'run_time',\n parameterName: '杩愯鏃堕棿(绉�)'\n }, {\n sourceField: 'stop_count',\n parameterName: '鐝鍋滄満娆℃暟'\n }, {\n sourceField: 'stop_time',\n parameterName: '鐝鍋滄満鏃堕棿(绉�)'\n }, {\n sourceField: 'stop_times',\n parameterName: '绱鍋滄満娆℃暟'\n }, {\n sourceField: 'remain_length',\n parameterName: '鍓╀綑缁忛暱'\n }, {\n sourceField: 'remain_length2',\n parameterName: '鍓╀綑缁忛暱2'\n }, {\n sourceField: 'cloth_length_cap',\n parameterName: '鏈尮浜ч噺(婧愬崟浣�)'\n }, {\n sourceField: 'worker_id',\n parameterName: '鑱屽憳id'\n },\n {\n sourceField: 'worker_name',\n parameterName: '鑱屽憳鍚嶇О'\n },\n {\n sourceField: \"variety_id\",\n parameterName: \"鍝佸彿\"\n },\n {\n sourceField: \"mach_id\",\n parameterName: \"鏈哄彴鍙穃"\n }\n ];\n function collectedValue(value) {\n if (value === null || value === undefined) return null;\n if (!['string', 'number', 'boolean'].includes(typeof value)) return null;\n if (typeof value === 'number' && !Number.isFinite(value)) return null;\n // 瀛楃涓插師鏍蜂繚鐣欙紝鍖呮嫭鍓嶅闆躲�佺┖瀛楃涓插拰灏忔暟绮惧害銆俓n return String(value);\n }\n function numericValue(value) {\n if (value === null || value === undefined || typeof value === 'boolean' || typeof value === 'object') return null;\n if (typeof value === 'string' && !value.trim()) return null;\n const parsed = Number(value);\n return Number.isFinite(parsed) ? Math.round(parsed * 100) / 100 : null;\n }\n function parseDeviceTime(value) {\n if (value === null || value === undefined || value === '') return null;\n if (value instanceof Date) return Number.isFinite(value.getTime()) ? value : null;\n const text = String(value).trim();\n const match = /^(\\d{4})-(\\d{1,2})-(\\d{1,2})(?:[ T](\\d{1,2}):(\\d{1,2})(?::(\\d{1,2})(?:\\.(\\d{1,3}))?)?)?$/.exec(text);\n if (match) {\n const year = Number(match[1]);\n const monthIndex = Number(match[2]) - 1;\n const day = Number(match[3]);\n const hour = Number(match[4] || 0);\n const minute = Number(match[5] || 0);\n const second = Number(match[6] || 0);\n const millisecond = Number((match[7] || '').padEnd(3, '0') || 0);\n // 鏄惧紡7涓弬鏁帮紝閬垮厤灞曞紑涓嶅畾闀挎暟缁勮Е鍙戠紪杈戝櫒TS2556銆俓n const date = new Date(year, monthIndex, day, hour, minute, second, millisecond);\n const matchesInput = date.getFullYear() === year && date.getMonth() === monthIndex && date.getDate() === day && date.getHours() === hour && date.getMinutes() === minute && date.getSeconds() === second;\n return matchesInput ? date : null;\n }\n if (/T.*(?:Z|[+-]\\d{2}:?\\d{2})$/i.test(text)) {\n const date = new Date(text);\n return Number.isFinite(date.getTime()) ? date : null;\n }\n return null;\n }\n function diagnostic(status, message, details = {}) {\n const previousStats = flow.get('mqtt_adapter_stats') || {};\n flow.set('mqtt_adapter_stats', {\n ...previousStats,\n received: (previousStats.received || 0) + 1,\n [status]: (previousStats[status] || 0) + 1,\n lastStatus: status,\n lastMessage: message,\n lastAt: new Date().toISOString()\n });\n const statusColors = {\n buffered: 'green',\n invalid: 'red',\n paused: 'yellow',\n unchanged: 'grey'\n };\n node.status({\n fill: statusColors[status],\n shape: status === 'buffered' ? 'dot' : 'ring',\n text: message\n });\n return {\n payload: {\n source: 'MQTT',\n status,\n message,\n ...details\n },\n _msgid: msg._msgid\n };\n }\n\n // 2. 浼樺厛鎺ユ敹瑙f瀽鑺傜偣msg.dev锛屼篃鏀寔鐩存帴浼犲叆JSON/Buffer銆俓n let deviceReport = msg.dev;\n if (!deviceReport || !deviceReport.items) {\n let body = msg.payload;\n if (Buffer.isBuffer(body)) body = body.toString('utf8');\n if (typeof body === 'string') {\n try {\n body = JSON.parse(body);\n } catch {\n body = null;\n }\n }\n if (body && typeof body === 'object' && !Array.isArray(body)) {\n const topicParts = String(msg.topic || '').split('/').filter(Boolean);\n deviceReport = {\n cmd: body.cmd,\n sn: body.sn || topicParts[2] || '',\n cmdId: body.cmd_id,\n items: body.items,\n receivedAt: new Date(),\n topic: msg.topic || ''\n };\n msg.dev = deviceReport;\n }\n }\n for (const field of ['queryParams', 'query', 'queryMode', 'rows', 'retryBuf', 'collect', 'collectionRows', 'signalRecord']) delete msg[field];\n const fields = deviceReport?.items;\n if (deviceReport?.cmd !== 'signal_msg' || !fields || typeof fields !== 'object' || Array.isArray(fields)) {\n const result = diagnostic('invalid', '涓嶆槸鏈夋晥 signal_msg 鎶ユ枃');\n node.warn(result.payload.message);\n return [null, result];\n }\n const machineId = fields.mach_id === null || fields.mach_id === undefined ? '' : String(fields.mach_id).trim();\n if (!machineId) {\n const result = diagnostic('invalid', '缂哄皯 mach_id锛屾湭閫佸叆缂撳啿');\n node.warn(result.payload.message);\n return [null, result];\n }\n // const deviceCode = ((deviceReport.sn ? String(deviceReport.sn).trim() + '-' : '') + machineId).slice(0, 50);\n const deviceCode = deviceReport.sn ? String(deviceReport.sn).trim() : ''\n const sourceTime = parseDeviceTime(fields.time);\n const receivedTime = new Date(deviceReport.receivedAt || Date.now());\n const collectedAt = sourceTime || (Number.isFinite(receivedTime.getTime()) ? receivedTime : new Date());\n const createdAt = new Date();\n const parameterValues = {};\n for (const mapping of fieldMappings) {\n const value = collectedValue(fields[mapping.sourceField]);\n if (value !== null) parameterValues[mapping.parameterName] = value;\n }\n const signal = numericValue(fields.signal);\n if (signal !== null) {\n parameterValues['淇″彿鍊�'] = collectedValue(fields.signal);\n parameterValues['杩愯鐘舵��'] = (signal & 3) === 3 ? 1 : 3;\n }\n\n // 鍘熸姤鏂囦繚鐣欎綔璇婃柇锛涙暟鍊煎拰鏂囨湰閲囬泦鍙傛暟缁熶竴鍐欏叆HResult銆俓n msg.signalRecord = {\n 璁惧缂栫爜: deviceCode,\n 鏈哄彴鍙�: machineId,\n 璁惧鏃堕棿: fields.time || '',\n 閲囨牱鏃堕棿: collectedAt.toISOString(),\n 鏃堕棿鏉ユ簮: sourceTime ? '璁惧鏃堕棿' : '鎺ユ敹鏃堕棿',\n 淇″彿: signal,\n 杞��: numericValue(fields.rpm),\n 浜ч噺: numericValue(fields.produce),\n 鏁堢巼: numericValue(fields.effect),\n 鎵瑰彿: fields.batch_number ?? null,\n 鍓╀綑缁忛暱: numericValue(fields.remain_length),\n 鍋滄満娆℃暟: numericValue(fields.stop_count),\n 鍋滄満鏃堕棿: numericValue(fields.stop_time),\n 寮�鏈烘椂闂�: numericValue(fields.boot_time),\n 杩愯鏃堕棿: numericValue(fields.run_time),\n 杞村彿: fields.axis_id ?? null,\n 鑱屽憳id: fields.worker_id ?? null,\n 鑱屽憳鍚嶇О: fields.worker_name ?? null,\n 鍝佸彿: fields.variety_id ?? null\n };\n const collectionRows = Object.entries(parameterValues).map(([name, value]) => createCollectionRow('MQTT', deviceCode, name, value, collectedAt, createdAt));\n const fieldCount = collectionRows.length;\n if (!fieldCount) return [null, diagnostic('invalid', '鏃犳湁鏁堥噰闆嗗瓧娈碉紝鏈�佸叆缂撳啿', {\n device: deviceCode,\n record: msg.signalRecord\n })];\n\n // 3. 鏆傚仠浠嶈緭鍑烘暟鎹簱瀛楁棰勮锛屾棦涓嶆洿鏂板幓閲嶇紦瀛橈紝涔熶笉鍏ラ槦銆俓n if (global.get('collection_paused') !== false) {\n return [null, diagnostic('paused', '閲囬泦宸叉殏鍋滐細宸茶В鏋� ' + fieldCount + ' 椤癸紝鏈�佸叆缂撳啿', {\n device: deviceCode,\n fields: fieldCount,\n values: parameterValues,\n record: msg.signalRecord,\n collectionRows\n })];\n }\n\n // 4. 鎸塇Result鍒ゆ柇鍙樺寲锛涗换涓�瀛楁鍙樺寲鏃堕�佸嚭鏈鎶ユ枃鐨勫叏閮ㄦ湁鏁堟槧灏勫瓧娈点�俓n let previousValues = flow.get('mqtt_seen') || {};\n let previousCount = flow.get('mqtt_seen_n') || 0;\n if (previousCount > 50000) {\n previousValues = {};\n previousCount = 0;\n }\n const changedRows = [];\n for (const row of collectionRows) {\n const cacheKey = row.HSourceCode + '|' + row.HTechParamName;\n if (previousValues[cacheKey] === row.HResult) continue;\n if (!Object.prototype.hasOwnProperty.call(previousValues, cacheKey)) previousCount += 1;\n previousValues[cacheKey] = row.HResult;\n changedRows.push(row);\n }\n flow.set('mqtt_seen', previousValues);\n flow.set('mqtt_seen_n', previousCount);\n if (!changedRows.length) return [null, diagnostic('unchanged', '閲囬泦鍊兼棤鍙樺寲锛屾湭閲嶅鍏ョ紦鍐�', {\n device: deviceCode,\n fields: fieldCount,\n record: msg.signalRecord\n })];\n msg.collectionRows = collectionRows;\n msg.payload = collectionRows;\n const result = diagnostic('buffered', '鍙樺寲 ' + changedRows.length + ' 椤� / 鍏ㄩ噺鍏ョ紦鍐� ' + fieldCount + ' 椤�', {\n device: deviceCode,\n fields: fieldCount,\n changed: changedRows.length,\n values: Object.fromEntries(collectionRows.map(row => [row.HTechParamName, row.HResult])),\n record: msg.signalRecord,\n collectionRows\n });\n return [msg, result];\n}\nreturn normalizeMqttReport(msg, flow, global, node);\n",
"outputs": 1,
@@ -970,15 +970,15 @@
"y": 420,
"wires": [
[
- "08c95ee2bd3a9073",
- "90d43ad76fa8926f"
+ "b5e431fb3fde0ed3",
+ "ed7ef3bcc3312839"
]
]
},
{
- "id": "90d43ad76fa8926f",
+ "id": "ed7ef3bcc3312839",
"type": "debug",
- "z": "cee834492540f06e",
+ "z": "e50e36e69b1c47f6",
"name": "MQTT 鏍囧噯鍖栫粨鏋�",
"active": true,
"tosidebar": true,
@@ -988,14 +988,14 @@
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
- "x": 1150,
+ "x": 1170,
"y": 320,
"wires": []
},
{
- "id": "cm_collector_note",
+ "id": "44adcd5a09d4df9b",
"type": "comment",
- "z": "tab_collector_mqtt",
+ "z": "7f2f4359c1fe45f9",
"name": "閲囬泦鍐欏簱宸茶縼鑷炽�孧QTT 路 閲囬泦鍏ュ簱锛堢嫭绔嬶級銆嶉〉绛�",
"info": "鏈〉绛捐亴璐o細\n1) /cmd 鎸囦护 鈫� 鎸囦护鍒嗙被 鈫� 寮�鐝�/鍋滄満/缁撶彮 HTTP 璇锋眰锛沑n2) 璁惧涓氬姟鍔ㄤ綔锛堝憳宸ヤ笂鐝�/钀藉竷/浜嗘満鈥︼級鈫� 纭鍥炴墽銆俓n\n閲囬泦涓庡啓搴擄細/report 涓婃姤鐨� signal_msg 宸茬敱鐙珛椤电銆孧QTT 路 閲囬泦鍏ュ簱锛堢嫭绔嬶級銆嶅畬鏁存帴绠★紙瑙f瀽 鈫� 鏍囧噯鍖� 鈫� 鐙珛缂撳啿 鈫� 姣�5s Bulk 鍐� dbo.Sb_EquipMentCollectionTechParam_Temp锛夈�俓n\n鑻ラ渶褰诲簳鍋滅敤鏈〉绛剧殑 /report 璁㈤槄锛屽彲鍒犻櫎鑺傜偣銆岃澶囦笂鎶� /report/#銆嶏紝鍥炴墽璧� /cmd 涓嶅彈褰卞搷銆�",
"x": 280,
@@ -1003,9 +1003,9 @@
"wires": []
},
{
- "id": "in_report",
+ "id": "031b1591fb04360b",
"type": "mqtt in",
- "z": "tab_collector_mqtt",
+ "z": "7f2f4359c1fe45f9",
"name": "璁惧涓婃姤 /report/#",
"topic": "/report/#",
"qos": "1",
@@ -1019,14 +1019,14 @@
"y": 120,
"wires": [
[
- "fn_parse"
+ "f3301541e5e50213"
]
]
},
{
- "id": "in_cmd",
+ "id": "0b955e19c54e9a99",
"type": "mqtt in",
- "z": "tab_collector_mqtt",
+ "z": "7f2f4359c1fe45f9",
"name": "鍏煎 /cmd/# 纭鏄惁鏄枃妗g瑪璇�",
"topic": "/cmd/#",
"qos": "1",
@@ -1040,35 +1040,40 @@
"y": 200,
"wires": [
[
- "fn_parse"
+ "f3301541e5e50213"
]
]
},
{
- "id": "fn_parse",
+ "id": "f3301541e5e50213",
"type": "function",
- "z": "tab_collector_mqtt",
+ "z": "7f2f4359c1fe45f9",
"name": "瑙f瀽璁惧鎶ユ枃",
- "func": "/**\n * MQTT鍗忚瑙f瀽\n * 杈撳叆锛氬師濮媘sg.payload鍜宮sg.topic\n * 杈撳嚭锛歮sg.dev锛沵sg.flowType渚汼witch鍒嗘祦\n * 涓婁笅鏂囷細涓嶅啓鏁版嵁搴�/缂撳啿\n */\n// 閲囬泦鍣ㄦ姤鏂囪В鏋愶細/report/**锛堣澶囦笂鎶ワ級涓� /cmd/**锛堟枃妗i噷鎶� 浜嗘満/鏈轰慨/閲囬泦鏁版嵁 璇啓鎴� /cmd锛屼袱鏉¢兘璁㈤槄锛塡nconst RECEIPT = {\n worker_register_msg: '鍛樺伐涓婄彮',\n worker_report_msg: '鍛樺伐涓嬬彮',\n axis_start_msg: '涓婅酱',\n variety_change_msg: '鏀瑰搧',\n fall_cloth_msg: '钀藉竷',\n axis_end_msg: '浜嗘満',\n repair_msg: '鏈轰慨'\n};\nconst SIGNAL_CMD = 'signal_msg';\nlet body = msg.payload;\nif (Buffer.isBuffer(body)) {\n body = body.toString('utf8');\n}\nif (typeof body === 'string') {\n try {\n body = JSON.parse(body);\n } catch (e) {\n node.warn('闈� JSON 鎶ユ枃锛屽凡涓㈠純锛�' + msg.topic);\n return null;\n }\n}\nif (!body || typeof body !== 'object') {\n node.warn('绌烘姤鏂囷紝宸蹭涪寮冿細' + msg.topic);\n return null;\n}\nconst topic = msg.topic || '';\nconst seg = topic.split('/').filter(function (s) {\n return s !== '';\n});\nconst dir = seg[0] || ''; // report | cmd\nconst kind = seg[1] || ''; // woven 姊粐 | round 鍦嗘満\nconst sn = String(body.sn || seg[2] || '');\nconst cmd = String(body.cmd || '');\nconst cmdId = body.cmd_id === undefined || body.cmd_id === null ? '' : String(body.cmd_id);\nconst items = body.items && typeof body.items === 'object' ? body.items : {};\n\n// 涓㈠純鏈満鍙戝嚭鐨勭‘璁ゅ洖鎵э紙璁㈤槄 /cmd/# 鏃� MQTT 浼氭妸鎴戜滑鑷繁鐨勫洖鎵у洖鏄惧洖鏉ワ級\n// 鍥炴墽鍙湁 mach_id锛堣惤甯冨啀鍔� cloth_id锛夛紝娌℃湁 time锛涜澶囦笂鎶ュ繀鐒跺甫 time\nif (dir === 'cmd' && (items.time === undefined || Object.keys(items).length < 2)) {\n node.status({\n fill: 'grey',\n shape: 'ring',\n text: '鍥炴墽鍥炴樉锛屽拷鐣�'\n });\n return null;\n}\nmsg.flowType = RECEIPT[cmd] ? 'confirm' : cmd === SIGNAL_CMD ? 'signal' : 'unknown';\nmsg.dev = {\n dir: dir,\n kind: kind || 'woven',\n sn: sn,\n cmd: cmd,\n cmdId: cmdId,\n items: items,\n label: RECEIPT[cmd] || (cmd === SIGNAL_CMD ? '閲囬泦鏁版嵁涓婃姤' : cmd || '(缂哄皯 cmd)'),\n topic: topic,\n receivedAt: new Date()\n};\nnode.status({\n fill: 'blue',\n shape: 'dot',\n text: msg.dev.label\n});\n\nmsg.cmd = cmd\nreturn msg;\n",
+ "func": "/**\n * MQTT鍗忚瑙f瀽\n * 杈撳叆锛氬師濮媘sg.payload鍜宮sg.topic\n * 杈撳嚭锛歮sg.dev锛沵sg.flowType渚汼witch鍒嗘祦\n * 涓婁笅鏂囷細涓嶅啓鏁版嵁搴�/缂撳啿\n */\n// 閲囬泦鍣ㄦ姤鏂囪В鏋愶細/report/**锛堣澶囦笂鎶ワ級涓� /cmd/**锛堟枃妗i噷鎶� 浜嗘満/鏈轰慨/閲囬泦鏁版嵁 璇啓鎴� /cmd锛屼袱鏉¢兘璁㈤槄锛塡nconst RECEIPT = {\n worker_register_msg: '鍛樺伐涓婄彮',\n worker_report_msg: '鍛樺伐涓嬬彮',\n axis_start_msg: '涓婅酱',\n variety_change_msg: '鏀瑰搧',\n fall_cloth_msg: '钀藉竷',\n axis_end_msg: '浜嗘満',\n repair_msg: '鏈轰慨'\n};\nconst SIGNAL_CMD = 'signal_msg';\nlet body = msg.payload;\nif (Buffer.isBuffer(body)) {\n body = body.toString('utf8');\n}\nif (typeof body === 'string') {\n try {\n body = JSON.parse(body);\n } catch (e) {\n node.warn('闈� JSON 鎶ユ枃锛屽凡涓㈠純锛�' + msg.topic);\n return null;\n }\n}\nif (!body || typeof body !== 'object') {\n node.warn('绌烘姤鏂囷紝宸蹭涪寮冿細' + msg.topic);\n return null;\n}\nconst topic = msg.topic || '';\nconst seg = topic.split('/').filter(function (s) {\n return s !== '';\n});\nconst dir = seg[0] || ''; // report | cmd\nconst kind = seg[1] || ''; // woven 姊粐 | round 鍦嗘満\nconst sn = String(body.sn || seg[2] || '');\nconst cmd = String(body.cmd || '');\nconst cmdId = body.cmd_id === undefined || body.cmd_id === null ? '' : String(body.cmd_id);\nconst items = body.items && typeof body.items === 'object' ? body.items : {};\n\n// 涓㈠純鏈満鍙戝嚭鐨勭‘璁ゅ洖鎵э紙璁㈤槄 /cmd/# 鏃� MQTT 浼氭妸鎴戜滑鑷繁鐨勫洖鎵у洖鏄惧洖鏉ワ級\n// 鍥炴墽鍙湁 mach_id锛堣惤甯冨啀鍔� cloth_id锛夛紝娌℃湁 time锛涜澶囦笂鎶ュ繀鐒跺甫 time\nif (dir === 'cmd' && (items.time === undefined || Object.keys(items).length < 2)) {\n node.status({\n fill: 'grey',\n shape: 'ring',\n text: '鍥炴墽鍥炴樉锛屽拷鐣�'\n });\n return null;\n}\nmsg.flowType = RECEIPT[cmd] ? 'confirm' : cmd === SIGNAL_CMD ? 'signal' : 'unknown';\nmsg.dev = {\n dir: dir,\n kind: kind || 'woven',\n sn: sn,\n cmd: cmd,\n cmdId: cmdId,\n items: items,\n label: RECEIPT[cmd] || (cmd === SIGNAL_CMD ? '閲囬泦鏁版嵁涓婃姤' : cmd || '(缂哄皯 cmd)'),\n topic: topic,\n receivedAt: moment().format('YYYY-MM-DD HH:mm:ss')\n};\nnode.status({\n fill: 'blue',\n shape: 'dot',\n text: msg.dev.label\n});\n\nmsg.cmd = cmd\nreturn msg;\n",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
- "libs": [],
+ "libs": [
+ {
+ "var": "moment",
+ "module": "moment"
+ }
+ ],
"x": 400,
"y": 160,
"wires": [
[
- "sw_type",
- "8a19a552dffdf1e1"
+ "ead3652bd97470c8",
+ "0384d5b73dbaba06"
]
]
},
{
- "id": "sw_type",
+ "id": "ead3652bd97470c8",
"type": "switch",
- "z": "tab_collector_mqtt",
+ "z": "7f2f4359c1fe45f9",
"name": "鎸夋秷鎭被鍨嬪垎娴�",
"property": "flowType",
"propertyType": "msg",
@@ -1094,21 +1099,21 @@
"y": 160,
"wires": [
[
- "fn_confirm"
+ "aae840bc801cab63"
],
[
- "dbg_signal",
- "223b29559f4a36ae"
+ "c074b26babe6eaf4",
+ "bbeb11d3b16af342"
],
[
- "dbg_unknown"
+ "f8ba4be1506a4794"
]
]
},
{
- "id": "fn_confirm",
+ "id": "aae840bc801cab63",
"type": "function",
- "z": "tab_collector_mqtt",
+ "z": "7f2f4359c1fe45f9",
"name": "鐢熸垚纭鍥炴墽",
"func": "/**\n * MQTT涓氬姟纭鍥炴墽\n * 杈撳叆锛歮sg.dev=宸茶В鏋愪笟鍔℃姤鏂嘰n * 杈撳嚭锛氳緭鍑�1=璇婃柇锛涜緭鍑�2=MQTT纭娑堟伅\n * 涓婁笅鏂囷細涓嶅啓閲囬泦缂撳啿锛泂ignal_msg涓嶈蛋姝よ妭鐐筡n */\n// 涓冪被闇�瑕佸洖鎵х殑娑堟伅锛氳緭鍑� 1 = 璋冭瘯绐楀彛璁板綍锛岃緭鍑� 2 = 鍥炴墽鎶ユ枃\nconst d = msg.dev || {};\nconst it = d.items || {};\n\n// 钀藉竷瑕佺粰鏈嶅姟鍣ㄧ敓鎴愶紙杩欓噷缁欒澶囷級鐨勫竷鍖瑰彿锛岀函鏁板瓧\nfunction clothIdOf() {\n const dev = it.cloth_id_dev;\n if (dev !== undefined && dev !== null && /^\\d+$/.test(String(dev).trim())) {\n return String(dev).trim();\n }\n // 鍏滃簳锛氱敤姣鏃堕棿鎴冲悗 9 浣嶏紝淇濊瘉绾暟瀛椾笖鍩烘湰涓嶉噸澶嶏紱姝e紡鐜寤鸿鎹㈡垚鏁版嵁搴撳簭鍒梊n return String(Date.now()).slice(-9);\n}\nconst ackItems = {\n mach_id: it.mach_id === undefined ? '' : String(it.mach_id)\n};\nlet clothId = null;\nif (d.cmd === 'fall_cloth_msg') {\n clothId = clothIdOf();\n ackItems.cloth_id = clothId;\n}\nconst record = {\n '娑堟伅': d.label,\n 'cmd': d.cmd,\n 'cmd_id': d.cmdId,\n '璁惧SN': d.sn,\n '鏈哄彴鍙�': ackItems.mach_id,\n '鏃堕棿': it.time || '',\n '涓婚': d.topic,\n '瀛楁': it\n};\nif (clothId) {\n record['鍥炴墽cloth_id'] = clothId;\n}\nconst ack = {\n cmd: d.cmd,\n sn: d.sn,\n cmd_id: d.cmdId,\n items: ackItems\n};\nconst ackMsg = {\n topic: '/cmd/' + (d.kind || 'woven') + '/' + d.sn,\n payload: JSON.stringify(ack),\n qos: 1,\n retain: false\n};\nnode.status({\n fill: 'green',\n shape: 'dot',\n text: d.label + ' 宸茬‘璁�'\n});\nreturn [{\n payload: record,\n _msgid: msg._msgid\n}, ackMsg];\n",
"outputs": 2,
@@ -1121,17 +1126,17 @@
"y": 120,
"wires": [
[
- "dbg_record"
+ "a37c2b42e32fcede"
],
[
- "mqtt_out_ack"
+ "0c49d2e1c5fbf7df"
]
]
},
{
- "id": "dbg_record",
+ "id": "a37c2b42e32fcede",
"type": "debug",
- "z": "tab_collector_mqtt",
+ "z": "7f2f4359c1fe45f9",
"name": "璁惧娑堟伅锛堣皟璇曠獥鍙o級",
"active": false,
"tosidebar": true,
@@ -1146,9 +1151,9 @@
"wires": []
},
{
- "id": "mqtt_out_ack",
+ "id": "0c49d2e1c5fbf7df",
"type": "mqtt out",
- "z": "tab_collector_mqtt",
+ "z": "7f2f4359c1fe45f9",
"name": "鍥炲纭娑堟伅",
"topic": "",
"qos": "1",
@@ -1164,9 +1169,9 @@
"wires": []
},
{
- "id": "dbg_unknown",
+ "id": "f8ba4be1506a4794",
"type": "debug",
- "z": "tab_collector_mqtt",
+ "z": "7f2f4359c1fe45f9",
"name": "鏈瘑鍒秷鎭紙璋冭瘯绐楀彛锛�",
"active": false,
"tosidebar": true,
@@ -1181,9 +1186,9 @@
"wires": []
},
{
- "id": "dbg_error",
+ "id": "dd19870861051cfa",
"type": "debug",
- "z": "tab_collector_mqtt",
+ "z": "7f2f4359c1fe45f9",
"name": "寮傚父锛堣皟璇曠獥鍙o級",
"active": false,
"tosidebar": true,
@@ -1198,9 +1203,9 @@
"wires": []
},
{
- "id": "dbg_signal",
+ "id": "c074b26babe6eaf4",
"type": "debug",
- "z": "tab_collector_mqtt",
+ "z": "7f2f4359c1fe45f9",
"name": "閲囬泦鍘熷瀛楁锛堣皟璇曠獥鍙o級",
"active": false,
"tosidebar": true,
@@ -1215,9 +1220,9 @@
"wires": []
},
{
- "id": "coll_catch",
+ "id": "25d3fd39b7fe3108",
"type": "catch",
- "z": "tab_collector_mqtt",
+ "z": "7f2f4359c1fe45f9",
"name": "閲囬泦鍣� 路 寮傚父",
"scope": null,
"uncaught": false,
@@ -1225,27 +1230,27 @@
"y": 380,
"wires": [
[
- "dbg_error"
+ "dd19870861051cfa"
]
]
},
{
- "id": "collection_mqtt_control_out",
+ "id": "82a08ca67d2a3afb",
"type": "link out",
- "z": "tab_collector_mqtt",
+ "z": "7f2f4359c1fe45f9",
"name": "鈫� 閲囬泦鎬诲紑鍏筹紙鍏ㄩ儴娴佺▼锛�",
"mode": "link",
"links": [
- "collection_control_link_in"
+ "603d604846aecbe1"
],
"x": 490,
"y": 310,
"wires": []
},
{
- "id": "collection_mqtt_pause",
+ "id": "974c8c694477c002",
"type": "inject",
- "z": "tab_collector_mqtt",
+ "z": "7f2f4359c1fe45f9",
"name": "鈴� 鏆傚仠鍏ㄩ儴閲囬泦/鍐欏簱",
"props": [
{
@@ -1263,14 +1268,14 @@
"y": 280,
"wires": [
[
- "collection_mqtt_control_out"
+ "82a08ca67d2a3afb"
]
]
},
{
- "id": "collection_mqtt_resume",
+ "id": "6dbd1b0ec56e7206",
"type": "inject",
- "z": "tab_collector_mqtt",
+ "z": "7f2f4359c1fe45f9",
"name": "鈻� 鎭㈠鍏ㄩ儴閲囬泦/鍐欏簱",
"props": [
{
@@ -1288,14 +1293,14 @@
"y": 340,
"wires": [
[
- "collection_mqtt_control_out"
+ "82a08ca67d2a3afb"
]
]
},
{
- "id": "2a9b70e492406c99",
+ "id": "44f768440f6a0965",
"type": "switch",
- "z": "tab_collector_mqtt",
+ "z": "7f2f4359c1fe45f9",
"name": "鎸夌収鎸囦护绫诲瀷鍒嗘祦",
"property": "cmdType",
"propertyType": "msg",
@@ -1316,9 +1321,7 @@
"vt": "str"
},
{
- "t": "eq",
- "v": "unknow",
- "vt": "str"
+ "t": "else"
}
],
"checkall": "true",
@@ -1328,23 +1331,23 @@
"y": 500,
"wires": [
[
- "746212d2b24dee79"
+ "8f2d6bd03730058b"
],
[
- "0d55791095dd9798"
+ "519e569fcc44c35f"
],
[
- "b1f55cf02a6874d6"
+ "886c4d0603f4aa3f"
],
[
- "969b330c32c6d99b"
+ "524a81520562e53a"
]
]
},
{
- "id": "129964fd2e838f95",
+ "id": "5d9b0b2ef2b2f293",
"type": "http request",
- "z": "tab_collector_mqtt",
+ "z": "7f2f4359c1fe45f9",
"name": "鎸囦护 鐢熸垚寮�鐝崟",
"method": "POST",
"ret": "obj",
@@ -1361,14 +1364,14 @@
"y": 420,
"wires": [
[
- "b95821d0ecf31b06"
+ "61a18e365847e814"
]
]
},
{
- "id": "b95821d0ecf31b06",
+ "id": "61a18e365847e814",
"type": "debug",
- "z": "tab_collector_mqtt",
+ "z": "7f2f4359c1fe45f9",
"name": "寮�鐝崟 杩斿洖缁撴灉",
"active": true,
"tosidebar": true,
@@ -1378,16 +1381,16 @@
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
- "x": 1450,
+ "x": 1470,
"y": 420,
"wires": []
},
{
- "id": "8a19a552dffdf1e1",
+ "id": "0384d5b73dbaba06",
"type": "function",
- "z": "tab_collector_mqtt",
+ "z": "7f2f4359c1fe45f9",
"name": "鎸囦护鍒嗙被",
- "func": "let msgType = 'unknow';\nlet cmd = flow.get(\"cmd\")\n// 鏍规嵁鍛戒护浼犺緭鐨勭被鍨嬪尯鍒嗛渶瑕佺敓鎴愬崟鎹殑绫诲瀷\n\nif (cmd == 'worker_register_msg') {\n // 鍛樺伐涓婄彮 鐢熸垚寮�鐝崟(鏆傚畾)\n msg.msgType = 'workbegin'\n}\nelse if(cmd == 'axis_start_msg'\n|| cmd =='fall_cloth_msg'\n|| cmd == 'axis_end_msg'\n|| cmd == 'repair_msg'\n|| cmd == 'variety_change_msg') {\n // 璁惧鍋滄満鎿嶄綔 闇�鐢熸垚鍋滄満鍗昞n msg.msgType = 'workstop'\n}\nelse if (cmd == 'worker_report_msg') {\n // 鍛樺伐涓嬬彮锛岀敓鎴愮粨鐝崟\n msg.msgType = 'workend'\n}\nelse {\n msg.msgType = 'unknow'\n}\n\nreturn msg;",
+ "func": "let cmd = msg.cmd;\n\n// 閲囬泦鏁版嵁涓婃姤涓嶆槸鎸囦护锛屽埆璁╁畠鎺夎繘 unknow 鍙樻垚\"寮傚父鎸囦护\"\nif (cmd === 'signal_msg') { return null; }\n\nswitch (cmd) {\n case 'worker_register_msg': // 鍛樺伐涓婄彮 鈫� 寮�鐝崟\n msg.cmdType = 'workbegin'; break;\n case 'axis_start_msg': // 涓婅酱/鏀瑰搧/钀藉竷/浜嗘満/鏈轰慨 鈫� 鍋滃伐鍗昞n case 'variety_change_msg':\n case 'fall_cloth_msg':\n case 'axis_end_msg':\n case 'repair_msg':\n msg.cmdType = 'workstop'; break;\n case 'worker_report_msg': // 鍛樺伐涓嬬彮 鈫� 缁撶彮鍗昞n msg.cmdType = 'workend'; break;\n default:\n msg.cmdType = 'unknow';\n}\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
@@ -1398,14 +1401,14 @@
"y": 500,
"wires": [
[
- "2a9b70e492406c99"
+ "44f768440f6a0965"
]
]
},
{
- "id": "969b330c32c6d99b",
+ "id": "524a81520562e53a",
"type": "debug",
- "z": "tab_collector_mqtt",
+ "z": "7f2f4359c1fe45f9",
"name": "寮傚父鎸囦护",
"active": true,
"tosidebar": true,
@@ -1415,19 +1418,19 @@
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
- "x": 1370,
+ "x": 1450,
"y": 540,
"wires": []
},
{
- "id": "22db5d23f5f3b117",
+ "id": "0ff6bf2b53ced194",
"type": "http request",
- "z": "tab_collector_mqtt",
- "name": "鎸囦护鐢熸垚 寮傚父鍙嶉璇锋眰鍗�",
- "method": "GET",
+ "z": "7f2f4359c1fe45f9",
+ "name": "鎸囦护鐢熸垚 鍋滃伐鍗�",
+ "method": "POST",
"ret": "obj",
"paytoqs": "ignore",
- "url": "",
+ "url": "http://localhost:81/API/Sc_MESStopWorkBill/SaveGetMESStopFrom",
"tls": "",
"persist": false,
"proxy": "",
@@ -1435,19 +1438,19 @@
"authType": "",
"senderr": false,
"headers": [],
- "x": 1290,
+ "x": 1260,
"y": 460,
"wires": [
[
- "89d8213271967cf2"
+ "5a594106130bbc57"
]
]
},
{
- "id": "89d8213271967cf2",
+ "id": "5a594106130bbc57",
"type": "debug",
- "z": "tab_collector_mqtt",
- "name": "寮傚父鍙嶉 杩斿洖缁撴灉",
+ "z": "7f2f4359c1fe45f9",
+ "name": "鍋滃伐鍗� 杩斿洖缁撴灉",
"active": true,
"tosidebar": true,
"console": true,
@@ -1456,19 +1459,19 @@
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
- "x": 1520,
+ "x": 1470,
"y": 460,
"wires": []
},
{
- "id": "5b954fff423a59e1",
+ "id": "26003aa407573869",
"type": "http request",
- "z": "tab_collector_mqtt",
+ "z": "7f2f4359c1fe45f9",
"name": "鎸囦护 鐢熸垚缁撶彮鍗�",
- "method": "GET",
- "ret": "txt",
+ "method": "POST",
+ "ret": "obj",
"paytoqs": "ignore",
- "url": "",
+ "url": "http://localhost:81/API//Sc_MESEndWorkBill/SaveGetMESEndFrom",
"tls": "",
"persist": false,
"proxy": "",
@@ -1480,14 +1483,14 @@
"y": 500,
"wires": [
[
- "6593cb6999b49bf4"
+ "30b232adbb2c88e6"
]
]
},
{
- "id": "6593cb6999b49bf4",
+ "id": "30b232adbb2c88e6",
"type": "debug",
- "z": "tab_collector_mqtt",
+ "z": "7f2f4359c1fe45f9",
"name": "缁撶彮鍗� 杩斿洖鐘舵��",
"active": true,
"tosidebar": true,
@@ -1497,90 +1500,105 @@
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
- "x": 1450,
+ "x": 1470,
"y": 500,
"wires": []
},
{
- "id": "223b29559f4a36ae",
+ "id": "bbeb11d3b16af342",
"type": "link out",
- "z": "tab_collector_mqtt",
+ "z": "7f2f4359c1fe45f9",
"name": "鈫� 鍘熷閲囬泦鎶ユ枃锛堜富娴佺▼缁熶竴杞崲锛�",
"mode": "link",
"links": [
- "c06152e6ab227d0b"
+ "55dfd316772445bf"
],
"x": 995,
"y": 220,
"wires": []
},
{
- "id": "746212d2b24dee79",
+ "id": "8f2d6bd03730058b",
"type": "function",
- "z": "tab_collector_mqtt",
+ "z": "7f2f4359c1fe45f9",
"name": "鐢熸垚寮�鐝崟璐熻浇",
- "func": "// 寮�鐝崟鏍囧噯缁撴瀯\n//{\"HInterID\":0,\"HBillNo\":\"SCKG000000001334\",\"HDate\":\"{{ 濉啓 褰撳墠鏃堕棿 骞�-鏈�-鏃� 鏃�:鍒�:绉� }}\",\"HMainSourceBillNo\":\"\",\n//\"HMainSourceInterID\":0,\"HMainSourceEntryID\":1,\"HProcExchBillNo\":\"\",\"HProcExchInterID\":0,\n//\"HProcExchEntryID\":1,\"HMainSourceBillType\":\"-1\",\"HICMOBillNo\":\"\",\"HICMOInterID\":0,\"HICMOEntryID\":1,\n//\"HSourceName\":\"\",\"HSourceID\":{{ 濉啓mach_id }},\"HProcName\":\"\",\"HProcID\":0,\"HMaterNumber\":\"\",\n//\"HMaterCode\":\"\",\"HMaterName\":\"\",\"HMaterSpec\":\"\",\"HMaterID\":0,\n//\"HBeginWorkTime\":\"{{ 濉啓 褰撳墠鏃堕棿 骞�-鏈�-鏃� 鏃�:鍒�:绉� }}\",\"HGroupName\":\"\",\"HGroupID\":0,\"HEmpName\":\"{{ 濉啓worker_name }}\",\n//\"HEmpID\":{{ 濉啓worker_id }},\"HDeptName\":\"\",\"HDeptID\":0,\"HWorkShiftName\":\"\",\"HWorkShiftID\":0,\n//\"SourceType\":\"1\",\"HPeopleSum\":1,\"HMaker\":\"admin\",\"HMakeDate\":\"{{ 濉啓 褰撳墠鏃堕棿 骞�-鏈�-鏃� 鏃�:鍒�:绉� }}\",\n//\"HUpDater\":\"\",\"HUpDateDate\":\"\",\"HChecker\":\"\",\"HCheckDate\":\"\",\"HCloseMan\":\"\",\"HDeleteMan\":\"\",\n//\"HCloseDate\":\"\",\"HDeleteDate\":\"\"};[{\"HMaterID\":\"0\",\"HMaterName\":\"\",\"HProcID\":\"0\",\"HProcName\":\"\",\n//\"HRelationBillInterID\":\"0\",\"HRelationBillEntryID\":\"0\",\"HRelationBillType\":\"\",\"HRelationBillNo\":\"\",\n//\"HICMOInterID\":\"0\",\"HICMOEntryID\":\"0\",\"HICMOBillNo\":\"\",\"HProcExchInterID\":\"0\",\"HProcExchEntryID\":\"0\",\n//\"HProcExchBillNo\":\"\",\"HRemark\":\"\",\"HSourceInterID\":\"0\",\"HSourceEntryID\":\"0\",\"HSourceBillNo\":\"\",\"HSourceBillType\":\"\",\n//\"LAY_TABLE_INDEX\":0}];admin;Add\n\n\nreturn msg;",
+ "func": "// 寮�鐝崟鏍囧噯缁撴瀯\n// {\"HInterID\":0,\"HBillNo\":\"SCKG000000001334\",\"HDate\":\"{{ 濉啓 褰撳墠鏃堕棿 骞�-鏈�-鏃� 鏃�:鍒�:绉� }}\",\"HMainSourceBillNo\":\"\",\n// \"HMainSourceInterID\":0,\"HMainSourceEntryID\":1,\"HProcExchBillNo\":\"\",\"HProcExchInterID\":0,\n// \"HProcExchEntryID\":1,\"HMainSourceBillType\":\"-1\",\"HICMOBillNo\":\"\",\"HICMOInterID\":0,\"HICMOEntryID\":1,\n// \"HSourceName\":\"\",\"HSourceID\":{{ 濉啓mach_id }},\"HProcName\":\"\",\"HProcID\":0,\"HMaterNumber\":\"\",\n// \"HMaterCode\":\"\",\"HMaterName\":\"\",\"HMaterSpec\":\"\",\"HMaterID\":0,\n// \"HBeginWorkTime\":\"{{ 濉啓 褰撳墠鏃堕棿 骞�-鏈�-鏃� 鏃�:鍒�:绉� }}\",\"HGroupName\":\"\",\"HGroupID\":0,\"HEmpName\":\"{{ 濉啓worker_name }}\",\n// \"HEmpID\":{{ 濉啓worker_id }},\"HDeptName\":\"\",\"HDeptID\":0,\"HWorkShiftName\":\"\",\"HWorkShiftID\":0,\n// \"SourceType\":\"1\",\"HPeopleSum\":1,\"HMaker\":\"admin\",\"HMakeDate\":\"{{ 濉啓 褰撳墠鏃堕棿 骞�-鏈�-鏃� 鏃�:鍒�:绉� }}\",\n// \"HUpDater\":\"\",\"HUpDateDate\":\"\",\"HChecker\":\"\",\"HCheckDate\":\"\",\"HCloseMan\":\"\",\"HDeleteMan\":\"\",\n// \"HCloseDate\":\"\",\"HDeleteDate\":\"\"};[{\"HMaterID\":\"0\",\"HMaterName\":\"\",\"HProcID\":\"0\",\"HProcName\":\"\",\n// \"HRelationBillInterID\":\"0\",\"HRelationBillEntryID\":\"0\",\"HRelationBillType\":\"\",\"HRelationBillNo\":\"\",\n// \"HICMOInterID\":\"0\",\"HICMOEntryID\":\"0\",\"HICMOBillNo\":\"\",\"HProcExchInterID\":\"0\",\"HProcExchEntryID\":\"0\",\n// \"HProcExchBillNo\":\"\",\"HRemark\":\"\",\"HSourceInterID\":\"0\",\"HSourceEntryID\":\"0\",\"HSourceBillNo\":\"\",\"HSourceBillType\":\"\",\n// \"LAY_TABLE_INDEX\":0}];admin;Add\n\n\nlet payload = msg.payload\nlet items = payload.items\nlet now = moment().format('YYYY-MM-DD HH:mm:ss');\nlet msgPayload = {\n \"msg\": `{\"HInterID\":0,\"HBillNo\":\"\",\"HDate\":\"${now}\",\"HMainSourceBillNo\":\"\",\n\"HMainSourceInterID\":0,\"HMainSourceEntryID\":1,\"HProcExchBillNo\":\"\",\"HProcExchInterID\":0,\n\"HProcExchEntryID\":1,\"HMainSourceBillType\":\"-1\",\"HICMOBillNo\":\"\",\"HICMOInterID\":0,\"HICMOEntryID\":1,\n\"HSourceName\":\"\",\"HSourceID\":${items.mach_id},\"HProcName\":\"\",\"HProcID\":0,\"HMaterNumber\":\"\",\n\"HMaterCode\":\"\",\"HMaterName\":\"\",\"HMaterSpec\":\"\",\"HMaterID\":0,\n\"HBeginWorkTime\":\"${now}\",\"HGroupName\":\"\",\"HGroupID\":0,\"HEmpName\":\"${items.worker_name}\",\n\"HEmpID\":${items.worker_id},\"HDeptName\":\"\",\"HDeptID\":0,\"HWorkShiftName\":\"\",\"HWorkShiftID\":0,\n\"SourceType\":\"1\",\"HPeopleSum\":1,\"HMaker\":\"admin\",\"HMakeDate\":\"${now}\",\n\"HUpDater\":\"\",\"HUpDateDate\":\"\",\"HChecker\":\"\",\"HCheckDate\":\"\",\"HCloseMan\":\"\",\"HDeleteMan\":\"\",\n\"HCloseDate\":\"\",\"HDeleteDate\":\"\"};[{\"HMaterID\":\"0\",\"HMaterName\":\"\",\"HProcID\":\"0\",\"HProcName\":\"\",\n\"HRelationBillInterID\":\"0\",\"HRelationBillEntryID\":\"0\",\"HRelationBillType\":\"\",\"HRelationBillNo\":\"\",\n\"HICMOInterID\":\"0\",\"HICMOEntryID\":\"0\",\"HICMOBillNo\":\"\",\"HProcExchInterID\":\"0\",\"HProcExchEntryID\":\"0\",\n\"HProcExchBillNo\":\"\",\"HRemark\":\"閲囬泦璁惧鎸囦护鐢熸垚\",\"HSourceInterID\":\"0\",\"HSourceEntryID\":\"0\",\"HSourceBillNo\":\"\",\"HSourceBillType\":\"\",\n\"LAY_TABLE_INDEX\":0}];admin;Add`\n}\nmsg.payload = msgPayload\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
- "libs": [],
+ "libs": [
+ {
+ "var": "moment",
+ "module": "moment"
+ }
+ ],
"x": 1020,
"y": 420,
"wires": [
[
- "129964fd2e838f95",
- "4f16c5c0b639cbda"
+ "fbc635ec53f6495b",
+ "5d9b0b2ef2b2f293"
]
]
},
{
- "id": "0d55791095dd9798",
+ "id": "519e569fcc44c35f",
"type": "function",
- "z": "tab_collector_mqtt",
- "name": "鐢熸垚寮傚父鍙嶉鍗曡礋杞�",
- "func": "\nreturn msg;",
+ "z": "7f2f4359c1fe45f9",
+ "name": "鐢熸垚鍋滃伐鍗曡礋杞�",
+ "func": "// 鍋滃伐鍗曟爣鍑嗙粨鏋勶紙瀵瑰簲鎺ュ彛 Sc_MESStopWorkBill/SaveGetMESStopFrom锛塡n// {\"HInterID\":9999,\"HBillNo\":\"TGSC00009999\",\"HDate\":\"浠婃棩 骞�-鏈�-鏃� 鏃�:鍒�:绉抃",\"HMainSourceBillNo\":\"\",\"HMainSourceInterID\":0,\n// \"HMainSourceEntryID\":1,\"HProcExchBillNo\":\"\",\"HProcExchInterID\":0,\"HProcExchEntryID\":1,\"HMainSourceBillType\":\"-1\",\n// \"HICMOBillNo\":\"\",\"HICMOInterID\":0,\"HICMOEntryID\":1,\"HSourceName\":\"\",\"HSourceID\":mach_id,\"HProcName\":\"\",\n// \"HProcID\":0,\"HMaterNumber\":\"\",\"HMaterCode\":\"\",\"HMaterName\":\"\",\"HMaterSpec\":\"\",\"HMaterID\":0,\n// \"HStopBeginWorkTime\":\"浠婃棩\",\"HStopEndWorkTime\":\"浠婃棩\",\"HStopType\":\"\",\"HStopReason\":\"鎸囦护绫诲埆涓枃\",\n// \"HGroupName\":\"\",\"HGroupID\":0,\"HEmpName\":\"worker_name\",\"HEmpID\":worker_id,\"HDeptName\":\"\",\"HDeptID\":0,\n// \"HWorkShiftName\":\"\",\"HWorkShiftID\":0,\"HRemark\":\"閲囬泦鍣ㄦ寚浠ょ敓鎴怽",\"HMaker\":\"admin\",\"HMakeDate\":\"浠婃棩\",\n// \"HUpDater\":\"\",\"HUpDateDate\":\"\",\"HChecker\":\"\",\"HCheckDate\":\"\",\"HCloseMan\":\"\",\"HDeleteMan\":\"\",\n// \"HCloseDate\":\"\",\"HDeleteDate\":\"\"};admin;Add\n\nconst CMD_LABEL = {\n axis_start_msg: '涓婅酱',\n variety_change_msg: '鏀瑰搧',\n fall_cloth_msg: '钀藉竷',\n axis_end_msg: '浜嗘満',\n repair_msg: '鏈轰慨'\n};\n\n// moment 鏉ヨ嚜鏈妭鐐广�岃缃� 鈫� 妯″潡銆嶏紙鍙橀噺鍚� moment锛夛紝鍒紡閰峔nconst now = moment().format('YYYY-MM-DD HH:mm:ss');\n\nconst items = (msg.payload && msg.payload.items) || {};\nconst dev = msg.dev || {};\n\nfunction str(v, dflt) {\n if (v === undefined || v === null) return dflt === undefined ? '' : dflt;\n return String(v);\n}\n// 鎺ュ彛鎸� ';' 鍒嗘锛屾枃鏈噷鐨勫垎鍙峰繀椤绘礂鎺夛紝鍚﹀垯浼氳鎷嗘垚 4 娈礬nfunction cln(s) {\n return String(s).replace(/;/g, '锛�');\n}\nfunction numOrRaw(v) {\n if (v === undefined || v === null || v === '') return 0;\n const n = Number(v);\n return Number.isFinite(n) ? n : String(v);\n}\n\nconst header = {\n HInterID: 9999,\n HBillNo: 'CSTGD000999',\n HDate: now,\n HMainSourceBillNo: '',\n HMainSourceInterID: 0,\n HMainSourceEntryID: 1,\n HProcExchBillNo: '',\n HProcExchInterID: 0,\n HProcExchEntryID: 1,\n HMainSourceBillType: '-1',\n HICMOBillNo: '',\n HICMOInterID: 0,\n HICMOEntryID: 1,\n HSourceName: '',\n HSourceID: numOrRaw(items.mach_id),\n HProcName: '',\n HProcID: 0,\n HMaterNumber: '',\n HMaterCode: '',\n HMaterName: '',\n HMaterSpec: '',\n HMaterID: 0,\n HStopBeginWorkTime: now,\n HStopEndWorkTime: now,\n HStopType: '',\n HStopReason: cln(str(dev.label || CMD_LABEL[msg.cmd] || msg.cmd, '鏈煡鍋滄満')),\n HGroupName: '',\n HGroupID: 0,\n HEmpName: cln(str(items.worker_name)),\n HEmpID: numOrRaw(items.worker_id),\n HDeptName: '',\n HDeptID: 0,\n HWorkShiftName: '',\n HWorkShiftID: 0,\n HRemark: '閲囬泦鍣ㄦ寚浠ょ敓鎴�',\n HMaker: 'admin',\n HMakeDate: now,\n HUpDater: '',\n HUpDateDate: '',\n HChecker: '',\n HCheckDate: '',\n HCloseMan: '',\n HDeleteMan: '',\n HCloseDate: '',\n HDeleteDate: ''\n};\n\n// 涓夋寮忥細{鎶ユ枃澶磢;admin;Add\nmsg.payload = {\n msg: JSON.stringify(header) + ';admin;Add'\n};\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
- "libs": [],
- "x": 1040,
+ "libs": [
+ {
+ "var": "moment",
+ "module": "moment"
+ }
+ ],
+ "x": 1020,
"y": 460,
"wires": [
[
- "22db5d23f5f3b117",
- "4f16c5c0b639cbda"
+ "0ff6bf2b53ced194",
+ "fbc635ec53f6495b"
]
]
},
{
- "id": "b1f55cf02a6874d6",
+ "id": "886c4d0603f4aa3f",
"type": "function",
- "z": "tab_collector_mqtt",
+ "z": "7f2f4359c1fe45f9",
"name": "鐢熸垚缁撶彮鍗曡礋杞�",
- "func": "\nreturn msg;",
+ "func": "// 缁撶彮鍗曡礋杞斤紙鎺ュ彛 Sc_MESEndWorkBill/SaveGetMESEndFrom锛塡n// {\"HInterID\":0,\"HBillNo\":\"\",\"HDate\":\"浠婃棩 骞�-鏈�-鏃� 鏃�:鍒�:绉抃",\"HMainSourceBillNo\":\"\",\"HMainSourceInterID\":0,\n// \"HMainSourceEntryID\":1,\"HProcExchBillNo\":\"\",\"HProcExchInterID\":0,\"HProcExchEntryID\":1,\"HMainSourceBillType\":\"-1\",\n// \"HICMOBillNo\":\"\",\"HICMOInterID\":0,\"HICMOEntryID\":1,\"HSourceName\":\"\",\"HSourceID\":mach_id,\"HProcName\":\"\",\"HProcID\":0,\n// \"HMaterNumber\":\"\",\"HMaterCode\":\"\",\"HMaterName\":\"\",\"HMaterSpec\":\"\",\"HMaterID\":variety_id,\n// \"HEndWorkTime\":\"浠婃棩\",\"HGroupName\":\"\",\"HGroupID\":0,\"HEmpName\":\"worker_name 娌℃湁鍒欑┖涓瞈",\"HEmpID\":worker_id,\n// \"HDeptName\":\"\",\"HDeptID\":0,\"HWorkShiftName\":\"\",\"HWorkShiftID\":shift_id,\"HMaker\":\"admin\",\"HMakeDate\":\"浠婃棩\",\n// \"HUpDater\":\"\",\"HUpDateDate\":\"\",\"HChecker\":\"\",\"HCheckDate\":\"\",\"HCloseMan\":\"\",\"HDeleteMan\":\"\",\n// \"HCloseDate\":\"\",\"HDeleteDate\":\"\"};admin;Add\n\n// moment 鏉ヨ嚜鏈妭鐐广�岃缃� 鈫� 妯″潡銆嶏紙鍙橀噺鍚� moment锛夛紝鍒紡閰峔nconst now = moment().format('YYYY-MM-DD HH:mm:ss');\n\nconst items = (msg.payload && msg.payload.items) || {};\n\nfunction cln(v) {\n // 鎺ュ彛鎸� ';' 鍒嗘锛屾枃鏈噷鐨勫垎鍙峰繀椤绘礂鎺夛紝鍚﹀垯浼氳褰撴垚棰濆娈礬n return String(v === undefined || v === null ? '' : v).replace(/;/g, '锛�');\n}\nfunction numOrRaw(v) {\n if (v === undefined || v === null || v === '') return 0;\n const n = Number(v);\n return Number.isFinite(n) ? n : String(v);\n}\n\nconst header = {\n HInterID: 0,\n HBillNo: '',\n HDate: now,\n HMainSourceBillNo: '',\n HMainSourceInterID: 0,\n HMainSourceEntryID: 1,\n HProcExchBillNo: '',\n HProcExchInterID: 0,\n HProcExchEntryID: 1,\n HMainSourceBillType: '-1',\n HICMOBillNo: '',\n HICMOInterID: 0,\n HICMOEntryID: 1,\n HSourceName: '',\n HSourceID: numOrRaw(items.mach_id),\n HProcName: '',\n HProcID: 0,\n HMaterNumber: '',\n HMaterCode: '',\n HMaterName: '',\n HMaterSpec: '',\n HMaterID: numOrRaw(items.variety_id),\n HEndWorkTime: now,\n HGroupName: '',\n HGroupID: 0,\n HEmpName: cln(items.worker_name),\n HEmpID: numOrRaw(items.worker_id),\n HDeptName: '',\n HDeptID: 0,\n HWorkShiftName: '',\n HWorkShiftID: numOrRaw(items.shift_id),\n HMaker: 'admin',\n HMakeDate: now,\n HUpDater: '',\n HUpDateDate: '',\n HChecker: '',\n HCheckDate: '',\n HCloseMan: '',\n HDeleteMan: '',\n HCloseDate: '',\n HDeleteDate: ''\n};\n\n// 涓夋寮忥細{鎶ユ枃澶磢;admin;Add\nmsg.payload = {\n msg: JSON.stringify(header) + ';admin;Add'\n};\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
- "libs": [],
+ "libs": [
+ {
+ "var": "moment",
+ "module": "moment"
+ }
+ ],
"x": 1020,
"y": 500,
"wires": [
[
- "5b954fff423a59e1",
- "4f16c5c0b639cbda"
+ "26003aa407573869",
+ "fbc635ec53f6495b"
]
]
},
{
- "id": "4f16c5c0b639cbda",
+ "id": "fbc635ec53f6495b",
"type": "debug",
- "z": "tab_collector_mqtt",
+ "z": "7f2f4359c1fe45f9",
"name": "鏌ョ湅 鐢熸垚鍗曟嵁璐熻浇",
"active": true,
"tosidebar": true,
@@ -1590,14 +1608,24 @@
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
- "x": 1400,
+ "x": 1480,
"y": 600,
"wires": []
},
{
- "id": "e9a1290762230e06",
+ "id": "674c45b1bce6c1fb",
+ "type": "comment",
+ "z": "7f2f4359c1fe45f9",
+ "name": "鍋滃伐鍗曟敞閲�",
+ "info": "鍋滃伐鍗曟湁鍓嶇疆鍗曟嵁銆傝鎯呭喌闇�瑕佷慨鏀箇ebAPI 鏌ョ湅鏄惁闇�瑕佹棤婧愬崟鍋滃伐",
+ "x": 1660,
+ "y": 460,
+ "wires": []
+ },
+ {
+ "id": "a522a559b2e5f1a2",
"type": "inject",
- "z": "yy_multi_collect",
+ "z": "c28cda1b8a90e5a0",
"name": "姣�10s 路 鍏矾閲囬泦/澶辫触閲嶈瘯",
"props": [],
"repeat": "10",
@@ -1609,16 +1637,16 @@
"y": 140,
"wires": [
[
- "fn_yy_q"
+ "a4fb996f8c07a2cf"
]
]
},
{
- "id": "c3e4894ab572dc51",
+ "id": "aac0c56c267ce1c6",
"type": "MSSQL",
- "z": "yy_multi_collect",
+ "z": "c28cda1b8a90e5a0",
"mssqlCN": "04dfbd6bd2067336",
- "name": "鐢ㄥ弸 路 闆嗗悎鍒嗚〃/瀛楀吀鏌ヨ",
+ "name": "鎮犳壃 路 闆嗗悎鍒嗚〃/瀛楀吀鏌ヨ",
"outField": "payload",
"returnType": "0",
"throwErrors": "1",
@@ -1637,15 +1665,15 @@
"y": 100,
"wires": [
[
- "ff402f329edcf253"
+ "1065e56986f4884d"
]
]
},
{
- "id": "ff402f329edcf253",
+ "id": "1065e56986f4884d",
"type": "function",
- "z": "yy_multi_collect",
- "name": "鐢ㄥ弸 路 瀛楀吀鏄犲皠涓烘暟鎹簱瀛楁",
+ "z": "c28cda1b8a90e5a0",
+ "name": "鎮犳壃 路 瀛楀吀鏄犲皠涓烘暟鎹簱瀛楁",
"func": "/**\n * 鐢ㄥ弸瀛楀吀鏄犲皠鏍囧噯鍖朶n * 杈撳叆锛歋QL缁撴灉锛沵sg.yySync\n * 杈撳嚭锛氳緭鍑�1=msg.collectionRows锛涜緭鍑�2=缁х画璋冨害\n * 涓婁笅鏂囷細yy_multi.pending/seen/stats锛涙澶勪笉鎻愬墠鎻愪氦鍐欏簱姘翠綅\n */\n// 鍙淮鎶ゅ瓧鍏革細婧愬瓧娈点�佺洰鏍囧弬鏁般�佸�嶇巼銆佸崟浣嶃�傚垎閽熻浆绉掔殑鍊嶇巼涓�60銆俓nconst config = {\n \"stateMap\": {\n \"1\": 5,\n \"2\": 1,\n \"3\": 3,\n \"4\": 3,\n \"5\": 3,\n \"6\": 3\n },\n \"production\": [{\n \"sourceField\": \"WorkNums\",\n \"parameterName\": \"鐝浜ч噺\",\n \"scale\": 1,\n \"unit\": \"output\"\n }, {\n \"sourceField\": \"ClothWorkNums\",\n \"parameterName\": \"褰撳墠鍖瑰凡鐢熶骇闀垮害\",\n \"scale\": 1,\n \"unit\": \"metres\"\n }, {\n \"sourceField\": \"ProductNums\",\n \"parameterName\": \"鐝鐢熶骇璁℃暟\",\n \"scale\": 1\n }, {\n \"sourceField\": \"StopNums\",\n \"parameterName\": \"鐝鍋滄満娆℃暟\",\n \"scale\": 1\n }, {\n \"sourceField\": \"OpenLong\",\n \"parameterName\": \"鐝寮�鏈烘椂闂�(绉�)\",\n \"scale\": 60\n }, {\n \"sourceField\": \"WorkLong\",\n \"parameterName\": \"鐝杩愯鏃堕棿(绉�)\",\n \"scale\": 60\n }, {\n \"sourceField\": \"StopLong\",\n \"parameterName\": \"鐝鍋滄満鏃堕棿(绉�)\",\n \"scale\": 60\n }, {\n \"sourceField\": \"OffLong\",\n \"parameterName\": \"鐝绂荤嚎鏃堕棿(绉�)\",\n \"scale\": 60\n }, {\n \"sourceField\": \"ZhouTimeLong\",\n \"parameterName\": \"鐝涓婅酱鏃堕棿(绉�)\",\n \"scale\": 60\n }, {\n \"sourceField\": \"ShaTimeLong\",\n \"parameterName\": \"鐝绌跨罕鏃堕棿(绉�)\",\n \"scale\": 60\n }, {\n \"sourceField\": \"RepairTimeLong\",\n \"parameterName\": \"鐝鏈轰慨鏃堕棿(绉�)\",\n \"scale\": 60\n }],\n \"event\": [{\n \"sourceField\": \"ClassOutPut\",\n \"parameterName\": \"鏈彮浜ч噺\",\n \"scale\": 1,\n \"unit\": \"output\"\n }, {\n \"sourceField\": \"ClothOutPut\",\n \"parameterName\": \"褰撳墠鍖瑰凡鐢熶骇闀垮害\",\n \"scale\": 1,\n \"unit\": \"metres\"\n }],\n \"plan\": [{\n \"sourceField\": \"NeedClothNums\",\n \"parameterName\": \"璁㈠崟鍖规暟\",\n \"scale\": 1\n }, {\n \"sourceField\": \"FinishCloth\",\n \"parameterName\": \"宸茬敓浜у尮鏁癨",\n \"scale\": 1\n }, {\n \"sourceField\": \"RealNums\",\n \"parameterName\": \"璁″垝绱浜ч噺\",\n \"scale\": 1,\n \"unit\": \"output\"\n }, {\n \"sourceField\": \"FinishNums\",\n \"parameterName\": \"璁″垝鐩爣浜ч噺\",\n \"scale\": 1,\n \"unit\": \"output\"\n }]\n};\nfunction localTime(date) {\n const d = new Date(date);\n if (!Number.isFinite(d.getTime())) return null;\n const p = n => String(n).padStart(2, '0');\n return d.getFullYear() + '-' + p(d.getMonth() + 1) + '-' + p(d.getDate()) + ' ' + p(d.getHours()) + ':' + p(d.getMinutes()) + ':' + p(d.getSeconds()) + '.' + String(d.getMilliseconds()).padStart(3, '0');\n}\nfunction parseTableCatalog(rows) {\n const roots = {\n speed: 'MachineSpeedInfo',\n state: 'MachineTimeLine',\n production: 'PWorkRecordDetail'\n },\n tables = {\n speed: [],\n state: [],\n production: []\n };\n let bootstrap = null;\n for (const r of rows) {\n if (r.BootstrapSpeed) bootstrap = localTime(r.BootstrapSpeed);\n for (const [k, root] of Object.entries(roots)) {\n if (typeof r.TableName === 'string' && new RegExp('^' + root + '[12]\\\\d{3}(0[1-9]|1[0-2])$').test(r.TableName)) tables[k].push(r.TableName);\n }\n }\n for (const k of Object.keys(tables)) tables[k] = [...new Set(tables[k])].sort();\n return {\n tables,\n bootstrap\n };\n}\nfunction canonicalParameterName(parameterName) {\n const aliases = {\n '杞��': '鏈哄櫒杞��',\n '鐝骞冲潎杞﹂��': '鐝骞冲潎杞��',\n '鏈彮浜ч噺': '鐝浜ч噺(婧愬崟浣�)',\n '鏈彮鏁堢巼': '鐝鏁堢巼(%)',\n '鏈彮鍋滄満娆℃暟': '鐝鍋滄満娆℃暟',\n '鏈彮鍋滄満鏃堕棿(绉�)': '鐝鍋滄満鏃堕棿(绉�)',\n '鏈尮浜ч噺': '鏈尮浜ч噺(婧愬崟浣�)'\n };\n const name = String(parameterName);\n // 鐢ㄥ弸浜嬩欢閲岀殑鏈彮浜ч噺闄勬湁瀹為檯鍗曚綅锛屾部鐢ㄥ悓涓�鐝浜ч噺鍚嶇О銆俓n const withUnit = /^鏈彮浜ч噺\\((.+)\\)$/.exec(name);\n if (withUnit) return '鐝浜ч噺(' + withUnit[1] + ')';\n return aliases[name] || name;\n}\nfunction createCollectionRow(source, deviceCode, parameterName, value, collectedAt, createdAt) {\n const amount = Math.round(Number(value) * 100) / 100;\n return {\n HItemID: null,\n // SQL Server 鑷锛孊ulk 涓嶄紶姝ゅ垪\n HDate: new Date(collectedAt),\n // 閲囨牱鏃堕棿/婧愯澶囨椂闂碶n HSourceCode: String(deviceCode).slice(0, 50),\n HTechParamID: 0,\n // 娌跨敤鐜版湁鐩爣琛ㄧ害瀹歕n HTechParamName: canonicalParameterName(parameterName).slice(0, 500),\n HCount: amount,\n // SQL decimal(18,2)\n HCreateTime: new Date(createdAt),\n // 鏍囧噯鍖栧垱寤烘椂闂达紱閲嶈瘯淇濇寔涓嶅彉\n HResult: String(amount).slice(0, 50),\n HProcNumber: String(source).slice(0, 50),\n // WY / YY / MQTT\n HFlag: 0\n };\n}\nfunction collectionRowKey(row) {\n // 淇濈暀鍘熸湁鑷劧閿紪鐮侊紝鍏煎鏃у緟纭鎵规鐨� doneKeys銆俓n return row.HProcNumber + '|' + row.HSourceCode + '|' + row.HTechParamName + '|' + new Date(row.HDate).getTime();\n}\nfunction mapYouyangSourceRows(stream, sourceRows, previousSignatures) {\n const collectionRows = [];\n const nextSeen = {};\n const createdAt = new Date();\n let cursor = null;\n let unknownStates = 0;\n function addParameter(sourceRow, parameterName, value, collectedAt = sourceRow.RowTime) {\n if (value === null || value === undefined || value === '' || !Number.isFinite(Number(value))) return;\n const date = new Date(collectedAt);\n if (!Number.isFinite(date.getTime())) return;\n const deviceCode = 'YY-' + String(sourceRow.MachineID).padStart(2, '0');\n collectionRows.push(createCollectionRow('YY', deviceCode, parameterName, value, date, createdAt));\n }\n function addMappedParameters(sourceRow, fieldMappings, namePrefix = '') {\n const outputUnit = String(sourceRow.OutPutUnit || '').trim();\n for (const mapping of fieldMappings) {\n // 浜旀磱鈥滃綋鍓嶅尮宸茬敓浜ч暱搴︹�濆彛寰勪负绫筹紱婧愬崟浣嶄笉鏄庢垨涓哄叕鏂ゆ椂涓嶅己琛屾槧灏勩�俓n if (mapping.unit === 'metres' && !/^(绫硘m|M|meter|metre)$/.test(outputUnit)) continue;\n let parameterName = namePrefix + mapping.parameterName;\n if (mapping.unit === 'output') parameterName += '(' + (outputUnit || '婧愬崟浣�') + ')';\n const sourceValue = sourceRow[mapping.sourceField];\n const value = sourceValue === null || sourceValue === undefined ? null : Number(sourceValue) * mapping.scale;\n addParameter(sourceRow, parameterName, value);\n }\n }\n for (const sourceRow of sourceRows) {\n const collectedAt = localTime(sourceRow.RowTime);\n if (!collectedAt || sourceRow.MachineID === null || sourceRow.MachineID === undefined) {\n throw new Error('鏃犳晥璁惧鎴栭噰闆嗘椂闂达紝鍋滄鎺ㄨ繘澧為噺姘翠綅');\n }\n cursor = {\n time: collectedAt,\n table: sourceRow.SourceTable,\n id: sourceRow.id\n };\n if (stream === 'speed') {\n addParameter(sourceRow, '鏈哄櫒杞��', sourceRow.SpeedValue);\n } else if (stream === 'state') {\n const stateCode = config.stateMap[String(sourceRow.MainType)];\n if (stateCode === undefined) {\n unknownStates += 1;\n addParameter(sourceRow, '鎮犳壃鍘熷鐘舵�佺爜', sourceRow.MainType);\n } else addParameter(sourceRow, '杩愯鐘舵��', stateCode);\n } else if (stream === 'production') {\n addMappedParameters(sourceRow, config.production);\n if (Number(sourceRow.OpenLong) > 0 && sourceRow.WorkLong !== null && sourceRow.WorkLong !== undefined) {\n addParameter(sourceRow, '鐝杩愯鏁堢巼(%)', Number(sourceRow.WorkLong) / Number(sourceRow.OpenLong) * 100);\n }\n } else if (stream === 'event') {\n addMappedParameters(sourceRow, config.event);\n } else if (stream === 'snapshot' || stream === 'plan') {\n const signatureKey = stream + '|' + sourceRow.FactoryID + '|' + sourceRow.MachineID + '|' + (sourceRow.PlanID || sourceRow.id);\n const stableFields = Object.fromEntries(Object.entries(sourceRow).filter(([name]) => name !== 'RowTime'));\n const signature = JSON.stringify(stableFields);\n nextSeen[signatureKey] = signature;\n if (previousSignatures[signatureKey] === signature) continue;\n if (stream === 'snapshot') {\n const currentMappings = config.production.filter(mapping => !['ProductNums', 'ClothWorkNums'].includes(mapping.sourceField));\n addMappedParameters(sourceRow, currentMappings, '褰撳墠');\n addMappedParameters(sourceRow, config.production.filter(mapping => mapping.sourceField === 'ClothWorkNums'));\n const stateCode = config.stateMap[String(sourceRow.WorkState)];\n if (stateCode !== undefined && sourceRow.StateLastUpdate) {\n addParameter(sourceRow, '杩愯鐘舵��', stateCode, sourceRow.StateLastUpdate);\n }\n } else addMappedParameters(sourceRow, config.plan);\n }\n }\n const uniqueRows = new Map();\n for (const row of collectionRows) uniqueRows.set(collectionRowKey(row), row);\n return {\n collectionRows: Array.from(uniqueRows.values()),\n cursor,\n nextSeen,\n unknownStates\n };\n}\nfunction normalizeYouyangQueryResult(msg, flow, global, node) {\n const state = flow.get('yy_multi');\n const batchMeta = msg.yySync;\n if (!state || !batchMeta) return null;\n if (batchMeta.stream === 'catalog') {\n if (state.sourceBusy?.batchId !== batchMeta.batchId) return null;\n const catalog = parseTableCatalog(Array.isArray(msg.payload) ? msg.payload : []);\n state.catalog = {\n ...catalog,\n at: Date.now(),\n month: localTime(new Date()).slice(0, 7),\n from: state.from\n };\n if (!state.manualBackfill && !state.cursors.speed && catalog.bootstrap && catalog.bootstrap > state.from) {\n state.cursors.speed = {\n time: catalog.bootstrap,\n table: '',\n id: 0\n };\n }\n delete state.sourceBusy;\n flow.set('yy_multi', state);\n return [null, {\n yyDrain: true\n }];\n }\n const pending = state.pending[batchMeta.stream];\n if (pending?.batchId !== batchMeta.batchId) return null;\n const sourceRows = Array.isArray(msg.payload) ? msg.payload : [];\n const result = mapYouyangSourceRows(batchMeta.stream, sourceRows, state.seen[batchMeta.stream] || {});\n pending.cursor = result.cursor;\n pending.nextSeen = result.nextSeen;\n delete state.sourceBusy;\n state.stats[batchMeta.stream] = {\n ...(state.stats[batchMeta.stream] || {}),\n read: sourceRows.length,\n candidates: result.collectionRows.length,\n lastQuery: new Date().toISOString()\n };\n if (result.unknownStates) node.warn(batchMeta.stream + ' 鍚湭璇嗗埆鐘舵�侊紝淇濈暀鍘熷鐘舵�佺爜');\n if (!result.collectionRows.length) {\n if (result.cursor && !['snapshot', 'plan'].includes(batchMeta.stream)) state.cursors[batchMeta.stream] = result.cursor;\n if (['snapshot', 'plan'].includes(batchMeta.stream)) state.seen[batchMeta.stream] = result.nextSeen;\n delete state.pending[batchMeta.stream];\n flow.set('yy_multi', state);\n return [null, {\n yyDrain: true\n }];\n }\n const output = {\n collectionRows: result.collectionRows,\n payload: result.collectionRows,\n yySync: {\n ...batchMeta,\n phase: 'buffer',\n count: result.collectionRows.length\n }\n };\n pending.write = output;\n pending.stage = 'buffer';\n pending.count = result.collectionRows.length;\n pending.retryAt = Date.now() + 10000;\n flow.set('yy_multi', state);\n node.status({\n fill: 'blue',\n shape: 'dot',\n text: batchMeta.stream + ' ' + sourceRows.length + '琛� 鈫� 缂撳啿 ' + result.collectionRows.length + '椤�'\n });\n return [output, null];\n}\nreturn normalizeYouyangQueryResult(msg, flow, global, node);\n",
"outputs": 2,
"timeout": 0,
@@ -1657,17 +1685,17 @@
"y": 120,
"wires": [
[
- "yy_data_out"
+ "a98e74f1e5a11dde"
],
[
- "fn_yy_q"
+ "a4fb996f8c07a2cf"
]
]
},
{
- "id": "fn_yy_q",
+ "id": "a4fb996f8c07a2cf",
"type": "function",
- "z": "yy_multi_collect",
+ "z": "c28cda1b8a90e5a0",
"name": "闆嗗悎鏌ヨ璋冨害 路 鍒嗚〃缂撳瓨/澧為噺姘翠綅",
"func": "/**\n * 鐢ㄥ弸鍒嗚矾璋冨害\n * 杈撳叆锛�10绉掕Е鍙戞垨msg.yyDrain锛涙棫寰呯‘璁ゆ壒娆″吋瀹筡n * 杈撳嚭锛氳緭鍑�1=涓茶婧愭煡璇紱杈撳嚭2=灏氭湭鍏ラ槦鍘熸壒閲嶆姇\n * 涓婁笅鏂囷細yy_multi锛歠rom/catalog/cursors/pending/sourceBusy/queue\n */\n// 璋冨害閰嶇疆锛涘瓧娈垫槧灏勯泦涓湪涓嬫父鈥滅敤鍙� 路 瀛楀吀鏄犲皠涓烘暟鎹簱瀛楁鈥濊妭鐐广�俓nconst config = {\n \"lookbackDays\": 30,\n \"batchRows\": 400,\n \"pollSeconds\": 10\n};\nfunction localTime(date) {\n const d = new Date(date);\n if (!Number.isFinite(d.getTime())) return null;\n const p = n => String(n).padStart(2, '0');\n return d.getFullYear() + '-' + p(d.getMonth() + 1) + '-' + p(d.getDate()) + ' ' + p(d.getHours()) + ':' + p(d.getMinutes()) + ':' + p(d.getSeconds()) + '.' + String(d.getMilliseconds()).padStart(3, '0');\n}\nfunction buildCatalogQuery(from, bootstrap) {\n return {\n query: `SET NOCOUNT ON;\nDECLARE @from datetime=CONVERT(datetime,@fromText,121),@speed datetime;\nIF @bootstrap=1 SELECT @speed=MAX(HDate) FROM HX_LMESsys.dbo.Sb_EquipMentCollectionTechParam_Temp WHERE HProcNumber='YY' AND HTechParamName='鏈哄櫒杞��' AND HDate>=@from;\nSELECT t.name AS TableName,@speed AS BootstrapSpeed FROM sys.tables t JOIN sys.schemas s ON s.schema_id=t.schema_id\nWHERE s.name='dbo' AND (t.name LIKE 'MachineSpeedInfo[12][0-9][0-9][0-9][01][0-9]' OR t.name LIKE 'MachineTimeLine[12][0-9][0-9][0-9][01][0-9]' OR t.name LIKE 'PWorkRecordDetail[12][0-9][0-9][0-9][01][0-9]')\nAND RIGHT(t.name,2) BETWEEN '01' AND '12'\nAND RIGHT(t.name,6)>=CONVERT(char(6),DATEADD(month,-1,@from),112) AND RIGHT(t.name,6)<=CONVERT(char(6),GETDATE(),112)\nUNION ALL SELECT NULL,@speed;`,\n queryParams: [{\n name: 'fromText',\n type: 'varchar(23)',\n value: from\n }, {\n name: 'bootstrap',\n type: 'bit',\n value: bootstrap ? 1 : 0\n }]\n };\n}\nfunction buildSourceQuery(stream, watermark, from, catalog, config) {\n const monthly = {\n speed: {\n root: 'MachineSpeedInfo',\n time: 's.SpeedTime',\n fields: 's.SpeedValue'\n },\n state: {\n root: 'MachineTimeLine',\n time: 'COALESCE(s.LastUpDate,s.BeginTime)',\n fields: 's.MainType,s.DetailType,s.StateName'\n },\n production: {\n root: 'PWorkRecordDetail',\n time: 'COALESCE(s.LastUpDate,s.WorkEndTime,s.WorkBeginTime)',\n fields: 's.WorkNums,s.ClothWorkNums,s.ProductNums,s.OpenLong,s.StopNums,s.StopLong,s.OffLong,s.WorkLong,s.ZhouTimeLong,s.ShaTimeLong,s.RepairTimeLong'\n }\n };\n let query;\n const header = 'SET NOCOUNT ON; DECLARE @from datetime=CONVERT(datetime,@fromText,121),@wm datetime=CONVERT(datetime,@cursorText,121); IF @wm IS NULL SET @wm=@from;\\n';\n if (monthly[stream]) {\n const def = monthly[stream];\n let tables = (catalog.tables[stream] || []).filter(name => new RegExp('^' + def.root + '[12]\\\\d{3}(0[1-9]|1[0-2])$').test(name));\n // 閫熷害閲囨牱鏃堕棿褰掑睘璇ユ湀浠斤紝宸茶瀹岀殑鏃ф湀鏃犻渶鍐嶆鎵弿銆傚彲鍙樼姸鎬�/鐝浠嶆壂鎻忕獥鍙e唴鐨勫墠鏈堣〃銆俓n if (stream === 'speed' && watermark?.time) {\n const ym = watermark.time.slice(0, 7).replace('-', '');\n tables = tables.filter(t => t.slice(-6) >= ym);\n }\n const parts = tables.map((name, i) => `SELECT * FROM (SELECT TOP (@take) s.id,s.MachineID,s.FactoryID,CAST(N'${name}' AS nvarchar(128)) AS SourceTable,${def.fields},${def.time} AS RowTime FROM dbo.[${name}] s WHERE ${def.time}>=@from AND (${def.time}>@wm OR (${def.time}=@wm AND (N'${name}'>@cursorTable OR (N'${name}'=@cursorTable AND s.id>@cursorId)))) ORDER BY ${def.time},s.id) p${i}`);\n query = header + (parts.length ? `WITH candidates AS (${parts.join('\\nUNION ALL\\n')}), page AS (SELECT TOP (@take) * FROM candidates ORDER BY RowTime,SourceTable,id)\nSELECT p.*,m.MachineNo,mt.OutPutUnit,mt.SpeedUnitName FROM page p\nLEFT JOIN StandPublicDB.dbo.PMachineNo m ON m.FactoryID=p.FactoryID AND m.MachineID=p.MachineID\nLEFT JOIN StandPublicDB.dbo.MachineType mt ON mt.TypeID=m.MachineType\nORDER BY p.RowTime,p.SourceTable,p.id;` : 'SELECT CAST(NULL AS int) AS id,CAST(NULL AS datetime) AS RowTime WHERE 1=0;');\n } else if (stream === 'event') {\n query = header + `WITH page AS (SELECT TOP (@take) s.id,s.MachineID,CAST(N'EventInfo' AS nvarchar(128)) AS SourceTable,COALESCE(s.SaveTime,s.DoTime) AS RowTime,s.DoTime,s.EventName,s.ClassOutPut,s.ClothOutPut,s.OpState\nFROM dbo.EventInfo s WHERE COALESCE(s.SaveTime,s.DoTime)>=@from AND (COALESCE(s.SaveTime,s.DoTime)>@wm OR (COALESCE(s.SaveTime,s.DoTime)=@wm AND s.id>@cursorId)) ORDER BY COALESCE(s.SaveTime,s.DoTime),s.id)\nSELECT p.*,m.MachineNo,mt.OutPutUnit,mt.SpeedUnitName FROM page p\nLEFT JOIN StandPublicDB.dbo.PMachineNo m ON m.MachineID=p.MachineID\nLEFT JOIN StandPublicDB.dbo.MachineType mt ON mt.TypeID=m.MachineType ORDER BY p.RowTime,p.id;`;\n } else if (stream === 'snapshot') {\n query = header + `SELECT s.id,s.MachineID,s.FactoryID,CAST(N'A_PWorkRecordDetail' AS nvarchar(128)) AS SourceTable,GETDATE() AS RowTime,s.WorkBeginTime,s.WorkEndTime,s.WorkNums,s.ClothWorkNums,s.ProductNums,s.OpenLong,s.StopNums,s.StopLong,s.OffLong,s.WorkLong,s.ZhouTimeLong,s.ShaTimeLong,s.RepairTimeLong,m.MachineNo,mt.OutPutUnit,mt.SpeedUnitName,st.WorkState,st.StateLastUpdate\nFROM dbo.A_PWorkRecordDetail s LEFT JOIN StandPublicDB.dbo.PMachineNo m ON m.FactoryID=s.FactoryID AND m.MachineID=s.MachineID\nLEFT JOIN StandPublicDB.dbo.MachineType mt ON mt.TypeID=m.MachineType LEFT JOIN StandPublicDB.dbo.MachineState st ON st.FactoryID=s.FactoryID AND st.MachineID=s.MachineID\nWHERE s.WorkBeginTime>=@from AND s.WorkEndTime IS NULL ORDER BY s.FactoryID,s.MachineID,s.id;`;\n } else if (stream === 'plan') {\n query = header + `SELECT pc.id,pc.MachineID,pc.FactoryID,CAST(N'ProductPlanPC' AS nvarchar(128)) AS SourceTable,GETDATE() AS RowTime,pc.PlanID,pc.DoDate,pc.RealNums,pc.FinishNums,pc.FinishCloth,b.NeedClothNums,b.Unit AS OutPutUnit,m.MachineNo\nFROM dbo.ProductPlanPC pc JOIN dbo.ProductPlanBill b ON b.FactoryID=pc.FactoryID AND b.PlanID=pc.PlanID LEFT JOIN StandPublicDB.dbo.PMachineNo m ON m.FactoryID=pc.FactoryID AND m.MachineID=pc.MachineID\nWHERE pc.FinishDate IS NULL AND COALESCE(pc.StartDate,pc.DoDate)>=@from ORDER BY pc.FactoryID,pc.MachineID,pc.PlanID;`;\n } else throw Error('Unknown stream ' + stream);\n return {\n query,\n queryParams: [{\n name: 'fromText',\n type: 'varchar(23)',\n value: from\n }, {\n name: 'cursorText',\n type: 'varchar(23)',\n value: watermark?.time || null\n }, {\n name: 'cursorTable',\n type: 'nvarchar(128)',\n value: watermark?.table || ''\n }, {\n name: 'cursorId',\n type: 'int',\n value: watermark?.id || 0\n }, {\n name: 'take',\n type: 'int',\n value: config.batchRows\n }]\n };\n}\nfunction collectItems(items) {\n const groups = new Map();\n for (const it of items) {\n const key = it.device + '|' + it.time;\n let group = groups.get(key);\n if (!group) {\n group = {\n src: 'YY',\n device: it.device,\n ts: new Date(it.time.replace(' ', 'T')),\n u: 'loc',\n data: {}\n };\n groups.set(key, group);\n }\n group.data[it.name] = it.value;\n }\n return [...groups.values()];\n}\nfunction readLegacyCollect(write) {\n if (Array.isArray(write?.collect)) return write.collect;\n const xml = write?.queryParams?.find(p => p.name === 'rowsXml')?.value;\n if (typeof xml !== 'string') return null;\n const decode = s => s.replace(/"/g, '\"').replace(/'/g, \"'\").replace(/</g, '<').replace(/>/g, '>').replace(/&/g, '&');\n const rows = [];\n for (const match of xml.matchAll(/<r\\s+d=\"([^\"]*)\"\\s+p=\"([^\"]*)\"\\s+v=\"([^\"]*)\"\\s+t=\"([^\"]*)\"\\s*\\/>/g)) rows.push({\n device: decode(match[1]),\n name: decode(match[2]),\n value: Number(decode(match[3])),\n time: decode(match[4])\n });\n return rows.length ? collectItems(rows) : null;\n}\nfunction legacyCollectToRows(collect, createdAt) {\n // 鍙敤浜庡崌绾у墠缂撳瓨鐨� pending.write锛涗笁璺柊娑堟伅閮界洿鎺ヨ緭鍑� collectionRows銆俓n const rows = [];\n for (const item of collect || []) {\n const collectedAt = new Date(item.ts);\n if (!Number.isFinite(collectedAt.getTime())) continue;\n for (const [parameterName, value] of Object.entries(item.data || {})) {\n if (value === null || value === undefined || value === '') continue;\n if (!Number.isFinite(Number(value))) continue;\n // 宸茬瓑寰呯‘璁ょ殑鏃ф壒涓嶆敼鍚嶏紝淇濊瘉涓庝箣鍓嶅凡钀藉簱閮ㄥ垎鐨勯槻閲嶉敭涓�鑷淬�俓n rows.push({\n HItemID: null,\n HDate: collectedAt,\n HSourceCode: String(item.device).slice(0, 50),\n HTechParamID: 0,\n HTechParamName: parameterName.slice(0, 500),\n HCount: Math.round(Number(value) * 100) / 100,\n HCreateTime: new Date(createdAt),\n HResult: String(Math.round(Number(value) * 100) / 100).slice(0, 50),\n HProcNumber: item.src,\n HFlag: 0\n });\n }\n }\n return rows;\n}\nfunction scheduleYouyangQueries(msg, flow, global, node) {\n if (global.get('collection_paused') !== false) {\n node.status({\n fill: 'yellow',\n shape: 'ring',\n text: '閲囬泦宸叉殏鍋�'\n });\n return null;\n }\n const now = Date.now();\n const state = flow.get('yy_multi') || {\n from: localTime(new Date(now - config.lookbackDays * 86400000))\n };\n for (const name of ['cursors', 'pending', 'seen', 'stats']) state[name] = state[name] || {};\n state.queue = state.queue || [];\n const retryMessages = [];\n\n // 1. 閲嶆姇鈥滃皻鏈叆闃熲�濈殑鍘熸壒锛涘凡鍏ラ槦鐨勬壒娆$敱鍏叡Bulk閲嶈瘯锛屼笉閲嶅鍏ラ槦銆俓n for (const pending of Object.values(state.pending)) {\n if (pending.write && !pending.stage) {\n const legacyCollect = readLegacyCollect(pending.write);\n if (!legacyCollect) {\n node.error('鏃у緟纭鎵规鏃犳硶杩佺Щ锛岃淇濈暀鍘熸壒妫�鏌�');\n return null;\n }\n pending.write = {\n collectionRows: legacyCollectToRows(legacyCollect, new Date()),\n yySync: {\n ...pending.write.yySync,\n phase: 'buffer'\n }\n };\n pending.stage = 'buffer';\n pending.retryAt = now;\n }\n if (pending.stage === 'buffer' && (!pending.retryAt || now >= pending.retryAt) && pending.write) {\n pending.retryAt = now + 10000;\n retryMessages.push(pending.write);\n }\n }\n\n // 2. 姣忚疆鍏矾鍚勮涓�娆★紱鏁版嵁搴撴煡璇覆琛岋紝鍏ラ槦鍚庣殑鎵规鍙悓鏃剁瓑寰匓ulk纭銆俓n if (!msg.yyDrain && !state.queue.length) {\n state.queue = ['speed', 'state', 'production', 'event', 'snapshot', 'plan'].filter(stream => !state.pending[stream]);\n }\n const bufferedCount = Object.values(state.pending).filter(pending => pending.stage === 'queued').reduce((total, pending) => total + (pending.count || 0), 0);\n if (state.sourceBusy || bufferedCount >= 20000) {\n flow.set('yy_multi', state);\n return [[], retryMessages];\n }\n\n // 3. 鍏堝埛鏂拌繃鏈熺殑鍒嗚〃娓呭崟锛涜法鏈堝拰鏀瑰彉鍥炶ˉ璧风偣涔熶細澶辨晥銆俓n const currentMonth = localTime(new Date(now)).slice(0, 7);\n const catalog = state.catalog;\n const catalogExpired = !catalog || catalog.from !== state.from || catalog.month !== currentMonth || now - catalog.at > 300000;\n if (state.queue.length && catalogExpired) {\n const batchMeta = {\n stream: 'catalog',\n batchId: 'catalog-' + now,\n phase: 'query'\n };\n const allowBootstrap = !state.manualBackfill && !state.cursors.speed;\n state.sourceBusy = batchMeta;\n flow.set('yy_multi', state);\n return [[{\n ...buildCatalogQuery(state.from, allowBootstrap),\n yySync: batchMeta\n }], retryMessages];\n }\n let nextStream;\n while (state.queue.length) {\n const candidate = state.queue.shift();\n if (!state.pending[candidate]) {\n nextStream = candidate;\n break;\n }\n }\n const queryMessages = [];\n if (nextStream) {\n const batchMeta = {\n stream: nextStream,\n batchId: nextStream + '-' + now + '-' + Math.random().toString(16).slice(2),\n phase: 'query'\n };\n state.pending[nextStream] = {\n batchId: batchMeta.batchId,\n startedAt: now,\n stage: 'query'\n };\n state.sourceBusy = batchMeta;\n queryMessages.push({\n ...buildSourceQuery(nextStream, state.cursors[nextStream], state.from, state.catalog, config),\n yySync: batchMeta\n });\n }\n flow.set('yy_multi', state);\n node.status({\n fill: 'blue',\n shape: 'dot',\n text: '闆嗗悎鏌ヨ ' + (nextStream || '绛夊緟Bulk纭') + ' / 閲嶈瘯 ' + retryMessages.length\n });\n return [queryMessages, retryMessages];\n}\nreturn scheduleYouyangQueries(msg, flow, global, node);\n",
"outputs": 2,
@@ -1680,46 +1708,46 @@
"y": 220,
"wires": [
[
- "c3e4894ab572dc51"
+ "aac0c56c267ce1c6"
],
[
- "yy_data_out"
+ "a98e74f1e5a11dde"
]
]
},
{
- "id": "yy_data_out",
+ "id": "a98e74f1e5a11dde",
"type": "link out",
- "z": "yy_multi_collect",
+ "z": "c28cda1b8a90e5a0",
"name": "鐢ㄥ弸鏍囧噯鏁版嵁 鈫� 鍏辩敤缂撳啿",
"mode": "link",
"links": [
- "yy_write_in"
+ "f7cc1e3161399854"
],
"x": 1305,
"y": 160,
"wires": []
},
{
- "id": "yy_ack_in",
+ "id": "36e0130220d85ae0",
"type": "link in",
- "z": "yy_multi_collect",
+ "z": "c28cda1b8a90e5a0",
"name": "鍏辩敤Bulk瀹屾暣鎵规纭",
"links": [
- "yy_ack_out"
+ "8cd53de2a6cf935d"
],
"x": 165,
"y": 340,
"wires": [
[
- "yy_commit"
+ "2fac9c2f3af2d3b4"
]
]
},
{
- "id": "yy_commit",
+ "id": "2fac9c2f3af2d3b4",
"type": "function",
- "z": "yy_multi_collect",
+ "z": "c28cda1b8a90e5a0",
"name": "Bulk鍏ㄩ儴纭 鈫� 鎻愪氦澧為噺姘翠綅",
"func": "/**\n * 鐢ㄥ弸瀹屾暣鎵规纭\n * 杈撳叆锛歮sg.yySync锛沵sg.yyAck鎴栨煡璇㈤敊璇痋n * 杈撳嚭锛氳緭鍑�1=缁熻锛涜緭鍑�2=璋冨害缁х画淇″彿\n * 涓婁笅鏂囷細yy_multi.cursors/seen浠呭湪鏁存壒committed鏃舵帹杩沑n */\nfunction commitYouyangWatermark(msg, flow, global, node) {\n const state = flow.get('yy_multi');\n const batchMeta = msg.yySync;\n if (!state || !batchMeta) return null;\n\n // 鏌ヨ閿欒鍙噴鏀炬簮鏌ヨ閿侊紝涓嶈兘鏇存敼宸茬‘璁ゆ按浣嶃�俓n if (msg.error) {\n if (state.sourceBusy?.batchId !== batchMeta.batchId) return null;\n if (batchMeta.stream !== 'catalog' && state.pending[batchMeta.stream]?.batchId === batchMeta.batchId) delete state.pending[batchMeta.stream];\n delete state.sourceBusy;\n delete state.catalog;\n flow.set('yy_multi', state);\n return [{\n payload: {\n stream: batchMeta.stream,\n error: msg.error.message || msg.error,\n retry: true\n }\n }, {\n yyDrain: true\n }];\n }\n const pending = state.pending[batchMeta.stream];\n if (pending?.batchId !== batchMeta.batchId) return null;\n const acknowledgement = msg.yyAck;\n if (!acknowledgement) return null;\n if (acknowledgement.kind === 'queued' || acknowledgement.kind === 'retrying') {\n pending.stage = 'queued';\n pending.retryAt = null;\n flow.set('yy_multi', state);\n node.status({\n fill: acknowledgement.kind === 'retrying' ? 'yellow' : 'blue',\n shape: 'ring',\n text: batchMeta.stream + ' 缂撳啿寰匓ulk纭'\n });\n return [null, {\n yyDrain: true\n }];\n }\n if (acknowledgement.kind === 'deferred') {\n pending.stage = 'buffer';\n pending.retryAt = Date.now() + 10000;\n flow.set('yy_multi', state);\n return [{\n payload: {\n stream: batchMeta.stream,\n deferred: acknowledgement.reason\n }\n }, {\n yyDrain: true\n }];\n }\n if (acknowledgement.kind !== 'committed' || !Number.isFinite(acknowledgement.inserted) || !Number.isFinite(acknowledgement.skipped)) return null;\n\n // 鍙湁鏁存壒committed鍥炴墽鎵嶈兘鎺ㄨ繘鏃堕棿/琛�/ID姘翠綅锛屾垨鎻愪氦蹇収鎸囩汗銆俓n if (pending.cursor && !['snapshot', 'plan'].includes(batchMeta.stream)) state.cursors[batchMeta.stream] = pending.cursor;\n if (['snapshot', 'plan'].includes(batchMeta.stream)) state.seen[batchMeta.stream] = pending.nextSeen || {};\n const previousStats = state.stats[batchMeta.stream] || {};\n state.stats[batchMeta.stream] = {\n ...previousStats,\n written: (previousStats.written || 0) + acknowledgement.inserted,\n skipped: (previousStats.skipped || 0) + acknowledgement.skipped,\n lastSuccess: new Date().toISOString()\n };\n delete state.pending[batchMeta.stream];\n flow.set('yy_multi', state);\n node.status({\n fill: 'green',\n shape: 'dot',\n text: batchMeta.stream + ' 鍐欏叆 ' + acknowledgement.inserted + ' / 宸叉湁 ' + acknowledgement.skipped\n });\n return [{\n payload: {\n stream: batchMeta.stream,\n inserted: acknowledgement.inserted,\n skipped: acknowledgement.skipped,\n cursor: state.cursors[batchMeta.stream] || null\n }\n }, {\n yyDrain: true\n }];\n}\nreturn commitYouyangWatermark(msg, flow, global, node);\n",
"outputs": 2,
@@ -1732,18 +1760,18 @@
"y": 340,
"wires": [
[
- "yy_result_debug"
+ "a97adb1ca042aaf1"
],
[
- "fn_yy_q"
+ "a4fb996f8c07a2cf"
]
]
},
{
- "id": "yy_result_debug",
+ "id": "a97adb1ca042aaf1",
"type": "debug",
- "z": "yy_multi_collect",
- "name": "鐢ㄥ弸 路 鏁村悎鍏ュ簱缁撴灉",
+ "z": "c28cda1b8a90e5a0",
+ "name": "鎮犳壃 路 鏁村悎鍏ュ簱缁撴灉",
"active": false,
"tosidebar": true,
"console": false,
@@ -1757,28 +1785,28 @@
"wires": []
},
{
- "id": "yy_query_catch",
+ "id": "87112d21de854e20",
"type": "catch",
- "z": "yy_multi_collect",
+ "z": "c28cda1b8a90e5a0",
"name": "鏌ヨ/鏄犲皠寮傚父",
"scope": [
- "fn_yy_q",
- "c3e4894ab572dc51",
- "ff402f329edcf253"
+ "a4fb996f8c07a2cf",
+ "aac0c56c267ce1c6",
+ "1065e56986f4884d"
],
"uncaught": false,
"x": 190,
"y": 420,
"wires": [
[
- "yy_commit"
+ "2fac9c2f3af2d3b4"
]
]
},
{
- "id": "yy_note",
+ "id": "723559773325b3fe",
"type": "comment",
- "z": "yy_multi_collect",
+ "z": "c28cda1b8a90e5a0",
"name": "闆嗗悎鏌ヨ 鈫� 铏氭嫙閾炬帴 鈫� 鍏辩敤缂撳啿/Bulk 鈫� 鍏ㄦ壒纭鍚庢帹杩涙按浣�",
"info": "鐢ㄥ弸澶氳〃閲囬泦锛氬垎琛ㄦ竻鍗曠紦瀛�5鍒嗛挓锛岄泦鍚堝垎椤垫煡璇紱淇濈暀(time,SourceTable,id)澧為噺姘翠綅銆傚瓧娈垫槧灏勭粡铏氭嫙閾炬帴杩涘叆MSSQL鏁版嵁鍚屾椤祍ync_rows鍐呭瓨缂撳啿锛�5绉�/鏈�澶�5000琛屽叡鐢˙ulk鍐欏叆HX_LMESsys.dbo.Sb_EquipMentCollectionTechParam_Temp銆傚彧鏈夋暣鎵规彃鍏�/闃查噸璺宠繃鍏ㄩ儴纭鍚庢墠鎻愪氦姘翠綅銆傛殏鍋滀笉娓呯┖缂撳啿锛屽け璐ュ師鎵瑰洖濉�� 瀛楁瀛楀吀鍜屽垎閽熻浆绉掕鍒欎繚鎸佸師閰嶇疆锛涘吋瀹筍QL Server绾у埆100锛屼笉闇�瑕丱PENJSON/STRING_AGG銆俓n2026-10-25瀛楁鐗堬細涓夎矾缁熶竴msg.collectionRows锛屼娇鐢ㄧ洰鏍囪〃瀹屾暣鍒楀悕銆侶ItemID涓鸿嚜澧炲崰浣峮ull锛孊ulk涓嶄紶銆傜敤鍙嬫壒娆″紩鐢ㄦ斁鍦ㄧ紦鍐茶_sync.yyBatchIds涓紝涓嶄綔涓烘暟鎹簱鍒椼��",
"x": 260,
@@ -1786,9 +1814,9 @@
"wires": []
},
{
- "id": "yy_manual_poll",
+ "id": "d27e4e59728cdfee",
"type": "inject",
- "z": "yy_multi_collect",
+ "z": "c28cda1b8a90e5a0",
"name": "绔嬪嵆閲囬泦/閲嶈瘯",
"props": [],
"repeat": "",
@@ -1800,30 +1828,30 @@
"y": 200,
"wires": [
[
- "fn_yy_q"
+ "a4fb996f8c07a2cf"
]
]
},
{
- "id": "yy_control_in",
+ "id": "aafd6d7e2e7385f5",
"type": "link in",
- "z": "yy_multi_collect",
+ "z": "c28cda1b8a90e5a0",
"name": "鈫� 鍘熼〉绛炬按浣�/鍥炶ˉ缁存姢",
"links": [
- "yy_control_out"
+ "2d3cdf62e602bda6"
],
"x": 165,
"y": 530,
"wires": [
[
- "yy_control_apply"
+ "5349e5e2dab9b33a"
]
]
},
{
- "id": "yy_control_apply",
+ "id": "5349e5e2dab9b33a",
"type": "function",
- "z": "yy_multi_collect",
+ "z": "c28cda1b8a90e5a0",
"name": "搴旂敤鍥炶ˉ璧风偣 路 淇濈暀鏈畬鎴愭壒娆�",
"func": "/**\n * 搴旂敤鐢ㄥ弸鍥炶ˉ璧风偣\n * 杈撳叆锛歮sg.yyControl.from=鏈湴鏃ユ湡鏃堕棿\n * 杈撳嚭锛氭帶鍒舵棩蹇楋紱鏈夋湭瀹屾垚鎵规鏃舵嫆缁濋噸缃甛n * 涓婁笅鏂囷細yy_multi閲嶇疆锛宮anualBackfill=true\n */\nfunction applyYouyangBackfill(msg, flow, global, node) {\n const state = flow.get('yy_multi');\n if (state && Object.keys(state.pending || {}).length) {\n msg.payload = '鐢ㄥ弸灏氭湁鏈畬鎴愭壒娆★紝鏈噸缃紱寰呭叆搴撳畬鎴愬悗閲嶆柊鐐瑰嚮鍥炶ˉ';\n node.warn(msg.payload);\n return msg;\n }\n const fromTime = msg.yyControl?.from;\n if (!fromTime || !/^\\d{4}-\\d{2}-\\d{2}[ T]\\d{2}:\\d{2}:\\d{2}/.test(fromTime)) {\n node.error('鏃犳晥鍥炶ˉ鏃堕棿', msg);\n return null;\n }\n flow.set('yy_multi', {\n from: fromTime,\n cursors: {},\n pending: {},\n seen: {},\n stats: {},\n manualBackfill: true\n });\n msg.payload = '鐢ㄥ弸鍥炶ˉ璧风偣宸茶缃负 ' + fromTime + '锛涘凡鏈夎褰曞皢璺宠繃';\n return msg;\n}\nreturn applyYouyangBackfill(msg, flow, global, node);\n",
"outputs": 1,
@@ -1836,27 +1864,27 @@
"y": 530,
"wires": [
[
- "yy_result_debug"
+ "a97adb1ca042aaf1"
]
]
},
{
- "id": "collection_yy_control_out",
+ "id": "79639b13a1a5d1f8",
"type": "link out",
- "z": "yy_multi_collect",
+ "z": "c28cda1b8a90e5a0",
"name": "鈫� 閲囬泦鎬诲紑鍏筹紙鍏ㄩ儴娴佺▼锛�",
"mode": "link",
"links": [
- "collection_control_link_in"
+ "603d604846aecbe1"
],
"x": 470,
"y": 650,
"wires": []
},
{
- "id": "collection_yy_pause",
+ "id": "42a4d98b94c5ad3d",
"type": "inject",
- "z": "yy_multi_collect",
+ "z": "c28cda1b8a90e5a0",
"name": "鈴� 鏆傚仠鍏ㄩ儴閲囬泦/鍐欏簱",
"props": [
{
@@ -1874,14 +1902,14 @@
"y": 620,
"wires": [
[
- "collection_yy_control_out"
+ "79639b13a1a5d1f8"
]
]
},
{
- "id": "collection_yy_resume",
+ "id": "f466ad6268ae5a6b",
"type": "inject",
- "z": "yy_multi_collect",
+ "z": "c28cda1b8a90e5a0",
"name": "鈻� 鎭㈠鍏ㄩ儴閲囬泦/鍐欏簱",
"props": [
{
@@ -1899,14 +1927,14 @@
"y": 680,
"wires": [
[
- "collection_yy_control_out"
+ "79639b13a1a5d1f8"
]
]
},
{
- "id": "mp_note",
+ "id": "d37e45d98df6c8d0",
"type": "comment",
- "z": "tab_mqtt_pipeline",
+ "z": "3df84dbf3ac69e5e",
"name": "璇存槑 路 鐙珛 MQTT 閲囬泦鍐欏簱",
"info": "鐙珛椤电锛歁QTT 閲囬泦 + 鍐欏簱锛堜笌浜旀磱/鐢ㄥ弸/閲囬泦鍣ㄩ〉绛句簰涓嶅奖鍝嶏級銆俓n寮�鍏筹細鈴� 鍋滄鏈〉绛� / 鈻� 鍚姩鏈〉绛撅紙global.mqtt_pipeline_paused锛夛紱鏈缃椂璺熼殢鎬诲紑鍏� collection_paused銆傚仠姝㈡椂缂撳啿淇濈暀銆�",
"x": 140,
@@ -1914,9 +1942,9 @@
"wires": []
},
{
- "id": "mp_in_report",
+ "id": "55d33620a724243a",
"type": "mqtt in",
- "z": "tab_mqtt_pipeline",
+ "z": "3df84dbf3ac69e5e",
"name": "璁惧涓婃姤 /report/#锛堢嫭绔嬶級",
"topic": "/report/#",
"qos": "1",
@@ -1930,14 +1958,14 @@
"y": 240,
"wires": [
[
- "mp_gate_in"
+ "84fe484ede3652c9"
]
]
},
{
- "id": "mp_fn_parse",
+ "id": "ac8eb44836a0173a",
"type": "function",
- "z": "tab_mqtt_pipeline",
+ "z": "3df84dbf3ac69e5e",
"name": "MQTT鍗忚瑙f瀽锛堢嫭绔嬶級",
"func": "/**\n * MQTT鍗忚瑙f瀽\n * 杈撳叆锛氬師濮媘sg.payload鍜宮sg.topic\n * 杈撳嚭锛歮sg.dev锛沵sg.flowType渚汼witch鍒嗘祦\n * 涓婁笅鏂囷細涓嶅啓鏁版嵁搴�/缂撳啿\n */\n// 閲囬泦鍣ㄦ姤鏂囪В鏋愶細/report/**锛堣澶囦笂鎶ワ級涓� /cmd/**锛堟枃妗i噷鎶� 浜嗘満/鏈轰慨/閲囬泦鏁版嵁 璇啓鎴� /cmd锛屼袱鏉¢兘璁㈤槄锛塡nconst RECEIPT = {\n worker_register_msg: '鍛樺伐涓婄彮',\n worker_report_msg: '鍛樺伐涓嬬彮',\n axis_start_msg: '涓婅酱',\n variety_change_msg: '鏀瑰搧',\n fall_cloth_msg: '钀藉竷',\n axis_end_msg: '浜嗘満',\n repair_msg: '鏈轰慨'\n};\nconst SIGNAL_CMD = 'signal_msg';\nlet body = msg.payload;\nif (Buffer.isBuffer(body)) {\n body = body.toString('utf8');\n}\nif (typeof body === 'string') {\n try {\n body = JSON.parse(body);\n } catch (e) {\n node.warn('闈� JSON 鎶ユ枃锛屽凡涓㈠純锛�' + msg.topic);\n return null;\n }\n}\nif (!body || typeof body !== 'object') {\n node.warn('绌烘姤鏂囷紝宸蹭涪寮冿細' + msg.topic);\n return null;\n}\nconst topic = msg.topic || '';\nconst seg = topic.split('/').filter(function (s) {\n return s !== '';\n});\nconst dir = seg[0] || ''; // report | cmd\nconst kind = seg[1] || ''; // woven 姊粐 | round 鍦嗘満\nconst sn = String(body.sn || seg[2] || '');\nconst cmd = String(body.cmd || '');\nconst cmdId = body.cmd_id === undefined || body.cmd_id === null ? '' : String(body.cmd_id);\nconst items = body.items && typeof body.items === 'object' ? body.items : {};\n\n// 涓㈠純鏈満鍙戝嚭鐨勭‘璁ゅ洖鎵э紙璁㈤槄 /cmd/# 鏃� MQTT 浼氭妸鎴戜滑鑷繁鐨勫洖鎵у洖鏄惧洖鏉ワ級\n// 鍥炴墽鍙湁 mach_id锛堣惤甯冨啀鍔� cloth_id锛夛紝娌℃湁 time锛涜澶囦笂鎶ュ繀鐒跺甫 time\nif (dir === 'cmd' && (items.time === undefined || Object.keys(items).length < 2)) {\n node.status({\n fill: 'grey',\n shape: 'ring',\n text: '鍥炴墽鍥炴樉锛屽拷鐣�'\n });\n return null;\n}\nmsg.flowType = RECEIPT[cmd] ? 'confirm' : cmd === SIGNAL_CMD ? 'signal' : 'unknown';\nmsg.dev = {\n dir: dir,\n kind: kind || 'woven',\n sn: sn,\n cmd: cmd,\n cmdId: cmdId,\n items: items,\n label: RECEIPT[cmd] || (cmd === SIGNAL_CMD ? '閲囬泦鏁版嵁涓婃姤' : cmd || '(缂哄皯 cmd)'),\n topic: topic,\n receivedAt: new Date()\n};\nnode.status({\n fill: 'blue',\n shape: 'dot',\n text: msg.dev.label\n});\n\nmsg.cmd = cmd\nreturn msg;\n",
"outputs": 1,
@@ -1950,14 +1978,14 @@
"y": 140,
"wires": [
[
- "mp_fn_mqtt_ad"
+ "6c6f3f665f2955fd"
]
]
},
{
- "id": "mp_fn_mqtt_ad",
+ "id": "6c6f3f665f2955fd",
"type": "function",
- "z": "tab_mqtt_pipeline",
+ "z": "3df84dbf3ac69e5e",
"name": "MQTT 路 鏍囧噯鍖栦负鏁版嵁搴撳瓧娈碉紙鐙珛锛�",
"func": "/**\n * MQTT閲囬泦鏍囧噯鍖朶n * 杈撳叆锛歮sg.dev鎴栧師濮婮SON/Buffer\n * 杈撳嚭锛氳緭鍑�1=msg.collectionRows锛涜緭鍑�2=璇婃柇/鏆傚仠棰勮\n * 涓婁笅鏂囷細mqtt_seen锛沵qtt_seen_n锛沵qtt_adapter_stats\n */\nfunction canonicalParameterName(parameterName) {\n const aliases = {\n '杞��': '鏈哄櫒杞��',\n '鐝骞冲潎杞﹂��': '鐝骞冲潎杞��',\n '鏈彮浜ч噺': '鐝浜ч噺(婧愬崟浣�)',\n '鏈彮鏁堢巼': '鐝鏁堢巼(%)',\n '鏈彮鍋滄満娆℃暟': '鐝鍋滄満娆℃暟',\n '鏈彮鍋滄満鏃堕棿(绉�)': '鐝鍋滄満鏃堕棿(绉�)',\n '鏈尮浜ч噺': '鏈尮浜ч噺(婧愬崟浣�)'\n };\n const name = String(parameterName);\n // 鐢ㄥ弸浜嬩欢閲岀殑鏈彮浜ч噺闄勬湁瀹為檯鍗曚綅锛屾部鐢ㄥ悓涓�鐝浜ч噺鍚嶇О銆俓n const withUnit = /^鏈彮浜ч噺\\((.+)\\)$/.exec(name);\n if (withUnit) return '鐝浜ч噺(' + withUnit[1] + ')';\n return aliases[name] || name;\n}\nfunction createCollectionRow(source, deviceCode, parameterName, value, collectedAt, createdAt) {\n const amount = Math.round(Number(value) * 100) / 100;\n return {\n HItemID: null,\n // SQL Server 鑷锛孊ulk 涓嶄紶姝ゅ垪\n HDate: new Date(collectedAt),\n // 閲囨牱鏃堕棿/婧愯澶囨椂闂碶n HSourceCode: String(deviceCode).slice(0, 50),\n HTechParamID: 0,\n // 娌跨敤鐜版湁鐩爣琛ㄧ害瀹歕n HTechParamName: canonicalParameterName(parameterName).slice(0, 500),\n HCount: amount,\n // SQL decimal(18,2)\n HCreateTime: new Date(createdAt),\n // 鏍囧噯鍖栧垱寤烘椂闂达紱閲嶈瘯淇濇寔涓嶅彉\n HResult: String(amount).slice(0, 50),\n HProcNumber: String(source).slice(0, 50),\n // WY / YY / MQTT\n HFlag: 0\n };\n}\nfunction normalizeMqttReport(msg, flow, global, node) {\n // 1. MQTT鍘熷瓧娈� -> 缁熶竴鍙傛暟鍚嶃�傛棤鏄庣‘鍗曚綅/缁熻鍛ㄦ湡鐨勫瓧娈典笉寮鸿鍐掑厖绱鎴栫彮娆″�笺�俓n const fieldMappings = [{\n sourceField: 'rpm',\n parameterName: '鏈哄櫒杞��'\n }, {\n sourceField: 'rpm_avr',\n parameterName: '鐝骞冲潎杞��'\n }, {\n sourceField: 'produce',\n parameterName: '鐝浜ч噺(婧愬崟浣�)'\n }, {\n sourceField: 'effect',\n parameterName: '鐝鏁堢巼(%)'\n }, {\n sourceField: 'beat',\n parameterName: '鎵撶含鏁�'\n }, {\n sourceField: 'boot_time',\n parameterName: '寮�鏈烘椂闂�(绉�)'\n }, {\n sourceField: 'run_time',\n parameterName: '杩愯鏃堕棿(绉�)'\n }, {\n sourceField: 'stop_count',\n parameterName: '鐝鍋滄満娆℃暟'\n }, {\n sourceField: 'stop_time',\n parameterName: '鐝鍋滄満鏃堕棿(绉�)'\n }, {\n sourceField: 'stop_times',\n parameterName: '绱鍋滄満娆℃暟'\n }, {\n sourceField: 'remain_length',\n parameterName: '鍓╀綑缁忛暱'\n }, {\n sourceField: 'remain_length2',\n parameterName: '鍓╀綑缁忛暱2'\n }, {\n sourceField: 'cloth_length_cap',\n parameterName: '鏈尮浜ч噺(婧愬崟浣�)'\n }];\n function numericValue(value) {\n if (value === null || value === undefined || typeof value === 'boolean' || typeof value === 'object') return null;\n if (typeof value === 'string' && !value.trim()) return null;\n const parsed = Number(value);\n return Number.isFinite(parsed) ? Math.round(parsed * 100) / 100 : null;\n }\n function parseDeviceTime(value) {\n if (value === null || value === undefined || value === '') return null;\n if (value instanceof Date) return Number.isFinite(value.getTime()) ? value : null;\n const text = String(value).trim();\n const match = /^(\\d{4})-(\\d{1,2})-(\\d{1,2})(?:[ T](\\d{1,2}):(\\d{1,2})(?::(\\d{1,2})(?:\\.(\\d{1,3}))?)?)?$/.exec(text);\n if (match) {\n const year = Number(match[1]);\n const monthIndex = Number(match[2]) - 1;\n const day = Number(match[3]);\n const hour = Number(match[4] || 0);\n const minute = Number(match[5] || 0);\n const second = Number(match[6] || 0);\n const millisecond = Number((match[7] || '').padEnd(3, '0') || 0);\n // 鏄惧紡7涓弬鏁帮紝閬垮厤灞曞紑涓嶅畾闀挎暟缁勮Е鍙戠紪杈戝櫒TS2556銆俓n const date = new Date(year, monthIndex, day, hour, minute, second, millisecond);\n const matchesInput = date.getFullYear() === year && date.getMonth() === monthIndex && date.getDate() === day && date.getHours() === hour && date.getMinutes() === minute && date.getSeconds() === second;\n return matchesInput ? date : null;\n }\n if (/T.*(?:Z|[+-]\\d{2}:?\\d{2})$/i.test(text)) {\n const date = new Date(text);\n return Number.isFinite(date.getTime()) ? date : null;\n }\n return null;\n }\n function diagnostic(status, message, details = {}) {\n const previousStats = flow.get('mqtt_adapter_stats') || {};\n flow.set('mqtt_adapter_stats', {\n ...previousStats,\n received: (previousStats.received || 0) + 1,\n [status]: (previousStats[status] || 0) + 1,\n lastStatus: status,\n lastMessage: message,\n lastAt: new Date().toISOString()\n });\n const statusColors = {\n buffered: 'green',\n invalid: 'red',\n paused: 'yellow',\n unchanged: 'grey'\n };\n node.status({\n fill: statusColors[status],\n shape: status === 'buffered' ? 'dot' : 'ring',\n text: message\n });\n return {\n payload: {\n source: 'MQTT',\n status,\n message,\n ...details\n },\n _msgid: msg._msgid\n };\n }\n\n // 2. 浼樺厛鎺ユ敹瑙f瀽鑺傜偣msg.dev锛屼篃鏀寔鐩存帴浼犲叆JSON/Buffer銆俓n let deviceReport = msg.dev;\n if (!deviceReport || !deviceReport.items) {\n let body = msg.payload;\n if (Buffer.isBuffer(body)) body = body.toString('utf8');\n if (typeof body === 'string') {\n try {\n body = JSON.parse(body);\n } catch {\n body = null;\n }\n }\n if (body && typeof body === 'object' && !Array.isArray(body)) {\n const topicParts = String(msg.topic || '').split('/').filter(Boolean);\n deviceReport = {\n cmd: body.cmd,\n sn: body.sn || topicParts[2] || '',\n cmdId: body.cmd_id,\n items: body.items,\n receivedAt: new Date(),\n topic: msg.topic || ''\n };\n msg.dev = deviceReport;\n }\n }\n for (const field of ['queryParams', 'query', 'queryMode', 'rows', 'retryBuf', 'collect', 'collectionRows', 'signalRecord']) delete msg[field];\n const fields = deviceReport?.items;\n if (deviceReport?.cmd !== 'signal_msg' || !fields || typeof fields !== 'object' || Array.isArray(fields)) {\n const result = diagnostic('invalid', '涓嶆槸鏈夋晥 signal_msg 鎶ユ枃');\n node.warn(result.payload.message);\n return [null, result];\n }\n const machineId = fields.mach_id === null || fields.mach_id === undefined ? '' : String(fields.mach_id).trim();\n if (!machineId) {\n const result = diagnostic('invalid', '缂哄皯 mach_id锛屾湭閫佸叆缂撳啿');\n node.warn(result.payload.message);\n return [null, result];\n }\n const deviceCode = ((deviceReport.sn ? String(deviceReport.sn).trim() + '-' : '') + machineId).slice(0, 50);\n const sourceTime = parseDeviceTime(fields.time);\n const receivedTime = new Date(deviceReport.receivedAt || Date.now());\n const collectedAt = sourceTime || (Number.isFinite(receivedTime.getTime()) ? receivedTime : new Date());\n const createdAt = new Date();\n const parameterValues = {};\n for (const mapping of fieldMappings) {\n const value = numericValue(fields[mapping.sourceField]);\n if (value !== null) parameterValues[mapping.parameterName] = value;\n }\n const signal = numericValue(fields.signal);\n if (signal !== null) {\n parameterValues['淇″彿鍊�'] = signal;\n parameterValues['杩愯鐘舵��'] = (signal & 3) === 3 ? 1 : 3;\n }\n\n // 鍘熸姤鏂囨枃鏈繚鐣欎綔璇婃柇锛涘啓搴撹鍙瓨鏁板�奸噰闆嗗弬鏁般�俓n msg.signalRecord = {\n 璁惧缂栫爜: deviceCode,\n 鏈哄彴鍙�: machineId,\n 璁惧鏃堕棿: fields.time || '',\n 閲囨牱鏃堕棿: collectedAt.toISOString(),\n 鏃堕棿鏉ユ簮: sourceTime ? '璁惧鏃堕棿' : '鎺ユ敹鏃堕棿',\n 淇″彿: signal,\n 杞��: numericValue(fields.rpm),\n 浜ч噺: numericValue(fields.produce),\n 鏁堢巼: numericValue(fields.effect),\n 鎵瑰彿: fields.batch_number ?? null,\n 鍓╀綑缁忛暱: numericValue(fields.remain_length),\n 鍋滄満娆℃暟: numericValue(fields.stop_count),\n 鍋滄満鏃堕棿: numericValue(fields.stop_time),\n 寮�鏈烘椂闂�: numericValue(fields.boot_time),\n 杩愯鏃堕棿: numericValue(fields.run_time),\n 杞村彿: fields.axis_id ?? null\n };\n const collectionRows = Object.entries(parameterValues).map(([name, value]) => createCollectionRow('MQTT', deviceCode, name, value, collectedAt, createdAt));\n const fieldCount = collectionRows.length;\n if (!fieldCount) return [null, diagnostic('invalid', '鏃犳湁鏁堟暟鍊煎瓧娈碉紝鏈�佸叆缂撳啿', {\n device: deviceCode,\n record: msg.signalRecord\n })];\n\n // 3. 鏆傚仠浠嶈緭鍑烘暟鎹簱瀛楁棰勮锛屾棦涓嶆洿鏂板幓閲嶇紦瀛橈紝涔熶笉鍏ラ槦銆俓nconst __local = global.get('mqtt_pipeline_paused');\nconst __master = global.get('collection_paused');\nconst __running = (__local === false) ? true : (__local === true) ? false : (__master === false);\n if (!__running) {\n return [null, diagnostic('paused', '閲囬泦宸叉殏鍋滐細宸茶В鏋� ' + fieldCount + ' 椤癸紝鏈�佸叆缂撳啿', {\n device: deviceCode,\n fields: fieldCount,\n values: parameterValues,\n record: msg.signalRecord,\n collectionRows\n })];\n }\n\n // 4. MQTT淇濇寔鈥滃彧閫佸彉鍖栧�尖�濓紝浜旀磱鐨勫叏閲忓揩鐓ц鍒欎笉鍦ㄦ澶勬贩鐢ㄣ�俓n let previousValues = flow.get('mqtt_seen') || {};\n let previousCount = flow.get('mqtt_seen_n') || 0;\n if (previousCount > 50000) {\n previousValues = {};\n previousCount = 0;\n }\n const changedRows = [];\n for (const row of collectionRows) {\n const cacheKey = row.HSourceCode + '|' + row.HTechParamName;\n if (previousValues[cacheKey] === row.HCount) continue;\n if (!Object.prototype.hasOwnProperty.call(previousValues, cacheKey)) previousCount += 1;\n previousValues[cacheKey] = row.HCount;\n changedRows.push(row);\n }\n flow.set('mqtt_seen', previousValues);\n flow.set('mqtt_seen_n', previousCount);\n if (!changedRows.length) return [null, diagnostic('unchanged', '鏁板�兼棤鍙樺寲锛屾湭閲嶅鍏ョ紦鍐�', {\n device: deviceCode,\n fields: fieldCount,\n record: msg.signalRecord\n })];\n msg.collectionRows = changedRows;\n msg.payload = changedRows;\n const result = diagnostic('buffered', '宸查�佸叆缂撳啿閾捐矾 ' + changedRows.length + ' 椤�', {\n device: deviceCode,\n fields: fieldCount,\n changed: changedRows.length,\n values: Object.fromEntries(changedRows.map(row => [row.HTechParamName, row.HCount])),\n record: msg.signalRecord,\n collectionRows: changedRows\n });\n return [msg, result];\n}\nreturn normalizeMqttReport(msg, flow, global, node);\n",
"outputs": 2,
@@ -1970,17 +1998,17 @@
"y": 60,
"wires": [
[
- "mp_fn_buffer"
+ "fdf757cb28013694"
],
[
- "mp_dbg_adapter"
+ "39619e59de5f3e7f"
]
]
},
{
- "id": "mp_dbg_adapter",
+ "id": "39619e59de5f3e7f",
"type": "debug",
- "z": "tab_mqtt_pipeline",
+ "z": "3df84dbf3ac69e5e",
"name": "MQTT 路 杞崲缁撴灉涓庤繃婊ゅ師鍥狅紙鐙珛锛�",
"active": true,
"tosidebar": true,
@@ -1995,9 +2023,9 @@
"wires": []
},
{
- "id": "mp_fn_buffer",
+ "id": "fdf757cb28013694",
"type": "function",
- "z": "tab_mqtt_pipeline",
+ "z": "3df84dbf3ac69e5e",
"name": "MQTT鏍囧噯琛� 鈫� 鐙珛缂撳啿",
"func": "/**\n * 缁熶竴鏁版嵁搴撹鍏ョ紦鍐瞈n * 杈撳叆锛歮sg.collectionRows锛涚敤鍙嬪彟甯sg.yySync\n * 杈撳嚭锛氳緭鍑�1=鍏ラ槦鎽樿/鏁版嵁搴撳瓧娈甸瑙堬紱杈撳嚭2=鐢ㄥ弸鍥炴墽\n * 涓婁笅鏂囷細sync_rows锛泂ync_yy_batches锛泂ync_yy_completed\n */\nfunction collectionRowKey(row) {\n // 淇濈暀鍘熸湁鑷劧閿紪鐮侊紝鍏煎鏃у緟纭鎵规鐨� doneKeys銆俓n return row.HProcNumber + '|' + row.HSourceCode + '|' + row.HTechParamName + '|' + new Date(row.HDate).getTime();\n}\nfunction convertLegacyBufferRow(row, createdAt) {\n if (row.HDate !== undefined && row.HSourceCode !== undefined) {\n // 宸叉槸鏂版牸寮忥細淇濈暀鏃㈡湁瀛楁鍜屾壒娆″紩鐢紝鍙仮澶� Date 绫诲瀷銆俓n return {\n ...row,\n HDate: new Date(row.HDate),\n HCreateTime: row.HCreateTime ? new Date(row.HCreateTime) : new Date(createdAt)\n };\n }\n // 閮ㄧ讲鍏煎锛氭棫 sync_rows 浣跨敤 s/d/p/v/t锛屽師鎵硅涔夊強鍘熷弬鏁板悕淇濇寔涓嶅彉銆俓n const converted = {\n HItemID: null,\n HDate: new Date(row.t),\n HSourceCode: row.d,\n HTechParamID: 0,\n HTechParamName: row.p,\n HCount: row.v,\n HCreateTime: new Date(createdAt),\n HResult: String(row.v).slice(0, 50),\n HProcNumber: row.s,\n HFlag: 0\n };\n if (row.yyRefs?.length) converted._sync = {\n yyBatchIds: [...row.yyRefs]\n };\n return converted;\n}\nfunction legacyCollectToRows(collect, createdAt) {\n // 鍙敤浜庡崌绾у墠缂撳瓨鐨� pending.write锛涗笁璺柊娑堟伅閮界洿鎺ヨ緭鍑� collectionRows銆俓n const rows = [];\n for (const item of collect || []) {\n const collectedAt = new Date(item.ts);\n if (!Number.isFinite(collectedAt.getTime())) continue;\n for (const [parameterName, value] of Object.entries(item.data || {})) {\n if (value === null || value === undefined || value === '') continue;\n if (!Number.isFinite(Number(value))) continue;\n // 宸茬瓑寰呯‘璁ょ殑鏃ф壒涓嶆敼鍚嶏紝淇濊瘉涓庝箣鍓嶅凡钀藉簱閮ㄥ垎鐨勯槻閲嶉敭涓�鑷淬�俓n rows.push({\n HItemID: null,\n HDate: collectedAt,\n HSourceCode: String(item.device).slice(0, 50),\n HTechParamID: 0,\n HTechParamName: parameterName.slice(0, 500),\n HCount: Math.round(Number(value) * 100) / 100,\n HCreateTime: new Date(createdAt),\n HResult: String(Math.round(Number(value) * 100) / 100).slice(0, 50),\n HProcNumber: item.src,\n HFlag: 0\n });\n }\n }\n return rows;\n}\nfunction enqueueCollectionRows(msg, flow, global, node) {\n const batchMeta = msg.yySync;\n const isYouyangBatch = Boolean(batchMeta?.batchId && batchMeta?.stream);\n const makeAck = (kind, details = {}) => ({\n yySync: batchMeta,\n yyAck: {\n kind,\n ...details\n },\n payload: {\n stream: batchMeta?.stream,\n ...details\n }\n });\n\n // 1. 鏆傚仠鍙仠姝㈡柊澧烇紝涓嶆竻绌哄師缂撳啿锛屼篃涓嶆彁浜ょ敤鍙嬫按浣嶃�俓nconst __local = global.get('mqtt_pipeline_paused');\nconst __master = global.get('collection_paused');\nconst __running = (__local === false) ? true : (__local === true) ? false : (__master === false);\n if (!__running) {\n node.status({\n fill: 'yellow',\n shape: 'ring',\n text: '閲囬泦宸叉殏鍋滐紝缂撳啿淇濈暀'\n });\n return isYouyangBatch ? [null, makeAck('deferred', {\n reason: '閲囬泦宸叉殏鍋�'\n })] : null;\n }\n const completedBatches = flow.get('sync_yy_completed') || {};\n const pendingBatches = flow.get('sync_yy_batches') || {};\n if (isYouyangBatch && completedBatches[batchMeta.batchId]) {\n return [null, completedBatches[batchMeta.batchId]];\n }\n if (isYouyangBatch && pendingBatches[batchMeta.batchId]) {\n return [null, makeAck('queued', {\n expected: pendingBatches[batchMeta.batchId].expected,\n duplicateRequest: true\n })];\n }\n\n // 2. 涓夎矾鏂拌緭鍏ュ潎涓烘暟鎹簱瀛楁瀵硅薄銆俢ollect 浠呭吋瀹归儴缃插墠鐨勫緟纭娑堟伅銆俓n const createdAt = new Date();\n const inputRows = Array.isArray(msg.collectionRows) ? msg.collectionRows : legacyCollectToRows(msg.collect, createdAt);\n const validRows = [];\n const uniqueYouyangRows = new Map();\n for (const input of inputRows) {\n const row = convertLegacyBufferRow(input, createdAt);\n const valid = row.HSourceCode && row.HTechParamName && Number.isFinite(row.HDate.getTime()) && Number.isFinite(row.HCreateTime.getTime()) && typeof row.HCount === 'number' && Number.isFinite(row.HCount);\n if (!valid) {\n // 涓嶆妸鈥滄牸寮忛敊璇�濅吉瑁呮垚鍐欏簱鎴愬姛锛涚敤鍙嬪繀椤讳繚鐣欏師鎵瑰拰姘翠綅銆俓n if (isYouyangBatch) return [null, makeAck('deferred', {\n reason: '鏍囧噯琛屾棤鏁堬紝妫�鏌ユ暟鎹簱瀛楁'\n })];\n node.warn('蹇界暐鏃犳晥閲囬泦鍙傛暟琛�');\n continue;\n }\n if (isYouyangBatch) {\n if (row.HProcNumber !== 'YY') return [null, makeAck('deferred', {\n reason: '鐢ㄥ弸鎵规鏉ユ簮蹇呴』涓篩Y'\n })];\n row._sync = {\n yyBatchIds: [batchMeta.batchId]\n }; // 浠呯敤浜庣‘璁わ紝涓嶆槸鏁版嵁搴撳垪\n uniqueYouyangRows.set(collectionRowKey(row), row);\n } else {\n validRows.push(row);\n }\n }\n if (isYouyangBatch) validRows.push(...uniqueYouyangRows.values());\n const bufferRows = flow.get('mqtt_sync_rows') || [];\n if (isYouyangBatch && bufferRows.length + validRows.length > 20000) {\n node.status({\n fill: 'yellow',\n shape: 'ring',\n text: '缂撳啿绉帇锛岀敤鍙嬪師鎵圭瓑寰�'\n });\n return [null, makeAck('deferred', {\n reason: '缂撳啿杈惧埌20000琛岄檺娴�'\n })];\n }\n if (!validRows.length) {\n return isYouyangBatch ? [null, makeAck('committed', {\n inserted: 0,\n skipped: 0,\n expected: 0\n })] : null;\n }\n\n // 3. 鍏ラ槦鍥炴墽浠呰〃绀哄凡鎺ユ敹銆傛暣鎵瑰啓鍏�/璺宠繃瀹屾垚鍚庯紝鎵嶄細鍙戦�� committed銆俓n if (isYouyangBatch) {\n pendingBatches[batchMeta.batchId] = {\n meta: {\n ...batchMeta,\n phase: 'buffer'\n },\n expected: validRows.length,\n done: 0,\n inserted: 0,\n skipped: 0,\n doneKeys: {},\n queuedAt: new Date().toISOString()\n };\n }\n bufferRows.push(...validRows);\n flow.set('mqtt_sync_rows', bufferRows);\n flow.set('sync_yy_batches', pendingBatches);\n node.status({\n fill: 'blue',\n shape: 'dot',\n text: '+' + validRows.length + ' / 缂撳啿 ' + bufferRows.length\n });\n\n // 璋冭瘯鍙瑙堝墠3琛岋紝渚夸簬瀵圭収鏁版嵁搴撳瓧娈碉紝涔熼伩鍏嶆瘡绉掓墦鍗板ぇ閲忓弬鏁般�俓n const preview = validRows.slice(0, 3).map(row => {\n const {\n _sync,\n ...databaseFields\n } = row;\n return databaseFields;\n });\n const diagnostic = {\n payload: {\n source: validRows[0].HProcNumber,\n buffered: validRows.length,\n pending: bufferRows.length,\n records: preview\n }\n };\n const ack = isYouyangBatch ? makeAck('queued', {\n expected: validRows.length,\n pending: bufferRows.length\n }) : null;\n return [diagnostic, ack];\n}\nreturn enqueueCollectionRows(msg, flow, global, node);\n",
"outputs": 2,
@@ -2010,15 +2038,15 @@
"y": 60,
"wires": [
[
- "mp_dbg_buffer"
+ "ba0a70a37b67792f"
],
[]
]
},
{
- "id": "mp_dbg_buffer",
+ "id": "ba0a70a37b67792f",
"type": "debug",
- "z": "tab_mqtt_pipeline",
+ "z": "3df84dbf3ac69e5e",
"name": "MQTT 鍏ョ紦鍐叉憳瑕�",
"active": true,
"tosidebar": true,
@@ -2033,9 +2061,9 @@
"wires": []
},
{
- "id": "mp_inject_flush",
+ "id": "e84e9b9ebc33af96",
"type": "inject",
- "z": "tab_mqtt_pipeline",
+ "z": "3df84dbf3ac69e5e",
"name": "MQTT 路 姣� 5s 鍐欏簱",
"props": [],
"repeat": "5",
@@ -2049,14 +2077,14 @@
"y": 340,
"wires": [
[
- "mp_gate_flush"
+ "3d13eb1a252090aa"
]
]
},
{
- "id": "mp_fn_flush",
+ "id": "b0123987740a8d3f",
"type": "function",
- "z": "tab_mqtt_pipeline",
+ "z": "3df84dbf3ac69e5e",
"name": "MQTT缂撳啿 鈫� Bulk鍒楁暟缁�",
"func": "/**\n * 缂撳啿杞珺ulk璇锋眰\n * 杈撳叆锛氭瘡5绉掕Е鍙慭n * 杈撳嚭锛歮sg.rows=鎸夊垪瀹氫箟鎺掑垪鐨勪簩缁存暟缁勶紱retryBuf=鍘熸暟鎹簱琛孿n * 涓婁笅鏂囷細sync_rows锛泂ync_inflight\n */\nfunction collectionRowKey(row) {\n // 淇濈暀鍘熸湁鑷劧閿紪鐮侊紝鍏煎鏃у緟纭鎵规鐨� doneKeys銆俓n return row.HProcNumber + '|' + row.HSourceCode + '|' + row.HTechParamName + '|' + new Date(row.HDate).getTime();\n}\nfunction convertLegacyBufferRow(row, createdAt) {\n if (row.HDate !== undefined && row.HSourceCode !== undefined) {\n // 宸叉槸鏂版牸寮忥細淇濈暀鏃㈡湁瀛楁鍜屾壒娆″紩鐢紝鍙仮澶� Date 绫诲瀷銆俓n return {\n ...row,\n HDate: new Date(row.HDate),\n HCreateTime: row.HCreateTime ? new Date(row.HCreateTime) : new Date(createdAt)\n };\n }\n // 閮ㄧ讲鍏煎锛氭棫 sync_rows 浣跨敤 s/d/p/v/t锛屽師鎵硅涔夊強鍘熷弬鏁板悕淇濇寔涓嶅彉銆俓n const converted = {\n HItemID: null,\n HDate: new Date(row.t),\n HSourceCode: row.d,\n HTechParamID: 0,\n HTechParamName: row.p,\n HCount: row.v,\n HCreateTime: new Date(createdAt),\n HResult: String(row.v).slice(0, 50),\n HProcNumber: row.s,\n HFlag: 0\n };\n if (row.yyRefs?.length) converted._sync = {\n yyBatchIds: [...row.yyRefs]\n };\n return converted;\n}\nfunction flushCollectionBuffer(msg, flow, global, node) {\nconst __local = global.get('mqtt_pipeline_paused');\nconst __master = global.get('collection_paused');\nconst __running = (__local === false) ? true : (__local === true) ? false : (__master === false);\n if (!__running) {\n node.status({\n fill: 'yellow',\n shape: 'ring',\n text: '閲囬泦宸叉殏鍋�'\n });\n return null;\n }\n if (flow.get('mqtt_sync_inflight')) return null;\n const bufferRows = flow.get('mqtt_sync_rows') || [];\n if (!bufferRows.length) return null;\n\n // 1. 鏈�澶氬彇5000琛屻�傚悓閿彧鍐欎竴娆★紝浣嗗悎骞舵墍鏈夌敤鍙嬫壒娆″紩鐢ㄣ�俓n const selectedRows = bufferRows.slice(0, 5000);\n const uniqueRows = new Map();\n const createdAt = new Date();\n for (const input of selectedRows) {\n const row = convertLegacyBufferRow(input, createdAt);\n const key = collectionRowKey(row);\n const previous = uniqueRows.get(key);\n const batchIds = new Set([...(previous?._sync?.yyBatchIds || []), ...(row._sync?.yyBatchIds || [])]);\n if (batchIds.size) row._sync = {\n yyBatchIds: Array.from(batchIds)\n };\n uniqueRows.set(key, row);\n }\n const selectedRecords = Array.from(uniqueRows.values());\n\n // 2. 鍙湁Bulk杈圭晫闇�瑕佷簩缁存暟缁勶紝鍒楅『搴忛泦涓畾涔夛紝涓嶅啀浣跨敤r.s/r.d/r.p绛夌缉鍐欍�俓n const bulkColumns = [{\n name: 'HDate',\n type: 'datetime'\n }, {\n name: 'HSourceCode',\n type: 'varchar(50)'\n }, {\n name: 'HTechParamID',\n type: 'int'\n }, {\n name: 'HTechParamName',\n type: 'varchar(500)'\n }, {\n name: 'HCount',\n type: 'decimal(18,2)'\n }, {\n name: 'HCreateTime',\n type: 'datetime'\n }, {\n name: 'HResult',\n type: 'varchar(50)'\n }, {\n name: 'HProcNumber',\n type: 'varchar(50)'\n }, {\n name: 'HFlag',\n type: 'bit'\n }].map(column => ({\n ...column,\n options: {\n nullable: false\n }\n }));\n flow.set('mqtt_sync_rows', bufferRows.slice(selectedRows.length));\n flow.set('mqtt_sync_inflight', true);\n msg.retryBuf = selectedRecords;\n msg.bulkColumns = bulkColumns;\n msg.rows = selectedRecords.map(record => bulkColumns.map(column => record[column.name]));\n msg.queryParams = bulkColumns.map(column => ({\n ...column\n }));\n msg.query = 'dbo.Sb_EquipMentCollectionTechParam_Temp';\n msg.queryMode = 'bulk';\n msg.syncWrittenRows = selectedRecords;\n msg.syncSkippedRows = [];\n msg.payload = {\n table: msg.query,\n rows: selectedRecords.length\n };\n return msg;\n}\nreturn flushCollectionBuffer(msg, flow, global, node);\n",
"outputs": 1,
@@ -2069,14 +2097,14 @@
"y": 320,
"wires": [
[
- "mp_fn_prepare_bulk"
+ "034ba260817b3a36"
]
]
},
{
- "id": "mp_fn_prepare_bulk",
+ "id": "034ba260817b3a36",
"type": "function",
- "z": "tab_mqtt_pipeline",
+ "z": "3df84dbf3ac69e5e",
"name": "Bulk鍒嗘祦锛圡QTT 鏃犵敤鍙嬮槻閲嶏級",
"func": "/**\n * Bulk鍓嶉泦鍚堥槻閲嶅垎娴乗n * 杈撳叆锛歮sg.retryBuf=鏁版嵁搴撹\n * 杈撳嚭锛氳緭鍑�1=鐩存帴Bulk锛涜緭鍑�2=鐢ㄥ弸闃查噸SELECT璇锋眰\n * 涓婁笅鏂囷細鏃犳柊澧炵姸鎬侊紱鏈�澶�1900涓猄QL鍙傛暟\n */\nfunction canonicalParameterName(parameterName) {\n const aliases = {\n '杞��': '鏈哄櫒杞��',\n '鐝骞冲潎杞﹂��': '鐝骞冲潎杞��',\n '鏈彮浜ч噺': '鐝浜ч噺(婧愬崟浣�)',\n '鏈彮鏁堢巼': '鐝鏁堢巼(%)',\n '鏈彮鍋滄満娆℃暟': '鐝鍋滄満娆℃暟',\n '鏈彮鍋滄満鏃堕棿(绉�)': '鐝鍋滄満鏃堕棿(绉�)',\n '鏈尮浜ч噺': '鏈尮浜ч噺(婧愬崟浣�)'\n };\n const name = String(parameterName);\n // 鐢ㄥ弸浜嬩欢閲岀殑鏈彮浜ч噺闄勬湁瀹為檯鍗曚綅锛屾部鐢ㄥ悓涓�鐝浜ч噺鍚嶇О銆俓n const withUnit = /^鏈彮浜ч噺\\((.+)\\)$/.exec(name);\n if (withUnit) return '鐝浜ч噺(' + withUnit[1] + ')';\n return aliases[name] || name;\n}\nfunction equivalentParameterNames(parameterName) {\n const canonicalName = canonicalParameterName(parameterName);\n const historicalNames = ['杞��', '鐝骞冲潎杞﹂��', '鏈彮浜ч噺', '鏈彮鏁堢巼', '鏈彮鍋滄満娆℃暟', '鏈彮鍋滄満鏃堕棿(绉�)', '鏈尮浜ч噺'];\n const names = new Set([parameterName, canonicalName]);\n for (const historicalName of historicalNames) {\n if (canonicalParameterName(historicalName) === canonicalName) names.add(historicalName);\n }\n const withUnit = /^鐝浜ч噺\\((.+)\\)$/.exec(canonicalName);\n if (withUnit) names.add('鏈彮浜ч噺(' + withUnit[1] + ')');\n return Array.from(names);\n}\nfunction prepareYouyangDuplicateCheck(msg, flow, global, node) {\n const youyangRows = (msg.retryBuf || []).filter(row => row.HProcNumber === 'YY');\n if (!youyangRows.length) return [msg, null];\n\n // 鎸夋簮鎵规鏀剁獎鏃堕棿銆佽澶囧拰鍙傛暟鑼冨洿锛屼竴娆℃煡璇㈡暣涓狟ulk鎵规銆俓n const groupsByBatch = new Map();\n for (const row of youyangRows) {\n const batchId = row._sync?.yyBatchIds?.[0] || 'untracked';\n const timestamp = new Date(row.HDate).getTime();\n if (!groupsByBatch.has(batchId)) {\n groupsByBatch.set(batchId, {\n minTime: timestamp,\n maxTime: timestamp,\n devices: new Set(),\n parameters: new Set()\n });\n }\n const group = groupsByBatch.get(batchId);\n group.minTime = Math.min(group.minTime, timestamp);\n group.maxTime = Math.max(group.maxTime, timestamp);\n group.devices.add(row.HSourceCode);\n for (const name of equivalentParameterNames(row.HTechParamName)) group.parameters.add(name);\n }\n let groups = Array.from(groupsByBatch.values());\n if (groups.length > 128) {\n const times = youyangRows.map(row => new Date(row.HDate).getTime());\n groups = [{\n minTime: Math.min(...times),\n maxTime: Math.max(...times),\n devices: new Set(youyangRows.map(row => row.HSourceCode)),\n parameters: new Set(youyangRows.flatMap(row => equivalentParameterNames(row.HTechParamName)))\n }];\n }\n\n // SQL Server鏈�澶�2100涓弬鏁帮紱棰勭暀浣欓噺銆傛潯浠舵敹缂╁彧浼氬鏌ワ紝涓嶄細婕忔煡銆俓n const queryParams = [];\n const predicates = [];\n const groupBudget = Math.floor(1900 / groups.length) - 2;\n groups.forEach((group, index) => {\n const prefix = 'group' + index;\n queryParams.push({\n name: prefix + 'MinTime',\n type: 'datetime',\n value: new Date(group.minTime)\n }, {\n name: prefix + 'MaxTime',\n type: 'datetime',\n value: new Date(group.maxTime)\n });\n const filters = ['HDate >= @' + prefix + 'MinTime', 'HDate <= @' + prefix + 'MaxTime'];\n let remainingBudget = groupBudget;\n for (const filter of [{\n values: group.parameters,\n column: 'HTechParamName',\n type: 'varchar(500)'\n }, {\n values: group.devices,\n column: 'HSourceCode',\n type: 'varchar(50)'\n }]) {\n if (filter.values.size > remainingBudget) continue;\n const names = Array.from(filter.values).map((value, valueIndex) => {\n const name = prefix + filter.column + valueIndex;\n queryParams.push({\n name,\n type: filter.type,\n value\n });\n return '@' + name;\n });\n filters.push(filter.column + ' IN (' + names.join(', ') + ')');\n remainingBudget -= filter.values.size;\n }\n predicates.push('(' + filters.join(' AND ') + ')');\n });\n msg.query = `SET NOCOUNT ON;\nSELECT HDate, HSourceCode, HTechParamName\nFROM dbo.Sb_EquipMentCollectionTechParam_Temp\nWHERE HProcNumber = 'YY'\n AND (${predicates.join('\\n OR ')});`;\n msg.queryParams = queryParams;\n msg.queryMode = 'query';\n msg.payload = null;\n return [null, msg];\n}\nreturn prepareYouyangDuplicateCheck(msg, flow, global, node);\n",
"outputs": 2,
@@ -2089,15 +2117,15 @@
"y": 320,
"wires": [
[
- "mp_db_bulk"
+ "2d48c1063fe82e7b"
],
[]
]
},
{
- "id": "mp_db_bulk",
+ "id": "2d48c1063fe82e7b",
"type": "MSSQL",
- "z": "tab_mqtt_pipeline",
+ "z": "3df84dbf3ac69e5e",
"mssqlCN": "9bb47eb9867c4772",
"name": "鐩爣搴� 路 bulk 鍐欑紦瀛樹复鏃惰〃锛圡QTT锛�",
"outField": "payload",
@@ -2118,14 +2146,14 @@
"y": 400,
"wires": [
[
- "mp_fn_success"
+ "707eeec34dd5e7b4"
]
]
},
{
- "id": "mp_fn_success",
+ "id": "707eeec34dd5e7b4",
"type": "function",
- "z": "tab_mqtt_pipeline",
+ "z": "3df84dbf3ac69e5e",
"name": "鍐欏簱鎴愬姛 鈫� 缁熻锛圡QTT锛�",
"func": "/**\n * Bulk鎴愬姛鍙婃壒娆$‘璁n * 杈撳叆锛歳etryBuf锛泂yncWrittenRows锛泂yncSkippedRows\n * 杈撳嚭锛氳緭鍑�1=鍐欏簱缁熻锛涜緭鍑�2=鏁存壒瀹屾垚鍥炴墽\n * 涓婁笅鏂囷細sync_inflight锛泂ync_yy_batches锛泂ync_written\n */\nfunction collectionRowKey(row) {\n // 淇濈暀鍘熸湁鑷劧閿紪鐮侊紝鍏煎鏃у緟纭鎵规鐨� doneKeys銆俓n return row.HProcNumber + '|' + row.HSourceCode + '|' + row.HTechParamName + '|' + new Date(row.HDate).getTime();\n}\nfunction confirmBulkSuccess(msg, flow, global, node) {\n flow.set('mqtt_sync_inflight', false);\n const originalRecords = Array.isArray(msg.retryBuf) ? msg.retryBuf : [];\n const writtenRecords = Array.isArray(msg.syncWrittenRows) ? msg.syncWrittenRows : originalRecords;\n const skippedRecords = Array.isArray(msg.syncSkippedRows) ? msg.syncSkippedRows : [];\n const skippedKeys = new Set(skippedRecords.map(collectionRowKey));\n const pendingBatches = flow.get('sync_yy_batches') || {};\n const completedBatches = flow.get('sync_yy_completed') || {};\n const acknowledgements = [];\n\n // 涓�涓狟ulk鍙互鍖呭惈澶氫釜婧愭壒娆★紝涔熷彲浠ュ彧鏄竴涓簮鎵规鐨勪竴閮ㄥ垎銆俓n for (const record of originalRecords) {\n const rowKey = collectionRowKey(record);\n for (const batchId of new Set(record._sync?.yyBatchIds || [])) {\n const batch = pendingBatches[batchId];\n if (!batch || batch.doneKeys[rowKey]) continue;\n batch.doneKeys[rowKey] = true;\n batch.done += 1;\n if (skippedKeys.has(rowKey)) batch.skipped += 1;else batch.inserted += 1;\n }\n }\n for (const [batchId, batch] of Object.entries(pendingBatches)) {\n if (batch.done < batch.expected) continue;\n const ack = {\n yySync: batch.meta,\n yyAck: {\n kind: 'committed',\n expected: batch.expected,\n inserted: batch.inserted,\n skipped: batch.skipped\n },\n payload: {\n stream: batch.meta.stream,\n inserted: batch.inserted,\n skipped: batch.skipped\n }\n };\n acknowledgements.push(ack);\n completedBatches[batchId] = ack;\n delete pendingBatches[batchId];\n }\n const completedIds = Object.keys(completedBatches);\n for (const batchId of completedIds.slice(0, Math.max(0, completedIds.length - 256))) delete completedBatches[batchId];\n flow.set('sync_yy_batches', pendingBatches);\n flow.set('sync_yy_completed', completedBatches);\n const totalWritten = (flow.get('mqtt_sync_written') || 0) + writtenRecords.length;\n flow.set('mqtt_sync_written', totalWritten);\n flow.set('mqtt_sync_last_success', new Date().toISOString());\n node.status({\n fill: 'green',\n shape: 'dot',\n text: 'Bulk鍐欏叆 ' + writtenRecords.length + ' / 宸叉湁 ' + skippedRecords.length\n });\n return [{\n payload: {\n written: writtenRecords.length,\n skipped: skippedRecords.length,\n total: totalWritten,\n pending: (flow.get('mqtt_sync_rows') || []).length,\n yyPendingBatches: Object.keys(pendingBatches).length\n }\n }, acknowledgements];\n}\nreturn confirmBulkSuccess(msg, flow, global, node);\n",
"outputs": 2,
@@ -2138,15 +2166,15 @@
"y": 320,
"wires": [
[
- "mp_dbg_success"
+ "b0a277d602900f4d"
],
[]
]
},
{
- "id": "mp_dbg_success",
+ "id": "b0a277d602900f4d",
"type": "debug",
- "z": "tab_mqtt_pipeline",
+ "z": "3df84dbf3ac69e5e",
"name": "MQTT 鍏ュ簱缁撴灉",
"active": true,
"tosidebar": true,
@@ -2161,29 +2189,29 @@
"wires": []
},
{
- "id": "mp_catch",
+ "id": "03a37b0d670d7ecd",
"type": "catch",
- "z": "tab_mqtt_pipeline",
+ "z": "3df84dbf3ac69e5e",
"name": "MQTT 閲囬泦鍐欏簱寮傚父",
"scope": [
- "mp_db_bulk",
- "mp_fn_prepare_bulk",
- "mp_fn_flush",
- "mp_fn_buffer"
+ "2d48c1063fe82e7b",
+ "034ba260817b3a36",
+ "b0123987740a8d3f",
+ "fdf757cb28013694"
],
"uncaught": false,
"x": 120,
"y": 460,
"wires": [
[
- "mp_fn_retry"
+ "931cc810e4b8d593"
]
]
},
{
- "id": "mp_fn_retry",
+ "id": "931cc810e4b8d593",
"type": "function",
- "z": "tab_mqtt_pipeline",
+ "z": "3df84dbf3ac69e5e",
"name": "澶辫触鍥炲~缂撳啿锛圡QTT锛�",
"func": "/**\n * 澶辫触鍘熸壒鍥炲~\n * 杈撳叆锛氬け璐ヨ姹傦紝msg.retryBuf鍜宮sg.error\n * 杈撳嚭锛氳緭鍑�1=閿欒鎽樿锛涜緭鍑�2=鐢ㄥ弸閲嶈瘯閫氱煡\n * 涓婁笅鏂囷細sync_rows锛泂ync_inflight\n */\nfunction requeueFailedBulk(msg, flow, global, node) {\n const retryRecords = Array.isArray(msg.retryBuf) ? msg.retryBuf : [];\n if (retryRecords.length) flow.set('mqtt_sync_rows', retryRecords.concat(flow.get('mqtt_sync_rows') || []));\n flow.set('mqtt_sync_inflight', false);\n const errorMessage = typeof msg.error === 'string' ? msg.error : msg.error?.details || msg.error?.message || 'Bulk鎴栭槻閲嶉鏌ュけ璐�';\n const pendingBatches = flow.get('sync_yy_batches') || {};\n const affectedBatchIds = new Set(retryRecords.flatMap(row => row._sync?.yyBatchIds || []));\n const acknowledgements = Array.from(affectedBatchIds).filter(batchId => pendingBatches[batchId]).map(batchId => ({\n yySync: pendingBatches[batchId].meta,\n yyAck: {\n kind: 'retrying',\n reason: errorMessage\n }\n }));\n node.status({\n fill: 'red',\n shape: 'ring',\n text: '澶辫触鍥炲~ ' + retryRecords.length + ' 琛岋紝姘翠綅鏈帹杩�'\n });\n return [{\n payload: {\n error: errorMessage,\n requeued: retryRecords.length\n }\n }, acknowledgements];\n}\nreturn requeueFailedBulk(msg, flow, global, node);\n",
"outputs": 2,
@@ -2196,15 +2224,15 @@
"y": 460,
"wires": [
[
- "mp_dbg_error"
+ "dcdb67b65ffa95ab"
],
[]
]
},
{
- "id": "mp_dbg_error",
+ "id": "dcdb67b65ffa95ab",
"type": "debug",
- "z": "tab_mqtt_pipeline",
+ "z": "3df84dbf3ac69e5e",
"name": "MQTT 寮傚父璇︽儏",
"active": true,
"tosidebar": true,
@@ -2219,9 +2247,9 @@
"wires": []
},
{
- "id": "mp_gate_in",
+ "id": "84fe484ede3652c9",
"type": "function",
- "z": "tab_mqtt_pipeline",
+ "z": "3df84dbf3ac69e5e",
"name": "鍚仠闂搁棬 路 鍏ュ彛锛堟湰椤电锛�",
"func": "/**\n * 鏈〉绛剧嫭绔嬪惎鍋滈椄闂紙鍏ュ彛锛塡n * 浼樺厛鏈〉绛惧紑鍏� mqtt_pipeline_paused锛歵rue=鍋滄锛宖alse=杩愯\n * 鏈缃紙undefined锛夋椂鍥炶惤鍒版�诲紑鍏� collection_paused\n */\nconst local = global.get('mqtt_pipeline_paused');\nconst master = global.get('collection_paused');\nconst running = (local === false) ? true : (local === true) ? false : (master === false);\nif (!running) {\n node.status({ fill: 'grey', shape: 'ring', text: local === true ? '鏈〉绛惧凡鍋滄' : '鏈惎鍔�/鎬诲紑鍏虫殏鍋�' });\n return null;\n}\nnode.status({ fill: 'green', shape: 'dot', text: '閲囬泦涓�' });\nreturn msg;",
"outputs": 1,
@@ -2234,14 +2262,14 @@
"y": 240,
"wires": [
[
- "mp_fn_parse"
+ "ac8eb44836a0173a"
]
]
},
{
- "id": "mp_gate_flush",
+ "id": "3d13eb1a252090aa",
"type": "function",
- "z": "tab_mqtt_pipeline",
+ "z": "3df84dbf3ac69e5e",
"name": "鍚仠闂搁棬 路 鍐欏簱锛堟湰椤电锛�",
"func": "/**\n * 鏈〉绛剧嫭绔嬪惎鍋滈椄闂紙鍐欏簱锛塡n * 瑙勫垯鍚屽叆鍙i椄闂紱鍋滄鏃剁紦鍐蹭繚鐣欍�佷笉鍐欏簱\n */\nconst local = global.get('mqtt_pipeline_paused');\nconst master = global.get('collection_paused');\nconst running = (local === false) ? true : (local === true) ? false : (master === false);\nif (!running) {\n node.status({ fill: 'grey', shape: 'ring', text: '鏈〉绛惧凡鍋滄锛岀紦鍐蹭繚鐣�' });\n return null;\n}\nnode.status({ fill: 'green', shape: 'dot', text: '鍐欏簱涓�' });\nreturn msg;",
"outputs": 1,
@@ -2254,14 +2282,14 @@
"y": 400,
"wires": [
[
- "mp_fn_flush"
+ "b0123987740a8d3f"
]
]
},
{
- "id": "mp_ctl_pause",
+ "id": "1358dc0590009a9c",
"type": "inject",
- "z": "tab_mqtt_pipeline",
+ "z": "3df84dbf3ac69e5e",
"name": "鈴� 鍋滄鏈〉绛撅紙娴嬭瘯锛�",
"props": [
{
@@ -2279,14 +2307,14 @@
"y": 560,
"wires": [
[
- "mp_ctl_fn"
+ "e8be1d7f90d46692"
]
]
},
{
- "id": "mp_ctl_resume",
+ "id": "cba570d01c94ebac",
"type": "inject",
- "z": "tab_mqtt_pipeline",
+ "z": "3df84dbf3ac69e5e",
"name": "鈻� 鍚姩鏈〉绛撅紙娴嬭瘯锛�",
"props": [
{
@@ -2304,14 +2332,14 @@
"y": 620,
"wires": [
[
- "mp_ctl_fn"
+ "e8be1d7f90d46692"
]
]
},
{
- "id": "mp_ctl_fn",
+ "id": "e8be1d7f90d46692",
"type": "function",
- "z": "tab_mqtt_pipeline",
+ "z": "3df84dbf3ac69e5e",
"name": "鐙珛鍚仠寮�鍏�",
"func": "/**\n * 鏈〉绛剧嫭绔嬪惎鍋滃紑鍏筹紙娴嬭瘯鐢級\n * 杈撳叆锛歮sg.payload = 'pause' | 'resume'\n * 杈撳嚭锛氬紑鍏崇姸鎬乗n * 涓婁笅鏂囷細global mqtt_pipeline_paused锛沢lobal mqtt_pipeline_state\n */\nconst action = String(msg.payload || '').trim().toLowerCase();\nif (action !== 'pause' && action !== 'resume') {\n node.warn('鏈煡寮�鍏虫寚浠わ細' + action + '锛堝彧鎺ュ彈 pause / resume锛�');\n return null;\n}\nconst paused = action === 'pause';\nglobal.set('mqtt_pipeline_paused', paused);\nconst state = {\n paused: paused,\n changedAt: new Date().toISOString(),\n note: paused ? '鏈〉绛惧仠姝細涓㈠純鏂版姤鏂囷紝缂撳啿淇濈暀涓嶅啓搴�' : '鏈〉绛捐繍琛岋細姝e父閲囬泦骞跺啓搴擄紙浠嶅彈鎬诲紑鍏崇害鏉燂級'\n};\nglobal.set('mqtt_pipeline_state', state);\nnode.status({ fill: paused ? 'grey' : 'green', shape: paused ? 'ring' : 'dot', text: paused ? '宸插仠姝�' : '杩愯涓�' });\nreturn { payload: state };",
"outputs": 1,
@@ -2324,14 +2352,14 @@
"y": 590,
"wires": [
[
- "mp_ctl_dbg"
+ "f9e446c88bdbfe7e"
]
]
},
{
- "id": "mp_ctl_dbg",
+ "id": "f9e446c88bdbfe7e",
"type": "debug",
- "z": "tab_mqtt_pipeline",
+ "z": "3df84dbf3ac69e5e",
"name": "鍚仠鐘舵��",
"active": true,
"tosidebar": true,
diff --git a/flows_cred.json b/flows_cred.json
index b0e3441..b42bd0d 100644
--- a/flows_cred.json
+++ b/flows_cred.json
@@ -14,8 +14,5 @@
"mqtt_broker_local": {
"user": "admin",
"password": "public"
- },
- "129964fd2e838f95": {},
- "22db5d23f5f3b117": {},
- "5b954fff423a59e1": {}
+ }
}
\ No newline at end of file
diff --git a/package.json b/package.json
index b763ea1..fa78162 100644
--- a/package.json
+++ b/package.json
@@ -1,8 +1,12 @@
{
- "name": "node-red-data-collection",
- "description": "node-red 鏁版嵁閲囬泦骞冲彴",
+ "name": "node-red-data-collection-qiaoyi",
+ "description": "node-red 鏁版嵁閲囬泦骞冲彴 涔斾竴",
"version": "0.0.1",
- "dependencies": {},
+ "dependencies": {
+ "node-red-contrib-mssql-plus": "0.13.1",
+ "moment": "^2.31.0",
+ "node-red-contrib-moment": "^5.0.0"
+ },
"node-red": {
"settings": {
"flowFile": "flows.json",
--
Gitblit v1.9.1