package com.unis.base.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.github.pagehelper.PageInfo;
import com.unis.base.common.vo.TyTfzyxxHisQueryVO;
import com.unis.base.common.vo.TyTfzyxxHisVO;
import com.unis.base.server.service.TyTfzyxxHisService;
import com.unis.common.utils.ResponseWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

/**
 * @author 张琪
 * @date 2019年9月16日 下午2:33:33
 * @description
 */
@RestController
@Api(value = "通风作业信息历史记录 ", tags = "通风作业信息历史记录 维护")
@Slf4j
public class AerationHisController {
	@Autowired
	private TyTfzyxxHisService tyTfzyxxHisService;
	@ApiOperation(value = "通风作业信息历史记录列表 根据条件【分页查询】",notes = "参数：方案编号/作业单编号")
	@PostMapping(value = "/aerationHisPageList/{pageNum}/{pageSize}")
	public ResponseWrapper getTfzyxxHisList(@PathVariable(value = "pageNum") Integer pageNum,
			  @PathVariable(value = "pageSize") Integer pageSize,@RequestBody TyTfzyxxHisQueryVO tyTfzyxxHisQueryVO){
		try {
			PageInfo<TyTfzyxxHisVO> pageInfos = tyTfzyxxHisService.getTfzyxxHisList(tyTfzyxxHisQueryVO,pageNum,pageSize);
			return ResponseWrapper.success(HttpStatus.OK.value(), HttpStatus.OK.getReasonPhrase(), pageInfos);
		} catch (Exception e) {
			log.error(e.getMessage());
			return ResponseWrapper.error(HttpStatus.INTERNAL_SERVER_ERROR.value(), HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase(),"服务错误，请联系管理员");
		}
	}

	/**
	 * @author 张琪
	 * @Description 根据主键ID获取通风作业历史信息
	 * @return 通风作业信息
	 */
	@ApiOperation(value = "根据主键编码获取通风作业历史信息", notes = "参数：主键ID")
	@GetMapping(value = "/aerationHisInfo/{lsId}")
	public ResponseWrapper getAerationHisInfoByLsId(@PathVariable("lsId")String lsId) {
		try {
			TyTfzyxxHisVO aerationHisVO=tyTfzyxxHisService.getAerationHisInfoByLsId(lsId);
			if(aerationHisVO == null) {
				return ResponseWrapper.success(HttpStatus.BAD_REQUEST.value(), "获取失败", null);
			}
            return ResponseWrapper.success(HttpStatus.OK.value(), HttpStatus.OK.getReasonPhrase(), aerationHisVO);
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage());
        }
        return ResponseWrapper.error(HttpStatus.INTERNAL_SERVER_ERROR.value(), HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase(),"服务错误，请联系管理员");
	}

	/**
	 * @author 张琪
	 * @Description 新增通风作业信息
	 * @param 通风作业信息对象 models
	 * @return 新增状态
	 */
	@ApiOperation(value = "新增通风作业信息", notes = "参数：备案类型【0_未备案，1_待提交，2_待审核，3_已驳回，4_已备案】")
	@PostMapping(value = "/aerationHisInfoSave")
    public ResponseWrapper insert(@RequestBody TyTfzyxxHisVO tyTfzyxxHisVO) {
		try{
			if(tyTfzyxxHisVO.getSfba()==null) {
				return ResponseWrapper.success(HttpStatus.BAD_REQUEST.value(), "有必传参数为空", null);
			}
			int vo = tyTfzyxxHisService.insert(tyTfzyxxHisVO);
			if(vo!=0) {
	            return ResponseWrapper.success(HttpStatus.OK.value(), HttpStatus.OK.getReasonPhrase(),vo);
			} else {
	            return ResponseWrapper.success(HttpStatus.BAD_REQUEST.value(), "添加失败", null);
			}
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage());
        }
        return ResponseWrapper.error(HttpStatus.INTERNAL_SERVER_ERROR.value(), HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase(),"服务错误，请联系管理员");
	}

}

