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.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import com.unis.common.utils.ResponseWrapper;
import com.unis.detectionnum.common.vo.ScanRuleVO;
import com.unis.detectionnum.server.service.ScanRuleService;

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

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

	@Autowired
	private ScanRuleService scanRuleService;
	
	@ApiOperation(value = "参数管理->扫描参数管理【新增/修改】")
    @PostMapping(value = "/paramManage/scanRule")
    public ResponseWrapper saveOrUpdateScanRule(@RequestBody ScanRuleVO scanRuleVO){
    	
    	try {
    		if(scanRuleVO != null) {
    			scanRuleService.saveOrUpdateScanRule(scanRuleVO);
        		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/scanRule/info/{sbCode}")
    public ResponseWrapper getScanRuleInfo(@PathVariable("sbCode")String sbCode){
    	
    	try {
    		
    		ScanRuleVO scanRuleVO = scanRuleService.getScanRuleInfo(sbCode);
        	return ResponseWrapper.success(HttpStatus.OK.value(), HttpStatus.OK.getReasonPhrase(), scanRuleVO);	

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



	@ApiOperation(value = "参数管理->扫描参数管理->根据仓房编号查询(1.出入库0.库存)【查询】")
	@GetMapping(value = "/paramManage/scanRule/IsOut/{sbCode}")
	public ResponseWrapper getScanRuleIsOut(@PathVariable("sbCode")String sbCode){

		try {

			ScanRuleVO scanRuleVO = scanRuleService.getScanRuleIsOut(sbCode);
			return ResponseWrapper.success(HttpStatus.OK.value(), HttpStatus.OK.getReasonPhrase(), scanRuleVO);

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