package com.ruoyi.mall.controller;

import java.util.List;

import com.ruoyi.mall.domain.vo.MallAppOrderGoodsExportVO;
import com.ruoyi.mall.domain.vo.MallOrderGoodsExportVO;
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.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mall.domain.MallAppOrderOrder;
import com.ruoyi.mall.service.IMallAppOrderOrderService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

import javax.annotation.Resource;

/**
 * app-线下订单Controller
 *
 * @author ruoyi
 * @date 2024-06-29
 */
@RestController
@RequestMapping("/mall/mallAppOrderOrder")
public class MallAppOrderOrderController extends BaseController
{
    @Resource
    private IMallAppOrderOrderService mallAppOrderOrderService;

    /**
     * 查询app-线下订单列表
     */
    @PreAuthorize("@ss.hasPermi('mall:mallAppOrderOrder:list')")
    @GetMapping("/list")
    public TableDataInfo list(MallAppOrderOrder mallAppOrderOrder)
    {
        startPage();
        mallAppOrderOrder.setDelFlag("0");
        List<MallAppOrderOrder> list = mallAppOrderOrderService.selectMallAppOrderOrderList(mallAppOrderOrder);
        return getDataTable(list);
    }

    /**
     * 导出app-线下订单列表
     */
    @PreAuthorize("@ss.hasPermi('mall:mallAppOrderOrder:export')")
    @Log(title = "导出线下订单", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(MallAppOrderOrder mallAppOrderOrder)
    {
        // List<MallAppOrderOrder> list = mallAppOrderOrderService.selectMallAppOrderOrderList(mallAppOrderOrder);
        // ExcelUtil<MallAppOrderOrder> util = new ExcelUtil<MallAppOrderOrder>(MallAppOrderOrder.class);
        // return util.exportExcel(list, "app-线下订单数据");
        List<MallAppOrderGoodsExportVO> list = mallAppOrderOrderService.selectExportAppOrderList(mallAppOrderOrder);
        ExcelUtil<MallAppOrderGoodsExportVO> util = new ExcelUtil<MallAppOrderGoodsExportVO>(MallAppOrderGoodsExportVO.class);
        return util.exportExcel(list, "app-线下订单数据");
    }

    /**
     * 获取app-线下订单详细信息
     */
    @PreAuthorize("@ss.hasPermi('mall:mallAppOrderOrder:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(mallAppOrderOrderService.selectMallAppOrderOrderById(id));
    }

    /**
     * 新增app-线下订单
     */
    @PreAuthorize("@ss.hasPermi('mall:mallAppOrderOrder:add')")
    @Log(title = "app-线下订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MallAppOrderOrder mallAppOrderOrder)
    {
        return toAjax(mallAppOrderOrderService.insertMallAppOrderOrder(mallAppOrderOrder));
    }

    /**
     * 修改app-线下订单
     */
    @PreAuthorize("@ss.hasPermi('mall:mallAppOrderOrder:edit')")
    @Log(title = "app-线下订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MallAppOrderOrder mallAppOrderOrder)
    {
        return toAjax(mallAppOrderOrderService.updateMallAppOrderOrder(mallAppOrderOrder));
    }

    /**
     * 删除app-线下订单
     */
    @PreAuthorize("@ss.hasPermi('mall:mallAppOrderOrder:remove')")
    @Log(title = "app-线下订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mallAppOrderOrderService.deleteMallAppOrderOrderByIds(ids));
    }

    /**
     * 导出订单列表
     */
    @PreAuthorize("@ss.hasPermi('mall:mallAppOrderOrder:export')")
    @Log(title = "导出线下订单", businessType = BusinessType.EXPORT)
    @PostMapping("/exportOrder")
    public AjaxResult exportOrder(@RequestBody Long[] orderIds)
    {
        List<MallAppOrderGoodsExportVO> list = mallAppOrderOrderService.selectExportAppOrderAppOrderOrderList(orderIds);
        ExcelUtil<MallAppOrderGoodsExportVO> util = new ExcelUtil<MallAppOrderGoodsExportVO>(MallAppOrderGoodsExportVO.class);
        return util.exportExcel(list, "app-线下订单数据");
    }
}
