package com.ruoyi.web.controller.food;

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

import org.springframework.security.access.prepost.PreAuthorize;
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.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
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.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.OrderFood;
import com.ruoyi.system.service.IOrderFoodService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 订餐预约Controller
 *
 * @author ruoyi
 * @date 2024-07-23
 */
@RestController
@RequestMapping("/food")
public class OrderFoodController extends BaseController {
    @Autowired
    private IOrderFoodService orderFoodService;

    /**
     * 查询订餐预约列表
     */
    @PreAuthorize("@ss.hasPermi('system:food:list')")
    @GetMapping("/list")
    public TableDataInfo list(OrderFood orderFood) {
        startPage();
        List<OrderFood> list = orderFoodService.selectOrderFoodList(orderFood);
        return getDataTable(list);
    }

    /**
     * 导出订餐预约列表
     */
    @PreAuthorize("@ss.hasPermi('system:food:export')")
    @Log(title = "订餐预约", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OrderFood orderFood) {
        List<OrderFood> list = orderFoodService.selectOrderFoodList(orderFood);
        ExcelUtil<OrderFood> util = new ExcelUtil<OrderFood>(OrderFood.class);
        util.exportExcel(response, list, "订餐预约数据");
    }

    /**
     * 获取订餐预约详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:food:query')")
    @GetMapping(value = "/{orderFoodId}")
    public AjaxResult getInfo(@PathVariable("orderFoodId") Long orderFoodId) {
        return success(orderFoodService.selectOrderFoodByOrderFoodId(orderFoodId));
    }

    /**
     * 新增订餐预约
     */
    @PreAuthorize("@ss.hasPermi('system:food:add')")
    @Log(title = "订餐预约", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OrderFood orderFood) {
        return orderFoodService.insertOrderFood(orderFood);
    }

    /**
     * 修改订餐预约
     */
    @PreAuthorize("@ss.hasPermi('system:food:edit')")
    @Log(title = "订餐预约", businessType = BusinessType.UPDATE)
    @PostMapping("/put")
    public AjaxResult edit(@RequestBody OrderFood orderFood) {
        return orderFoodService.updateOrderFood(orderFood);
    }

    /**
     * 删除订餐预约
     */
    @PreAuthorize("@ss.hasPermi('system:food:remove')")
    @Log(title = "订餐预约", businessType = BusinessType.DELETE)
    @GetMapping("/delete/{orderFoodIds}")
    public AjaxResult remove(@PathVariable Long[] orderFoodIds) {
        return toAjax(orderFoodService.deleteOrderFoodByOrderFoodIds(orderFoodIds));
    }
}
