|
@@ -37,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.*;
|
|
@@ -159,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<>();
|
|
@@ -175,132 +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);
|
|
|
+ }
|
|
|
|
|
|
- // 创建一个分区编号
|
|
|
- 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);
|
|
|
|
|
|
- // 合并兄弟分支额度
|
|
|
- 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);
|
|
@@ -320,7 +321,7 @@ public class PartitionCrashServiceImpl implements PartitionCrashService {
|
|
|
// 当前平台总积分
|
|
|
// Integer ptTotalAdd = ptProfit.getPtTotalAdd();
|
|
|
|
|
|
- if(entry.getValue() == 0){
|
|
|
+ if (entry.getValue() == 0) {
|
|
|
continue;
|
|
|
}
|
|
|
|