From a66a9ee56cf443c90a228a627d4bcaf561b3347b Mon Sep 17 00:00:00 2001 From: ping <1017253325@qq.com> Date: Wed, 29 Jul 2026 17:36:49 +0800 Subject: [PATCH] update --- b/news/enterprise_news_article.sql | 6 ++- b/news/front_news_detail.dspy | 4 +- b/news/front_news_search.dspy | 8 +++- b/news/news_article_add.dspy | 15 ++++-- b/news/news_article_publish.dspy | 14 ++++-- b/news/news_article_search.dspy | 9 ++-- b/news/news_article_update.dspy | 17 +++---- .../2026-07-29-bilingual-enterprise-news.md | 46 +++++++++++++++++++ 8 files changed, 94 insertions(+), 25 deletions(-) diff --git a/b/news/enterprise_news_article.sql b/b/news/enterprise_news_article.sql index e6fea1f..4b264db 100644 --- a/b/news/enterprise_news_article.sql +++ b/b/news/enterprise_news_article.sql @@ -1,3 +1,4 @@ +# 新版本表结构 CREATE TABLE `enterprise_news_article` ( `id` varchar(32) NOT NULL COMMENT '唯一标识符', `domain_name` varchar(64) NOT NULL COMMENT '所属域名', @@ -9,6 +10,10 @@ CREATE TABLE `enterprise_news_article` ( `article_type_en` varchar(20) DEFAULT NULL COMMENT '英文文章类型', `content_zh` text DEFAULT NULL COMMENT '中文正文', `content_en` text DEFAULT NULL COMMENT '英文正文', + `cover_img_zh` varchar(255) DEFAULT NULL COMMENT '中文封面图片', + `cover_img_en` varchar(255) DEFAULT NULL COMMENT '英文封面图片', + `publish_time_zh` date DEFAULT NULL COMMENT '中文发布时间', + `publish_time_en` date DEFAULT NULL COMMENT '英文发布时间', `title` varchar(100) DEFAULT NULL COMMENT '文章标题', `article_type` varchar(20) DEFAULT NULL COMMENT '文章类型(企业动态/产品动态/行业洞察/活动资讯)', `summary` varchar(255) DEFAULT NULL COMMENT '文章摘要', @@ -23,7 +28,6 @@ CREATE TABLE `enterprise_news_article` ( PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC COMMENT='企业文章表'; - # 旧版本表结构 CREATE TABLE `enterprise_news_article` ( `id` varchar(32) NOT NULL COMMENT '唯一标识符', diff --git a/b/news/front_news_detail.dspy b/b/news/front_news_detail.dspy index bd7cbe4..fb19531 100644 --- a/b/news/front_news_detail.dspy +++ b/b/news/front_news_detail.dspy @@ -12,8 +12,8 @@ async def front_news_detail(ns={}): await sor.sqlExe(update_sql, {}) search_sql = """ select id, title_zh, title_en, article_type_zh, article_type_en, - summary_zh, summary_en, cover_img, content_zh, content_en, - publish_time, read_count + summary_zh, summary_en, cover_img_zh, cover_img_en, + content_zh, content_en, publish_time_zh, publish_time_en, read_count from enterprise_news_article where id = '%s' and status = '1' and del_flg = '0'; """ % ns.get('id') diff --git a/b/news/front_news_search.dspy b/b/news/front_news_search.dspy index 19b1035..c24eb05 100644 --- a/b/news/front_news_search.dspy +++ b/b/news/front_news_search.dspy @@ -30,10 +30,14 @@ async def front_news_search(ns={}): total_count = (await sor.sqlExe(count_sql, {}))[0]['total_count'] search_sql = """ select id, title_zh, title_en, article_type_zh, article_type_en, - summary_zh, summary_en, cover_img, publish_time, read_count + summary_zh, summary_en, cover_img_zh, cover_img_en, + publish_time_zh, publish_time_en, read_count from enterprise_news_article where %s - order by publish_time desc, update_time desc + order by greatest( + ifnull(publish_time_zh, '1000-01-01'), + ifnull(publish_time_en, '1000-01-01') + ) desc, update_time desc limit %s offset %s; """ % (where_clause, page_size, offset) result = await sor.sqlExe(search_sql, {}) diff --git a/b/news/news_article_add.dspy b/b/news/news_article_add.dspy index cf4b4d3..680041d 100644 --- a/b/news/news_article_add.dspy +++ b/b/news/news_article_add.dspy @@ -27,11 +27,13 @@ async def news_article_add(ns={}): 'article_type_en': ns.get('article_type_en'), 'summary_zh': ns.get('summary_zh'), 'summary_en': ns.get('summary_en'), - 'cover_img': ns.get('cover_img'), + 'cover_img_zh': ns.get('cover_img_zh'), + 'cover_img_en': ns.get('cover_img_en'), 'content_zh': ns.get('content_zh'), 'content_en': ns.get('content_en'), 'status': status, - 'publish_time': ns.get('publish_time'), + 'publish_time_zh': ns.get('publish_time_zh'), + 'publish_time_en': ns.get('publish_time_en'), 'read_count': 0, 'del_flg': '0' } @@ -40,8 +42,13 @@ async def news_article_add(ns={}): async with db.sqlorContext('kboss') as sor: try: await sor.C('enterprise_news_article', ns_dic) - if status == '1' and not ns.get('publish_time'): - publish_sql = """update enterprise_news_article set publish_time = current_timestamp() where id = '%s';""" % ns_dic.get('id') + if status == '1': + publish_sql = """ + update enterprise_news_article + set publish_time_zh = ifnull(publish_time_zh, current_date()), + publish_time_en = ifnull(publish_time_en, current_date()) + where id = '%s'; + """ % ns_dic.get('id') await sor.sqlExe(publish_sql, {}) return { 'status': True, diff --git a/b/news/news_article_publish.dspy b/b/news/news_article_publish.dspy index 219ab3a..853edf1 100644 --- a/b/news/news_article_publish.dspy +++ b/b/news/news_article_publish.dspy @@ -8,11 +8,15 @@ async def news_article_publish(ns={}): db = DBPools() async with db.sqlorContext('kboss') as sor: try: - publish_time = ns.get('publish_time') - if publish_time: - publish_sql = """update enterprise_news_article set status = '1', publish_time = '%s' where id = '%s' and del_flg = '0';""" % (publish_time, ns.get('id')) - else: - publish_sql = """update enterprise_news_article set status = '1' where id = '%s' and del_flg = '0';""" % ns.get('id') + publish_time_zh = "'%s'" % ns.get('publish_time_zh') if ns.get('publish_time_zh') else "ifnull(publish_time_zh, current_date())" + publish_time_en = "'%s'" % ns.get('publish_time_en') if ns.get('publish_time_en') else "ifnull(publish_time_en, current_date())" + publish_sql = """ + update enterprise_news_article + set status = '1', + publish_time_zh = %s, + publish_time_en = %s + where id = '%s' and del_flg = '0'; + """ % (publish_time_zh, publish_time_en, ns.get('id')) await sor.sqlExe(publish_sql, {}) return { 'status': True, diff --git a/b/news/news_article_search.dspy b/b/news/news_article_search.dspy index 72ee9f4..bfbc28a 100644 --- a/b/news/news_article_search.dspy +++ b/b/news/news_article_search.dspy @@ -70,11 +70,14 @@ async def news_article_search(ns={}): }) search_sql = """ select id, domain_name, title_zh, title_en, article_type_zh, article_type_en, - summary_zh, summary_en, cover_img, content_zh, content_en, status, - publish_time, read_count, update_time, create_at + summary_zh, summary_en, cover_img_zh, cover_img_en, content_zh, content_en, + status, publish_time_zh, publish_time_en, read_count, update_time, create_at from enterprise_news_article where %s - order by publish_time desc, update_time desc + order by greatest( + ifnull(publish_time_zh, '1000-01-01'), + ifnull(publish_time_en, '1000-01-01') + ) desc, update_time desc limit %s offset %s; """ % (where_clause, page_size, offset) result = await sor.sqlExe(search_sql, {}) diff --git a/b/news/news_article_update.dspy b/b/news/news_article_update.dspy index a8eac0c..ae3d493 100644 --- a/b/news/news_article_update.dspy +++ b/b/news/news_article_update.dspy @@ -10,12 +10,11 @@ async def news_article_update(ns={}): } for field in [ 'title_zh', 'title_en', 'article_type_zh', 'article_type_en', - 'summary_zh', 'summary_en', 'content_zh', 'content_en' + 'summary_zh', 'summary_en', 'content_zh', 'content_en', + 'cover_img_zh', 'cover_img_en', 'publish_time_zh', 'publish_time_en' ]: if field in ns: ns_dic[field] = ns.get(field) - if 'cover_img' in ns: - ns_dic['cover_img'] = ns.get('cover_img') if 'status' in ns: if ns.get('status') not in ['0', '1']: return { @@ -23,15 +22,17 @@ async def news_article_update(ns={}): 'msg': '状态错误' } ns_dic['status'] = ns.get('status') - if 'publish_time' in ns: - ns_dic['publish_time'] = ns.get('publish_time') - db = DBPools() async with db.sqlorContext('kboss') as sor: try: await sor.U('enterprise_news_article', ns_dic) - if ns.get('status') == '1' and not ns.get('publish_time'): - publish_sql = """update enterprise_news_article set publish_time = ifnull(publish_time, current_timestamp()) where id = '%s';""" % ns.get('id') + if ns.get('status') == '1': + publish_sql = """ + update enterprise_news_article + set publish_time_zh = ifnull(publish_time_zh, current_date()), + publish_time_en = ifnull(publish_time_en, current_date()) + where id = '%s'; + """ % ns.get('id') await sor.sqlExe(publish_sql, {}) return { 'status': True, diff --git a/docs/superpowers/plans/2026-07-29-bilingual-enterprise-news.md b/docs/superpowers/plans/2026-07-29-bilingual-enterprise-news.md index 90725ec..96fe9a6 100644 --- a/docs/superpowers/plans/2026-07-29-bilingual-enterprise-news.md +++ b/docs/superpowers/plans/2026-07-29-bilingual-enterprise-news.md @@ -185,3 +185,49 @@ git diff --check -- b/news ``` Expected: no output and exit code 0. + +### Task 5: Add bilingual cover images and publish times + +**Files:** +- Modify: `b/news/news_article_add.dspy` +- Modify: `b/news/news_article_update.dspy` +- Modify: `b/news/news_article_publish.dspy` +- Modify: `b/news/news_article_search.dspy` +- Modify: `b/news/front_news_search.dspy` +- Modify: `b/news/front_news_detail.dspy` + +- [ ] **Step 1: Replace shared write fields** + +Use `cover_img_zh`, `cover_img_en`, `publish_time_zh`, and +`publish_time_en` in add and update. Do not write `cover_img` or +`publish_time`. + +- [ ] **Step 2: Apply publication defaults** + +When status becomes `1`, set each missing publish-time column with: + +```sql +publish_time_zh = ifnull(publish_time_zh, current_date()), +publish_time_en = ifnull(publish_time_en, current_date()) +``` + +- [ ] **Step 3: Update publish endpoint** + +Accept both publish-time parameters and use `current_date()` for either +missing value while setting `status = '1'`. + +- [ ] **Step 4: Update list and detail output** + +Return both cover-image and publish-time columns. Sort lists by: + +```sql +greatest( + ifnull(publish_time_zh, '1000-01-01'), + ifnull(publish_time_en, '1000-01-01') +) desc, update_time desc +``` + +- [ ] **Step 5: Verify** + +Run static field-contract checks, IDE diagnostics, and +`git diff --check -- b/news`. Expected: all pass.