update:
fix
This commit is contained in:
@@ -6,6 +6,7 @@ import lombok.AllArgsConstructor;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springblade.common.utils.date.DateUtil;
|
import org.springblade.common.utils.date.DateUtil;
|
||||||
import org.springblade.core.redis.cache.BladeRedis;
|
import org.springblade.core.redis.cache.BladeRedis;
|
||||||
|
import org.springblade.modules.auth.provider.UserType;
|
||||||
import org.springblade.modules.common.eums.BusinessModule;
|
import org.springblade.modules.common.eums.BusinessModule;
|
||||||
import org.springblade.modules.common.pojo.entity.CommonOrderConfirmLogEntity;
|
import org.springblade.modules.common.pojo.entity.CommonOrderConfirmLogEntity;
|
||||||
import org.springblade.modules.common.service.ICommonOrderConfirmLogService;
|
import org.springblade.modules.common.service.ICommonOrderConfirmLogService;
|
||||||
@@ -26,6 +27,7 @@ import tech.powerjob.worker.core.processor.sdk.BasicProcessor;
|
|||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
|
||||||
@@ -54,7 +56,7 @@ public class InitPerformanceDayLogProcessor implements BasicProcessor {
|
|||||||
Map<Long, MarketPerformanceDayLogEntity> marketPerformanceDayLogMap = new HashMap<>();
|
Map<Long, MarketPerformanceDayLogEntity> marketPerformanceDayLogMap = new HashMap<>();
|
||||||
Map<Long, MarketTeamEntity> marketTeamMap = new HashMap<>();
|
Map<Long, MarketTeamEntity> marketTeamMap = new HashMap<>();
|
||||||
|
|
||||||
List<User> marketInfoEntityList = userService.list(Wrappers.<User>lambdaQuery().eq(User::getUserType, 2).eq(User::getIsDeleted, 0).le(User::getCreateTime, today));
|
List<User> marketInfoEntityList = userService.list(Wrappers.<User>lambdaQuery().eq(User::getUserType, UserType.APP.getCategory()).eq(User::getIsDeleted, 0).le(User::getCreateTime, today));
|
||||||
log.info("初始化团队业绩开始执行...查询团队数据完成,数据量:{}", marketInfoEntityList.size());
|
log.info("初始化团队业绩开始执行...查询团队数据完成,数据量:{}", marketInfoEntityList.size());
|
||||||
|
|
||||||
if (!marketInfoEntityList.isEmpty()) {
|
if (!marketInfoEntityList.isEmpty()) {
|
||||||
@@ -90,7 +92,6 @@ public class InitPerformanceDayLogProcessor implements BasicProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 计算团队总消费
|
// 计算团队总消费
|
||||||
String orderType = BusinessModule.SELF_OPERATED_MALL.getCode().toUpperCase();
|
String orderType = BusinessModule.SELF_OPERATED_MALL.getCode().toUpperCase();
|
||||||
List<CommonOrderConfirmLogEntity> orderConfirmLogList = commonOrderConfirmLogService.list(
|
List<CommonOrderConfirmLogEntity> orderConfirmLogList = commonOrderConfirmLogService.list(
|
||||||
@@ -138,7 +139,6 @@ public class InitPerformanceDayLogProcessor implements BasicProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
List<MarketBenefitPackageEntity> packageEntityList = marketBenefitPackageService.list(
|
List<MarketBenefitPackageEntity> packageEntityList = marketBenefitPackageService.list(
|
||||||
Wrappers.lambdaQuery(MarketBenefitPackageEntity.class)
|
Wrappers.lambdaQuery(MarketBenefitPackageEntity.class)
|
||||||
.eq(MarketBenefitPackageEntity::getType, 1)
|
.eq(MarketBenefitPackageEntity::getType, 1)
|
||||||
@@ -199,8 +199,6 @@ public class InitPerformanceDayLogProcessor implements BasicProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Integer day = Integer.parseInt(DateUtil.convertFromDate(DateUtil.getYesterday(), "yyyyMMdd"));
|
Integer day = Integer.parseInt(DateUtil.convertFromDate(DateUtil.getYesterday(), "yyyyMMdd"));
|
||||||
Integer mouth = Integer.parseInt(DateUtil.convertFromDate(DateUtil.getYesterday(), "yyyyMM"));
|
Integer mouth = Integer.parseInt(DateUtil.convertFromDate(DateUtil.getYesterday(), "yyyyMM"));
|
||||||
// marketPerformanceDayLogMap 转list
|
// marketPerformanceDayLogMap 转list
|
||||||
@@ -236,4 +234,71 @@ public class InitPerformanceDayLogProcessor implements BasicProcessor {
|
|||||||
return userAncestorCache;
|
return userAncestorCache;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Map<Long, Integer> calculateTeamSizes(List<MarketInfoEntity> allUsers) {
|
||||||
|
if (allUsers == null || allUsers.isEmpty()) {
|
||||||
|
return Collections.emptyMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 1. 构建 id -> user 映射(确保 id 唯一)
|
||||||
|
Map<Long, MarketInfoEntity> userMap = allUsers.stream()
|
||||||
|
.collect(Collectors.toMap(MarketInfoEntity::getId, Function.identity(), (u1, u2) -> u1));
|
||||||
|
|
||||||
|
Set<Long> userIds = userMap.keySet();
|
||||||
|
|
||||||
|
// 2. 构建 childrenMap: parentId -> List<childId>
|
||||||
|
Map<Long, List<Long>> childrenMap = new HashMap<>();
|
||||||
|
for (MarketInfoEntity user : allUsers) {
|
||||||
|
Long parentId = user.getPid(); // 注意:根节点 parentId == null
|
||||||
|
if (parentId != null && userIds.contains(parentId)) {
|
||||||
|
childrenMap.computeIfAbsent(parentId, k -> new ArrayList<>()).add(user.getId());
|
||||||
|
}
|
||||||
|
// 如果 parentId != null 但不在当前集合中(如数据分页),可选择忽略或报错
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. 初始化结果
|
||||||
|
Map<Long, Integer> teamSize = new HashMap<>();
|
||||||
|
for (Long id : userIds) {
|
||||||
|
teamSize.put(id, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. 计算每个节点的深度(用于排序)
|
||||||
|
Map<Long, Integer> depth = new HashMap<>();
|
||||||
|
Deque<Long> queue = new ArrayDeque<>();
|
||||||
|
|
||||||
|
// 所有根节点:parentId == null
|
||||||
|
for (MarketInfoEntity user : allUsers) {
|
||||||
|
if (user.getPid() == null) {
|
||||||
|
depth.put(user.getId(), 0);
|
||||||
|
queue.offer(user.getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// BFS 计算深度
|
||||||
|
while (!queue.isEmpty()) {
|
||||||
|
Long current = queue.poll();
|
||||||
|
for (Long child : childrenMap.getOrDefault(current, Collections.emptyList())) {
|
||||||
|
depth.put(child, depth.get(current) + 1);
|
||||||
|
queue.offer(child);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 5. 按深度降序排序(从最深的叶子开始处理)
|
||||||
|
List<Long> sortedIds = userIds.stream()
|
||||||
|
.sorted(Comparator.comparing(depth::get, Comparator.nullsLast(Comparator.reverseOrder())))
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
// 6. 自底向上累加团队人数
|
||||||
|
for (Long id : sortedIds) {
|
||||||
|
int total = 0;
|
||||||
|
for (Long childId : childrenMap.getOrDefault(id, Collections.emptyList())) {
|
||||||
|
total += 1 + teamSize.get(childId); // 子节点本身 + 子节点的整个团队
|
||||||
|
}
|
||||||
|
teamSize.put(id, total);
|
||||||
|
}
|
||||||
|
|
||||||
|
return teamSize; // key: userId, value: 团队总人数(不含自己)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,12 +66,12 @@ public class CommonOrderConfirmLogEntity extends BaseEntity {
|
|||||||
/**
|
/**
|
||||||
* 是否分发极差代理 (0:未分发, 1:已分发)
|
* 是否分发极差代理 (0:未分发, 1:已分发)
|
||||||
*/
|
*/
|
||||||
@Schema(description = "是否分发极差代理 (0:未分发, 1:已分发)")
|
@Schema(description = "是否分发级差代理 (0:未分发, 1:已分发)")
|
||||||
private Integer isAgencyDistributed;
|
private Integer isAgencyDistributed;
|
||||||
/**
|
/**
|
||||||
* 极差代理发放时间
|
* 极差代理发放时间
|
||||||
*/
|
*/
|
||||||
@Schema(description = "极差代理发放时间")
|
@Schema(description = "级差代理发放时间")
|
||||||
private Date agencyDistributeTime;
|
private Date agencyDistributeTime;
|
||||||
/**
|
/**
|
||||||
* 是否发放服务商佣金 (0:未发放, 1:已发放)
|
* 是否发放服务商佣金 (0:未发放, 1:已发放)
|
||||||
|
|||||||
Reference in New Issue
Block a user