yujian
2019-03-27 cdcbed9af813b2a02cdc01eefa24db8bec6b51a9
fanli/src/main/java/com/yeshi/fanli/job/UpdateOrderJob.java
@@ -11,22 +11,16 @@
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import com.taobao.api.TaobaoObject;
import com.yeshi.fanli.entity.bus.user.Order;
import com.yeshi.fanli.entity.taobao.PidUser;
import com.yeshi.fanli.entity.taobao.TaoBaoOrder;
import com.yeshi.fanli.entity.taobao.TaoBaoUnionConfig;
import com.yeshi.fanli.entity.taobao.TaoBaoWeiQuanOrder;
import com.yeshi.fanli.exception.TaoBaoOrderException;
import com.yeshi.fanli.log.LogHelper;
import com.yeshi.fanli.service.inter.common.DataMonitorService;
import com.yeshi.fanli.service.inter.hongbao.HongBaoService;
import com.yeshi.fanli.service.inter.hongbao.ThreeSaleGiftService;
import com.yeshi.fanli.service.inter.order.LostOrderService;
import com.yeshi.fanli.service.inter.order.OrderItemServcie;
import com.yeshi.fanli.service.inter.order.OrderProcessService;
import com.yeshi.fanli.service.inter.order.OrderService;
import com.yeshi.fanli.service.inter.order.PidOrderService;
import com.yeshi.fanli.service.inter.taobao.TaoBaoOrderService;
import com.yeshi.fanli.service.inter.taobao.TaoBaoUnionConfigService;
import com.yeshi.fanli.service.inter.taobao.TaoBaoWeiQuanOrderService;
@@ -35,7 +29,6 @@
import com.yeshi.fanli.util.RedisManager;
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.util.TimeUtil;
import com.yeshi.fanli.util.taobao.TaoBao110Util;
import com.yeshi.fanli.util.taobao.TaoBaoOrderUtil;
import com.yeshi.fanli.util.taobao.TaoKeOrderApiUtil;
@@ -46,18 +39,6 @@
   public UpdateOrderJob() {
      System.out.println("初始化:UpdateOrderJob");
   }
   @Resource
   private OrderItemServcie orderItemServcie;
   @Resource
   private ThreeSaleGiftService threeSaleGiftService;
   @Resource
   private HongBaoService hongBaoService;
   @Resource
   private PidOrderService pidOrderService;
   @Resource
   private OrderProcessService orderProcessService;
