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

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import com.bonus.canteen.core.common.utils.RedisUtil;
import com.bonus.canteen.core.common.utils.TenantContextHolder;
import com.bonus.canteen.core.menu.dto.MenuRecipeAddDTO;
import com.bonus.canteen.core.menu.dto.MenuRecipeParamDTO;
import com.bonus.canteen.core.menu.service.IMenuRecipeService;
import com.bonus.common.core.exception.ServiceException;
import com.bonus.common.houqin.constant.GlobalConstants;
import com.bonus.common.houqin.i18n.I18n;
import com.bonus.common.log.enums.OperaType;
import com.bonus.common.security.annotation.Logical;
import com.bonus.common.security.annotation.RequiresPermissions;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.bonus.common.log.annotation.SysLog;
import com.bonus.canteen.core.menu.domain.MenuRecipe;
import com.bonus.common.core.web.controller.BaseController;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.common.core.utils.poi.ExcelUtil;
import com.bonus.common.core.web.page.TableDataInfo;

/**
 * 菜品计划信息Controller
 * 
 * @author xsheng
 * @date 2025-04-03
 */
@Api(tags = "菜品计划信息接口")
@RestController
@RequestMapping("/menu_recipe")
public class MenuRecipeController extends BaseController {
    @Autowired
    private IMenuRecipeService menuRecipeService;


    @PostMapping({"/getDishesList"})
    @ApiOperation("菜谱列表-获取菜品列表")
    public AjaxResult getDishesList(@RequestBody MenuRecipeParamDTO dto) {
        return this.menuRecipeService.getDishesList(dto);
    }

    @PostMapping({"/add"})
    @ApiOperation("菜谱计划发布v2")
    public Long addMenuRecipeV2(@RequestBody @Valid MenuRecipeAddDTO dto) {
        Long recipeId = null;
        String var10000 = "yst:merchant-id:menu:recipe:edit:".replace("merchant-id", String.valueOf(GlobalConstants.TENANT_ID));
        String lockKey = var10000 + dto.getRecipeId();
        boolean succ = RedisUtil.tryLock(lockKey, 0, 300);
        if (!succ) {
            throw new ServiceException("获取锁失败，停止新增！");
        } else {
            try {
                recipeId = this.menuRecipeService.add(dto);
            } finally {
                RedisUtil.safeUnLock(lockKey);
            }

            return recipeId;
        }
    }

}
