package com.fs.user.controller;

import java.util.List;
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.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.enums.BusinessType;
import com.fs.user.domain.FsUserComplaintMsg;
import com.fs.user.service.IFsUserComplaintMsgService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;

/**
 * 投诉消息记录Controller
 *
 * @author fs
 * @date 2025-09-08
 */
@RestController
@RequestMapping("/user/msg")
public class FsUserComplaintMsgController extends BaseController
{
    @Autowired
    private IFsUserComplaintMsgService fsUserComplaintMsgService;

    /**
     * 查询投诉消息记录列表
     */
//    @PreAuthorize("@ss.hasPermi('user:msg:list')")
    @GetMapping("/list")
    public TableDataInfo list(FsUserComplaintMsg fsUserComplaintMsg)
    {
        startPage();
        List<FsUserComplaintMsg> list = fsUserComplaintMsgService.selectFsUserComplaintMsgList(fsUserComplaintMsg);
        return getDataTable(list);
    }

    /**
     * 导出投诉消息记录列表
     */
//    @PreAuthorize("@ss.hasPermi('user:msg:export')")
    @Log(title = "投诉消息记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsUserComplaintMsg fsUserComplaintMsg)
    {
        List<FsUserComplaintMsg> list = fsUserComplaintMsgService.selectFsUserComplaintMsgList(fsUserComplaintMsg);
        ExcelUtil<FsUserComplaintMsg> util = new ExcelUtil<FsUserComplaintMsg>(FsUserComplaintMsg.class);
        return util.exportExcel(list, "投诉消息记录数据");
    }

    /**
     * 获取投诉消息记录详细信息
     */
//    @PreAuthorize("@ss.hasPermi('user:msg:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(fsUserComplaintMsgService.selectFsUserComplaintMsgById(id));
    }

    /**
     * 新增投诉消息记录
     */
    @PreAuthorize("@ss.hasPermi('user:msg:add')")
    @Log(title = "投诉消息记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FsUserComplaintMsg fsUserComplaintMsg)
    {
        if (fsUserComplaintMsg.getComplaintId() == null){
            return AjaxResult.error("未查询到相关投诉！");
        }
        Long userId = getUserId();
        fsUserComplaintMsg.setUserId(userId);
        fsUserComplaintMsg.setSendType(2); //平台
        return toAjax(fsUserComplaintMsgService.insertFsUserComplaintMsg(fsUserComplaintMsg));
    }

    /**
     * 修改投诉消息记录
     */
    @PreAuthorize("@ss.hasPermi('user:msg:edit')")
    @Log(title = "投诉消息记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsUserComplaintMsg fsUserComplaintMsg)
    {
        return toAjax(fsUserComplaintMsgService.updateFsUserComplaintMsg(fsUserComplaintMsg));
    }

    /**
     * 删除投诉消息记录
     */
    @PreAuthorize("@ss.hasPermi('user:msg:remove')")
    @Log(title = "投诉消息记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(fsUserComplaintMsgService.deleteFsUserComplaintMsgByIds(ids));
    }
}
