|
@@ -31,9 +31,9 @@ export async function POST(req: any) {
|
|
|
|
|
|
|
|
const [rows, fields] = await connection.query('SELECT * FROM dialog where id = ?', [id]);
|
|
const [rows, fields] = await connection.query('SELECT * FROM dialog where id = ?', [id]);
|
|
|
|
|
|
|
|
- if (!rows) {
|
|
|
|
|
|
|
+ if (rows.length === 0) {
|
|
|
// 执行 MySQL 添加头表
|
|
// 执行 MySQL 添加头表
|
|
|
- await connection.execute('INSERT INTO dialog (id, create_time) VALUES (?,?)', [data, new Date])
|
|
|
|
|
|
|
+ connection.execute('INSERT INTO dialog (id, create_time) VALUES (?,?)', [id, new Date])
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
messages.forEach(async function (message) {
|
|
messages.forEach(async function (message) {
|
|
@@ -41,11 +41,10 @@ export async function POST(req: any) {
|
|
|
const role = message.role;
|
|
const role = message.role;
|
|
|
const createDate = message.date;
|
|
const createDate = message.date;
|
|
|
const content = message.content;
|
|
const content = message.content;
|
|
|
- console.log(message);
|
|
|
|
|
const [detailRows, fields] = await connection.query('SELECT * FROM dialog_detail where id = ?', [detailId]);
|
|
const [detailRows, fields] = await connection.query('SELECT * FROM dialog_detail where id = ?', [detailId]);
|
|
|
- if (!detailRows) {
|
|
|
|
|
|
|
+ if (detailRows.length === 0) {
|
|
|
// 执行 MySQL 添加头表
|
|
// 执行 MySQL 添加头表
|
|
|
- await connection.execute('INSERT INTO dialog_detail (id,dialog_id,type,content,create_by, create_time) VALUES (?, ?, ?)', [detailId, id, role, content, role, createDate])
|
|
|
|
|
|
|
+ connection.execute('INSERT INTO dialog_detail (id,dialog_id,type,content,create_by, create_time) VALUES (?, ?, ?,?,?,?)', [detailId, id, role, content, role, createDate])
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
|
|
@@ -64,7 +63,7 @@ export async function GET() {
|
|
|
const connection = await pool.getConnection()
|
|
const connection = await pool.getConnection()
|
|
|
|
|
|
|
|
// 执行 MySQL 查询
|
|
// 执行 MySQL 查询
|
|
|
- const [rows, fields] = await connection.query('SELECT he.id,he.dialog_name,de.id did,de.dialog_id,de.type,de.content FROM dialog he left join dialog_detail de on he.id = de.dialog_id')
|
|
|
|
|
|
|
+ const [rows, fields] = await connection.query('SELECT he.id,he.dialog_name,de.id did,de.dialog_id,de.type,de.content,de.create_time FROM dialog he left join dialog_detail de on he.id = de.dialog_id')
|
|
|
|
|
|
|
|
// 释放连接回连接池
|
|
// 释放连接回连接池
|
|
|
connection.release()
|
|
connection.release()
|