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.ss.feedback.domain.Feedback;
import com.ruoyi.ss.feedback.service.IFeedbackService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 反馈意见Controller
 *
 * @author qzz
 * @date 2024-10-18
 */
@RestController
@RequestMapping("/system/feedback")
public class FeedbackController extends BaseController
{
    @Resource
    private IFeedbackService asFeedbackService;

    /**
     * 查询反馈意见列表
     */
    @PreAuthorize("@ss.hasPermi('system:feedback:list')")
    @GetMapping("/list")
    public TableDataInfo list(Feedback asFeedback)
    {
        startPage();
        List<Feedback> list = asFeedbackService.selectAsFeedbackList(asFeedback);
        return getDataTable(list);
    }

    /**
     * 导出反馈意见列表
     */
    @PreAuthorize("@ss.hasPermi('system:feedback:export')")
    @Log(title = "反馈意见", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Feedback asFeedback)
    {
        List<Feedback> list = asFeedbackService.selectAsFeedbackList(asFeedback);
        ExcelUtil<Feedback> util = new ExcelUtil<Feedback>(Feedback.class);
        util.exportExcel(response, list, "反馈意见数据");
    }

    /**
     * 获取反馈意见详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:feedback:query')")
    @GetMapping(value = "/{feedbackId}")
    public AjaxResult getInfo(@PathVariable("feedbackId") Long feedbackId)
    {
        return success(asFeedbackService.selectAsFeedbackByFeedbackId(feedbackId));
    }

    /**
     * 新增反馈意见
     */
    @PreAuthorize("@ss.hasPermi('system:feedback:add')")
    @Log(title = "反馈意见", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Feedback asFeedback)
    {
        return toAjax(asFeedbackService.insertAsFeedback(asFeedback));
    }

    /**
     * 修改反馈意见
     */
    @PreAuthorize("@ss.hasPermi('system:feedback:edit')")
    @Log(title = "反馈意见", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Feedback asFeedback)
    {
        return toAjax(asFeedbackService.updateAsFeedback(asFeedback));
    }

    /**
     * 删除反馈意见
     */
    @PreAuthorize("@ss.hasPermi('system:feedback:remove')")
    @Log(title = "反馈意见", businessType = BusinessType.DELETE)
	@DeleteMapping("/{feedbackIds}")
    public AjaxResult remove(@PathVariable Long[] feedbackIds)
    {
        return toAjax(asFeedbackService.deleteAsFeedbackByFeedbackIds(feedbackIds));
    }
}
