package com.ghy.web.controller.order;

import java.util.List;
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.OrderAddRecord;
import com.ghy.order.service.IOrderAddRecordService;
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 2023-11-03
 */
@Controller
@RequestMapping("/add/record")
public class OrderAddRecordController extends BaseController
{
    private String prefix = "add/record";

    @Autowired
    private IOrderAddRecordService orderAddRecordService;

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

    /**
     * 查询发单加价记录列表
     */
    @RequiresPermissions("worker:record:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(OrderAddRecord orderAddRecord)
    {
        startPage();
        List<OrderAddRecord> list = orderAddRecordService.selectOrderAddRecordList(orderAddRecord);
        return getDataTable(list);
    }

    /**
     * App查询发单加价记录列表
     */
    @PostMapping("/app/list")
    @ResponseBody
    public TableDataInfo appList(@RequestBody OrderAddRecord orderAddRecord)
    {
        startPage();
        List<OrderAddRecord> list = orderAddRecordService.selectOrderAddRecordList(orderAddRecord);
        return getDataTable(list);
    }

    @PostMapping("/app/add")
    @ResponseBody
    public AjaxResult appAddSave(@RequestBody OrderAddRecord orderAddRecord)
    {
        return toAjax(orderAddRecordService.insertOrderAddRecord(orderAddRecord));
    }


    /**
     * 导出发单加价记录列表
     */
    @RequiresPermissions("worker:record:export")
    @Log(title = "发单加价记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(OrderAddRecord orderAddRecord)
    {
        List<OrderAddRecord> list = orderAddRecordService.selectOrderAddRecordList(orderAddRecord);
        ExcelUtil<OrderAddRecord> util = new ExcelUtil<OrderAddRecord>(OrderAddRecord.class);
        return util.exportExcel(list, "发单加价记录数据");
    }

    /**
     * 新增发单加价记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存发单加价记录
     */
    @RequiresPermissions("worker:record:add")
    @Log(title = "发单加价记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(OrderAddRecord orderAddRecord)
    {
        return toAjax(orderAddRecordService.insertOrderAddRecord(orderAddRecord));
    }

    /**
     * 修改发单加价记录
     */
    @RequiresPermissions("worker:record:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        OrderAddRecord orderAddRecord = orderAddRecordService.selectOrderAddRecordById(id);
        mmap.put("orderAddRecord", orderAddRecord);
        return prefix + "/edit";
    }

    /**
     * 修改保存发单加价记录
     */
    @RequiresPermissions("worker:record:edit")
    @Log(title = "发单加价记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(OrderAddRecord orderAddRecord)
    {
        return toAjax(orderAddRecordService.updateOrderAddRecord(orderAddRecord));
    }

    /**
     * 删除发单加价记录
     */
    @RequiresPermissions("worker:record:remove")
    @Log(title = "发单加价记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(orderAddRecordService.deleteOrderAddRecordByIds(ids));
    }
}