# 资讯类别 — 接口说明 > 数据表:`biz_information_category`(DDL/种子见 `sql/biz_information_category.sql`)。 > 后端包:`com.ruoyi.web.modules.category`;Controller:`BizInformationCategoryController`。 > 前端 API:`ruoyi-ui/src/api/category/informationCategory.js`。 本文描述 **只读查询** 接口。JSON 字段名统一为英文 **`code`**、**`name`**(不再使用 `编号`、`名称`)。 --- ## 1. 数据模型摘要 | 库字段 | 含义 | 接口字段 | | --- | --- | --- | | `category_code` | 类别编码(业务唯一) | `code` | | `category_name` | 类别名称 | `name` | | `parent_code` | 上级编码,指向父节点 `category_code` | 建树用,平铺接口不返回 | | `category_type` | 类型(同父下分子组时使用,如养殖标准 1~5) | `categoryType`(仅树节点) | | `module_id` | 模块:`01` 养殖资讯、`02` 畜牧资源、`03` 农技课堂 | `/tree` 支持按 `moduleId` 筛选;树节点响应字段 `moduleId` | | `visible` | `1` 可见、`0` 不可见 | **仅 `/tree` 只返回 `visible=1`**;`/children` 不按 visible 过滤 | | `del_flag` | `0` 有效,`2` 逻辑删除 | 已删除记录不出现在接口结果中 | ### 1.1 种子数据层级(示意) | 根节点 `code` | `name` | 子节点说明 | | --- | --- | --- | | `001` | 养殖标准 | `category_type` 1~5 分组,叶子 `001001`~`001013` | | `002` | 科技项目指南 | 叶子 `002001`~`002004`,子项 `category_type` 多为 NULL | | `003` | 产业政策 | 叶子 `003001`~`003004`,子项 `category_type` 多为 NULL | ### 1.2 与业务模块、视图的对应 | 叶子 `code` 示例 | 业务用途 | | --- | --- | | `001001`~`001004` | 养殖标准(繁育/饲养等,`parentCode=001`,`categoryType=1`) | | `001005`~`001006` | 饲喂标准(`categoryType=2`) | | `001007`~`001010` | 设备实施作业标准(`categoryType=3`) | | `001011`~`001012` | 生长与出栏标准(`categoryType=4`) | | `001013` | 疾病决策(`categoryType=5`,**`visible=0`**,不出现在 `/tree`) | | `002001`~`002004` | 科技项目指南 `project_type` | | `003001`~`003004` | 产业政策宣传/补贴/共富等固定类型;亦用于 `v_farming_news` 中政策类资讯 | 移动端「养殖资讯」列表按 `type` 筛选时,`type` 取值与上述叶子 `code` 一致(见 `sql/biz_v_farming_news.sql`)。 --- ## 2. 通用约定 | 项 | 说明 | | --- | --- | | **Base Path** | `/category/informationCategory`(与项目 `context-path` 拼接) | | **鉴权** | 与若依登录态一致;须携带有效 Token(与业务后台其它 GET 接口相同) | | **响应封装** | RuoYi `AjaxResult`:`code`(HTTP 业务码,如 200)、`msg`、`data` | | **排序** | 库表查询按 `category_code` 升序;树内各级子节点同样按 `code` 升序 | | **错误** | `parentCode` 为空时,`/children` 返回 `msg`:「上级编码不能为空」 | --- ## 3. 查询类别树 仅返回 **`del_flag=0` 且 `visible=1`** 的类别;不可见节点(如 `001013` 疾病决策)不会出现在树中。若某节点的父级不可见或未命中筛选条件,该节点会作为**根节点**出现在 `data` 中(与建树逻辑一致)。 ### 3.1 请求 | 项 | 值 | | --- | --- | | **Method** | `GET` | | **URI** | `/category/informationCategory/tree` | **Query 参数(均可选)** | 参数 | 类型 | 必填 | 说明 | | --- | --- | --- | --- | | `categoryType` | string | 否 | 仅加载 `category_type` 等于该值的记录后再组装树 | | `moduleId` | string | 否 | 仅加载指定模块:`01` 养殖资讯、`02` 畜牧资源、`03` 农技课堂 | 示例: ```http GET /category/informationCategory/tree GET /category/informationCategory/tree?moduleId=01 GET /category/informationCategory/tree?categoryType=1&moduleId=01 ``` ### 3.2 响应 `data` 类型:`InformationCategoryTreeVo[]`,森林(多个根节点)。单节点字段: | 字段 | 类型 | 说明 | | --- | --- | --- | | `code` | string | 类别编码 | | `name` | string | 类别名称 | | `categoryType` | string | 类型,根节点常为 `null` | | `children` | array | 子节点列表,结构同父节点;无子节点时可省略或 `[]` | **示例(节选)** ```json { "code": 200, "msg": "操作成功", "data": [ { "code": "001", "name": "养殖标准", "moduleId": "01", "children": [ { "code": "001001", "name": "繁育作业", "categoryType": "1", "moduleId": "01" }, { "code": "001002", "name": "饲养工作", "categoryType": "1" } ] }, { "code": "002", "name": "科技项目指南", "children": [ { "code": "002001", "name": "高新技术" }, { "code": "002002", "name": "农业科技" } ] } ] } ``` ### 3.3 使用场景 - 移动端 / 管理端 **对外展示** 的分类树(养殖资讯 Tab、畜牧资源、农技课堂等),应使用本接口。 - 按业务模块拉树时传 `moduleId=01`(养殖资讯仅含 `001`~`003` 及其可见子节点)。 - 仅需某一 `categoryType` 下的子树时,可叠加 `categoryType`。 - 管理端下拉、后台校验等需包含不可见编码时,请用 **§4 `/children`**,不要用 `/tree`。 --- ## 4. 查询直接下级类别 返回 **`del_flag=0` 的全部直接下级**,**不按 `visible` 过滤**(例如 `parentCode=001&categoryType=5` 可返回 `001013`)。 ### 4.1 请求 | 项 | 值 | | --- | --- | | **Method** | `GET` | | **URI** | `/category/informationCategory/children` | **Query 参数** | 参数 | 类型 | 必填 | 说明 | | --- | --- | --- | --- | | `parentCode` | string | **是** | 上级编码,如 `001`、`002`、`003` | | `categoryType` | string | 否 | 传入时增加 `category_type` 精确匹配 | 示例: ```http GET /category/informationCategory/children?parentCode=001&categoryType=1 GET /category/informationCategory/children?parentCode=002 GET /category/informationCategory/children?parentCode=003 ``` ### 4.2 响应 `data` 类型:`InformationCategoryItemVo[]`,**仅直接下级**(不含孙子节点)。 | 字段 | 类型 | 说明 | | --- | --- | --- | | `code` | string | 类别编码 | | `name` | string | 类别名称 | **示例** ```json { "code": 200, "msg": "操作成功", "data": [ { "code": "001001", "name": "繁育作业" }, { "code": "001002", "name": "饲养工作" }, { "code": "001003", "name": "免疫程序" }, { "code": "001004", "name": "环境调控" } ] } ``` ### 4.3 各业务模块推荐参数 | 模块 | `parentCode` | `categoryType` | 叶子编码示例 | | --- | --- | --- | --- | | 养殖标准 | `001` | `1` | `001001`~`001004` | | 饲喂标准 | `001` | `2` | `001005`、`001006` | | 设备实施作业标准 | `001` | `3` | `001007`~`001010` | | 生长与出栏标准 | `001` | `4` | `001011`、`001012` | | 疫病诊疗标准 | `001` | `5` | `001013`(种子 `visible=0`,`/tree` 不展示,`/children` 仍返回) | | 科技项目指南 | `002` | 省略 | `002001`~`002004` | | 产业政策(资讯展示) | `003` | 省略 | `003001`~`003004` | 后端保存校验(`*TypeValidator`)以本接口(或等价 Service)返回的 `code` 集合为准;非法编码返回「标准/项目类型无效,请选择资讯类别中的类型」类提示。 --- ## 5. 前端调用 文件:`ruoyi-ui/src/api/category/informationCategory.js` ```javascript import { listInformationCategoryTree, listInformationCategoryChildren } from '@/api/category/informationCategory' // 树(仅 visible=1;养殖资讯模块示例) listInformationCategoryTree({ moduleId: '01', categoryType: '1' }).then((res) => { const tree = res.data || [] }) // 下拉选项(常见) listInformationCategoryChildren('001', '1').then((res) => { const options = (res.data || []).map((item) => ({ value: item.code, label: item.name })) }) ``` **注意**:勿再使用 `item['编号']`、`item['名称']`。 --- ## 6. 相关接口(非本模块) | 接口 | 说明 | | --- | --- | | `GET /app/farmingNews/list?type={code}` | 按资讯类别编码分页查询 `v_farming_news`(`pageNum`/`pageSize`,默认 1/10,上限 50);响应 `rows`、`total`,字段见 [养殖资讯接口说明](../养殖资讯/养殖资讯接口说明.md) | | `GET /app/livestockResource/list?type={code}` | 按资源类型编码分页查询 `v_livestock_resource`;返回含 `id`、`sourceType` | | `GET /app/livestockResource/{id}?type=1\|2` | 详情:按源表主键与来源(1 医疗 / 2 科技)返回全字段;见 [畜牧资源接口说明](../畜牧资源/畜牧资源接口说明.md) | | `GET /app/agriculturalCourse/list?type={code}` | 按类型编码分页查询 `v_agricultural_course`(`005001`–`005004` 或 `006001`–`006004`);见 [农技课堂接口说明](../农技课堂/农技课堂接口说明.md) | | 各标准/项目 CRUD | 表字段 `standard_type` / `project_type` 存叶子 `code`,与本文 `children` 返回值一致 | --- ## 7. 修订记录 | 日期 | 说明 | | --- | --- | | 2026-05-20 | 初版:`/tree`、`/children` 接口说明;JSON 字段统一为 `code`、`name` | | 2026-05-20 | 补充种子层级、业务模块参数对照及前端调用示例 | | 2026-05-20 | 关联养殖资讯列表文档(视图 `cover_file_url` / `content_file_url`) | | 2026-05-20 | 养殖资讯列表接口补充分页说明 | | 2026-05-20 | 表增 `module_id`、`visible`;`/tree` 仅 `visible=1` 且支持 `moduleId`;`/children` 不按 visible 过滤 | | 2026-05-20 | 关联畜牧资源列表文档(`v_livestock_resource`、`/app/livestockResource/list`) |