设备端复制菜谱接口

接口地址:POST /api/device/recipe/copy。用于设备端把指定天或指定周的指定餐次菜谱复制到后面的日期或周。

请求参数

参数类型必填说明
equipment_codestring设备编号,兼容 code
restaurant_idint档口 ID。
source_typestringday 指定天,week 指定周,默认 day
source_datestring天复制必填源日期,兼容 by_menu_date
target_datestring天复制必填目标日期,兼容 menu_datedate
source_start_datestring周复制必填源周开始日期。
target_start_datestring周复制必填目标周开始日期。
meal_timesint/string/array1 早餐,2 午餐,3 晚餐,4 夜宵,0 或空表示全天。
overwriteint源有菜谱且目标已有菜谱时是否覆盖,默认 1
strictint源菜谱存在停用或删除菜品时是否失败,默认 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,目标日期使用目标单元日期,餐次保持对应餐次,typelimit_num 跟随源记录,create_by 写入 DeviceApi

接口同步维护 ydy_dishes.menu_quantity,删除目标旧菜谱时递减,插入目标新菜谱时递增,并把被复制菜品标记为食堂常用菜 attribute=1