From c8462138ed44bee2ae68d6a3d9eb3bff857e50f1 Mon Sep 17 00:00:00 2001 From: SwTt29 <2055018491@qq.com> Date: Thu, 18 Dec 2025 14:21:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=89=8B=E5=8A=A8=E5=90=8C?= =?UTF-8?q?=E6=AD=A5=E6=97=B6jiandaoyun=5Frecord=5Fid=E4=B8=BAnull?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=8C=E5=B9=B6=E5=AE=8C=E5=96=84?= =?UTF-8?q?=E5=90=8C=E6=AD=A5=E7=8A=B6=E6=80=81=E6=9B=B4=E6=96=B0=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/services/jiandaoyunService.js | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/src/services/jiandaoyunService.js b/src/services/jiandaoyunService.js index ff3deb7..c8d9793 100644 --- a/src/services/jiandaoyunService.js +++ b/src/services/jiandaoyunService.js @@ -169,6 +169,27 @@ class JiandaoyunService { // 更新数据 const result = await this.updateDataInForm(recordId, jiandaoyunData); + + // 更新数据库中的同步状态 + if (connection && item.user && item.user.userId) { + try { + console.log(`更新用户 ${item.user.userId} 的同步状态`); + const [updateResult] = await connection.execute( + `UPDATE ${config.tables.users.name} SET ${config.sync.statusField} = ${config.sync.syncedValue}, ${config.sync.timeField} = NOW() WHERE userId = ?`, + [item.user.userId] + ); + + if (updateResult.affectedRows > 0) { + console.log(`✅ 成功更新用户 ${item.user.userId} 的同步状态`); + } else { + console.log(`⚠️ 更新用户 ${item.user.userId} 的同步状态失败: 未找到匹配的用户`); + } + } catch (updateError) { + console.error(`❌ 更新数据库同步状态时发生错误:`, updateError.message); + console.error(`错误堆栈:`, updateError.stack); + } + } + results.push({ success: true, updated: true, @@ -194,20 +215,20 @@ class JiandaoyunService { if (connection && item.user && item.user.userId) { try { - console.log(`准备更新用户 ${item.user.userId} 的jiandaoyun_record_id为 ${newRecordId}`); + 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 = ?`, + `UPDATE ${config.tables.users.name} SET jiandaoyun_record_id = ?, ${config.sync.statusField} = ${config.sync.syncedValue}, ${config.sync.timeField} = NOW() WHERE userId = ?`, [newRecordId, item.user.userId] ); console.log(`数据库更新结果:`, updateResult); if (updateResult.affectedRows > 0) { - console.log(`✅ 成功将简道云记录ID ${newRecordId} 保存到数据库`); + console.log(`✅ 成功将简道云记录ID ${newRecordId} 保存到数据库并更新同步状态`); } else { - console.log(`⚠️ 更新用户 ${item.user.userId} 的jiandaoyun_record_id失败: 未找到匹配的用户`); + console.log(`⚠️ 更新用户 ${item.user.userId} 的jiandaoyun_record_id和同步状态失败: 未找到匹配的用户`); } } catch (updateError) { - console.error(`❌ 更新数据库jiandaoyun_record_id时发生错误:`, updateError.message); + console.error(`❌ 更新数据库jiandaoyun_record_id和同步状态时发生错误:`, updateError.message); console.error(`错误堆栈:`, updateError.stack); } } else {