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 | 84 +++++++++++++++++++++++++++++++++++++++++- 1 files changed, 82 insertions(+), 2 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 ca2d549..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; @@ -114,6 +115,15 @@ 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() @@ -224,6 +234,67 @@ /** * 记录用户观看记录 */ + @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 = {"用户端-用户相关接口"}) @ApiImplicitParams({ @@ -244,7 +315,17 @@ appUserViewingHistory.setViewingType(1); appUserViewingHistory.setTimeLook(timeLook); appUserViewingHistory.setCreateTime(LocalDateTime.now()); - appUserViewingHistoryService.save(appUserViewingHistory); + // 先查询用户当天有没有观看过该音频 + 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); // 查询用户今日观看疗愈多少秒 @@ -260,7 +341,6 @@ for (AppUserViewingHistory appUserViewingHistory1 : list) { if (appUserViewingHistory1.getTimeLook() != null) { temp += appUserViewingHistory1.getTimeLook(); - } } AppUserTree one = appUserTreeService.lambdaQuery().eq(AppUserTree::getAppUserId, userId) -- Gitblit v1.7.1