package com.ruoyi.web.controller.business;

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.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.ReReq;
import com.ruoyi.business.service.IReReqService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 投诉Controller
 * 
 * @author xiatao
 * @date 2022-01-18
 */
@Controller
@RequestMapping("/business/req")
public class ReReqController extends BaseController
{
    private String prefix = "business/req";

    @Autowired
    private IReReqService reReqService;

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

    /**
     * 查询投诉列表
     */
    @RequiresPermissions("business:req:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ReReq reReq)
    {
        startPage();
        List<ReReq> list = reReqService.selectReReqList(reReq);
        return getDataTable(list);
    }

    /**
     * 导出投诉列表
     */
    @RequiresPermissions("business:req:export")
    @Log(title = "投诉", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ReReq reReq)
    {
        List<ReReq> list = reReqService.selectReReqList(reReq);
        ExcelUtil<ReReq> util = new ExcelUtil<ReReq>(ReReq.class);
        return util.exportExcel(list, "投诉数据");
    }

    /**
     * 新增投诉
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存投诉
     */
    @RequiresPermissions("business:req:add")
    @Log(title = "投诉", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ReReq reReq)
    {
        return toAjax(reReqService.insertReReq(reReq));
    }

    /**
     * 修改投诉
     */
    @RequiresPermissions("business:req:edit")
    @GetMapping("/edit/{reqId}")
    public String edit(@PathVariable("reqId") Long reqId, ModelMap mmap)
    {
        ReReq reReq = reReqService.selectReReqByReqId(reqId);
        mmap.put("reReq", reReq);
        return prefix + "/edit";
    }

    /**
     * 修改保存投诉
     */
    @RequiresPermissions("business:req:edit")
    @Log(title = "投诉", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ReReq reReq)
    {
        return toAjax(reReqService.updateReReq(reReq));
    }

    /**
     * 删除投诉
     */
    @RequiresPermissions("business:req:remove")
    @Log(title = "投诉", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(reReqService.deleteReReqByReqIds(ids));
    }
}
