package com.ruoyi.web.controller.ai;

import com.ruoyi.ai.domain.AiUserMessage;
import com.ruoyi.ai.service.IAiUserMessageService;
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 shi
 * @date 2025-11-13
 */
@RestController
@RequestMapping("/ai/message")
public class AiUserMessageController extends BaseController
{
    @Autowired
    private IAiUserMessageService aiUserMessageService;

    /**
     * 查询站内信管理列表
     */
    @PreAuthorize("@ss.hasPermi('ai:message:list')")
    @GetMapping("/list")
    public TableDataInfo list(AiUserMessage aiUserMessage)
    {
        startPage();
        List<AiUserMessage> list = aiUserMessageService.selectAiUserMessageList(aiUserMessage);
        return getDataTable(list);
    }

    /**
     * 导出站内信管理列表
     */
    @PreAuthorize("@ss.hasPermi('ai:message:export')")
    @Log(title = "站内信管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AiUserMessage aiUserMessage)
    {
        List<AiUserMessage> list = aiUserMessageService.selectAiUserMessageList(aiUserMessage);
        ExcelUtil<AiUserMessage> util = new ExcelUtil<AiUserMessage>(AiUserMessage.class);
        util.exportExcel(response, list, "站内信管理数据");
    }

    /**
     * 获取站内信管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('ai:message:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(aiUserMessageService.selectAiUserMessageById(id));
    }

    /**
     * 新增站内信管理
     */
    @PreAuthorize("@ss.hasPermi('ai:message:add')")
    @Log(title = "站内信管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AiUserMessage aiUserMessage)
    {
        return toAjax(aiUserMessageService.insertAiUserMessage(aiUserMessage));
    }

    /**
     * 修改站内信管理
     */
    @PreAuthorize("@ss.hasPermi('ai:message:edit')")
    @Log(title = "站内信管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AiUserMessage aiUserMessage)
    {
        return toAjax(aiUserMessageService.updateAiUserMessage(aiUserMessage));
    }

    /**
     * 删除站内信管理
     */
    @PreAuthorize("@ss.hasPermi('ai:message:remove')")
    @Log(title = "站内信管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(aiUserMessageService.deleteAiUserMessageByIds(ids));
    }
}
