/**
   * @param param
   * @return
   */
  @Transactional
  public OrderBean createOrder(OrderSubmitParam param) {
    if (param.getOrderBean() != null
        && param.getOrderBean().getThirdTradeNo() != null
        && param.getOrderBean().getOrderChannel() != null) {
      String tno = param.getOrderBean().getThirdTradeNo();
      OrderBeanExample orderBeanExample = new OrderBeanExample();
      orderBeanExample
          .createCriteria()
          .andThirdTradeNoEqualTo(tno)
          .andOrderChannelEqualTo(param.getOrderBean().getOrderChannel());
      List<OrderBean> olist = orderBeanMapper.selectByExample(orderBeanExample);

      if (olist != null && olist.size() > 0) {
        log.info(tno + "已经成功下单,兼容直接返回");
        return olist.get(0);
      }
    }
    Timestamp curtime = new Timestamp(System.currentTimeMillis());
    OrderBean orderBean = addTradeOrder(param, curtime);
    addThirdOrder(param, orderBean, curtime);
    insertPayment(param, curtime);
    copyToRedis(param.getThirdOrderBean());
    return orderBean;
  }
  @Transactional
  private OrderBean addTradeOrder(OrderSubmitParam param, Timestamp curtime) {
    log.info("OTA下单,StandardService参数适配结果:" + JSON.toJSONString(param));

    OrderBean orderBean = param.getOrderBean();
    OrderBeanExample example = new OrderBeanExample();
    example
        .createCriteria()
        .andThirdTradeNoEqualTo(orderBean.getThirdTradeNo())
        .andOrderChannelEqualTo(orderBean.getOrderChannel());
    if (orderBeanMapper.countByExample(example) > 0) {
      log.error("订单已存在,不可重复下单。");
      throw new TradeException(
          new ReturnCode() {
            @Override
            public String getMessage() {
              return QunarErrorCode.CANNOT_CREATE_THE_SAME_ORDER.name();
            }

            @Override
            public int getCode() {
              return QunarErrorCode.CANNOT_CREATE_THE_SAME_ORDER.code();
            }
          });
    }

    TradeThirdOrder thirdOrderBean = param.getThirdOrderBean();
    orderBean.setPriceBase(thirdOrderBean.getPrice());
    orderBean.setPriceChannel(thirdOrderBean.getPrice());
    orderBean.setPriceGuide(thirdOrderBean.getPrice());
    orderBean.setPriceGuideBase(thirdOrderBean.getPrice());
    orderBean.setPriceTicket(thirdOrderBean.getPrice());
    orderBean.setCreateTime(curtime);
    orderBean.setUpdateTime(curtime);
    orderBean.setCheckInPrice(
        orderBean.getCheckInPrice() == null ? 0.0 : orderBean.getCheckInPrice());
    String flightCode =
        orderBean.getFlightAirportCode() == null
            ? orderBean.getFlightDestCode()
            : orderBean.getFlightAirportCode();
    AirportBean airportBean = controllerService.getAirportByCode(flightCode); // validated
    orderBean.setServiceCityId(airportBean.getCityId());
    orderBean.setOrderSource(OrderSource.OTA.value);
    String orderNo = orderService.addOrderProccess(orderBean); // validated
    orderBean.setOrderNo(orderNo);
    log.info("OTA新订单下单成功,结果OrderBean:" + JSON.toJSONString(orderBean));
    return orderBean;
  }
  /**
   * 2015-12-29,废弃,by 贺伟。用log文件代替。
   *
   * @param param
   * @param orderNo
   * @param curtime
   */
  @Deprecated
  @Transactional
  private void addThirdOrderLogs(OrderSubmitParam param, String orderNo, Timestamp curtime) {
    OrderBean orderBean = param.getOrderBean();
    TradeThirdOrderLogWithBLOBs tradeThirdOrderLogWithBLOBs = new TradeThirdOrderLogWithBLOBs();
    tradeThirdOrderLogWithBLOBs.setCreateTime(curtime);
    tradeThirdOrderLogWithBLOBs.setThirdPartner(Integer.parseInt(orderBean.getAgentId()));
    tradeThirdOrderLogWithBLOBs.setThirdTradeNo(orderBean.getThirdTradeNo());
    tradeThirdOrderLogWithBLOBs.setLogType("orderSubmit");
    tradeThirdOrderLogWithBLOBs.setRequestUrl("v1.0/orderSubmit");
    tradeThirdOrderLogWithBLOBs.setRequestData(JSON.toJSONString(param));
    tradeThirdOrderLogWithBLOBs.setOrderNo(orderNo);
    tradeThirdOrderLogWithBLOBs.setResponseData(JSON.toJSONString(orderBean));

    try {
      thirdOrderLogService.addOrderLog(tradeThirdOrderLogWithBLOBs);
    } catch (Exception e) {
      log.error(
          "OTA下单LOG【TradeThirdOrderLogWithBLOBs-"
              + orderNo
              + "】入库失败,容错。参数:"
              + JSON.toJSONString(tradeThirdOrderLogWithBLOBs),
          e);
    }
  }