@@ -107,9 +88,10 @@
      }
      return orderList;
   }
   /**
    * 获取第三方普通订单
    *
    * @param startTime
    * @param span
    * @return
@@ -131,13 +113,14 @@
   /**
    * 获取某个区间段的订单
    *
    * @param startTime
    * @param endTime
    * @return
    */
   public static List<TaoBaoOrder> getCommonOrder(long startTime, long endTime) {
      List<TaoBaoOrder> orderList = new ArrayList<>();
      long span =(endTime - startTime)%1000==0? (endTime - startTime)/1000:(endTime - startTime)/1000+1;
      long span = (endTime - startTime) % 1000 == 0 ? (endTime - startTime) / 1000 : (endTime - startTime) / 1000 + 1;
      int count = (int) (span / 1200);
      if (span % 1200 != 0)
         count++;
@@ -155,17 +138,17 @@
      }
      return orderList;
   }
   /**
    * 爬取三方订单
    *
    * @param startTime
    * @param endTime
    * @return
    */
   public static List<TaoBaoOrder> getThirdCommonOrder(long startTime, long endTime) {
      List<TaoBaoOrder> orderList = new ArrayList<>();
      long span =(endTime - startTime)%1000==0? (endTime - startTime)/1000:(endTime - startTime)/1000+1;
      long span = (endTime - startTime) % 1000 == 0 ? (endTime - startTime) / 1000 : (endTime - startTime) / 1000 + 1;
      int count = (int) (span / 1200);
      if (span % 1200 != 0)
         count++;
@@ -202,29 +185,38 @@
   }
   public void updateOrder(long startTime, long endTime) {
      List<TaoBaoUnionConfig> configList = taoBaoUnionConfigService.getConfigByTypeCache(PidUser.TYPE_FANLI_ANDROID);
      List<TaoBaoOrder> orderList = new ArrayList<>();
      try {
         orderList = TaoBaoOrderUtil.getOrderList(startTime, endTime, configList.get(0));
      } catch (TaoBaoOrderException e2) {
         try {
            LogHelper.errorDetailInfo(e2);
         } catch (Exception e) {
            e.printStackTrace();
         }
      }
      List<TaoBaoOrder> thirdOrderList = new ArrayList<>();
      try {
         thirdOrderList = TaoBaoOrderUtil.getThirdServiceOrderList(startTime, endTime, configList.get(0));
      } catch (TaoBaoOrderException e2) {
         try {
            LogHelper.errorDetailInfo(e2);
         } catch (Exception e) {
            e.printStackTrace();
         }
      }
      if (thirdOrderList != null && thirdOrderList.size() > 0)
         orderList.addAll(thirdOrderList);
      // 老版本处理方式
      // List<TaoBaoUnionConfig> configList =
      // taoBaoUnionConfigService.getConfigByTypeCache(PidUser.TYPE_FANLI_ANDROID);
      // List<TaoBaoOrder> orderList = new ArrayList<>();
      // try {
      // orderList = TaoBaoOrderUtil.getOrderList(startTime, endTime,
      // configList.get(0));
      // } catch (TaoBaoOrderException e2) {
      // try {
      // LogHelper.errorDetailInfo(e2);
      // } catch (Exception e) {
      // e.printStackTrace();
      // }
      // }
      // List<TaoBaoOrder> thirdOrderList = new ArrayList<>();
      // try {
      // thirdOrderList = TaoBaoOrderUtil.getThirdServiceOrderList(startTime,
      // endTime, configList.get(0));
      // } catch (TaoBaoOrderException e2) {
      // try {
      // LogHelper.errorDetailInfo(e2);
      // } catch (Exception e) {
      // e.printStackTrace();
      // }
      // }
      // if (thirdOrderList != null && thirdOrderList.size() > 0)
      // orderList.addAll(thirdOrderList);
      // 新版本处理方式
      List<TaoBaoOrder> orderList = getCommonOrder(startTime, endTime);
      List<TaoBaoOrder> tempOrderList2 = getThirdCommonOrder(startTime, endTime);
      if (tempOrderList2 != null && tempOrderList2.size() > 0)
         orderList.addAll(tempOrderList2);
      LogHelper.orderInfo("正在执行订单爬取结束,共有订单:" + orderList.size());
      addOrder(orderList);
@@ -269,54 +261,6 @@
      }
      return orderList;
   }
   private void addRelationAndSpecialOrder(List<TaoBaoOrder> orderList) {
      try {
         taoBaoOrderService.addTaoBaoOrderList(orderList);
      } catch (Exception e) {
         try {
            LogHelper.errorDetailInfo(e);
         } catch (Exception e1) {
            e1.printStackTrace();
         }
      }
      try {
         Map<String, List<TaoBaoOrder>> map = TaoBaoOrderUtil.classifyTaoBaoOrderByOrderId(orderList);
         if (map != null) {
            Iterator<String> its = map.keySet().iterator();
            while (its.hasNext()) {
               String key = its.next();
               List<TaoBaoOrder> orders = map.get(key);
               String redisKey = "addorderqueue-" + key;
               // redis做频率限制
               try {
                  if (!StringUtil.isNullOrEmpty(redisManager.getCommonString(redisKey))) {
                     continue;
                  }
               } catch (Exception e) {
               }
               CMQManager.getInstance().addTaoBaoOrderMsg(key, orders);
               try {
                  // 6小时内不再处理
                  redisManager.cacheCommonString(redisKey, "1", 60 * 60 * 6);
               } catch (Exception e) {
               }
            }
         }
      } catch (Exception e) {
         try {
            LogHelper.errorDetailInfo(e);
         } catch (Exception e1) {
            e1.printStackTrace();
         }
      }
   }
   private void addOrder(List<TaoBaoOrder> orderList) {
@@ -395,7 +339,7 @@
   public void doJob1() {
      if (!Constant.IS_TASK)
         return;
      long currentTime = System.currentTimeMillis();
      long currentTime = System.currentTimeMillis() - 1000 * 60;
      String h = TimeUtil.getGernalTime(currentTime, "HH");
      String m = TimeUtil.getGernalTime(currentTime, "mm");
      int mm = Integer.parseInt(h) * 60 + Integer.parseInt(m);
@@ -414,39 +358,9 @@
   public void doJob6() {
      if (!Constant.IS_TASK)
         return;
      List<TaoBaoUnionConfig> configList = taoBaoUnionConfigService.getConfigByTypeCache(PidUser.TYPE_FANLI_ANDROID);
      LogHelper.orderInfo("正在执行订单爬取...");
      // 爬取1分钟以前的
      long endTime = System.currentTimeMillis() - 1000 * 60 * 1L;
      List<TaoBaoOrder> orderList = new ArrayList<TaoBaoOrder>();
      try {
         orderList = TaoBaoOrderUtil.getOrderList(endTime - 1000 * 60 * 60 * 24 * 2L, endTime, configList.get(0));
         TaoBao110Util.rightTaoBaoOrderWarning();
      } catch (TaoBaoOrderException e) {
         try {
            LogHelper.errorDetailInfo(e);
            TaoBao110Util.reportTaoBaoOrderWarning(e.getCode(), e.getMessage());
         } catch (Exception e2) {
            e2.printStackTrace();
         }
      }
      List<TaoBaoOrder> thirdOrderList = new ArrayList<>();
      try {
         thirdOrderList = TaoBaoOrderUtil.getThirdServiceOrderList(endTime - 1000 * 60 * 60 * 24 * 2L, endTime,
               configList.get(0));
      } catch (TaoBaoOrderException e) {
         try {
            LogHelper.errorDetailInfo(e);
         } catch (Exception e2) {
            e2.printStackTrace();
         }
      }
      if (thirdOrderList != null && thirdOrderList.size() > 0)
         orderList.addAll(thirdOrderList);
      if (orderList != null && orderList.size() > 0)
         dataMonitorService.parseTaoBaoOrderSuccess();
      LogHelper.orderInfo("正在执行订单爬取结束,共有订单:" + orderList.size());
      addOrder(orderList);
      long endTime = System.currentTimeMillis() - 1000 * 60;
      ;
      updateOrder(endTime - 1000 * 60 * 20L, endTime);
   }
   // 返利