From 15bfd012429367bf9b8f03bdc8bb101ae0bdfe4d Mon Sep 17 00:00:00 2001 From: Pu Zhibing <393733352@qq.com> Date: 星期五, 21 三月 2025 15:26:39 +0800 Subject: [PATCH] 修改统计bug --- ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/AppUserController.java | 200 +++++++++++++++++++++++++++++++++---------------- 1 files changed, 135 insertions(+), 65 deletions(-) diff --git a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/AppUserController.java b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/AppUserController.java index 0ef6e50..5d9b385 100644 --- a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/AppUserController.java +++ b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/AppUserController.java @@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollectionUtil; import com.alibaba.fastjson2.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; @@ -171,7 +172,7 @@ @PostMapping("/getCouponCount") public R<Long> getCouponCount(@RequestParam("userId") Long userId, @RequestParam("couponId") Integer couponId) { LambdaQueryChainWrapper<UserCoupon> chainWrapper = userCouponService.lambdaQuery().eq(UserCoupon::getCouponId, couponId); - if(null != userId && -1 == userId){ + if(null != userId && -1 != userId){ chainWrapper.eq(UserCoupon::getAppUserId, userId); } Long count = chainWrapper.count(); @@ -322,7 +323,11 @@ //获取绑定上级 if (user.getInviteUserId() != null) { AppUser byId = appUserService.getById(user.getInviteUserId()); - user.setTopUser(byId); + if(null != byId){ + user.setTopUser(byId); + }else{ + user.setTopUser(new AppUser()); + } }else { AppUser topUser = new AppUser(); user.setTopUser(topUser); @@ -370,7 +375,6 @@ .eq(AppUser::getDelFlag, 0) .ne(AppUser::getStatus, 3) .count(); - vip1Count1 += count1; Long count2 = appUserService.lambdaQuery() .eq(AppUser::getVipId, 2) @@ -378,42 +382,36 @@ .eq(AppUser::getDelFlag, 0) .ne(AppUser::getStatus, 3) .count(); - vip1Count2 += count2; Long count3 = appUserService.lambdaQuery() .eq(AppUser::getVipId, 3) .eq(AppUser::getInviteUserId, appUser.getId()) .eq(AppUser::getDelFlag, 0) .ne(AppUser::getStatus, 3) .count(); - vip1Count3 += count3; Long count4 = appUserService.lambdaQuery() .eq(AppUser::getVipId, 4) .eq(AppUser::getInviteUserId, appUser.getId()) .eq(AppUser::getDelFlag, 0) .ne(AppUser::getStatus, 3) .count(); - vip1Count4 += count4; Long count5 = appUserService.lambdaQuery() .eq(AppUser::getVipId, 5) .eq(AppUser::getInviteUserId, appUser.getId()) .eq(AppUser::getDelFlag, 0) .ne(AppUser::getStatus, 3) .count(); - vip1Count5 += count5; Long count6 = appUserService.lambdaQuery() .eq(AppUser::getVipId, 6) .eq(AppUser::getInviteUserId, appUser.getId()) .eq(AppUser::getDelFlag, 0) .ne(AppUser::getStatus, 3) .count(); - vip1Count6 += count6; Long count7 = appUserService.lambdaQuery() .eq(AppUser::getVipId, 7) .eq(AppUser::getInviteUserId, appUser.getId()) .eq(AppUser::getDelFlag, 0) .ne(AppUser::getStatus, 3) .count(); - vip1Count7 += count7; appUser.setCount1(count1); appUser.setCount2(count2); appUser.setCount3(count3); @@ -422,6 +420,7 @@ appUser.setCount6(count6); appUser.setCount7(count7); } + user.setBottomUsers(list); user.setCount1(vip1Count1); user.setCount2(vip1Count2); @@ -511,42 +510,23 @@ ArrayList<Long> userIds = new ArrayList<>(); userIds.add(userId); // 获取当前用户的所有下级 - List<AppUser> allSubordinates = getAllSubordinates(userId); - // 统计下级中每种会员类型的人数 - Map<Integer, Long> countMap = allSubordinates.stream() - .collect(Collectors.groupingBy(AppUser::getVipId, Collectors.counting())); - countMap.forEach((vipId, count) -> { - switch (vipId) { - case 1: - Long count1 = user.getCount1() == null ? 0 : user.getCount1(); - user.setCount1(count1 + count); - break; - case 2: - Long count2 = user.getCount2() == null ? 0 : user.getCount2(); - user.setCount2(count2 + count); - break; - case 3: - Long count3 = user.getCount3() == null ? 0 : user.getCount3(); - user.setCount3(count3 + count); - break; - case 4: - Long count4 = user.getCount4() == null ? 0 : user.getCount4(); - user.setCount4(count4 + count); - break; - case 5: - Long count5 = user.getCount5() == null ? 0 : user.getCount5(); - user.setCount5(count5 + count); - break; - case 6: - Long count6 = user.getCount6() == null ? 0 : user.getCount6(); - user.setCount6(count6 + count); - break; - case 7: - Long count7 = user.getCount7() == null ? 0 : user.getCount7(); - user.setCount7(count7 + count); - break; - } - }); + List<AppUser> allSubordinates = appUserService.list(new LambdaQueryWrapper<AppUser>() + .eq(AppUser::getInviteUserId, user.getId()).eq(AppUser::getDelFlag, 0) + .ne(AppUser::getStatus, 3)); + Long count1 = allSubordinates.stream().filter(s->s.getVipId() == 1).count(); + user.setCount1(count1); + Long count2 = allSubordinates.stream().filter(s->s.getVipId() == 2).count(); + user.setCount2(count2); + Long count3 = allSubordinates.stream().filter(s->s.getVipId() == 3).count(); + user.setCount3(count3); + Long count4 = allSubordinates.stream().filter(s->s.getVipId() == 4).count(); + user.setCount4(count4); + Long count5 = allSubordinates.stream().filter(s->s.getVipId() == 5).count(); + user.setCount5(count5); + Long count6 = allSubordinates.stream().filter(s->s.getVipId() == 6).count(); + user.setCount6(count6); + Long count7 = allSubordinates.stream().filter(s->s.getVipId() == 7).count(); + user.setCount7(count7); List<UserSignRecord> list = userSignRecordService.lambdaQuery().eq(UserSignRecord::getSignDay, LocalDate.now()) .eq(UserSignRecord::getAppUserId,userId).list(); if (!list.isEmpty()) { @@ -688,14 +668,77 @@ return R.ok(list); } + + @GetMapping("/getUserPointsPage") + @ApiOperation(value = "用户列表", tags = {"管理后台"}) + public R<IPage<AppUser>> getUserPointsPage(@ApiParam("页码") @RequestParam Integer pageNum, + @ApiParam("每一页数据大小") Integer pageSize, + AppUser appUser) { + + Long userId = tokenService.getLoginUser().getUserid(); + SysUser data = sysUserClient.getSysUser(userId).getData(); + + QueryWrapper<AppUser> queryWrapper = new QueryWrapper<>(); + if (data.getRoleType() == 2) { + Integer shopId = data.getObjectId(); + List<Order> orders = orderClient.getRedeemedOrdersByShop(shopId).getData(); + List<Long> userIds = orders.stream().map(Order::getAppUserId).collect(Collectors.toList()); + queryWrapper.in(!CollectionUtils.isEmpty(userIds), "id", userIds) + .like(StringUtils.isNotEmpty( appUser.getName()),"name", appUser.getName()); + } + queryWrapper.eq("del_flag", 0); + queryWrapper.ne("status", 3); + + List<AppUser> appUserList = appUserService.list(queryWrapper); + Page<AppUser> objectPage = Page.of(pageNum, pageSize); + objectPage.setRecords(appUserList); + return R.ok(objectPage); + + } + /** * 获取用户列表 */ @GetMapping("/getAppuserPage") - @ApiOperation(value = "用户列表", tags = {"管理后台"}) public R<IPage<AppUser>> getAppuserPage(@ApiParam("页码") @RequestParam Integer pageNum, - @ApiParam("每一页数据大小") Integer pageSize, - AppUser appUser) { + @ApiParam("每一页数据大小") Integer pageSize, + AppUser appUser){ + + Long userid = tokenService.getLoginUser().getUserid(); + SysUser sysUser = sysUserClient.getSysUser(userid).getData(); + Integer shopId = null; + Set<Long> userId = null; + if(sysUser.getRoleType() == 2){ + shopId = sysUser.getObjectId(); + userId = orderClient.getAppUserByShoppingShop(shopId).getData(); + } + appUser.setExcludeStatus(3); + IPage<AppUser> appuserPage = appUserService.getAppuserPage(pageNum, pageSize, appUser, shopId, userId); + for (AppUser record : appuserPage.getRecords()) { + if (record.getInviteUserId() != null) { + AppUser byId1 = appUserService.getById(record.getInviteUserId()); + if (byId1!=null) { + record.setInviteUserName(byId1.getName()); + } + } + Shop shop1 = shopClient.getServiceProvider(record.getId()).getData(); + if(null != shop1){ + record.setShopName(shop1.getName()); + record.setShopId(shop1.getId()); + } + record.setTotalPoint(record.getUserTotalPoint()); + } + return R.ok(appuserPage); + } + + + /** + * 获取用户积分列表 + */ + @GetMapping("/getUserPotPage") + public R<IPage<AppUser>> getUserPotPage(@ApiParam("页码") @RequestParam Integer pageNum, + @ApiParam("每一页数据大小") Integer pageSize, + AppUser appUser) { Long userid = tokenService.getLoginUser().getUserid(); SysUser sysUser = sysUserClient.getSysUser(userid).getData(); Integer shopId = null; @@ -718,9 +761,11 @@ record.setShopName(shopById.getData().getName()); } } + record.setTotalPoint(record.getUserTotalPoint()); } return R.ok(appuserPage); } + @GetMapping("/shop/getAppuserPage") @ApiOperation(value = "用户列表", tags = {"门店后台"}) @@ -908,9 +953,10 @@ Long userid = tokenService.getLoginUser().getUserid(); SysUser sysUser = sysUserClient.getSysUser(userid).getData(); AppUser byId = appUserService.getById(id); - Shop shop1 = shopClient.getServiceProvider(id).getData(); + Shop shop1 = shopClient.getServiceProvider(byId.getId()).getData(); if(null != shop1){ byId.setShopName(shop1.getName()); + byId.setShopId(shop1.getId()); } R<List<Shop>> shopByUserId = shopClient.getShopByUserId(id); if (shopByUserId.getData() != null) { @@ -1072,22 +1118,46 @@ @GetMapping("/statistics") @ApiOperation(value = "用户统计", tags = {"管理后台-首页统计-用户统计"}) public R<UserStatistics> statistics() { - Long userid = tokenService.getLoginUser().getUserid(); - SysUser data = sysUserClient.getSysUser(userid).getData(); - Integer shopId = null; - Set<Long> userId = null; - if(data.getRoleType() == 2){ - shopId = data.getObjectId(); - userId = orderClient.getAppUserByShoppingShop(shopId).getData(); + Long userId = tokenService.getLoginUser().getUserid(); + SysUser data = sysUserClient.getSysUser(userId).getData(); + + QueryWrapper<AppUser> queryWrapper = new QueryWrapper<>(); + if (data.getRoleType() == 2) { + Integer shopId = data.getObjectId(); + List<Order> orders = orderClient.getRedeemedOrdersByShop(shopId).getData(); + List<Long> userIds = orders.stream().map(Order::getAppUserId).collect(Collectors.toList()); + queryWrapper.in(!CollectionUtils.isEmpty(userIds), "id", userIds); // userIds 不为空时,查询 id 在 userIds 中 } - UserStatistics userStatistics = appUserMapper.getUserStatistics(shopId, userId); - List<Shop> shopList = shopClient.getAllShop().getData(); - if (CollectionUtil.isNotEmpty(shopList)){ - long count = shopList.stream().map(Shop::getAppUserId).distinct().count(); - userStatistics.setShopUser((int) count); - }else { - userStatistics.setShopUser(0); - } + queryWrapper.eq("del_flag", 0); + queryWrapper.ne("status", 3); + List<AppUser> appUserList = appUserService.list(queryWrapper); + + Map<Integer, Long> vipIdCountMap = appUserList.stream() + .collect(Collectors.groupingBy(AppUser::getVipId, Collectors.counting())); + + UserStatistics userStatistics = new UserStatistics(); + userStatistics.setTotalUser(appUserList.size()); + userStatistics.setConsumerUser(vipIdCountMap.getOrDefault(0, 0L).intValue() + + vipIdCountMap.getOrDefault(1, 0L).intValue() + + vipIdCountMap.getOrDefault(2, 0L).intValue() + + vipIdCountMap.getOrDefault(3, 0L).intValue()); + userStatistics.setCommonUser(vipIdCountMap.getOrDefault(1, 0L).intValue()); + userStatistics.setGoldUser(vipIdCountMap.getOrDefault(2, 0L).intValue()); + userStatistics.setDiamondUser(vipIdCountMap.getOrDefault(3, 0L).intValue()); + userStatistics.setEntrepreneurUser(vipIdCountMap.getOrDefault(4, 0L).intValue() + + vipIdCountMap.getOrDefault(5, 0L).intValue() + + vipIdCountMap.getOrDefault(6, 0L).intValue() + + vipIdCountMap.getOrDefault(7, 0L).intValue()); + userStatistics.setProxyUser(vipIdCountMap.getOrDefault(4, 0L).intValue()); + userStatistics.setAgentUser(vipIdCountMap.getOrDefault(5, 0L).intValue()); + userStatistics.setTotalAgentUser(vipIdCountMap.getOrDefault(6, 0L).intValue()); + userStatistics.setPartnerUser(vipIdCountMap.getOrDefault(7, 0L).intValue()); + + long shopUserCount = appUserList.stream() + .filter(appUser -> appUser.getUserType() == 2) + .count(); + userStatistics.setShopUser((int) shopUserCount); + return R.ok(userStatistics); } @@ -1142,7 +1212,7 @@ .eq(BalanceChangeRecord::getVipId, i); if(sysUser.getRoleType() == 2){ Integer objectId = sysUser.getObjectId(); - List<AppUser> list = appUserService.list(new LambdaQueryWrapper<AppUser>().eq(AppUser::getShopId, objectId).eq(AppUser::getDelFlag, 0).eq(AppUser::getStatus, 1)); + List<AppUser> list = appUserService.list(new LambdaQueryWrapper<AppUser>().eq(AppUser::getShopId, objectId).eq(AppUser::getDelFlag, 0).ne(AppUser::getStatus, 1)); List<Long> appUserIds = list.stream().map(AppUser::getId).collect(Collectors.toList()); Set<Long> data = orderClient.getAppUserByShoppingShop(objectId).getData(); if(null != data){ -- Gitblit v1.7.1