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.SysAlertConfigurationQueryDTO;
import com.prolog.rdc.tms.model.dto.basicConfigure.SysAlertUsersQueryDTO;
import com.prolog.rdc.tms.service.basicConfigure.SysAlertConfigurationService;

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

/**
 * 
 *
 * 基础配置-预警配置控制层
 *
 * @className :SysAlertConfigurationController
 * @author :fanzw
 * @creationTime :2022/01/18
 * @description :
 *
 * @modifier :fanzw
 * @modifyTime :2022/01/18
 * @reviseRemarks:
 *
 * @version :1.0.0
 *
 */
@Api(tags = "基础配置-预警配置")
@RestController
@RequestMapping("/alertConfiguration")
public class SysAlertConfigurationController {

	@Autowired
	private SysAlertConfigurationService sysAlertConfigurationService;

	@UserLog("预警配置查询")
	@ApiOperation(value = "预警配置查询", notes = "预警配置查询")
	@PostMapping("/query")
	public RestMessage<Page<SysAlertConfigurationQueryDTO>> listAlertConfigurationExecute(@RequestBody SysAlertConfigurationQueryVO sysAlertConfigurationQueryVO) {
		try {
			Page<SysAlertConfigurationQueryDTO> sysAlertConfigurationQueryDTOs = sysAlertConfigurationService.listAlertConfigurationData(sysAlertConfigurationQueryVO);
			return RestMessage.newInstance(true, "查询成功", sysAlertConfigurationQueryDTOs);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("预警配置查询")
	@ApiOperation(value = "预警配置查询", notes = "预警配置查询")
	@PostMapping("/alert_cfg_query")
	public RestMessage<List<SysAlertConfigurationQueryDTO>> alertConfigurationQueryExecute(@RequestBody SysAlertConfigurationQueryVO sysAlertConfigurationQueryVO) {
		try {
			List<SysAlertConfigurationQueryDTO> sysAlertConfigurationQueryDTOs = sysAlertConfigurationService.alertConfigurationQuery(sysAlertConfigurationQueryVO);
			return RestMessage.newInstance(true, "查询成功", sysAlertConfigurationQueryDTOs);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("预警配置用户查询")
	@ApiOperation(value = "预警配置用户查询", notes = "预警配置用户查询")
	@PostMapping("/usersQuery")
	public RestMessage<List<SysAlertUsersQueryDTO>> listAlertUsersExecute(@RequestBody SysAlertUsersQueryVO sysAlertUsersQueryVO) {
		try {
			List<SysAlertUsersQueryDTO> sysAlertUsersQueryDTOs = sysAlertConfigurationService.listAlertUsersData(sysAlertUsersQueryVO);
			return RestMessage.newInstance(true, "查询成功", sysAlertUsersQueryDTOs);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("预警配置保存")
	@ApiOperation(value = "预警配置保存", notes = "预警配置保存")
	@PostMapping("/save")
	public RestMessage<String> saveAlertConfigurationExecute(@RequestBody SysAlertConfigurationSaveVO sysAlertConfigurationSaveVO) {
		try {
			sysAlertConfigurationService.saveAlertConfigurationData(sysAlertConfigurationSaveVO);
			return RestMessage.newInstance(true, "保存成功", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("预警配置修改")
	@ApiOperation(value = "预警配置修改", notes = "预警配置修改")
	@PostMapping("/update")
	public RestMessage<String> updateAlertConfigurationExecute(@RequestBody SysAlertConfigurationUpdateVO sysAlertConfigurationUpdateVO) {
		try {
			sysAlertConfigurationService.updateAlertConfigurationData(sysAlertConfigurationUpdateVO);
			return RestMessage.newInstance(true, "修改成功", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("预警配置删除")
	@ApiOperation(value = "预警配置删除", notes = "预警配置删除")
	@PostMapping("/delete")
	public RestMessage<String> deleteAlertConfigurationExecute(@RequestBody List<SysAlertConfigurationDeleteVO> sysAlertConfigurationDeleteVOs) {
		try {
			sysAlertConfigurationService.deleteAlertConfigurationData(sysAlertConfigurationDeleteVOs);
			return RestMessage.newInstance(true, "删除成功", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("预警配置用户删除")
	@ApiOperation(value = "预警配置用户删除", notes = "预警配置用户删除")
	@PostMapping("/usersDelete")
	public RestMessage<String> deleteAlertUsersExecute(@RequestBody List<SysAlertUsersDeleteVO> sysAlertUsersDeleteVOs) {
		try {
			sysAlertConfigurationService.deleteAlertUsersData(sysAlertUsersDeleteVOs);
			return RestMessage.newInstance(true, "删除成功", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

}
