Sfoglia il codice sorgente

Merge branch 'dev/2024/0425/update-admin' of Harper/feifan-backend-zx-admin into master

更新合赢奖的计算
Yangzw 10 mesi fa
parent
commit
ba716b77b0

+ 115 - 124
feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/service/partitioncrash/PartitionCrashServiceImpl.java

@@ -6,7 +6,6 @@ import cn.newfeifan.mall.module.distri.controller.admin.integral.vo.IntegralSave
 import cn.newfeifan.mall.module.distri.controller.admin.partitionbrothers.vo.PartitionBrothersSaveReqVO;
 import cn.newfeifan.mall.module.distri.controller.admin.partitionson.vo.PartitionSonSaveReqVO;
 import cn.newfeifan.mall.module.distri.controller.admin.ptprofit.vo.PtProfitSaveReqVO;
-import cn.newfeifan.mall.module.distri.controller.admin.sharepath.vo.SharePathSaveReqVO;
 import cn.newfeifan.mall.module.distri.dal.dataobject.duser.DuserDO;
 import cn.newfeifan.mall.module.distri.dal.dataobject.integral.IntegralDO;
 import cn.newfeifan.mall.module.distri.dal.dataobject.ordercalc.OrderCalcDO;
@@ -38,7 +37,6 @@ import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.time.LocalTime;
 import java.util.*;
-import java.util.concurrent.CompletableFuture;
 import java.util.stream.Collectors;
 
 import cn.newfeifan.mall.module.distri.controller.admin.partitioncrash.vo.*;
