package com.shanghaichengdi.ghjgitem.controller;

import com.alibaba.fastjson.JSONObject;
import com.shanghaichengdi.ghjgitem.constant.HttpStatus;
import com.shanghaichengdi.ghjgitem.domain.WaterTemporaryFlights;
import com.shanghaichengdi.ghjgitem.service.WaterPublicFlightsService;
import com.shanghaichengdi.ghjgitem.service.WaterSelfOperatedService;
import com.shanghaichengdi.ghjgitem.service.WaterTemporaryFlightsService;
import com.shanghaichengdi.ghjgitem.util.CommonTools;
import com.shanghaichengdi.ghjgitem.vo.ObjectBodyVo;
import com.shanghaichengdi.ghjgitem.vo.PageVo;
import com.shanghaichengdi.ghjgitem.vo.VwCertInfoSelfAllVo;
import com.shanghaichengdi.ghjgitem.vo.request.WaterExcursionReq;
import com.shanghaichengdi.ghjgitem.vo.response.*;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 智慧水运-浦江游览
 */
@RestController
@CrossOrigin
@RequestMapping("/waterTransport/excursion/")
public class PuJiangExcursionController extends CommonController{

  @Resource
  WaterTemporaryFlightsService waterTemporaryFlightsService;

  @Resource
  WaterPublicFlightsService waterPublicFlightsService;

  @Resource
  WaterSelfOperatedService waterSelfOperatedService;

  /**
   * 根据时间范围查询包船航班数据
   * @param vo
   * @return
   */
  @PostMapping("/waterTemporaryFlightList")
  public ReturnMsg waterTemporaryFlightList(@RequestBody @Validated ObjectBodyVo vo){
    if (!checkDbKey(vo.getKey())) {
      return ReturnMsg.error(HttpStatus.BAD_REQUEST, "key值有误,请确认您输入的key值正确!");
    }
    String paramJsonData = getParamJsonData(vo.getData());
    WaterExcursionReq req = JSONObject.parseObject(paramJsonData, WaterExcursionReq.class);
    List<WaterTemporaryFlightsRes> list = waterTemporaryFlightsService.getPageList(req);
    ResultRes resultRes = ResultRes.encapsulationResult(req.getPageIndex(),req.getPageSize(),
        CommonTools.getTotal(list),list);
    String jsonString = JSONObject.toJSONString(resultRes);
    String encodedData = resultEncode(jsonString);
    return ReturnMsg.success("获取成功", encodedData);
  }

  /**
   * 根据时间范围查询公共航班增量数据
   * @param vo
   * @return
   */
  @PostMapping("/waterPublicFlightList")
  public ReturnMsg waterPublicFlightList(@RequestBody @Validated ObjectBodyVo vo){
    if (!checkDbKey(vo.getKey())) {
      return ReturnMsg.error(HttpStatus.BAD_REQUEST, "key值有误,请确认您输入的key值正确!");
    }
    String paramJsonData = getParamJsonData(vo.getData());
    WaterExcursionReq req = JSONObject.parseObject(paramJsonData, WaterExcursionReq.class);
    List<WaterPublicFlightsRes> list = waterPublicFlightsService.getPageList(req);
    ResultRes resultRes = ResultRes.encapsulationResult(req.getPageIndex(),req.getPageSize(),
        CommonTools.getTotal(list),list);
    String jsonString = JSONObject.toJSONString(resultRes);
    String encodedData = resultEncode(jsonString);
    return ReturnMsg.success("获取成功", encodedData);
  }

  /**
   * 根据时间范围查询特色航班增量数据
   * @param vo
   * @return
   */
  @PostMapping("/waterFeatureFlightList")
  public ReturnMsg waterFeatureFlightList(@RequestBody @Validated ObjectBodyVo vo){
    if (!checkDbKey(vo.getKey())) {
      return ReturnMsg.error(HttpStatus.BAD_REQUEST, "key值有误,请确认您输入的key值正确!");
    }
    String paramJsonData = getParamJsonData(vo.getData());
    WaterExcursionReq req = JSONObject.parseObject(paramJsonData, WaterExcursionReq.class);
    List<WaterSelfOperatedRes> list = waterSelfOperatedService.getPageList(req);
    ResultRes resultRes = ResultRes.encapsulationResult(req.getPageIndex(),req.getPageSize(),
        CommonTools.getTotal(list),list);
    String jsonString = JSONObject.toJSONString(resultRes);
    String encodedData = resultEncode(jsonString);
    return ReturnMsg.success("获取成功", encodedData);
  }

}
