From b01f752252eaadd1fa31eda6a9ad43146660b721 Mon Sep 17 00:00:00 2001 From: 无关风月 <443237572@qq.com> Date: 星期四, 03 四月 2025 23:42:57 +0800 Subject: [PATCH] bug修改 --- xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/controller/client/ClientAppUserViewingHistoryController.java | 285 ++++++++++++++++++++++++++++++++++++++++++++++---------- 1 files changed, 234 insertions(+), 51 deletions(-) diff --git a/xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/controller/client/ClientAppUserViewingHistoryController.java b/xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/controller/client/ClientAppUserViewingHistoryController.java index 9b422c4..f1491a9 100644 --- a/xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/controller/client/ClientAppUserViewingHistoryController.java +++ b/xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/controller/client/ClientAppUserViewingHistoryController.java @@ -1,6 +1,7 @@ package com.xinquan.user.controller.client; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.xinquan.common.core.domain.R; import com.xinquan.common.core.utils.page.PageDTO; @@ -8,16 +9,16 @@ import com.xinquan.common.security.service.TokenService; import com.xinquan.common.security.utils.SecurityUtils; import com.xinquan.course.api.domain.Course; +import com.xinquan.course.api.domain.CourseChapter; import com.xinquan.course.api.domain.OrderCourseVO; import com.xinquan.course.api.feign.RemoteCourseService; import com.xinquan.meditation.api.domain.Meditation; import com.xinquan.meditation.api.feign.RemoteMeditationService; -import com.xinquan.system.api.domain.AppUser; -import com.xinquan.system.api.domain.AppUserTree; -import com.xinquan.system.api.domain.AppUserViewingHistory; +import com.xinquan.system.api.domain.*; import com.xinquan.system.api.domain.vo.AppUserVO; import com.xinquan.system.api.model.LoginUser; import com.xinquan.user.api.feign.RemoteAppUserService; +import com.xinquan.user.service.AppUserEnergyRecordService; import com.xinquan.user.service.AppUserService; import com.xinquan.user.service.AppUserTreeService; import com.xinquan.user.service.AppUserViewingHistoryService; @@ -70,18 +71,19 @@ /** * 远程调用 根据章节id和用户id查询是否观看完毕 + * * @param id * @return */ @PostMapping("/getCourseChapterHistoryState/{id}/{chapterId}") - public R<Integer> getCourseChapterHistoryState(@PathVariable("id") Long id,@PathVariable("chapterId") Long chapterId) { + public R<Integer> getCourseChapterHistoryState(@PathVariable("id") Long id, @PathVariable("chapterId") Long chapterId) { List<AppUserViewingHistory> list = appUserViewingHistoryService.lambdaQuery() .eq(AppUserViewingHistory::getChapterId, chapterId) .eq(AppUserViewingHistory::getAppUserId, id) .eq(AppUserViewingHistory::getViewingType, 2) .list(); for (AppUserViewingHistory appUserViewingHistory : list) { - if (appUserViewingHistory.getIsOver()!=null && appUserViewingHistory.getIsOver()==1){ + if (appUserViewingHistory.getIsOver() != null && appUserViewingHistory.getIsOver() == 1) { return R.ok(1); } } @@ -90,6 +92,7 @@ /** * 远程调用查询用户观看了哪些课程 + * * @return */ @PostMapping("/getCourseHistoryByUserId/{id}") @@ -101,6 +104,7 @@ .collect(Collectors.toList()); return R.ok(one); } + @PostMapping("/getMeditationHistoryCount/{id}") public R<Long> getMeditationHistoryCount(@PathVariable("id") Long id) { List<AppUserViewingHistory> list = appUserViewingHistoryService.lambdaQuery() @@ -110,6 +114,16 @@ .list(); return R.ok(Long.valueOf(list.size())); } + + @PostMapping("/getMeditationHistoryCountAll") + public R<List<AppUserViewingHistory>> getMeditationHistoryCountAll() { + List<AppUserViewingHistory> list = appUserViewingHistoryService.lambdaQuery() + .eq(AppUserViewingHistory::getViewingType, 1) + .groupBy(AppUserViewingHistory::getAppUserId) + .list(); + return R.ok(list); + } + @PostMapping("/getCourseHistoryCount/{id}") public R<Long> getCourseHistoryCount(@PathVariable("id") Long id) { List<AppUserViewingHistory> list = appUserViewingHistoryService.lambdaQuery() @@ -118,6 +132,7 @@ .list(); return R.ok(Long.valueOf(list.size())); } + @PostMapping("/getCourseChapterHistoryCount/{id}") public R<Long> getCourseChapterHistoryCount(@PathVariable("id") Long id) { List<AppUserViewingHistory> list = appUserViewingHistoryService.lambdaQuery() @@ -127,6 +142,7 @@ .list(); return R.ok(Long.valueOf(list.size())); } + @PostMapping("/lookHistory") @ApiOperation(value = "观看历史") @ApiImplicitParams({ @@ -136,13 +152,13 @@ }) public R<List<OrderCourseVO>> lookHistory(Integer state, Integer pageCurr, Integer pageSize) { LoginUser loginUser = tokenService.getLoginUser(); - if (loginUser==null){ + if (loginUser == null) { return R.tokenError("登录失效"); } Long userId = loginUser.getUserid(); List<OrderCourseVO> orderCourseVOS = new ArrayList<>(); - switch (state){ + switch (state) { case 1: List<Long> collect1 = appUserViewingHistoryService.lambdaQuery() .eq(AppUserViewingHistory::getAppUserId, userId) @@ -150,15 +166,15 @@ .stream().map(AppUserViewingHistory::getBizId).collect(Collectors.toList()); List<Long> collect2 = collect1.stream().distinct().collect(Collectors.toList()); StringBuilder temp = new StringBuilder(); - if (collect1.isEmpty()){ - temp=temp.append("-1"); - }else{ + if (collect1.isEmpty()) { + temp = temp.append("-1"); + } else { for (Long l : collect2) { temp.append(l).append(","); } temp.deleteCharAt(temp.length() - 1); } - Page<Meditation> data = remoteMeditationService.getMeditationByIds(pageCurr,pageSize,temp.toString()).getData(); + Page<Meditation> data = remoteMeditationService.getMeditationByIds(pageCurr, pageSize, temp.toString()).getData(); for (Meditation meditation : data.getRecords()) { OrderCourseVO orderCourseVO = new OrderCourseVO(); @@ -169,7 +185,7 @@ orderCourseVO.setGeneralPrice(meditation.getGeneralPrice()); orderCourseVO.setIosPrice(meditation.getIosPrice()); orderCourseVO.setCoverUrl(meditation.getCoverUrl()); - orderCourseVO.setCount(meditation.getRealLearnedNum()+meditation.getVirtualLearnedNum()); + orderCourseVO.setCount(meditation.getRealLearnedNum() + meditation.getVirtualLearnedNum()); orderCourseVO.setCoverDescription(meditation.getCoverDescription()); orderCourseVOS.add(orderCourseVO); } @@ -181,15 +197,15 @@ .stream().map(AppUserViewingHistory::getBizId).collect(Collectors.toList()); List<Long> collect4 = collect3.stream().distinct().collect(Collectors.toList()); StringBuilder temp1 = new StringBuilder(); - if (collect4.isEmpty()){ - temp1=temp1.append("-1"); - }else{ + if (collect4.isEmpty()) { + temp1 = temp1.append("-1"); + } else { for (Long l : collect4) { temp1.append(l).append(","); } temp1.deleteCharAt(temp1.length() - 1); } - Page<Course> data2 = remoteCourseService.getCourseByIds(pageCurr,pageSize,temp1.toString()).getData(); + Page<Course> data2 = remoteCourseService.getCourseByIds(pageCurr, pageSize, temp1.toString()).getData(); for (Course record : data2.getRecords()) { OrderCourseVO orderCourseVO = new OrderCourseVO(); orderCourseVO.setBusinessId(record.getId()); @@ -199,17 +215,85 @@ orderCourseVO.setGeneralPrice(record.getGeneralPrice()); orderCourseVO.setIosPrice(record.getIosPrice()); orderCourseVO.setCoverUrl(record.getCoverUrl()); - List<AppUser> data1 = remoteAppUserService.getUserByCourseId(record.getId()).getData(); - orderCourseVO.setCount(data1.size()); + List<CourseChapter> data1 = remoteCourseService.getChapterByCourseId(orderCourseVO.getBusinessId() + "").getData(); + int a = 0; + int b = 0; + for (CourseChapter courseChapter : data1) { + a += courseChapter.getVirtualLearnedNum(); + Long data9 = remoteAppUserService.getCourseChapterHistoryCount(courseChapter.getId()).getData(); + b += data9; + } + orderCourseVO.setCount(a + b); orderCourseVOS.add(orderCourseVO); } break; } return R.ok(orderCourseVOS); } + /** * 记录用户观看记录 - * + */ + @PostMapping("/testLookHistory") + @ApiOperation(value = "记录用户观看冥想记录", tags = {"用户端-用户相关接口"}) + @ApiImplicitParams({ + @ApiImplicitParam(name = "id", value = "冥想id", dataType = "Long", required = true), + @ApiImplicitParam(name = "timeLook", value = "播放时长单位秒", dataType = "Integer", required = true) + }) + public R<?> testLookHistory(@RequestParam("id") Long id, + @RequestParam("timeLook") Integer timeLook) { + +// AppUserViewingHistory appUserViewingHistory = new AppUserViewingHistory(); +// appUserViewingHistory.setAppUserId(1907408237773807618L); +// appUserViewingHistory.setBizId(id); +// appUserViewingHistory.setViewingType(1); +// appUserViewingHistory.setTimeLook(timeLook); +// appUserViewingHistory.setCreateTime(LocalDateTime.now()); +// // 先查询用户当天有没有观看过该音频 +// AppUserViewingHistory appUserViewingHistory3 = appUserViewingHistoryService.lambdaQuery().eq(AppUserViewingHistory::getAppUserId, 1907408237773807618L) +// .eq(AppUserViewingHistory::getBizId, id) +// .apply("date_format(create_time,'%Y-%M-%D')=date_format(now(),'%Y-%M-%D')") +// .eq(AppUserViewingHistory::getViewingType, 1).last("limit 1").one(); +// if (appUserViewingHistory3 != null) { +// appUserViewingHistory3.setTimeLook(appUserViewingHistory3.getTimeLook() + timeLook); +// appUserViewingHistoryService.updateById(appUserViewingHistory3); +// } else { +// appUserViewingHistoryService.save(appUserViewingHistory); +// } +// List<Long> collect = appUserService.list().stream().map(AppUser::getId).collect(Collectors.toList()); + List<Long> collect = appUserViewingHistoryService.list(new LambdaQueryWrapper<AppUserViewingHistory>() + .groupBy(AppUserViewingHistory::getAppUserId)).stream().map(AppUserViewingHistory::getAppUserId).collect(Collectors.toList()); + + for (Long l : collect) { + List<AppUserViewingHistory> list = appUserViewingHistoryService.lambdaQuery() + .eq(AppUserViewingHistory::getAppUserId, l) + .eq(AppUserViewingHistory::getViewingType, 1) + .last("GROUP BY date_format(create_time,'%Y-%M-%D')").list(); + for (AppUserViewingHistory appUserViewingHistory : list) { + List<AppUserViewingHistory> list1 = appUserViewingHistoryService.lambdaQuery().eq(AppUserViewingHistory::getAppUserId, appUserViewingHistory.getAppUserId()) + .eq(AppUserViewingHistory::getViewingType, 1) + .ne(AppUserViewingHistory::getId, appUserViewingHistory.getId()) + .eq(AppUserViewingHistory::getBizId, appUserViewingHistory.getBizId()) + .apply("date_format(CONVERT_TZ(create_time, '+00:00', '+08:00'), '%Y-%m-%d')="+"'"+appUserViewingHistory.getCreateTime().toLocalDate()+"'").list(); + Integer timeLook1 = appUserViewingHistory.getTimeLook(); + for (AppUserViewingHistory userViewingHistory : list1) { + timeLook1+=userViewingHistory.getTimeLook(); + appUserViewingHistoryService.removeById(userViewingHistory.getId()); + + } + appUserViewingHistory.setTimeLook(timeLook1); + appUserViewingHistoryService.updateById(appUserViewingHistory); + } + } + + return R.ok(); + } + + + + + /** + * 记录用户观看记录 */ @PostMapping("/saveViewingHistory") @ApiOperation(value = "记录用户观看冥想记录", tags = {"用户端-用户相关接口"}) @@ -218,22 +302,32 @@ @ApiImplicitParam(name = "timeLook", value = "播放时长单位秒", dataType = "Integer", required = true) }) public R<?> saveViewingRecord(@RequestParam("id") Long id, - @RequestParam("timeLook") Integer timeLook - ) { + @RequestParam("timeLook") Integer timeLook + ) { LoginUser loginUser = tokenService.getLoginUser(); - if (loginUser==null){ + if (loginUser == null) { return R.tokenError("登录失效"); } Long userId = loginUser.getUserid(); - AppUser byId = appUserService.getById(userId); AppUserViewingHistory appUserViewingHistory = new AppUserViewingHistory(); appUserViewingHistory.setAppUserId(userId); appUserViewingHistory.setBizId(id); appUserViewingHistory.setViewingType(1); appUserViewingHistory.setTimeLook(timeLook); appUserViewingHistory.setCreateTime(LocalDateTime.now()); - appUserViewingHistoryService.save(appUserViewingHistory); - // 查询用户今日观看了多久冥想 如果达到30分钟 用户能量+10 如果达到60分钟 用户能量额外增加20 + // 先查询用户当天有没有观看过该音频 + AppUserViewingHistory appUserViewingHistory3 = appUserViewingHistoryService.lambdaQuery().eq(AppUserViewingHistory::getAppUserId, userId) + .eq(AppUserViewingHistory::getBizId, id) + .apply("date_format(create_time,'%Y-%M-%D')=date_format(now(),'%Y-%M-%D')") + .eq(AppUserViewingHistory::getViewingType, 1).last("limit 1").one(); + if (appUserViewingHistory3!=null){ + appUserViewingHistory3.setTimeLook(appUserViewingHistory3.getTimeLook()+timeLook); + appUserViewingHistoryService.updateById(appUserViewingHistory3); + }else{ + appUserViewingHistoryService.save(appUserViewingHistory); + } + AppUser byId = appUserService.getById(userId); + appUserService.updateById(byId); // 查询用户今日观看疗愈多少秒 LocalDateTime now = LocalDateTime.now(); LocalDateTime startOfDay = now.toLocalDate().atStartOfDay(); @@ -241,42 +335,130 @@ List<AppUserViewingHistory> list = appUserViewingHistoryService .lambdaQuery().eq(AppUserViewingHistory::getAppUserId, userId) .eq(AppUserViewingHistory::getViewingType, 1) - .eq(BaseModel::getDelFlag,0) - .between(AppUserViewingHistory::getCreateTime, startOfDay,endOfDay).list(); + .eq(BaseModel::getDelFlag, 0) + .between(AppUserViewingHistory::getCreateTime, startOfDay, endOfDay).list(); int temp = 0; for (AppUserViewingHistory appUserViewingHistory1 : list) { - temp += appUserViewingHistory1.getTimeLook(); + if (appUserViewingHistory1.getTimeLook() != null) { + temp += appUserViewingHistory1.getTimeLook(); + } } AppUserTree one = appUserTreeService.lambdaQuery().eq(AppUserTree::getAppUserId, userId) - .eq(AppUserTree::getSowAgain,2).one(); - if (one == null){ + .eq(AppUserTree::getSowAgain, 2).one(); + + if (one == null) { AppUserTree appUserTree = new AppUserTree(); + appUserTree.setTime(LocalDateTime.now()); appUserTree.setAppUserId(userId); appUserTree.setTreeLevelType(1); appUserTree.setGrowthValue(0); - appUserTree.setSowAgain(2); appUserTree.setCreateTime(LocalDateTime.now()); - if (temp>=60){ - byId.setEnergyValue(byId.getEnergyValue()+30); + // 如果用户的签到时间是今天 那么修改为已签到 + if (byId.getSignTime() != null && byId.getSignTime().toLocalDate().equals(LocalDateTime.now().toLocalDate())) { + appUserTree.setIsSign(1); + } else { + appUserTree.setIsSign(2); } - else if (temp>=30){ - byId.setEnergyValue(byId.getEnergyValue()+10); + if (temp >= 3600) { + if (appUserTree.getTaskOne() == 2) { + AppUserEnergyRecord appUserEnergyRecord = new AppUserEnergyRecord(); + appUserEnergyRecord.setAppUserId(userId); + appUserEnergyRecord.setChangeType(1); + appUserEnergyRecord.setEnergyValue(10); + appUserEnergyRecord.setReason("完成【每日疗愈30分钟】任务"); + appUserEnergyRecordService.save(appUserEnergyRecord); + byId.setTotalEnergyValue(byId.getTotalEnergyValue() + 10); + byId.setEnergyValue(byId.getEnergyValue() + 10); + + } + if (appUserTree.getTaskTwo() == 2) { + AppUserEnergyRecord appUserEnergyRecord = new AppUserEnergyRecord(); + appUserEnergyRecord.setAppUserId(userId); + appUserEnergyRecord.setChangeType(1); + appUserEnergyRecord.setEnergyValue(20); + appUserEnergyRecord.setReason("完成【每日疗愈60分钟】任务"); + appUserEnergyRecordService.save(appUserEnergyRecord); + byId.setTotalEnergyValue(byId.getTotalEnergyValue() + 20); + byId.setEnergyValue(byId.getEnergyValue() + 20); + + } + appUserTree.setTaskOne(1); + appUserTree.setTaskTwo(1); + } else if (temp >= 1800) { + if (appUserTree.getTaskOne() == 2) { + AppUserEnergyRecord appUserEnergyRecord = new AppUserEnergyRecord(); + appUserEnergyRecord.setAppUserId(userId); + appUserEnergyRecord.setChangeType(1); + appUserEnergyRecord.setEnergyValue(10); + appUserEnergyRecord.setReason("完成【每日疗愈30分钟】任务"); + appUserEnergyRecordService.save(appUserEnergyRecord); + byId.setTotalEnergyValue(byId.getTotalEnergyValue() + 10); + byId.setEnergyValue(byId.getEnergyValue() + 10); + } + appUserTree.setTaskOne(2); + appUserTree.setTaskTwo(1); + } else { + appUserTree.setTaskOne(2); + appUserTree.setTaskTwo(2); } - appUserService.updateById(byId); + appUserTree.setEnergyValue(byId.getEnergyValue()); + appUserTree.setNextLevel(1000); appUserTreeService.save(appUserTree); - }else{ - if (temp>=60){ - byId.setEnergyValue(byId.getEnergyValue()+30); + appUserTree.setTotalEnergyValue(byId.getTotalEnergyValue()); + return R.ok(appUserTree); + } else { + if (temp >= 3600) { + if (one.getTaskOne() == 2) { + AppUserEnergyRecord appUserEnergyRecord = new AppUserEnergyRecord(); + appUserEnergyRecord.setAppUserId(userId); + appUserEnergyRecord.setChangeType(1); + appUserEnergyRecord.setEnergyValue(10); + appUserEnergyRecord.setReason("完成【每日疗愈30分钟】任务"); + appUserEnergyRecordService.save(appUserEnergyRecord); + byId.setTotalEnergyValue(byId.getTotalEnergyValue() + 10); + one.setTaskOne(1); + byId.setEnergyValue(byId.getEnergyValue() + 10); + + } + if (one.getTaskTwo() == 2) { + AppUserEnergyRecord appUserEnergyRecord = new AppUserEnergyRecord(); + appUserEnergyRecord.setAppUserId(userId); + appUserEnergyRecord.setChangeType(1); + appUserEnergyRecord.setEnergyValue(20); + appUserEnergyRecord.setReason("完成【每日疗愈60分钟】任务"); + appUserEnergyRecordService.save(appUserEnergyRecord); + byId.setTotalEnergyValue(byId.getTotalEnergyValue() + 20); + one.setTaskTwo(1); + byId.setEnergyValue(byId.getEnergyValue() + 20); + + } + + } else if (temp >= 1800) { + if (one.getTaskOne() == 2) { + AppUserEnergyRecord appUserEnergyRecord = new AppUserEnergyRecord(); + appUserEnergyRecord.setAppUserId(userId); + appUserEnergyRecord.setChangeType(1); + appUserEnergyRecord.setEnergyValue(10); + appUserEnergyRecord.setReason("完成【每日疗愈30分钟】任务"); + appUserEnergyRecordService.save(appUserEnergyRecord); + byId.setTotalEnergyValue(byId.getTotalEnergyValue() + 10); + one.setTaskOne(1); + byId.setEnergyValue(byId.getEnergyValue() + 10); + } + } else { + one.setTaskOne(2); + one.setTaskTwo(2); } - else if (temp>=30){ - byId.setEnergyValue(byId.getEnergyValue()+10); - } - appUserService.updateById(byId); appUserTreeService.updateById(one); + appUserService.updateById(byId); + return R.ok(); } - return R.ok(); } + + @Resource + private AppUserEnergyRecordService appUserEnergyRecordService; + @PostMapping("/saveCourseStudyHistory") @ApiOperation(value = "记录用户观看课程记录", tags = {"用户端-用户相关接口"}) @ApiImplicitParams({ @@ -291,7 +473,7 @@ @RequestParam("isOver") Integer isOver ) { LoginUser loginUser = tokenService.getLoginUser(); - if (loginUser==null){ + if (loginUser == null) { return R.tokenError("登录失效"); } Long userId = loginUser.getUserid(); @@ -299,17 +481,17 @@ .eq(AppUserViewingHistory::getAppUserId, userId) .eq(AppUserViewingHistory::getViewingType, 2) .eq(AppUserViewingHistory::getChapterId, chapterId).one(); - if (one!=null){ - if (one.getIsOver() == 1){ + if (one != null) { + if (one.getIsOver() == 1) { // 如果已经看完了 那么不更新状态 只更新观看时间 one.setMinuteLook(minuteLook); one.setSecondLook(secondLook); one.setTimeLook(secondLook); - }else{ + } else { one.setIsOver(isOver); } appUserViewingHistoryService.updateById(one); - }else{ + } else { AppUserViewingHistory appUserViewingHistory = new AppUserViewingHistory(); appUserViewingHistory.setAppUserId(userId); appUserViewingHistory.setBizId(chapterId); @@ -324,10 +506,11 @@ } return R.ok(); } + @PostMapping("/getCourseStudyHistory") public R<AppUserViewingHistory> getCourseStudyHistory(@RequestParam("chapterId") Long chapterId) { LoginUser loginUser = tokenService.getLoginUser(); - if (loginUser==null){ + if (loginUser == null) { return R.tokenError("登录失效"); } Long userId = loginUser.getUserid(); @@ -335,7 +518,7 @@ .eq(AppUserViewingHistory::getAppUserId, userId) .eq(AppUserViewingHistory::getViewingType, 2) .eq(AppUserViewingHistory::getChapterId, chapterId).one(); - if (one==null){ + if (one == null) { AppUserViewingHistory appUserViewingHistory = new AppUserViewingHistory(); appUserViewingHistory.setAppUserId(userId); appUserViewingHistory.setBizId(chapterId); -- Gitblit v1.7.1