實作前台 APP 呈現、APP 詳細頁面

This commit is contained in:
2025-09-10 00:27:26 +08:00
parent 900e33aefa
commit bc2104d374
17 changed files with 318 additions and 1565 deletions

View File

@@ -1396,6 +1396,7 @@ export class AppService {
SELECT
ur.id,
ur.rating,
ur.comment,
ur.rated_at,
u.name as user_name,
u.department as user_department,
@@ -1411,7 +1412,7 @@ export class AppService {
return reviews.map((review: any) => ({
id: review.id,
rating: review.rating,
review: '用戶評價', // 暫時使用固定文字,因為資料庫中沒有 review 欄位
review: review.comment || '用戶評價', // 使用 comment 欄位,如果為空則顯示預設文字
ratedAt: review.rated_at,
userName: review.user_name,
userDepartment: review.user_department,
@@ -1464,6 +1465,79 @@ export class AppService {
return { success: false, error: '刪除評價時發生錯誤' };
}
}
// 獲取應用部門列表
async getAppDepartments(): Promise<{ department: string; count: number }[]> {
try {
const sql = `
SELECT
u.department,
COUNT(DISTINCT a.id) as count
FROM apps a
JOIN users u ON a.creator_id = u.id
WHERE a.is_active = TRUE
GROUP BY u.department
ORDER BY count DESC, u.department ASC
`;
const departments = await this.query(sql);
return departments.map((dept: any) => ({
department: dept.department,
count: parseInt(dept.count)
}));
} catch (error) {
console.error('獲取應用部門列表錯誤:', error);
return [];
}
}
// 獲取應用類型列表
async getAppTypes(): Promise<{ type: string; count: number }[]> {
try {
const sql = `
SELECT
type,
COUNT(*) as count
FROM apps
WHERE is_active = TRUE
GROUP BY type
ORDER BY count DESC, type ASC
`;
const types = await this.query(sql);
return types.map((type: any) => ({
type: type.type,
count: parseInt(type.count)
}));
} catch (error) {
console.error('獲取應用類型列表錯誤:', error);
return [];
}
}
// 獲取應用分類列表
async getAppCategories(): Promise<{ category: string; count: number }[]> {
try {
const sql = `
SELECT
category,
COUNT(*) as count
FROM apps
WHERE is_active = TRUE
GROUP BY category
ORDER BY count DESC, category ASC
`;
const categories = await this.query(sql);
return categories.map((cat: any) => ({
category: cat.category,
count: parseInt(cat.count)
}));
} catch (error) {
console.error('獲取應用分類列表錯誤:', error);
return [];
}
}
}
// =====================================================