Files
shz-backend/docs/cms-news-info-api.md
lapuda c1a7aa3532 feat: Add news information management module with API and database support
- Introduced new API endpoints for querying and managing news information in the CMS.
- Implemented data model for NewsInfo and NewsInfoQuery with validation.
- Created NewsInfoMapper for database interactions and corresponding XML mappings.
- Developed INewsInfoService interface and its implementation for business logic.
- Added RichTextSanitizer utility for cleaning HTML content to prevent XSS attacks.
- Created unit tests for RichTextSanitizer to ensure proper functionality.
- Updated database schema with news_info table and necessary fields, including status and module.
- Added migration scripts for setting up the news information module in the database.
- Integrated jsoup library for HTML sanitization.
2026-07-20 14:54:15 +08:00

4.4 KiB
Raw Blame History

新闻资讯 API

约定

  • 基础地址:/api
  • CMS 接口需要登录,并按菜单权限校验。
  • 上下架状态:0 上架,1 下架。新增新闻默认下架。
  • module 保存业务字典 news_moduledict_value,展示名称来自 dict_label。管理员可以在 CMS 的“业务字典”中继续维护模块项。
  • content 为富文本 HTML。服务端保存前会按白名单清理脚本、事件属性、危险协议等内容。
  • 列表接口返回分页结构:{ code, msg, total, rows };详情和写操作返回标准 RuoYi 结构。

CMS 管理接口

1. 查询新闻资讯列表

GET /api/cms/newsInfo/list

权限:cms:newsInfo:list

请求参数:

参数 类型 必填 说明
pageNum integer 页码,默认 1
pageSize integer 每页条数,默认 10
title string 标题关键词
module string news_module 字典值
status string 0 上架,1 下架

示例:

GET /api/cms/newsInfo/list?pageNum=1&pageSize=10&module=interview_tips&status=1

响应示例:

{
  "code": 200,
  "msg": "查询成功",
  "total": 1,
  "rows": [
    {
      "id": 1,
      "module": "interview_tips",
      "moduleName": "面试技巧",
      "title": "结构化面试准备指南",
      "status": "1",
      "createTime": "2026-07-20 15:00:00",
      "updateTime": null
    }
  ]
}

列表不返回正文,查看正文使用详情接口。

2. 查询新闻资讯详情

GET /api/cms/newsInfo/{id}

权限:cms:newsInfo:query

响应示例:

{
  "code": 200,
  "msg": "查询成功",
  "data": {
    "id": 1,
    "module": "interview_tips",
    "moduleName": "面试技巧",
    "title": "结构化面试准备指南",
    "content": "<h2>准备重点</h2><p><strong>先了解岗位要求。</strong></p>",
    "status": "1",
    "createBy": "admin",
    "createTime": "2026-07-20 15:00:00",
    "updateBy": "admin",
    "updateTime": null,
    "remark": ""
  }
}

3. 新增新闻资讯

POST /api/cms/newsInfo
Content-Type: application/json

权限:cms:newsInfo:add

请求体:

{
  "module": "job_information",
  "title": "求职资讯标题",
  "content": "<p>经过白名单清理的富文本正文。</p>",
  "status": "1",
  "remark": ""
}

module 必须是启用状态的 news_module 字典值;status 省略时按下架处理。标题不能为空且最多 200 个字符,正文必须包含文字或图片内容。

4. 修改新闻资讯

PUT /api/cms/newsInfo
Content-Type: application/json

权限:cms:newsInfo:edit

请求体与新增相同,必须带 id

{
  "id": 1,
  "module": "interview_tips",
  "title": "更新后的标题",
  "content": "<p>更新后的正文。</p>",
  "status": "1",
  "remark": ""
}

5. 上架或下架

PUT /api/cms/newsInfo/changeStatus?id=1&status=0

权限:cms:newsInfo:status

参数 status 只能是 0(上架)或 1(下架)。接口会同时记录更新人和更新时间。

6. 删除新闻资讯

DELETE /api/cms/newsInfo/{ids}

权限:cms:newsInfo:remove

ids 支持逗号分隔的多个 ID例如

DELETE /api/cms/newsInfo/1,2,3

删除使用软删除,数据不会从数据库物理移除。

公开查询接口

7. 查询已上架新闻资讯

GET /api/app/newsInfo/list

无需登录。参数与 CMS 列表相同,但服务端始终强制 status=0;调用方可使用 titlemodule 过滤。列表同样不返回正文。

8. 查询已上架新闻资讯详情

GET /api/app/newsInfo/{id}

无需登录。只有同时满足“未删除、已上架”的记录才会返回;下架或不存在时 datanull

业务字典

新闻模块选项通过现有接口查询:

GET /api/cms/dict/data/type/news_module

典型初始化数据:

dict_value dict_label
job_information 求职资讯
interview_tips 面试技巧
resume_guide 简历指南
industry_guide 行业指南
policy_regulations 政策法规

图片上传

富文本编辑器图片使用现有通用上传接口:

POST /api/common/upload
Content-Type: multipart/form-data

表单字段:file。响应中的 url 用于插入富文本图片。