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

import java.util.List;

import com.prolog.rdc.tms.model.vo.basicConfigure.*;
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.RestController;

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.basicConfigure.MessageCountDTO;
import com.prolog.rdc.tms.model.dto.basicConfigure.SysAlertMessageQueryDTO;
import com.prolog.rdc.tms.service.basicConfigure.SysAlertMessageService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 
 *
 * 首页-预警消息控制层
 *
 * @className :SysAlertMessageController
 * @author :fanzw
 * @creationTime :2022/01/18
 * @description :
 *
 * @modifier :fanzw
 * @modifyTime :2022/01/18
 * @reviseRemarks:
 *
 * @version :1.0.0
 *
 */
@Api(tags = "首页-预警消息")
@RestController
@RequestMapping("/alertMessage")
public class SysAlertMessageController {

	@Autowired
	private SysAlertMessageService sysAlertMessageService;

	@UserLog("预警消息查询")
	@ApiOperation(value = "预警消息查询", notes = "预警消息查询")
	@PostMapping("/query")
	public RestMessage<Page<SysAlertMessageQueryDTO>> listAlertMessageExecute(@RequestBody SysAlertMessageQueryVO sysAlertMessageQueryVO) {
		try {
			Page<SysAlertMessageQueryDTO> sysAlertMessageQueryDTOs = sysAlertMessageService.listAlertMessageData(sysAlertMessageQueryVO);
			return RestMessage.newInstance(true, "查询成功", sysAlertMessageQueryDTOs);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("预警消息是否存在")
	@ApiOperation(value = "预警消息是否存在", notes = "预警消息是否存在")
	@PostMapping("/is_exist")
	public RestMessage<Boolean> alertMessageIsExistExecute(@RequestBody AlertMessageIsExistVO alertMessageIsExistVO) {
		try {
			Boolean isExist = sysAlertMessageService.alertMessageIsExist(alertMessageIsExistVO);
			return RestMessage.newInstance(true, "预警消息是否存在查询成功", isExist);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("预警消息新增")
	@ApiOperation(value = "预警消息新增", notes = "预警消息新增")
	@PostMapping("/add")
	public RestMessage<String> alertMessageAddExecute(@RequestBody List<AlertMessageAddVO> alertMessageAddVOs) {
		try {
			sysAlertMessageService.alertMessageAdd(alertMessageAddVOs);
			return RestMessage.newInstance(true, "预警消息新增成功", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("消息数量查询")
	@ApiOperation(value = "消息数量查询", notes = "消息数量查询")
	@PostMapping("/count")
	public RestMessage<MessageCountDTO> countMessageExecute() {
		try {
			MessageCountDTO messageCountDTO = sysAlertMessageService.countMessageData();
			return RestMessage.newInstance(true, "查询成功", messageCountDTO);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("预警消息已读")
	@ApiOperation(value = "预警消息已读", notes = "预警消息已读")
	@PostMapping("/read")
	public RestMessage<String> readAlertMessageExecute(@RequestBody List<SysAlertMessageReadVO> sysAlertMessageReadVOs) {
		try {
			sysAlertMessageService.readAlertMessageData(sysAlertMessageReadVOs);
			return RestMessage.newInstance(true, "处理成功", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("预警消息处理")
	@ApiOperation(value = "预警消息处理", notes = "预警消息处理")
	@PostMapping("/handle")
	public RestMessage<String> handleAlertMessageExecute(@RequestBody List<SysAlertMessageHandleVO> sysAlertMessageHandleVOs) {
		try {
			sysAlertMessageService.handleAlertMessageData(sysAlertMessageHandleVOs);
			return RestMessage.newInstance(true, "处理成功", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

}
