From f7a5dde9984ccd1e2c682891496f958ad523d438 Mon Sep 17 00:00:00 2001 From: SwTt29 <2055018491@qq.com> Date: Thu, 18 Dec 2025 14:13:43 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=BC=BAbatchSubmitData=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E7=9A=84=E9=94=99=E8=AF=AF=E5=A4=84=E7=90=86=E5=92=8C?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E8=BE=93=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/services/jiandaoyunService.js | 39 ++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/src/services/jiandaoyunService.js b/src/services/jiandaoyunService.js index 32a1936..ff3deb7 100644 --- a/src/services/jiandaoyunService.js +++ b/src/services/jiandaoyunService.js @@ -186,13 +186,40 @@ class JiandaoyunService { const result = await this.submitDataToForm(jiandaoyunData); // 保存返回的记录ID到数据库 - if (result.data && result.data._id && connection && item.user && item.user.userId) { + console.log('检查返回结果结构:', JSON.stringify(result, null, 2)); + + if (result && result.data && result.data._id) { const newRecordId = result.data._id; - await connection.execute( - `UPDATE ${config.tables.users.name} SET jiandaoyun_record_id = ? WHERE userId = ?`, - [newRecordId, item.user.userId] - ); - console.log(`已将简道云记录ID ${newRecordId} 保存到数据库`); + console.log(`获取到简道云记录ID: ${newRecordId}`); + + if (connection && item.user && item.user.userId) { + try { + console.log(`准备更新用户 ${item.user.userId} 的jiandaoyun_record_id为 ${newRecordId}`); + const [updateResult] = await connection.execute( + `UPDATE ${config.tables.users.name} SET jiandaoyun_record_id = ? WHERE userId = ?`, + [newRecordId, item.user.userId] + ); + + console.log(`数据库更新结果:`, updateResult); + if (updateResult.affectedRows > 0) { + console.log(`✅ 成功将简道云记录ID ${newRecordId} 保存到数据库`); + } else { + console.log(`⚠️ 更新用户 ${item.user.userId} 的jiandaoyun_record_id失败: 未找到匹配的用户`); + } + } catch (updateError) { + console.error(`❌ 更新数据库jiandaoyun_record_id时发生错误:`, updateError.message); + console.error(`错误堆栈:`, updateError.stack); + } + } else { + console.log(`⚠️ 无法更新数据库: 缺少connection或item.user.userId`); + console.log(`connection存在: ${!!connection}`); + console.log(`item.user存在: ${!!item.user}`); + console.log(`item.user.userId存在: ${item.user ? !!item.user.userId : 'N/A'}`); + } + } else { + console.log(`⚠️ 简道云API返回结果中没有包含有效的记录ID`); + console.log(`result.data存在: ${!!result.data}`); + console.log(`result.data._id存在: ${result.data ? !!result.data._id : 'N/A'}`); } results.push({