package com.ruoyi.frequency.userappmessage.controller;

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 com.ruoyi.frequency.userappmessage.entity.UserAppMessage;
import com.ruoyi.frequency.userappmessage.service.UserAppMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户已读消息Controller
 * 
 * @author liwenlong
 * @date 2023-07-20
 */
@RestController
@RequestMapping("/frequency/userappmessage")
public class UserAppMessageController extends BaseController
{
    @Autowired
    private UserAppMessageService userAppMessageService;

    /**
     * 查询用户已读消息列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:userappmessage:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserAppMessage userAppMessage)
    {
        startPage();
        List<UserAppMessage> list = userAppMessageService.selectUserAppMessageList(userAppMessage);
        return getDataTable(list);
    }

    /**
     * 导出用户已读消息列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:userappmessage:export')")
    @Log(title = "用户已读消息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(UserAppMessage userAppMessage)
    {
        List<UserAppMessage> list = userAppMessageService.selectUserAppMessageList(userAppMessage);
        ExcelUtil<UserAppMessage> util = new ExcelUtil<UserAppMessage>(UserAppMessage.class);
        return util.exportExcel(list, "用户已读消息数据");
    }

    /**
     * 获取用户已读消息详细信息
     */
    @PreAuthorize("@ss.hasPermi('frequency:userappmessage:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(userAppMessageService.selectUserAppMessageById(id));
    }

    /**
     * 新增用户已读消息
     */
    @PreAuthorize("@ss.hasPermi('frequency:userappmessage:add')")
    @Log(title = "用户已读消息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserAppMessage userAppMessage)
    {
        return toAjax(userAppMessageService.insertUserAppMessage(userAppMessage));
    }

    /**
     * 修改用户已读消息
     */
    @PreAuthorize("@ss.hasPermi('frequency:userappmessage:edit')")
    @Log(title = "用户已读消息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserAppMessage userAppMessage)
    {
        return toAjax(userAppMessageService.updateUserAppMessage(userAppMessage));
    }

    /**
     * 删除用户已读消息
     */
    @PreAuthorize("@ss.hasPermi('frequency:userappmessage:remove')")
    @Log(title = "用户已读消息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(userAppMessageService.deleteUserAppMessageByIds(ids));
    }
}
