西藏巴青项目

资讯类别接口说明.md 9.6KB

资讯类别 — 接口说明

数据表: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 字段名统一为英文 codename(不再使用 编号名称)。


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 分组,叶子 001001001013
002 科技项目指南 叶子 002001002004,子项 category_type 多为 NULL
003 产业政策 叶子 003001003004,子项 category_type 多为 NULL

1.2 与业务模块、视图的对应

叶子 code 示例 业务用途
001001001004 养殖标准(繁育/饲养等,parentCode=001categoryType=1
001005001006 饲喂标准(categoryType=2
001007001010 设备实施作业标准(categoryType=3
001011001012 生长与出栏标准(categoryType=4
001013 疾病决策(categoryType=5visible=0,不出现在 /tree
002001002004 科技项目指南 project_type
003001003004 产业政策宣传/补贴/共富等固定类型;亦用于 v_farming_news 中政策类资讯

移动端「养殖资讯」列表按 type 筛选时,type 取值与上述叶子 code 一致(见 sql/biz_v_farming_news.sql)。


2. 通用约定

说明
Base Path /category/informationCategory(与项目 context-path 拼接)
鉴权 与若依登录态一致;须携带有效 Token(与业务后台其它 GET 接口相同)
响应封装 RuoYi AjaxResultcode(HTTP 业务码,如 200)、msgdata
排序 库表查询按 category_code 升序;树内各级子节点同样按 code 升序
错误 parentCode 为空时,/children 返回 msg:「上级编码不能为空」

3. 查询类别树

仅返回 del_flag=0visible=1 的类别;不可见节点(如 001013 疾病决策)不会出现在树中。若某节点的父级不可见或未命中筛选条件,该节点会作为根节点出现在 data 中(与建树逻辑一致)。

3.1 请求

Method GET
URI /category/informationCategory/tree

Query 参数(均可选)

参数 类型 必填 说明
categoryType string 仅加载 category_type 等于该值的记录后再组装树
moduleId string 仅加载指定模块:01 养殖资讯、02 畜牧资源、03 农技课堂

示例:

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 子节点列表,结构同父节点;无子节点时可省略或 []

示例(节选)

{
  "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(养殖资讯仅含 001003 及其可见子节点)。
  • 仅需某一 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 上级编码,如 001002003
categoryType string 传入时增加 category_type 精确匹配

示例:

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 类别名称

示例

{
  "code": 200,
  "msg": "操作成功",
  "data": [
    { "code": "001001", "name": "繁育作业" },
    { "code": "001002", "name": "饲养工作" },
    { "code": "001003", "name": "免疫程序" },
    { "code": "001004", "name": "环境调控" }
  ]
}

4.3 各业务模块推荐参数

模块 parentCode categoryType 叶子编码示例
养殖标准 001 1 001001001004
饲喂标准 001 2 001005001006
设备实施作业标准 001 3 001007001010
生长与出栏标准 001 4 001011001012
疫病诊疗标准 001 5 001013(种子 visible=0/tree 不展示,/children 仍返回)
科技项目指南 002 省略 002001002004
产业政策(资讯展示) 003 省略 003001003004

后端保存校验(*TypeValidator)以本接口(或等价 Service)返回的 code 集合为准;非法编码返回「标准/项目类型无效,请选择资讯类别中的类型」类提示。


5. 前端调用

文件:ruoyi-ui/src/api/category/informationCategory.js

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_newspageNum/pageSize,默认 1/10,上限 50);响应 rowstotal,字段见 养殖资讯接口说明
GET /app/livestockResource/list?type={code} 按资源类型编码分页查询 v_livestock_resource;返回含 idsourceType
GET /app/livestockResource/{id}?type=1\|2 详情:按源表主键与来源(1 医疗 / 2 科技)返回全字段;见 畜牧资源接口说明
GET /app/agriculturalCourse/list?type={code} 按类型编码分页查询 v_agricultural_course005001005004006001006004);见 农技课堂接口说明
各标准/项目 CRUD 表字段 standard_type / project_type 存叶子 code,与本文 children 返回值一致

7. 修订记录

日期 说明
2026-05-20 初版:/tree/children 接口说明;JSON 字段统一为 codename
2026-05-20 补充种子层级、业务模块参数对照及前端调用示例
2026-05-20 关联养殖资讯列表文档(视图 cover_file_url / content_file_url
2026-05-20 养殖资讯列表接口补充分页说明
2026-05-20 表增 module_idvisible/treevisible=1 且支持 moduleId/children 不按 visible 过滤
2026-05-20 关联畜牧资源列表文档(v_livestock_resource/app/livestockResource/list