package com.unis.detectionnum.server.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageInfo;
import com.unis.common.utils.ResponseWrapper;
import com.unis.detectionnum.common.vo.AlarmGenerateMainVO;
import com.unis.detectionnum.server.service.AlarmGenerateService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

/** 
 * @ClassName: AlarmGenerateController 
 * @Description: 告警规则信息维护Controller 
 * @author LiuFeng 
 * @date 2019年9月28日 下午3:39:53  
 */
@RestController
@Slf4j
@Api(value = "告警规则管理", tags = "告警规则管理")
public class AlarmGenerateController {

	@Autowired
	private AlarmGenerateService alarmGenerateService;
	
	/**
	 * 添加告警规则信息
	 * @param alarmGenerateMainVO
	 * @return
	 */
	@ApiOperation(value = "告警规则->添加",notes = "参数：告警规则VO")
	@PostMapping(value = "/alarmgenerate/main")
	public ResponseWrapper saveAlarmGenerateMain(@RequestBody AlarmGenerateMainVO alarmGenerateMainVO){
		try {
			if(alarmGenerateMainVO != null) {
				String generateNo = alarmGenerateService.saveAlarmGenerateMain(alarmGenerateMainVO);
				return ResponseWrapper.success(HttpStatus.OK.value(), "告警规则信息保存成功", generateNo);
			}else {
				return ResponseWrapper.error(HttpStatus.INTERNAL_SERVER_ERROR.value(),"告警规则参数为空",null);
			}
			
		} catch (Exception e) {
			log.error(e.getMessage());
			return ResponseWrapper.error(HttpStatus.INTERNAL_SERVER_ERROR.value(),"操作失败",null);
		}
	}
	
	/**
	 * 修改告警规则信息
	 * @param alarmGenerateMainVO
	 * @return
	 */
	@ApiOperation(value = "告警规则->修改",notes = "参数：告警规则VO")
	@PutMapping(value = "/alarmgenerate/main")
	public ResponseWrapper updateAlarmGenerateMain(@RequestBody AlarmGenerateMainVO alarmGenerateMainVO){
		try {
			if(alarmGenerateMainVO != null) {
				alarmGenerateService.updateAlarmGenerateMain(alarmGenerateMainVO);
				return ResponseWrapper.success(HttpStatus.OK.value(), "告警规则信息修改成功", null);
			}else {
				return ResponseWrapper.error(HttpStatus.INTERNAL_SERVER_ERROR.value(),"告警规则参数为空",null);
			}
			
		} catch (Exception e) {
			log.error(e.getMessage());
			return ResponseWrapper.error(HttpStatus.INTERNAL_SERVER_ERROR.value(),"修改失败",null);
		}
	}
	
	/**
	 * 根据告警规则编号删除
	 * @param alarmGenerateMainVO
	 * @return
	 */
	@ApiOperation(value = "告警规则->根据告警规则编号删除",notes = "参数：告警规则编号")
	@GetMapping(value = "/alarmgenerate/main/{generateNo}")
	public ResponseWrapper deleteAlarmGenerateMain(@PathVariable("generateNo")String generateNo){
		try {
			
			alarmGenerateService.deleteAlarmGenerateMain(generateNo);
			return ResponseWrapper.success(HttpStatus.OK.value(), "告警规则信息删除成功", generateNo);
		} catch (Exception e) {
			log.error(e.getMessage());
			return ResponseWrapper.error(HttpStatus.INTERNAL_SERVER_ERROR.value(),"修改失败",null);
		}
	}
	
	/**
	 * 分页查询告警规则信息列表
	 * @param alarmGenerateMainVO
	 * @return
	 */
	@ApiOperation(value = "告警规则->列表分页查询",notes = "参数：告警规则编号")
	@PostMapping(value = "/alarmgenerate/main/{pageNum}/{pageSize}")
	public ResponseWrapper AlarmGenerateMainPageList(
			@PathVariable("pageNum")Integer pageNum,
			@PathVariable("pageSize")Integer pageSize,
			@RequestBody AlarmGenerateMainVO alarmGenerateMainVO){
		try {
			PageInfo<AlarmGenerateMainVO> aPageInfo = alarmGenerateService.alarmGenerateMainPageList(pageNum,pageSize,alarmGenerateMainVO);
			return ResponseWrapper.success(HttpStatus.OK.value(), "查询成功", aPageInfo);
		} catch (Exception e) {
			log.error(e.getMessage());
			return ResponseWrapper.error(HttpStatus.INTERNAL_SERVER_ERROR.value(),"查询失败",null);
		}
	}
}
