| | |
| | | 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; |
| | |
| | | |
| | | /** |
| | | * 远程调用 根据章节id和用户id查询是否观看完毕 |
| | | * |
| | | * @param id |
| | | * @return |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 远程调用查询用户观看了哪些课程 |
| | | * |
| | | * @return |
| | | */ |
| | | @PostMapping("/getCourseHistoryByUserId/{id}") |
| | |
| | | .collect(Collectors.toList()); |
| | | return R.ok(one); |
| | | } |
| | | |
| | | @PostMapping("/getMeditationHistoryCount/{id}") |
| | | public R<Long> getMeditationHistoryCount(@PathVariable("id") Long id) { |
| | | List<AppUserViewingHistory> list = appUserViewingHistoryService.lambdaQuery() |
| | |
| | | .list(); |
| | | return R.ok(Long.valueOf(list.size())); |
| | | } |
| | | |
| | | @PostMapping("/getCourseHistoryCount/{id}") |
| | | public R<Long> getCourseHistoryCount(@PathVariable("id") Long id) { |
| | | List<AppUserViewingHistory> list = appUserViewingHistoryService.lambdaQuery() |
| | |
| | | .list(); |
| | | return R.ok(Long.valueOf(list.size())); |
| | | } |
| | | |
| | | @PostMapping("/getCourseChapterHistoryCount/{id}") |
| | | public R<Long> getCourseChapterHistoryCount(@PathVariable("id") Long id) { |
| | | List<AppUserViewingHistory> list = appUserViewingHistoryService.lambdaQuery() |
| | |
| | | .list(); |
| | | return R.ok(Long.valueOf(list.size())); |
| | | } |
| | | |
| | | @PostMapping("/lookHistory") |
| | | @ApiOperation(value = "观看历史") |
| | | @ApiImplicitParams({ |
| | |
| | | } |
| | | return R.ok(orderCourseVOS); |
| | | } |
| | | |
| | | /** |
| | | * 记录用户观看记录 |
| | | * |
| | | */ |
| | | @PostMapping("/saveViewingHistory") |
| | | @ApiOperation(value = "记录用户观看冥想记录", tags = {"用户端-用户相关接口"}) |
| | |
| | | appUserViewingHistory.setTimeLook(timeLook); |
| | | appUserViewingHistory.setCreateTime(LocalDateTime.now()); |
| | | appUserViewingHistoryService.save(appUserViewingHistory); |
| | | AppUser byId = appUserService.getById(userId); |
| | | appUserService.updateById(byId); |
| | | // 查询用户今日观看疗愈多少秒 |
| | | 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) { |
| | | if (appUserViewingHistory1.getTimeLook() != null) { |
| | | temp += appUserViewingHistory1.getTimeLook(); |
| | | |
| | | } |
| | | } |
| | | AppUserTree one = appUserTreeService.lambdaQuery().eq(AppUserTree::getAppUserId, userId) |
| | | .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 (byId.getSignTime() != null && byId.getSignTime().toLocalDate().equals(LocalDateTime.now().toLocalDate())) { |
| | | appUserTree.setIsSign(1); |
| | | } else { |
| | | appUserTree.setIsSign(2); |
| | | } |
| | | 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); |
| | | } |
| | | appUserTree.setEnergyValue(byId.getEnergyValue()); |
| | | appUserTree.setNextLevel(1000); |
| | | appUserTreeService.save(appUserTree); |
| | | 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); |
| | | } |
| | | appUserTreeService.updateById(one); |
| | | appUserService.updateById(byId); |
| | | return R.ok(); |
| | | } |
| | | } |
| | | |
| | | @Resource |
| | | private AppUserEnergyRecordService appUserEnergyRecordService; |
| | | |
| | | @PostMapping("/saveCourseStudyHistory") |
| | | @ApiOperation(value = "记录用户观看课程记录", tags = {"用户端-用户相关接口"}) |
| | | @ApiImplicitParams({ |
| | |
| | | } |
| | | return R.ok(); |
| | | } |
| | | |
| | | @PostMapping("/getCourseStudyHistory") |
| | | public R<AppUserViewingHistory> getCourseStudyHistory(@RequestParam("chapterId") Long chapterId) { |
| | | LoginUser loginUser = tokenService.getLoginUser(); |