From bb19b19c71eea297360b41429d73812b04eea9f2 Mon Sep 17 00:00:00 2001 From: Default User Date: Fri, 16 Jan 2026 17:28:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=95=B0=E6=8D=AE=E5=BA=93?= =?UTF-8?q?=E8=BF=9E=E6=8E=A5=E6=B3=84=E6=BC=8F=E9=97=AE=E9=A2=98=EF=BC=8C?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=B5=8B=E8=AF=95=E8=84=9A=E6=9C=AC=E5=BF=BD?= =?UTF-8?q?=E7=95=A5=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 4 ++++ Reject.js | 58 +++++++++++++++++++++++++++++++----------------------- 2 files changed, 37 insertions(+), 25 deletions(-) diff --git a/.gitignore b/.gitignore index d354dbf..6396410 100644 --- a/.gitignore +++ b/.gitignore @@ -116,6 +116,10 @@ dist # Stores VSCode versions used for testing VSCode extensions .vscode-test +# Test scripts +*.test.js +test-*.js + # yarn v2 .yarn/cache .yarn/unplugged diff --git a/Reject.js b/Reject.js index de18189..ba9b1aa 100644 --- a/Reject.js +++ b/Reject.js @@ -2008,31 +2008,39 @@ app.post('/api/supplies/log', async (req, res) => { } // 3. 插入日志到informationtra表 - const connection = await pool.getConnection(); - const [result] = await connection.query( - `INSERT INTO informationtra ( - tracompany, tradepartment, traorganization, trarole, - trauserName, traassistant, userId, operationEvent, - operationTime, originalData, modifiedData, changedFields - ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, - [ - logData.tracompany, - logData.tradepartment, - logData.traorganization, - logData.trarole, - logData.trauserName, - logData.traassistant, - logData.userId, - logData.operationEvent, - logData.operationTime, - logData.originalData, - logData.modifiedData, - logData.changedFields - ] - ); - connection.release(); - - sendResponse(res, true, { logId: result.insertId }, '日志记录成功'); + let connection; + try { + connection = await pool.getConnection(); + const [result] = await connection.query( + `INSERT INTO informationtra ( + tracompany, tradepartment, traorganization, trarole, + trauserName, traassistant, userId, operationEvent, + operationTime, originalData, modifiedData, changedFields + ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, + [ + logData.tracompany, + logData.tradepartment, + logData.traorganization, + logData.trarole, + logData.trauserName, + logData.traassistant, + logData.userId, + logData.operationEvent, + logData.operationTime, + logData.originalData, + logData.modifiedData, + logData.changedFields + ] + ); + sendResponse(res, true, { logId: result.insertId }, '日志记录成功'); + } catch (error) { + console.error('记录日志失败:', error); + sendResponse(res, false, null, '记录日志失败'); + } finally { + if (connection) { + connection.release(); + } + } } catch (error) { console.error('记录日志失败:', error); sendResponse(res, false, null, '记录日志失败');