| | |
| | | |
| | | @Override |
| | | public UserPointStatistics getStatistics(UserPoint userPoint) { |
| | | 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); |
| | | } |
| | | |
| | | if (StringUtils.isNotEmpty(userPoint.getUserName()) || StringUtils.isNotEmpty(userPoint.getPhone())) { |
| | | List<Long> userIds = appUserService.listObjs(new LambdaQueryWrapper<AppUser>() |
| | | .select(AppUser::getId) |
| | | .like(StringUtils.isNotEmpty(userPoint.getUserName()),AppUser::getName, userPoint.getUserName()) |
| | | .like(StringUtils.isNotEmpty(userPoint.getPhone()),AppUser::getPhone, userPoint.getPhone())) |
| | | .stream() |
| | | .map(appUserId -> (Long) appUserId) |
| | | .collect(Collectors.toList()); |
| | | userPoint.setUserIds(userIds); |
| | | List<UserPoint> userPointList = userPointMapper.findLatestChangeByType(userPoint); |
| | | |
| | | Map<Integer, Integer> userBalanceMap = userPointList.stream() |
| | | .collect(Collectors.groupingBy( |
| | | UserPoint::getType, |
| | | Collectors.summingInt(UserPoint::getBalance) |
| | | )); |
| | | |
| | | 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); |
| | | } |
| | | |
| | | List<UserPoint> userPointList = userPointMapper.findLatestChangeByType(userPoint); |
| | | Map<Integer, Integer> userBalanceMap = userPointList.stream() |
| | | .collect(Collectors.toMap(UserPoint::getType, UserPoint::getBalance)); |
| | | |
| | | |
| | | Integer consumePoint = Optional.ofNullable(userBalanceMap.get(PointChangeType.CONSUME.getCode())).orElse(0); |
| | | Integer sharePoint = Optional.ofNullable(userBalanceMap.get(PointChangeType.COMMISSION_RETURN.getCode())).orElse(0); |
| | | Integer pullNewPoint = Optional.ofNullable(userBalanceMap.get(PointChangeType.NEW_USER_REFERRAL.getCode())).orElse(0); |
| | | Integer registerPoint = Optional.ofNullable(userBalanceMap.get(PointChangeType.REGISTRATION.getCode())).orElse(0); |
| | | Integer workPoint = Optional.ofNullable(userBalanceMap.get(PointChangeType.WORK_PERFORMANCE.getCode())).orElse(0); |
| | | Integer shopAchievementPoint = Optional.ofNullable(userBalanceMap.get(PointChangeType.TECHNICIAN_PERFORMANCE.getCode())).orElse(0); |
| | | Integer exchangeGoodsPoint = Optional.ofNullable(userBalanceMap.get(PointChangeType.EXCHANGE_GOODS.getCode())).orElse(0); |
| | | Integer storeAchievementPoint = Optional.ofNullable(userBalanceMap.get(PointChangeType.STORE_PERFORMANCE.getCode())).orElse(0); |
| | | Integer storeCommissionPoint = Optional.ofNullable(userBalanceMap.get(PointChangeType.STORE_COMMISSION_RETURN.getCode())).orElse(0); |
| | | Integer transferPoint = Optional.ofNullable(userBalanceMap.get(PointChangeType.TRANSFER_POINTS.getCode())).orElse(0); |
| | | Integer 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; |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public IPage<UserPoint> getUserPointPage(Page<UserPoint> page, UserPoint userPoint) { |
| | | List<AppUser> appUserList = appUserService.list(new LambdaQueryWrapper<AppUser>() |