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

import com.bonus.canteen.core.order.domain.OrderDetail;
import com.bonus.canteen.core.order.service.IOrderDetailService;
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.OperaType;
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;
import java.util.List;

/**
 * 订单详情Controller
 * 
 * @author ruoyi
 * @date 2025-04-14
 */
@Controller
@RequestMapping("/system/detail")
public class OrderDetailController extends BaseController
{
    @Autowired
    private IOrderDetailService orderDetailService;

    /**
     * 查询订单详情列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(OrderDetail orderDetail)
    {
        startPage();
        List<OrderDetail> list = orderDetailService.selectOrderDetailList(orderDetail);
        return getDataTable(list);
    }

    /**
     * 导出订单详情列表
     */
    @SysLog(title = "订单详情", module = "订单-订单详情", businessType = OperaType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public void export(OrderDetail orderDetail, HttpServletResponse response)
    {
        List<OrderDetail> list = orderDetailService.selectOrderDetailList(orderDetail);
        ExcelUtil<OrderDetail> util = new ExcelUtil<OrderDetail>(OrderDetail.class);
        util.exportExcel(response, list, "订单详情数据");
    }

    /**
     * 新增保存订单详情
     */
    @SysLog(title = "订单详情", module = "订单-订单详情", businessType = OperaType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(OrderDetail orderDetail)
    {
        return toAjax(orderDetailService.insertOrderDetail(orderDetail));
    }

    /**
     * 修改订单详情
     */
    @GetMapping("/edit/{detailId}")
    public OrderDetail edit(@PathVariable("detailId") Long detailId, ModelMap mmap)
    {
        OrderDetail orderDetail = orderDetailService.selectOrderDetailByDetailId(detailId);
        mmap.put("orderDetail", orderDetail);
        return orderDetail;
    }

    /**
     * 修改保存订单详情
     */
    @SysLog(title = "订单详情", module = "订单-订单详情", businessType = OperaType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(OrderDetail orderDetail)
    {
        return toAjax(orderDetailService.updateOrderDetail(orderDetail));
    }

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