yujian
2019-12-18 89cc8f054c27f70fcfe16f14554a8a12e0c19e23
fanli/src/main/java/com/yeshi/fanli/service/impl/order/OrderMoneySettleServiceImpl.java
@@ -28,7 +28,8 @@
import com.yeshi.fanli.dao.mybatis.order.HongBaoOrderMapper;
import com.yeshi.fanli.dao.mybatis.taobao.TaoBaoWeiQuanOrderMapper;
import com.yeshi.fanli.dto.HongBao;
import com.yeshi.fanli.dto.order.OrderMoneyRecievedMQMsgDTO;
import com.yeshi.fanli.dto.mq.order.OrderTopicTagEnum;
import com.yeshi.fanli.dto.mq.order.body.OrderMoneyRecievedMQMsg;
import com.yeshi.fanli.entity.bus.user.HongBaoV2;
import com.yeshi.fanli.entity.bus.user.UserInfo;
import com.yeshi.fanli.entity.money.UserMoneyDetail;
@@ -59,6 +60,7 @@
import com.yeshi.fanli.util.TimeUtil;
import com.yeshi.fanli.util.cmq.HongBaoRecieveCMQManager;
import com.yeshi.fanli.util.factory.UserMoneyDetailFactory;
import com.yeshi.fanli.util.rocketmq.MQMsgBodyFactory;
import com.yeshi.fanli.util.rocketmq.MQTopicName;
import com.yeshi.fanli.util.taobao.TaoKeOrderApiUtil;
@@ -152,9 +154,10 @@
      }
      // 邀请赚到账事务消息
      OrderMoneyRecievedMQMsgDTO mqMsg = new OrderMoneyRecievedMQMsgDTO(OrderMoneyRecievedMQMsgDTO.TYPE_INVITE, uid,
            sourceType, null, null, new Date());
      Message msg = new Message(MQTopicName.TOPIC_FANLI.name(), "actual", new Gson().toJson(mqMsg).getBytes());
      OrderMoneyRecievedMQMsg mqMsg = new OrderMoneyRecievedMQMsg(OrderMoneyRecievedMQMsg.TYPE_INVITE, uid,
            sourceType, null, null, new Date(), 0);
      Message msg = MQMsgBodyFactory.create(MQTopicName.TOPIC_ORDER, OrderTopicTagEnum.orderFanLiActual, mqMsg);
      String taskKey = getTaskKey(uid);
      msg.setKey(taskKey);
      // 添加事务消息
@@ -173,6 +176,7 @@
      } catch (Exception e) {
         LogHelper.mqError(e.getMessage(), msg.getTopic(), msg.getTag(), new Gson().toJson(mqMsg));
      }
      System.out.println(new Gson().toJson(mqMsg));
   }
   @Transactional
@@ -215,9 +219,9 @@
      }
      // 邀请赚到账事务消息
      OrderMoneyRecievedMQMsgDTO mqMsg = new OrderMoneyRecievedMQMsgDTO(OrderMoneyRecievedMQMsgDTO.TYPE_INVITE, uid,
            sourceType, null, null, new Date());
      Message msg = new Message(MQTopicName.TOPIC_FANLI.name(), "actual", new Gson().toJson(mqMsg).getBytes());
      OrderMoneyRecievedMQMsg mqMsg = new OrderMoneyRecievedMQMsg(OrderMoneyRecievedMQMsg.TYPE_INVITE, uid,
            sourceType, null, null, new Date(), 0);
      Message msg = MQMsgBodyFactory.create(MQTopicName.TOPIC_ORDER, OrderTopicTagEnum.orderFanLiActual, mqMsg);
      String taskKey = getTaskKey(uid);
      msg.setKey(taskKey);
      // 添加事务消息
@@ -274,9 +278,9 @@
      }
      // 邀请赚到账事务消息
      OrderMoneyRecievedMQMsgDTO mqMsg = new OrderMoneyRecievedMQMsgDTO(OrderMoneyRecievedMQMsgDTO.TYPE_INVITE, uid,
            sourceType, null, null, new Date());
      Message msg = new Message(MQTopicName.TOPIC_FANLI.name(), "actual", new Gson().toJson(mqMsg).getBytes());
      OrderMoneyRecievedMQMsg mqMsg = new OrderMoneyRecievedMQMsg(OrderMoneyRecievedMQMsg.TYPE_INVITE, uid,
            sourceType, null, null, new Date(), 0);
      Message msg = MQMsgBodyFactory.create(MQTopicName.TOPIC_ORDER, OrderTopicTagEnum.orderFanLiActual, mqMsg);
      String taskKey = getTaskKey(uid);
      msg.setKey(taskKey);
      // 添加事务消息
