Example #1
0
  /**
   * @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;
  }
Example #2
0
  @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;
  }
Example #3
0
 public TradeThirdOrder getThirdOrderBythirdTradeNo(Integer partner, String thirdTradeNo) {
   TradeThirdOrderExample tradeThirdOrderExample = new TradeThirdOrderExample();
   TradeThirdOrderExample.Criteria criteria = tradeThirdOrderExample.createCriteria();
   criteria.andThirdPartnerEqualTo(partner);
   criteria.andThirdTradeNoEqualTo(thirdTradeNo);
   List<TradeThirdOrder> tOrders = tradeThirdOrderMapper.selectByExample(tradeThirdOrderExample);
   if (tOrders == null || tOrders.size() == 0) {
     OrderBeanExample orderBeanExample = new OrderBeanExample();
     orderBeanExample.createCriteria().andThirdTradeNoEqualTo(thirdTradeNo);
     List<OrderBean> olist = orderBeanMapper.selectByExample(orderBeanExample);
     if (olist.size() == 1) {
       TradeThirdOrder tradeThirdOrder =
           tradeThirdOrderMapper.selectByPrimaryKey(olist.get(0).getOrderNo());
       return tradeThirdOrder;
     }
     return null;
   } else {
     return tOrders.get(0);
   }
 }