From 0f704a4650edd60cea2e57778b6703509376a42c Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期五, 08 三月 2024 17:48:09 +0800
Subject: [PATCH] 京东API(大淘客补充)优化/日志优化

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/order/OrderMoneySettleServiceImpl.java |   70 ++++++++++++++++++++++++++--------
 1 files changed, 53 insertions(+), 17 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 d6d5432..c707697 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
@@ -13,6 +13,8 @@
 
 import javax.annotation.Resource;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -64,6 +66,8 @@
 @Service
 public class OrderMoneySettleServiceImpl implements OrderMoneySettleService {
 
+    Logger logger = LoggerFactory.getLogger(OrderMoneySettleService.class);
+
     @Resource
     private HongBaoV2Mapper hongBaoV2Mapper;
 
@@ -112,8 +116,16 @@
     private RocketMQManager rocketMQManager;
 
     // 涓嬬骇琚皝绂侊紝绾㈠寘澶辨晥
-    private void invalidHongBaoForbidden(Long id) {
-        HongBaoV2 updateHongBaoV2 = new HongBaoV2(id);
+    private void invalidHongBaoForbidden(HongBaoV2 hongBaoV2) throws TeamRewardDebtException {
+        if (hongBaoV2.getState() == HongBaoV2.STATE_SHIXIAO || hongBaoV2.getState() == HongBaoV2.STATE_YILINGQU || hongBaoV2.getState() == HongBaoV2.STATE_LINGQUING)
+            return;
+        //濡傛灉鍦ㄥ伩杩橀噷闈㈠氨鍏堝伩杩橈紝鐒跺悗鍐嶅け鏁�
+        TeamRewardDebt debt = teamRewardDebtService.selectBySourceId(hongBaoV2.getId());
+        if (debt != null && debt.getLeftMoney().compareTo(hongBaoV2.getMoney()) <= 0) {
+            teamRewardDebtService.repayDebt(debt.getId(), hongBaoV2.getMoney(), "灏佺澶辨晥锛屽厛鍋胯繕鍐嶅け鏁�");
+        }
+
+        HongBaoV2 updateHongBaoV2 = new HongBaoV2(hongBaoV2.getId());
         updateHongBaoV2.setState(HongBaoV2.STATE_SHIXIAO);
         updateHongBaoV2.setBeizhu("灏佺澶辨晥");
         updateHongBaoV2.setUpdateTime(new Date());
@@ -125,7 +137,7 @@
     public void inviteSettleTB(Long uid, Date maxPregetTime) throws OrderMoneySettleException {
         // 鏌ヨUID鐨勪竴浜岀骇閭�璇疯禋
         int sourceType = Constant.SOURCE_TYPE_TAOBAO;
-        inviteSettle(uid,sourceType,maxPregetTime);
+        inviteSettle(uid, sourceType, maxPregetTime);
     }
 
     @Transactional(rollbackFor = Exception.class)
@@ -133,7 +145,7 @@
     public void inviteSettleJD(Long uid, Date maxPregetTime) throws OrderMoneySettleException {
         // 鏌ヨUID鐨勪竴浜岀骇閭�璇疯禋
         int sourceType = Constant.SOURCE_TYPE_JD;
-        inviteSettle(uid,sourceType,maxPregetTime);
+        inviteSettle(uid, sourceType, maxPregetTime);
     }
 
     @Transactional(rollbackFor = Exception.class)
@@ -141,7 +153,7 @@
     public void inviteSettlePDD(Long uid, Date maxPregetTime) throws OrderMoneySettleException {
         // 鏌ヨUID鐨勪竴浜岀骇閭�璇疯禋
         int sourceType = Constant.SOURCE_TYPE_PDD;
-        inviteSettle(uid,sourceType,maxPregetTime);
+        inviteSettle(uid, sourceType, maxPregetTime);
     }
 
     @Transactional(rollbackFor = Exception.class)
@@ -149,7 +161,14 @@
     public void inviteSettleVipShop(Long uid, Date maxPregetTime) throws OrderMoneySettleException {
         // 鏌ヨUID鐨勪竴浜岀骇閭�璇疯禋
         int sourceType = Constant.SOURCE_TYPE_VIP;
-        inviteSettle(uid,sourceType,maxPregetTime);
+        inviteSettle(uid, sourceType, maxPregetTime);
+    }
+
+    @Override
+    public void inviteSettleDY(Long uid, Date maxPregetTime) throws OrderMoneySettleException {
+        // 鏌ヨUID鐨勪竴浜岀骇閭�璇疯禋
+        int sourceType = Constant.SOURCE_TYPE_DY;
+        inviteSettle(uid, sourceType, maxPregetTime);
     }
 
 
@@ -158,7 +177,7 @@
     public void inviteSettleSuning(Long uid, Date maxPregetTime) throws OrderMoneySettleException {
         // 鏌ヨUID鐨勪竴浜岀骇閭�璇疯禋
         int sourceType = Constant.SOURCE_TYPE_SUNING;
-        inviteSettle(uid,sourceType,maxPregetTime);
+        inviteSettle(uid, sourceType, maxPregetTime);
     }
 
 
@@ -190,7 +209,11 @@
                         // 涓婄骇鐢ㄦ埛涓嶆槸姝e父鐢ㄦ埛锛岃鍗曞潎涓嶈兘鍒拌处
                         UserInfo userInfo = userInfoMapper.selectAvailableByPrimaryKey(co.getUserInfo().getId());
                         if (userInfo == null || userInfo.getState() != UserInfo.STATE_NORMAL) {
-                            invalidHongBaoForbidden(item.getId());
+                            try {
+                                invalidHongBaoForbidden(item);
+                            } catch (TeamRewardDebtException e) {
+                                throw new OrderMoneySettleException(10, "鍋胯繕鍑洪敊");
+                            }
                             hongBaoList.remove(i);
                             i--;
                         }
@@ -260,7 +283,7 @@
                 @Override
                 public TransactionStatus execute(Message arg0, Object arg1) {
                     try {
-                        fanLiShareTB(hongBaoList, uid, taskKey);
+                        fanLiShareTB(hongBaoList, uid, taskKey,maxPregetTime);
                     } catch (TaoBaoWeiQuanException e) {
                         return TransactionStatus.RollbackTransaction;
                     }
@@ -304,7 +327,7 @@
             orderTransactionProducer.send(msg, new LocalTransactionExecuter() {
                 @Override
                 public TransactionStatus execute(Message arg0, Object arg1) {
-                    fanLiShareOther(hongBaoList, uid, sourceType, taskKey);
+                    fanLiShareOther(hongBaoList, uid, sourceType, taskKey,maxPregetTime);
                     return TransactionStatus.CommitTransaction;
                 }
             }, null);
@@ -329,6 +352,11 @@
     @Override
     public void shareSettleSuning(Long uid, Date maxPregetTime) throws OrderMoneySettleException {
         shareSettle(Constant.SOURCE_TYPE_SUNING, uid, maxPregetTime);
+    }
+
+    @Override
+    public void shareSettleDY(Long uid, Date maxPregetTime) throws OrderMoneySettleException {
+        shareSettle(Constant.SOURCE_TYPE_DY, uid, maxPregetTime);
     }
 
     private void shareSettle(int sourceType, Long uid, Date maxPregetTime) throws OrderMoneySettleException {
@@ -360,7 +388,7 @@
             orderTransactionProducer.send(msg, new LocalTransactionExecuter() {
                 @Override
                 public TransactionStatus execute(Message arg0, Object arg1) {
-                    fanLiShareOther(hongBaoList, uid, sourceType, taskKey);
+                    fanLiShareOther(hongBaoList, uid, sourceType, taskKey,maxPregetTime);
                     return TransactionStatus.CommitTransaction;
                 }
             }, null);
@@ -380,6 +408,9 @@
         Map<Long, Integer> userGoodsCount = new HashMap<>();
         for (CommonOrder co : orderList) {
             HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByCommonOrderId(co.getId());
+            if (hongBaoOrder == null) {
+                continue;
+            }
             hongBaoList.add(hongBaoOrder.getHongBaoV2());
             Long uid = co.getUserInfo().getId();
             if (userGoodsCount.get(uid) == null)
@@ -518,6 +549,7 @@
 
     private void fanliInvite(List<HongBaoV2> hongBaoList, Long uid, int sourceType, String key, Date maxPreGetTime)
             throws TeamEincomeRecordException, ParamsException, TeamRewardDebtException {
+        logger.info("閭�璇峰閲戦鍒拌处锛歶id-{} sourceType-{} key-{}", new Object[]{uid, sourceType, key});
         List<Long> hbIdList = new ArrayList<>();
         BigDecimal invitemoney = new BigDecimal(0);
         Set<String> inviteOrders = new HashSet<>();
@@ -529,15 +561,17 @@
                 continue;
             hongBao = hongBaoV2Mapper.selectByPrimaryKeyForUpdate(hongBao.getId());
             if (hongBao.getState() == HongBaoV2.STATE_BUKELINGQU || hongBao.getState() == HongBaoV2.STATE_KELINGQU) {
+                logger.info("閭�璇峰閲戦鍒拌处-姣忎釜绾㈠寘-鍒拌处寮�濮嬶細hongbaoid-{}", hongBao.getId());
                 TeamRewardDebt debt = teamRewardDebtService.selectBySourceId(hongBao.getId());
                 BigDecimal money = hongBao.getMoney();
                 if (debt != null && debt.getLeftMoney().compareTo(new BigDecimal(0)) > 0
                         && money.compareTo(debt.getLeftMoney()) >= 0) {
                     money = money.subtract(debt.getLeftMoney());
                     // 杩橀挶
-                    teamRewardDebtService.repayDebt(debt.getId(), debt.getLeftMoney());
+                    teamRewardDebtService.repayDebt(debt.getId(), debt.getLeftMoney(), null);
+                    logger.info("閭�璇峰閲戦鍒拌处-姣忎釜绾㈠寘-杩樻锛歨ongbaoid-{} debtId-{} debtMoney-{}", new Object[]{hongBao.getId(), debt.getId(), debt.getLeftMoney()});
                 }
-
+                logger.info("閭�璇峰閲戦鍒拌处-姣忎釜绾㈠寘锛歨ongbaoid-{} money-{}", new Object[]{hongBao.getId(), money});
                 invitemoney = invitemoney.add(money);
                 HongBaoV2 updateHongBao = new HongBaoV2();
                 updateHongBao.setId(hongBao.getId());
@@ -549,6 +583,7 @@
                 hbIdList.add(hongBao.getId());
                 HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByHongBaoId(hongBao.getParent().getId());
                 inviteOrders.add(hongBaoOrder.getCommonOrder().getOrderNo());
+                logger.info("閭�璇峰閲戦鍒拌处-姣忎釜绾㈠寘-鍒拌处鎴愬姛锛歨ongbaoid-{}", hongBao.getId());
             }
         }
 
@@ -556,6 +591,7 @@
         if (invitemoney.compareTo(new BigDecimal(0)) > 0) {
             // 鑾峰彇褰撳墠鐨勬湀浠�
             teamRewardManager.addToEincome(uid, maxPreGetTime, invitemoney, sourceType);
+            logger.info("閭�璇峰閲戦鍒拌处-娣诲姞鍒板洟闃熸敹鐩婃垚鍔燂細uid-{} day-{} money-{} sourceType-{}", new Object[]{uid, maxPreGetTime, invitemoney, sourceType});
         }
 
         hongBaoV2SettleTempService.addTemp(hbIdList, key);
@@ -578,7 +614,7 @@
      * @param uid
      * @throws TaoBaoWeiQuanException
      */
-    private void fanLiShareTB(List<HongBaoV2> hongBaoList, Long uid, String key) throws TaoBaoWeiQuanException {
+    private void fanLiShareTB(List<HongBaoV2> hongBaoList, Long uid, String key,Date recieveMonth) throws TaoBaoWeiQuanException {
         BigDecimal sharemoney = new BigDecimal(0);
         List<Long> hbIdList = new ArrayList<>();
         Set<String> drawBackOrders = new HashSet<String>();
@@ -623,7 +659,7 @@
             // 娣诲姞鏂扮増璇︽儏璁板綍
             try {
                 UserMoneyDetail userMoneyDetail = UserMoneyDetailFactory.createShare(uid, Constant.SOURCE_TYPE_TAOBAO,
-                        sharemoney, new Date());
+                        sharemoney,recieveMonth);
                 // 娣诲姞璧勯噾
                 userMoneyService.addUserMoney(uid, sharemoney, userMoneyDetail);
 
@@ -668,7 +704,7 @@
      * @param uid
      * @param sourceType
      */
-    private void fanLiShareOther(List<HongBaoV2> hongBaoList, Long uid, int sourceType, String key) {
+    private void fanLiShareOther(List<HongBaoV2> hongBaoList, Long uid, int sourceType, String key,Date recieveMonth) {
         BigDecimal sharemoney = new BigDecimal(0);
         List<Long> hbIdList = new ArrayList<>();
         List<Long> recieveHongBaoIds = new ArrayList<>();
@@ -704,7 +740,7 @@
             // 娣诲姞鏂扮増璇︽儏璁板綍
             try {
                 UserMoneyDetail userMoneyDetail = UserMoneyDetailFactory.createShare(uid, sourceType, sharemoney,
-                        new Date());
+                        recieveMonth);
                 // 娣诲姞璧勯噾
                 userMoneyService.addUserMoney(uid, sharemoney, userMoneyDetail);
 

--
Gitblit v1.8.0