yujian
2020-04-15 c6b718c3cadf5e5fff4c2a47fd1247842439f8c7
fanli/src/main/java/com/yeshi/fanli/util/SpringContext.java
@@ -20,6 +20,7 @@
import com.yeshi.fanli.dto.ad.DouYinDeviceActiveQueueDTO;
import com.yeshi.fanli.dto.money.UserMoneyChangeDTO;
import com.yeshi.fanli.dto.order.dividents.UserDividentsDayDTO;
import com.yeshi.fanli.entity.ad.DouYinClickEvent;
import com.yeshi.fanli.entity.bus.user.AlipayTransferResultInfo;
import com.yeshi.fanli.entity.bus.user.HongBaoV2;
@@ -57,13 +58,13 @@
import com.yeshi.fanli.service.inter.user.integral.IntegralGetService;
import com.yeshi.fanli.service.inter.user.integral.IntegralTaskRecordService;
import com.yeshi.fanli.service.inter.user.invite.ThreeSaleSerivce;
import com.yeshi.fanli.service.manger.order.TeamDividentsManager;
import com.yeshi.fanli.util.ad.DouYinAdUtil;
import com.yeshi.fanli.util.cmq.DouYinDeviceActiveCMQManager;
import com.yeshi.fanli.util.cmq.HongBaoRecieveCMQManager;
import com.yeshi.fanli.util.cmq.JDOrderCMQManager;
import com.yeshi.fanli.util.cmq.PDDOrderCMQManager;
import com.yeshi.fanli.util.cmq.PlaceOrderCMQManager;
import com.yeshi.fanli.util.cmq.ThreeSaleCMQManager;
import com.yeshi.fanli.util.cmq.UserMoneyChangeCMQManager;
import com.yeshi.fanli.util.taobao.TaoKeApiUtil;
@@ -139,6 +140,9 @@
   @Resource
   private DeviceActiveService deviceActiveService;
   @Resource
   private TeamDividentsManager teamDividentsManager;
   private static boolean isInited = false;
   public void onApplicationEvent(ContextRefreshedEvent arg0) {
@@ -166,7 +170,6 @@
         doOrderTiChengFanLi();// 处理订单提成返利
         doWeiQuanOrder();// 处理维权订单
         doPushIOS();// 处理发送IOS消息
         doThreeSaleUserCouponJob();// 处理邀请队列
         doUserMoneyDebtJob();// 债务偿还
         initScheduler();// 启动商品更新定时任务
         doUpdateGoodsJob(); // 更新商品队列
@@ -176,6 +179,9 @@
         doHongBaoRecieveIntegralGetJob();// 返利到账,金币增加
         // doPlaceOrderIntegralJob();// 下单赠送金币任务
         // doDouYinDeviceActiveJob();// 抖音设备激活广告监测
         doDividentsJob();
      }
   }
