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.TbIdea;
import com.ruoyi.business.service.ITbIdeaService;
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/idea")
public class TbIdeaController extends BaseController
{
    private String prefix = "business/idea";

    @Autowired
    private ITbIdeaService tbIdeaService;

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

    /**
     * 查询意见反馈列表
     */
    @RequiresPermissions("business:idea:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TbIdea tbIdea)
    {
        startPage();
        List<TbIdea> list = tbIdeaService.selectTbIdeaList(tbIdea);
        return getDataTable(list);
    }

    /**
     * 导出意见反馈列表
     */
    @RequiresPermissions("business:idea:export")
    @Log(title = "意见反馈", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TbIdea tbIdea)
    {
        List<TbIdea> list = tbIdeaService.selectTbIdeaList(tbIdea);
        ExcelUtil<TbIdea> util = new ExcelUtil<TbIdea>(TbIdea.class);
        return util.exportExcel(list, "意见反馈数据");
    }

    /**
     * 新增意见反馈
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存意见反馈
     */
    @RequiresPermissions("business:idea:add")
    @Log(title = "意见反馈", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TbIdea tbIdea)
    {
        return toAjax(tbIdeaService.insertTbIdea(tbIdea));
    }

    /**
     * 修改意见反馈
     */
    @RequiresPermissions("business:idea:edit")
    @GetMapping("/edit/{ideaId}")
    public String edit(@PathVariable("ideaId") Long ideaId, ModelMap mmap)
    {
        TbIdea tbIdea = tbIdeaService.selectTbIdeaByIdeaId(ideaId);
        mmap.put("tbIdea", tbIdea);
        return prefix + "/edit";
    }

    /**
     * 修改保存意见反馈
     */
    @RequiresPermissions("business:idea:edit")
    @Log(title = "意见反馈", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TbIdea tbIdea)
    {
        return toAjax(tbIdeaService.updateTbIdea(tbIdea));
    }

    /**
     * 删除意见反馈
     */
    @RequiresPermissions("business:idea:remove")
    @Log(title = "意见反馈", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tbIdeaService.deleteTbIdeaByIdeaIds(ids));
    }
}
