package com.tuoheng.admin.tzhl.service.airport;

import com.alibaba.fastjson.JSON;
import com.tuoheng.admin.tzhl.constant.TZHLConstant;
import com.tuoheng.admin.tzhl.response.TZHLAirportMsgResponse;
import com.tuoheng.admin.tzhl.service.CallTianYiPlatformService;
import com.tuoheng.common.core.utils.JsonResult;
import com.tuoheng.common.core.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 获取机场列表
 * @Author ChengWang
 * @Date 2023/8/9
 */
@Service
@Slf4j
public class TZHLGetAirportMsgService {

    @Autowired
    private CallTianYiPlatformService callTianYiPlatformService;

    public TZHLAirportMsgResponse getAirportMsg(String sn){

        JsonResult jsonResult = this.check(sn);
        if(jsonResult.getCode() != 0){
            return null;
        }
        //读取全量机场平台列表
        String param = "?sn=" +sn;
        String url = TZHLConstant.TIAN_YI_API_AIRPORT_MSG + param;

        String data = callTianYiPlatformService.callGet(url, null);
        TZHLAirportMsgResponse tzhlAirportMsgResponse = JSON.parseObject(data, TZHLAirportMsgResponse.class);

        return tzhlAirportMsgResponse;
    }

    private JsonResult check(String sn) {
        if(StringUtils.isEmpty(sn)){
            return JsonResult.error("机场方舱序列号为空");
        }

        return JsonResult.success();
    }


}
