package com.ruoyi.web.controller.ss;

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

import com.ruoyi.ss.complaint.domain.SmComplaintQuery;
import com.ruoyi.ss.complaint.domain.SmComplaintVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ss.complaint.domain.SmComplaint;
import com.ruoyi.ss.complaint.service.ISmComplaintService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 投诉Controller
 *
 * @author ruoyi
 * @date 2024-03-02
 */
@RestController
@RequestMapping("/system/complaint")
public class SmComplaintController extends BaseController
{
    @Autowired
    private ISmComplaintService smComplaintService;

    /**
     * 查询投诉列表
     */
    @PreAuthorize("@ss.hasPermi('system:complaint:list')")
    @GetMapping("/list")
    public TableDataInfo list(SmComplaintQuery smComplaint)
    {
        startPage();
        List<SmComplaintVo> list = smComplaintService.selectSmComplaintList(smComplaint);
        return getDataTable(list);
    }

    /**
     * 导出投诉列表
     */
    @PreAuthorize("@ss.hasPermi('system:complaint:export')")
    @Log(title = "投诉", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SmComplaintQuery smComplaint)
    {
        List<SmComplaintVo> list = smComplaintService.selectSmComplaintList(smComplaint);
        ExcelUtil<SmComplaintVo> util = new ExcelUtil<SmComplaintVo>(SmComplaintVo.class);
        util.exportExcel(response, list, "投诉数据");
    }

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

    /**
     * 新增投诉
     */
    @PreAuthorize("@ss.hasPermi('system:complaint:add')")
    @Log(title = "投诉", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SmComplaint smComplaint)
    {
        return toAjax(smComplaintService.insertSmComplaint(smComplaint));
    }

    /**
     * 修改投诉
     */
    @PreAuthorize("@ss.hasPermi('system:complaint:edit')")
    @Log(title = "投诉", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SmComplaint smComplaint)
    {
        return toAjax(smComplaintService.updateSmComplaint(smComplaint));
    }

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