@@ -315,9 +319,9 @@
            hongBaoList.addAll(tempHongBaoList);
      }
      OrderMoneyRecievedMQMsgDTO mqMsg = new OrderMoneyRecievedMQMsgDTO(OrderMoneyRecievedMQMsgDTO.TYPE_SHARE, uid,
            sourceType, null, null, new Date());
      Message msg = new Message(MQTopicName.TOPIC_FANLI.name(), "actual", new Gson().toJson(mqMsg).getBytes());
      OrderMoneyRecievedMQMsg mqMsg = new OrderMoneyRecievedMQMsg(OrderMoneyRecievedMQMsg.TYPE_SHARE, uid, sourceType,
            null, null, new Date(), 0);
      Message msg = MQMsgBodyFactory.create(MQTopicName.TOPIC_ORDER, OrderTopicTagEnum.orderFanLiActual, mqMsg);
      String taskKey = getTaskKey(uid);
      msg.setKey(taskKey);
      // 添加事务消息
@@ -360,9 +364,9 @@
            hongBaoList.addAll(tempHongBaoList);
      }
      OrderMoneyRecievedMQMsgDTO mqMsg = new OrderMoneyRecievedMQMsgDTO(OrderMoneyRecievedMQMsgDTO.TYPE_SHARE, uid,
            sourceType, null, null, new Date());
      Message msg = new Message(MQTopicName.TOPIC_FANLI.name(), "actual", new Gson().toJson(mqMsg).getBytes());
      OrderMoneyRecievedMQMsg mqMsg = new OrderMoneyRecievedMQMsg(OrderMoneyRecievedMQMsg.TYPE_SHARE, uid, sourceType,
            null, null, new Date(), 0);
      Message msg = MQMsgBodyFactory.create(MQTopicName.TOPIC_ORDER, OrderTopicTagEnum.orderFanLiActual, mqMsg);
      String taskKey = getTaskKey(uid);
      msg.setKey(taskKey);
      // 添加事务消息
@@ -401,9 +405,9 @@
            hongBaoList.addAll(tempHongBaoList);
      }
      OrderMoneyRecievedMQMsgDTO mqMsg = new OrderMoneyRecievedMQMsgDTO(OrderMoneyRecievedMQMsgDTO.TYPE_SHARE, uid,
            sourceType, null, null, new Date());
      Message msg = new Message(MQTopicName.TOPIC_FANLI.name(), "actual", new Gson().toJson(mqMsg).getBytes());
      OrderMoneyRecievedMQMsg mqMsg = new OrderMoneyRecievedMQMsg(OrderMoneyRecievedMQMsg.TYPE_SHARE, uid, sourceType,
            null, null, new Date(), 0);
      Message msg = MQMsgBodyFactory.create(MQTopicName.TOPIC_ORDER, OrderTopicTagEnum.orderFanLiActual, mqMsg);
      String taskKey = getTaskKey(uid);
      msg.setKey(taskKey);
      // 添加事务消息
@@ -422,7 +426,7 @@
   @Transactional
   @Override
   public void ziGouSettle(String orderId, int sourceType,String taskKey) throws OrderMoneySettleException {
   public void ziGouSettle(String orderId, int sourceType, String taskKey) throws OrderMoneySettleException {
      // 查询同一订单号的红包
      List<CommonOrder> orderList = commonOrderService.listBySourceTypeAndOrderId(sourceType, orderId);
      List<HongBaoV2> hongBaoList = new ArrayList<>();
@@ -466,6 +470,10 @@
         }
      }
      // if (userMoney.isEmpty()) {
      // throw new OrderMoneySettleException(1, "没有需要结算的订单");
      // }
      Iterator<Long> its = userMoney.keySet().iterator();
      while (its.hasNext()) {
@@ -486,8 +494,8 @@
         }
         userMoneyService.addUserMoney(uid, money, userMoneyDetail);
         List<Long> hbIdList=new ArrayList<>();
         List<Long> hbIdList = new ArrayList<>();
         // 添加资金明细与红包的映射关系
         for (HongBaoV2 v2 : userHongBao.get(uid)) {
            hbIdList.add(v2.getId());
@@ -498,7 +506,7 @@
               LogHelper.errorDetailInfo(e);
            }
         }
         //添加结算映射
         // 添加结算映射
         hongBaoV2SettleTempService.addTemp(hbIdList, taskKey);
         // 站内信+推送
