yujian
2020-04-14 c04a59775ee986f33fe19e21ae02cff9f6b002a7
fanli/src/main/java/com/yeshi/fanli/service/impl/order/OrderMoneySettleServiceImpl.java
@@ -29,6 +29,7 @@
import com.yeshi.fanli.dto.HongBao;
import com.yeshi.fanli.dto.mq.order.OrderTopicTagEnum;
import com.yeshi.fanli.dto.mq.order.body.OrderMoneyRecievedMQMsg;
import com.yeshi.fanli.dto.mq.order.body.TeamRewardPreRecieveMQMsg;
import com.yeshi.fanli.entity.bus.user.HongBaoV2;
import com.yeshi.fanli.entity.bus.user.UserInfo;
import com.yeshi.fanli.entity.money.TeamRewardDebt;
@@ -52,7 +53,6 @@
import com.yeshi.fanli.service.inter.order.CommonOrderService;
import com.yeshi.fanli.service.inter.order.OrderMoneySettleService;
import com.yeshi.fanli.service.inter.user.UserSystemCouponService;
import com.yeshi.fanli.service.manger.money.TeamEincomeManager;
import com.yeshi.fanli.service.manger.order.TeamRewardManager;
import com.yeshi.fanli.service.manger.order.TeamSubsidyManager;
import com.yeshi.fanli.util.Constant;
@@ -123,7 +123,7 @@
   @Transactional(rollbackFor = Exception.class)
   @Override
   public void inviteSettleTB(Long uid) throws OrderMoneySettleException {
   public void inviteSettleTB(Long uid, Date maxPregetTime) throws OrderMoneySettleException {
      // 查询UID的一二级邀请赚
      int sourceType = Constant.SOURCE_TYPE_TAOBAO;
      List<Integer> types = new ArrayList<>();
@@ -131,13 +131,13 @@
      types.add(HongBaoV2.TYPE_ERJI);
      types.add(HongBaoV2.TYPE_SHARE_YIJI);
      types.add(HongBaoV2.TYPE_SHARE_ERJI);
      long count = hongBaoV2Mapper.countCanBalanceHongBaoByTypeAndUid(types, uid, sourceType);
      long count = hongBaoV2Mapper.countCanBalanceHongBaoByTypeAndUid(types, uid, sourceType, maxPregetTime);
      List<HongBaoV2> hongBaoList = new ArrayList<>();
      // 1000条数据为1页
      int page = (int) (count % 1000 == 0 ? count / 1000 : count / 1000 + 1);
      for (int i = 0; i < page; i++) {
         List<HongBaoV2> tempHongBaoList = hongBaoV2Mapper.listCanBalanceHongBaoByTypeAndUid(types, uid, sourceType,
               i * 1000, 1000);
               maxPregetTime, i * 1000, 1000);
         if (tempHongBaoList != null && tempHongBaoList.size() > 0)
            hongBaoList.addAll(tempHongBaoList);
      }
@@ -161,12 +161,13 @@
         }
      }
      // 邀请赚到账事务消息
      OrderMoneyRecievedMQMsg mqMsg = new OrderMoneyRecievedMQMsg(OrderMoneyRecievedMQMsg.TYPE_INVITE, uid,
            sourceType, null, null, new Date(), 0);
      String taskKey = getTaskKey(uid);
      TeamRewardPreRecieveMQMsg mqMsg = new TeamRewardPreRecieveMQMsg(taskKey, uid, sourceType, maxPregetTime,
            new Date());
      Message msg = MQMsgBodyFactory.create(MQTopicName.TOPIC_ORDER, OrderTopicTagEnum.teamRewardPreRecieved, mqMsg);
      String taskKey = getTaskKey(uid);
      msg.setKey(taskKey);
      // 添加事务消息
      try {
@@ -174,14 +175,16 @@
            @Override
            public TransactionStatus execute(Message arg0, Object arg1) {
               try {
                  fanliInvite(hongBaoList, uid, Constant.SOURCE_TYPE_TAOBAO, taskKey);
                  fanliInvite(hongBaoList, uid, Constant.SOURCE_TYPE_TAOBAO, taskKey, maxPregetTime);
               } catch (Exception e) {
                  e.printStackTrace();
                  return TransactionStatus.RollbackTransaction;
               }
               return TransactionStatus.CommitTransaction;
            }
         }, null);
      } catch (Exception e) {
         e.printStackTrace();
         LogHelper.mqError(e.getMessage(), msg.getTopic(), msg.getTag(), new Gson().toJson(mqMsg));
      }
      System.out.println(new Gson().toJson(mqMsg));
