|
|
@ -82,7 +82,7 @@ class JiandaoyunService { |
|
|
const products = databaseData.products; |
|
|
const products = databaseData.products; |
|
|
console.log('产品数据:', JSON.stringify(products, null, 2)); |
|
|
console.log('产品数据:', JSON.stringify(products, null, 2)); |
|
|
|
|
|
|
|
|
if (products.length > 0) { |
|
|
if (products && products.length > 0) { |
|
|
const firstProduct = products[0]; |
|
|
const firstProduct = products[0]; |
|
|
jiandaoyunData[mapping.productName] = { value: firstProduct.productName || '' }; |
|
|
jiandaoyunData[mapping.productName] = { value: firstProduct.productName || '' }; |
|
|
jiandaoyunData[mapping.specification] = { value: firstProduct.specification || '' }; |
|
|
jiandaoyunData[mapping.specification] = { value: firstProduct.specification || '' }; |
|
|
@ -152,6 +152,20 @@ class JiandaoyunService { |
|
|
async batchSubmitData(dataList, connection) { |
|
|
async batchSubmitData(dataList, connection) { |
|
|
const results = []; |
|
|
const results = []; |
|
|
|
|
|
|
|
|
|
|
|
// 尝试从databaseService获取连接,如果参数中没有提供
|
|
|
|
|
|
let dbConnection = connection; |
|
|
|
|
|
if (!dbConnection) { |
|
|
|
|
|
try { |
|
|
|
|
|
const databaseService = require('./databaseService'); |
|
|
|
|
|
if (databaseService.connection) { |
|
|
|
|
|
dbConnection = databaseService.connection; |
|
|
|
|
|
console.log('从databaseService获取数据库连接成功'); |
|
|
|
|
|
} |
|
|
|
|
|
} catch (error) { |
|
|
|
|
|
console.log('无法从databaseService获取连接:', error.message); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
for (const item of dataList) { |
|
|
for (const item of dataList) { |
|
|
try { |
|
|
try { |
|
|
// 检查数据库中是否已有简道云记录ID
|
|
|
// 检查数据库中是否已有简道云记录ID
|
|
|
@ -171,10 +185,10 @@ class JiandaoyunService { |
|
|
const result = await this.updateDataInForm(recordId, jiandaoyunData); |
|
|
const result = await this.updateDataInForm(recordId, jiandaoyunData); |
|
|
|
|
|
|
|
|
// 更新数据库中的同步状态
|
|
|
// 更新数据库中的同步状态
|
|
|
if (connection && item.user && item.user.userId) { |
|
|
if (dbConnection && item.user && item.user.userId) { |
|
|
try { |
|
|
try { |
|
|
console.log(`更新用户 ${item.user.userId} 的同步状态`); |
|
|
console.log(`更新用户 ${item.user.userId} 的同步状态`); |
|
|
const [updateResult] = await connection.execute( |
|
|
const [updateResult] = await dbConnection.execute( |
|
|
`UPDATE ${config.tables.users.name} SET ${config.sync.statusField} = ${config.sync.syncedValue}, ${config.sync.timeField} = NOW() WHERE userId = ?`, |
|
|
`UPDATE ${config.tables.users.name} SET ${config.sync.statusField} = ${config.sync.syncedValue}, ${config.sync.timeField} = NOW() WHERE userId = ?`, |
|
|
[item.user.userId] |
|
|
[item.user.userId] |
|
|
); |
|
|
); |
|
|
@ -213,10 +227,10 @@ class JiandaoyunService { |
|
|
const newRecordId = result.data._id; |
|
|
const newRecordId = result.data._id; |
|
|
console.log(`获取到简道云记录ID: ${newRecordId}`); |
|
|
console.log(`获取到简道云记录ID: ${newRecordId}`); |
|
|
|
|
|
|
|
|
if (connection && item.user && item.user.userId) { |
|
|
if (dbConnection && item.user && item.user.userId) { |
|
|
try { |
|
|
try { |
|
|
console.log(`准备更新用户 ${item.user.userId} 的jiandaoyun_record_id为 ${newRecordId} 并设置同步状态`); |
|
|
console.log(`准备更新用户 ${item.user.userId} 的jiandaoyun_record_id为 ${newRecordId} 并设置同步状态`); |
|
|
const [updateResult] = await connection.execute( |
|
|
const [updateResult] = await dbConnection.execute( |
|
|
`UPDATE ${config.tables.users.name} SET jiandaoyun_record_id = ?, ${config.sync.statusField} = ${config.sync.syncedValue}, ${config.sync.timeField} = NOW() 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] |
|
|
[newRecordId, item.user.userId] |
|
|
); |
|
|
); |
|
|
@ -233,7 +247,7 @@ class JiandaoyunService { |
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
console.log(`⚠️ 无法更新数据库: 缺少connection或item.user.userId`); |
|
|
console.log(`⚠️ 无法更新数据库: 缺少connection或item.user.userId`); |
|
|
console.log(`connection存在: ${!!connection}`); |
|
|
console.log(`connection存在: ${!!dbConnection}`); |
|
|
console.log(`item.user存在: ${!!item.user}`); |
|
|
console.log(`item.user存在: ${!!item.user}`); |
|
|
console.log(`item.user.userId存在: ${item.user ? !!item.user.userId : 'N/A'}`); |
|
|
console.log(`item.user.userId存在: ${item.user ? !!item.user.userId : 'N/A'}`); |
|
|
} |
|
|
} |
|
|
|