package com.unis.base.server.controller;

import com.alibaba.fastjson.JSONObject;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
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.Page;
import com.github.pagehelper.PageInfo;
import com.unis.base.common.vo.DqyxxckVO;
import com.unis.base.server.service.DqyxxckService;
import com.unis.common.utils.ResponseWrapper;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * @author lidiaoquan
 * @version 1.0
 * @Title: DqyxxckController
 * @Description:储备粮企业信息查看
 * @date 2019年12月7日 下午5:01:48
 */
@RestController
@Api(value = "储备粮企业信息查看 ", tags = "储备粮企业信息查看")
@Log4j2
public class DqyxxckController {

	@Autowired
	private DqyxxckService dqyxxckService;

	@ApiOperation(value = "根据企业名称获取-仓房-相关企业列表【分页查询】", notes = "参数：企业名称")
	@PostMapping(value = "/getCfQyxxList/{pageNum}/{pageSize}")
	public ResponseWrapper getCfQyxxList(@PathVariable(value = "pageNum") Integer pageNum,
			@PathVariable(value = "pageSize") Integer pageSize, @RequestBody DqyxxckVO vo) {
		try {
			Page<DqyxxckVO> pageInfos =dqyxxckService.getCfQyxxList(vo, pageNum, pageSize);
			PageInfo<DqyxxckVO> page=new PageInfo<>(pageInfos);
            JSONObject data = JSONObject.parseObject(JSONObject.toJSONString(page));
            JSONObject dataTotal = dqyxxckService.getCfQyxxTotal(vo);
            data.put("dataTatal", dataTotal);
            return ResponseWrapper.success(HttpStatus.OK.value(), HttpStatus.OK.getReasonPhrase(), data);
		} catch (Exception e) {
            e.printStackTrace();
			log.error(e.getCause());
			return ResponseWrapper.error(HttpStatus.INTERNAL_SERVER_ERROR.value(),
					HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase(), "服务错误，请联系管理员");
		}
	}

	@ApiOperation(value = "根据企业名称获取-设备-相关企业列表【分页查询】", notes = "参数：企业名称")
	@PostMapping(value = "/getSbQyxxList/{pageNum}/{pageSize}")
	public ResponseWrapper getSbQyxxList(@PathVariable(value = "pageNum") Integer pageNum,
			@PathVariable(value = "pageSize") Integer pageSize, @RequestBody DqyxxckVO vo) {
		try {
			Page<DqyxxckVO> pageInfos =dqyxxckService.getSbQyxxList(vo, pageNum, pageSize);
			PageInfo<DqyxxckVO> page=new PageInfo<>(pageInfos);
			return ResponseWrapper.success(HttpStatus.OK.value(), HttpStatus.OK.getReasonPhrase(), page);
		} catch (Exception e) {
			log.error(e.getMessage());
			return ResponseWrapper.error(HttpStatus.INTERNAL_SERVER_ERROR.value(),
					HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase(), "服务错误，请联系管理员");
		}
	}

	@ApiOperation(value = "根据企业名称获取-药品-相关企业列表【分页查询】", notes = "参数：企业名称")
	@PostMapping(value = "/getYpQyxxList/{pageNum}/{pageSize}")
	public ResponseWrapper getYpQyxxList(@PathVariable(value = "pageNum") Integer pageNum,
			@PathVariable(value = "pageSize") Integer pageSize, @RequestBody DqyxxckVO vo) {
		try {
			Page<DqyxxckVO> pageInfos =dqyxxckService.getYpQyxxList(vo, pageNum, pageSize);
			PageInfo<DqyxxckVO> page=new PageInfo<>(pageInfos);
			return ResponseWrapper.success(HttpStatus.OK.value(), HttpStatus.OK.getReasonPhrase(), page);
		} catch (Exception e) {
			log.error(e.getMessage());
			return ResponseWrapper.error(HttpStatus.INTERNAL_SERVER_ERROR.value(),
					HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase(), "服务错误，请联系管理员");
		}
	}

	@ApiOperation(value = "根据企业名称获取-人员-相关企业列表【分页查询】", notes = "参数：企业名称")
	@PostMapping(value = "/getRyQyxxList/{pageNum}/{pageSize}")
	public ResponseWrapper getRyQyxxList(@PathVariable(value = "pageNum") Integer pageNum,
			@PathVariable(value = "pageSize") Integer pageSize, @RequestBody DqyxxckVO vo) {
		try {
			Page<DqyxxckVO> pageInfos =dqyxxckService.getRyQyxxList(vo, pageNum, pageSize);
			PageInfo<DqyxxckVO> page=new PageInfo<>(pageInfos);
            int personTotal = dqyxxckService.getRyTotal(vo);
            JSONObject object = JSONObject.parseObject(JSONObject.toJSONString(page));
            object.put("personTotal", personTotal);
            return ResponseWrapper.success(HttpStatus.OK.value(), HttpStatus.OK.getReasonPhrase(), object);
		} catch (Exception e) {
			log.error(e.getMessage());
			return ResponseWrapper.error(HttpStatus.INTERNAL_SERVER_ERROR.value(),
					HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase(), "服务错误，请联系管理员");
		}
	}
	@ApiOperation(value = "根据企业名称获取-油罐-相关企业列表【分页查询】", notes = "参数：企业名称")
	@PostMapping(value = "/getYgQyxxList/{pageNum}/{pageSize}")
	public ResponseWrapper getYgQyxxList(@PathVariable(value = "pageNum") Integer pageNum,
										 @PathVariable(value = "pageSize") Integer pageSize, @RequestBody DqyxxckVO vo) {
		try {
			Page<DqyxxckVO> pageInfos =dqyxxckService.getYgQyxxList(vo, pageNum, pageSize);
			PageInfo<DqyxxckVO> page=new PageInfo<>(pageInfos);
			return ResponseWrapper.success(HttpStatus.OK.value(), HttpStatus.OK.getReasonPhrase(), page);
		} catch (Exception e) {
			log.error(e.getMessage());
			return ResponseWrapper.error(HttpStatus.INTERNAL_SERVER_ERROR.value(),
					HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase(), "服务错误，请联系管理员");
		}
	}
}
