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.TyXzzyxxHisQueryVO;
import com.unis.base.common.vo.TyXzzyxxHisVO;
import com.unis.base.server.service.TyXzzyxxHisService;
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日 下午6:09:33
 * @description Fumigation 熏蒸作业历史纪录
 */
@RestController
@Api(value = "熏蒸作业信息历史记录 ", tags = "熏蒸作业信息历史记录 维护")
@Slf4j
public class FumigationHisController {
	@Autowired
	private TyXzzyxxHisService tyXzzyxxHisService;
	@ApiOperation(value = "熏蒸作业信息历史记录列表 根据条件【分页查询】",notes = "参数：方案编号/作业单编号")
	@PostMapping(value = "/fumigationHisPageList/{pageNum}/{pageSize}")
	public ResponseWrapper getTfzyxxHisList(@PathVariable(value = "pageNum") Integer pageNum,
			  @PathVariable(value = "pageSize") Integer pageSize,@RequestBody TyXzzyxxHisQueryVO tyXzzyxxHisQueryVO){
		try {
			PageInfo<TyXzzyxxHisVO> pageInfos = tyXzzyxxHisService.getTyXzzyxxHisList(tyXzzyxxHisQueryVO,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 = "/fumigationHisInfo/{lsId}")
	public ResponseWrapper getFumigationHisInfoByLsId(@PathVariable("lsId")String lsId) {
		try {
			TyXzzyxxHisVO fumigationHisVO=tyXzzyxxHisService.getTyXzzyxxHisInfoByLsId(lsId);
			if(fumigationHisVO == null) {
				return ResponseWrapper.success(HttpStatus.BAD_REQUEST.value(), "获取失败", null);
			}
            return ResponseWrapper.success(HttpStatus.OK.value(), HttpStatus.OK.getReasonPhrase(), fumigationHisVO);
        } 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 = "/fumigationHisInfoSave")
    public ResponseWrapper insert(@RequestBody TyXzzyxxHisVO tyXzzyxxHisVO) {
		try{
			if(tyXzzyxxHisVO.getSfba()==null) {
				return ResponseWrapper.success(HttpStatus.BAD_REQUEST.value(), "有必传参数为空", null);
			}
			int vo = tyXzzyxxHisService.insert(tyXzzyxxHisVO);
			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(),"服务错误，请联系管理员");
	}
}
