From cf4e9e9e041545f77f57f7a0c3485d66efe5ce19 Mon Sep 17 00:00:00 2001
From: phpcjl <phpcjl@gmail.com>
Date: 星期二, 17 十二月 2024 16:33:34 +0800
Subject: [PATCH] 1
---
ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/service/impl/UserPointServiceImpl.java | 71 +++++++++++++++++++++++++++--------
1 files changed, 54 insertions(+), 17 deletions(-)
diff --git a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/service/impl/UserPointServiceImpl.java b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/service/impl/UserPointServiceImpl.java
index 590c636..61c0ede 100644
--- a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/service/impl/UserPointServiceImpl.java
+++ b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/service/impl/UserPointServiceImpl.java
@@ -18,6 +18,7 @@
import com.ruoyi.account.vo.UserPointVO;
import com.ruoyi.common.core.exception.ServiceException;
import com.ruoyi.common.core.utils.PhoneNumberValidator;
+import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.security.service.TokenService;
import com.ruoyi.other.api.domain.PointSetting;
import com.ruoyi.other.api.domain.VipSetting;
@@ -30,10 +31,7 @@
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.time.LocalDateTime;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
+import java.util.*;
import java.util.stream.Collectors;
/**
@@ -165,32 +163,71 @@
@Override
public UserPointStatistics getStatistics(UserPoint userPoint) {
- List<AppUser> appUserList = appUserService.list(new LambdaQueryWrapper<AppUser>()
- .eq(AppUser::getPhone, userPoint.getPhone())
- .like(AppUser::getName, userPoint.getUserName()));
- List<Long> userIds = appUserList.stream().map(AppUser::getId).collect(Collectors.toList());
+ try {
+ if (StringUtils.isNotEmpty(userPoint.getUserName()) && StringUtils.isNotEmpty(userPoint.getPhone())) {
+ List<Long> userIds = appUserService.listObjs(new LambdaQueryWrapper<AppUser>()
+ .select(AppUser::getId)
+ .like(AppUser::getName, userPoint.getUserName())
+ .like(AppUser::getPhone, userPoint.getPhone()))
+ .stream()
+ .map(appUserId -> (Long) appUserId)
+ .collect(Collectors.toList());
+ userPoint.setUserIds(userIds);
+ }
- list(new LambdaQueryWrapper<UserPoint>()
- .in(!CollectionUtils.isEmpty(userIds), UserPoint::getAppUserId, userIds)
- .eq(UserPoint::getType, userPoint.getType())
- .between(UserPoint::getCreateTime, userPoint.getStartTime(), userPoint.getEndTime()));
+ List<UserPoint> userPointList = userPointMapper.findLatestChangeByType(userPoint);
+ Map<Integer, Integer> userBalanceMap = userPointList.stream()
+ .collect(Collectors.groupingBy(
+ UserPoint::getType,
+ Collectors.summingInt(UserPoint::getBalance)
+ ));
- return null;
+ int consumePoint = userBalanceMap.getOrDefault(PointChangeType.CONSUME.getCode(), 0);
+ int sharePoint = userBalanceMap.getOrDefault(PointChangeType.COMMISSION_RETURN.getCode(), 0);
+ int pullNewPoint = userBalanceMap.getOrDefault(PointChangeType.NEW_USER_REFERRAL.getCode(), 0);
+ int registerPoint = userBalanceMap.getOrDefault(PointChangeType.REGISTRATION.getCode(), 0);
+ int workPoint = userBalanceMap.getOrDefault(PointChangeType.WORK_PERFORMANCE.getCode(), 0);
+ int shopAchievementPoint = userBalanceMap.getOrDefault(PointChangeType.TECHNICIAN_PERFORMANCE.getCode(), 0);
+ int exchangeGoodsPoint = userBalanceMap.getOrDefault(PointChangeType.EXCHANGE_GOODS.getCode(), 0);
+ int storeAchievementPoint = userBalanceMap.getOrDefault(PointChangeType.STORE_PERFORMANCE.getCode(), 0);
+ int storeCommissionPoint = userBalanceMap.getOrDefault(PointChangeType.STORE_COMMISSION_RETURN.getCode(), 0);
+ int transferPoint = userBalanceMap.getOrDefault(PointChangeType.TRANSFER_POINTS.getCode(), 0);
+ int totalPoint = consumePoint + sharePoint + pullNewPoint + registerPoint + workPoint + shopAchievementPoint + exchangeGoodsPoint + storeAchievementPoint + storeCommissionPoint + transferPoint;
+
+ UserPointStatistics userPointStatistics = new UserPointStatistics();
+ userPointStatistics.setTotalPoint(totalPoint);
+ userPointStatistics.setConsumePoint(consumePoint);
+ userPointStatistics.setSharePoint(sharePoint);
+ userPointStatistics.setPullNewPoint(pullNewPoint);
+ userPointStatistics.setRegisterPoint(registerPoint);
+ userPointStatistics.setWorkPoint(workPoint);
+ userPointStatistics.setShopAchievementPoint(shopAchievementPoint);
+
+ return userPointStatistics;
+ } catch (Exception e) {
+ // 记录异常日志
+ log.error("获取用户点统计信息时出错", e);
+ throw new RuntimeException("获取用户点统计信息时出错", e);
+ }
}
+
@Override
public IPage<UserPoint> getUserPointPage(Page<UserPoint> page, UserPoint userPoint) {
List<AppUser> appUserList = appUserService.list(new LambdaQueryWrapper<AppUser>()
.eq(AppUser::getPhone, userPoint.getPhone())
.like(AppUser::getName, userPoint.getUserName()));
+ if (appUserList.isEmpty()){
+ return page;
+ }
+
List<Long> userIds = appUserList.stream().map(AppUser::getId).collect(Collectors.toList());
Page<UserPoint> userPointPage = page(page, new LambdaQueryWrapper<UserPoint>()
- .in(!CollectionUtils.isEmpty(userIds), UserPoint::getAppUserId, userIds)
- .eq(UserPoint::getType, userPoint.getType())
- .between(userPoint.getStartTime() !=null && userPoint.getEndTime() != null,
- UserPoint::getCreateTime, userPoint.getStartTime(), userPoint.getEndTime())
+ .in(UserPoint::getAppUserId, userIds)
+ .eq(userPoint.getType() != null, UserPoint::getType, userPoint.getType())
+ .between( userPoint.getStartTime()!= null && userPoint.getEndTime() !=null,UserPoint::getCreateTime, userPoint.getStartTime(), userPoint.getEndTime())
.orderByDesc(UserPoint::getCreateTime));
userPointPage.getRecords().forEach(userPoint1 -> appUserList.stream()
--
Gitblit v1.7.1