package com.waimai.web.admin.controller;

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

import com.waimai.web.admin.service.IOrderFoodsService;
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.waimai.common.annotation.Log;
import com.waimai.common.core.controller.BaseController;
import com.waimai.common.core.domain.AjaxResult;
import com.waimai.common.enums.BusinessType;
import com.waimai.web.admin.domain.OrderFoods;
import com.waimai.common.utils.poi.ExcelUtil;
import com.waimai.common.core.page.TableDataInfo;

/**
 * 订单商品Controller
 * 
 * @author callmeyan
 * @date 2023-03-24
 */
@RestController
@RequestMapping("/admin/orderFoods")
public class OrderFoodsController extends BaseController
{
    @Autowired
    private IOrderFoodsService orderFoodsService;

    /**
     * 查询订单商品列表
     */
    @PreAuthorize("@ss.hasPermi('admin:orderFoods:list')")
    @GetMapping("/list")
    public TableDataInfo list(OrderFoods orderFoods)
    {
        startPage();
        List<OrderFoods> list = orderFoodsService.selectOrderFoodsList(orderFoods);
        return getDataTable(list);
    }

    /**
     * 导出订单商品列表
     */
    @PreAuthorize("@ss.hasPermi('admin:orderFoods:export')")
    @Log(title = "订单商品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OrderFoods orderFoods)
    {
        List<OrderFoods> list = orderFoodsService.selectOrderFoodsList(orderFoods);
        ExcelUtil<OrderFoods> util = new ExcelUtil<OrderFoods>(OrderFoods.class);
        util.exportExcel(response, list, "订单商品数据");
    }

    /**
     * 获取订单商品详细信息
     */
    @PreAuthorize("@ss.hasPermi('admin:orderFoods:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(orderFoodsService.selectOrderFoodsById(id));
    }

    /**
     * 新增订单商品
     */
    @PreAuthorize("@ss.hasPermi('admin:orderFoods:add')")
    @Log(title = "订单商品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OrderFoods orderFoods)
    {
        return toAjax(orderFoodsService.insertOrderFoods(orderFoods));
    }

    /**
     * 修改订单商品
     */
    @PreAuthorize("@ss.hasPermi('admin:orderFoods:edit')")
    @Log(title = "订单商品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OrderFoods orderFoods)
    {
        return toAjax(orderFoodsService.updateOrderFoods(orderFoods));
    }

    /**
     * 删除订单商品
     */
    @PreAuthorize("@ss.hasPermi('admin:orderFoods:remove')")
    @Log(title = "订单商品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(orderFoodsService.deleteOrderFoodsByIds(ids));
    }
}
