package com.fs.chat.controller;

import java.util.List;

import com.fs.chat.param.ChatMsgLogsListCParam;
import com.fs.chat.vo.ChatMsgLogsListCVO;
import com.fs.chat.vo.ChatMsgLogsVO;
import com.fs.common.core.domain.R;
import com.fs.common.utils.ServletUtils;
import com.fs.framework.security.LoginUser;
import com.fs.framework.service.TokenService;
import com.fs.his.vo.FsDoctorArticleListUVO;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
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.chat.domain.ChatMsgLogs;
import com.fs.chat.service.IChatMsgLogsService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;

/**
 * 消息操作日志Controller
 *
 * @author fs
 * @date 2024-05-10
 */
@RestController
@RequestMapping("/chat/chatMsgLogs")
public class ChatMsgLogsController extends BaseController
{
    @Autowired
    private IChatMsgLogsService chatMsgLogsService;
    @Autowired
    private TokenService tokenService;

    /**
     * 查询消息操作日志列表
     */

    @GetMapping("/list")
    public TableDataInfo list(ChatMsgLogs chatMsgLogs)
    {
        startPage();
        List<ChatMsgLogsVO> list = chatMsgLogsService.selectChatMsgLogsListCVO(chatMsgLogs);
        return getDataTable(list);
    }

    @GetMapping("/logsList")
    public R list(ChatMsgLogsListCParam param)
    {
        PageHelper.startPage(param.getPageNum(), param.getPageSize());
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        param.setCompanyId(loginUser.getCompany().getCompanyId());
        List<ChatMsgLogsListCVO> list= chatMsgLogsService.selectChatMsgLogsListVO(param);
        PageInfo<ChatMsgLogsListCVO> listPageInfo=new PageInfo<>(list);
        return R.ok().put("data",listPageInfo);
    }

    /**
     * 导出消息操作日志列表
     */
    @PreAuthorize("@ss.hasPermi('chat:chatMsgLogs:export')")
    @Log(title = "消息操作日志", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ChatMsgLogsListCParam chatMsgLogs)
    {
        List<ChatMsgLogsListCVO> list = chatMsgLogsService.selectChatMsgLogsListVO(chatMsgLogs);
        ExcelUtil<ChatMsgLogsListCVO> util = new ExcelUtil<ChatMsgLogsListCVO>(ChatMsgLogsListCVO.class);
        return util.exportExcel(list, "消息操作日志数据");
    }

    /**
     * 获取消息操作日志详细信息
     */
    @PreAuthorize("@ss.hasPermi('chat:chatMsgLogs:query')")
    @GetMapping(value = "/{logsId}")
    public AjaxResult getInfo(@PathVariable("logsId") Long logsId)
    {
        return AjaxResult.success(chatMsgLogsService.selectChatMsgLogsByLogsId(logsId));
    }

    /**
     * 新增消息操作日志
     */
    @PreAuthorize("@ss.hasPermi('chat:chatMsgLogs:add')")
    @Log(title = "消息操作日志", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ChatMsgLogs chatMsgLogs)
    {
        return toAjax(chatMsgLogsService.insertChatMsgLogs(chatMsgLogs));
    }

    /**
     * 修改消息操作日志
     */
    @PreAuthorize("@ss.hasPermi('chat:chatMsgLogs:edit')")
    @Log(title = "消息操作日志", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ChatMsgLogs chatMsgLogs)
    {
        return toAjax(chatMsgLogsService.updateChatMsgLogs(chatMsgLogs));
    }

    /**
     * 删除消息操作日志
     */
    @PreAuthorize("@ss.hasPermi('chat:chatMsgLogs:remove')")
    @Log(title = "消息操作日志", businessType = BusinessType.DELETE)
	@DeleteMapping("/{logsIds}")
    public AjaxResult remove(@PathVariable Long[] logsIds)
    {
        return toAjax(chatMsgLogsService.deleteChatMsgLogsByLogsIds(logsIds));
    }
}
