`
niuge
  • 浏览: 8493 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
文章分类
社区版块
存档分类
最新评论

多线程查询

 
阅读更多

public class IapSearchAirInfoServiceImpl implements IapSearchAirInfoService {

 

    private final Logger logger = LoggerFactory.getLogger(IapSearchAirInfoServiceImpl.class);

 

    @Inject

    private IapServiceCenter iapServiceCenter;

 

    @Inject

    private IapDataCenter iapDataCenter;

 

    @Inject

    @ServiceLocator(SvrTypeConstants.ST_OSGI)

    private ZasServiceCenter zasServiceCenter;

 

    @Inject

    @ServiceLocator(SvrTypeConstants.ST_OSGI)

    BusinessClientInvoker invoker;

 

    private final static String TARGET_CLENT_CLASS = "com.zte.intairsp.home.business.BusinessCenter4IntairSpThr";

 

    private static final String YYYY_MM_DD = "yyyy-MM-dd";

 

    /**

     * 查询客规

     * 

     * @param context

     * @param param

     * @return

     * @throws Exception

     */

    @Override

    public IntAirFlightBean findNtAirInfoRule(ContextInfo context, IntAirFlightBean param) throws Exception {

        if (IapConstants.FREIGHT_SOURCE_STANDARD.equals(param.getFreightSource())

                || IapConstants.FREIGHT_SOURCE_DISCOUNT.equals(param.getFreightSource())) {

           //运价库客规

           return this.getFreightPolicy(context, param);            

            }

        if (IapConstants.FREIGHT_SOURCE_AIR86.equals(param.getFreightSource())) {

            return param;

        }

        // 如果客规已存在,多程直接返回,不是FD和FQSBB直接返回----这段逻辑已经不需要了,以后考虑去掉

        /*if (BusinessUtils.isNotNull(param.getBackPolicy())

                && !IapConstants.FREIGHT_SOURCE_ASLAN.equals(param.getFreightSource())

                && !IapConstants.FREIGHT_SOURCE_ESPEED.equals(param.getFreightSource())) {

            if (IapConstants.FLIGHT_TYPE_MULTIPLE.equals(param.getFlightType())) {

                return param;

            } else if (!IapConstants.FREIGHT_SOURCE_FD.equals(param.getFreightSource())

                    || !IapConstants.FREIGHT_SOURCE_FQSBB.equals(param.getFreightSource())) {

                try {

                    Thread.sleep(500L);

                } catch (RuntimeException e) {

                    logger.error("取客规错误", e);

                }

                return param;

            }

            // 如果单程

            else if (IapConstants.FLIGHT_TYPE_SINGLE.equals(param.getFlightType())) {

                try {

                    Thread.sleep(500L);

                } catch (RuntimeException e) {

                    logger.error("取客规错误", e);

                }

                return param;

            }

        }*/

        // FD运价

        if (IapConstants.FREIGHT_SOURCE_FD.equals(param.getFreightSource())) {

            // 单程和往返重新取rulesXml 和 bagsXml

                List<IntAirFlightBean> airFlights = new ArrayList<IntAirFlightBean>();

                airFlights.add(param);

            // FD 取第一个返程航班客规

                if (IapConstants.FLIGHT_TYPE_RETURN.equals(param.getFlightType()) && param.getReturnFlights() != null

                    && param.getReturnFlights().size() > 0) {

                    airFlights.add(param.getReturnFlights().get(0));

                }

                HashMap<String, List<String>> ruleMap = iapServiceCenter.getIapVendorInfService().findFSRulesXml(

                        context, airFlights);

                List<String> rulesXml = ruleMap.get("RULES");

                List<String> bagsXml = ruleMap.get("BAGS");

                param.setRulesXml(rulesXml);

                param.setBagXml(bagsXml);

                if (param.getReturnFlights() != null && !param.getReturnFlights().isEmpty()) {

                    param.getReturnFlights().get(0).setRulesXml(rulesXml);

                    param.getReturnFlights().get(0).setBagXml(bagsXml);

                }

            }

        // FQSBB、FQSBB_PF 取第一个返程航班客规,原因:GWS按返程查客规,其他GDS按往返程查客规

        if (IapConstants.FREIGHT_SOURCE_FQSBB.equals(param.getFreightSource())

                || IapConstants.FREIGHT_SOURCE_FQSBB_PF.equals(param.getFreightSource())){

        if (IapConstants.FLIGHT_TYPE_RETURN.equals(param.getFlightType()) && param.getReturnFlights() != null

                    && param.getReturnFlights().size() > 0) {

            param = param.getReturnFlights().get(0);

        }

        }

        // ESPEED按每一程查,去程查去程,返程查返程

        if (IapConstants.FREIGHT_SOURCE_ESPEED.equals(param.getFreightSource()) && "2".equals(param.getRuleIndex())){

            if (IapConstants.FLIGHT_TYPE_RETURN.equals(param.getFlightType()) && param.getReturnFlights() != null

                    && param.getReturnFlights().size() == 1) {

                param = param.getReturnFlights().get(0);

            }

        }

        // AMADEUS往返一起

        // ASLAN运价

        /*if (IapConstants.FREIGHT_SOURCE_ASLAN.equals(param.getFreightSource())) {

            param.setVendorCode(IapConstants.VENDOR_CODE_ASLAN);

        }*/

        IntAirFlightBean rt = iapServiceCenter.getIapVendorInfService().findNtAirInfoRule(context, param);

        if (rt == null) {

            return param;

        }

        if (IapConstants.FREIGHT_SOURCE_ASLAN.equals(param.getFreightSource())) {

            try {

                Thread.sleep(500L);

            } catch (RuntimeException e) {

                logger.error("取ASLAN运价库客规休眠500毫秒错误", e);

            }

        }

        return rt;

    }

 

    private IntAirFlightBean getFreightPolicy(ContextInfo context, IntAirFlightBean param) throws Exception {

        Long freightItemId = param.getFreightInfo().getFreightItemId();

        if (freightItemId == null) {

            logger.error("国际机票错误IapSearchAirInfoServiceImpl,但是freighItemId为空!freightItemId=" + freightItemId);

            return param;

        }

        IapFreightItem item = iapDataCenter.getIapFreightItemDao().getById(freightItemId);

        if (item == null || !"Y".equals(item.getEnabledFlag())) {

            logger.error("国际机票错误IapSearchAirInfoServiceImpl,无法找到运价条目!freighItemId=" + freightItemId);

            return param;

        }

        IapFreight freight = iapDataCenter.getIapFreightDao().getById(item.getFreightId());

        if (freight == null || !"Y".equals(freight.getEnabledFlag())) {

            logger.error("国际机票错误IapSearchAirInfoServiceImpl,无法找到运价!FreightId=" + item.getFreightId());

            return param;

        }

        IapFreightItemPolicy policy = getFreightItemPolicy(context, freightItemId);

        // 适用基础客规

        if ("Y".equals(item.getGdsPolicyFlag())) {

            // 往返程的返程

            if (IapConstants.FLIGHT_TYPE_RETURN.equals(param.getFlightType()) && param.getReturnFlights() != null

                    && param.getReturnFlights().size() == 1) {

                param = param.getReturnFlights().get(0);

            }

            String vendorCode = this.getVendorCodeFromGds(param.getGds());

            param.setVendorCode(vendorCode);

            IntAirFlightBean rt = iapServiceCenter.getIapVendorInfService().findNtAirInfoRule(context, param);

            this.setFreightPolicyToAirInfo(item, policy, rt, false);

            return rt;

        } else {

            this.setFreightPolicyToAirInfo(item, policy, param, true);

            return param;

        }

    }

    

    private String getVendorCodeFromGds(String gds) {

        String vendorCode = null;

        if (IapConstants.BOOK_SYSTEM_1E.equals(gds)) {

            vendorCode = IapConstants.VENDOR_CODE_ESPEED;

        } else if (IapConstants.BOOK_SYSTEM_1G.equals(gds)) {

            vendorCode = IapConstants.VENDOR_CODE_GWS;

        } else if (IapConstants.BOOK_SYSTEM_1A.equals(gds)) {

            vendorCode = IapConstants.VENDOR_CODE_AMADEUS;

        }else {

            return "";

        }

        return vendorCode;

    }

 

    private IapFreightItemPolicy getFreightItemPolicy(ContextInfo context, Long itemId) {

        String lanugage = IapConstants.LANGUAGE_SIMPLIFIED;// 默认简体中文

        if (!StringU.isEmpty(context.getLanuage())) {

            if (!context.getLanuage().equals(LanguageUtil.ZHS)) {

                lanugage = IapConstants.LANGUAGE_ENGLISH;

            }

        }

        IapFreightItemPolicy policys = iapDataCenter.getIapFreightItemPolicyDao().findPolicyByItemId(lanugage, itemId);

        return policys;

    }

    

    private String getBagPolicy(IapFreightItemPolicy policy, String infBagPolicy, boolean force) {

        String baggageType = policy.getBaggageType();

        StringBuilder bagPolicy = new StringBuilder();        

        // 按GDS客规来订是按件还是按重量

        if (!StringU.isEmpty(infBagPolicy) && infBagPolicy.contains("PC") && !force) { // updated by xxh 2014-04-14 add "&& !force" 标准运价不关注GDS,直接取录入值

            baggageType = IapConstants.BAGGAGE_TYPE_1001;

        }

        if (IapConstants.BAGGAGE_TYPE_1001.equals(baggageType)) {

            if (!StringU.isEmpty(policy.getBaggageQuantity())) {

                bagPolicy.append(policy.getBaggageQuantity()).append("PC");

            }

            if (!StringU.isEmpty(policy.getBaggageWeight())) {

                if (bagPolicy.length() > 0) {

                    bagPolicy.append(",");

                }

                bagPolicy.append("每件最大重量").append(policy.getBaggageWeight()).append("KG");

            }

            //适用GDS客规,并且没有维护基本的行李

            if(bagPolicy.length() == 0 && !force){

                bagPolicy.append(infBagPolicy);

            }

            if (!StringU.isEmpty(policy.getExtraBaggageQuantity()) && !StringU.isEmpty(policy.getExtraBaggageWeight())) {

                if (bagPolicy.length() > 0) {

                    bagPolicy.append(",");

                }

                bagPolicy.append("额外允许行李");

            }

            if (!StringU.isEmpty(policy.getExtraBaggageQuantity())) {

                bagPolicy.append(policy.getExtraBaggageQuantity()).append("PC");

            }

            if (!StringU.isEmpty(policy.getExtraBaggageWeight())) {

                if (bagPolicy.length() > 0) {

                    bagPolicy.append(",");

                }

                bagPolicy.append("每件最大重量").append(policy.getExtraBaggageWeight()).append("KG");

            }

        } else {

            if (!StringU.isEmpty(policy.getBaggageWeight2())) {

                bagPolicy.append(policy.getBaggageWeight2()).append("KG");

            }

            //适用GDS客规,并且没有维护基本的行李

            if(bagPolicy.length() == 0 && !force){

                bagPolicy.append(infBagPolicy);

            }

            if (!StringU.isEmpty(policy.getExtraBaggageWeight2())) {

                if (bagPolicy.length() > 0) {

                    bagPolicy.append(",");

                }

                bagPolicy.append("额外允许行李,最大重量").append(policy.getExtraBaggageWeight2()).append("KG");

            }

        }

        return bagPolicy.toString();

    }

    

    //设值接口客规

    private void setFreightPolicyToAirInfo(IapFreightItem item, IapFreightItemPolicy policy, IntAirFlightBean airInf,

            boolean force) {

        airInf.setBackPolicy(this.getPolicyStr(policy.getBackPolicy(), airInf.getBackPolicy(), force));

        airInf.setChangePolicy(this.getPolicyStr(policy.getChangePolicy(), airInf.getChangePolicy(), force));

        airInf.setSignPolicy(this.getPolicyStr(policy.getSignPolicy(), airInf.getSignPolicy(), force));

        airInf.setNoShow(this.getPolicyStr(policy.getNoShowPolicy(), airInf.getNoShow(), force));

        //最短停留

        airInf.setMinStay(this.getPolicyStr(

                this.getFreightStayTime(item.getValidPeriodStart(), item.getValidPeriodStartUnit()),

                airInf.getMinStay(), force));

        //最长停留

        airInf.setMaxStay(this.getPolicyStr(

                this.getFreightStayTime(item.getValidPeriodEnd(), item.getValidPeriodEndUnit()), airInf.getMaxStay(),

                force));

        airInf.setRemarks(policy.getRemarks() == null ? "" : policy.getRemarks());

        airInf.setBagPolicy(this.getBagPolicy(policy, airInf.getBagPolicy(), force));

    }

    

    private String getFreightStayTime(Long staty, String unit) {

        if (staty == null || StringU.isEmpty(unit)) {

            return "";

        }

        return staty + this.getUnitShow(unit);

    }

 

    private String getUnitShow(String str) {

        if (IapConstants.IAP_VALID_PERIOD_UNIT_DAY.equals(str)) {

            return "天";

        } else if (IapConstants.IAP_VALID_PERIOD_UNIT_MONTH.equals(str)) {

            return "月";

        } else if (IapConstants.IAP_VALID_PERIOD_UNIT_YEAR.equals(str)) {

            return "年";

        }

        return "";

    }

 

    private String getPolicyStr(String freightPolicy, String infPolicy, boolean force) {

        if (!force && StringU.isEmpty(freightPolicy)) {

            return infPolicy == null ? "" : infPolicy;

        }

        return freightPolicy == null ? "" : freightPolicy;

    }

 

    /**

     * 通过接口获取税金

     * 

     * @param o

     * @param airInfoBean

     * @return

     * @throws Exception

     */

    public String getTax(ContextInfo context, IntAirInfoBean airInfoBean) throws Exception {

        IntAirFlightBean goFlight = airInfoBean.getGoFlight();

        List<IntAirFlightBean> returnFlights = airInfoBean.getReturnFlights();

        String freightSource = goFlight.getFreightSource();

        if (IapConstants.FREIGHT_SOURCE_FQSBB.equals(freightSource)

                || IapConstants.FREIGHT_SOURCE_FD.equals(freightSource)

                || IapConstants.FREIGHT_SOURCE_STANDARD.equals(freightSource)

                || IapConstants.FREIGHT_SOURCE_DISCOUNT.equals(freightSource)

                || IapConstants.FREIGHT_SOURCE_AIR86.equals(freightSource)) {

            List<IntAirFlightBean> airFlights = new ArrayList<IntAirFlightBean>();

            if (airInfoBean != null) {

                airFlights.add(goFlight);

                if (returnFlights != null && !returnFlights.isEmpty()) {

                    airFlights.add(returnFlights.get(0));

                    IapQueryAirInfoBean param = new IapQueryAirInfoBean();

                    param.setDeparture(goFlight.getAirPassage().get(0).getDeparture());

                    param.setArrival(goFlight.getAirPassage().get(goFlight.getAirPassage().size() - 1).getArrival());

                    param.setDepartureDate(goFlight.getAirPassage().get(0).getTakeoffDate());

                    CommonResult result = this.getFareInfoWhenBook(context, param, airFlights, null);

                    if (CommonResult.SUCCESS.equals(result.getResult())) {

                        if (result.getRtnMap() != null) {

                            double tax = 0d;

                                tax = Double.valueOf(result.getRtnMap().get("Tax"));

                                return String.valueOf(tax);

                            }

                        }

                    }

                }

            }

        /*if (IapConstants.FREIGHT_SOURCE_AIR86.equals(freightSource)) {

            String tax = iapServiceCenter.getIapVendorInfService().getTax(context, airInfoBean);

            return tax;

        }*/

        return goFlight.getTax();

    }

 

    /**

     * 查询国际航班接口

     * 

     * @param context

     * @param param

     * @return

     * @throws Exception

     */

    @Override

    public List<IntAirInfoBean> findIntAirInfo(ContextInfo context, IapQueryAirInfoBean param) throws Exception {

        if ("yyyy-mm-dd".equals(param.getReturnDate())){

            param.setReturnDate("");

        }

        long startTime1 = new Date().getTime();

        List<IntAirInfoBean> dataListAll = new ArrayList<IntAirInfoBean>();

        // 取接口供应商。取不到返回空列表

        String vendorCode = IapConstants.VENDOR_CODE_GWS;

        param.setVendorCode(vendorCode); // 供应商设置

        String inlandFlag = iapServiceCenter.getIapCommonService().getInlandFlag(param);

        QueryAirInfoThread fareGoThread = null;

        QueryAirInfoThread espeedThread = null;

        QueryAirInfoThread gwsThread = null;

        QueryAirInfoThread gwsSotoThread = null;

        QueryAirInfoThread amadeusThread = null;

        QueryAirInfoThread air86Thread = null;

        

        // 取出发到达地区。

        String fromCountryCode = iapServiceCenter.getIapCommonService().getCountryFromCityCode(param.getDeparture());

        String toCountryCode = iapServiceCenter.getIapCommonService().getCountryFromCityCode(param.getArrival());

        if (NullU.isNotNull(fromCountryCode)) {

            param.setDepartureArea(fromCountryCode);

        }

        if (NullU.isNotNull(toCountryCode)) {

            param.setArrivalArea(toCountryCode);

        }

        Long managementBodyId = context.getManagementBodyId();

        List<IapConfig> iapConfigs = iapServiceCenter.getIapConfigService().findIapConfigsFromCache();

        HashMap<String, String> configs = new HashMap<String, String>();

        if (NullU.isNotNull(iapConfigs)){

            for (IapConfig iapConfig : iapConfigs){

                configs.put(iapConfig.getManagementBodyId() + iapConfig.getQuery(), iapConfig.getStatus());

            }

        }

        

        // 取GDS配置

        String gds = getGdsFlag(param);

 

        // 后返处理标识

        FbpConfig commissionConfig = zasServiceCenter.getSysConfigService().findFbpConfigFromCache(

                IapConstants.INTAIR_MANAGEMENT_COMMISSION);

        if (NullU.isNull(inlandFlag)){

            vendorCode = null;

        } else if (IapConstants.INLAND_FLAG_I.equals(inlandFlag)) {

            FbpConfig config = zasServiceCenter.getSysConfigService().findFbpConfigFromCache(

                    IapConstants.INTAIR_DOM_FARE_CONFIG);

            if (config != null && NullU.isNotNull(config.getConfigValue())){

                if (config.getConfigValue().contains(IapConstants.FREIGHT_SOURCE_FAREGO) 

                        && !"N".equals(configs.get(managementBodyId + IapConstants.FREIGHT_SOURCE_FAREGO))) {

                    FbpConfig c = zasServiceCenter.getSysConfigService().findFbpConfigFromCache(

                            IapConstants.TENANT_FAREGO_CONFIG);

                    if (c != null && NullU.isNotNull(c.getConfigValue())){

                        Long tenantId = context.getTenantId();

                        String tenant = tenantId == null? "" : tenantId.toString();

                        if (NullU.isNotNull(tenant)){

                            if (!tenant.equals(c.getConfigValue()) && !c.getConfigValue().contains(tenant + ",")

                                    && !c.getConfigValue().contains("," + tenant)){

                                vendorCode = IapConstants.VENDOR_CODE_FAREGO;

                                param.setVendorCode(vendorCode);

                                fareGoThread = new QueryAirInfoThread(context, param, vendorCode);

                                fareGoThread.start();

                            }

                        }

                    } else {

                        vendorCode = IapConstants.VENDOR_CODE_FAREGO;

                        param.setVendorCode(vendorCode);

                        fareGoThread = new QueryAirInfoThread(context, param, vendorCode);

                        fareGoThread.start();

                    }

                }

                if (config.getConfigValue().contains(IapConstants.FREIGHT_SOURCE_ESPEED)

                        && !"N".equals(configs.get(managementBodyId + IapConstants.FREIGHT_SOURCE_ESPEED))) {

                    vendorCode = IapConstants.VENDOR_CODE_ESPEED;

                    param.setVendorCode(vendorCode);

                    espeedThread = new QueryAirInfoThread(context, param, vendorCode);

                    espeedThread.start();

                }

                if (config.getConfigValue().contains(IapConstants.FREIGHT_SOURCE_AIR86)

                        && !"N".equals(configs.get(managementBodyId + IapConstants.FREIGHT_SOURCE_AIR86))) {

                    vendorCode = IapConstants.VENDOR_CODE_AIR86;

                    param.setVendorCode(vendorCode);

                    air86Thread = new QueryAirInfoThread(context, param, vendorCode);

                    air86Thread.start();

            }

            }

        } else if (IapConstants.INLAND_FLAG_O.equals(inlandFlag)) {

            FbpConfig config = zasServiceCenter.getSysConfigService().findFbpConfigFromCache(

                    IapConstants.INTAIR_INT_FARE_CONFIG);

            if (config != null && NullU.isNotNull(config.getConfigValue())){

                if (config.getConfigValue().contains(IapConstants.FREIGHT_SOURCE_AMADEUSSHOPPING)

                        && IapConstants.BOOK_SYSTEM_1A.equals(gds)

                        && !"N".equals(configs.get(managementBodyId + IapConstants.FREIGHT_SOURCE_AMADEUSSHOPPING))) {

                    vendorCode = IapConstants.VENDOR_CODE_AMADEUS;

                    param.setVendorCode(vendorCode);

                    amadeusThread = new QueryAirInfoThread(context, param, vendorCode);

                    amadeusThread.start();

                }

                else if (config.getConfigValue().contains(IapConstants.FREIGHT_SOURCE_FQSBB)

                        && !"N".equals(configs.get(managementBodyId + IapConstants.FREIGHT_SOURCE_FQSBB))) {

                    if (config.getConfigValue().contains(IapConstants.FREIGHT_SOURCE_FQSBB_PF)

                            && !"N".equals(configs.get(managementBodyId + IapConstants.FREIGHT_SOURCE_FQSBB_PF))){

                        param.setPrivateFaresFlag(IapConstants.FREIGHT_SOURCE_FQSBB_PF);

                    }

                    vendorCode = IapConstants.VENDOR_CODE_GWS;

                    param.setVendorCode(vendorCode);

                    gwsThread = new QueryAirInfoThread(context, param, vendorCode);

                    gwsThread.start();

                }

            }

            // SOTO票查询

            if (config != null && NullU.isNotNull(config.getConfigValue())){

                if (config.getConfigValue().contains(IapConstants.FREIGHT_SOURCE_SOTO)

                        && !"N".equals(configs.get(managementBodyId + IapConstants.FREIGHT_SOURCE_SOTO))) {

                    if (IapConstants.SINGLE.equals(param.getFlightType())) {

                        // 默认两天

                        int returnDay = 2;

                        // 如果配置不为空并且是正整数,则取配置信息

                        if (NullU.isNotNull(config.getAttribute1()) && ValidationUtil.isNumber3(config.getAttribute1())){

                            returnDay = Integer.valueOf(config.getAttribute1());

        }

                        vendorCode = IapConstants.VENDOR_CODE_GWS;

                        param.setVendorCode(vendorCode);

                        IapQueryAirInfoBean sotoParam = ObjectU.copyAs(param, IapQueryAirInfoBean.class);

                        sotoParam.setFlightType(IapConstants.RETURN);

                        sotoParam.setSotoFlag("Y");

                        String departureDate = sotoParam.getDepartureDate();

                        if (NullU.isNotNull(departureDate)){

                            Long departureDateL = Long.valueOf(departureDate.replaceAll("-", "") + "000000");

                            Long departureDateLAdd = DateU.addDay(departureDateL, returnDay);

                            String returnDate = DateU.toStrDate(departureDateLAdd, YYYY_MM_DD);

                            sotoParam.setReturnDate(returnDate);

                            gwsSotoThread = new QueryAirInfoThread(context, sotoParam, vendorCode);

                            gwsSotoThread.start();

                        }

                    }

                }

            }

        }

        if (NullU.isNull(vendorCode)) {

            return new ArrayList<IntAirInfoBean>();

        }

        // 从缓存取代理费设置

        List<IapAgencyPriceSet> agencyPriceList = iapServiceCenter.getIapAgencyService().findAgencyPriceSetList(

                context, param);

        // 取航线缓存设置

        List<IapAirFlight> airFlights = iapDataCenter.getIapAirFlightDao().findIapAirFlights(param);

        

        // 取私有运价。国内始发默认飞狗查询,但是私有运价要从GWS取

        if (iapServiceCenter.getIapCommonService().checkFlightPcc(context, param, IapConstants.INTERFACE_TYPE_FQSBB)) {

            String pfVendorCode = IapConstants.VENDOR_CODE_GWS;

            List<String> airlineList = iapServiceCenter.getIapCommonService().getFlightAirlineList(param);

            // 为空时取所有航空公司

            if (airlineList.isEmpty()) {

                airlineList.add("");

            }

            iapServiceCenter.getIapAirInfoService().findIntAirByThreadPool(context, dataListAll, pfVendorCode, param,

                    agencyPriceList, airlineList);

        }

        long startTime = new Date().getTime();

        // 运价库。从FD取GDS票价和参考税,从AV取航班,然后做运价匹配

        // if (IapConstants.VENDOR_CODE_GWS.equals(vendorCode)){

        iapServiceCenter.getIapAirInfoService().findIntAirByFDAndAV(context, param, vendorCode, agencyPriceList,

                dataListAll, airFlights, inlandFlag, commissionConfig, gds, configs);

        // }

        long endTime = java.util.Calendar.getInstance().getTimeInMillis();

        long interval = (endTime - startTime);

        //System.out.println("time1==== " + interval);

        // 线程查询航班。

        if (gwsThread != null) {

            vendorCode = IapConstants.VENDOR_CODE_GWS;

            this.findIntAirByThread(context, dataListAll, param, gwsThread, agencyPriceList, airFlights, vendorCode,

                    commissionConfig);

        }

        if (amadeusThread != null) {

            vendorCode = IapConstants.VENDOR_CODE_AMADEUS;

            this.findIntAirByThread(context, dataListAll, param, amadeusThread, agencyPriceList, airFlights, vendorCode,

                    commissionConfig);

        }

        if (gwsSotoThread != null){

            vendorCode = IapConstants.VENDOR_CODE_GWS;

            this.findIntAirByThread(context, dataListAll, param, gwsSotoThread, agencyPriceList, airFlights,

                    vendorCode, commissionConfig);

        }

        if (fareGoThread != null){

            vendorCode = IapConstants.VENDOR_CODE_FAREGO;

            this.findIntAirByThread(context, dataListAll, param, fareGoThread, agencyPriceList, airFlights, vendorCode,

                    commissionConfig);

        }

        if (espeedThread != null){

            vendorCode = IapConstants.VENDOR_CODE_ESPEED;

            this.findIntAirByThread(context, dataListAll, param, espeedThread, agencyPriceList, airFlights, vendorCode,

                    commissionConfig);

        }

        if (air86Thread != null) {

            vendorCode = IapConstants.VENDOR_CODE_AIR86;

            this.findIntAirByThread(context, dataListAll, param, air86Thread, agencyPriceList, airFlights, vendorCode,

                    commissionConfig);

        }

        long endTime2 = java.util.Calendar.getInstance().getTimeInMillis();

        long interval2 = (endTime2 - endTime);

        //System.out.println("time2==== " + interval2);

        if (dataListAll == null || dataListAll.isEmpty()) {

            return new ArrayList<IntAirInfoBean>();

        }

        // 填充城市名称、机场名称、航空公司名称、舱位等级

        iapServiceCenter.getIapCommonService().fillAllName(context, dataListAll, param);

        // 设置出票航司

        iapServiceCenter.getIapCommonService().fillIssueAirlineFlag(context, dataListAll);

        // 加价

        iapServiceCenter.getIapPriceService().priceProcessForOrder(context, dataListAll, param);

        // 排序

        this.sortAirList(dataListAll);

        long endTime8 = java.util.Calendar.getInstance().getTimeInMillis();

        long interval8 = (endTime8 - endTime2);

        //System.out.println("time8==== " + interval8);

        long endTime9 = java.util.Calendar.getInstance().getTimeInMillis();

        long interval9 = (endTime9 - startTime1);

        // System.out.println("time9==== " + interval9 + "=====" +

        return dataListAll;

    }

 

    private String getGdsFlag(IapQueryAirInfoBean param){

        String gds = IapConstants.BOOK_SYSTEM_1G;

        // 判断GDS配置

        List<IapGdsConfig> gdsConfigs = iapServiceCenter.getIapConfigService().findIapGdsConfigsFromCache();

        String fromArea = param.getDepartureArea();

        Long now = DateU.toLongDate(new Date());

        for (IapGdsConfig gdsConfig : gdsConfigs) {

            if (gdsConfig.getStartDate().compareTo(now) < 0 && gdsConfig.getEndDate().compareTo(now) > 0) {

                if (NullU.isNotNull(gdsConfig.getFromArea()) && NullU.isNotNull(gdsConfig.getAirlines())) {

                    if (gdsConfig.getFromArea().contains(fromArea) && NullU.isNotNull(param.getAirline())

                            && gdsConfig.getAirlines().contains(param.getAirline())) {

                        gds = gdsConfig.getGds();

                    }

                } else if (NullU.isNotNull(gdsConfig.getFromArea()) && NullU.isNull(gdsConfig.getAirlines())) {

                    if (gdsConfig.getFromArea().contains(fromArea)) {

                        gds = gdsConfig.getGds();

                    }

                } else if (NullU.isNull(gdsConfig.getFromArea()) && NullU.isNotNull(gdsConfig.getAirlines())) {

                    if (NullU.isNotNull(param.getAirline()) && gdsConfig.getAirlines().contains(param.getAirline())) {

                        gds = gdsConfig.getGds();

                    }

                }

            }

        }

        return gds;

    }

 

    /**

     * 线程查询航班

     * 

     * @param context

     * @param dataList

     * @param param

     * @param thread

     * @param agencyPriceList

     * @throws Exception

     */

    @SuppressWarnings("static-access")

    private void findIntAirByThread(ContextInfo context, List<IntAirInfoBean> dataList, IapQueryAirInfoBean param,

            QueryAirInfoThread thread, List<IapAgencyPriceSet> agencyPriceList, List<IapAirFlight> airFlights,

            String vendorCode, FbpConfig commissionConfig) throws Exception {

        long startTime = new Date().getTime();

        while (true) {

            long endTime = java.util.Calendar.getInstance().getTimeInMillis();

            long interval = (endTime - startTime) / 1000;

            if (interval > 30) {

                break;

            }

            if (thread.isRunEnd()) {

                List<IntAirInfoBean> threadDataList = thread.getDataList();

                long endTime2 = java.util.Calendar.getInstance().getTimeInMillis();

                long interval2 = (endTime2 - startTime);

                //System.out.println("====="+ interval2);

                if (threadDataList != null

                        && threadDataList.size() > 0

                        && (IapConstants.VENDOR_CODE_GWS.equals(threadDataList.get(0).getGoFlight().getVendorCode()) 

                                || IapConstants.VENDOR_CODE_AMADEUS.equals(threadDataList.get(0).getGoFlight().getVendorCode()))) {

                    // 转换成人民币

                    iapServiceCenter.getIapCurrencyService().currencyConverter(context, threadDataList, param);

                    try {

                        iapServiceCenter.getIapAgencyService()

                                .reduceAgencyPrice(threadDataList, agencyPriceList, param);

                    } catch (RuntimeException e) {

                        logger.error("匹配并减去代理费错误:", e);

                    }

                }

                if (threadDataList != null

                        && threadDataList.size() > 0

                        && (IapConstants.VENDOR_CODE_ESPEED.equals(threadDataList.get(0).getGoFlight().getVendorCode()))) {

                    try {

                        iapServiceCenter.getIapAgencyService()

                                .reduceAgencyPrice(threadDataList, agencyPriceList, param);

                    } catch (RuntimeException e) {

                        logger.error("ESPEED匹配并减去代理费错误:", e);

                    }

                }

                // 后返处理--以后统一处理

                /*if (NullU.isNotNull(context.getManagementBodyId()) && commissionConfig != null

                        && NullU.isNotNull(commissionConfig.getConfigValue())

                        && commissionConfig.getConfigValue().contains("," + context.getManagementBodyId() + ",")){

                    iapServiceCenter.getIapCommissionService().commissionProcess(context, threadDataList);

                }*/

                // 航线、税费缓存

                 iapServiceCenter.getIapFlightService().addAirFlight(context, param, threadDataList, airFlights);

                if (threadDataList != null) {

                    dataList.addAll(threadDataList);

                }

                break;

            }

            try {

                Thread.currentThread().sleep(100);

            } catch (InterruptedException e) {

                logger.error("线程查询国际航班错误:" + e.getMessage(), e);

            }

        }

    }

 

    /**

     * 多线程查询航班

     * 

     */

    class QueryAirInfoThread extends Thread {

        private ContextInfo context;

        private IapQueryAirInfoBean param;

        private String vendorCode;

        List<IntAirInfoBean> dataList;

        private boolean runEnd = false;

        private boolean used = false;

        QueryAirInfoThread(ContextInfo context, IapQueryAirInfoBean param, String vendorCode) {

            this.context = context;

            this.param = param;

            this.vendorCode = vendorCode;

        }

        @SuppressWarnings("deprecation")

        public void run() {

            runEnd = false;

            try {

                // dataList =

                // iapServiceCenter.getIapVendorInfService().findNtAirInfo(context,

                // param, this.vendorCode);

                String businessId = BusinessUtil.getBusinessId4Local(TARGET_CLENT_CLASS, "thread__findNtAirInfo");

                Map<String, Object> params = new HashMap<String, Object>();

                params.put("param", param);

                params.put("vendorCode", vendorCode);

                dataList = invoker.invokeReList(businessId, context.getPassport(), params, IntAirInfoBean.class);

            } catch (Exception ex) {

                logger.error("多线程查询国际航班错误,vendorCode=" + this.vendorCode, ex);

            } finally {

                runEnd = true;

            }

        }

 

        public List<IntAirInfoBean> getDataList() {

            return dataList;

        }

 

        public void setDataList(List<IntAirInfoBean> dataList) {

            this.dataList = dataList;

        }

 

        public ContextInfo getContext() {

            return context;

        }

 

        public void setContext(ContextInfo context) {

            this.context = context;

        }

 

        public String getVendorCode() {

            return vendorCode;

        }

 

        public void setVendorCode(String vendorCode) {

            this.vendorCode = vendorCode;

        }

 

        public boolean isRunEnd() {

            return runEnd;

        }

 

        public void setRunEnd(boolean runEnd) {

            this.runEnd = runEnd;

        }

 

        public boolean isUsed() {

            return used;

        }

 

        public void setUsed(boolean used) {

            this.used = used;

        }

 

        public IapQueryAirInfoBean getParam() {

            return param;

        }

 

        public void setParam(IapQueryAirInfoBean param) {

            this.param = param;

        }

    }

 

    /**

     * 航班列表排序

     * 

     * @param airInfo

     */

    private void sortAirList(List<IntAirInfoBean> dataList) {

        if (dataList == null || dataList.isEmpty()) {

            return;

        }

        Collections.sort(dataList, new Comparator<IntAirInfoBean>() {

            public int compare(IntAirInfoBean o1, IntAirInfoBean o2) {

                IntAirFlightBean flight1 = o1.getGoFlight();

                Double amount1 = Double.valueOf(flight1.getTicketPrice()) + Double.valueOf(flight1.getTax());

                IntAirFlightBean flight2 = o2.getGoFlight();

                Double amount2 = Double.valueOf(flight2.getTicketPrice()) + Double.valueOf(flight2.getTax());

 

                int rt = amount1.compareTo(amount2);

                if (rt == 0) {

                    rt = flight1.getAirPassage().get(0).getDepTime()

                            .compareTo(flight2.getAirPassage().get(0).getDepTime());

                }

                return rt;

            }

        });

    }

 

    /**

     * 查询国际航班(多程)

     * 

     * @param context

     * @param param

     * @return

     * @throws Exception

     */

    @SuppressWarnings("static-access")

    @Override

    public List<IntAirFlightBean> findMultiAirInfo(ContextInfo context, IapQueryAirInfoBean param) throws Exception {

        String vendorCode = IapConstants.VENDOR_CODE_GWS;

        List<IntAirFlightBean> dataList = null;

        QueryIntAirInfoThread thread = new QueryIntAirInfoThread(context, param, vendorCode);

        thread.start();

        long startTime = new Date().getTime();

        while (true) {

            long endTime = java.util.Calendar.getInstance().getTimeInMillis();

            long interval = (endTime - startTime) / 1000;

            if (interval > 120) {

                break;

            }

            if (thread.isRunEnd()) {

                dataList = thread.getDataList();

                break;

            }

            try {

                Thread.currentThread().sleep(100);

            } catch (InterruptedException e) {

                logger.error(":" + e.getMessage(), e);

            }

        }

        if (dataList == null || dataList.isEmpty()) {

            return new ArrayList<IntAirFlightBean>();

        }

        // 币种转换成人民币

        String equivCurrency = new GenQuoteInfo().getEquivCurrency();

        if (!IapConstants.IAP_CURRENCY_CNY.equals(equivCurrency)) {

            FbpRate rate = zasServiceCenter.getFbpRateService().getRateByCurrencyFromCache(equivCurrency,

                    IapConstants.IAP_CURRENCY_CNY);

            if (rate == null) {

                throw ExceptionFactory.exception("未找到汇率信息");

            }

            iapServiceCenter.getIapCurrencyService().currencyConverterMulti(context, dataList, rate);

        }

        // 填充城市名称、机场名称、航空公司名称、舱位等级

        iapServiceCenter.getIapCommonService().fillIntAirName(context, dataList, param);

        // 加价

        iapServiceCenter.getIapPriceService().priceProcessForOrderForMultiple(context, dataList, param);

        // 票价加完价后,逢一进十,税逢奇进一,并去掉小数点

        this.roundIntAirPrice(context, dataList);

        this.sortIntAirList(dataList);

        return dataList;

    }

 

    /**

     * 多线程查询航班(多程)

     * 

     */

    class QueryIntAirInfoThread extends Thread {

        private ContextInfo context;

        private IapQueryAirInfoBean param;

        private String vendorCode;

        List<IntAirFlightBean> dataList;

        private boolean runEnd = false;

        private boolean used = false;

        QueryIntAirInfoThread(ContextInfo context, IapQueryAirInfoBean param, String vendorCode) {

            this.context = context;

            this.param = param;

            this.vendorCode = vendorCode;

        }

        @SuppressWarnings("deprecation")

        public void run() {

            runEnd = false;

            try {

                String businessId = BusinessUtil.getBusinessId4Local(TARGET_CLENT_CLASS, "thread__findIntAirInfo");

                Map<String, Object> params = new HashMap<String, Object>();

                params.put("param", param);

                params.put("vendorCode", vendorCode);

                dataList = invoker.invokeReList(businessId, context.getPassport(), params, IntAirFlightBean.class);

            } catch (Exception ex) {

                logger.error("多线程查询多程国际航班错误,vendorCode=" + this.vendorCode, ex);

            } finally {

                runEnd = true;

            }

        }

 

        public List<IntAirFlightBean> getDataList() {

            return dataList;

        }

 

        public void setDataList(List<IntAirFlightBean> dataList) {

            this.dataList = dataList;

        }

 

        public ContextInfo getContext() {

            return context;

        }

 

        public void setContext(ContextInfo context) {

            this.context = context;

        }

 

        public String getVendorCode() {

            return vendorCode;

        }

 

        public void setVendorCode(String vendorCode) {

            this.vendorCode = vendorCode;

        }

 

        public boolean isRunEnd() {

            return runEnd;

        }

 

        public void setRunEnd(boolean runEnd) {

            this.runEnd = runEnd;

        }

 

        public boolean isUsed() {

            return used;

        }

 

        public void setUsed(boolean used) {

            this.used = used;

        }

 

        public IapQueryAirInfoBean getParam() {

            return param;

        }

 

        public void setParam(IapQueryAirInfoBean param) {

            this.param = param;

        }

    }

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics