package com.ruoyi.web.controller.coffee;

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

import com.ruoyi.system.domain.Goods;
import org.apache.ibatis.annotations.Param;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ShopRecommend;
import com.ruoyi.system.service.IShopRecommendService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 推荐和今日特惠Controller
 * 
 * @author ruoyi
 * @date 2022-04-28
 */
@RestController
@RequestMapping("/system/recommend")
public class ShopRecommendController extends BaseController
{
    @Autowired
    private IShopRecommendService shopRecommendService;



    @GetMapping("/turn")
    public AjaxResult turn(Long shopId,String firstGoodsId,String lastGoodsId,String type)
    {
        return AjaxResult.success(shopRecommendService.turn(shopId,firstGoodsId,lastGoodsId,type));
    }

    /**
     * 查询推荐和今日特惠列表
     */
    @PreAuthorize("@ss.hasPermi('system:recommend:list')")
    @GetMapping("/list")
    public TableDataInfo list(ShopRecommend shopRecommend)
    {
        startPage();
        List<Goods> list = shopRecommendService.selectShopRecommendList(shopRecommend);
        return getDataTable(list);
    }



    /**
     * 获取推荐和今日特惠详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:recommend:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(shopRecommendService.selectShopRecommendById(id));
    }

    /**
     * 新增推荐和今日特惠
     */
    @PreAuthorize("@ss.hasPermi('system:recommend:add')")
    @Log(title = "推荐和今日特惠", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ShopRecommend shopRecommend)
    {
        return toAjax(shopRecommendService.insertShopRecommend(shopRecommend));
    }

    /**
     * 修改推荐和今日特惠
     */
    @PreAuthorize("@ss.hasPermi('system:recommend:edit')")
    @Log(title = "推荐和今日特惠", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ShopRecommend shopRecommend)
    {
        return toAjax(shopRecommendService.updateShopRecommend(shopRecommend));
    }

    /**
     * 删除推荐和今日特惠
     */
    @PreAuthorize("@ss.hasPermi('system:recommend:remove')")
    @Log(title = "推荐和今日特惠", businessType = BusinessType.DELETE)
	@GetMapping("/remove")
    public AjaxResult remove(@RequestParam("goodsId")String goodsId, @RequestParam("shopId")String shopId, @RequestParam("type")String type)
    {
        return toAjax(shopRecommendService.deleteShopRecommend(goodsId,shopId,type));
    }


}
