package com.ruoyi.hezhi.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.hezhi.domain.TbMemberOrder;
import com.ruoyi.hezhi.service.ITbMemberOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 会员订单信息Controller
 *
 * @author ruoyi
 * @date 2024-11-18
 */
@RestController
@RequestMapping("/hezhi/memberOrder")
public class TbMemberOrderController extends BaseController
{
    @Autowired
    private ITbMemberOrderService tbMemberOrderService;

    /**
     * 查询会员订单信息列表
     */
    @PreAuthorize("@ss.hasPermi('hezhi:memberOrder:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbMemberOrder tbMemberOrder)
    {
        startPage();
        List<TbMemberOrder> list = tbMemberOrderService.selectTbMemberOrderList(tbMemberOrder);
        return getDataTable(list);
    }

    /**
     * 导出会员订单信息列表
     */
    @PreAuthorize("@ss.hasPermi('hezhi:memberOrder:export')")
    @Log(title = "会员订单信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbMemberOrder tbMemberOrder)
    {
        List<TbMemberOrder> list = tbMemberOrderService.selectTbMemberOrderList(tbMemberOrder);
        ExcelUtil<TbMemberOrder> util = new ExcelUtil<TbMemberOrder>(TbMemberOrder.class);
        util.exportExcel(response, list, "会员订单信息数据");
    }

    /**
     * 获取会员订单信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('hezhi:memberOrder:query')")
    @GetMapping(value = "/{orderId}")
    public AjaxResult getInfo(@PathVariable("orderId") Long orderId)
    {
        return success(tbMemberOrderService.selectTbMemberOrderByOrderId(orderId));
    }

    /**
     * 新增会员订单信息
     */
    @PreAuthorize("@ss.hasPermi('hezhi:memberOrder:add')")
    @Log(title = "会员订单信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbMemberOrder tbMemberOrder)
    {
        return toAjax(tbMemberOrderService.insertTbMemberOrder(tbMemberOrder));
    }

    /**
     * 修改会员订单信息
     */
    @PreAuthorize("@ss.hasPermi('hezhi:memberOrder:edit')")
    @Log(title = "会员订单信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbMemberOrder tbMemberOrder)
    {
        return toAjax(tbMemberOrderService.updateTbMemberOrder(tbMemberOrder));
    }

    /**
     * 删除会员订单信息
     */
    @PreAuthorize("@ss.hasPermi('hezhi:memberOrder:remove')")
    @Log(title = "会员订单信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orderIds}")
    public AjaxResult remove(@PathVariable Long[] orderIds)
    {
        return toAjax(tbMemberOrderService.deleteTbMemberOrderByOrderIds(orderIds));
    }
}
