package com.younike.merchant;

import com.younike.common.annotation.Log;
import com.younike.common.core.controller.BaseController;
import com.younike.common.core.domain.AjaxResult;
import com.younike.common.core.page.TableDataInfo;
import com.younike.common.enums.BusinessType;
import com.younike.common.utils.poi.ExcelUtil;
import com.younike.system.domain.Order;
import com.younike.system.domain.vo.OrdersVO;
import com.younike.system.service.IMerchantOrderService;
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 jubs
 * @date 2022-01-05
 */
@RestController
@RequestMapping("/system/order")
public class MerchantOrderController extends BaseController {
    @Autowired
    private IMerchantOrderService orderService;

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

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

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

    /**
     * 新增订单主
     */
    @PreAuthorize("@ss.hasPermi('system:order:add')")
    @Log(title = "订单主", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OrdersVO order)
    {
        return toAjax(orderService.insertOrder(order));
    }

    /**
     * 修改订单主
     */
    @PreAuthorize("@ss.hasPermi('system:order:edit')")
    @Log(title = "订单主", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OrdersVO order)
    {
        return toAjax(orderService.updateOrder(order));
    }

    /**
     * 删除订单主
     */
    @PreAuthorize("@ss.hasPermi('system:order:remove')")
    @Log(title = "订单主", businessType = BusinessType.DELETE)
    @DeleteMapping("/{orderIds}")
    public AjaxResult remove(@PathVariable Long[] orderIds)
    {
        return toAjax(orderService.deleteOrderByOrderIds(orderIds));
    }
}
