Compare commits
No commits in common. "65d5dc0920c8bb7cfcb8252219e1f3d11bc9b5c6" and "2dbf1a859e85dd4fc9f9d24fb78c00c8ad6aa8a6" have entirely different histories.
65d5dc0920
...
2dbf1a859e
@ -1,4 +1,3 @@
|
||||
# 新版本表结构
|
||||
CREATE TABLE `enterprise_news_article` (
|
||||
`id` varchar(32) NOT NULL COMMENT '唯一标识符',
|
||||
`domain_name` varchar(64) NOT NULL COMMENT '所属域名',
|
||||
@ -10,10 +9,6 @@ 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 '文章摘要',
|
||||
@ -28,6 +23,7 @@ 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 '唯一标识符',
|
||||
|
||||
@ -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_zh, cover_img_en,
|
||||
content_zh, content_en, publish_time_zh, publish_time_en, read_count
|
||||
summary_zh, summary_en, cover_img, content_zh, content_en,
|
||||
publish_time, read_count
|
||||
from enterprise_news_article
|
||||
where id = '%s' and status = '1' and del_flg = '0';
|
||||
""" % ns.get('id')
|
||||
|
||||
@ -30,14 +30,10 @@ 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_zh, cover_img_en,
|
||||
publish_time_zh, publish_time_en, read_count
|
||||
summary_zh, summary_en, cover_img, publish_time, read_count
|
||||
from enterprise_news_article
|
||||
where %s
|
||||
order by greatest(
|
||||
ifnull(publish_time_zh, '1000-01-01'),
|
||||
ifnull(publish_time_en, '1000-01-01')
|
||||
) desc, update_time desc
|
||||
order by publish_time desc, update_time desc
|
||||
limit %s offset %s;
|
||||
""" % (where_clause, page_size, offset)
|
||||
result = await sor.sqlExe(search_sql, {})
|
||||
|
||||
@ -27,13 +27,11 @@ 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_zh': ns.get('cover_img_zh'),
|
||||
'cover_img_en': ns.get('cover_img_en'),
|
||||
'cover_img': ns.get('cover_img'),
|
||||
'content_zh': ns.get('content_zh'),
|
||||
'content_en': ns.get('content_en'),
|
||||
'status': status,
|
||||
'publish_time_zh': ns.get('publish_time_zh') or None,
|
||||
'publish_time_en': ns.get('publish_time_en') or None,
|
||||
'publish_time': ns.get('publish_time'),
|
||||
'read_count': 0,
|
||||
'del_flg': '0'
|
||||
}
|
||||
@ -42,13 +40,8 @@ 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':
|
||||
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')
|
||||
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')
|
||||
await sor.sqlExe(publish_sql, {})
|
||||
return {
|
||||
'status': True,
|
||||
|
||||
@ -8,15 +8,11 @@ async def news_article_publish(ns={}):
|
||||
db = DBPools()
|
||||
async with db.sqlorContext('kboss') as sor:
|
||||
try:
|
||||
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'))
|
||||
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')
|
||||
await sor.sqlExe(publish_sql, {})
|
||||
return {
|
||||
'status': True,
|
||||
|
||||
@ -70,14 +70,11 @@ 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_zh, cover_img_en, content_zh, content_en,
|
||||
status, publish_time_zh, publish_time_en, read_count, update_time, create_at
|
||||
summary_zh, summary_en, cover_img, content_zh, content_en, status,
|
||||
publish_time, read_count, update_time, create_at
|
||||
from enterprise_news_article
|
||||
where %s
|
||||
order by greatest(
|
||||
ifnull(publish_time_zh, '1000-01-01'),
|
||||
ifnull(publish_time_en, '1000-01-01')
|
||||
) desc, update_time desc
|
||||
order by publish_time desc, update_time desc
|
||||
limit %s offset %s;
|
||||
""" % (where_clause, page_size, offset)
|
||||
result = await sor.sqlExe(search_sql, {})
|
||||
|
||||
@ -10,14 +10,12 @@ 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',
|
||||
'cover_img_zh', 'cover_img_en', 'publish_time_zh', 'publish_time_en'
|
||||
'summary_zh', 'summary_en', 'content_zh', 'content_en'
|
||||
]:
|
||||
if field in ns:
|
||||
if field in ['publish_time_zh', 'publish_time_en']:
|
||||
ns_dic[field] = ns.get(field) or None
|
||||
else:
|
||||
ns_dic[field] = ns.get(field)
|
||||
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 {
|
||||
@ -25,17 +23,15 @@ 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':
|
||||
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')
|
||||
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')
|
||||
await sor.sqlExe(publish_sql, {})
|
||||
return {
|
||||
'status': True,
|
||||
|
||||
@ -185,49 +185,3 @@ 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.
|
||||
|
||||
@ -10,12 +10,9 @@
|
||||
|
||||
- 中文:`title_zh`、`article_type_zh`、`summary_zh`、`content_zh`
|
||||
- 英文:`title_en`、`article_type_en`、`summary_en`、`content_en`
|
||||
- 中文扩展:`cover_img_zh`、`publish_time_zh`
|
||||
- 英文扩展:`cover_img_en`、`publish_time_en`
|
||||
- 共用:`status`、`read_count`
|
||||
- 共用:`cover_img`、`status`、`publish_time`、`read_count`
|
||||
|
||||
新增文章仅要求 `title_zh` 必填,其余中英文字段允许为空。
|
||||
文章发布时,如果未传中英文发布时间,两个字段都默认当天日期。
|
||||
|
||||
## 接口调整
|
||||
|
||||
@ -25,20 +22,16 @@
|
||||
- `news_article_detail.dspy`:返回全部中英文字段。
|
||||
- `front_news_search.dspy`:支持中英文标题和类型筛选,返回全部中英文字段。
|
||||
- `front_news_detail.dspy`:返回全部中英文字段,并保持阅读量加一。
|
||||
- `news_article_publish.dspy`:支持分别设置中英文发布时间,未传时均默认当天。
|
||||
|
||||
下架、删除接口不涉及语言字段,不调整。
|
||||
发布、下架、删除接口不涉及语言字段,不调整。
|
||||
|
||||
## 兼容边界
|
||||
|
||||
旧字段已由数据库移除非空约束,本次接口不再维护旧字段。调用方需要改为传入和读取中英文新字段。
|
||||
旧字段 `cover_img`、`publish_time` 同样不再读写。列表按两个发布时间中的较晚日期倒序排列,再按更新时间倒序排列。
|
||||
|
||||
## 验证
|
||||
|
||||
- 新增时缺少 `title_zh` 返回校验错误。
|
||||
- 新增、更新后详情能完整返回中英文字段。
|
||||
- 后台和前端列表能按中英文标题、类型筛选。
|
||||
- 新增、编辑、列表和详情能分别读写中英文封面及发布时间。
|
||||
- 发布时未传中英文发布时间,两个字段均写入当天日期。
|
||||
- 前端详情仍仅允许读取已发布文章,并正确增加阅读量。
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user