#!/bin/bash

echo "===== 旅游内容创作系统数据库信息 ====="
echo ""

echo "【1】数据库表列表："
mysql -u root -e "USE travel_content; SHOW TABLES;"
echo ""

echo "【2】用户信息："
mysql -u root -e "USE travel_content; SELECT id, userAccount, userName, userRole, userEmail FROM user;"
echo ""

echo "【3】景区信息："
mysql -u root -e "USE travel_content; SELECT id, name, address, advantage, highlight, isPublic FROM scenicSpot;"
echo ""

echo "【4】产品信息："
mysql -u root -e "USE travel_content; SELECT id, name, originPrice, realPrice, packageInfo, advantage FROM product;"
echo ""

echo "【5】内容风格："
mysql -u root -e "USE travel_content; SELECT id, styleName, description FROM contentStyle;"
echo ""

echo "【6】目标受众："
mysql -u root -e "USE travel_content; SELECT id, audienceName, description FROM targetAudience;"
echo ""

echo "【7】选题信息："
mysql -u root -e "USE travel_content; SELECT id, title, description, status FROM topics;"
echo ""

echo "【8】选题详细信息（包含关联数据）："
mysql -u root -e "USE travel_content; 
SELECT 
    CONCAT('【', t.id, '】') AS '选题ID',
    t.title AS '选题标题',
    t.description AS '选题描述',
    CASE 
        WHEN t.status = 'published' THEN '已发布'
        WHEN t.status = 'draft' THEN '草稿'
        ELSE t.status
    END AS '状态',
    u.userName AS '创建者',
    s.name AS '关联景区',
    p.name AS '关联产品',
    CONCAT(p.originPrice, ' → ', p.realPrice) AS '价格(原价→实际)',
    cs.styleName AS '内容风格',
    GROUP_CONCAT(DISTINCT ta.audienceName SEPARATOR '、') AS '目标受众'
FROM 
    topics t
JOIN 
    user u ON t.userId = u.id
JOIN 
    topicScenic ts ON t.id = ts.topicId
JOIN 
    scenicSpot s ON ts.scenicId = s.id
JOIN 
    topicProduct tp ON t.id = tp.topicId
JOIN 
    product p ON tp.productId = p.id
JOIN 
    topicStyle tst ON t.id = tst.topicId
JOIN 
    contentStyle cs ON tst.styleId = cs.id
LEFT JOIN 
    topicAudience taud ON t.id = taud.topicId
LEFT JOIN 
    targetAudience ta ON taud.audienceId = ta.id
WHERE 
    t.isDelete = 0
GROUP BY 
    t.id, t.title, t.description, t.status, u.userName, s.name, p.name, p.originPrice, p.realPrice, cs.styleName
ORDER BY 
    t.status = 'published' DESC, t.id;"
echo ""

echo "【9】素材文件夹："
mysql -u root -e "USE travel_content; SELECT id, userId, folderName, parentId, description, isPublic FROM material_folder;"
echo ""

echo "【10】素材信息："
mysql -u root -e "USE travel_content; SELECT id, userId, folderId, materialName, materialType, fileFormat, tags, isPublic FROM material;"
echo ""

echo "===== 数据库信息展示完毕 =====" 