Beispiel #4
0
  public String createOrder(OrderSubmitParam param) {
    OrderBean orderBean = param.getOrderBean();

    if (orderBean.getAdultNum() == null) {
      orderBean.setAdultNum(1); // TODO ctrip 怎么传递?
    }

    CarTypeAdaptor carTypeAdaptor =
        CarTypeContext.getInstance()
            .parseThirdCarType(orderBean.getCarTypeId(), CTripCarAdaptor.getInstance());
    orderBean.setCarTypeId(carTypeAdaptor.getCarType());
    orderBean.setCarSeatNum(carTypeAdaptor.getSeatCategory());
    orderBean.setCarDesc(carTypeAdaptor.getHbcCarDesc());
    param.setOrderBean(orderBean);

    return otaOrderService.createOrder(param).getOrderNo();
  }
 @Transactional
 private void addThirdOrder(OrderSubmitParam inputs, OrderBean orderBean, Timestamp curtime) {
   TradeThirdOrder tradeThirdOrder = inputs.getThirdOrderBean();
   tradeThirdOrder.setPriceMark(orderBean.getPriceMark());
   tradeThirdOrder.setCreateTime(curtime);
   tradeThirdOrder.setOrderNo(orderBean.getOrderNo());
   tradeThirdOrder.setOrderStatus(ThirdOrderStatus.PAYSUCCESS.value);
   tradeThirdOrderMapper.insert(tradeThirdOrder);
   log.info("insert trade_trird_order [" + tradeThirdOrder + "]");
 }
  @Transactional
  private void insertPayment(OrderSubmitParam param, Timestamp curtime) {
    OrderBean orderBean = param.getOrderBean();
    String subject = null;
    String postfix = "订单支付";
    AgentChannelEnum channel = AgentChannelEnum.getType(orderBean.getOrderChannel());
    switch (channel) {
      case CTRIP_CHANNEL:
        subject = GetWayEnum.CTRIP.name + postfix;
        break;
      case QUA_CHANNEL:
        subject = GetWayEnum.QUA.name + postfix;
        break;
      case QUNAR_CHANNEL:
        subject = GetWayEnum.QUNAR.name + postfix;
        break;
      default:
        log.error("渠道下单的支付方式不支持:channel=" + channel);
        throw new TradeException(
            new ReturnCode() {
              @Override
              public String getMessage() {
                return QunarErrorCode.ERR_PARAM.name();
              }

              @Override
              public int getCode() {
                return QunarErrorCode.ERR_PARAM.code();
              }
            });
    }

    try {
      otaPaymentService.payOTA(
          orderBean,
          orderBean.getPriceChannel(),
          subject,
          AgentChannelEnum.getType(orderBean.getOrderChannel()));
    } catch (Exception e) {
      log.error("内部账户支付异常。", e);
      throw new TradeException(
          new ReturnCode() {
            @Override
            public String getMessage() {
              return QunarErrorCode.SERVER_ERR.value();
            }

            @Override
            public int getCode() {
              return QunarErrorCode.SERVER_ERR.code();
            }
          });
    }
  }