From d960fdbfe07a65cb80ccb764bfb15ce78ebfd84a Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期五, 10 四月 2020 18:21:04 +0800 Subject: [PATCH] 消息修改 --- fanli/src/main/java/com/yeshi/fanli/service/impl/order/OrderMoneySettleServiceImpl.java | 150 +++++++++++++++++++++++++++----------------------- 1 files changed, 81 insertions(+), 69 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/order/OrderMoneySettleServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/order/OrderMoneySettleServiceImpl.java index 538ba34..88133fd 100644 --- a/fanli/src/main/java/com/yeshi/fanli/service/impl/order/OrderMoneySettleServiceImpl.java +++ b/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; @@ -36,7 +37,6 @@ import com.yeshi.fanli.entity.order.HongBaoOrder; import com.yeshi.fanli.entity.order.HongBaoV2SettleTemp; import com.yeshi.fanli.entity.order.InviteOrderSubsidy; -import com.yeshi.fanli.entity.taobao.TaoBaoOrder; import com.yeshi.fanli.entity.taobao.TaoBaoWeiQuanOrder; import com.yeshi.fanli.exception.money.InviteOrderSubsidyDebtException; import com.yeshi.fanli.exception.money.OrderMoneySettleException; @@ -59,8 +59,8 @@ 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; @Service public class OrderMoneySettleServiceImpl implements OrderMoneySettleService { @@ -112,7 +112,16 @@ @Resource private HongBaoV2SettleTempService hongBaoV2SettleTempService; - @Transactional + // 涓嬬骇琚皝绂侊紝绾㈠寘澶辨晥 + private void invalidHongBaoForbidden(Long id) { + HongBaoV2 updateHongBaoV2 = new HongBaoV2(id); + updateHongBaoV2.setState(HongBaoV2.STATE_SHIXIAO); + updateHongBaoV2.setBeizhu("灏佺澶辨晥"); + updateHongBaoV2.setUpdateTime(new Date()); + hongBaoV2Mapper.updateByPrimaryKeySelective(updateHongBaoV2); + } + + @Transactional(rollbackFor = Exception.class) @Override public void inviteSettleTB(Long uid) throws OrderMoneySettleException { // 鏌ヨUID鐨勪竴浜岀骇閭�璇疯禋 @@ -143,6 +152,7 @@ // 涓婄骇鐢ㄦ埛涓嶆槸姝e父鐢ㄦ埛锛岃鍗曞潎涓嶈兘鍒拌处 UserInfo userInfo = userInfoMapper.selectAvailableByPrimaryKey(co.getUserInfo().getId()); if (userInfo == null || userInfo.getState() != UserInfo.STATE_NORMAL) { + invalidHongBaoForbidden(item.getId()); hongBaoList.remove(i); i--; } @@ -152,9 +162,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,9 +184,10 @@ } catch (Exception e) { LogHelper.mqError(e.getMessage(), msg.getTopic(), msg.getTag(), new Gson().toJson(mqMsg)); } + System.out.println(new Gson().toJson(mqMsg)); } - @Transactional + @Transactional(rollbackFor = Exception.class) @Override public void inviteSettleJD(Long uid) throws OrderMoneySettleException { // 鏌ヨUID鐨勪竴浜岀骇閭�璇疯禋 @@ -206,6 +218,7 @@ // 涓婄骇鐢ㄦ埛涓嶆槸姝e父鐢ㄦ埛锛岃鍗曞潎涓嶈兘鍒拌处 UserInfo userInfo = userInfoMapper.selectAvailableByPrimaryKey(co.getUserInfo().getId()); if (userInfo == null || userInfo.getState() != UserInfo.STATE_NORMAL) { + invalidHongBaoForbidden(item.getId()); hongBaoList.remove(i); i--; } @@ -215,9 +228,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); // 娣诲姞浜嬪姟娑堟伅 @@ -234,7 +247,7 @@ } } - @Transactional + @Transactional(rollbackFor = Exception.class) @Override public void inviteSettlePDD(Long uid) throws OrderMoneySettleException { // 鏌ヨUID鐨勪竴浜岀骇閭�璇疯禋 @@ -265,6 +278,7 @@ // 涓婄骇鐢ㄦ埛涓嶆槸姝e父鐢ㄦ埛锛岃鍗曞潎涓嶈兘鍒拌处 UserInfo userInfo = userInfoMapper.selectAvailableByPrimaryKey(co.getUserInfo().getId()); if (userInfo == null || userInfo.getState() != UserInfo.STATE_NORMAL) { + invalidHongBaoForbidden(item.getId()); hongBaoList.remove(i); i--; } @@ -274,9 +288,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); // 娣诲姞浜嬪姟娑堟伅 @@ -293,7 +307,7 @@ } } - @Transactional + @Transactional(rollbackFor = Exception.class) @Override public void shareSettleTB(Long uid) throws OrderMoneySettleException { /** @@ -315,11 +329,12 @@ 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); + // 娣诲姞浜嬪姟娑堟伅 try { orderTransactionProducer.send(msg, new LocalTransactionExecuter() { @@ -338,7 +353,7 @@ } } - @Transactional + @Transactional(rollbackFor = Exception.class) @Override public void shareSettleJD(Long uid) throws OrderMoneySettleException { /** @@ -360,9 +375,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); // 娣诲姞浜嬪姟娑堟伅 @@ -379,7 +394,7 @@ } } - @Transactional + @Transactional(rollbackFor = Exception.class) @Override public void shareSettlePDD(Long uid) throws OrderMoneySettleException { /** @@ -401,9 +416,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); // 娣诲姞浜嬪姟娑堟伅 @@ -420,7 +435,7 @@ } } - @Transactional + @Transactional(rollbackFor = Exception.class) @Override public void ziGouSettle(String orderId, int sourceType, String taskKey) throws OrderMoneySettleException { // 鏌ヨ鍚屼竴璁㈠崟鍙风殑绾㈠寘 @@ -463,6 +478,25 @@ userHongBao.put(uid, new ArrayList<>()); userHongBao.get(uid).add(hb); } + } + } + + // 鑾峰彇缁存潈璧勯噾 + if (sourceType == Constant.SOURCE_TYPE_TAOBAO) { + try { + Map<Long, BigDecimal> userSubMoneyMap = taoBaoWeiQuanDrawBackService.doWeiQuanFanli(orderId, false); + if (userSubMoneyMap != null) { + for (Iterator<Long> its = userMoney.keySet().iterator(); its.hasNext();) { + Long uid = its.next(); + if (userSubMoneyMap.get(uid) != null) { + // 鍑忓幓缁存潈璧勯噾 + userMoney.put(uid, userMoney.get(uid).subtract(userSubMoneyMap.get(uid))); + } + } + } + } catch (Exception e) { + LogHelper.errorDetailInfo(e); + throw new OrderMoneySettleException(2, "缁存潈璁㈠崟鍑洪敊"); } } @@ -509,39 +543,15 @@ UserInfo user = userInfoMapper.selectByPrimaryKey(uid); // 鏂扮増閫氱煡 + userMoneyMsgNotificationService.fanliOrderReceived(uid, orderId, sourceType, userGoodsCount.get(uid), money, - user.getMyHongBao()); + user.getMyHongBao(), orderList.get(0).getThirdCreateTime()); } // 閫氱煡鍏嶅崟鍒拌处 try { userSystemCouponService.updateStateByArrivalAccount(orderId); } catch (Exception e) { e.printStackTrace(); - } - - // 缁存潈鎵f锛�2018-08-05鍚庡紑濮嬪疄琛岋級 - - try { - if (sourceType == Constant.SOURCE_TYPE_TAOBAO) - taoBaoWeiQuanDrawBackService.doWeiQuanFanli(orderId); - } catch (TaoBaoWeiQuanException e) { - if (e.getCode() == TaoBaoWeiQuanException.CODE_NEDD_UPDATE_ORDER) { - List<TaoBaoOrder> olist = taoBaoOrderService.getTaoBaoOrderByOrderId(orderId); - if (olist != null && olist.size() > 0) { - long time = TimeUtil.convertToTimeTemp(olist.get(0).getCreateTime(), "yyyy-MM-dd HH:mm:ss"); - olist = TaoKeOrderApiUtil.getTaoBaoCommonOrderList(time, time + 1000 * 2L, 1); - if (olist != null && olist.size() > 0) { - for (int i = 0; i < olist.size(); i++) { - if (!olist.get(i).getOrderId().equalsIgnoreCase(orderId)) {// 鍒犻櫎鏃犲叧璁㈠崟 - olist.remove(i); - i--; - } - } - taoBaoOrderService.addTaoBaoOrderList(olist); - } - } - } else - throw new OrderMoneySettleException(e.getCode(), "缁存潈澶勭悊鍑洪敊:" + e.getMsg()); } // 娣诲姞缁撶畻鏄犲皠 @@ -572,7 +582,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); @@ -625,9 +635,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()); @@ -711,9 +721,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()); @@ -809,9 +819,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()); @@ -832,7 +842,8 @@ // 鏂扮増閫氱煡 userMoneyMsgNotificationService.shareOrderReceived(uid, Constant.SOURCE_TYPE_TAOBAO, shareOrders.size(), - shareGoodsCount, sharemoney, userInfoMapper.selectAvailableByPrimaryKey(uid).getMyHongBao()); + shareGoodsCount, sharemoney, userInfoMapper.selectAvailableByPrimaryKey(uid).getMyHongBao(), null, + null); for (String orderId : drawBackOrders) taoBaoWeiQuanDrawBackService.doWeiQuanShare(orderId); @@ -907,12 +918,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); @@ -930,8 +941,8 @@ // 鏂扮増閫氱煡 userMoneyMsgNotificationService.shareOrderReceived(uid, Constant.SOURCE_TYPE_TAOBAO, shareOrders.size(), - shareGoodsCount, sharemoney, userInfoMapper.selectAvailableByPrimaryKey(uid).getMyHongBao()); - + shareGoodsCount, sharemoney, userInfoMapper.selectAvailableByPrimaryKey(uid).getMyHongBao(), null, + null); } hongBaoV2SettleTempService.addTemp(recieveHongBaoIds, key); @@ -952,7 +963,7 @@ * @param orderId * @param sourceType */ - @Transactional + @Transactional(rollbackFor = Exception.class) @Override public void inviteSubsidySettle(Long uid, String taskKey) throws OrderMoneySettleException { // 鏌ヨkey @@ -1054,4 +1065,5 @@ } return debtMoney; } + } -- Gitblit v1.8.0