v1.2.64 - 修复龙钞统计数据API

This commit is contained in:
甲辰生产 2026-04-08 15:27:52 +08:00
parent d207d6d329
commit 90ce5a031f
1 changed files with 67 additions and 52 deletions

View File

@ -259,64 +259,79 @@ def get_dragons_stats_today(
"""获取今日龙钞详细统计数据(按号码分类)""" """获取今日龙钞详细统计数据(按号码分类)"""
from sqlalchemy import text from sqlalchemy import text
# 查询今日龙钞数据,按分类统计 # 带4龙钞包含"龙"且包含"4"
result = db.execute(text(""" dai4 = db.execute(text("""
SELECT SELECT
category,
COUNT(*) as total, COUNT(*) as total,
SUM(CASE WHEN content LIKE '%带4%' OR title LIKE '%带4%' THEN 1 ELSE 0 END) as dai4, SUM(CASE WHEN post_type = 'deal' THEN 1 ELSE 0 END) as deals,
SUM(CASE WHEN content NOT LIKE '%带4%' AND title NOT LIKE '%带4%' AND (content LIKE '%无4%' OR title LIKE '%无4%') THEN 1 ELSE 0 END) as wu4, SUM(CASE WHEN post_type = 'want' THEN 1 ELSE 0 END) as wants
SUM(CASE WHEN (content LIKE '%无47%' OR title LIKE '%无47%') AND (content NOT LIKE '%无247%' AND title NOT LIKE '%无247%') THEN 1 ELSE 0 END) as wu47, FROM yichens_posts
SUM(CASE WHEN (content LIKE '%无247%' OR title LIKE '%无247%') AND (content NOT LIKE '%无347%' AND title NOT LIKE '%无347%') THEN 1 ELSE 0 END) as wu247, WHERE post_time >= CURRENT_DATE
SUM(CASE WHEN content LIKE '%无347%' OR title LIKE '%无347%' THEN 1 ELSE 0 END) as wu347 AND category LIKE '%%'
FROM yichen_posts AND (content LIKE '%带4%' OR title LIKE '%带4%')
WHERE created_at >= CURRENT_DATE """)).fetchone()
AND (category LIKE '%%' OR category LIKE '%龙钞%')
GROUP BY category
"""))
rows = result.fetchall() # 无4龙钞包含"龙"且包含"无4"但不包含"无47"
wu4 = db.execute(text("""
# 汇总统计
dai4_count = sum(r[2] or 0 for r in rows)
wu4_count = sum(r[3] or 0 for r in rows)
wu47_count = sum(r[4] or 0 for r in rows)
wu247_count = sum(r[5] or 0 for r in rows)
wu347_count = sum(r[6] or 0 for r in rows)
# 查询出售和求购分类
deals_result = db.execute(text("""
SELECT SELECT
SUM(CASE WHEN content LIKE '%带4%' OR title LIKE '%带4%' THEN 1 ELSE 0 END) as dai4_deals, COUNT(*) as total,
SUM(CASE WHEN (content NOT LIKE '%带4%' AND title NOT LIKE '%带4%') AND (content LIKE '%无4%' OR title LIKE '%无4%') THEN 1 ELSE 0 END) as wu4_deals, SUM(CASE WHEN post_type = 'deal' THEN 1 ELSE 0 END) as deals,
SUM(CASE WHEN (content LIKE '%无47%' OR title LIKE '%无47%') AND (content NOT LIKE '%无247%' AND title NOT LIKE '%无247%') THEN 1 ELSE 0 END) as wu47_deals, SUM(CASE WHEN post_type = 'want' THEN 1 ELSE 0 END) as wants
SUM(CASE WHEN (content LIKE '%无247%' OR title LIKE '%无247%') AND (content NOT LIKE '%无347%' AND title NOT LIKE '%无347%') THEN 1 ELSE 0 END) as wu247_deals, FROM yichens_posts
SUM(CASE WHEN content LIKE '%无347%' OR title LIKE '%无347%' THEN 1 ELSE 0 END) as wu347_deals WHERE post_time >= CURRENT_DATE
FROM yichen_posts AND category LIKE '%%'
WHERE created_at >= CURRENT_DATE AND (content LIKE '%无4%' OR title LIKE '%无4%')
AND (category LIKE '%%' OR category LIKE '%龙钞%') AND content NOT LIKE '%无47%'
AND category NOT LIKE '%求购%' AND title NOT LIKE '%无47%'
""")) AND content NOT LIKE '%无247%'
deals_row = deals_result.fetchone() AND title NOT LIKE '%无247%'
""")).fetchone()
wants_result = db.execute(text(""" # 无47龙钞包含"龙"且包含"无47"但不包含"无247"
wu47 = db.execute(text("""
SELECT SELECT
SUM(CASE WHEN content LIKE '%带4%' OR title LIKE '%带4%' THEN 1 ELSE 0 END) as dai4_wants, COUNT(*) as total,
SUM(CASE WHEN (content NOT LIKE '%带4%' AND title NOT LIKE '%带4%') AND (content LIKE '%无4%' OR title LIKE '%无4%') THEN 1 ELSE 0 END) as wu4_wants, SUM(CASE WHEN post_type = 'deal' THEN 1 ELSE 0 END) as deals,
SUM(CASE WHEN (content LIKE '%无47%' OR title LIKE '%无47%') AND (content NOT LIKE '%无247%' AND title NOT LIKE '%无247%') THEN 1 ELSE 0 END) as wu47_wants, SUM(CASE WHEN post_type = 'want' THEN 1 ELSE 0 END) as wants
SUM(CASE WHEN (content LIKE '%无247%' OR title LIKE '%无247%') AND (content NOT LIKE '%无347%' AND title NOT LIKE '%无347%') THEN 1 ELSE 0 END) as wu247_wants, FROM yichens_posts
SUM(CASE WHEN content LIKE '%无347%' OR title LIKE '%无347%' THEN 1 ELSE 0 END) as wu347_wants WHERE post_time >= CURRENT_DATE
FROM yichen_posts AND category LIKE '%%'
WHERE created_at >= CURRENT_DATE AND (content LIKE '%无47%' OR title LIKE '%无47%')
AND (category LIKE '%%' OR category LIKE '%龙钞%') AND content NOT LIKE '%无247%'
AND category LIKE '%求购%' AND title NOT LIKE '%无247%'
""")) """)).fetchone()
wants_row = wants_result.fetchone()
# 无247龙钞包含"龙"且包含"无247"但不包含"无347"
wu247 = db.execute(text("""
SELECT
COUNT(*) as total,
SUM(CASE WHEN post_type = 'deal' THEN 1 ELSE 0 END) as deals,
SUM(CASE WHEN post_type = 'want' THEN 1 ELSE 0 END) as wants
FROM yichens_posts
WHERE post_time >= CURRENT_DATE
AND category LIKE '%%'
AND (content LIKE '%无247%' OR title LIKE '%无247%')
AND content NOT LIKE '%无347%'
AND title NOT LIKE '%无347%'
""")).fetchone()
# 无347龙钞包含"龙"且包含"无347"
wu347 = db.execute(text("""
SELECT
COUNT(*) as total,
SUM(CASE WHEN post_type = 'deal' THEN 1 ELSE 0 END) as deals,
SUM(CASE WHEN post_type = 'want' THEN 1 ELSE 0 END) as wants
FROM yichens_posts
WHERE post_time >= CURRENT_DATE
AND category LIKE '%%'
AND (content LIKE '%无347%' OR title LIKE '%无347%')
""")).fetchone()
return { return {
"dai4": {"total": dai4_count, "deals": deals_row[0] or 0, "wants": wants_row[0] or 0}, "dai4": {"total": dai4[0] or 0, "deals": dai4[1] or 0, "wants": dai4[2] or 0},
"wu4": {"total": wu4_count, "deals": deals_row[1] or 0, "wants": wants_row[1] or 0}, "wu4": {"total": wu4[0] or 0, "deals": wu4[1] or 0, "wants": wu4[2] or 0},
"wu47": {"total": wu47_count, "deals": deals_row[2] or 0, "wants": wants_row[2] or 0}, "wu47": {"total": wu47[0] or 0, "deals": wu47[1] or 0, "wants": wu47[2] or 0},
"wu247": {"total": wu247_count, "deals": deals_row[3] or 0, "wants": wants_row[3] or 0}, "wu247": {"total": wu247[0] or 0, "deals": wu247[1] or 0, "wants": wu247[2] or 0},
"wu347": {"total": wu347_count, "deals": deals_row[4] or 0, "wants": wants_row[4] or 0} "wu347": {"total": wu347[0] or 0, "deals": wu347[1] or 0, "wants": wu347[2] or 0}
} }