@@ -329,7 +335,8 @@
                        try {
                           HongBaoV2 hongbao = map.get(handler);
                           if (hongbao != null) {
                              String key = "hongbao-fanli-" + hongbao.getId();
                              String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.hongBaoFanLi,
                                    hongbao.getId() + "");
                              if (StringUtil.isNullOrEmpty(redisManager.getCommonString(key))) {
                                 // 处理之后要隔2小时再次进行处理
                                 redisManager.cacheCommonString(key, "1", 60 * 60 * 2);
@@ -516,66 +523,6 @@
   }
   /**
    * 邀请关系变化后券的更新
    */
   public void doThreeSaleUserCouponJob() {
      // 采用2个线程做更新
      for (int i = 0; i < 2; i++)
         executor.execute(new Runnable() {
            @Override
            public void run() {
               while (true) {
                  try {
                     Map<String, ThreeSale> map = ThreeSaleCMQManager.getInstance()
                           .consumeQueueMsg(ThreeSaleCMQManager.QUEUE_USER_COUPON, 16);
                     if (map != null) {
                        Iterator<String> its = map.keySet().iterator();
                        while (its.hasNext()) {
                           String key = its.next();
                           try {
                              ThreeSale threeSale = map.get(key);
                              if (threeSale != null)
                                 threeSale = threeSaleSerivce.selectByPrimaryKey(threeSale.getId());
                              if (threeSale != null) {
                                 if (threeSale.getState() != null && threeSale.getState() == true) {
                                    // 邀请成功 - 券激活生效
                                    LogHelper.test("doThreeSaleUserCouponJob-" + threeSale.getId());
                                    Long bossId = threeSale.getBoss().getId();
                                    // 下级昵称
                                    String workerNickName = userInfoService
                                          .selectByPKey(threeSale.getWorker().getId()).getNickName();
                                    userSystemCouponService.activatedWelfareFreeCoupon(bossId,
                                          workerNickName);
                                 }
                              }
                              ThreeSaleCMQManager.getInstance()
                                    .deleteQueueMsg(ThreeSaleCMQManager.QUEUE_USER_COUPON, key);
                           } catch (Exception e) {
                              try {
                                 LogHelper.errorDetailInfo(e);
                              } catch (Exception e1) {
                                 e1.printStackTrace();
                              }
                           }
                        }
                     }
                  } catch (Exception e) {
                     LogHelper.error("更新商品出错:" + e.getMessage());
                  }
               }
            }
         });
   }
   /**
    * 用户借贷处理
    */
   public void doUserMoneyDebtJob() {
@@ -747,8 +694,8 @@
                           fanliGetIntegral(hongBaoV2);
                           HongBaoRecieveCMQManager.getInstance()
                                 .deleteQueueMsg(HongBaoRecieveCMQManager.QUEUE_INTEGRAL, key);
                           //返利不足0.01元送金币
                           // 返利不足0.01元送金币
                           if (hongBaoV2.getType() == HongBaoV2.TYPE_ZIGOU) {// 自购
                              // 判断是否为该用户的首笔红包
                              List<Integer> typeList = new ArrayList<>();
@@ -902,14 +849,28 @@
   private void fanliGetIntegral(HongBaoV2 hongBaoV2) {
      if (hongBaoV2 != null && hongBaoV2.getState() == HongBaoV2.STATE_YILINGQU
            && hongBaoV2.getMoney().compareTo(new BigDecimal(0)) > 0) {
         // 查询对应的订单号
         Long mainHongBaoId = hongBaoV2.getId();
         if (hongBaoV2.getParent() != null && hongBaoV2.getParent().getId() != null)
            mainHongBaoId = hongBaoV2.getParent().getId();
         HongBaoOrder hongbaoOrder = hongBaoOrderService.selectDetailByHongBaoId(mainHongBaoId);
         if (hongbaoOrder == null || hongbaoOrder.getCommonOrder() == null)
            return;
         CommonOrder commonOrder = hongbaoOrder.getCommonOrder();
         if (hongBaoV2.getType() == HongBaoV2.TYPE_ZIGOU) {// 自购订单
            integralGetService.addRebateOrder(hongBaoV2.getUserInfo().getId());
            integralGetService.addRebateOrder(hongBaoV2.getUserInfo().getId(), commonOrder.getOrderNo(),
                  commonOrder.getSourceType());
         } else if (hongBaoV2.getType() == HongBaoV2.TYPE_SHARE_GOODS) {// 分享订单
            integralGetService.addShareOrder(hongBaoV2.getUserInfo().getId());
            integralGetService.addShareOrder(hongBaoV2.getUserInfo().getId(), commonOrder.getOrderNo(),
                  commonOrder.getSourceType());
         } else if (hongBaoV2.getType() == HongBaoV2.TYPE_YIJI || hongBaoV2.getType() == HongBaoV2.TYPE_SHARE_YIJI) {// 一级邀请
            integralGetService.addInviteOrderLevelOne(hongBaoV2.getUserInfo().getId());
            integralGetService.addInviteOrderLevelOne(hongBaoV2.getUserInfo().getId(), commonOrder.getOrderNo(),
                  commonOrder.getSourceType());
         } else if (hongBaoV2.getType() == HongBaoV2.TYPE_ERJI || hongBaoV2.getType() == HongBaoV2.TYPE_SHARE_ERJI) {// 二级邀请
            integralGetService.addInviteOrderLevelTwo(hongBaoV2.getUserInfo().getId());
            integralGetService.addInviteOrderLevelTwo(hongBaoV2.getUserInfo().getId(), commonOrder.getOrderNo(),
                  commonOrder.getSourceType());
         }
      }
   }
@@ -1113,4 +1074,34 @@
      });
   }
   // 分红
   public void doDividentsJob() {
      executor.execute(new Runnable() {
         @Override
         public void run() {
            while (true) {
               Map<String, UserDividentsDayDTO> map = CMQManager.getInstance().consumeTeamDividentsMsg(16);
               if (map != null) {
                  Iterator<String> its = map.keySet().iterator();
                  while (its.hasNext()) {
                     String key = its.next();
                     UserDividentsDayDTO dto = map.get(key);
                     try {
                        teamDividentsManager.addToTeamEincome(dto.getUid(), dto.getPreGetTime());
                     } catch (Exception e) {
                        try {
                           LogHelper.errorDetailInfo(e);
                        } catch (Exception e1) {
                           e1.printStackTrace();
                        }
                     } finally {
                     }
                  }
               }
            }
         }
      });
   }
}