package com.ruoyi.frequency.appmessage.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.appmessage.entity.AppMessage;
import com.ruoyi.frequency.appmessage.service.AppMessageService;
import com.ruoyi.vo.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * app端消息Controller
 * 
 * @author liwenlong
 * @date 2023-07-20
 */
@RestController
@RequestMapping("/frequency/appmessage")
public class AppMessageController extends BaseController
{
    @Autowired
    private AppMessageService appMessageService;

    /**
     * 查询app端消息列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:appmessage:list')")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody AppMessage appMessage)
    {
        startPage();
        List<AppMessage> list = appMessageService.selectAppMessageList(appMessage);
        return getDataTable(list);
    }

    /**
     * 导出app端消息列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:appmessage:export')")
    @Log(title = "app端消息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(AppMessage appMessage)
    {
        List<AppMessage> list = appMessageService.selectAppMessageList(appMessage);
        ExcelUtil<AppMessage> util = new ExcelUtil<AppMessage>(AppMessage.class);
        return util.exportExcel(list, "app端消息数据");
    }

    /**
     * 获取app端消息详细信息
     */
    @PreAuthorize("@ss.hasPermi('frequency:appmessage:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(appMessageService.selectAppMessageById(id));
    }

    /**
     * 新增app端消息
     */
    @PreAuthorize("@ss.hasPermi('frequency:appmessage:add')")
    @Log(title = "app端消息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppMessage appMessage)
    {
        return toAjax(appMessageService.insertAppMessage(appMessage));
    }

    /**
     * 修改app端消息
     */
    @PreAuthorize("@ss.hasPermi('frequency:appmessage:edit')")
    @Log(title = "app端消息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppMessage appMessage)
    {
        return toAjax(appMessageService.updateAppMessage(appMessage));
    }

    /**
     * 删除app端消息
     */
    @PreAuthorize("@ss.hasPermi('frequency:appmessage:remove')")
    @Log(title = "app端消息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}/{delFlag}")
    public AjaxResult remove(@PathVariable("ids") Long[] ids ,@PathVariable("delFlag") Integer delFlag)
    {
        return toAjax(appMessageService.deleteAppMessageByIds(ids,delFlag));
    }

    /**
     * 消息用户列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:appmessage:messageUserPage')")
    @Log(title = "app端消息", businessType = BusinessType.DELETE)
    @DeleteMapping("/messageUserPage")
    public TableDataInfo messageUserPage(@RequestBody AppMessage appMessage)
    {
        startPage();
        List<UserInfo> list = appMessageService.messageUserPage(appMessage);
        return getDataTable(list);
    }

}
