package com.ghy.web.controller.order;

import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ghy.common.annotation.Log;
import com.ghy.common.enums.BusinessType;
import com.ghy.order.domain.OrderOperationRecord;
import com.ghy.order.service.IOrderOperationRecordService;
import com.ghy.common.core.controller.BaseController;
import com.ghy.common.core.domain.AjaxResult;
import com.ghy.common.utils.poi.ExcelUtil;
import com.ghy.common.core.page.TableDataInfo;

/**
 * 订单操作记录Controller
 *
 * @author clunt
 * @date 2024-02-17
 */
@Api
@Controller
@RequestMapping("/order/operate")
public class OrderOperationRecordController extends BaseController
{
    private String prefix = "order/operate";

    @Autowired
    private IOrderOperationRecordService orderOperationRecordService;

    @RequiresPermissions("order:operate:view")
    @GetMapping()
    public String record()
    {
        return prefix + "/operate";
    }

    /**
     * 查询订单操作记录列表
     */
    @RequiresPermissions("order:operate:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(OrderOperationRecord orderOperationRecord)
    {
        startPage();
        List<OrderOperationRecord> list = orderOperationRecordService.selectOrderOperationRecordList(orderOperationRecord);
        return getDataTable(list);
    }

    /**
     * App查询订单操作记录列表
     */
    @ApiOperation("订单操作记录列表")
    @PostMapping("/app/list")
    @ResponseBody
    public TableDataInfo appList(@RequestBody OrderOperationRecord orderOperationRecord)
    {
        startPage();
        List<OrderOperationRecord> list = orderOperationRecordService.selectOrderOperationRecordList(orderOperationRecord);
        return getDataTable(list);
    }

    /**
     * 新增保存订单操作记录
     */
    @ApiOperation("新增订单操作记录")
    @PostMapping("/app/add")
    @ResponseBody
    public AjaxResult appAdd(@RequestBody OrderOperationRecord orderOperationRecord)
    {
        return toAjax(orderOperationRecordService.insertOrderOperationRecord(orderOperationRecord));
    }


    /**
     * 导出订单操作记录列表
     */
    @RequiresPermissions("order:operate:export")
    @Log(title = "订单操作记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(OrderOperationRecord orderOperationRecord)
    {
        List<OrderOperationRecord> list = orderOperationRecordService.selectOrderOperationRecordList(orderOperationRecord);
        ExcelUtil<OrderOperationRecord> util = new ExcelUtil<OrderOperationRecord>(OrderOperationRecord.class);
        return util.exportExcel(list, "订单操作记录数据");
    }

    /**
     * 新增订单操作记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存订单操作记录
     */
    @RequiresPermissions("order:operate:add")
    @Log(title = "订单操作记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(OrderOperationRecord orderOperationRecord)
    {
        return toAjax(orderOperationRecordService.insertOrderOperationRecord(orderOperationRecord));
    }

    /**
     * 修改订单操作记录
     */
    @RequiresPermissions("order:operate:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        OrderOperationRecord orderOperationRecord = orderOperationRecordService.selectOrderOperationRecordById(id);
        mmap.put("orderOperationRecord", orderOperationRecord);
        return prefix + "/edit";
    }

    /**
     * 修改保存订单操作记录
     */
    @RequiresPermissions("order:operate:edit")
    @Log(title = "订单操作记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(OrderOperationRecord orderOperationRecord)
    {
        return toAjax(orderOperationRecordService.updateOrderOperationRecord(orderOperationRecord));
    }

    /**
     * 删除订单操作记录
     */
    @RequiresPermissions("order:operate:remove")
    @Log(title = "订单操作记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(orderOperationRecordService.deleteOrderOperationRecordByIds(ids));
    }
}
