1
0
forked from erp-dev/erp
Files
erpnew/docs/print_count_delta.md

55 lines
1.6 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 打印次数增量 API
该接口用于为支持 `print_count` 字段的业务对象递增打印次数。目前支持:
- `printing_order``printing.models.PrintingOrder`
- `plate_order``printing.models.PlateOrder`
未来可以在后端枚举中扩展更多对象类型(例如采购单等)。
## Endpoint
- **Method**: `POST`
- **Path**: `/api/v1/print-count/delta/`
- **Auth**: 需要登录(仅校验是否认证)
- **Content-Type**: `application/json`
## 请求参数
| 字段 | 类型 | 必填 | 说明 |
|------|------|------|------|
| `object_type` | string | 是 | 对象类型,`printing_order``plate_order` |
| `object_id` | integer | 是 | 目标对象的 ID |
| `delta` | integer/string | 否 | 增量值,默认 1若传入小于 1 或无法转换为整数,则自动回退为 1 |
## 响应
```json
{
"object_type": "printing_order",
"object_id": 12,
"delta": 3,
"print_count": 5
}
```
字段说明:
- `delta`: 实际生效的增量(若请求非法会改为 1
- `print_count`: 更新后的打印次数
## 错误响应
| HTTP 状态码 | 场景 | 响应 |
|-------------|------|------|
| 400 | `object_type` 不受支持 | `{"detail": "不支持的对象类型"}` |
| 404 | `object_id``object_type` 匹配的对象不存在 | `{"detail": "指定对象不存在"}` |
| 401 | 未认证访问 | DRF 默认未认证响应 |
## 扩展说明
- `delta` 仅做加法,不提供回退逻辑。
- 所有增量操作在数据库事务中执行,可避免并发更新冲突。
- 新的对象类型只需在后端的 `PrintCountObjectType` 枚举和映射表中补充即可。