update:
fix
This commit is contained in:
@@ -6,6 +6,7 @@ import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springblade.common.utils.date.DateUtil;
|
||||
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.pojo.entity.CommonOrderConfirmLogEntity;
|
||||
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.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
@@ -51,13 +53,13 @@ public class InitPerformanceDayLogProcessor implements BasicProcessor {
|
||||
log.info("初始化团队业绩开始执行...");
|
||||
|
||||
Date today = DateUtil.getToday();
|
||||
Map<Long , MarketPerformanceDayLogEntity> marketPerformanceDayLogMap = new HashMap<>();
|
||||
Map<Long , MarketTeamEntity> marketTeamMap = new HashMap<>();
|
||||
Map<Long, MarketPerformanceDayLogEntity> marketPerformanceDayLogMap = 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());
|
||||
|
||||
if (!marketInfoEntityList.isEmpty()){
|
||||
if (!marketInfoEntityList.isEmpty()) {
|
||||
List<Long> parentIds = new ArrayList<>();
|
||||
|
||||
for (User marketInfo : marketInfoEntityList) {
|
||||
@@ -90,7 +92,6 @@ public class InitPerformanceDayLogProcessor implements BasicProcessor {
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 计算团队总消费
|
||||
String orderType = BusinessModule.SELF_OPERATED_MALL.getCode().toUpperCase();
|
||||
List<CommonOrderConfirmLogEntity> orderConfirmLogList = commonOrderConfirmLogService.list(
|
||||
@@ -102,7 +103,7 @@ public class InitPerformanceDayLogProcessor implements BasicProcessor {
|
||||
);
|
||||
|
||||
|
||||
if (!orderConfirmLogList.isEmpty()){
|
||||
if (!orderConfirmLogList.isEmpty()) {
|
||||
Set<Long> userIds = orderConfirmLogList.stream()
|
||||
.map(CommonOrderConfirmLogEntity::getUserId)
|
||||
.collect(Collectors.toSet());
|
||||
@@ -121,7 +122,7 @@ public class InitPerformanceDayLogProcessor implements BasicProcessor {
|
||||
List<Long> ancestorIds = userAncestorCache.getOrDefault(order.getUserId(), Collections.emptyList());
|
||||
ancestorIds.remove(order.getUserId());
|
||||
|
||||
for (Long ancestorId : ancestorIds){
|
||||
for (Long ancestorId : ancestorIds) {
|
||||
|
||||
marketTeamMap.compute(ancestorId, (key, existingTeam) -> {
|
||||
// 如果不存在,先 new 一个
|
||||
@@ -138,7 +139,6 @@ public class InitPerformanceDayLogProcessor implements BasicProcessor {
|
||||
}
|
||||
|
||||
|
||||
|
||||
List<MarketBenefitPackageEntity> packageEntityList = marketBenefitPackageService.list(
|
||||
Wrappers.lambdaQuery(MarketBenefitPackageEntity.class)
|
||||
.eq(MarketBenefitPackageEntity::getType, 1)
|
||||
@@ -146,7 +146,7 @@ public class InitPerformanceDayLogProcessor implements BasicProcessor {
|
||||
.le(MarketBenefitPackageEntity::getCreateTime, today)
|
||||
);
|
||||
|
||||
if (!packageEntityList.isEmpty()){
|
||||
if (!packageEntityList.isEmpty()) {
|
||||
Set<Long> userIdToPacks = orderConfirmLogList.stream()
|
||||
.map(CommonOrderConfirmLogEntity::getUserId)
|
||||
.collect(Collectors.toSet());
|
||||
@@ -168,13 +168,13 @@ public class InitPerformanceDayLogProcessor implements BasicProcessor {
|
||||
List<Long> ancestorIds = userAncestorToPackCache.getOrDefault(userId, Collections.emptyList());
|
||||
ancestorIds.remove(userId);
|
||||
|
||||
for (Long ancestorId : ancestorIds){
|
||||
for (Long ancestorId : ancestorIds) {
|
||||
MarketPerformanceDayLogEntity marketPerformanceDayLog;
|
||||
if (marketPerformanceDayLogMap.containsKey(ancestorId)){
|
||||
if (marketPerformanceDayLogMap.containsKey(ancestorId)) {
|
||||
marketPerformanceDayLog = marketPerformanceDayLogMap.get(ancestorId);
|
||||
marketPerformanceDayLog.setBenefitsValue(marketPerformanceDayLog.getBenefitsValue().add(totalUserBenefit));
|
||||
marketPerformanceDayLog.setBenefitsPack(marketPerformanceDayLog.getBenefitsPack() + packageList.size());
|
||||
}else {
|
||||
} else {
|
||||
marketPerformanceDayLog = new MarketPerformanceDayLogEntity();
|
||||
marketPerformanceDayLog.setUserId(ancestorId);
|
||||
marketPerformanceDayLog.setBenefitsValue(totalUserBenefit);
|
||||
@@ -199,25 +199,23 @@ public class InitPerformanceDayLogProcessor implements BasicProcessor {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Integer day = Integer.parseInt(DateUtil.convertFromDate(DateUtil.getYesterday() , "yyyyMMdd"));
|
||||
Integer mouth = Integer.parseInt(DateUtil.convertFromDate(DateUtil.getYesterday() , "yyyyMM"));
|
||||
Integer day = Integer.parseInt(DateUtil.convertFromDate(DateUtil.getYesterday(), "yyyyMMdd"));
|
||||
Integer mouth = Integer.parseInt(DateUtil.convertFromDate(DateUtil.getYesterday(), "yyyyMM"));
|
||||
// marketPerformanceDayLogMap 转list
|
||||
List<MarketPerformanceDayLogEntity> marketPerformanceDayLogList = new ArrayList<>(marketPerformanceDayLogMap.values());
|
||||
marketPerformanceDayLogList.forEach(marketPerformanceDayLog -> {
|
||||
marketPerformanceDayLog.setStatsDay(day);
|
||||
marketPerformanceDayLog.setStatsMonth(mouth);
|
||||
});
|
||||
marketPerformanceDayLogService.saveBatch(marketPerformanceDayLogList , 2000);
|
||||
marketPerformanceDayLogService.saveBatch(marketPerformanceDayLogList, 2000);
|
||||
|
||||
List<MarketTeamEntity> marketTeamList = new ArrayList<>(marketTeamMap.values());
|
||||
marketTeamService.saveBatch(marketTeamList , 2000);
|
||||
marketTeamService.saveBatch(marketTeamList, 2000);
|
||||
|
||||
return new ProcessResult(true, "result is success");
|
||||
}
|
||||
|
||||
private Map<Long, List<Long>> batchSelectAncestorIds(Set<Long> userIdList){
|
||||
private Map<Long, List<Long>> batchSelectAncestorIds(Set<Long> userIdList) {
|
||||
Map<Long, List<Long>> userAncestorCache = new HashMap<>();
|
||||
String key = "yiyu:market:user:ancestor:";
|
||||
userIdList.forEach(userId -> {
|
||||
@@ -228,7 +226,7 @@ public class InitPerformanceDayLogProcessor implements BasicProcessor {
|
||||
ancestorIds.addAll(marketInfoService.selectAncestorIds(userId));
|
||||
bladeRedis.set(key + userId, ancestorIds);
|
||||
userAncestorCache.put(userId, ancestorIds);
|
||||
}else {
|
||||
} else {
|
||||
userAncestorCache.put(userId, JSONArray.parseArray(JSONArray.toJSONString(ancestorIdsObject), Long.class));
|
||||
}
|
||||
});
|
||||
@@ -236,4 +234,71 @@ public class InitPerformanceDayLogProcessor implements BasicProcessor {
|
||||
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:已分发)
|
||||
*/
|
||||
@Schema(description = "是否分发极差代理 (0:未分发, 1:已分发)")
|
||||
@Schema(description = "是否分发级差代理 (0:未分发, 1:已分发)")
|
||||
private Integer isAgencyDistributed;
|
||||
/**
|
||||
* 极差代理发放时间
|
||||
*/
|
||||
@Schema(description = "极差代理发放时间")
|
||||
@Schema(description = "级差代理发放时间")
|
||||
private Date agencyDistributeTime;
|
||||
/**
|
||||
* 是否发放服务商佣金 (0:未发放, 1:已发放)
|
||||
|
||||
Reference in New Issue
Block a user