@@ -539,10 +547,9 @@
         } else
            throw new OrderMoneySettleException(e.getCode(), "维权处理出错:" + e.getMsg());
      }
      //添加结算映射
      // 添加结算映射
   }
   private HongBaoV2 filterWeiQuanINGHongBao(HongBaoV2 hongBao) {
@@ -569,7 +576,7 @@
      return hongBao;
   }
   @Transactional
   @Transactional(rollbackFor = Exception.class)
   private void fanliInviteTB(List<HongBaoV2> hongBaoList, Long uid, String key) throws TaoBaoWeiQuanException {
      List<Long> hbIdList = new ArrayList<>();
      BigDecimal invitemoney = new BigDecimal(0);
@@ -622,9 +629,9 @@
            Date minDate = new Date(TimeUtil
                  .convertToTimeTemp(ca.get(Calendar.YEAR) + "-" + (ca.get(Calendar.MONTH) + 1), "yyyy-M"));
            long validCount = hongBaoV2Mapper.countInviteOrderCountByUidAndSettleTime(uid, CommonOrder.STATE_JS,
                  minDate, maxDate);
                  minDate, maxDate, Constant.SOURCE_TYPE_TAOBAO);
            long weiQuanCount = hongBaoV2Mapper.countInviteOrderCountByUidAndSettleTime(uid, CommonOrder.STATE_WQ,
                  minDate, maxDate);
                  minDate, maxDate, Constant.SOURCE_TYPE_TAOBAO);
            UserMoneyDetail userMoneyDetail = UserMoneyDetailFactory.createInvite(uid, Constant.SOURCE_TYPE_TAOBAO,
                  (int) validCount, (int) weiQuanCount, invitemoney, new Date());
@@ -708,9 +715,9 @@
            Date minDate = new Date(TimeUtil
                  .convertToTimeTemp(ca.get(Calendar.YEAR) + "-" + (ca.get(Calendar.MONTH) + 1), "yyyy-M"));
            long validCount = hongBaoV2Mapper.countInviteOrderCountByUidAndSettleTime(uid, CommonOrder.STATE_JS,
                  minDate, maxDate);
                  minDate, maxDate, sourceType);
            long weiQuanCount = hongBaoV2Mapper.countInviteOrderCountByUidAndSettleTime(uid, CommonOrder.STATE_WQ,
                  minDate, maxDate);
                  minDate, maxDate, sourceType);
            UserMoneyDetail userMoneyDetail = UserMoneyDetailFactory.createInvite(uid, sourceType, (int) validCount,
                  (int) weiQuanCount, invitemoney, new Date());
@@ -806,9 +813,9 @@
            Date minDate = new Date(TimeUtil
                  .convertToTimeTemp(ca.get(Calendar.YEAR) + "-" + (ca.get(Calendar.MONTH) + 1), "yyyy-M"));
            long validCount = hongBaoV2Mapper.countShareOrderCountByUidAndSettleTime(uid, CommonOrder.STATE_JS,
                  minDate, maxDate);
                  minDate, maxDate, Constant.SOURCE_TYPE_TAOBAO);
            long weiQuanCount = hongBaoV2Mapper.countShareOrderCountByUidAndSettleTime(uid, CommonOrder.STATE_WQ,
                  minDate, maxDate);
                  minDate, maxDate, Constant.SOURCE_TYPE_TAOBAO);
            UserMoneyDetail userMoneyDetail = UserMoneyDetailFactory.createShare(uid, Constant.SOURCE_TYPE_TAOBAO,
                  (int) validCount, (int) weiQuanCount, sharemoney, new Date());
@@ -904,12 +911,12 @@
            Date minDate = new Date(TimeUtil
                  .convertToTimeTemp(ca.get(Calendar.YEAR) + "-" + (ca.get(Calendar.MONTH) + 1), "yyyy-M"));
            long validCount = hongBaoV2Mapper.countShareOrderCountByUidAndSettleTime(uid, CommonOrder.STATE_JS,
                  minDate, maxDate);
                  minDate, maxDate, sourceType);
            long weiQuanCount = hongBaoV2Mapper.countShareOrderCountByUidAndSettleTime(uid, CommonOrder.STATE_WQ,
                  minDate, maxDate);
                  minDate, maxDate, sourceType);
            UserMoneyDetail userMoneyDetail = UserMoneyDetailFactory.createShare(uid, Constant.SOURCE_TYPE_TAOBAO,
                  (int) validCount, (int) weiQuanCount, sharemoney, new Date());
            UserMoneyDetail userMoneyDetail = UserMoneyDetailFactory.createShare(uid, sourceType, (int) validCount,
                  (int) weiQuanCount, sharemoney, new Date());
            // 添加资金
            userMoneyService.addUserMoney(uid, sharemoney, userMoneyDetail);
@@ -961,7 +968,7 @@
         for (HongBaoV2SettleTemp temp : list) {
            Long hongBaoId = temp.getHongBaoId();
            HongBaoV2 hongBao = hongBaoV2Mapper.selectByPrimaryKey(hongBaoId);
            if (sourceType != null)
            if (hongBao != null)
               sourceType = hongBao.getOrderType();
            if (hongBao.getParent() != null)
               hongBao = hongBao.getParent();
@@ -1018,7 +1025,9 @@
            }
            // 添加资金
            userMoneyService.addUserMoney(uid, totalMoney, userMoneyDetail);
            // TODO 添加消息
            // 添加消息
            userMoneyMsgNotificationService.inviteOrderSubSidy(uid, new Date(), "系统自动下发", totalMoney,
                  userInfoMapper.selectAvailableByPrimaryKey(uid).getMyHongBao());
         }
      }
   }