package com.bonus.canteen.core.cook.controller;

import cn.hutool.core.util.ObjectUtil;
import com.bonus.canteen.core.basic.domain.AllocMobileCanteenQueryDTO;
import com.bonus.canteen.core.cook.domain.CookRecipe;
import com.bonus.canteen.core.cook.dto.*;
import com.bonus.canteen.core.cook.service.ICookDishesService;
import com.bonus.canteen.core.cook.service.ICookRecipeH5Service;
import com.bonus.canteen.core.cook.service.ICookRecipeService;
import com.bonus.canteen.core.cook.vo.AllocRecipeStallVO;
import com.bonus.canteen.core.cook.vo.AppletDishesDetailVO;
import com.bonus.canteen.core.cook.vo.CookRecipeDetailVO;
import com.bonus.common.core.utils.poi.ExcelUtil;
import com.bonus.common.core.web.controller.BaseController;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.common.core.web.page.TableDataInfo;
import com.bonus.common.log.annotation.SysLog;
import com.bonus.common.log.enums.OperaType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.time.LocalDate;
import java.util.List;

import static com.bonus.common.core.web.domain.AjaxResult.success;

/**
 * 菜品计划信息Controller
 * 
 * @author xsheng
 * @date 2025-05-25
 */
@Api(tags = "菜谱h5接口")
@RestController
@RequestMapping("/cook_recipe_h5")
@Slf4j
public class CookRecipeH5Controller extends BaseController {
    @Autowired
    private ICookRecipeH5Service cookRecipeH5Service;
    @Autowired
    private ICookDishesService cookDishesService;

    @ApiOperation("获取预定餐食堂列表")
    @GetMapping({"/reserve/canteen/shopstall/list"})
    public TableDataInfo getReserveMealCanteenList() {
        try {
            return getDataTable(this.cookRecipeH5Service.getReserveMealCanteenList());
        } catch (Exception e) {
            log.error(e.toString(), e);
            return getDataTable(null);
        }
    }

    @ApiOperation("移动端-查询预订日期列表")
    @PostMapping({"/reserve-date/list"})
    public AjaxResult listReserveDate(@RequestBody AllocMobileCanteenQueryDTO bean) {
        return AjaxResult.success(this.cookRecipeH5Service.listReserveDate(bean));
    }

    @ApiOperation("获取预定餐菜谱详情")
    @PostMapping({"/reserve/recipe/detail"})
    public TableDataInfo getReserveRecipeDetailList(@RequestBody AppletReserveRecipeDTO content) {
        try {
            return getDataTable(this.cookRecipeH5Service.getReserveRecipeDetailList(content));
        } catch (Exception e) {
            log.error(e.toString(), e);
            return getDataTable(null);
        }
    }

    @PostMapping({"/list/week/canteen"})
    @ApiOperation("获取一周菜谱食堂列表")
    public AjaxResult getWeekMealList(@RequestBody AppletWeekCanteenDTO appletWeekCanteenDTO) {
        try {
            return AjaxResult.success(this.cookRecipeH5Service.selectWeekCanteenList(appletWeekCanteenDTO));
        } catch (Exception e) {
            return AjaxResult.error("获取一周菜谱食堂列表失败");
        }
    }

    @ApiOperation("获取一周菜谱详情")
    @PostMapping({"/week/recipe/detail"})
    public TableDataInfo getWeekRecipeDetailList(@RequestBody @Valid AppletWeekRecipeDTO content) {
        try {
            return getDataTable(this.cookRecipeH5Service.getWeekRecipeDetailList(content));
        } catch (Exception e) {
            log.error(e.toString(), e);
            return getDataTable(null);
        }
    }

    @PostMapping({"/dishes/detail"})
    @ApiOperation("根据菜品id获取菜品详情")
    public AjaxResult getRecipeDetail(@RequestBody AppletDishesDetailDTO dto) {
        AppletDishesDetailVO dishesDetailVO = this.cookDishesService.getDishesDetailByDishesId(dto);
        return success(dishesDetailVO);
    }
}
