1
0
forked from erp-dev/erp

fix: business.object_id maybe null, missing parameters when plate-Order cloned

This commit is contained in:
2025-12-17 11:02:07 +08:00
parent 639efe8421
commit 51fad953c3
24 changed files with 13247 additions and 47 deletions

View File

@@ -0,0 +1,107 @@
## api_v2按流程查询 PlateOrder 列表(返回所有节点参数 `process_params`
### 目标
-`process_id` + `created_at` 时间范围查询 `PlateOrder` 列表
- 每条 `PlateOrder` 额外返回 `process_params`**该流程的全部节点**,以及每个节点的 **是否已执行****参数 key/value订单维度**
### 接口信息
- **Method**GET
- **Path**`/api/v2/plate-orders/by-process/`
- **认证**JWT`IsAuthenticated`
- **权限**:仅允许印染/工厂侧用户(`IsPrintingFactory`
### Query 参数
| 参数 | 必填 | 类型 | 默认值 | 说明 |
|---|---:|---|---|---|
| `process_id` | 是 | int | - | `stateflow.Process.id` |
| `date_from` | 是 | string(date) | - | 起始日期 `YYYY-MM-DD`(按 `PlateOrder.created_at` 过滤,闭区间) |
| `date_to` | 是 | string(date) | - | 结束日期 `YYYY-MM-DD`(闭区间,包含当日 23:59:59.999999 |
| `plate_order` | 否 | string | - | 单一查询参数:同时支持主键与设计编号(见“查询规则”) |
| `ordering` | 否 | string | `-created_at` | 排序字段(见“排序规则”) |
| `limit` | 否 | int | `20` | 分页大小LimitOffsetPagination |
| `offset` | 否 | int | `0` | 分页偏移LimitOffsetPagination |
### 查询规则plate_order
-`plate_order` 为**纯数字**
- 匹配 `PlateOrder.id == int(plate_order)` **或**
- 匹配 `PlateOrder.design_code icontains plate_order`
-`plate_order` 为**非纯数字**
- 仅匹配 `PlateOrder.design_code icontains plate_order`
### 排序规则ordering
- 默认:`-created_at`
- 支持字段:`id` / `created_at` / `updated_at` / `design_code`
- `design_code` 排序规则:
-`design_code` 为空时,使用 `id` 的字符串作为兜底值参与排序
- 传入不支持的 `ordering`:返回 **400**
### 返回值200
响应为分页结构。
#### 顶层字段
| 字段 | 类型 | 说明 |
|---|---|---|
| `process` | object | 流程信息(见下) |
| `count` | int | 总数 |
| `next` | string\|null | 下一页链接 |
| `previous` | string\|null | 上一页链接 |
| `results` | array[object] | `PlateOrder` 列表(见下) |
#### `process` 字段
| 字段 | 类型 | 说明 |
|---|---|---|
| `id` | int | `Process.id` |
| `name` | string | `Process.name` |
| `node_count` | int | 节点数量 |
#### `results` 元素字段PlateOrder 列表项)
| 字段 | 类型 | 说明 |
|---|---|---|
| `id` | int | PlateOrder 主键 |
| `design_code` | string\|null | 设计编号;若为空则返回 `id` 的字符串兜底值 |
| `customer` | int | 客户 ID |
| `customer_name` | string | 客户名称 |
| `style_name` | string\|null | 款号名称 |
| `urgency_level` | string | 紧急程度 |
| `is_invalid` | bool | 是否作废 |
| `business_object_id` | int\|null | 关联流程实例 ID |
| `process_params` | array[object] | **流程全部节点**的参数结构(见下,严格 schema |
| `created_at` | string | 创建时间ISO 8601 |
| `updated_at` | string | 更新时间ISO 8601 |
#### `process_params` 元素字段(严格 schema
| 字段 | 类型 | 说明 |
|---|---|---|
| `process_node_id` | int | `ProcessNode.id` |
| `state_id` | int | `State.id` |
| `node_name` | string | 节点名称(`State.name` |
| `order` | int | 节点顺序号 |
| `is_executed` | bool | **是否已执行**:存在未撤销的 `StateFlowRecord` 则为 true仅有撤销记录视为 false |
| `params` | array[object] | 该节点参数 key/value订单维度见下 |
#### `params` 元素字段(订单维度:严格 schema
| 字段 | 类型 | 说明 |
|---|---|---|
| `key` | string | 参数键(来自该节点 `State.parameters` |
| `value` | JSONValue\|null | 订单在该节点的最新已提交参数值;未执行/未提交则为 null |
**JSONValue 定义**
- `string` \| `number` \| `boolean` \| `object` \| `array` \| `null`
**不变性约束(前端可依赖)**
- `process_params` **一定存在**,类型恒为 `array`
- `process_params` **一定包含该流程的全部节点**,按 `order` 升序
- 对每个节点:
- `params` **一定存在**,类型恒为 `array`
- `params`**key 集合与顺序**与该节点 `State.parameters` **完全一致**
- 若该节点没有任何参数:`params=[]`
### 常见错误码
| HTTP 状态码 | 场景 | 返回 `detail` |
|---:|---|---|
| 400 | 缺少/非法参数(如 `process_id` 非数字、`date_from/date_to` 缺失或格式错误、`ordering` 不支持) | 错误原因文本 |
| 401 | 未认证 | DRF 默认 |
| 403 | 无权限(非工厂用户) | `您没有访问印染订单的权限` |
| 404 | `process_id` 不存在 | `process 不存在` |