| | |
| | | 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; |
| | |
| | | @Resource |
| | | private RemoteCourseService remoteCourseService; |
| | | private final RemoteAppUserService remoteAppUserService; |
| | | |
| | | /** |
| | | * 远程调用 根据章节id和用户id查询是否观看完毕 |
| | | * @param id |
| | | * @return |
| | | */ |
| | | @PostMapping("/getCourseChapterHistoryState/{id}/{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){ |
| | | return R.ok(1); |
| | | } |
| | | } |
| | | return R.ok(2); |
| | | } |
| | | |
| | | /** |
| | | * 远程调用查询用户观看了哪些课程 |
| | | * @return |
| | | */ |
| | | @PostMapping("/getCourseHistoryByUserId/{id}") |
| | | public R<List<Long>> getCourseHistoryByUserId(@PathVariable("id") Long id) { |
| | | List<Long> one = appUserViewingHistoryService.lambdaQuery() |
| | | .eq(AppUserViewingHistory::getAppUserId, id) |
| | | .eq(AppUserViewingHistory::getViewingType, 2) |
| | | .list().stream().map(AppUserViewingHistory::getBizId) |
| | | .collect(Collectors.toList()); |
| | | return R.ok(one); |
| | | } |
| | | @PostMapping("/getMeditationHistoryCount/{id}") |
| | | public R<Long> getMeditationHistoryCount(@PathVariable("id") Long id) { |
| | | List<AppUserViewingHistory> list = appUserViewingHistoryService.lambdaQuery() |
| | | .eq(AppUserViewingHistory::getBizId, id) |
| | | .eq(AppUserViewingHistory::getViewingType, 1) |
| | | .groupBy(AppUserViewingHistory::getAppUserId) |
| | | .list(); |
| | | return R.ok(Long.valueOf(list.size())); |
| | | } |
| | | @PostMapping("/getCourseHistoryCount/{id}") |
| | | public R<Long> getCourseHistoryCount(@PathVariable("id") Long id) { |
| | | List<AppUserViewingHistory> list = appUserViewingHistoryService.lambdaQuery() |
| | | .eq(AppUserViewingHistory::getBizId, id) |
| | | .eq(AppUserViewingHistory::getViewingType, 2) |
| | | .list(); |
| | | return R.ok(Long.valueOf(list.size())); |
| | | } |
| | | @PostMapping("/getCourseChapterHistoryCount/{id}") |
| | | public R<Long> getCourseChapterHistoryCount(@PathVariable("id") Long id) { |
| | | List<AppUserViewingHistory> list = appUserViewingHistoryService.lambdaQuery() |
| | | .eq(AppUserViewingHistory::getChapterId, id) |
| | | .eq(AppUserViewingHistory::getViewingType, 2) |
| | | .groupBy(AppUserViewingHistory::getAppUserId) |
| | | .list(); |
| | | return R.ok(Long.valueOf(list.size())); |
| | | } |
| | | @PostMapping("/lookHistory") |
| | | @ApiOperation(value = "观看历史") |
| | | @ApiImplicitParams({ |
| | |
| | | orderCourseVO.setIosPrice(meditation.getIosPrice()); |
| | | orderCourseVO.setCoverUrl(meditation.getCoverUrl()); |
| | | orderCourseVO.setCount(meditation.getRealLearnedNum()+meditation.getVirtualLearnedNum()); |
| | | orderCourseVO.setCoverDescription(meditation.getCoverDescription()); |
| | | orderCourseVOS.add(orderCourseVO); |
| | | } |
| | | break; |
| | |
| | | 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.tokenError("登录失效"); |
| | | } |
| | | Long userId = loginUser.getUserid(); |
| | | AppUser byId = appUserService.getById(userId); |
| | | AppUserViewingHistory appUserViewingHistory = new AppUserViewingHistory(); |
| | | appUserViewingHistory.setAppUserId(userId); |
| | | appUserViewingHistory.setBizId(id); |
| | |
| | | appUserViewingHistory.setTimeLook(timeLook); |
| | | appUserViewingHistory.setCreateTime(LocalDateTime.now()); |
| | | appUserViewingHistoryService.save(appUserViewingHistory); |
| | | // 查询用户今日观看了多久冥想 如果达到30分钟 用户能量+10 如果达到60分钟 用户能量额外增加20 |
| | | // 查询用户今日观看疗愈多少秒 |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | LocalDateTime startOfDay = now.toLocalDate().atStartOfDay(); |
| | | LocalDateTime endOfDay = now.toLocalDate().atTime(LocalTime.MAX); |
| | | List<AppUserViewingHistory> list = appUserViewingHistoryService |
| | | .lambdaQuery().eq(AppUserViewingHistory::getAppUserId, userId) |
| | | .eq(AppUserViewingHistory::getViewingType, 1) |
| | | .eq(BaseModel::getDelFlag,0) |
| | | .between(AppUserViewingHistory::getCreateTime, startOfDay,endOfDay).list(); |
| | | int temp = 0; |
| | | for (AppUserViewingHistory appUserViewingHistory1 : list) { |
| | | temp += appUserViewingHistory1.getTimeLook(); |
| | | } |
| | | AppUserTree one = appUserTreeService.lambdaQuery().eq(AppUserTree::getAppUserId, userId) |
| | | .eq(AppUserTree::getSowAgain,2).one(); |
| | | if (one == null){ |
| | | AppUserTree appUserTree = new AppUserTree(); |
| | | appUserTree.setAppUserId(userId); |
| | | appUserTree.setTreeLevelType(1); |
| | | appUserTree.setGrowthValue(0); |
| | | |
| | | appUserTree.setSowAgain(2); |
| | | appUserTree.setCreateTime(LocalDateTime.now()); |
| | | if (temp>=60){ |
| | | byId.setEnergyValue(byId.getEnergyValue()+30); |
| | | } |
| | | else if (temp>=30){ |
| | | byId.setEnergyValue(byId.getEnergyValue()+10); |
| | | } |
| | | appUserService.updateById(byId); |
| | | appUserTreeService.save(appUserTree); |
| | | }else{ |
| | | if (temp>=60){ |
| | | byId.setEnergyValue(byId.getEnergyValue()+30); |
| | | } |
| | | else if (temp>=30){ |
| | | byId.setEnergyValue(byId.getEnergyValue()+10); |
| | | } |
| | | appUserService.updateById(byId); |
| | | appUserTreeService.updateById(one); |
| | | } |
| | | return R.ok(); |
| | | } |
| | | @PostMapping("/saveCourseStudyHistory") |
| | |
| | | // 如果已经看完了 那么不更新状态 只更新观看时间 |
| | | one.setMinuteLook(minuteLook); |
| | | one.setSecondLook(secondLook); |
| | | one.setTimeLook(secondLook); |
| | | }else{ |
| | | one.setIsOver(isOver); |
| | | } |
| | |
| | | appUserViewingHistory.setSecondLook(secondLook); |
| | | appUserViewingHistory.setChapterId(chapterId); |
| | | appUserViewingHistory.setIsOver(isOver); |
| | | appUserViewingHistory.setTimeLook(secondLook); |
| | | |
| | | appUserViewingHistoryService.save(appUserViewingHistory); |
| | | } |
| | | return R.ok(); |