package com.ruoyi.frequency.ordermessage.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.ordermessage.entity.OrderMessage;
import com.ruoyi.frequency.ordermessage.entity.OrderMessageUtil;
import com.ruoyi.frequency.ordermessage.service.OrderMessageService;
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/ordermessage")
public class OrderMessageController extends BaseController {
    @Autowired
    private OrderMessageService orderMessageService;

    /**
     * 查询订单消息列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:ordermessage:list')")
    @GetMapping("/list")
    public TableDataInfo<OrderMessageUtil> list(OrderMessage orderMessage) {
        startPage();
        List<OrderMessage> list = orderMessageService.selectOrderMessageList(orderMessage);
        return getDataTable(list);
    }

    /**
     * 导出订单消息列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:ordermessage:export')")
    @Log(title = "订单消息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(OrderMessage orderMessage) {
        List<OrderMessage> list = orderMessageService.selectOrderMessageList(orderMessage);
        ExcelUtil<OrderMessage> util = new ExcelUtil<OrderMessage>(OrderMessage.class);
        return util.exportExcel(list, "订单消息数据");
    }

    /**
     * 获取订单消息详细信息
     */
    @PreAuthorize("@ss.hasPermi('frequency:ordermessage:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult<OrderMessageUtil> getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(orderMessageService.selectOrderMessageById(id));
    }

    /**
     * 新增订单消息
     */
    @PreAuthorize("@ss.hasPermi('frequency:ordermessage:add')")
    @Log(title = "订单消息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OrderMessage orderMessage) {
        return toAjax(orderMessageService.insertOrderMessage(orderMessage));
    }

    /**
     * 修改订单消息
     */
    @PreAuthorize("@ss.hasPermi('frequency:ordermessage:edit')")
    @Log(title = "订单消息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OrderMessage orderMessage) {
        return toAjax(orderMessageService.updateOrderMessage(orderMessage));
    }

    /**
     * 删除订单消息
     */
    @PreAuthorize("@ss.hasPermi('frequency:ordermessage:remove')")
    @Log(title = "订单消息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(orderMessageService.deleteOrderMessageByIds(ids));
    }
}
