/**   
 * @Title: AlarmParamController.java 
 * @Package com.unis.detectionnum.server.controller 
 * @Description: 参数管理-告警参数信息维护
 * @author LiuFeng  
 * @date 2019年10月16日 下午4:55:23 
 * @version V1.0   
 */
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.unis.common.utils.ResponseWrapper;
import com.unis.detectionnum.common.vo.AlarmParamVO;
import com.unis.detectionnum.server.service.AlarmParamService;

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

/** 
 * @ClassName: AlarmParamController 
 * @Description: 参数管理-告警参数信息维护 
 * @author LiuFeng 
 * @date 2019年10月16日 下午4:55:23  
 */
@RestController
@Slf4j
@Api(value = "参数管理-报警参数信息管理", tags = "参数管理-报警参数信息管理")
public class AlarmParamController {

	@Autowired
	private AlarmParamService alarmParamService;
	
	/*@ApiOperation(value = "参数管理->告警参数管理【新增】")
    @PostMapping(value = "/paramManage/alarm")
    public ResponseWrapper saveAlarmParam(@RequestBody AlarmParamVO alarmParamVO){
    	
    	try {
    		if(alarmParamVO != null) {
    			alarmParamService.saveAlarmParam(alarmParamVO);
        		return ResponseWrapper.success(HttpStatus.OK.value(), HttpStatus.OK.getReasonPhrase(), null);	
    		}
    		
		} catch (Exception e) {
			e.printStackTrace();
			log.error(e.getMessage());
		}
		return ResponseWrapper.error(HttpStatus.INTERNAL_SERVER_ERROR.value(), HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase(),"服务错误，请联系管理员");
    }*/

	@ApiOperation(value = "参数管理->告警参数管理【修改】")
	@PutMapping(value = "/paramManage/alarm")
	public ResponseWrapper updateAlarmParam(@RequestBody AlarmParamVO alarmParamVO) {

		try {
			if (alarmParamVO.getCfbh() == null) {
				return ResponseWrapper.error(HttpStatus.INTERNAL_SERVER_ERROR.value(), HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase(), "仓房编码不能为空，请选中左侧仓房");
			}
			if (alarmParamVO.getId() != null) {
				alarmParamService.updateAlarmParam(alarmParamVO);
			} else {
				alarmParamService.saveAlarmParam(alarmParamVO);
			}
			return ResponseWrapper.success(HttpStatus.OK.value(), HttpStatus.OK.getReasonPhrase(), null);

		} catch (Exception e) {
			e.printStackTrace();
			log.error(e.getMessage());
		}
		return ResponseWrapper.error(HttpStatus.INTERNAL_SERVER_ERROR.value(), HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase(), "服务错误，请联系管理员");
	}
	
	@ApiOperation(value = "参数管理->告警参数管理->根据仓房编号查询告警信息【查询】")
    @GetMapping(value = "/paramManage/alarm/info/{cfbh}")
    public ResponseWrapper getAlarmParamInfo(@PathVariable("cfbh")String cfbh){
    	
    	try {
    		
    		AlarmParamVO alarmParamVO = alarmParamService.getAlarmParamByCfbh(cfbh);
        	return ResponseWrapper.success(HttpStatus.OK.value(), HttpStatus.OK.getReasonPhrase(), alarmParamVO);	

		} catch (Exception e) {
			e.printStackTrace();
			log.error(e.getMessage());
		}
		return ResponseWrapper.error(HttpStatus.INTERNAL_SERVER_ERROR.value(), HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase(),"服务错误，请联系管理员");
    }
}
