package com.ruoyi.frequency.mallorder.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.mallorder.entity.MallOrder;
import com.ruoyi.frequency.mallorder.model.result.MallOrderCount;
import com.ruoyi.frequency.mallorder.service.MallOrderService;
import com.ruoyi.frequency.store.entity.Store;
import com.ruoyi.frequency.store.model.result.StoreCount;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 订单主Controller
 *
 * @author liwenlong
 * @date 2024-01-25
 */
@RestController
@RequestMapping("/frequency/mallorder")
public class MallOrderController extends BaseController
{
    @Autowired
    private MallOrderService mallOrderService;

    /**
     * 查询订单主列表
     */
    //@PreAuthorize("@ss.hasPermi('frequency:mallorder:list')")
    @PostMapping("/list")
    public TableDataInfo<MallOrder> list(@RequestBody MallOrder mallOrder)
    {
        startPage();
        List<MallOrder> list = mallOrderService.selectMallOrderList(mallOrder);
        return getDataTable(list);
    }

    /**
     * 统计
     */
    @PostMapping("/statistics")
    public AjaxResult statistics(@RequestBody MallOrder mallOrder)
    {
        MallOrderCount count = mallOrderService.statistics(mallOrder);
        return AjaxResult.success(count);
    }



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

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

    /**
     * 新增订单主
     */
    //@PreAuthorize("@ss.hasPermi('frequency:mallorder:add')")
    @Log(title = "订单主", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MallOrder mallOrder)
    {
        return toAjax(mallOrderService.insertMallOrder(mallOrder));
    }

    /**
     * 修改订单主
     */
    //@PreAuthorize("@ss.hasPermi('frequency:mallorder:edit')")
    @Log(title = "订单主", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MallOrder mallOrder)
    {
        return toAjax(mallOrderService.updateMallOrder(mallOrder));
    }

    /**
     * 删除订单主
     */
    //@PreAuthorize("@ss.hasPermi('frequency:mallorder:remove')")
    @Log(title = "订单主", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}/{delFlag}")
    public AjaxResult remove(@PathVariable("ids") Long[] ids,@PathVariable("delFlag") Integer delFlag)
    {
        return toAjax(mallOrderService.deleteMallOrderByIds(ids,delFlag));
    }

    /**
     * 发送货
     *
     * @author 李文龙
     * @date 2022/01/13 14:19
     */
    @PostMapping("/send")
    @Log(title = "订单主", businessType = BusinessType.UPDATE)
    public AjaxResult send(@RequestBody MallOrder mallOrder) {
        return mallOrderService.send(mallOrder);
    }
}
