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

import java.util.List;

import com.bonus.canteen.core.order.domain.OrderInfo;
import com.bonus.canteen.core.order.service.IOrderInfoService;
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.BusinessType;
import com.bonus.common.log.enums.OperaType;
import com.bonus.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * 订单Controller
 * 
 * @author ruoyi
 * @date 2025-04-14
 */
@Controller
@RequestMapping("/system/info")
public class OrderInfoController extends BaseController
{
    @Autowired
    private IOrderInfoService orderInfoService;

    /**
     * 查询订单列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(OrderInfo orderInfo)
    {
        startPage();
        List<OrderInfo> list = orderInfoService.selectOrderInfoList(orderInfo);
        return getDataTable(list);
    }

    /**
     * 导出订单列表
     */
    @SysLog(title = "订单", module = "订单", businessType = OperaType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public void export(OrderInfo orderInfo, HttpServletResponse response)
    {
        List<OrderInfo> list = orderInfoService.selectOrderInfoList(orderInfo);
        ExcelUtil<OrderInfo> util = new ExcelUtil<OrderInfo>(OrderInfo.class);
        util.exportExcel(response, list, "订单数据");
    }

    /**
     * 新增保存订单
     */
    @SysLog(title = "订单",  module = "订单", businessType = OperaType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(OrderInfo orderInfo)
    {
        return toAjax(orderInfoService.insertOrderInfo(orderInfo));
    }

    /**
     * 修改订单
     */
    @GetMapping("/edit/{orderId}")
    public OrderInfo edit(@PathVariable("orderId") Long orderId, ModelMap mmap)
    {
        OrderInfo orderInfo = orderInfoService.selectOrderInfoByOrderId(orderId);
        mmap.put("orderInfo", orderInfo);
        return orderInfo;
    }

    /**
     * 修改保存订单
     */
    @SysLog(title = "订单",  module = "订单", businessType = OperaType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(OrderInfo orderInfo)
    {
        return toAjax(orderInfoService.updateOrderInfo(orderInfo));
    }

    /**
     * 删除订单
     */
    @SysLog(title = "订单",  module = "订单", businessType = OperaType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(@RequestBody List<Long> ids)
    {
        return toAjax(orderInfoService.deleteOrderInfoByOrderIds(ids));
    }
}
