update:
1. fix
This commit is contained in:
@@ -37,28 +37,74 @@ public class DailyBenefitsPackageRelativeProcessor implements BasicProcessor {
|
||||
log.info("福利包、值相关日志统计开始,时间:{}", DateUtil.formatDateTime(DateUtil.now()));
|
||||
Map<String, String> paramsMap = context.getWorkflowContext().getData();
|
||||
|
||||
if (!paramsMap.containsKey(DailyBenefitLogProcessor.USER_LIST) || !paramsMap.containsKey(DailyBenefitLogProcessor.SUMMARY_LIST)) {
|
||||
if (!paramsMap.containsKey(DailySummaryProcessor.USER_LIST) || !paramsMap.containsKey(DailySummaryProcessor.SUMMARY_LIST)) {
|
||||
result.setSuccess(false);
|
||||
result.setMsg("获取用户列表或汇总列表失败");
|
||||
return result;
|
||||
}
|
||||
|
||||
List<MarketInfoSummaryDTO> userDtoList = JSONArray.parseArray(paramsMap.get(DailyBenefitLogProcessor.USER_LIST), MarketInfoSummaryDTO.class);
|
||||
List<MarketInfoSummaryDTO> userDtoList = JSONArray.parseArray(paramsMap.get(DailySummaryProcessor.USER_LIST), MarketInfoSummaryDTO.class);
|
||||
|
||||
List<MarketDailySummaryEntity> summaryEntityList = JSONArray.parseArray(paramsMap.get(DailyBenefitLogProcessor.SUMMARY_LIST), MarketDailySummaryEntity.class);
|
||||
List<MarketDailySummaryEntity> summaryEntityList = JSONArray.parseArray(paramsMap.get(DailySummaryProcessor.SUMMARY_LIST), MarketDailySummaryEntity.class);
|
||||
Map<Long, MarketDailySummaryEntity> summaryMap = summaryEntityList.stream().collect(Collectors.toMap(MarketDailySummaryEntity::getUserId, s -> s));
|
||||
|
||||
String formatedDate = paramsMap.get(DailyBenefitLogProcessor.DATE);
|
||||
Date date = DateUtil.parse(formatedDate, DateUtil.PATTERN_DATE);
|
||||
Date today = DateUtil.plusDays(date, 1);
|
||||
String formatedDateToday = paramsMap.get(DailySummaryProcessor.TODAY);
|
||||
Date today = DateUtil.parse(formatedDateToday, DateUtil.PATTERN_DATE);
|
||||
String formatedDateYesterday = paramsMap.get(DailySummaryProcessor.YESTERDAY);
|
||||
Date yesterday = DateUtil.parse(formatedDateYesterday, DateUtil.PATTERN_DATE);
|
||||
|
||||
List<MarketDailySummaryEntity> batchList = new ArrayList<>(summaryMap.size());
|
||||
|
||||
//获取生效的福利包并分组求和
|
||||
List<MarketBenefitsPackageSummaryDTO> benefitPackageList = benefitPackageService.selectCurrentBenefitsPackageByDate(date);
|
||||
//获取有效的福利包并分组求和
|
||||
List<MarketBenefitsPackageSummaryDTO> benefitPackageList = benefitPackageService.selectCurrentBenefitsPackageByDate(today, yesterday);
|
||||
Map<Long, List<MarketBenefitsPackageSummaryDTO>> packageMap = benefitPackageList.stream().collect(Collectors.groupingBy(MarketBenefitsPackageSummaryDTO::getUserId));
|
||||
|
||||
//构建列表
|
||||
//预构建福利包列表的个人信息
|
||||
Map<Long, BigDecimal> personalTotalBenefitsValueMap = new HashMap<>();
|
||||
Map<Long, BigDecimal> personalCurrentBenefitsValueMap = new HashMap<>();
|
||||
Map<Long, BigDecimal> personalIncreaseBenefitsValueMap = new HashMap<>();
|
||||
Map<Long, BigDecimal> personalIncreaseCurrentBenefitsValueMap = new HashMap<>();
|
||||
Map<Long, List<Long>> personalIncreasePackageDetailMap = new HashMap<>();
|
||||
Map<Long, BigDecimal> personalRemainBenefitsPointMap = new HashMap<>();
|
||||
|
||||
|
||||
packageMap.forEach((userId, packageList) -> {
|
||||
BigDecimal total = BigDecimal.ZERO;
|
||||
BigDecimal totalCurrent = BigDecimal.ZERO;
|
||||
BigDecimal increase = BigDecimal.ZERO;
|
||||
BigDecimal increaseCurrent = BigDecimal.ZERO;
|
||||
BigDecimal remain = BigDecimal.ZERO;
|
||||
List<Long> increasePackageIds = new ArrayList<>();
|
||||
|
||||
for (MarketBenefitsPackageSummaryDTO pkg : packageList) {
|
||||
BigDecimal faceValue = Optional.ofNullable(pkg.getBenefitsPointFaceValue()).orElse(BigDecimal.ZERO);
|
||||
total = total.add(faceValue);
|
||||
|
||||
BigDecimal amount = Optional.ofNullable(pkg.getTotalAmount()).orElse(BigDecimal.ZERO);
|
||||
BigDecimal claimed = Optional.ofNullable(pkg.getClaimedAmount()).orElse(BigDecimal.ZERO);
|
||||
remain = remain.add(amount.subtract(claimed));
|
||||
|
||||
if (pkg.getType() == 1) {
|
||||
totalCurrent = totalCurrent.add(faceValue);
|
||||
}
|
||||
|
||||
Date createTime = pkg.getCreateTime();
|
||||
if (createTime != null && !createTime.before(yesterday) && createTime.before(today)) {
|
||||
increase = increase.add(faceValue);
|
||||
increasePackageIds.add(pkg.getId());
|
||||
if (pkg.getType() == 1) {
|
||||
increaseCurrent = increaseCurrent.add(faceValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
personalTotalBenefitsValueMap.put(userId, total);
|
||||
personalCurrentBenefitsValueMap.put(userId, totalCurrent);
|
||||
personalIncreaseBenefitsValueMap.put(userId, increase);
|
||||
personalIncreaseCurrentBenefitsValueMap.put(userId, increaseCurrent);
|
||||
personalIncreasePackageDetailMap.put(userId, increasePackageIds);
|
||||
personalRemainBenefitsPointMap.put(userId, remain);
|
||||
});
|
||||
|
||||
//构建直接下属关系
|
||||
Map<Long, List<Long>> directChildren = new HashMap<>();
|
||||
for (MarketInfoSummaryDTO user : userDtoList) {
|
||||
Long uid = user.getId();
|
||||
@@ -68,154 +114,114 @@ public class DailyBenefitsPackageRelativeProcessor implements BasicProcessor {
|
||||
}
|
||||
}
|
||||
|
||||
Map<Long, BigDecimal> personalTotalValueMap = new HashMap<>();
|
||||
Map<Long, BigDecimal> personalIncreaseValueMap = new HashMap<>();
|
||||
|
||||
for (Map.Entry<Long, List<MarketBenefitsPackageSummaryDTO>> entry : packageMap.entrySet()) {
|
||||
Long userId = entry.getKey();
|
||||
List<MarketBenefitsPackageSummaryDTO> packages = entry.getValue();
|
||||
|
||||
BigDecimal total = BigDecimal.ZERO;
|
||||
BigDecimal increase = BigDecimal.ZERO;
|
||||
|
||||
for (MarketBenefitsPackageSummaryDTO pkg : packages) {
|
||||
BigDecimal faceValue = Optional.ofNullable(pkg.getBenefitsPointFaceValue()).orElse(BigDecimal.ZERO);
|
||||
total = total.add(faceValue);
|
||||
|
||||
Date createTime = pkg.getCreateTime();
|
||||
if (createTime != null && !createTime.before(date) && createTime.before(today)) {
|
||||
increase = increase.add(faceValue);
|
||||
}
|
||||
}
|
||||
|
||||
personalTotalValueMap.put(userId, total);
|
||||
personalIncreaseValueMap.put(userId, increase);
|
||||
}
|
||||
|
||||
packageMap.forEach((userId, packageList) -> {
|
||||
if (!summaryMap.containsKey(userId)) {
|
||||
return;
|
||||
}
|
||||
|
||||
MarketDailySummaryEntity summary = summaryMap.get(userId);
|
||||
MarketDailySummaryEntity s = new MarketDailySummaryEntity();
|
||||
s.setId(summary.getId());
|
||||
|
||||
List<Long> increasePackageIds = new ArrayList<>();
|
||||
BigDecimal totalAmount = BigDecimal.ZERO;
|
||||
BigDecimal claimedAmount = BigDecimal.ZERO;
|
||||
|
||||
for (MarketBenefitsPackageSummaryDTO pkg : packageList) {
|
||||
totalAmount = totalAmount.add(Optional.ofNullable(pkg.getTotalAmount()).orElse(BigDecimal.ZERO));
|
||||
claimedAmount = claimedAmount.add(Optional.ofNullable(pkg.getClaimedAmount()).orElse(BigDecimal.ZERO));
|
||||
|
||||
Date createTime = pkg.getCreateTime();
|
||||
if (createTime != null && !createTime.before(date) && createTime.before(today)) {
|
||||
if (pkg.getId() != null) {
|
||||
increasePackageIds.add(pkg.getId());
|
||||
//计算“有福利包的直接下属人数”
|
||||
Set<Long> usersWithPackages = packageMap.keySet();
|
||||
Map<Long, Integer> directSubordinatesWithPackagesCount = new HashMap<>();
|
||||
for (MarketInfoSummaryDTO user : userDtoList) {
|
||||
Long userId = user.getId();
|
||||
List<Long> directKids = directChildren.get(userId);
|
||||
int count = 0;
|
||||
if (directKids != null) {
|
||||
for (Long kidId : directKids) {
|
||||
if (usersWithPackages.contains(kidId)) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//个人总福利值
|
||||
s.setPersonalTotalBenefitsValue(personalTotalValueMap.getOrDefault(userId, BigDecimal.ZERO));
|
||||
|
||||
//新增福利包
|
||||
s.setPersonalIncreaseBenefitsValue(personalIncreaseValueMap.getOrDefault(userId, BigDecimal.ZERO));
|
||||
|
||||
//新增福利包明细(只存 id)
|
||||
s.setPersonalIncreaseBenefitsPackageDetail(increasePackageIds);
|
||||
|
||||
//剩余可兑换值
|
||||
s.setPersonalBenefitsPackageRemainValue(totalAmount.subtract(claimedAmount));
|
||||
|
||||
// === 直推人新增福利包明细(ID 列表)===
|
||||
List<Long> directReferrals = directChildren.getOrDefault(userId, Collections.emptyList());
|
||||
|
||||
//持有福利包的直推人数
|
||||
long qualifiedReferralCount = directReferrals.stream()
|
||||
.filter(packageMap::containsKey)
|
||||
.count();
|
||||
s.setPersonalInviteBenefitsPackageHolderCount((int) qualifiedReferralCount);
|
||||
|
||||
//当日直推人新增的福利包明细
|
||||
List<Long> referralNewPackageIds = new ArrayList<>();
|
||||
for (Long referralId : directReferrals) {
|
||||
List<MarketBenefitsPackageSummaryDTO> referralPackages = packageMap.get(referralId);
|
||||
referralNewPackageIds.addAll(extractNewPackageIds(referralPackages, date, today));
|
||||
}
|
||||
s.setPersonalInviteIncreaseBenefitsPackageDetail(referralNewPackageIds);
|
||||
|
||||
// === 【新增】团队总福利值 & 团队昨日新增福利值(不含本人)===
|
||||
Set<Long> allTeamMembers = getAllDescendants(userId, directChildren);
|
||||
|
||||
// 团队总福利值(不含本人)
|
||||
BigDecimal teamTotal = allTeamMembers.stream().map(id -> personalTotalValueMap.getOrDefault(id, BigDecimal.ZERO)).reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
s.setTeamTotalBenefitsValue(teamTotal);
|
||||
|
||||
// 当日新增团队福利值(不含本人)
|
||||
BigDecimal teamIncrease = allTeamMembers.stream().map(id -> personalIncreaseValueMap.getOrDefault(id, BigDecimal.ZERO)).reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
s.setTeamIncreaseBenefitsValue(teamIncrease);
|
||||
|
||||
// 团队新增福利包明细
|
||||
List<Long> teamNewPackageIds = new ArrayList<>();
|
||||
for (Long memberId : allTeamMembers) {
|
||||
List<MarketBenefitsPackageSummaryDTO> memberPackages = packageMap.get(memberId);
|
||||
teamNewPackageIds.addAll(extractNewPackageIds(memberPackages, date, today));
|
||||
}
|
||||
s.setTeamIncreaseBenefitsPackageDetail(teamNewPackageIds);
|
||||
|
||||
batchList.add(s);
|
||||
|
||||
});
|
||||
if(summaryService.updateBatchById(batchList)){
|
||||
omsLogger.info("福利包、值相关日志统计结束,时间:{},统计完成", DateUtil.formatDateTime(DateUtil.now()));
|
||||
return result;
|
||||
directSubordinatesWithPackagesCount.put(userId, count);
|
||||
}
|
||||
|
||||
//缓存每个用户的全部下属(用于团队统计)
|
||||
Map<Long, Set<Long>> descendantsCache = new HashMap<>();
|
||||
for (MarketInfoSummaryDTO user : userDtoList) {
|
||||
getAllDescendants(user.getId(), directChildren, descendantsCache);
|
||||
}
|
||||
|
||||
Map<Long, BigDecimal> teamTotalBenefitsValueMap = new HashMap<>();
|
||||
Map<Long, BigDecimal> teamCurrentBenefitsValueMap = new HashMap<>();
|
||||
Map<Long, BigDecimal> teamIncreaseBenefitsValueMap = new HashMap<>();
|
||||
Map<Long, List<Long>> teamIncreasePackageDetailMap = new HashMap<>();
|
||||
|
||||
for (MarketInfoSummaryDTO user : userDtoList) {
|
||||
Long userId = user.getId();
|
||||
Set<Long> descendants = descendantsCache.get(userId);
|
||||
if (descendants == null || descendants.isEmpty()) {
|
||||
teamTotalBenefitsValueMap.put(userId, BigDecimal.ZERO);
|
||||
teamCurrentBenefitsValueMap.put(userId, BigDecimal.ZERO);
|
||||
teamIncreaseBenefitsValueMap.put(userId, BigDecimal.ZERO);
|
||||
teamIncreasePackageDetailMap.put(userId, Collections.emptyList());
|
||||
} else {
|
||||
BigDecimal total = BigDecimal.ZERO;
|
||||
BigDecimal totalCurrent = BigDecimal.ZERO;
|
||||
BigDecimal increase = BigDecimal.ZERO;
|
||||
List<Long> increasePackageDetail = new ArrayList<>();
|
||||
|
||||
for (Long descId : descendants) {
|
||||
total = total.add(personalTotalBenefitsValueMap.getOrDefault(descId, BigDecimal.ZERO));
|
||||
totalCurrent = totalCurrent.add(personalCurrentBenefitsValueMap.getOrDefault(descId, BigDecimal.ZERO));
|
||||
increase = increase.add(personalIncreaseBenefitsValueMap.getOrDefault(descId, BigDecimal.ZERO));
|
||||
increasePackageDetail.addAll(personalIncreasePackageDetailMap.getOrDefault(descId,Collections.emptyList()));
|
||||
}
|
||||
|
||||
teamTotalBenefitsValueMap.put(userId, total);
|
||||
teamCurrentBenefitsValueMap.put(userId, totalCurrent);
|
||||
teamIncreaseBenefitsValueMap.put(userId, increase);
|
||||
teamIncreasePackageDetailMap.put(userId, increasePackageDetail);
|
||||
}
|
||||
}
|
||||
|
||||
// ====== 构建最终更新列表 ======
|
||||
List<MarketDailySummaryEntity> batchUpdateList = new ArrayList<>();
|
||||
for (MarketInfoSummaryDTO user : userDtoList) {
|
||||
Long userId = user.getId();
|
||||
MarketDailySummaryEntity summary = summaryMap.get(userId);
|
||||
if (summary == null) {
|
||||
continue; // 理论上不应发生
|
||||
}
|
||||
MarketDailySummaryEntity s = new MarketDailySummaryEntity();
|
||||
s.setId(summary.getId());
|
||||
|
||||
// === 个人维度 ===
|
||||
s.setPersonalTotalBenefitsValue(personalTotalBenefitsValueMap.getOrDefault(userId, BigDecimal.ZERO));
|
||||
s.setPersonalCurrentBenefitsValue(personalCurrentBenefitsValueMap.getOrDefault(userId, BigDecimal.ZERO));
|
||||
s.setPersonalIncreaseBenefitsValue(personalIncreaseBenefitsValueMap.getOrDefault(userId, BigDecimal.ZERO));
|
||||
s.setPersonalIncreaseCurrentBenefitsValue(personalIncreaseCurrentBenefitsValueMap.getOrDefault(userId, BigDecimal.ZERO));
|
||||
s.setPersonalIncreaseBenefitsPackageDetail(personalIncreasePackageDetailMap.getOrDefault(userId,Collections.emptyList()));
|
||||
s.setPersonalBenefitsPackageRemainValue(personalRemainBenefitsPointMap.getOrDefault(userId, BigDecimal.ZERO));
|
||||
s.setPersonalInviteBenefitsPackageHolderCount(directSubordinatesWithPackagesCount.getOrDefault(userId, 0));
|
||||
|
||||
//=== 团队维度 ===
|
||||
s.setTeamTotalBenefitsValue(teamTotalBenefitsValueMap.getOrDefault(userId, BigDecimal.ZERO));
|
||||
s.setTeamCurrentBenefitsValue(teamCurrentBenefitsValueMap.getOrDefault(userId, BigDecimal.ZERO));
|
||||
s.setTeamIncreaseBenefitsValue(teamIncreaseBenefitsValueMap.getOrDefault(userId, BigDecimal.ZERO));
|
||||
s.setTeamIncreaseBenefitsPackageDetail(teamIncreasePackageDetailMap.getOrDefault(userId, Collections.emptyList()));
|
||||
|
||||
batchUpdateList.add(s);
|
||||
}
|
||||
|
||||
if (!batchUpdateList.isEmpty()) {
|
||||
summaryService.updateBatchById(batchUpdateList);
|
||||
}
|
||||
result.setSuccess(false);
|
||||
result.setMsg("执行失败");
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
private Set<Long> getAllDescendants(Long rootId, Map<Long, List<Long>> directChildren) {
|
||||
if (rootId == null || directChildren == null) {
|
||||
return Collections.emptySet();
|
||||
private Set<Long> getAllDescendants(Long userId, Map<Long, List<Long>> directChildren, Map<Long, Set<Long>> descendantsCache) {
|
||||
if (descendantsCache.containsKey(userId)) {
|
||||
return descendantsCache.get(userId);
|
||||
}
|
||||
|
||||
Set<Long> all = new HashSet<>();
|
||||
Queue<Long> queue = new LinkedList<>();
|
||||
queue.add(rootId);
|
||||
|
||||
while (!queue.isEmpty()) {
|
||||
Long current = queue.poll();
|
||||
List<Long> children = directChildren.get(current);
|
||||
if (children != null) {
|
||||
for (Long child : children) {
|
||||
if (all.add(child)) { // 避免重复(防环,虽然业务一般无环)
|
||||
queue.add(child);
|
||||
}
|
||||
}
|
||||
Set<Long> allDescendants = new HashSet<>();
|
||||
List<Long> directKids = directChildren.get(userId);
|
||||
if (directKids != null && !directKids.isEmpty()) {
|
||||
for (Long childId : directKids) {
|
||||
allDescendants.add(childId);
|
||||
allDescendants.addAll(getAllDescendants(childId, directChildren, descendantsCache));
|
||||
}
|
||||
}
|
||||
return all;
|
||||
|
||||
descendantsCache.put(userId, allDescendants);
|
||||
return allDescendants;
|
||||
}
|
||||
|
||||
private List<Long> extractNewPackageIds(List<MarketBenefitsPackageSummaryDTO> packages, Date startDate, Date endDate) {
|
||||
if (packages == null || packages.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<Long> ids = new ArrayList<>(packages.size() / 4); // 预估容量
|
||||
for (MarketBenefitsPackageSummaryDTO pkg : packages) {
|
||||
Date createTime = pkg.getCreateTime();
|
||||
if (createTime != null && !createTime.before(startDate) && createTime.before(endDate)) {
|
||||
Long id = pkg.getId();
|
||||
if (id != null) {
|
||||
ids.add(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
return ids;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,286 @@
|
||||
package org.springblade.job.processor.daily;
|
||||
|
||||
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springblade.core.tool.utils.DateUtil;
|
||||
import org.springblade.modules.common.eums.BusinessModule;
|
||||
import org.springblade.modules.common.eums.PaymentType;
|
||||
import org.springblade.modules.common.service.ICommonUserOrderService;
|
||||
import org.springblade.modules.market.pojo.dto.MarketInfoSummaryDTO;
|
||||
import org.springblade.modules.market.pojo.dto.UserOrderSummaryDTO;
|
||||
import org.springblade.modules.market.pojo.entity.MarketDailySummaryEntity;
|
||||
import org.springblade.modules.market.service.IMarketDailySummaryService;
|
||||
import org.springframework.stereotype.Component;
|
||||
import tech.powerjob.worker.core.processor.ProcessResult;
|
||||
import tech.powerjob.worker.core.processor.TaskContext;
|
||||
import tech.powerjob.worker.core.processor.sdk.BasicProcessor;
|
||||
import tech.powerjob.worker.log.OmsLogger;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@AllArgsConstructor
|
||||
public class DailyOrderRelativeProcessor implements BasicProcessor {
|
||||
|
||||
private final ICommonUserOrderService orderService;
|
||||
|
||||
private final IMarketDailySummaryService summaryService;
|
||||
|
||||
|
||||
@Override
|
||||
public ProcessResult process(TaskContext context) throws Exception {
|
||||
|
||||
OmsLogger omsLogger = context.getOmsLogger();
|
||||
ProcessResult result = new ProcessResult(true, "执行成功");
|
||||
omsLogger.info("订单、业绩关日志统计开始,时间:{}", DateUtil.formatDateTime(DateUtil.now()));
|
||||
log.info("订单、业绩相关日志统计开始,时间:{}", DateUtil.formatDateTime(DateUtil.now()));
|
||||
Map<String, String> paramsMap = context.getWorkflowContext().getData();
|
||||
|
||||
if (!paramsMap.containsKey(DailySummaryProcessor.USER_LIST) || !paramsMap.containsKey(DailySummaryProcessor.SUMMARY_LIST)) {
|
||||
result.setSuccess(false);
|
||||
result.setMsg("获取用户列表或汇总列表失败");
|
||||
return result;
|
||||
}
|
||||
|
||||
List<MarketInfoSummaryDTO> userDtoList = JSONArray.parseArray(paramsMap.get(DailySummaryProcessor.USER_LIST), MarketInfoSummaryDTO.class);
|
||||
|
||||
List<MarketDailySummaryEntity> summaryEntityList = JSONArray.parseArray(paramsMap.get(DailySummaryProcessor.SUMMARY_LIST), MarketDailySummaryEntity.class);
|
||||
Map<Long, MarketDailySummaryEntity> summaryMap = summaryEntityList.stream().collect(Collectors.toMap(MarketDailySummaryEntity::getUserId, s -> s));
|
||||
|
||||
String formatedDateToday = paramsMap.get(DailySummaryProcessor.TODAY);
|
||||
Date today = DateUtil.parse(formatedDateToday, DateUtil.PATTERN_DATE);
|
||||
String formatedDateYesterday = paramsMap.get(DailySummaryProcessor.YESTERDAY);
|
||||
Date yesterday = DateUtil.parse(formatedDateYesterday, DateUtil.PATTERN_DATE);
|
||||
|
||||
//获取有效的订单并分组求和
|
||||
List<UserOrderSummaryDTO> userOrderList = orderService.selectCurrentOrderByDate(today);
|
||||
Map<Long, List<UserOrderSummaryDTO>> orderMap = userOrderList.stream().collect(Collectors.groupingBy(UserOrderSummaryDTO::getUserId));
|
||||
|
||||
//预构建订单列表内的个人信息
|
||||
Map<Long, BigDecimal> personalTotalAmountMap = new HashMap<>();
|
||||
Map<Long, BigDecimal> personalTotalOnlineAmountMap = new HashMap<>();
|
||||
Map<Long, BigDecimal> personalTotalOfflineAmountMap = new HashMap<>();
|
||||
Map<Long, BigDecimal> personalTotalOtherAmountMap = new HashMap<>();
|
||||
Map<Long, BigDecimal> personalIncreaseAmountMap = new HashMap<>();
|
||||
Map<Long, BigDecimal> personalIncreaseOnlineAmountMap = new HashMap<>();
|
||||
Map<Long, BigDecimal> personalIncreaseOfflineAmountMap = new HashMap<>();
|
||||
Map<Long, BigDecimal> personalIncreaseOtherAmountMap = new HashMap<>();
|
||||
Map<Long, List<Long>> personalIncreaseOrderDetailMap = new HashMap<>();
|
||||
|
||||
orderMap.forEach((userId, orderList) -> {
|
||||
|
||||
BigDecimal total = BigDecimal.ZERO;
|
||||
BigDecimal totalOnline = BigDecimal.ZERO;
|
||||
BigDecimal totalOffline = BigDecimal.ZERO;
|
||||
BigDecimal totalOther = BigDecimal.ZERO;
|
||||
BigDecimal increase = BigDecimal.ZERO;
|
||||
BigDecimal increaseOnline = BigDecimal.ZERO;
|
||||
BigDecimal increaseOffline = BigDecimal.ZERO;
|
||||
BigDecimal increaseOther = BigDecimal.ZERO;
|
||||
List<Long> increaseOrderIds = new ArrayList<>();
|
||||
|
||||
for (UserOrderSummaryDTO order : orderList) {
|
||||
BigDecimal amount = Optional.ofNullable(order.getAmount()).orElse(BigDecimal.ZERO);
|
||||
total = total.add(amount);
|
||||
|
||||
if (order.getOrderType().equalsIgnoreCase(BusinessModule.SELF_OPERATED_MALL.getCode())) {
|
||||
if (order.getPaymentType() == PaymentType.OFFLINE.getCode()) {
|
||||
totalOffline = totalOffline.add(amount);
|
||||
} else {
|
||||
totalOnline = totalOnline.add(amount);
|
||||
}
|
||||
} else {
|
||||
totalOther = totalOther.add(amount);
|
||||
}
|
||||
|
||||
Date updateTime = order.getUpdateTime();
|
||||
if (updateTime != null && !updateTime.before(yesterday) && updateTime.before(today)) {
|
||||
increase = increase.add(amount);
|
||||
increaseOrderIds.add(order.getId());
|
||||
if (order.getOrderType().equalsIgnoreCase(BusinessModule.SELF_OPERATED_MALL.getCode())) {
|
||||
if (order.getPaymentType() == PaymentType.OFFLINE.getCode()) {
|
||||
increaseOnline = increaseOnline.add(amount);
|
||||
} else {
|
||||
increaseOffline = increaseOffline.add(amount);
|
||||
}
|
||||
} else {
|
||||
increaseOther = increaseOther.add(amount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
personalTotalAmountMap.put(userId, total);
|
||||
personalTotalOnlineAmountMap.put(userId, totalOnline);
|
||||
personalTotalOfflineAmountMap.put(userId, totalOffline);
|
||||
personalTotalOtherAmountMap.put(userId, totalOther);
|
||||
personalIncreaseAmountMap.put(userId, increase);
|
||||
personalIncreaseOnlineAmountMap.put(userId, increaseOnline);
|
||||
personalIncreaseOfflineAmountMap.put(userId, increaseOffline);
|
||||
personalIncreaseOtherAmountMap.put(userId, increaseOther);
|
||||
personalIncreaseOrderDetailMap.put(userId, increaseOrderIds);
|
||||
});
|
||||
|
||||
//构建直接下属关系
|
||||
Map<Long, List<Long>> directChildren = new HashMap<>();
|
||||
for (MarketInfoSummaryDTO user : userDtoList) {
|
||||
Long uid = user.getId();
|
||||
Long pid = user.getPid();
|
||||
if (uid != null && pid != null) {
|
||||
directChildren.computeIfAbsent(pid, k -> new ArrayList<>()).add(uid);
|
||||
}
|
||||
}
|
||||
|
||||
//计算“有订单的直接下属人数”
|
||||
Set<Long> usersWithOrders = orderMap.keySet();
|
||||
Map<Long, Integer> directSubordinatesWithOrderCount = new HashMap<>();
|
||||
for (MarketInfoSummaryDTO user : userDtoList) {
|
||||
Long userId = user.getId();
|
||||
List<Long> directKids = directChildren.get(userId);
|
||||
int count = 0;
|
||||
if (directKids != null) {
|
||||
for (Long kidId : directKids) {
|
||||
if (usersWithOrders.contains(kidId)) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
directSubordinatesWithOrderCount.put(userId, count);
|
||||
}
|
||||
|
||||
//缓存每个用户的全部下属(用于团队统计)
|
||||
Map<Long, Set<Long>> descendantsCache = new HashMap<>();
|
||||
for (MarketInfoSummaryDTO user : userDtoList) {
|
||||
getAllDescendants(user.getId(), directChildren, descendantsCache);
|
||||
}
|
||||
|
||||
Map<Long, BigDecimal> teamTotalAmountMap = new HashMap<>();
|
||||
Map<Long, BigDecimal> teamOnlineAmountMap = new HashMap<>();
|
||||
Map<Long, BigDecimal> teamOfflineAmountMap = new HashMap<>();
|
||||
Map<Long, BigDecimal> teamOtherAmountMap = new HashMap<>();
|
||||
Map<Long, BigDecimal> teamIncreaseAmountMap = new HashMap<>();
|
||||
Map<Long, BigDecimal> teamIncreaseOnlineAmountMap = new HashMap<>();
|
||||
Map<Long, BigDecimal> teamIncreaseOfflineAmountMap = new HashMap<>();
|
||||
Map<Long, BigDecimal> teamIncreaseOtherAmountMap = new HashMap<>();
|
||||
|
||||
for (MarketInfoSummaryDTO user : userDtoList) {
|
||||
Long userId = user.getId();
|
||||
Set<Long> descendants = descendantsCache.get(userId);
|
||||
if (descendants == null || descendants.isEmpty()) {
|
||||
teamTotalAmountMap.put(userId, BigDecimal.ZERO);
|
||||
teamOnlineAmountMap.put(userId, BigDecimal.ZERO);
|
||||
teamOfflineAmountMap.put(userId, BigDecimal.ZERO);
|
||||
teamOtherAmountMap.put(userId, BigDecimal.ZERO);
|
||||
teamIncreaseAmountMap.put(userId, BigDecimal.ZERO);
|
||||
teamIncreaseOnlineAmountMap.put(userId, BigDecimal.ZERO);
|
||||
teamIncreaseOfflineAmountMap.put(userId, BigDecimal.ZERO);
|
||||
teamIncreaseOtherAmountMap.put(userId, BigDecimal.ZERO);
|
||||
} else {
|
||||
BigDecimal total = BigDecimal.ZERO;
|
||||
BigDecimal online = BigDecimal.ZERO;
|
||||
BigDecimal offline = BigDecimal.ZERO;
|
||||
BigDecimal other = BigDecimal.ZERO;
|
||||
BigDecimal increase = BigDecimal.ZERO;
|
||||
BigDecimal increaseOnline = BigDecimal.ZERO;
|
||||
BigDecimal increaseOffline = BigDecimal.ZERO;
|
||||
BigDecimal increaseOther = BigDecimal.ZERO;
|
||||
|
||||
for (Long descId : descendants) {
|
||||
total = total.add(personalTotalAmountMap.getOrDefault(descId, BigDecimal.ZERO));
|
||||
online = online.add(personalTotalOnlineAmountMap.getOrDefault(descId, BigDecimal.ZERO));
|
||||
offline = offline.add(personalTotalOfflineAmountMap.getOrDefault(descId, BigDecimal.ZERO));
|
||||
other = other.add(personalTotalOtherAmountMap.getOrDefault(descId, BigDecimal.ZERO));
|
||||
|
||||
increase = increase.add(personalIncreaseAmountMap.getOrDefault(descId, BigDecimal.ZERO));
|
||||
increaseOnline = increaseOnline.add(personalIncreaseOnlineAmountMap.getOrDefault(descId, BigDecimal.ZERO));
|
||||
increaseOffline = increaseOffline.add(personalIncreaseOfflineAmountMap.getOrDefault(descId, BigDecimal.ZERO));
|
||||
increaseOther = increaseOther.add(personalIncreaseOtherAmountMap.getOrDefault(descId, BigDecimal.ZERO));
|
||||
}
|
||||
|
||||
teamTotalAmountMap.put(userId, total);
|
||||
teamOnlineAmountMap.put(userId, online);
|
||||
teamOfflineAmountMap.put(userId, offline);
|
||||
teamOtherAmountMap.put(userId, other);
|
||||
teamIncreaseAmountMap.put(userId, increase);
|
||||
teamIncreaseOnlineAmountMap.put(userId, increaseOnline);
|
||||
teamIncreaseOfflineAmountMap.put(userId, increaseOffline);
|
||||
teamIncreaseOtherAmountMap.put(userId, increaseOther);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ====== 构建最终更新列表 ======
|
||||
List<MarketDailySummaryEntity> batchUpdateList = new ArrayList<>();
|
||||
for (MarketInfoSummaryDTO user : userDtoList) {
|
||||
Long userId = user.getId();
|
||||
MarketDailySummaryEntity summary = summaryMap.get(userId);
|
||||
if (summary == null) {
|
||||
continue; // 理论上不应发生
|
||||
}
|
||||
|
||||
MarketDailySummaryEntity s = new MarketDailySummaryEntity();
|
||||
s.setId(summary.getId());
|
||||
|
||||
// === 个人维度 ===
|
||||
s.setPersonalTotalAmount(personalTotalAmountMap.getOrDefault(userId, BigDecimal.ZERO));
|
||||
s.setPersonalOnlineAmount(personalTotalOnlineAmountMap.getOrDefault(userId, BigDecimal.ZERO));
|
||||
s.setPersonalOfflineAmount(personalTotalOfflineAmountMap.getOrDefault(userId, BigDecimal.ZERO));
|
||||
s.setPersonalOtherAmount(personalTotalOtherAmountMap.getOrDefault(userId, BigDecimal.ZERO));
|
||||
|
||||
s.setPersonalIncreaseAmount(personalIncreaseAmountMap.getOrDefault(userId, BigDecimal.ZERO));
|
||||
s.setPersonalIncreaseOnlineAmount(personalIncreaseOnlineAmountMap.getOrDefault(userId, BigDecimal.ZERO));
|
||||
s.setPersonalIncreaseOfflineAmount(personalIncreaseOfflineAmountMap.getOrDefault(userId, BigDecimal.ZERO));
|
||||
s.setPersonalIncreaseOtherAmount(personalIncreaseOtherAmountMap.getOrDefault(userId, BigDecimal.ZERO));
|
||||
s.setPersonalIncreaseOrderDetail(personalIncreaseOrderDetailMap.getOrDefault(userId, Collections.emptyList()));
|
||||
s.setPersonalInviteOrderHolderCount(directSubordinatesWithOrderCount.getOrDefault(userId, 0));
|
||||
|
||||
// === 团队维度 ===
|
||||
s.setTeamTotalAmount(teamTotalAmountMap.getOrDefault(userId, BigDecimal.ZERO));
|
||||
s.setTeamOnlineAmount(teamOnlineAmountMap.getOrDefault(userId, BigDecimal.ZERO));
|
||||
s.setTeamOfflineAmount(teamOfflineAmountMap.getOrDefault(userId, BigDecimal.ZERO));
|
||||
s.setTeamOtherAmount(teamOtherAmountMap.getOrDefault(userId, BigDecimal.ZERO));
|
||||
|
||||
s.setTeamIncreaseAmount(teamIncreaseAmountMap.getOrDefault(userId, BigDecimal.ZERO));
|
||||
s.setTeamIncreaseOnlineAmount(teamIncreaseOnlineAmountMap.getOrDefault(userId, BigDecimal.ZERO));
|
||||
s.setTeamIncreaseOfflineAmount(teamIncreaseOfflineAmountMap.getOrDefault(userId, BigDecimal.ZERO));
|
||||
s.setTeamIncreaseOtherAmount(teamIncreaseOtherAmountMap.getOrDefault(userId, BigDecimal.ZERO));
|
||||
|
||||
|
||||
batchUpdateList.add(s);
|
||||
}
|
||||
|
||||
// ====== 批量更新数据库 ======
|
||||
if (!batchUpdateList.isEmpty()) {
|
||||
summaryService.updateBatchById(batchUpdateList);
|
||||
}
|
||||
|
||||
omsLogger.info("订单、业绩相关日志统计结束,时间:{}", DateUtil.formatDateTime(DateUtil.now()));
|
||||
omsLogger.info("共处理 {} 个用户,{} 笔订单", userDtoList.size(), userOrderList.size());
|
||||
log.info("订单、业绩相关日志统计结束,时间:{}", DateUtil.formatDateTime(DateUtil.now()));
|
||||
|
||||
return result; // 返回成功结果
|
||||
}
|
||||
|
||||
|
||||
private Set<Long> getAllDescendants(Long userId, Map<Long, List<Long>> directChildren, Map<Long, Set<Long>> descendantsCache) {
|
||||
if (descendantsCache.containsKey(userId)) {
|
||||
return descendantsCache.get(userId);
|
||||
}
|
||||
|
||||
Set<Long> allDescendants = new HashSet<>();
|
||||
List<Long> directKids = directChildren.get(userId);
|
||||
if (directKids != null && !directKids.isEmpty()) {
|
||||
for (Long childId : directKids) {
|
||||
allDescendants.add(childId);
|
||||
allDescendants.addAll(getAllDescendants(childId, directChildren, descendantsCache));
|
||||
}
|
||||
}
|
||||
|
||||
descendantsCache.put(userId, allDescendants);
|
||||
return allDescendants;
|
||||
}
|
||||
}
|
||||
@@ -3,10 +3,14 @@ package org.springblade.job.processor.daily;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springblade.core.tool.utils.DateUtil;
|
||||
import org.springblade.modules.common.pojo.entity.CommonUserPointEntity;
|
||||
import org.springblade.modules.common.service.ICommonUserPointService;
|
||||
import org.springblade.modules.market.pojo.dto.MarketInfoSummaryDTO;
|
||||
import org.springblade.modules.market.pojo.entity.MarketBenefitPointEntity;
|
||||
import org.springblade.modules.market.pojo.entity.MarketCashCouponEntity;
|
||||
import org.springblade.modules.market.pojo.entity.MarketDailySummaryEntity;
|
||||
import org.springblade.modules.market.service.IMarketDailySummaryService;
|
||||
import org.springblade.modules.market.service.IMarketInfoService;
|
||||
import org.springblade.modules.market.pojo.entity.MarketUserCommissionEntity;
|
||||
import org.springblade.modules.market.service.*;
|
||||
import org.springframework.dao.DuplicateKeyException;
|
||||
import org.springframework.stereotype.Component;
|
||||
import tech.powerjob.worker.core.processor.ProcessResult;
|
||||
@@ -21,26 +25,38 @@ import java.util.List;
|
||||
@Slf4j
|
||||
@Component
|
||||
@AllArgsConstructor
|
||||
public class DailyBenefitLogProcessor implements BasicProcessor {
|
||||
public class DailySummaryProcessor implements BasicProcessor {
|
||||
|
||||
private final IMarketDailySummaryService dailySummaryService;
|
||||
|
||||
private final IMarketInfoService marketInfoService;
|
||||
|
||||
private final ICommonUserPointService userPointService;
|
||||
|
||||
private final IMarketUserCommissionService commissionService;
|
||||
|
||||
private final IMarketBenefitPointService benefitPointService;
|
||||
|
||||
private final IMarketCashCouponService cashCouponService;
|
||||
|
||||
public static final String USER_LIST = "user-list";
|
||||
|
||||
public static final String SUMMARY_LIST = "daily-list";
|
||||
|
||||
public static final String DATE = "date";
|
||||
public static final String TODAY = "today";
|
||||
|
||||
public static final String YESTERDAY = "yesterday";
|
||||
|
||||
|
||||
@Override
|
||||
public ProcessResult process(TaskContext context) throws Exception {
|
||||
OmsLogger omsLogger = context.getOmsLogger();
|
||||
Date today = DateUtil.now();
|
||||
String formattedDateToday = DateUtil.formatDate(today);
|
||||
Date yesterday = DateUtil.plusDays(DateUtil.now(), -1);
|
||||
String formatDate = DateUtil.formatDate(yesterday);
|
||||
String formattedDateYesterday = DateUtil.formatDate(yesterday);
|
||||
ProcessResult result = new ProcessResult();
|
||||
List<MarketInfoSummaryDTO> marketInfoEntityList = marketInfoService.selectMarketInfoSummary();
|
||||
List<MarketInfoSummaryDTO> marketInfoEntityList = marketInfoService.selectMarketInfoSummaryByDate(DateUtil.parse(formattedDateToday, DateUtil.PATTERN_DATE));
|
||||
omsLogger.info("每日动态结算任务开始,结算日期:{},用户总数:{}", DateUtil.formatDate(yesterday), marketInfoEntityList.size());
|
||||
log.info("每日动态结算任务开始,结算日期:{},用户总数:{}", DateUtil.formatDate(yesterday), marketInfoEntityList.size());
|
||||
List<MarketDailySummaryEntity> dailySummaryEntities = new ArrayList<>(marketInfoEntityList.size());
|
||||
@@ -49,6 +65,22 @@ public class DailyBenefitLogProcessor implements BasicProcessor {
|
||||
summary.setStatDate(yesterday);
|
||||
summary.setUserId(info.getId());
|
||||
summary.setUserAccount(info.getAccount());
|
||||
CommonUserPointEntity userPoint = userPointService.getById(info.getId());
|
||||
if (userPoint != null) {
|
||||
summary.setPersonalUserPointsBalance(userPoint.getAmount());
|
||||
}
|
||||
MarketUserCommissionEntity commission = commissionService.getById(info.getId());
|
||||
if (commission != null) {
|
||||
summary.setPersonalCommissionBalance(commission.getAmount());
|
||||
}
|
||||
MarketBenefitPointEntity benefitPoint = benefitPointService.getById(info.getId());
|
||||
if (benefitPoint != null) {
|
||||
summary.setPersonalBenefitsPointsBalance(benefitPoint.getAmount());
|
||||
}
|
||||
MarketCashCouponEntity cashCoupon = cashCouponService.getById(info.getId());
|
||||
if (cashCoupon != null) {
|
||||
summary.setPersonalCashCouponBalance(cashCoupon.getAmount());
|
||||
}
|
||||
dailySummaryEntities.add(summary);
|
||||
});
|
||||
try {
|
||||
@@ -64,7 +96,8 @@ public class DailyBenefitLogProcessor implements BasicProcessor {
|
||||
}
|
||||
context.getWorkflowContext().appendData2WfContext(USER_LIST, marketInfoEntityList);
|
||||
context.getWorkflowContext().appendData2WfContext(SUMMARY_LIST, dailySummaryEntities);
|
||||
context.getWorkflowContext().appendData2WfContext(DATE, formatDate);
|
||||
context.getWorkflowContext().appendData2WfContext(TODAY, formattedDateToday);
|
||||
context.getWorkflowContext().appendData2WfContext(YESTERDAY, formattedDateYesterday);
|
||||
omsLogger.info("每日动态结算任务结束,结算日期:{},用户总数:{},骨架创建完成。", DateUtil.formatDate(yesterday), marketInfoEntityList.size());
|
||||
return result;
|
||||
}
|
||||
@@ -32,21 +32,22 @@ public class DailyUserCountRelativeProcessor implements BasicProcessor {
|
||||
log.info("直推相关日志统计开始,时间:{}", DateUtil.formatDateTime(DateUtil.now()));
|
||||
Map<String, String> paramsMap = context.getWorkflowContext().getData();
|
||||
|
||||
if (!paramsMap.containsKey(DailyBenefitLogProcessor.USER_LIST) || !paramsMap.containsKey(DailyBenefitLogProcessor.SUMMARY_LIST)) {
|
||||
if (!paramsMap.containsKey(DailySummaryProcessor.USER_LIST) || !paramsMap.containsKey(DailySummaryProcessor.SUMMARY_LIST)) {
|
||||
result.setSuccess(false);
|
||||
result.setMsg("获取用户列表或汇总列表失败");
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
List<MarketInfoSummaryDTO> dtoList = JSONArray.parseArray(paramsMap.get(DailyBenefitLogProcessor.USER_LIST), MarketInfoSummaryDTO.class);
|
||||
List<MarketInfoSummaryDTO> dtoList = JSONArray.parseArray(paramsMap.get(DailySummaryProcessor.USER_LIST), MarketInfoSummaryDTO.class);
|
||||
|
||||
List<MarketDailySummaryEntity> summaryEntityList = JSONArray.parseArray(paramsMap.get(DailyBenefitLogProcessor.SUMMARY_LIST), MarketDailySummaryEntity.class);
|
||||
List<MarketDailySummaryEntity> summaryEntityList = JSONArray.parseArray(paramsMap.get(DailySummaryProcessor.SUMMARY_LIST), MarketDailySummaryEntity.class);
|
||||
Map<Long, MarketDailySummaryEntity> summaryMap = summaryEntityList.stream().collect(Collectors.toMap(MarketDailySummaryEntity::getUserId, s -> s));
|
||||
|
||||
String formatedDate = paramsMap.get(DailyBenefitLogProcessor.DATE);
|
||||
Date date = DateUtil.parse(formatedDate, DateUtil.PATTERN_DATE);
|
||||
Date today = DateUtil.plusDays(date, 1);
|
||||
String formatedDateToday = paramsMap.get(DailySummaryProcessor.TODAY);
|
||||
Date today = DateUtil.parse(formatedDateToday, DateUtil.PATTERN_DATE);
|
||||
String formatedDateYesterday = paramsMap.get(DailySummaryProcessor.YESTERDAY);
|
||||
Date yesterday = DateUtil.parse(formatedDateYesterday, DateUtil.PATTERN_DATE);
|
||||
|
||||
// 构建 children 映射
|
||||
Map<Long, List<MarketInfoSummaryDTO>> pidToChildren = dtoList.stream().filter(u -> u.getPid() != null).collect(Collectors.groupingBy(MarketInfoSummaryDTO::getPid));
|
||||
@@ -70,13 +71,13 @@ public class DailyUserCountRelativeProcessor implements BasicProcessor {
|
||||
int inviteCount = inviteList.size();
|
||||
s.setPersonalTotalInviteCount(inviteCount);
|
||||
//当日新增
|
||||
long increaseCount = inviteList.stream().filter(i -> i.getCreateTime().after(date)).count();
|
||||
long increaseCount = inviteList.stream().filter(i -> i.getCreateTime().after(yesterday)).count();
|
||||
s.setPersonalIncreaseInviteCount((int) increaseCount);
|
||||
// 计算团队总人数
|
||||
int teamTotal = computeTeamSize(u.getId(), pidToChildren, teamSizeCache);
|
||||
s.setTeamMemberCount(teamTotal);
|
||||
// 计算团队当日新增
|
||||
int teamIncrease = computeTeamIncrease(u.getId(), pidToChildren, date, today, teamIncreaseCache);
|
||||
int teamIncrease = computeTeamIncrease(u.getId(), pidToChildren, yesterday, today, teamIncreaseCache);
|
||||
s.setTeamIncreaseCount(teamIncrease);
|
||||
batchList.add(s);
|
||||
});
|
||||
@@ -107,7 +108,7 @@ public class DailyUserCountRelativeProcessor implements BasicProcessor {
|
||||
return size;
|
||||
}
|
||||
|
||||
private int computeTeamIncrease(Long userId, Map<Long, List<MarketInfoSummaryDTO>> pidToChildren, Date date, Date today, Map<Long, Integer> cache) {
|
||||
private int computeTeamIncrease(Long userId, Map<Long, List<MarketInfoSummaryDTO>> pidToChildren, Date yesterday, Date today, Map<Long, Integer> cache) {
|
||||
|
||||
if (cache.containsKey(userId)) {
|
||||
return cache.get(userId);
|
||||
@@ -117,13 +118,13 @@ public class DailyUserCountRelativeProcessor implements BasicProcessor {
|
||||
|
||||
// 当日新增的直接下级数量
|
||||
int increaseCount = (int) children.stream()
|
||||
.filter(c -> c.getCreateTime() != null && c.getCreateTime().after(date))
|
||||
.filter(c -> c.getCreateTime() != null && c.getCreateTime().after(yesterday))
|
||||
.filter(c -> c.getCreateTime().before(today))
|
||||
.count();
|
||||
|
||||
// 递归累加下级的团队当日新增
|
||||
for (MarketInfoSummaryDTO child : children) {
|
||||
increaseCount += computeTeamIncrease(child.getId(), pidToChildren, date, today, cache);
|
||||
increaseCount += computeTeamIncrease(child.getId(), pidToChildren, yesterday, today, cache);
|
||||
}
|
||||
|
||||
cache.put(userId, increaseCount);
|
||||
|
||||
@@ -33,6 +33,7 @@ import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springblade.modules.common.pojo.vo.CommonUserTourOrderVO;
|
||||
import org.springblade.modules.market.pojo.dto.UserOrderSummaryDTO;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
@@ -70,4 +71,7 @@ public interface CommonUserOrderMapper extends BaseMapper<CommonUserOrderEntity>
|
||||
List<CommonUserOrderVO> selectOrderExcelList(Integer orderStatus, String account ,Date startDate, Date endDate , String orderType);
|
||||
|
||||
Long countOrderExcelList(Integer orderStatus, String account ,Date startDate, Date endDate , String orderType);
|
||||
|
||||
List<UserOrderSummaryDTO> selectCurrentOrderBeforeDate(Integer orderStatus, Date date);
|
||||
|
||||
}
|
||||
|
||||
@@ -192,7 +192,15 @@
|
||||
|
||||
</select>
|
||||
|
||||
|
||||
<select id="selectCurrentOrderBeforeDate" resultType="org.springblade.modules.market.pojo.dto.UserOrderSummaryDTO">
|
||||
select id, user_id, order_type, payment_type, actual_amount as amount, update_time
|
||||
from user_order
|
||||
where is_deleted = 0
|
||||
and create_time < #{date}
|
||||
<if test="orderStatus != null">
|
||||
and order_status = #{orderStatus}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
|
||||
</mapper>
|
||||
|
||||
@@ -42,6 +42,7 @@ import org.springblade.modules.common.excel.CommonUserOrderExcel;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import org.springblade.modules.common.pojo.vo.CommonUserTourOrderVO;
|
||||
import org.springblade.modules.market.pojo.dto.UserOrderSummaryDTO;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
@@ -105,4 +106,6 @@ public interface ICommonUserOrderService extends IService<CommonUserOrderEntity>
|
||||
boolean confirmItinerary(Long id);
|
||||
|
||||
boolean closeOrderById(Long id);
|
||||
|
||||
List<UserOrderSummaryDTO> selectCurrentOrderByDate(Date date);
|
||||
}
|
||||
|
||||
@@ -56,6 +56,7 @@ import org.springblade.modules.common.pojo.vo.CommonUserTourOrderVO;
|
||||
import org.springblade.modules.common.service.*;
|
||||
import org.springblade.modules.mall.pojo.entity.MallProductEntity;
|
||||
import org.springblade.modules.mall.service.IMallProductService;
|
||||
import org.springblade.modules.market.pojo.dto.UserOrderSummaryDTO;
|
||||
import org.springblade.modules.market.pojo.entity.MarketInfoEntity;
|
||||
import org.springblade.modules.market.service.IMarketInfoService;
|
||||
import org.springblade.modules.market.service.IMarketUserCommissionService;
|
||||
@@ -469,7 +470,7 @@ public class CommonUserOrderServiceImpl extends ServiceImpl<CommonUserOrderMappe
|
||||
if (!order.getPaymentType().equals(PaymentType.OFFLINE.getCode())) {
|
||||
userPointService.grantPointsByUserOrder(order);
|
||||
MarketInfoEntity marketInfo = marketInfoService.getById(AuthUtil.getUserId());
|
||||
if (marketInfo == null){
|
||||
if (marketInfo == null) {
|
||||
throw new ServiceException("无效用户");
|
||||
}
|
||||
if (marketInfo.getPid() != null) {
|
||||
@@ -612,6 +613,10 @@ public class CommonUserOrderServiceImpl extends ServiceImpl<CommonUserOrderMappe
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UserOrderSummaryDTO> selectCurrentOrderByDate(Date date) {
|
||||
return baseMapper.selectCurrentOrderBeforeDate(OrderStatus.COMPLETED.getCode(), date);
|
||||
}
|
||||
|
||||
private void validateCertificates(CommonTourInfoEntity traveler, TourProductEntity product) {
|
||||
String name = Optional.ofNullable(traveler.getUserName()).orElse("未知用户");
|
||||
|
||||
@@ -27,5 +27,5 @@ public interface MarketBenefitPackageMapper extends BaseMapper<MarketBenefitPack
|
||||
List<MarketBenefitPackageVO> selectUserMarketBenefitPackagePage(IPage page, MarketBenefitPackageVO userMarketBenefitPackage);
|
||||
|
||||
|
||||
List<MarketBenefitsPackageSummaryDTO> selectCurrentBenefitsPackageByDate(Date date);
|
||||
List<MarketBenefitsPackageSummaryDTO> selectCurrentBenefitsPackageByDate(Date today, Date yesterday);
|
||||
}
|
||||
|
||||
@@ -44,8 +44,9 @@
|
||||
select id, user_id, type, user_benefit as benefitsPointFaceValue, amount_total as totalAmount, amount_out as claimedAmount, create_time
|
||||
from user_market_benefit_package
|
||||
where is_deleted = 0
|
||||
and expired_date > #{date}
|
||||
and amount_total > amount_out
|
||||
and expired_date > #{yesterday}
|
||||
and amount_total > amount_out
|
||||
and create_time < #{today}
|
||||
</select>
|
||||
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
<result column="personal_total_invite_count" property="personalTotalInviteCount"/>
|
||||
<result column="personal_increase_invite_count" property="personalIncreaseInviteCount"/>
|
||||
<result column="personal_total_benefits_value" property="personalTotalBenefitsValue"/>
|
||||
<result column="personal_current_benefits_value" property="personalCurrentBenefitsValue"/>
|
||||
<result column="personal_increase_benefits_value" property="personalIncreaseBenefitsValue"/>
|
||||
<result column="personal_increase_benefits_package_detail" property="personalIncreaseBenefitsPackageDetail" typeHandler="org.springblade.common.handler.PgLongArrayToListTypeHandler"/>
|
||||
<result column="personal_benefits_package_speed_up_value" property="personalBenefitsPackageSpeedUpValue"/>
|
||||
@@ -27,6 +28,7 @@
|
||||
<result column="personal_increase_online_amount" property="personalIncreaseOnlineAmount"/>
|
||||
<result column="personal_increase_offline_amount" property="personalIncreaseOfflineAmount"/>
|
||||
<result column="personal_increase_other_amount" property="personalIncreaseOtherAmount"/>
|
||||
<result column="personal_invite_order_holder_count" property="personalInviteOrderHolderCount"/>
|
||||
<result column="personal_cash_level" property="personalCashLevel"/>
|
||||
<result column="personal_increase_order_detail" property="personalIncreaseOrderDetail" typeHandler="org.springblade.common.handler.PgLongArrayToListTypeHandler"/>
|
||||
<result column="personal_dynamic_rewards_amount" property="personalDynamicRewardsAmount"/>
|
||||
@@ -37,6 +39,7 @@
|
||||
<result column="team_member_count" property="teamMemberCount"/>
|
||||
<result column="team_increase_count" property="teamIncreaseCount"/>
|
||||
<result column="team_total_benefits_value" property="teamTotalBenefitsValue"/>
|
||||
<result column="team_current_benefits_value" property="teamCurrentBenefitsValue"/>
|
||||
<result column="team_increase_benefits_value" property="teamIncreaseBenefitsValue"/>
|
||||
<result column="team_benefits_package_holder_count" property="teamBenefitsPackageHolderCount"/>
|
||||
<result column="team_increase_benefits_package_detail" property="teamIncreaseBenefitsPackageDetail" typeHandler="org.springblade.common.handler.PgLongArrayToListTypeHandler"/>
|
||||
|
||||
@@ -31,6 +31,8 @@ import org.springblade.modules.market.pojo.entity.MarketInfoEntity;
|
||||
import org.springblade.modules.market.pojo.vo.MarketInfoVO;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -52,6 +54,5 @@ public interface MarketInfoMapper extends BaseMapper<MarketInfoEntity> {
|
||||
|
||||
List<Long> selectAncestorIds(@Param("userId") Long userId);
|
||||
|
||||
List<MarketInfoSummaryDTO> selectMarketInfoSummary();
|
||||
|
||||
List<MarketInfoSummaryDTO> selectMarketInfoSummaryByDate(Date date);
|
||||
}
|
||||
|
||||
@@ -76,11 +76,11 @@
|
||||
ORDER BY depth
|
||||
</select>
|
||||
|
||||
<select id="selectMarketInfoSummary" resultType="org.springblade.modules.market.pojo.dto.MarketInfoSummaryDTO">
|
||||
<select id="selectMarketInfoSummaryByDate" resultType="org.springblade.modules.market.pojo.dto.MarketInfoSummaryDTO">
|
||||
select umi.id as id, umi.pid as pid ,bu.account as account, bu.create_time as createTime
|
||||
from user_market_info umi
|
||||
left join blade_user bu on umi.id = bu.id
|
||||
where umi.is_deleted = 0
|
||||
where umi.is_deleted = 0 and bu.create_time < #{date}
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package org.springblade.modules.market.pojo.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class UserOrderSummaryDTO implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Long id;
|
||||
|
||||
private Long userId;
|
||||
|
||||
private String orderType;
|
||||
|
||||
private Integer paymentType;
|
||||
|
||||
private BigDecimal amount;
|
||||
|
||||
private Date updateTime;
|
||||
|
||||
}
|
||||
@@ -75,8 +75,8 @@ public class MarketDailySummaryEntity extends BaseEntity {
|
||||
/**
|
||||
* 统计日期,如 '2026-04-29'
|
||||
*/
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
@Schema(description = "统计日期,如 '2026-04-29'")
|
||||
private Date statDate;
|
||||
/**
|
||||
@@ -94,11 +94,21 @@ public class MarketDailySummaryEntity extends BaseEntity {
|
||||
*/
|
||||
@Schema(description = "个人总福利值(由持有的有效福利包赋予的累计值)")
|
||||
private BigDecimal personalTotalBenefitsValue;
|
||||
/**
|
||||
* 个人有效总福利值(不包含划拨的福利包)
|
||||
*/
|
||||
@Schema(description = "个人有效总福利值(不包含划拨的福利包)")
|
||||
private BigDecimal personalCurrentBenefitsValue;
|
||||
/**
|
||||
* 当日新增个人福利值
|
||||
*/
|
||||
@Schema(description = "当日新增个人福利值")
|
||||
private BigDecimal personalIncreaseBenefitsValue;
|
||||
/**
|
||||
* 当日新增个人有效福利值
|
||||
*/
|
||||
@Schema(description = "当日新增个人有效福利值")
|
||||
private BigDecimal personalIncreaseCurrentBenefitsValue;
|
||||
/**
|
||||
* 个人当日新增福利包明细(存储福利包主键ID数组)
|
||||
*/
|
||||
@@ -171,6 +181,11 @@ public class MarketDailySummaryEntity extends BaseEntity {
|
||||
*/
|
||||
@Schema(description = "当日新增其他渠道个人消费金额")
|
||||
private BigDecimal personalIncreaseOtherAmount;
|
||||
/**
|
||||
* 有现金消费的直推人数
|
||||
*/
|
||||
@Schema(description = "有现金消费的直推人数")
|
||||
private Integer personalInviteOrderHolderCount;
|
||||
/**
|
||||
* 当日现金动态系统等级
|
||||
*/
|
||||
@@ -222,6 +237,11 @@ public class MarketDailySummaryEntity extends BaseEntity {
|
||||
*/
|
||||
@Schema(description = "团队总福利值(不含本人,累计)")
|
||||
private BigDecimal teamTotalBenefitsValue;
|
||||
/**
|
||||
* 团队总有效福利值(不包含划拨的福利包)
|
||||
*/
|
||||
@Schema(description = "团队总有效福利值(不包含划拨的福利包)")
|
||||
private BigDecimal teamCurrentBenefitsValue;
|
||||
/**
|
||||
* 当日新增团队福利值(不含本人)
|
||||
*/
|
||||
|
||||
@@ -30,5 +30,5 @@ public interface IMarketBenefitPackageService extends BaseService<MarketBenefitP
|
||||
|
||||
boolean revokeBenefitPackInfo(Long id);
|
||||
|
||||
List<MarketBenefitsPackageSummaryDTO> selectCurrentBenefitsPackageByDate(Date date);
|
||||
List<MarketBenefitsPackageSummaryDTO> selectCurrentBenefitsPackageByDate(Date today, Date yesterday);
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import org.springblade.core.mp.base.BaseService;
|
||||
import org.springblade.modules.system.pojo.entity.User;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -60,6 +61,6 @@ public interface IMarketInfoService extends BaseService<MarketInfoEntity> {
|
||||
|
||||
boolean hasVerifyRealName(Long userId);
|
||||
|
||||
List<MarketInfoSummaryDTO> selectMarketInfoSummary();
|
||||
List<MarketInfoSummaryDTO> selectMarketInfoSummaryByDate(Date date);
|
||||
|
||||
}
|
||||
|
||||
@@ -79,8 +79,8 @@ public class MarketBenefitPackageServiceImpl extends BaseServiceImpl<MarketBenef
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MarketBenefitsPackageSummaryDTO> selectCurrentBenefitsPackageByDate(Date date) {
|
||||
return baseMapper.selectCurrentBenefitsPackageByDate(date);
|
||||
public List<MarketBenefitsPackageSummaryDTO> selectCurrentBenefitsPackageByDate(Date today, Date yesterday) {
|
||||
return baseMapper.selectCurrentBenefitsPackageByDate(today, yesterday);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -57,6 +57,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import org.springblade.core.mp.base.BaseServiceImpl;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
@@ -186,7 +187,7 @@ public class MarketInfoServiceImpl extends BaseServiceImpl<MarketInfoMapper, Mar
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MarketInfoSummaryDTO> selectMarketInfoSummary() {
|
||||
return baseMapper.selectMarketInfoSummary();
|
||||
public List<MarketInfoSummaryDTO> selectMarketInfoSummaryByDate(Date date) {
|
||||
return baseMapper.selectMarketInfoSummaryByDate(date);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user