package com.ghy.web.controller.order;

import com.ghy.common.annotation.Log;
import com.ghy.common.core.controller.BaseController;
import com.ghy.common.core.domain.AjaxResult;
import com.ghy.common.core.page.TableDataInfo;
import com.ghy.common.enums.BusinessType;
import com.ghy.common.utils.poi.ExcelUtil;
import com.ghy.order.domain.OrderAssessLabel;
import com.ghy.order.service.IOrderAssessLabelService;
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 java.util.List;

/**
 * 订单与评价标签关联关系Controller
 *
 * @author ydq
 * @date : 2022-10-08 22:11
 */
@Controller
@RequestMapping("/worker/label")
public class OrderAssessLabelController extends BaseController
{
    private String prefix = "worker/label";

    @Autowired
    private IOrderAssessLabelService orderAssessLabelService;

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

    /**
     * 查询订单与评价标签关联关系列表
     */
    @RequiresPermissions("worker:label:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(OrderAssessLabel orderAssessLabel)
    {
        startPage();
        List<OrderAssessLabel> list = orderAssessLabelService.selectOrderAssessLabelList(orderAssessLabel);
        return getDataTable(list);
    }

    /**
     * App查询订单与评价标签关联关系列表
     */
    @PostMapping("/app/list")
    @ResponseBody
    public TableDataInfo appList(@RequestBody OrderAssessLabel orderAssessLabel)
    {
        startPage();
        List<OrderAssessLabel> list = orderAssessLabelService.selectOrderAssessLabelList(orderAssessLabel);
        return getDataTable(list);
    }


    /**
     * 导出订单与评价标签关联关系列表
     */
    @RequiresPermissions("worker:label:export")
    @Log(title = "订单与评价标签关联关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(OrderAssessLabel orderAssessLabel)
    {
        List<OrderAssessLabel> list = orderAssessLabelService.selectOrderAssessLabelList(orderAssessLabel);
        ExcelUtil<OrderAssessLabel> util = new ExcelUtil<OrderAssessLabel>(OrderAssessLabel.class);
        return util.exportExcel(list, "订单与评价标签关联关系数据");
    }

    /**
     * 新增订单与评价标签关联关系
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存订单与评价标签关联关系
     */
    @RequiresPermissions("worker:label:add")
    @Log(title = "订单与评价标签关联关系", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(OrderAssessLabel orderAssessLabel)
    {
        return toAjax(orderAssessLabelService.insertOrderAssessLabel(orderAssessLabel));
    }

    /**
     * 修改订单与评价标签关联关系
     */
    @RequiresPermissions("worker:label:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        OrderAssessLabel orderAssessLabel = orderAssessLabelService.selectOrderAssessLabelById(id);
        mmap.put("orderAssessLabel", orderAssessLabel);
        return prefix + "/edit";
    }

    /**
     * 修改保存订单与评价标签关联关系
     */
    @RequiresPermissions("worker:label:edit")
    @Log(title = "订单与评价标签关联关系", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(OrderAssessLabel orderAssessLabel)
    {
        return toAjax(orderAssessLabelService.updateOrderAssessLabel(orderAssessLabel));
    }

    /**
     * 删除订单与评价标签关联关系
     */
    @RequiresPermissions("worker:label:remove")
    @Log(title = "订单与评价标签关联关系", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(orderAssessLabelService.deleteOrderAssessLabelByIds(ids));
    }
}
