/**
   * 保存指定状态的原始订单至数据库
   *
   * @param originalOrderList
   */
  public void saveOriginalOrders(List<OriginalOrder> originalOrderList) {

    if (CollectionUtils.isEmpty(originalOrderList)) {
      return;
    }

    for (OriginalOrder originalOrder : originalOrderList) {

      if (!(StringUtils.equalsIgnoreCase(
              originalOrder.getStatus(), OriginalOrderStatus.WAIT_SELLER_SEND_GOODS.toString())
          || StringUtils.equalsIgnoreCase(
              originalOrder.getStatus(), OriginalOrderStatus.WAIT_BUYER_CONFIRM_GOODS.toString())
          || StringUtils.equalsIgnoreCase(
              originalOrder.getStatus(), OriginalOrderStatus.TRADE_FINISHED.toString()))) {
        continue;
      }
      // 保存原始订单
      saveOriginalOrder(originalOrder);
      for (OriginalOrderItem originalOrderItem : originalOrder.getOriginalOrderItemList()) {
        // 保存原始订单项
        originalOrderItem.setOriginalOrderId(originalOrder.getId());
        saveOriginalOrderItem(originalOrderItem);
      }
      for (PromotionInfo promotionInfo : originalOrder.getPromotionInfoList()) {
        // 保存订单优惠记录
        promotionInfo.setOriginalOrderId(originalOrder.getId());
        savePromotionInfo(promotionInfo);
      }
    }
  }
 /**
  * 删除原始订单与品牌的关系记录
  *
  * @param originalOrder 如果为null,删除表中所有记录
  */
 private void deleteOriginalOrderBrands(OriginalOrder originalOrder) {
   String sql = "delete from t_original_order_brand ";
   if (originalOrder != null) {
     sql += " where original_order_id = " + originalOrder.getId();
   }
   generalDAO.getSession().createSQLQuery(sql).executeUpdate();
 }
 private void createOriginalOrderBrand(
     OriginalOrder originalOrder, OriginalOrderItem originalOrderItem, Integer brandId) {
   OriginalOrderBrand originalOrderBrand = new OriginalOrderBrand();
   originalOrderBrand.setOriginalOrderId(originalOrder.getId());
   originalOrderBrand.setOriginalOrderItemId(originalOrderItem.getId());
   originalOrderBrand.setBrandId(brandId);
   generalDAO.saveOrUpdate(originalOrderBrand);
 }
 @Transactional
 public void createAnalyzeLog(OriginalOrder originalOrder, boolean processed, String errorMsg) {
   OrderAnalyzeLog log = new OrderAnalyzeLog();
   log.setCreateTime(new Date());
   log.setOriginalOrderId(originalOrder.getId());
   log.setProcessed(processed);
   log.setMessage(errorMsg);
   generalDAO.saveOrUpdate(log);
 }
  /**
   * 获取订单、订单项、订单优惠信息
   *
   * @param originalOrder
   * @param startTime
   * @param endTime
   * @return
   */
  @Transactional(readOnly = true)
  public List<OriginalOrder> findOriginalOrderFullinfos(
      OriginalOrder originalOrder, Date startTime, Date endTime) {
    List<OriginalOrder> originalOrderList = getOriginalOrder(originalOrder, startTime, endTime);

    if (CollectionUtils.isNotEmpty(originalOrderList)) {
      for (OriginalOrder originalOrderOri : originalOrderList) {
        OriginalOrderItem originalOrderItem = new OriginalOrderItem();
        originalOrderItem.setOriginalOrderId(originalOrderOri.getId());
        List<OriginalOrderItem> originalOrderItemList = findOriginalOrderItem(originalOrderItem);
        if (CollectionUtils.isNotEmpty(originalOrderItemList)) {
          originalOrderOri.setOriginalOrderItemList(originalOrderItemList);
        }

        PromotionInfo promotionInfo = new PromotionInfo();
        promotionInfo.setOriginalOrderId(originalOrderOri.getId());
        List<PromotionInfo> promotionInfoList = findPromotionInfos(promotionInfo);
        if (CollectionUtils.isNotEmpty(promotionInfoList)) {
          originalOrderOri.setPromotionInfoList(promotionInfoList);
        }
      }
    }
    return originalOrderList;
  }