package com.prolog.rdc.tms.controller.message;

import com.prolog.framework.common.message.RestMessage;
import com.prolog.framework.core.pojo.Page;
import com.prolog.framework.log.aop.annotation.UserLog;
import com.prolog.rdc.tms.model.dto.message.MessageCountDTO;
import com.prolog.rdc.tms.model.dto.message.MessageDTO;
import com.prolog.rdc.tms.model.vo.message.MessageQueryVO;
import com.prolog.rdc.tms.model.vo.message.MessageReadAllVO;
import com.prolog.rdc.tms.model.vo.message.PullMessageVO;
import com.prolog.rdc.tms.model.vo.message.ReadMessageVO;
import com.prolog.rdc.tms.service.message.MessageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author hongbo.pan
 * @date 2022/11/15
 */
@RestController
@Api(tags = "基础配置-消息控制层")
@RequestMapping("/message")
public class MessageController {

    @Autowired
    private MessageService messageService;

    @UserLog("消息分页查询")
    @ApiOperation(httpMethod = "POST", value = "消息分页查询")
    @PostMapping(value = "/page")
    public RestMessage<Page<MessageDTO>> page(@RequestBody MessageQueryVO vo) {
        Page<MessageDTO> pageDTOs = messageService.query(vo);
        return RestMessage.newInstance(true, "查询成功", pageDTOs);
    }

    @UserLog("消息查询")
    @ApiOperation(httpMethod = "POST", value = "消息查询")
    @PostMapping(value = "/findById")
    public RestMessage<MessageDTO> findById(@RequestParam("id") Long id) {
        MessageDTO messageDTO = messageService.findById(id);
        return RestMessage.newInstance(true, "查询成功", messageDTO);
    }

    @UserLog("消息合计查询")
    @ApiOperation(httpMethod = "POST", value = "消息合计查询")
    @PostMapping(value = "/countMessage")
    public RestMessage<Long> countMessage(@RequestBody MessageQueryVO vo) {
        Long count = messageService.countMessage(vo);
        return RestMessage.newInstance(true, "查询成功", count);
    }

    @UserLog("消息已读")
    @ApiOperation(httpMethod = "POST", value = "消息已读")
    @PostMapping(value = "/read")
    public RestMessage read(@RequestBody ReadMessageVO vo) {
        messageService.read(vo);
        return RestMessage.newInstance(true, "已读成功", null);
    }

    @UserLog("消息全部已读")
    @ApiOperation(httpMethod = "POST", value = "消息全部已读")
    @PostMapping(value = "/readAll")
    public RestMessage readAll(@RequestBody MessageReadAllVO vo) {
        messageService.readAll(vo);
        return RestMessage.newInstance(true, "全部已读成功", null);
    }

    @UserLog("消息拉取")
    @ApiOperation(httpMethod = "POST", value = "消息拉取")
    @PostMapping(value = "/pullMessage")
    public RestMessage<List<MessageDTO>> pullMessage(@RequestBody PullMessageVO vo) {
        return RestMessage.newInstance(true, "查询成功", messageService.pullMessage(vo));
    }

    @UserLog("预警运单合计")
    @ApiOperation(httpMethod = "POST", value = "预警运单合计")
    @PostMapping(value = "/countByMessageType")
    public RestMessage<MessageCountDTO> countByMessageType() {
        return RestMessage.newInstance(true, "查询成功", messageService.countByMessageType());
    }

}
