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 {