package com.waimai.web.admin.controller;

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.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.Orders;
import com.waimai.web.admin.service.IOrdersService;
import com.waimai.common.utils.poi.ExcelUtil;
import com.waimai.common.core.page.TableDataInfo;

/**
 * 订单记录Controller
 * 
 * @author callmeyan
 * @date 2023-03-24
 */
@RestController
@RequestMapping("/admin/orders")
public class OrdersController extends BaseController
{
    @Autowired
    private IOrdersService ordersService;

    /**
     * 查询订单记录列表
     */
    @PreAuthorize("@ss.hasPermi('admin:orders:list')")
    @GetMapping("/list")
    public TableDataInfo list(Orders orders)
    {
        startPage();
        List<Orders> list = ordersService.selectOrdersList(orders);
        return getDataTable(list);
    }

    /**
     * 导出订单记录列表
     */
    @PreAuthorize("@ss.hasPermi('admin:orders:export')")
    @Log(title = "订单记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Orders orders)
    {
        List<Orders> list = ordersService.selectOrdersList(orders);
        ExcelUtil<Orders> util = new ExcelUtil<Orders>(Orders.class);
        util.exportExcel(response, list, "订单记录数据");
    }

    /**
     * 获取订单记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('admin:orders:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(ordersService.selectOrdersById(id));
    }

    /**
     * 新增订单记录
     */
    @PreAuthorize("@ss.hasPermi('admin:orders:add')")
    @Log(title = "订单记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Orders orders)
    {
        return toAjax(ordersService.insertOrders(orders));
    }

    /**
     * 修改订单记录
     */
    @PreAuthorize("@ss.hasPermi('admin:orders:edit')")
    @Log(title = "订单记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Orders orders)
    {
        return toAjax(ordersService.updateOrders(orders));
    }

    /**
     * 删除订单记录
     */
    @PreAuthorize("@ss.hasPermi('admin:orders:remove')")
    @Log(title = "订单记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(ordersService.deleteOrdersByIds(ids));
    }
}
