/**   
 * @Title: ForwardController.java 
 * @Package com.unis.detectionnum.server.controller 
 * @Description: 前传规则
 * @author LiuFeng  
 * @date 2019年10月9日 下午4:01:09 
 * @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.github.pagehelper.PageInfo;
import com.unis.common.utils.ResponseWrapper;
import com.unis.detectionnum.common.vo.ForwardMainVO;
import com.unis.detectionnum.common.vo.ForwardPeopleVO;
import com.unis.detectionnum.server.service.ForwardService;

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

/** 
 * @ClassName: ForwardController 
 * @Description: 前传规则 Controller
 * @author LiuFeng 
 * @date 2019年10月9日 下午4:01:09  
 */

@RestController
@Slf4j
@Api(value = "前传规则管理", tags = "前传规则管理")
public class ForwardController {

	@Autowired
	private ForwardService forwardService;
	
	/**
	 * 添加前传规则信息
	 * @param forwardMainVO
	 * @return
	 */
	@ApiOperation(value = "前传规则->添加",notes = "参数：前传规则VO")
	@PostMapping(value = "/forward/main")
	public ResponseWrapper saveForwardMain(@RequestBody ForwardMainVO forwardMainVO){
		try {
			if(forwardMainVO != null) {
				String forwardNo = forwardService.saveForwardMain(forwardMainVO);
				return ResponseWrapper.success(HttpStatus.OK.value(), "保存成功", forwardNo);
			}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 = "/forward/main")
	public ResponseWrapper updateForwardMain(@RequestBody ForwardMainVO forwardMainVO){
		try {
			if(forwardMainVO != null) {
				forwardService.updateForwardMain(forwardMainVO);
				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 = "/forward/main/{forwardNo}")
	public ResponseWrapper deleteForwardMain(@PathVariable("forwardNo")String forwardNo){
		try {
			
			forwardService.deleteForwardMain(forwardNo);
			return ResponseWrapper.success(HttpStatus.OK.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")
	@PostMapping(value = "/forward/main/{pageNum}/{pageSize}")
	public ResponseWrapper AlarmGenerateMainPageList(
			@PathVariable("pageNum")Integer pageNum,
			@PathVariable("pageSize")Integer pageSize,
			@RequestBody ForwardMainVO forwardMainVO){
		try {
			PageInfo<ForwardMainVO> fPageInfo = forwardService.forwardMainPageList(pageNum,pageSize,forwardMainVO);
			return ResponseWrapper.success(HttpStatus.OK.value(), "查询成功", fPageInfo);
		} catch (Exception e) {
			log.error(e.getMessage());
			return ResponseWrapper.error(HttpStatus.INTERNAL_SERVER_ERROR.value(),"查询失败",null);
		}
	}
	
	/**
	 * 前传人员信息新增
	 * @param forwardPeopleVO
	 * @return
	 */
	@ApiOperation(value = "前传人员->添加",notes = "参数：前传人员信息VO")
	@PostMapping(value = "/forward/people")
	public ResponseWrapper saveForwardPeople(@RequestBody ForwardPeopleVO forwardPeopleVO){
		try {
			if(forwardPeopleVO != null) {
				String forwardPeopleNo = forwardService.saveForwardPeople(forwardPeopleVO);
				return ResponseWrapper.success(HttpStatus.OK.value(), "保存成功", forwardPeopleNo);
			}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 forwardPeopleVO
	 * @return
	 */
	@ApiOperation(value = "前传人员->修改",notes = "参数：前传人员信息VO")
	@PutMapping(value = "/forward/people")
	public ResponseWrapper updateForwardPeople(@RequestBody ForwardPeopleVO forwardPeopleVO){
		try {
			if(forwardPeopleVO != null) {
				forwardService.updateForwardPeople(forwardPeopleVO);
				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);
		}
	}
}