@@ -189,7 +192,7 @@
   @Transactional(rollbackFor = Exception.class)
   @Override
   public void inviteSettleJD(Long uid) throws OrderMoneySettleException {
   public void inviteSettleJD(Long uid, Date maxPregetTime) throws OrderMoneySettleException {
      // 查询UID的一二级邀请赚
      int sourceType = Constant.SOURCE_TYPE_JD;
      List<Integer> types = new ArrayList<>();
@@ -197,13 +200,13 @@
      types.add(HongBaoV2.TYPE_ERJI);
      types.add(HongBaoV2.TYPE_SHARE_YIJI);
      types.add(HongBaoV2.TYPE_SHARE_ERJI);
      long count = hongBaoV2Mapper.countCanBalanceHongBaoByTypeAndUid(types, uid, sourceType);
      long count = hongBaoV2Mapper.countCanBalanceHongBaoByTypeAndUid(types, uid, sourceType, maxPregetTime);
      List<HongBaoV2> hongBaoList = new ArrayList<>();
      // 1000条数据为1页
      int page = (int) (count % 1000 == 0 ? count / 1000 : count / 1000 + 1);
      for (int i = 0; i < page; i++) {
         List<HongBaoV2> tempHongBaoList = hongBaoV2Mapper.listCanBalanceHongBaoByTypeAndUid(types, uid, sourceType,
               i * 1000, 1000);
               maxPregetTime, i * 1000, 1000);
         if (tempHongBaoList != null && tempHongBaoList.size() > 0)
            hongBaoList.addAll(tempHongBaoList);
      }
@@ -228,10 +231,11 @@
      }
      // 邀请赚到账事务消息
      OrderMoneyRecievedMQMsg mqMsg = new OrderMoneyRecievedMQMsg(OrderMoneyRecievedMQMsg.TYPE_INVITE, uid,
            sourceType, null, null, new Date(), 0);
      Message msg = MQMsgBodyFactory.create(MQTopicName.TOPIC_ORDER, OrderTopicTagEnum.teamRewardPreRecieved, mqMsg);
      String taskKey = getTaskKey(uid);
      TeamRewardPreRecieveMQMsg mqMsg = new TeamRewardPreRecieveMQMsg(taskKey, uid, sourceType, maxPregetTime,
            new Date());
      Message msg = MQMsgBodyFactory.create(MQTopicName.TOPIC_ORDER, OrderTopicTagEnum.teamRewardPreRecieved, mqMsg);
      msg.setKey(taskKey);
      // 添加事务消息
      try {
@@ -239,7 +243,7 @@
            @Override
            public TransactionStatus execute(Message arg0, Object arg1) {
               try {
                  fanliInvite(hongBaoList, uid, sourceType, taskKey);
                  fanliInvite(hongBaoList, uid, sourceType, taskKey, maxPregetTime);
               } catch (Exception e) {
                  e.printStackTrace();
                  return TransactionStatus.RollbackTransaction;
@@ -254,7 +258,7 @@
   @Transactional(rollbackFor = Exception.class)
   @Override
   public void inviteSettlePDD(Long uid) throws OrderMoneySettleException {
   public void inviteSettlePDD(Long uid, Date maxPregetTime) throws OrderMoneySettleException {
      // 查询UID的一二级邀请赚
      int sourceType = Constant.SOURCE_TYPE_PDD;
      List<Integer> types = new ArrayList<>();
@@ -262,13 +266,13 @@
      types.add(HongBaoV2.TYPE_ERJI);
      types.add(HongBaoV2.TYPE_SHARE_YIJI);
      types.add(HongBaoV2.TYPE_SHARE_ERJI);
      long count = hongBaoV2Mapper.countCanBalanceHongBaoByTypeAndUid(types, uid, sourceType);
      long count = hongBaoV2Mapper.countCanBalanceHongBaoByTypeAndUid(types, uid, sourceType, maxPregetTime);
      List<HongBaoV2> hongBaoList = new ArrayList<>();
      // 1000条数据为1页
      int page = (int) (count % 1000 == 0 ? count / 1000 : count / 1000 + 1);
      for (int i = 0; i < page; i++) {
         List<HongBaoV2> tempHongBaoList = hongBaoV2Mapper.listCanBalanceHongBaoByTypeAndUid(types, uid, sourceType,
               i * 1000, 1000);
               maxPregetTime, i * 1000, 1000);
         if (tempHongBaoList != null && tempHongBaoList.size() > 0)
            hongBaoList.addAll(tempHongBaoList);
      }
@@ -293,10 +297,10 @@
      }
      // 邀请赚到账事务消息
      OrderMoneyRecievedMQMsg mqMsg = new OrderMoneyRecievedMQMsg(OrderMoneyRecievedMQMsg.TYPE_INVITE, uid,
            sourceType, null, null, new Date(), 0);
      Message msg = MQMsgBodyFactory.create(MQTopicName.TOPIC_ORDER, OrderTopicTagEnum.teamRewardPreRecieved, mqMsg);
      String taskKey = getTaskKey(uid);
      TeamRewardPreRecieveMQMsg mqMsg = new TeamRewardPreRecieveMQMsg(taskKey, uid, sourceType, maxPregetTime,
            new Date());
      Message msg = MQMsgBodyFactory.create(MQTopicName.TOPIC_ORDER, OrderTopicTagEnum.teamRewardPreRecieved, mqMsg);
      msg.setKey(taskKey);
      // 添加事务消息
      try {
@@ -304,7 +308,7 @@
            @Override
            public TransactionStatus execute(Message arg0, Object arg1) {
               try {
                  fanliInvite(hongBaoList, uid, sourceType, taskKey);
                  fanliInvite(hongBaoList, uid, sourceType, taskKey, maxPregetTime);
               } catch (Exception e) {
                  return TransactionStatus.RollbackTransaction;
               }
@@ -319,6 +323,7 @@
   @Transactional(rollbackFor = Exception.class)
   @Override
   public void shareSettleTB(Long uid) throws OrderMoneySettleException {
      Date maxPregetTime = new Date();
      /**
       * 处理分享赚
       */
@@ -327,13 +332,13 @@
      // 查询UID的分享赚订单
      types.add(HongBaoV2.TYPE_SHARE_GOODS);
      long count = hongBaoV2Mapper.countCanBalanceHongBaoByTypeAndUid(types, uid, sourceType);
      long count = hongBaoV2Mapper.countCanBalanceHongBaoByTypeAndUid(types, uid, sourceType, maxPregetTime);
      List<HongBaoV2> hongBaoList = new ArrayList<>();
      // 1000条数据为1页
      int page = (int) (count % 1000 == 0 ? count / 1000 : count / 1000 + 1);
      for (int i = 0; i < page; i++) {
         List<HongBaoV2> tempHongBaoList = hongBaoV2Mapper.listCanBalanceHongBaoByTypeAndUid(types, uid, sourceType,
               i * 1000, 1000);
               maxPregetTime, i * 1000, 1000);
         if (tempHongBaoList != null && tempHongBaoList.size() > 0)
            hongBaoList.addAll(tempHongBaoList);
      }
@@ -365,6 +370,7 @@
   @Transactional(rollbackFor = Exception.class)
   @Override
   public void shareSettleJD(Long uid) throws OrderMoneySettleException {
      Date maxPregetTime = new Date();
      /**
       * 处理分享赚
       */
@@ -373,13 +379,13 @@
      // 查询UID的分享赚订单
      types.add(HongBaoV2.TYPE_SHARE_GOODS);
      long count = hongBaoV2Mapper.countCanBalanceHongBaoByTypeAndUid(types, uid, sourceType);
      long count = hongBaoV2Mapper.countCanBalanceHongBaoByTypeAndUid(types, uid, sourceType, maxPregetTime);
      List<HongBaoV2> hongBaoList = new ArrayList<>();
      // 1000条数据为1页
      int page = (int) (count % 1000 == 0 ? count / 1000 : count / 1000 + 1);
      for (int i = 0; i < page; i++) {
         List<HongBaoV2> tempHongBaoList = hongBaoV2Mapper.listCanBalanceHongBaoByTypeAndUid(types, uid, sourceType,
               i * 1000, 1000);
               maxPregetTime, i * 1000, 1000);
         if (tempHongBaoList != null && tempHongBaoList.size() > 0)
            hongBaoList.addAll(tempHongBaoList);
      }
@@ -406,6 +412,7 @@
   @Transactional(rollbackFor = Exception.class)
   @Override
   public void shareSettlePDD(Long uid) throws OrderMoneySettleException {
      Date maxPregetTime = new Date();
      /**
       * 处理分享赚
       */
@@ -414,13 +421,13 @@
      // 查询UID的分享赚订单
      types.add(HongBaoV2.TYPE_SHARE_GOODS);
      long count = hongBaoV2Mapper.countCanBalanceHongBaoByTypeAndUid(types, uid, sourceType);
      long count = hongBaoV2Mapper.countCanBalanceHongBaoByTypeAndUid(types, uid, sourceType, maxPregetTime);
      List<HongBaoV2> hongBaoList = new ArrayList<>();
      // 1000条数据为1页
      int page = (int) (count % 1000 == 0 ? count / 1000 : count / 1000 + 1);
      for (int i = 0; i < page; i++) {
         List<HongBaoV2> tempHongBaoList = hongBaoV2Mapper.listCanBalanceHongBaoByTypeAndUid(types, uid, sourceType,
               i * 1000, 1000);
               maxPregetTime, i * 1000, 1000);
         if (tempHongBaoList != null && tempHongBaoList.size() > 0)
            hongBaoList.addAll(tempHongBaoList);
      }
@@ -592,7 +599,7 @@
   }
   @Transactional
   private void fanliInvite(List<HongBaoV2> hongBaoList, Long uid, int sourceType, String key)
   private void fanliInvite(List<HongBaoV2> hongBaoList, Long uid, int sourceType, String key, Date maxPreGetTime)
         throws TeamEincomeRecordException, ParamsException, TeamRewardDebtException {
      List<Long> hbIdList = new ArrayList<>();
      BigDecimal invitemoney = new BigDecimal(0);
@@ -633,11 +640,8 @@
      // 邀请赚到账
      if (invitemoney.compareTo(new BigDecimal(0)) > 0) {
         Calendar ca = Calendar.getInstance();
         Date date = new Date(TimeUtil.convertToTimeTemp(
               ca.get(Calendar.YEAR) + "-" + (ca.get(Calendar.MONTH) + 1) + "-25", "yyyy-M-dd"));
         // 获取当前的月份
         teamRewardManager.addToEincome(uid, date, invitemoney, sourceType);
         teamRewardManager.addToEincome(uid, maxPreGetTime, invitemoney, sourceType);
      }
      hongBaoV2SettleTempService.addTemp(hbIdList, key);
@@ -645,7 +649,8 @@
      // 所有的返利到账红包ID
      for (Long hongBaoId : hbIdList) {
         try {
            HongBaoRecieveCMQManager.getInstance().addHongBaoRecieveMsg(hongBaoId);
            if (Constant.ENABLE_MQ)
               HongBaoRecieveCMQManager.getInstance().addHongBaoRecieveMsg(hongBaoId);
         } catch (Exception e) {
            LogHelper.errorDetailInfo(e);
         }
@@ -863,9 +868,9 @@
    */
   @Transactional(rollbackFor = Exception.class)
   @Override
   public void inviteSubsidySettle(Long uid, String taskKey)
   public void inviteSubsidySettle(Long uid, String taskKey,Date maxPreGetTime)
         throws OrderMoneySettleException, TeamEincomeRecordException, ParamsException {
      teamSubsidyManager.addToTeamEincome(uid, taskKey);
      teamSubsidyManager.addToTeamEincome(uid, taskKey,maxPreGetTime);
   }
   private String getTaskKey(Long uid) {