设备端复制菜谱接口
接口地址:POST /api/device/recipe/copy。用于设备端把指定天或指定周的指定餐次菜谱复制到后面的日期或周。
请求参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
equipment_code | string | 是 | 设备编号,兼容 code。 |
restaurant_id | int | 是 | 档口 ID。 |
source_type | string | 否 | day 指定天,week 指定周,默认 day。 |
source_date | string | 天复制必填 | 源日期,兼容 by_menu_date。 |
target_date | string | 天复制必填 | 目标日期,兼容 menu_date、date。 |
source_start_date | string | 周复制必填 | 源周开始日期。 |
target_start_date | string | 周复制必填 | 目标周开始日期。 |
meal_times | int/string/array | 否 | 1 早餐,2 午餐,3 晚餐,4 夜宵,0 或空表示全天。 |
overwrite | int | 否 | 源有菜谱且目标已有菜谱时是否覆盖,默认 1。 |
strict | int | 否 | 源菜谱存在停用或删除菜品时是否失败,默认 1。 |
天复制示例
{
"equipment_code": "WEIGH-001",
"restaurant_id": 12,
"source_type": "day",
"source_date": "2026-06-25",
"target_date": "2026-06-26",
"meal_times": 2,
"overwrite": 1,
"strict": 1
}
周复制示例
{
"equipment_code": "WEIGH-001",
"restaurant_id": 12,
"source_type": "week",
"source_start_date": "2026-06-22",
"target_start_date": "2026-06-29",
"meal_times": 0,
"overwrite": 1,
"strict": 1
}
复制规则
| 源单元 | 目标单元 | 处理 |
|---|---|---|
| 有菜谱 | 无菜谱 | 插入源菜谱。 |
| 有菜谱 | 有菜谱 | overwrite=1 时先清空再插入;overwrite=0 时追加去重。 |
| 无菜谱 | 无菜谱 | 不处理。 |
| 无菜谱 | 有菜谱 | 清空目标单元。 |
周复制会把源周 7 天分别对应到目标周 7 天;全天会展开为早餐、午餐、晚餐、夜宵四个餐次。
成功响应
{
"code": 0,
"message": "复制成功",
"data": {
"equipment_code": "WEIGH-001",
"restaurant_id": 12,
"source_type": "week",
"meal_times": [1, 2, 3, 4],
"overwrite": 1,
"strict": 1,
"copied_count": 36,
"deleted_count": 20,
"skipped_count": 0,
"cleared_empty_source_count": 6,
"empty_source_slots": [
{"source_date": "2026-06-23", "target_date": "2026-06-30", "meal_times": 3}
],
"invalid_source_slots": []
}
}
失败响应
{
"code": 1,
"message": "设备编号不能为空",
"data": []
}
数据影响
接口写入 ydy_recipes,复制时生成新 uuid,目标日期使用目标单元日期,餐次保持对应餐次,type 和 limit_num 跟随源记录,create_by 写入 DeviceApi。
接口同步维护 ydy_dishes.menu_quantity,删除目标旧菜谱时递减,插入目标新菜谱时递增,并把被复制菜品标记为食堂常用菜 attribute=1。