package com.ruoyi.mall.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
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.mall.domain.MemberMessage;
import com.ruoyi.mall.service.IMemberMessageService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户消息Controller
 * (帖子消息）
 * @author ruoyi
 * @date 2023-10-18
 */
@RestController
@RequestMapping("/mall/message")
public class MemberMessageController extends BaseController
{
    @Autowired
    private IMemberMessageService memberMessageService;

    /**
     * 查询用户消息列表
     */
    @PreAuthorize("@ss.hasPermi('mall:message:list')")
    @GetMapping("/list")
    public TableDataInfo list(MemberMessage memberMessage)
    {
        startPage();
        List<MemberMessage> list = memberMessageService.selectMemberMessageList(memberMessage);
        return getDataTable(list);
    }

    /**
     * 导出用户消息列表
     */
    @PreAuthorize("@ss.hasPermi('mall:message:export')")
    @Log(title = "用户消息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MemberMessage memberMessage)
    {
        List<MemberMessage> list = memberMessageService.selectMemberMessageList(memberMessage);
        ExcelUtil<MemberMessage> util = new ExcelUtil<MemberMessage>(MemberMessage.class);
        util.exportExcel(response, list, "用户消息数据");
    }

    /**
     * 获取用户消息详细信息
     */
    @PreAuthorize("@ss.hasPermi('mall:message:query')")
    @GetMapping(value = "/{messageId}")
    public AjaxResult getInfo(@PathVariable("messageId") Long messageId)
    {
        return AjaxResult.success(memberMessageService.selectMemberMessageByMessageId(messageId));
    }

    /**
     * 新增用户消息
     */
    @PreAuthorize("@ss.hasPermi('mall:message:add')")
    @Log(title = "用户消息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MemberMessage memberMessage)
    {
        return toAjax(memberMessageService.insertMemberMessage(memberMessage));
    }

    /**
     * 修改用户消息
     */
    @PreAuthorize("@ss.hasPermi('mall:message:edit')")
    @Log(title = "用户消息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MemberMessage memberMessage)
    {
        return toAjax(memberMessageService.updateMemberMessage(memberMessage));
    }

    /**
     * 删除用户消息
     */
    @PreAuthorize("@ss.hasPermi('mall:message:remove')")
    @Log(title = "用户消息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{messageIds}")
    public AjaxResult remove(@PathVariable Long[] messageIds)
    {
        return toAjax(memberMessageService.deleteMemberMessageByMessageIds(messageIds));
    }
}
