package com.ghy.web.controller.order;

import java.util.List;
import com.ghy.order.domain.OrderCallRecord;
import com.ghy.order.service.IOrderCallRecordService;
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.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-06-04
 */
@Controller
@RequestMapping("/order/record")
public class OrderCallRecordController extends BaseController
{
    private String prefix = "order/record";

    @Autowired
    private IOrderCallRecordService orderCallRecordService;

//    @RequiresPermissions("worker:record:view")
    @GetMapping()
    public String record(Long orderId, ModelMap mmap)
    {
        mmap.put("orderId", orderId);
        return prefix;
    }

    /**
     * 查询订单约单记录列表
     */
    @RequiresPermissions("worker:record:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(OrderCallRecord orderCallRecord)
    {
        startPage();
        List<OrderCallRecord> list = orderCallRecordService.selectOrderCallRecordList(orderCallRecord);
        return getDataTable(list);
    }

    /**
     * App查询订单约单记录列表
     */
    @PostMapping("/app/list")
    @ResponseBody
    public TableDataInfo appList(@RequestBody OrderCallRecord orderCallRecord)
    {
        startPage();
        List<OrderCallRecord> list = orderCallRecordService.selectOrderCallRecordList(orderCallRecord);
        return getDataTable(list);
    }


    /**
     * 导出订单约单记录列表
     */
    @RequiresPermissions("worker:record:export")
    @Log(title = "订单约单记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(OrderCallRecord orderCallRecord)
    {
        List<OrderCallRecord> list = orderCallRecordService.selectOrderCallRecordList(orderCallRecord);
        ExcelUtil<OrderCallRecord> util = new ExcelUtil<OrderCallRecord>(OrderCallRecord.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(OrderCallRecord orderCallRecord)
    {
        return toAjax(orderCallRecordService.insertOrderCallRecord(orderCallRecord));
    }

    /**
     * 修改订单约单记录
     */
    @RequiresPermissions("worker:record:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        OrderCallRecord orderCallRecord = orderCallRecordService.selectOrderCallRecordById(id);
        mmap.put("orderCallRecord", orderCallRecord);
        return prefix + "/edit";
    }

    /**
     * 修改保存订单约单记录
     */
    @RequiresPermissions("worker:record:edit")
    @Log(title = "订单约单记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(OrderCallRecord orderCallRecord)
    {
        return toAjax(orderCallRecordService.updateOrderCallRecord(orderCallRecord));
    }

    /**
     * 删除订单约单记录
     */
    @RequiresPermissions("worker:record:remove")
    @Log(title = "订单约单记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(orderCallRecordService.deleteOrderCallRecordByIds(ids));
    }
}
