fix: 最新公告直接返回最新5条 + 显示来源网站 + 菜单调整
- latest_announcements 不再过滤 keyword_matched,返回全部最新5条 - 每条公告显示来源网站(广西政府采购网/大化县政府网采购公告) - 菜单「今日公告」改为顶级按钮「最新公告」,移除子菜单重复项
This commit is contained in:
@@ -245,7 +245,6 @@ class WeChatMessageHandler:
|
||||
async for db in get_db():
|
||||
stmt = (
|
||||
select(Announcement)
|
||||
.where(Announcement.keyword_matched == True) # noqa: E712
|
||||
.order_by(desc(Announcement.publish_date))
|
||||
.limit(5)
|
||||
)
|
||||
@@ -253,14 +252,16 @@ class WeChatMessageHandler:
|
||||
items = result.scalars().all()
|
||||
|
||||
if not items:
|
||||
await self.client.send_text("暂无匹配关键词的公告", from_user)
|
||||
await self.client.send_text("暂无公告", from_user)
|
||||
return None
|
||||
|
||||
lines = ["最新匹配公告(最近5条):"]
|
||||
lines = ["最新公告(最近5条):"]
|
||||
for i, ann in enumerate(items, 1):
|
||||
date_str = ann.publish_date.strftime("%m-%d") if ann.publish_date else "?"
|
||||
title = ann.title[:30] + "..." if len(ann.title) > 30 else ann.title
|
||||
lines.append(f"{i}. [{date_str}] {title}")
|
||||
date_str = ann.publish_date.strftime("%m-%d %H:%M") if ann.publish_date else "?"
|
||||
title = ann.title[:28] + "..." if len(ann.title) > 28 else ann.title
|
||||
source = ann.source_name or ann.source_code
|
||||
lines.append(f"{i}. [{date_str}] {source}")
|
||||
lines.append(f" {title}")
|
||||
await self.client.send_text("\n".join(lines), from_user)
|
||||
except Exception as e:
|
||||
logger.error(f"查询最新公告失败: {e}")
|
||||
|
||||
+2
-7
@@ -9,9 +9,9 @@ logger = logging.getLogger(__name__)
|
||||
MENU = {
|
||||
"button": [
|
||||
{
|
||||
"name": "今日公告",
|
||||
"name": "最新公告",
|
||||
"type": "click",
|
||||
"key": "today_stats",
|
||||
"key": "latest_announcements",
|
||||
},
|
||||
{
|
||||
"name": "查询",
|
||||
@@ -31,11 +31,6 @@ MENU = {
|
||||
"type": "click",
|
||||
"key": "workday_status",
|
||||
},
|
||||
{
|
||||
"name": "最新公告",
|
||||
"type": "click",
|
||||
"key": "latest_announcements",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user