From 111652d23733d04e379c2454c8b39171596a6b50 Mon Sep 17 00:00:00 2001 From: 无关风月 <443237572@qq.com> Date: 星期六, 09 十一月 2024 14:28:51 +0800 Subject: [PATCH] 代码提交 --- xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/controller/client/ClientAppUserController.java | 307 +++++++++++++++++++++++++++++++++++--------------- 1 files changed, 214 insertions(+), 93 deletions(-) diff --git a/xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/controller/client/ClientAppUserController.java b/xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/controller/client/ClientAppUserController.java index 82ea0cb..a331dc1 100644 --- a/xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/controller/client/ClientAppUserController.java +++ b/xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/controller/client/ClientAppUserController.java @@ -18,6 +18,7 @@ import com.xinquan.course.api.domain.Course; import com.xinquan.course.api.domain.CourseCategory; import com.xinquan.course.api.domain.CourseDTO; +import com.xinquan.course.api.domain.OrderCourseVO; import com.xinquan.order.api.feign.RemoteOrderService; import com.xinquan.system.api.RemoteBannerService; import com.xinquan.system.api.RemoteUserService; @@ -113,7 +114,11 @@ private RemoteOrderService remoteOrderService; @Resource private RemoteUserService remoteUserService; - + @GetMapping("/getAllUserList") + public R<List<AppUser>> getAllUserList() { + List<AppUser> list = appUserService.list(); + return R.ok(list); + } public static void main(String[] args) { // 获取当前年份 int currentYear = LocalDate.now().getYear(); @@ -424,17 +429,19 @@ appUserQuestions.add(appUserQuestion); } List<Tag> list1 = tagService.lambdaQuery().eq(Tag::getTagType,2).list(); - String[] split = tagId.split(","); - List<String> list2 = Arrays.asList(split); - if (!list2.isEmpty()){ - for (Tag tag : list1) { - if (list2.contains(tag.getId().toString())){ - tag.setIsCheck(1); + if (org.springframework.util.StringUtils.hasLength(tagId)){ + String[] split = tagId.split(","); + List<String> list2 = Arrays.asList(split); + if (!list2.isEmpty()){ + for (Tag tag : list1) { + if (list2.contains(tag.getId().toString())){ + tag.setIsCheck(1); + } } } }else{ for (Tag tag : list1) { - tag.setIsCheck(2); + tag.setIsCheck(2); } } viewReport.setQuestions(appUserQuestions); @@ -457,9 +464,6 @@ } @GetMapping("/detail") @ApiOperation(value = "用户详情", tags = "管理后台-用户管理") - @ApiImplicitParams({ - @ApiImplicitParam(name = "uid", value = "uid", dataType = "String", required = true), - }) public R<AppUser> detail(String uid) { AppUser byId = appUserService.getById(uid); List<AppUserTree> list1 = appUserTreeService.lambdaQuery().eq(AppUserTree::getAppUserId, byId.getId()) @@ -485,6 +489,12 @@ if (data!=null){ byId.setLevelName(data.getLevelName()); byId.setLevelIcon(data.getLevelIcon()); + } + if (org.springframework.util.StringUtils.hasLength(byId.getTagId())){ + List<String> list = Arrays.asList(byId.getTagId().split(",")); + List<String> collect = tagService.lambdaQuery().in(Tag::getId, list).list().stream() + .map(Tag::getTagName).collect(Collectors.toList()); + byId.setTags(collect); } return R.ok(byId); } @@ -520,6 +530,11 @@ }) public R setTotalEnergyValue(String uid,Integer energyValue,String reason) { AppUser byId = appUserService.getById(uid); + if (energyValue<0){ + if (byId.getTotalEnergyValue()<Math.abs(energyValue)){ + return R.fail("扣除能量值应小于当前能量值"); + } + } byId.setTotalEnergyValue(byId.getTotalEnergyValue()+energyValue); byId.setEnergyValue(byId.getEnergyValue()+energyValue); appUserService.updateById(byId); @@ -555,10 +570,9 @@ AppUser byId = appUserService.getById(uid); switch (vipType){ case 1: - appUserLambdaUpdateWrapper.set(AppUser::getVipExpireTime,null); - appUserLambdaUpdateWrapper.set(AppUser::getVipLevel,null); - appUserLambdaUpdateWrapper.eq(AppUser::getId,byId.getUserId()); - appUserService.update(appUserLambdaUpdateWrapper); + byId.setVipExpireTime(null); + byId.setVipLevel(null); + appUserService.updateById(byId); break; case 2: if (byId.getVipExpireTime() == null){ @@ -921,43 +935,54 @@ .orderByDesc(AppUser::getRegisterTime); if (org.springframework.util.StringUtils.hasLength(courseDTO.getVipType())){ String[] split = courseDTO.getVipType().split(","); - List<String> list1 = Arrays.asList(split); + List<Integer> objects = new ArrayList<>(); + for (String s : split) { + objects.add(Integer.parseInt(s)-1); + } List<AppUser> appUsers = new ArrayList<>(); - List<AppUser> list = appUserService.lambdaQuery().gt(AppUser::getVipExpireTime, LocalDateTime.now()).list(); + List<AppUser> list = appUserService.lambdaQuery().list(); for (AppUser appUser : list) { - if(appUser.getVipLevel()!=null){ - if (list1.contains(appUser.getVipLevel().toString())){ + if (objects.contains(0)){ + if (appUser.getVipExpireTime()==null){ + appUsers.add(appUser); + }else if (appUser.getVipExpireTime().isBefore(LocalDateTime.now())){ + appUsers.add(appUser); + } + } + if (objects.contains(1)){ + if (appUser.getVipExpireTime()!=null&&appUser.getVipExpireTime().isAfter(LocalDateTime.now())&&appUser.getVipLevel()==1){ + appUsers.add(appUser); + } + } + if (objects.contains(2)){ + if (appUser.getVipExpireTime()!=null&&appUser.getVipExpireTime().isAfter(LocalDateTime.now())&&appUser.getVipLevel()==2){ + appUsers.add(appUser); + } + } + if (objects.contains(3)){ + if (appUser.getVipExpireTime()!=null&&appUser.getVipExpireTime().isAfter(LocalDateTime.now())&&appUser.getVipLevel()==3){ appUsers.add(appUser); } } } - List<Long> collect = appUsers.stream().map(AppUser::getId).collect(Collectors.toList()); + List<Long> collect = appUsers.stream().distinct().map(AppUser::getId).collect(Collectors.toList()); if (collect.isEmpty()){ collect.add(-1L); } - courseLambdaQueryWrapper.in(AppUser::getId, longs); + courseLambdaQueryWrapper.in(AppUser::getId, collect); } if (org.springframework.util.StringUtils.hasLength(courseDTO.getLevel())){ List<String> list2 = Arrays.asList(courseDTO.getLevel().split(",")); List<AppUser> list = appUserService.lambdaQuery().list(); List<AppUser> appUsers = new ArrayList<>(); for (AppUser appUser : list) { - List<AppUserTree> list1 = appUserTreeService.lambdaQuery().eq(AppUserTree::getAppUserId, appUser.getId()) - .list(); - // 查询用户等级最高的那颗树苗 - AppUserTree tree = list1.stream().max((o1, o2) -> { - if (o1.getTreeLevelType() > o2.getTreeLevelType()) { - return 1; - } else if (o1.getTreeLevelType() < o2.getTreeLevelType()) { - return -1; - } else { - return 0; - } - }).orElse(null); + AppUserTree list1 = appUserTreeService.lambdaQuery().eq(AppUserTree::getAppUserId, appUser.getId()) + .eq(AppUserTree::getSowAgain,2) + .one(); // 查询疗愈等级 名称 图标 int level = 1; - if (tree != null){ - level = tree.getTreeLevelType(); + if (list1 != null){ + level = list1.getTreeLevelType(); } if (list2.contains(level+"")){ appUsers.add(appUser); @@ -1053,7 +1078,12 @@ return R.tokenError("登录失效"); } Long userId = loginUser.getUserid(); - + AppUser byId = appUserService.getById(userId); + byId.setUserStatus(3); + byId.setLogoutTime(LocalDateTime.now()); + appUserService.updateById(byId); + appUserService.removeById(byId); + remoteUserService.removeByAppUserId(byId.getUserId()); return R.ok(); } @PostMapping("/wallet") @@ -1068,7 +1098,22 @@ WalletVO walletVO = new WalletVO(); walletVO.setId(userId); walletVO.setBalance(byId.getBalance()); - walletVO.setIncome(byId.getIncome()); + + List<AppUser> page = appUserService.lambdaQuery() + .eq(AppUser::getInviteUserId, userId) + .list(); + // 查询登录用户邀请了哪些人 + List<Long> collect = page.stream().map(AppUser::getId).collect(Collectors.toList()); + BigDecimal bigDecimal1 = new BigDecimal("0"); + + for (AppUser record : page) { + List<AppUserWalletRecord> list = appUserWalletRecordService.lambdaQuery().eq(AppUserWalletRecord::getAppUserId, userId) + .like(AppUserWalletRecord::getReason,"分佣").eq(AppUserWalletRecord::getChildAppUserId, record.getId()).list(); + BigDecimal reduce = list.stream().map(AppUserWalletRecord::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add); + bigDecimal1 = bigDecimal1.add(reduce); + record.setMoney(reduce); + } + walletVO.setIncome(bigDecimal1); // 查询用户充值 String data = remoteOrderService.queryChargeByUserId(userId).getData(); BigDecimal bigDecimal = new BigDecimal(data); @@ -1095,33 +1140,27 @@ if (loginUser==null){ return R.tokenError("登录失效"); } - Long userId = loginUser.getUserid(); - Page<AppUser> page = appUserService.lambdaQuery().ne(AppUser::getUserStatus, 3) - .eq(AppUser::getInviteUserId, userId) - .page(new Page<>(pageCurr, pageSize)); - if (page.getRecords().isEmpty()){ - return R.ok(PageDTO.empty(page)); - } - // 查询登录用户邀请了哪些人 - List<Long> collect = page.getRecords().stream().map(AppUser::getId).collect(Collectors.toList()); - if (collect.isEmpty())return R.ok(PageDTO.empty(page)); - for (int i = 0; i < page.getRecords().size(); i++) { - AppUser appUser = page.getRecords().get(i); - // 查询该给用户带来收益 - List<AppUserWalletRecord> list = appUserWalletRecordService.lambdaQuery().eq(AppUserWalletRecord::getAppUserId, userId) - .eq(AppUserWalletRecord::getChildAppUserId,appUser.getUserId()).list(); - BigDecimal bigDecimal = new BigDecimal("0"); - for (AppUserWalletRecord appUserWalletRecord : list) { - if (appUserWalletRecord.getAmount()!=null && appUserWalletRecord.getChangeType() == 1){ - bigDecimal = bigDecimal.add(appUserWalletRecord.getAmount()); - } - } - appUser.setMoney(bigDecimal); + Page<AppUser> objectPage = new Page<>(pageCurr, pageSize); + Long userId = loginUser.getUserid(); + List<AppUser> page = appUserService.lambdaQuery().ne(AppUser::getUserStatus, 3) + .eq(AppUser::getInviteUserId, userId) + .list(); + // 查询登录用户邀请了哪些人 + List<Long> collect = page.stream().map(AppUser::getId).collect(Collectors.toList()); + for (AppUser record : page) { + List<AppUserWalletRecord> list = appUserWalletRecordService.lambdaQuery().eq(AppUserWalletRecord::getAppUserId, userId) + .like(AppUserWalletRecord::getReason,"分佣").eq(AppUserWalletRecord::getChildAppUserId, record.getId()).list(); + BigDecimal reduce = list.stream().map(AppUserWalletRecord::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add); + record.setMoney(reduce); } // 根据佣金金额 从大到小排序 - page.getRecords().sort((o1, o2) -> o2.getMoney().compareTo(o1.getMoney())); - return R.ok(PageDTO.of(page, InviteRankListVO.class)); + page.sort((o1, o2) -> o2.getMoney().compareTo(o1.getMoney())); + + List<AppUser> testing = testing(page.size(), pageCurr, pageSize, page); + objectPage.setTotal(testing.size()); + objectPage.setRecords(testing); + return R.ok(PageDTO.of(objectPage, InviteRankListVO.class)); } @PostMapping("/myInviteRankListShare") @ApiOperation(value = "我的助力-分页", tags = {"H5分享"}) @@ -1134,32 +1173,25 @@ @RequestParam(value = "pageCurr", defaultValue = "1") Integer pageCurr, @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize, @RequestParam(value = "userId") String userId) { - Page<AppUser> page = appUserService.lambdaQuery().ne(AppUser::getUserStatus, 3) + Page<AppUser> objectPage = new Page<>(pageCurr, pageSize); + List<AppUser> page = appUserService.lambdaQuery().ne(AppUser::getUserStatus, 3) .eq(AppUser::getInviteUserId, userId) - .page(new Page<>(pageCurr, pageSize)); - if (page.getRecords().isEmpty()){ - return R.ok(PageDTO.empty(page)); - } + .list(); // 查询登录用户邀请了哪些人 - List<Long> collect = page.getRecords().stream().map(AppUser::getId).collect(Collectors.toList()); - if (collect.isEmpty())return R.ok(PageDTO.empty(page)); - for (int i = 0; i < page.getRecords().size(); i++) { - AppUser appUser = page.getRecords().get(i); - // 查询该给用户带来收益 + List<Long> collect = page.stream().map(AppUser::getId).collect(Collectors.toList()); + for (AppUser record : page) { List<AppUserWalletRecord> list = appUserWalletRecordService.lambdaQuery().eq(AppUserWalletRecord::getAppUserId, userId) - .eq(AppUserWalletRecord::getChildAppUserId,appUser.getUserId()).list(); - BigDecimal bigDecimal = new BigDecimal("0"); - for (AppUserWalletRecord appUserWalletRecord : list) { - if (appUserWalletRecord.getAmount()!=null && appUserWalletRecord.getChangeType() == 1){ - bigDecimal = bigDecimal.add(appUserWalletRecord.getAmount()); - } - } - appUser.setMoney(bigDecimal); - + .like(AppUserWalletRecord::getReason,"分佣").eq(AppUserWalletRecord::getChildAppUserId, record.getId()).list(); + BigDecimal reduce = list.stream().map(AppUserWalletRecord::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add); + record.setMoney(reduce); } // 根据佣金金额 从大到小排序 - page.getRecords().sort((o1, o2) -> o2.getMoney().compareTo(o1.getMoney())); - return R.ok(PageDTO.of(page, InviteRankListVO.class)); + page.sort((o1, o2) -> o2.getMoney().compareTo(o1.getMoney())); + + List<AppUser> testing = testing(page.size(), pageCurr, pageSize, page); + objectPage.setTotal(testing.size()); + objectPage.setRecords(testing); + return R.ok(PageDTO.of(objectPage, InviteRankListVO.class)); } @Resource private AppUserWalletRecordService appUserWalletRecordService; @@ -1179,17 +1211,47 @@ public R<PageDTO<InviteRankListVO>> inviteRankList( @RequestParam(value = "pageCurr", defaultValue = "1") Integer pageCurr, @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) { - Page<AppUser> page = appUserService.lambdaQuery().ne(AppUser::getUserStatus, 3) - .page(new Page<>(pageCurr, pageSize)); - for (AppUser appUser : page.getRecords()) { + Page<AppUser> objectPage = new Page<>(pageCurr, pageSize); + + List<AppUser> page = appUserService.lambdaQuery().ne(AppUser::getUserStatus, 3) + .list(); + List<AppUser> res = new ArrayList<>(); + for (AppUser appUser : page) { int size = appUserService.lambdaQuery().ne(AppUser::getUserStatus, 3) .eq(AppUser::getInviteUserId, appUser.getId()) .list().size(); appUser.setCount(size); + if (size>0){ + res.add(appUser); + } } // 根据帮助人数 从大到小排序 - page.getRecords().sort((o1, o2) -> o2.getCount() - o1.getCount()); - return R.ok(PageDTO.of(page, InviteRankListVO.class)) ; + res.sort((o1, o2) -> o2.getCount() - o1.getCount()); + List<AppUser> testing = testing(res.size(), pageCurr, pageSize, res); + objectPage.setRecords(testing); + objectPage.setTotal(res.size()); + return R.ok(PageDTO.of(objectPage, InviteRankListVO.class)) ; + } + public static List<AppUser> testing(long total, long current, long size, List<AppUser> str){ + List<AppUser> result = new ArrayList<>(); + //获取初始化分页结构 + Page<AppUser> page = new Page<>(current - 1, size, total); + //获取集合下标初始值 + long startIndex = (current - 1) * size; + //获取集合下标结束值 + long endInddex = 0; + if(startIndex + page.getCurrent() >= total || size > total){ + endInddex = total; + }else { + endInddex = Math.min(startIndex + page.getSize(), total); + } + //如果输入的开始查询下标大于集合大小,则查询为空值 + if(startIndex > total){ + result = Collections.emptyList(); + }else{ + result = str.subList((int)startIndex,(int)endInddex); + } + return result; } @PostMapping("/inviteRankListShare") @ApiOperation(value = "爱心助力榜单-分页", tags = {"H5分享"}) @@ -1200,17 +1262,26 @@ public R<PageDTO<InviteRankListVO>> inviteRankListShare( @RequestParam(value = "pageCurr", defaultValue = "1") Integer pageCurr, @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) { - Page<AppUser> page = appUserService.lambdaQuery().ne(AppUser::getUserStatus, 3) - .page(new Page<>(pageCurr, pageSize)); - for (AppUser appUser : page.getRecords()) { + Page<AppUser> objectPage = new Page<>(pageCurr, pageSize); + + List<AppUser> page = appUserService.lambdaQuery().ne(AppUser::getUserStatus, 3) + .list(); + List<AppUser> res = new ArrayList<>(); + for (AppUser appUser : page) { int size = appUserService.lambdaQuery().ne(AppUser::getUserStatus, 3) .eq(AppUser::getInviteUserId, appUser.getId()) .list().size(); appUser.setCount(size); + if (size>0){ + res.add(appUser); + } } // 根据帮助人数 从大到小排序 - page.getRecords().sort((o1, o2) -> o2.getCount() - o1.getCount()); - return R.ok(PageDTO.of(page, InviteRankListVO.class)) ; + res.sort((o1, o2) -> o2.getCount() - o1.getCount()); + List<AppUser> testing = testing(res.size(), pageCurr, pageSize, res); + objectPage.setRecords(testing); + objectPage.setTotal(res.size()); + return R.ok(PageDTO.of(objectPage, InviteRankListVO.class)) ; } @PostMapping("/getUserInfo") @ApiOperation(value = "获取用户信息", tags = {"个人中心"}) @@ -1315,6 +1386,56 @@ }else{ appUser.setIsVip(2); } + AppUserTree list1 = appUserTreeService.lambdaQuery().eq(AppUserTree::getAppUserId, userId) + .eq(AppUserTree::getSowAgain,2) + .one(); + // 查询疗愈等级 名称 图标 + int level = list1.getTreeLevelType(); + appUser.setLevel(level); + // 查询用户累计学习天数 + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + List<AppUserViewingHistory> com = appUserViewingHistoryService.cumulative(userId); + appUser.setCumulative(com.size()); + // 查询用户今日学习多少分钟 + Integer temp = appUserViewingHistoryService.today(userId); + if (temp == null){ + temp =0; + } + if (temp == 0){ + appUser.setToday(0); + }else if (temp<60){ + // 不足一分钟按一分钟计算 + appUser.setToday(1); + }else{ + appUser.setToday(temp/60); + } + // 查询用户连续观看天数 + List<AppUserViewingHistory> list = appUserViewingHistoryService.lambdaQuery().eq(AppUserViewingHistory::getAppUserId, userId) + .eq(AppUserViewingHistory::getViewingType, 1) + .orderByDesc(BaseModel::getCreateTime).list(); + Set<LocalDate> viewingDates = list.stream() + .map(record -> LocalDate.parse(record.getCreateTime().toLocalDate().toString(), formatter)) + .collect(Collectors.toCollection(HashSet::new)); + // 获取今天的日期 + LocalDate today = LocalDate.now(); + // 计算连续观看天数 + int consecutiveDays = 0; + LocalDate currentDate = today; + // 如果今天没有观看 也进入循环判断 + while (viewingDates.contains(currentDate)||LocalDate.parse(currentDate.toString(), formatter).equals(today)) { + if (!viewingDates.contains(currentDate)){ + // 如果今天没有观看 + currentDate = currentDate.minusDays(1); + continue; + } + consecutiveDays++; + currentDate = currentDate.minusDays(1); + } + appUser.setToday(consecutiveDays); + // 根据等级查询疗愈名称和图标 + UserLevelSetting data = remoteBannerService.getIconNameByLevel(level).getData(); + appUser.setLevelName(data.getLevelName()); + appUser.setLevelIcon(data.getLevelIcon()); return R.ok(appUser); } @PostMapping("/healingLevel") @@ -1443,7 +1564,7 @@ updateWrapper.set(AppUser::getOccupation, dto.getOccupation()); updateWrapper.set(AppUser::getLocation, dto.getLocation()); updateWrapper.set(AppUser::getHometown, dto.getHometown()); - updateWrapper.set(AppUser::getEmail, dto.getEducation()); + updateWrapper.set(AppUser::getEmail, dto.getEmail()); updateWrapper.eq(AppUser::getId,userId); appUserService.update(byId, updateWrapper); return R.ok(byId); -- Gitblit v1.7.1