package com.ruoyi.web.controller.complaintSuggestion;

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.complaintSuggestion.ComplaintSuggestion;
import com.ruoyi.system.service.IComplaintSuggestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 投诉建议Controller
 *
 * @author boman
 * @date 2025-02-14
 */
@RestController
@RequestMapping("/wuYe/suggestion")
public class ComplaintSuggestionController extends BaseController {
    @Autowired
    private IComplaintSuggestionService complaintSuggestionService;

    /**
     * 查询投诉建议列表
     */
    @PreAuthorize("@ss.hasPermi('wuYe:suggestion:list')")
    @GetMapping("/list")
    public TableDataInfo list(ComplaintSuggestion complaintSuggestion) {
        startPage();
        List<ComplaintSuggestion> list = complaintSuggestionService.selectComplaintSuggestionList(complaintSuggestion);
        return getDataTable(list);
    }

    /**
     * 导出投诉建议列表
     */
    @PreAuthorize("@ss.hasPermi('wuYe:suggestion:export')")
    @Log(title = "投诉建议", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ComplaintSuggestion complaintSuggestion) {
        List<ComplaintSuggestion> list = complaintSuggestionService.selectComplaintSuggestionList(complaintSuggestion);
        ExcelUtil<ComplaintSuggestion> util = new ExcelUtil<ComplaintSuggestion>(ComplaintSuggestion.class);
        util.exportExcel(response, list, "投诉建议数据");
    }

    /**
     * 获取投诉建议详细信息
     */
    @PreAuthorize("@ss.hasPermi('wuYe:suggestion:query')")
    @GetMapping(value = "/{suggestionId}")
    public AjaxResult getInfo(@PathVariable("suggestionId") Long suggestionId) {
        return success(complaintSuggestionService.selectComplaintSuggestionBySuggestionId(suggestionId));
    }

    /**
     * 新增投诉建议
     */
    @PreAuthorize("@ss.hasPermi('wuYe:suggestion:add')")
    @Log(title = "投诉建议", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ComplaintSuggestion complaintSuggestion) {
        return toAjax(complaintSuggestionService.insertComplaintSuggestion(complaintSuggestion));
    }

    /**
     * 修改投诉建议
     */
    @PreAuthorize("@ss.hasPermi('wuYe:suggestion:edit')")
    @Log(title = "投诉建议", businessType = BusinessType.UPDATE)
    @PostMapping("/put")
    public AjaxResult edit(@RequestBody ComplaintSuggestion complaintSuggestion) {
        return toAjax(complaintSuggestionService.updateComplaintSuggestion(complaintSuggestion));
    }

    /**
     * 删除投诉建议
     */
    @PreAuthorize("@ss.hasPermi('wuYe:suggestion:remove')")
    @Log(title = "投诉建议", businessType = BusinessType.DELETE)
    @GetMapping("/delete/{suggestionIds}")
    public AjaxResult remove(@PathVariable Long[] suggestionIds) {
        return toAjax(complaintSuggestionService.deleteComplaintSuggestionBySuggestionIds(suggestionIds));
    }
}
