From 64f7ccb9ef8b5a0618e65cddc14b981c1f108ba3 Mon Sep 17 00:00:00 2001 From: 无关风月 <443237572@qq.com> Date: 星期一, 04 十一月 2024 09:01:59 +0800 Subject: [PATCH] 代码提交 --- xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/controller/client/ClientAppUserViewingHistoryController.java | 305 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 293 insertions(+), 12 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 239e7e4..5312db0 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,17 +1,43 @@ package com.xinquan.user.controller.client; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.xinquan.common.core.domain.R; +import com.xinquan.common.core.utils.page.PageDTO; +import com.xinquan.common.core.web.domain.BaseModel; +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.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.vo.AppUserVO; +import com.xinquan.system.api.model.LoginUser; +import com.xinquan.user.api.feign.RemoteAppUserService; +import com.xinquan.user.service.AppUserService; +import com.xinquan.user.service.AppUserTreeService; import com.xinquan.user.service.AppUserViewingHistoryService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; +import io.swagger.models.auth.In; +import lombok.Data; import lombok.RequiredArgsConstructor; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.stream.Collectors; /** * <p> @@ -28,23 +54,278 @@ public class ClientAppUserViewingHistoryController { private final AppUserViewingHistoryService appUserViewingHistoryService; + @Resource + private TokenService tokenService; + @Resource + private AppUserTreeService appUserTreeService; + @Resource + private AppUserService appUserService; + @Resource + private RemoteMeditationService remoteMeditationService; + @Resource + private RemoteCourseService courseUserFavoriteService; + @Resource + private RemoteCourseService remoteCourseService; + private final RemoteAppUserService remoteAppUserService; + @PostMapping("/lookHistory") + @ApiOperation(value = "观看历史") + @ApiImplicitParams({ + @ApiImplicitParam(name = "state", value = "1冥想 2课程", dataType = "Integer", required = true), + @ApiImplicitParam(name = "pageCurr", value = "分页参数,当前页码", dataType = "Integer", required = true), + @ApiImplicitParam(name = "pageSize", value = "分页参数,每页数量", dataType = "Integer", required = true) + }) + public R<List<OrderCourseVO>> lookHistory(Integer state, Integer pageCurr, Integer pageSize) { + LoginUser loginUser = tokenService.getLoginUser(); + if (loginUser==null){ + return R.tokenError("登录失效"); + } + Long userId = loginUser.getUserid(); + List<OrderCourseVO> orderCourseVOS = new ArrayList<>(); + switch (state){ + case 1: + List<Long> collect1 = appUserViewingHistoryService.lambdaQuery() + .eq(AppUserViewingHistory::getAppUserId, userId) + .eq(AppUserViewingHistory::getViewingType, 1).list() + .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{ + for (Long l : collect2) { + temp.append(l).append(","); + } + temp.deleteCharAt(temp.length() - 1); + } + Page<Meditation> data = remoteMeditationService.getMeditationByIds(pageCurr,pageSize,temp.toString()).getData(); + + for (Meditation meditation : data.getRecords()) { + OrderCourseVO orderCourseVO = new OrderCourseVO(); + orderCourseVO.setBusinessId(meditation.getId()); + orderCourseVO.setCourseTitle(meditation.getMeditationTitle()); + orderCourseVO.setDescription(meditation.getDetailDescription()); + orderCourseVO.setChargeType(meditation.getChargeType()); + orderCourseVO.setGeneralPrice(meditation.getGeneralPrice()); + orderCourseVO.setIosPrice(meditation.getIosPrice()); + orderCourseVO.setCoverUrl(meditation.getCoverUrl()); + orderCourseVO.setCount(meditation.getRealLearnedNum()+meditation.getVirtualLearnedNum()); + orderCourseVOS.add(orderCourseVO); + } + break; + case 2: + List<Long> collect3 = appUserViewingHistoryService.lambdaQuery() + .eq(AppUserViewingHistory::getAppUserId, userId) + .eq(AppUserViewingHistory::getViewingType, 2).list() + .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{ + for (Long l : collect4) { + temp1.append(l).append(","); + } + temp1.deleteCharAt(temp1.length() - 1); + } + Page<Course> data2 = remoteCourseService.getCourseByIds(pageCurr,pageSize,temp1.toString()).getData(); + for (Course record : data2.getRecords()) { + OrderCourseVO orderCourseVO = new OrderCourseVO(); + orderCourseVO.setBusinessId(record.getId()); + orderCourseVO.setCourseTitle(record.getCourseTitle()); + orderCourseVO.setDescription(record.getDescription()); + orderCourseVO.setChargeType(record.getChargeType()); + orderCourseVO.setGeneralPrice(record.getGeneralPrice()); + orderCourseVO.setIosPrice(record.getIosPrice()); + orderCourseVO.setCoverUrl(record.getCoverUrl()); + List<AppUser> data1 = remoteAppUserService.getUserByCourseId(record.getId()).getData(); + orderCourseVO.setCount(data1.size()); + orderCourseVOS.add(orderCourseVO); + } + break; + } + return R.ok(orderCourseVOS); + } /** * 记录用户观看记录 * - * @param bizId 业务id - * @param viewingType 观看类型 1=疗愈 2=课程 */ @PostMapping("/saveViewingHistory") - @ApiOperation(value = "记录用户观看记录", tags = {"用户端-用户相关接口"}) + @ApiOperation(value = "记录用户观看冥想记录", tags = {"用户端-用户相关接口"}) @ApiImplicitParams({ - @ApiImplicitParam(name = "bizId", value = "业务id", dataType = "Long", required = true), - @ApiImplicitParam(name = "viewingType", value = "观看类型 1=疗愈 2=课程", dataType = "Integer", required = true) + @ApiImplicitParam(name = "id", value = "冥想id", dataType = "Long", required = true), + @ApiImplicitParam(name = "timeLook", value = "播放时长单位秒", dataType = "Integer", required = true) }) - public R<?> saveViewingRecord(@RequestParam("bizId") Long bizId, - @RequestParam("viewingType") Integer viewingType) { - appUserViewingHistoryService.saveViewingRecord(bizId, viewingType); + public R<?> saveViewingRecord(@RequestParam("id") Long id, + @RequestParam("timeLook") Integer timeLook + ) { + LoginUser loginUser = tokenService.getLoginUser(); + 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 + // 查询用户今日观看疗愈多少秒 + 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") + @ApiOperation(value = "记录用户观看课程记录", tags = {"用户端-用户相关接口"}) + @ApiImplicitParams({ + @ApiImplicitParam(name = "chapterId", value = "章节id", dataType = "Long", required = true), + @ApiImplicitParam(name = "isOver", value = "是否观看完成 1是2否", dataType = "int", required = true), + @ApiImplicitParam(name = "minuteLook", value = "观看到xx分钟", dataType = "int", required = true), + @ApiImplicitParam(name = "secondLook", value = "观看到xx秒", dataType = "int", required = true), + }) + public R<?> saveCourseStudyHistory(@RequestParam("chapterId") Long chapterId, + @RequestParam("minuteLook") Integer minuteLook, + @RequestParam("secondLook") Integer secondLook, + @RequestParam("isOver") Integer isOver + ) { + LoginUser loginUser = tokenService.getLoginUser(); + if (loginUser==null){ + return R.tokenError("登录失效"); + } + Long userId = loginUser.getUserid(); + AppUserViewingHistory one = appUserViewingHistoryService.lambdaQuery() + .eq(AppUserViewingHistory::getAppUserId, userId) + .eq(AppUserViewingHistory::getViewingType, 2) + .eq(AppUserViewingHistory::getChapterId, chapterId).one(); + if (one!=null){ + if (one.getIsOver() == 1){ + // 如果已经看完了 那么不更新状态 只更新观看时间 + one.setMinuteLook(minuteLook); + one.setSecondLook(secondLook); + }else{ + one.setIsOver(isOver); + } + appUserViewingHistoryService.updateById(one); + }else{ + AppUserViewingHistory appUserViewingHistory = new AppUserViewingHistory(); + appUserViewingHistory.setAppUserId(userId); + appUserViewingHistory.setBizId(chapterId); + appUserViewingHistory.setViewingType(2); + appUserViewingHistory.setMinuteLook(minuteLook); + appUserViewingHistory.setSecondLook(secondLook); + appUserViewingHistory.setChapterId(chapterId); + appUserViewingHistory.setIsOver(isOver); + appUserViewingHistoryService.save(appUserViewingHistory); + } + return R.ok(); + } + @PostMapping("/getCourseStudyHistory") + public R<AppUserViewingHistory> getCourseStudyHistory(@RequestParam("chapterId") Long chapterId) { + LoginUser loginUser = tokenService.getLoginUser(); + if (loginUser==null){ + return R.tokenError("登录失效"); + } + Long userId = loginUser.getUserid(); + AppUserViewingHistory one = appUserViewingHistoryService.lambdaQuery() + .eq(AppUserViewingHistory::getAppUserId, userId) + .eq(AppUserViewingHistory::getViewingType, 2) + .eq(AppUserViewingHistory::getChapterId, chapterId).one(); + if (one==null){ + AppUserViewingHistory appUserViewingHistory = new AppUserViewingHistory(); + appUserViewingHistory.setAppUserId(userId); + appUserViewingHistory.setBizId(chapterId); + appUserViewingHistory.setViewingType(2); + appUserViewingHistory.setMinuteLook(0); + appUserViewingHistory.setSecondLook(0); + appUserViewingHistory.setChapterId(chapterId); + appUserViewingHistory.setIsOver(2); + appUserViewingHistoryService.save(appUserViewingHistory); + return R.ok(appUserViewingHistory); + } + return R.ok(one); + } + +// @PostMapping("/studyRecord") +// @ApiOperation(value = "学习页面记录观看到xx分钟xx秒") +// @ApiImplicitParams({ +// @ApiImplicitParam(value = "章节id", name = "chapterId", required = true, dataType = "String"), +// @ApiImplicitParam(value = "上次观看到xx分钟", name = "minuteLook", required = true, dataType = "Integer"), +// @ApiImplicitParam(value = "上次观看到xx秒", name = "secondLook", required = true, dataType = "Integer"), +// @ApiImplicitParam(value = "是否观看完成", name = "isOver", required = true, dataType = "Integer"), +// }) +// public R studyRecord(@RequestParam(value = "chapterId")Long chapterId, +// @RequestParam(value = "minuteLook") Integer minuteLook, +// @RequestParam(value = "secondLook") Integer secondLook, +// @RequestParam(value = "isOver") Integer isOver +// ) { +// Long userId = tokenService.getLoginUser().getUserid(); +// if(userId ==null || userId == 0)return R.tokenError("登录失效"); +// AppUserViewingHistory one = appUserViewingHistoryService.lambdaQuery() +// .eq(AppUserViewingHistory::getAppUserId, userId) +// .eq(AppUserViewingHistory::getViewingType, 2) +// .eq(AppUserViewingHistory::getChapterId, chapterId).one(); +// if (one!=null){ +// if (one.getIsOver() == 1){ +// // 如果已经看完了 那么不更新状态 只更新观看时间 +// one.setMinuteLook(minuteLook); +// one.setSecondLook(secondLook); +// }else{ +// one.setIsOver(isOver); +// } +// appUserViewingHistoryService.updateById(one); +// }else{ +// AppUserViewingHistory appUserViewingHistory = new AppUserViewingHistory(); +// appUserViewingHistory.setAppUserId(userId); +// appUserViewingHistory.setBizId(chapterId); +// appUserViewingHistory.setViewingType(2); +// appUserViewingHistory.setMinuteLook(minuteLook); +// appUserViewingHistory.setSecondLook(secondLook); +// appUserViewingHistory.setChapterId(chapterId); +// appUserViewingHistory.setIsOver(isOver); +// appUserViewingHistoryService.save(appUserViewingHistory); +// } +// return R.ok(); +// } } -- Gitblit v1.7.1