This commit is contained in:
ping 2026-07-29 17:36:49 +08:00
parent 15079ad730
commit a66a9ee56c
8 changed files with 94 additions and 25 deletions

View File

@ -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 '唯一标识符',

View File

@ -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')

View File

@ -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, {})

View File

@ -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,

View File

@ -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,

View File

@ -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, {})

View File

@ -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,

View File

@ -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.