From cbf2486983b77a27af9968bbb362cb8d43789115 Mon Sep 17 00:00:00 2001 From: Pu Zhibing <393733352@qq.com> Date: 星期三, 26 三月 2025 15:30:53 +0800 Subject: [PATCH] 修改统计bug和部分功能修改 --- ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/AppUserController.java | 168 +++++++++++++++++++++++++++++++++++++------------------ 1 files changed, 113 insertions(+), 55 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 e99289b..013d0f6 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 @@ -323,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); @@ -371,7 +375,6 @@ .eq(AppUser::getDelFlag, 0) .ne(AppUser::getStatus, 3) .count(); - vip1Count1 += count1; Long count2 = appUserService.lambdaQuery() .eq(AppUser::getVipId, 2) @@ -379,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); @@ -423,6 +420,7 @@ appUser.setCount6(count6); appUser.setCount7(count7); } + user.setBottomUsers(list); user.setCount1(vip1Count1); user.setCount2(vip1Count2); @@ -512,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()) { @@ -595,10 +574,42 @@ } return allSubordinates; } - - - - + + + /** + * 获取门店作为服务商的所有用户 + * @param shopId + * @return + */ + public Set<Long> getShopServerUser(Integer shopId){ + Shop shop = shopClient.getShopById(shopId).getData(); + List<Shop> shopList = shopClient.getAllShop().getData(); + List<Long> appUserIds = shopList.stream().map(Shop::getAppUserId).collect(Collectors.toList()); + Long appUserId = shop.getAppUserId(); + //所有未开店的用户 + List<AppUser> list = appUserService.list(new LambdaQueryWrapper<AppUser>().eq(AppUser::getDelFlag, 0) + .ne(AppUser::getStatus, 3).notIn(AppUser::getId, appUserIds)); + Set<Long> ids = new HashSet<>(); + getShopServerUser(appUserId, list, ids); + return ids; + } + + + + public void getShopServerUser(Long appUserId, List<AppUser> appUserList, Set<Long> ids){ + List<AppUser> collect = appUserList.stream().filter(s->s.getInviteUserId().equals(appUserId)).collect(Collectors.toList()); + if(collect.size() == 0){ + return; + } + Set<Long> appUserSet = collect.stream().map(AppUser::getId).collect(Collectors.toSet()); + if(ids.containsAll(appUserSet)){ + return; + } + ids.addAll(appUserSet); + for (AppUser appUser : collect) { + getShopServerUser(appUser.getId(), appUserList, ids); + } + } @@ -704,6 +715,9 @@ Integer shopId = data.getObjectId(); List<Order> orders = orderClient.getRedeemedOrdersByShop(shopId).getData(); List<Long> userIds = orders.stream().map(Order::getAppUserId).collect(Collectors.toList()); + //门店作为服务商的用户 + Set<Long> shopServerUser = getShopServerUser(shopId); + userIds.addAll(shopServerUser); queryWrapper.in(!CollectionUtils.isEmpty(userIds), "id", userIds) .like(StringUtils.isNotEmpty( appUser.getName()),"name", appUser.getName()); } @@ -733,6 +747,41 @@ 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; + Set<Long> userId = null; + if(sysUser.getRoleType() == 2){ + shopId = sysUser.getObjectId(); + userId = orderClient.getAppUserByShoppingShop(shopId).getData(); + } IPage<AppUser> appuserPage = appUserService.getAppuserPage(pageNum, pageSize, appUser, shopId, userId); for (AppUser record : appuserPage.getRecords()) { if (record.getInviteUserId() != null) { @@ -747,10 +796,10 @@ record.setShopName(shopById.getData().getName()); } } + record.setTotalPoint(record.getUserTotalPoint()); } return R.ok(appuserPage); } - @GetMapping("/shop/getAppuserPage") @@ -771,8 +820,10 @@ for (Order datum : listR.getData()) { userIds.add(datum.getAppUserId()); } + Set<Long> shopServerUser = getShopServerUser(objectId); + userIds.addAll(shopServerUser); } - IPage<AppUser> appuserPage = appUserService.getAppuserPage1(pageCurr, pageSize, appUser, objectId, userIds); + IPage<AppUser> appuserPage = appUserService.getAppuserPage1(pageCurr, pageSize, appUser, userIds); return R.ok(appuserPage); } @@ -939,9 +990,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) { @@ -1154,8 +1206,8 @@ public R<UserStatisticsDetail> statisticsDetail(@ApiParam(value = "用户id") Long userId) { Long userid = tokenService.getLoginUser().getUserid(); SysUser data = sysUserClient.getSysUser(userid).getData(); - Integer shopId = null; - Set<Long> userIds = null; + Integer shopId = 0; + Set<Long> userIds = new HashSet<>(); if(null != userId){ userIds = new HashSet<>(); userIds.add(userId); @@ -1164,12 +1216,18 @@ shopId = data.getObjectId(); if(null == userId){ userIds = orderClient.getAppUserByShoppingShop(shopId).getData(); + Set<Long> shopServerUser = getShopServerUser(shopId); + userIds.addAll(shopServerUser); }else{ userIds = new HashSet<>(); userIds.add(userId); } + } - UserStatisticsDetail userStatisticsDetail = appUserMapper.getUserStatisticsDetail(shopId, userIds); + UserStatisticsDetail userStatisticsDetail = appUserMapper.getUserStatisticsDetail(null, userIds); + List<Order> orderList = orderClient.getOrderByAppUserIdsAndWriteOffShop(shopId, userIds).getData(); + BigDecimal shopAmount = orderList.stream().map(Order::getPaymentAmount).reduce(BigDecimal.ZERO, BigDecimal::add); + userStatisticsDetail.setShopAmount(shopAmount); return R.ok(userStatisticsDetail); } @@ -1197,7 +1255,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