package com.ruoyi.frequency.order.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.frequency.order.entity.Order;
import com.ruoyi.frequency.order.model.result.OrderCount;
import com.ruoyi.frequency.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 订单主Controller
 *
 * @author zj
 * @date 2023-10-13
 */
@RestController
@RequestMapping("/frequency/order")
public class OrderController extends BaseController
{
    @Autowired
    private OrderService orderService;

    /**
     * 查询订单主列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:order:list')")
    @PostMapping("/list")
    public TableDataInfo<Order> list(@RequestBody Order order)
    {
        startPage();
        List<Order> list = orderService.selectOrderList(order);
        return getDataTable(list);
    }

    /**
     * 统计
     */
    @PostMapping("/statistics")
    public AjaxResult statistics(@RequestBody Order order)
    {
        OrderCount count = orderService.statistics(order);
        return AjaxResult.success(count);
    }

    /**
     * 导出订单主列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:order:export')")
    @Log(title = "订单主", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Order order)
    {
        List<Order> list = orderService.selectOrderList(order);
        ExcelUtil<Order> util = new ExcelUtil<Order>(Order.class);
        return util.exportExcel(list, "订单主数据");
    }

    /**
     * 获取订单主详细信息
     */
    @PreAuthorize("@ss.hasPermi('frequency:order:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult<Order> getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(orderService.selectOrderById(id));
    }

}
