package com.ruoyi.web.bst;

import com.ruoyi.bst.complaint.domain.Complaint;
import com.ruoyi.bst.complaint.domain.ComplaintQuery;
import com.ruoyi.bst.complaint.domain.ComplaintVO;
import com.ruoyi.bst.complaint.service.ComplaintService;
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 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 ruoyi
 * @date 2025-03-31
 */
@RestController
@RequestMapping("/bst/complaint")
public class ComplaintController extends BaseController
{
    @Autowired
    private ComplaintService complaintService;

    /**
     * 查询投诉列表
     */
    @PreAuthorize("@ss.hasPermi('bst:complaint:list')")
    @GetMapping("/list")
    public TableDataInfo list(ComplaintQuery query)
    {
        startPage();
        startOrderBy();
        List<ComplaintVO> list = complaintService.selectComplaintList(query);
        return getDataTable(list);
    }

    /**
     * 导出投诉列表
     */
    @PreAuthorize("@ss.hasPermi('bst:complaint:export')")
    @Log(title = "投诉", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ComplaintQuery query)
    {
        List<ComplaintVO> list = complaintService.selectComplaintList(query);
        ExcelUtil<ComplaintVO> util = new ExcelUtil<ComplaintVO>(ComplaintVO.class);
        util.exportExcel(response, list, "投诉数据");
    }

    /**
     * 获取投诉详细信息
     */
    @PreAuthorize("@ss.hasPermi('bst:complaint:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(complaintService.selectComplaintById(id));
    }

    /**
     * 新增投诉
     */
    @PreAuthorize("@ss.hasPermi('bst:complaint:add')")
    @Log(title = "投诉", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Complaint complaint)
    {
        return toAjax(complaintService.insertComplaint(complaint));
    }

    /**
     * 修改投诉
     */
    @PreAuthorize("@ss.hasPermi('bst:complaint:edit')")
    @Log(title = "投诉", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Complaint complaint)
    {
        return toAjax(complaintService.updateComplaint(complaint));
    }

    /**
     * 删除投诉
     */
    @PreAuthorize("@ss.hasPermi('bst:complaint:remove')")
    @Log(title = "投诉", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(complaintService.deleteComplaintByIds(ids));
    }
}