@@ -160,11 +158,11 @@ public class PartitionCrashServiceImpl implements PartitionCrashService {
         // 获取当前所有用户的父亲
         Map<Long, Long> sonAndParent = new HashMap<>();
         List<Long> userIds = duserDOS.stream().map(DuserDO::getUserId).collect(Collectors.toList());
-        userIds.stream().map(k -> CompletableFuture.supplyAsync(() -> {
+
+        userIds.forEach(k -> {
             Long parent = sharePathService.queryParentBySonUserId(k);
             sonAndParent.put(k, parent);
-            return parent;
-        })).collect(Collectors.toList()).stream().map(CompletableFuture::join).collect(Collectors.toList());
+        });
 
         List<PartitionSonSaveReqVO> partitionSonSaveReqVOS = new ArrayList<>();
         List<PartitionBrothersSaveReqVO> partitionBrothersSaveReqVOS = new ArrayList<>();
@@ -176,141 +174,134 @@ public class PartitionCrashServiceImpl implements PartitionCrashService {
             // 获取当前父亲的钱包
             Long parent = sonAndParent.get(k.getUserId());
             IntegralDO parentIntegralDo = integralDOMap.get(parent);
+            if (parentIntegralDo != null) {
+
+                // 创建一个分区编号
+                String todayNo = crashTodayNo(k.getUserId());
+                String yesterdayNo = crashYesterdayNo(k.getUserId());
+
+                PartitionSonSaveReqVO.PartitionSonSaveReqVOBuilder sonBuilder = PartitionSonSaveReqVO.builder();
+                PartitionBrothersSaveReqVO.PartitionBrothersSaveReqVOBuilder brotherBuilder = PartitionBrothersSaveReqVO.builder();
+                PartitionCrashSaveReqVO.PartitionCrashSaveReqVOBuilder crashSaveReqVOBuilder = PartitionCrashSaveReqVO.builder();
+                sonBuilder.partNo(todayNo);
+                sonBuilder.userId(k.getUserId());
+                sonBuilder.name(k.getName());
+                sonBuilder.nickName(k.getNickName());
+                sonBuilder.hasHit(1);
+
+                brotherBuilder.partNo(todayNo);
+                brotherBuilder.userId(k.getUserId());
+                brotherBuilder.name(k.getName());
+                brotherBuilder.nickName(k.getNickName());
+                brotherBuilder.hasHit(1);
+
+
+                crashSaveReqVOBuilder.partNo(todayNo);
+                crashSaveReqVOBuilder.nickName(k.getNickName());
+                crashSaveReqVOBuilder.userName(k.getName());
+
+                // 获取当前用户的后代分区 , 并且该分区存在有下单的用户
+                List<OrderCalcDO> sonOrderCalcDOS = sharePathService.selectSons(k.getUserId(), userId);
+                if (sonOrderCalcDOS.isEmpty()) {
+                    // 插入空数据
+                    sonBuilder = addSonEmpty(sonBuilder, k);
+                    crashSaveReqVOBuilder.sonPrice(0L);
+                }
+                // 合计儿子分支额度
+                double grossProfitBonusQuotaPerc = Double.parseDouble(orderPercentageDO.getGrossProfitBonusQuotaPerc());
+                Long sonSumPrice = (long) (sonOrderCalcDOS.stream().mapToLong(OrderCalcDO::getGrossProfit).sum() * grossProfitBonusQuotaPerc);
+                sonBuilder.price(sonSumPrice);
+
+                // 获取当前用户的兄弟分区
+                List<OrderCalcDO> brothersOrderCalcDOS = sharePathService.selectBrothers(k.getUserId(), userId);
+                if (brothersOrderCalcDOS.isEmpty()) {
+                    // 插入空数据
+                    brotherBuilder = addBrotherEmpty(brotherBuilder, k);
+                    crashSaveReqVOBuilder.brotherPrice(0L);
+                }
 
-            if (parentIntegralDo == null) {
-                sharePathService.createSharePath(SharePathSaveReqVO.builder()
-                        .ancestor(PT_ID)
-                        .descendant(k.getUserId())
-                        .build());
-                parentIntegralDo = integralDOMap.get(PT_ID);
-            }
-
+                // 合并兄弟分支额度
+                Long brotherSumPrice = (long) (brothersOrderCalcDOS.stream().mapToLong(OrderCalcDO::getGrossProfit).sum() * grossProfitBonusQuotaPerc);
+                brotherBuilder.price(brotherSumPrice);
 
-            // 创建一个分区编号
-            String todayNo = crashTodayNo(k.getUserId());
-            String yesterdayNo = crashYesterdayNo(k.getUserId());
-
-            PartitionSonSaveReqVO.PartitionSonSaveReqVOBuilder sonBuilder = PartitionSonSaveReqVO.builder();
-            PartitionBrothersSaveReqVO.PartitionBrothersSaveReqVOBuilder brotherBuilder = PartitionBrothersSaveReqVO.builder();
-            PartitionCrashSaveReqVO.PartitionCrashSaveReqVOBuilder crashSaveReqVOBuilder = PartitionCrashSaveReqVO.builder();
-            sonBuilder.partNo(todayNo);
-            sonBuilder.userId(k.getUserId());
-            sonBuilder.name(k.getName());
-            sonBuilder.nickName(k.getNickName());
-            sonBuilder.hasHit(1);
-
-            brotherBuilder.partNo(todayNo);
-            brotherBuilder.userId(k.getUserId());
-            brotherBuilder.name(k.getName());
-            brotherBuilder.nickName(k.getNickName());
-            brotherBuilder.hasHit(1);
-
-
-            crashSaveReqVOBuilder.partNo(todayNo);
-            crashSaveReqVOBuilder.nickName(k.getNickName());
-            crashSaveReqVOBuilder.userName(k.getName());
-
-            // 获取当前用户的后代分区 , 并且该分区存在有下单的用户
-            List<OrderCalcDO> sonOrderCalcDOS = sharePathService.selectSons(k.getUserId(), userId);
-            if (sonOrderCalcDOS.isEmpty()) {
-                // 插入空数据
-                sonBuilder = addSonEmpty(sonBuilder, k);
-                crashSaveReqVOBuilder.sonPrice(0L);
-            }
-            // 合计儿子分支额度
-            double grossProfitBonusQuotaPerc = Double.parseDouble(orderPercentageDO.getGrossProfitBonusQuotaPerc());
-            Long sonSumPrice = (long) (sonOrderCalcDOS.stream().mapToLong(OrderCalcDO::getGrossProfit).sum() * grossProfitBonusQuotaPerc);
-            sonBuilder.price(sonSumPrice);
-
-            // 获取当前用户的兄弟分区
-            List<OrderCalcDO> brothersOrderCalcDOS = sharePathService.selectBrothers(k.getUserId(), userId);
-            if (brothersOrderCalcDOS.isEmpty()) {
-                // 插入空数据
-                brotherBuilder = addBrotherEmpty(brotherBuilder, k);
-                crashSaveReqVOBuilder.brotherPrice(0L);
-            }
 
-            // 合并兄弟分支额度
-            Long brotherSumPrice = (long) (brothersOrderCalcDOS.stream().mapToLong(OrderCalcDO::getGrossProfit).sum() * grossProfitBonusQuotaPerc);
-            brotherBuilder.price(brotherSumPrice);
+                // 判断,昨天是否有存余的分支
+                PartitionCrashDO yesterdayCrash = partitionCrashMapper.selectOne(new LambdaQueryWrapperX<PartitionCrashDO>().eqIfPresent(PartitionCrashDO::getPartNo, yesterdayNo));
+                // 如果不为空, 则判断增加到哪个分支中
+                if (yesterdayCrash != null) {
+                    if (yesterdayCrash.getSonPrice() >= yesterdayCrash.getBrotherPrice()) {
+                        sonSumPrice = sonSumPrice + yesterdayCrash.getSonPrice();
+                    } else {
+                        brotherSumPrice = brotherSumPrice + yesterdayCrash.getBrotherPrice();
+                    }
+                }
 
+                Long afterCrash = 0L;
+                Long smallQuota = 0L;
+                // 碰撞计算
+                if (sonSumPrice >= brotherSumPrice) {
+                    sonBuilder.size(1);
+                    brotherBuilder.size(0);
+                    afterCrash = sonSumPrice - brotherSumPrice;
+                    smallQuota = brotherSumPrice;
 
-            // 判断,昨天是否有存余的分支
-            PartitionCrashDO yesterdayCrash = partitionCrashMapper.selectOne(new LambdaQueryWrapperX<PartitionCrashDO>().eqIfPresent(PartitionCrashDO::getPartNo, yesterdayNo));
-            // 如果不为空, 则判断增加到哪个分支中
-            if (yesterdayCrash != null) {
-                if (yesterdayCrash.getSonPrice() >= yesterdayCrash.getBrotherPrice()) {
-                    sonSumPrice = sonSumPrice + yesterdayCrash.getSonPrice();
                 } else {
-                    brotherSumPrice = brotherSumPrice + yesterdayCrash.getBrotherPrice();
+                    sonBuilder.size(0);
+                    brotherBuilder.size(1);
+                    afterCrash = brotherSumPrice - sonSumPrice;
+                    smallQuota = sonSumPrice;
                 }
-            }
-
-            Long afterCrash = 0L;
-            Long smallQuota = 0L;
-            // 碰撞计算
-            if (sonSumPrice >= brotherSumPrice) {
-                sonBuilder.size(1);
-                brotherBuilder.size(0);
-                afterCrash = sonSumPrice - brotherSumPrice;
-                smallQuota = brotherSumPrice;
-
-            } else {
-                sonBuilder.size(0);
-                brotherBuilder.size(1);
-                afterCrash = brotherSumPrice - sonSumPrice;
-                smallQuota = sonSumPrice;
-            }
 
 
-            crashSaveReqVOBuilder.brotherPrice(brotherSumPrice);
-            crashSaveReqVOBuilder.sonPrice(sonSumPrice);
-            crashSaveReqVOBuilder.afterHitQuota(afterCrash);
+                crashSaveReqVOBuilder.brotherPrice(brotherSumPrice);
+                crashSaveReqVOBuilder.sonPrice(sonSumPrice);
+                crashSaveReqVOBuilder.afterHitQuota(afterCrash);
 
-            // 积分添加 添加的时候, 需要注意当前用户是否有足够的积分可以获取
-            // 碰撞后的额度的
-            Long highQuota = integralDO.getHighQuota();
-            Long parentHighQuota = parentIntegralDo.getHighQuota();
+                // 积分添加 添加的时候, 需要注意当前用户是否有足够的积分可以获取
+                // 碰撞后的额度的
+                Long highQuota = integralDO.getHighQuota();
+                Long parentHighQuota = parentIntegralDo.getHighQuota();
 
-            BigDecimal smallBigDecimal = new BigDecimal(String.valueOf(smallQuota));
-            BigDecimal multiply = smallBigDecimal.divide(new BigDecimal("2.0"), 4, RoundingMode.DOWN);
-            if (compare(highQuota, multiply)) {
-                integralDO.setCurrentQuota(integralDO.getCurrentQuota() + multiply.intValue());
-                integralDO.setHighQuota(parentIntegralDo.getHighQuota() - multiply.intValue());
-                // 碰撞后的额度添加到日志中 增加日志模块
-                integralService.updateIntegral(BeanUtils.toBean(integralDO, IntegralSaveReqVO.class));
-                ptProfitLogService.addMessage(k.getUserId(), CaclEnum.SMALL_QUOTA_CRASH, Long.parseLong(String.valueOf(multiply.intValue())), integralDO.getCurrentQuota(), JsonUtils.toJsonString(orderPercentageDO));
-            }
-            if (compare(parentHighQuota, multiply)) {
-                // 减去最高额度
-                parentIntegralDo.setCurrentQuota(parentIntegralDo.getCurrentQuota() + multiply.intValue());
-                parentIntegralDo.setHighQuota(parentIntegralDo.getHighQuota() - multiply.intValue());
-                // 碰撞后的额度添加到日志中 增加日志模块
-                integralService.updateIntegral(BeanUtils.toBean(parentIntegralDo, IntegralSaveReqVO.class));
-                ptProfitLogService.addMessage(parentIntegralDo.getUserId(), CaclEnum.SMALL_QUOTA_CRASH, Long.parseLong(String.valueOf(multiply.intValue())), parentIntegralDo.getCurrentQuota(), JsonUtils.toJsonString(orderPercentageDO));
-            }
+                BigDecimal smallBigDecimal = new BigDecimal(String.valueOf(smallQuota));
+                BigDecimal multiply = smallBigDecimal.divide(new BigDecimal("2.0"), 4, RoundingMode.DOWN);
+                if (compare(highQuota, multiply)) {
+                    integralDO.setCurrentQuota(integralDO.getCurrentQuota() + multiply.intValue());
+                    integralDO.setHighQuota(parentIntegralDo.getHighQuota() - multiply.intValue());
+                    // 碰撞后的额度添加到日志中 增加日志模块
+                    integralService.updateIntegral(BeanUtils.toBean(integralDO, IntegralSaveReqVO.class));
+                    ptProfitLogService.addMessage(k.getUserId(), CaclEnum.SMALL_QUOTA_CRASH, Long.parseLong(String.valueOf(multiply.intValue())), integralDO.getCurrentQuota(), JsonUtils.toJsonString(orderPercentageDO));
+                }
+                if (compare(parentHighQuota, multiply)) {
+                    // 减去最高额度
+                    parentIntegralDo.setCurrentQuota(parentIntegralDo.getCurrentQuota() + multiply.intValue());
+                    parentIntegralDo.setHighQuota(parentIntegralDo.getHighQuota() - multiply.intValue());
+                    // 碰撞后的额度添加到日志中 增加日志模块
+                    integralService.updateIntegral(BeanUtils.toBean(parentIntegralDo, IntegralSaveReqVO.class));
+                    ptProfitLogService.addMessage(parentIntegralDo.getUserId(), CaclEnum.SMALL_QUOTA_CRASH, Long.parseLong(String.valueOf(multiply.intValue())), parentIntegralDo.getCurrentQuota(), JsonUtils.toJsonString(orderPercentageDO));
+                }
 
-            // 获取计算后积分, Long为userId, Integer为碰撞后额度
-            HashMap<Long, Long> map = new HashMap<>();
-            // 如果为当前用户为平台,则不需要存入这个地方
-            if (!k.getUserId().equals(PT_ID)) {
-                map.put(k.getUserId(), multiply.longValue());
-            }
-            if (!parentIntegralDo.getUserId().equals(PT_ID)) {
-                map.put(parentIntegralDo.getUserId(), multiply.longValue());
-            }
-            afterCrashMap.add(map);
+                // 获取计算后积分, Long为userId, Integer为碰撞后额度
+                HashMap<Long, Long> map = new HashMap<>();
+                // 如果为当前用户为平台,则不需要存入这个地方
+                if (!k.getUserId().equals(PT_ID)) {
+                    map.put(k.getUserId(), multiply.longValue());
+                }
+                if (!parentIntegralDo.getUserId().equals(PT_ID)) {
+                    map.put(parentIntegralDo.getUserId(), multiply.longValue());
+                }
+                afterCrashMap.add(map);
 
-            log.info(k.getNickName() + "用户合赢奖已经计算: 该用户合赢奖为: \t" +
-                    "兄弟分区为: " + brotherBuilder.build() + "\t" +
-                    "后代分区为: " + sonBuilder.build() + "\t" +
-                    "碰撞分区为: " + crashSaveReqVOBuilder.build() + "\t");
+                log.info(k.getNickName() + "用户合赢奖已经计算: 该用户合赢奖为: \t" +
+                        "兄弟分区为: " + brotherBuilder.build() + "\t" +
+                        "后代分区为: " + sonBuilder.build() + "\t" +
+                        "碰撞分区为: " + crashSaveReqVOBuilder.build() + "\t");
 
-            partitionSonSaveReqVOS.add(sonBuilder.build());
-            partitionBrothersSaveReqVOS.add(brotherBuilder.build());
-            partitionCrashSaveReqVOS.add(crashSaveReqVOBuilder.build());
+                partitionSonSaveReqVOS.add(sonBuilder.build());
+                partitionBrothersSaveReqVOS.add(brotherBuilder.build());
+                partitionCrashSaveReqVOS.add(crashSaveReqVOBuilder.build());
 
 
+            }
         });
 
         partitionSonService.saveBatch(partitionSonSaveReqVOS);

+ 17 - 10
feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/service/sharepath/SharePathServiceImpl.java

@@ -125,7 +125,7 @@ public class SharePathServiceImpl implements SharePathService {
     }
 
     private Boolean hasParent(Long descendant) {
-        SharePathDO sharePathDO = sharePathMapper.selectOne(new LambdaQueryWrapperX<SharePathDO>()
+        List<SharePathDO> sharePathDO = sharePathMapper.selectList(new LambdaQueryWrapperX<SharePathDO>()
                 .eqIfPresent(SharePathDO::getDescendant, descendant)
                 .eqIfPresent(SharePathDO::getDepth, 1));
         return sharePathDO != null;
@@ -220,10 +220,10 @@ public class SharePathServiceImpl implements SharePathService {
                 .eq(SharePathDO::getDescendant, userId)
                 .eq(SharePathDO::getDepth, 1)
         );
-        if(sharePathDO != null) memberUserRespVO.setAncNickName(sharePathDO.getAncName());
+        if (sharePathDO != null) memberUserRespVO.setAncNickName(sharePathDO.getAncName());
 
         IntegralDO integral = integralService.getIntegralByUserId(userId);
-        if(integral != null) memberUserRespVO.setCurrentQuota(integral.getCurrentQuota());
+        if (integral != null) memberUserRespVO.setCurrentQuota(integral.getCurrentQuota());
 
         return memberUserRespVO;
     }
@@ -329,14 +329,14 @@ public class SharePathServiceImpl implements SharePathService {
     public List<OrderCalcDO> selectBrothers(Long userId, List<Long> userIds) {
         List<Long> sortedSiblings = new ArrayList<>();
         // 先查询出他的父亲
-        SharePathDO sharePathDO = sharePathMapper.selectOne(new LambdaQueryWrapperX<SharePathDO>().eq(SharePathDO::getDepth, 1).eq(SharePathDO::getDescendant, userId));
-        if (sharePathDO == null) {
+        List<SharePathDO> sharePathDO = sharePathMapper.selectList(new LambdaQueryWrapperX<SharePathDO>().eq(SharePathDO::getDepth, 1).eq(SharePathDO::getDescendant, userId));
+        if (sharePathDO.isEmpty()) {
             sortedSiblings = sharePathMapper.findLessSortedSiblings(userId);
         } else {
             // 再根据父亲查询他的所有儿子
             List<SharePathDO> sharePathDOS = sharePathMapper.selectList(new LambdaQueryWrapperX<SharePathDO>()
                     .eq(SharePathDO::getDepth, 1)
-                    .eq(SharePathDO::getAncestor, sharePathDO.getAncestor()));
+                    .eq(SharePathDO::getAncestor, sharePathDO.get(0).getAncestor()));
             //最后再进行排序
             sortedSiblings = filterByDescendant(sharePathDOS, userId);
             // 查询兄弟的所有儿子
@@ -383,7 +383,14 @@ public class SharePathServiceImpl implements SharePathService {
 
         // 过滤出所有 sort 值大于找到的 sort 值的记录
         return sharePaths.stream()
-                .filter(sharePath -> sharePath.getSort() > reference.getSort())
+                .filter(sharePath ->
+                        {
+                            if (reference.getSort() != null && sharePath.getSort() != null) {
+                                return sharePath.getSort() > reference.getSort();
+                            }
+                            return false;
+                        }
+                )
                 .map(SharePathDO::getDescendant)
                 .collect(Collectors.toList());
     }
@@ -392,12 +399,12 @@ public class SharePathServiceImpl implements SharePathService {
     @Override
     public Long queryParentBySonUserId(Long userId) {
 
-        SharePathDO sharePathDO = sharePathMapper.selectOne(new LambdaQueryWrapperX<SharePathDO>()
+        List<SharePathDO> sharePathDO = sharePathMapper.selectList(new LambdaQueryWrapperX<SharePathDO>()
                 .eqIfPresent(SharePathDO::getDescendant, userId).eqIfPresent(SharePathDO::getDepth, 1));
-        if (sharePathDO == null) {
+        if (sharePathDO.isEmpty()) {
             return 1L;
         } else {
-            return sharePathDO.getAncestor();
+            return sharePathDO.get(0).getAncestor();
         }