package com.ruoyi.frequency.orderchangerecord.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.orderchangerecord.entity.OrderChangeRecord;
import com.ruoyi.frequency.orderchangerecord.service.OrderChangeRecordService;
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/orderchangerecord")
public class OrderChangeRecordController extends BaseController
{
    @Autowired
    private OrderChangeRecordService orderChangeRecordService;

    /**
     * 查询订单改价记录列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:orderchangerecord:list')")
    @PostMapping("/list")
    public TableDataInfo<OrderChangeRecord> list(@RequestBody OrderChangeRecord orderChangeRecord)
    {
        startPage();
        List<OrderChangeRecord> list = orderChangeRecordService.selectOrderChangeRecordList(orderChangeRecord);
        return getDataTable(list);
    }

    /**
     * 导出订单改价记录列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:orderchangerecord:export')")
    @Log(title = "订单改价记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(OrderChangeRecord orderChangeRecord)
    {
        List<OrderChangeRecord> list = orderChangeRecordService.selectOrderChangeRecordList(orderChangeRecord);
        ExcelUtil<OrderChangeRecord> util = new ExcelUtil<OrderChangeRecord>(OrderChangeRecord.class);
        return util.exportExcel(list, "订单改价记录数据");
    }

    /**
     * 获取订单改价记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('frequency:orderchangerecord:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult<OrderChangeRecord> getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(orderChangeRecordService.selectOrderChangeRecordById(id));
    }

    /**
     * 新增订单改价记录
     */
    @PreAuthorize("@ss.hasPermi('frequency:orderchangerecord:add')")
    @Log(title = "订单改价记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OrderChangeRecord orderChangeRecord)
    {
        return toAjax(orderChangeRecordService.insertOrderChangeRecord(orderChangeRecord));
    }

    /**
     * 修改订单改价记录
     */
    @PreAuthorize("@ss.hasPermi('frequency:orderchangerecord:edit')")
    @Log(title = "订单改价记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OrderChangeRecord orderChangeRecord)
    {
        return toAjax(orderChangeRecordService.updateOrderChangeRecord(orderChangeRecord));
    }

    /**
     * 删除订单改价记录
     */
    @PreAuthorize("@ss.hasPermi('frequency:orderchangerecord:remove')")
    @Log(title = "订单改价记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(orderChangeRecordService.deleteOrderChangeRecordByIds(ids));
    }
}
