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.MessageConfigDTO;
import com.prolog.rdc.tms.model.vo.message.DeleteMessageConfigVO;
import com.prolog.rdc.tms.model.vo.message.MessageConfigQueryVO;
import com.prolog.rdc.tms.model.vo.message.SaveMessageConfigVO;
import com.prolog.rdc.tms.model.vo.message.UpdateMessageConfigStatusVO;
import com.prolog.rdc.tms.service.message.MessageConfigService;
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;

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

    @Autowired
    private MessageConfigService messageConfigService;

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

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

    @UserLog("消息配置保存")
    @ApiOperation(httpMethod = "POST", value = "消息配置保存")
    @PostMapping(value = "/save")
    public RestMessage save(@RequestBody SaveMessageConfigVO vo) {
        messageConfigService.save(vo);
        return RestMessage.newInstance(true, "保存成功", null);
    }

    @UserLog("消息配置启用/停用")
    @ApiOperation(httpMethod = "POST", value = "消息配置启用/停用")
    @PostMapping(value = "/updateStatus")
    public RestMessage updateStatus(@RequestBody UpdateMessageConfigStatusVO vo) {
        messageConfigService.updateStatus(vo);
        return RestMessage.newInstance(true, "操作成功", null);
    }

    @UserLog("消息配置删除")
    @ApiOperation(httpMethod = "POST", value = "消息配置删除")
    @PostMapping(value = "/delete")
    public RestMessage delete(@RequestBody DeleteMessageConfigVO vo) {
        messageConfigService.delete(vo);
        return RestMessage.newInstance(true, "删除成功", null);
    }
}
