package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.FeedbackFile;
import com.ruoyi.system.service.IFeedbackFileService;
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 ruoyi
 * @date 2022-10-21
 */
@Controller
@RequestMapping("/system/feedbackFile")
public class FeedbackFileController extends BaseController
{
    private String prefix = "system/feedbackFile";

    @Autowired
    private IFeedbackFileService feedbackFileService;

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

    /**
     * 查询反馈附件列表
     */
    @RequiresPermissions("system:feedbackFile:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(FeedbackFile feedbackFile)
    {
        startPage();
        List<FeedbackFile> list = feedbackFileService.selectFeedbackFileList(feedbackFile);
        return getDataTable(list);
    }

    /**
     * 导出反馈附件列表
     */
    @RequiresPermissions("system:feedbackFile:export")
    @Log(title = "反馈附件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(FeedbackFile feedbackFile)
    {
        List<FeedbackFile> list = feedbackFileService.selectFeedbackFileList(feedbackFile);
        ExcelUtil<FeedbackFile> util = new ExcelUtil<FeedbackFile>(FeedbackFile.class);
        return util.exportExcel(list, "feedbackFile");
    }

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

    /**
     * 新增保存反馈附件
     */
    @RequiresPermissions("system:feedbackFile:add")
    @Log(title = "反馈附件", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(FeedbackFile feedbackFile)
    {
        return toAjax(feedbackFileService.insertFeedbackFile(feedbackFile));
    }

    /**
     * 修改反馈附件
     */
    @GetMapping("/edit/{fileId}")
    public String edit(@PathVariable("fileId") Long fileId, ModelMap mmap)
    {
        FeedbackFile feedbackFile = feedbackFileService.selectFeedbackFileById(fileId);
        mmap.put("feedbackFile", feedbackFile);
        return prefix + "/edit";
    }

    /**
     * 修改保存反馈附件
     */
    @RequiresPermissions("system:feedbackFile:edit")
    @Log(title = "反馈附件", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(FeedbackFile feedbackFile)
    {
        return toAjax(feedbackFileService.updateFeedbackFile(feedbackFile));
    }

    /**
     * 删除反馈附件
     */
    @RequiresPermissions("system:feedbackFile:remove")
    @Log(title = "反馈附件", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(feedbackFileService.deleteFeedbackFileByIds(ids));
    }
}
