This commit is contained in:
ruoyunbai 2025-11-03 21:48:44 +08:00
parent f999ec4792
commit cbba920fb3
2 changed files with 163 additions and 113 deletions

View File

@ -1146,11 +1146,11 @@
"id": "6b82573f9ffd406c",
"type": "http request",
"z": "2bbc1a949095492c",
"name": "创建",
"method": "POST",
"name": "创建",
"method": "use",
"ret": "txt",
"paytoqs": "ignore",
"url": "https://www.dev.ideas.cnpc/api/dms/well_kd_wellbore_ideas01/v1/cd_well",
"url": "",
"tls": "",
"persist": true,
"proxy": "",
@ -1158,7 +1158,7 @@
"authType": "",
"senderr": false,
"headers": [],
"x": 1030,
"x": 950,
"y": 480,
"wires": [
[
@ -1199,7 +1199,7 @@
"y": 320,
"wires": [
[
"af408af17987663d"
"6b82573f9ffd406c"
]
]
},
@ -1357,8 +1357,8 @@
"id": "1c0decb86a5b16bc",
"type": "http request",
"z": "2bbc1a949095492c",
"name": "查询列表",
"method": "POST",
"name": "查询列表",
"method": "use",
"ret": "txt",
"paytoqs": "ignore",
"url": "",
@ -1369,7 +1369,7 @@
"authType": "",
"senderr": false,
"headers": [],
"x": 290,
"x": 280,
"y": 420,
"wires": [
[
@ -1382,7 +1382,7 @@
"id": "c226f4cb78c4eeda",
"type": "function",
"z": "2bbc1a949095492c",
"name": "function 6",
"name": "判断是否为空",
"func": "try {\n \n const payload = JSON.parse(msg.payload);\n if (payload && payload.data && Array.isArray(payload.data.list)) {\n msg.isEmpty = payload.data.list.length === 0;\n } else {\n msg.isEmpty = false; \n }\n} catch (e) {\n \n \n msg.isEmpty = false\n}\n\n\nreturn msg;",
"outputs": 1,
"timeout": 0,
@ -1390,7 +1390,7 @@
"initialize": "",
"finalize": "",
"libs": [],
"x": 300,
"x": 320,
"y": 520,
"wires": [
[
@ -1425,7 +1425,7 @@
"wires": [
[
"58738307f84d7063",
"af408af17987663d"
"e9fc4a2ffe2cd375"
],
[
"0d33ba7f9e75ba14"
@ -1466,47 +1466,6 @@
"y": 560,
"wires": []
},
{
"id": "af408af17987663d",
"type": "change",
"z": "2bbc1a949095492c",
"name": "",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "{\"version\":\"1.0.0\",\"act\":-1,\"data\":[{\"dsid\":\"testid2\",\"wellId\":\"WELL-zzlhTEST-002\",\"wellCommonName\":\"zzlh测试用井名\",\"wellLegalName\":\"zzlh-test-01\",\"wellPurpose\":\"开发井\",\"wellType\":\"直井\",\"dataRegion\":\"ZZLH\",\"projectId\":\"PROJ-ZZLH-001\",\"projectName\":\"zzlh测试地质单元\",\"orgId\":\"ORG-ZZLH-01\",\"orgName\":\"zzlh采油厂\",\"bsflag\":1,\"wellState\":\"生产中\",\"spudDate\":\"2024-01-15\",\"completionDate\":\"2024-05-20\",\"prodDate\":\"2024-06-01\",\"egl\":145.5,\"kbd\":5.2,\"kb\":150.7,\"actualXAxis\":550123.45,\"actualYAxis\":4998765.32,\"coordinateSystemName\":\"zzlh测试坐标系\",\"geoDescription\":\"位于zzlh测试区域\",\"remarks\":\"这是一口用于系统测试的生产井。\",\"createUserId\":\"testuser001\",\"createDate\":\"2025-09-12T10:00:00Z\",\"updateUserId\":\"testuser001\",\"updateDate\":\"2025-09-12T10:00:00Z\"}]}",
"tot": "json"
},
{
"t": "set",
"p": "headers",
"pt": "msg",
"to": "{\"Content-Type\":\"application/json\",\"Authorization\":\"1\",\"Dataregion\":\"ZZLH\"}",
"tot": "json"
},
{
"t": "set",
"p": "rejectUnauthorized",
"pt": "msg",
"to": "false",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 880,
"y": 480,
"wires": [
[
"6b82573f9ffd406c"
]
]
},
{
"id": "eae40b8b1740da9d",
"type": "switch",
@ -1534,7 +1493,7 @@
"wires": [
[
"7f25bc1c56632834",
"7e2390487c525c25"
"9130d5e40d2e8b53"
],
[
"b32a8f9b0f2cd01b"
@ -1545,7 +1504,7 @@
"id": "dff6a9719efe6bb8",
"type": "function",
"z": "2bbc1a949095492c",
"name": "function 7",
"name": "判断创建结果",
"func": "try {\n const payloadObject = JSON.parse(msg.payload);\n msg.isCreated = (payloadObject.code === 0);\n\n} catch (e) {\n msg.isCreated = false;\n}\n\n// 返回更新后的 msg 对象\nreturn msg;",
"outputs": 1,
"timeout": 0,
@ -1553,7 +1512,7 @@
"initialize": "",
"finalize": "",
"libs": [],
"x": 1160,
"x": 1120,
"y": 540,
"wires": [
[
@ -1632,8 +1591,8 @@
"id": "6b971983d782d570",
"type": "http request",
"z": "2bbc1a949095492c",
"name": "删除",
"method": "DELETE",
"name": "删除",
"method": "use",
"ret": "txt",
"paytoqs": "ignore",
"url": "",
@ -1710,54 +1669,6 @@
]
]
},
{
"id": "7e2390487c525c25",
"type": "change",
"z": "2bbc1a949095492c",
"name": "",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "{\"version\":\"1.0.0\",\"data\":[\"testid2\"]}",
"tot": "json"
},
{
"t": "set",
"p": "headers",
"pt": "msg",
"to": "{\"Content-Type\":\"application/json\",\"Authorization\":\"1\",\"Dataregion\":\"ZZLH\"}",
"tot": "json"
},
{
"t": "set",
"p": "rejectUnauthorized",
"pt": "msg",
"to": "false",
"tot": "str"
},
{
"t": "set",
"p": "url",
"pt": "msg",
"to": "https://www.dev.ideas.cnpc/api/dms/well_kd_wellbore_ideas01/v1/cd_well",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 1580,
"y": 540,
"wires": [
[
"6b971983d782d570"
]
]
},
{
"id": "87da5039b77ae777",
"type": "debug",
@ -1909,8 +1820,8 @@
"name": "",
"statusCode": "",
"headers": {},
"x": 2370,
"y": 620,
"x": 2410,
"y": 700,
"wires": []
},
{
@ -1929,7 +1840,7 @@
"y": 560,
"wires": [
[
"608d38ac3750e9a9"
"ab1f2a98d3200f0d"
]
]
},
@ -2014,15 +1925,137 @@
"type": "link in",
"z": "2bbc1a949095492c",
"name": "crud子流程linkin",
"links": [],
"x": 175,
"links": [
"80da1e9b993f73dc"
],
"x": 65,
"y": 340,
"wires": [
[
"1c0decb86a5b16bc"
"b23f184ea63d57f8"
]
]
},
{
"id": "b23f184ea63d57f8",
"type": "function",
"z": "2bbc1a949095492c",
"name": "设置查询请求",
"func": "'use strict';\n\n/**\n * 根据 msg.crudFlow.list 设置查询请求,兼容旧的手工注入流程。\n */\n\nreturn configureListRequest(msg, node);\n\nfunction configureListRequest(message, node) {\n if (!message.crudFlow || !message.crudFlow.list) {\n return message;\n }\n\n const list = message.crudFlow.list;\n const baseUrl = message.crudFlow.baseUrl || '';\n\n message.method = (list.method || 'GET').toUpperCase();\n message.url = mergeUrl(baseUrl, list.path || '');\n message.headers = Object.assign({}, message.crudFlow.headers || {}, list.headers || {});\n\n if (list.payload !== undefined) {\n message.payload = clone(list.payload);\n }\n\n message.listRequestConfigured = true;\n return message;\n}\n\nfunction mergeUrl(base, path) {\n const prefix = (base || '').replace(/\\/+$/, '');\n const suffix = (path || '').replace(/^\\/+/, '');\n if (!prefix) {\n return `/${suffix}`;\n }\n if (!suffix) {\n return prefix;\n }\n return `${prefix}/${suffix}`;\n}\n\nfunction clone(value) {\n return value == null ? value : JSON.parse(JSON.stringify(value));\n}\n",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 280,
"y": 660,
"wires": [
[
"bd042d824b60b5ac"
]
]
},
{
"id": "bd042d824b60b5ac",
"type": "http request",
"z": "2bbc1a949095492c",
"name": "",
"method": "GET",
"ret": "txt",
"paytoqs": false,
"url": "",
"persist": false,
"insecureHTTPParser": false,
"authType": "",
"senderr": false,
"headers": [],
"x": 280,
"y": 720,
"wires": [
[
"c226f4cb78c4eeda"
]
]
},
{
"id": "e9fc4a2ffe2cd375",
"type": "function",
"z": "2bbc1a949095492c",
"name": "准备create",
"func": "'use strict';\n\n/**\n * 使用 msg.crudFlow.create 配置创建请求;若未提供则保持旧有注入负载。\n */\n\nreturn configureCreateRequest(msg, node);\n\nfunction configureCreateRequest(message, node) {\n if (!message.crudFlow || !message.crudFlow.create) {\n return message;\n }\n\n const create = message.crudFlow.create;\n const baseUrl = message.crudFlow.baseUrl || '';\n const payload = selectCreatePayload(create);\n\n message.method = (create.method || 'POST').toUpperCase();\n message.url = mergeUrl(baseUrl, create.path || '');\n message.headers = Object.assign({}, message.crudFlow.headers || {}, create.headers || {});\n\n if (payload !== undefined) {\n message.payload = clone(payload);\n }\n\n const identityField = message.crudFlow.identityField || message.identityField || 'dsid';\n const keyValue = payload && typeof payload === 'object'\n ? extractPrimaryKey(payload, identityField)\n : undefined;\n\n if (keyValue !== undefined) {\n message.primaryKeyValue = keyValue;\n message.crudFlow.delete = message.crudFlow.delete || {};\n message.crudFlow.delete.actualKey = keyValue;\n }\n\n return message;\n}\n\nfunction selectCreatePayload(create) {\n if (create.payload && Object.keys(create.payload).length > 0) {\n return create.payload;\n }\n if (create.samplePayload) {\n return create.samplePayload;\n }\n return undefined;\n}\n\nfunction extractPrimaryKey(payload, identityField) {\n if (!payload) {\n return undefined;\n }\n if (Object.prototype.hasOwnProperty.call(payload, identityField)) {\n return payload[identityField];\n }\n if (Array.isArray(payload.data) && payload.data.length > 0 && payload.data[0][identityField] !== undefined) {\n return payload.data[0][identityField];\n }\n return undefined;\n}\n\nfunction mergeUrl(base, path) {\n const prefix = (base || '').replace(/\\/+$/, '');\n const suffix = (path || '').replace(/^\\/+/, '');\n if (!prefix) {\n return `/${suffix}`;\n }\n if (!suffix) {\n return prefix;\n }\n return `${prefix}/${suffix}`;\n}\n\nfunction clone(value) {\n return value == null ? value : JSON.parse(JSON.stringify(value));\n}\n",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 750,
"y": 480,
"wires": [
[
"6b82573f9ffd406c"
]
]
},
{
"id": "9130d5e40d2e8b53",
"type": "function",
"z": "2bbc1a949095492c",
"name": "准备delete",
"func": "'use strict';\n\n/**\n * 依据 msg.crudFlow.delete 生成删除请求体,支持占位符 {{primaryKey}}。\n */\n\nreturn configureDeleteRequest(msg, node);\n\nfunction configureDeleteRequest(message, node) {\n if (!message.crudFlow || !message.crudFlow.delete) {\n return message;\n }\n\n const del = message.crudFlow.delete;\n const baseUrl = message.crudFlow.baseUrl || '';\n const primaryKeyValue = del.actualKey || message.primaryKeyValue || del.primaryKey || 'testid2';\n const method = (del.method || 'POST').toUpperCase();\n\n let path = del.path || '';\n let payload = null;\n\n if (method === 'DELETE' && path.includes('{')) {\n path = path.replace(/\\{[^}]+\\}/g, encodeURIComponent(primaryKeyValue));\n } else {\n const template = del.payloadTemplate || { version: '1.0.0', data: ['{{primaryKey}}'] };\n payload = materialiseTemplate(template, primaryKeyValue);\n }\n\n message.method = method;\n message.url = mergeUrl(baseUrl, path);\n message.headers = Object.assign({}, message.crudFlow.headers || {}, del.headers || {});\n\n if (payload !== null) {\n message.payload = payload;\n } else if (message.payload !== undefined) {\n delete message.payload;\n }\n\n return message;\n}\n\nfunction materialiseTemplate(template, primaryKeyValue) {\n const cloned = clone(template);\n return replacePlaceholder(cloned, primaryKeyValue);\n}\n\nfunction replacePlaceholder(value, primaryKeyValue) {\n if (typeof value === 'string') {\n return value.replace(/\\{\\{\\s*primaryKey\\s*\\}\\}/g, primaryKeyValue);\n }\n if (Array.isArray(value)) {\n return value.map(item => replacePlaceholder(item, primaryKeyValue));\n }\n if (value && typeof value === 'object') {\n const result = {};\n for (const key of Object.keys(value)) {\n result[key] = replacePlaceholder(value[key], primaryKeyValue);\n }\n return result;\n }\n return value;\n}\n\nfunction mergeUrl(base, path) {\n const prefix = (base || '').replace(/\\/+$/, '');\n const suffix = (path || '').replace(/^\\/+/, '');\n if (!prefix) {\n return `/${suffix}`;\n }\n if (!suffix) {\n return prefix;\n }\n return `${prefix}/${suffix}`;\n}\n\nfunction clone(value) {\n return value == null ? value : JSON.parse(JSON.stringify(value));\n}\n",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1570,
"y": 560,
"wires": [
[
"6b971983d782d570"
]
]
},
{
"id": "ab1f2a98d3200f0d",
"type": "function",
"z": "2bbc1a949095492c",
"name": "汇总",
"func": "'use strict';\n\n/**\n * 汇总 CRUD 执行结果,生成统一响应结构。\n */\n\nreturn summariseCrudResult(msg, node);\n\nfunction summariseCrudResult(message, node) {\n const identityField = (message.crudFlow && message.crudFlow.identityField) ||\n message.identityField || 'dsid';\n const primaryKey = (message.crudFlow && message.crudFlow.delete && message.crudFlow.delete.actualKey) ||\n message.primaryKeyValue || null;\n\n const listOk = message.listError ? false : true;\n const createOk = message.isCreated === undefined ? true : !!message.isCreated;\n const deleteOk = message.isDeleted === undefined ? true : !!message.isDeleted;\n\n const success = listOk && createOk && deleteOk;\n\n message.payload = {\n code: success ? 0 : 1,\n message: success ? '井创建删除流程测试成功' : '井创建删除流程部分失败',\n details: {\n listOk,\n createOk,\n deleteOk,\n identityField,\n primaryKey,\n },\n };\n\n return message;\n}\n",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 2310,
"y": 640,
"wires": [
[
"608d38ac3750e9a9",
"35caa921acd6676e"
]
]
},
{
"id": "35caa921acd6676e",
"type": "debug",
"z": "2bbc1a949095492c",
"name": "汇总结果",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 2500,
"y": 580,
"wires": []
},
{
"id": "fd3672b8ebb314ee",
"type": "http in",
@ -2413,7 +2446,8 @@
"y": 520,
"wires": [
[
"cfa3c9b06af4840e"
"cfa3c9b06af4840e",
"80da1e9b993f73dc"
]
]
},
@ -2433,5 +2467,18 @@
"x": 1060,
"y": 460,
"wires": []
},
{
"id": "80da1e9b993f73dc",
"type": "link out",
"z": "78d15f59dee4b6d8",
"name": "link out 1",
"mode": "link",
"links": [
"6c06fbe60248c14c"
],
"x": 1155,
"y": 540,
"wires": []
}
]

View File

@ -7,5 +7,8 @@
"0d437a2a77570c57": {},
"5921574867140eb3": {},
"551a78c76ae2bccf": {},
"540a5771113ca5dd": {}
"540a5771113ca5dd": {},
"6b82573f9ffd406c": {},
"1c0decb86a5b16bc": {},
"6b971983d782d570": {}
}