| | |
| | | |
| | | import cn.hutool.core.collection.CollectionUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.account.api.model.AppUser; |
| | | import com.ruoyi.account.api.model.UserPoint; |
| | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | |
| | | |
| | | @Override |
| | | public UserPointStatistics getStatistics(UserPoint userPoint) { |
| | | LoginUser loginUser = tokenService.getLoginUser(); |
| | | userPoint.setAppUserId(loginUser.getUserid()); |
| | | List<UserPoint> userPointList = userPointMapper.findLatestChangeByType(userPoint); |
| | | Map<Integer, Integer> userBalanceMap = userPointList.stream() |
| | | .collect(Collectors.toMap(UserPoint::getType, UserPoint::getBalance)); |
| | | 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()); |
| | | |
| | | 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; |
| | | list(new LambdaQueryWrapper<UserPoint>() |
| | | .in(!CollectionUtils.isEmpty(userIds), UserPoint::getAppUserId, userIds) |
| | | .eq(UserPoint::getType, userPoint.getType()) |
| | | .between(UserPoint::getCreateTime, userPoint.getStartTime(), userPoint.getEndTime())); |
| | | |
| | | |
| | | 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; |
| | | return null; |
| | | } |
| | | |
| | | @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())); |
| | | 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()) |
| | | .orderByDesc(UserPoint::getCreateTime)); |
| | | |
| | | userPointPage.getRecords().forEach(userPoint1 -> appUserList.stream() |
| | | .filter(appUser -> appUser.getId().equals(userPoint1.getAppUserId())) |
| | | .findFirst().ifPresent(appUser -> { |
| | | userPoint1.setUserName(appUser.getName()); |
| | | userPoint1.setPhone(appUser.getPhone()); |
| | | })); |
| | | return userPointPage; |
| | | } |
| | | } |