實作個人收藏、個人活動紀錄

This commit is contained in:
2025-09-11 17:40:07 +08:00
parent bc2104d374
commit 9c5dceb001
29 changed files with 3781 additions and 601 deletions

View File

@@ -0,0 +1,67 @@
const mysql = require('mysql2/promise');
// 資料庫連接配置
const dbConfig = {
host: 'mysql.theaken.com',
port: 33306,
user: 'AI_Platform',
password: 'Aa123456',
database: 'db_AI_Platform',
charset: 'utf8mb4'
};
async function checkAppStatus() {
let connection;
try {
console.log('連接到資料庫...');
connection = await mysql.createConnection(dbConfig);
const appId = '7f7395f4-ad9f-4d14-9e2c-84962ecbcfd7';
// 檢查應用狀態
console.log('檢查應用狀態...');
const appSql = 'SELECT id, name, is_active FROM apps WHERE id = ?';
const appResult = await connection.execute(appSql, [appId]);
console.log('應用狀態:', appResult[0]);
// 檢查活動日誌
console.log('\n檢查活動日誌...');
const activitySql = 'SELECT * FROM activity_logs WHERE resource_id = ? ORDER BY created_at DESC LIMIT 3';
const activityResult = await connection.execute(activitySql, [appId]);
console.log('活動日誌:', activityResult[0]);
// 測試 JOIN 查詢
console.log('\n測試 JOIN 查詢...');
const joinSql = `
SELECT
a.*,
u.name as creator_name,
u.department as creator_department,
al.created_at as last_used,
al.details
FROM activity_logs al
JOIN apps a ON al.resource_id = a.id
LEFT JOIN users u ON a.creator_id = u.id
WHERE al.user_id = ?
AND al.action = 'view'
AND al.resource_type = 'app'
AND a.is_active = TRUE
ORDER BY al.created_at DESC
LIMIT ?
`;
const joinResult = await connection.execute(joinSql, ['7fbe6712-fcce-45b8-9889-608232161315', 10]);
console.log('JOIN 查詢結果:', joinResult[0]);
} catch (error) {
console.error('檢查過程中發生錯誤:', error);
} finally {
if (connection) {
await connection.end();
console.log('資料庫連接已關閉');
}
}
}
// 執行檢查
checkAppStatus().catch(console.error);