From b01f752252eaadd1fa31eda6a9ad43146660b721 Mon Sep 17 00:00:00 2001 From: 无关风月 <443237572@qq.com> Date: 星期四, 03 四月 2025 23:42:57 +0800 Subject: [PATCH] bug修改 --- xinquan-api/xinquan-api-user/src/main/java/com/xinquan/user/api/feign/RemoteAppUserService.java | 2 xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/controller/client/ClientAppUserViewingHistoryController.java | 84 +++++++++++++++++++++++++++ xinquan-api/xinquan-api-user/src/main/java/com/xinquan/user/api/factory/RemoteAppUserFallbackFactory.java | 5 + xinquan-auth/src/main/java/com/xinquan/auth/service/SysLoginService.java | 8 +- xinquan-modules/xinquan-meditation/src/main/java/com/xinquan/meditation/service/impl/MeditationServiceImpl.java | 37 +++++------ 5 files changed, 110 insertions(+), 26 deletions(-) diff --git a/xinquan-api/xinquan-api-user/src/main/java/com/xinquan/user/api/factory/RemoteAppUserFallbackFactory.java b/xinquan-api/xinquan-api-user/src/main/java/com/xinquan/user/api/factory/RemoteAppUserFallbackFactory.java index deae664..8e9ac6a 100644 --- a/xinquan-api/xinquan-api-user/src/main/java/com/xinquan/user/api/factory/RemoteAppUserFallbackFactory.java +++ b/xinquan-api/xinquan-api-user/src/main/java/com/xinquan/user/api/factory/RemoteAppUserFallbackFactory.java @@ -77,6 +77,11 @@ } @Override + public R<List<AppUserViewingHistory>> getMeditationHistoryCountAll() { + return null; + } + + @Override public R<Long> getCourseHistoryCount(Long id) { return R.fail("后台远程调用 根据课程id 获取实际观看人数"); } diff --git a/xinquan-api/xinquan-api-user/src/main/java/com/xinquan/user/api/feign/RemoteAppUserService.java b/xinquan-api/xinquan-api-user/src/main/java/com/xinquan/user/api/feign/RemoteAppUserService.java index 285327a..a576d9d 100644 --- a/xinquan-api/xinquan-api-user/src/main/java/com/xinquan/user/api/feign/RemoteAppUserService.java +++ b/xinquan-api/xinquan-api-user/src/main/java/com/xinquan/user/api/feign/RemoteAppUserService.java @@ -49,6 +49,8 @@ public R<AppUser> getUserByPhone(@PathVariable("phone")String phone); @PostMapping("/user/app-user-viewing-history/getMeditationHistoryCount/{id}") public R<Long> getMeditationHistoryCount(@PathVariable("id") Long id); + @PostMapping("/user/app-user-viewing-history/getMeditationHistoryCountAll") + public R<List<AppUserViewingHistory>> getMeditationHistoryCountAll(); @PostMapping("/user/app-user-viewing-history/getCourseHistoryCount/{id}") public R<Long> getCourseHistoryCount(@PathVariable("id") Long id); @PostMapping("/user/app-user-viewing-history/getCourseChapterHistoryCount/{id}") diff --git a/xinquan-auth/src/main/java/com/xinquan/auth/service/SysLoginService.java b/xinquan-auth/src/main/java/com/xinquan/auth/service/SysLoginService.java index c3a9a04..5ade740 100644 --- a/xinquan-auth/src/main/java/com/xinquan/auth/service/SysLoginService.java +++ b/xinquan-auth/src/main/java/com/xinquan/auth/service/SysLoginService.java @@ -341,25 +341,25 @@ if (StringUtils.isNull(appUser)) { recordLogService.recordLogininfor(body.getCellPhone(), Constants.LOGIN_FAIL, "登录用户不存在"); - throw new ServiceException("登录用户:" + body.getCellPhone() + " 不存在"); + throw new ServiceException("登录用户:" + body.getCellPhone() + " 不存在",500); } // 1:正常 2:冻结 3:注销 if (appUser.getUserStatus().equals(AppUserStatusEnum.FROZEN.getCode())) { recordLogService.recordLogininfor(body.getCellPhone(), Constants.LOGIN_FAIL, "账号已冻结"); - throw new ServiceException("账号已冻结"); + throw new ServiceException("账号已冻结",500); } if (appUser.getUserStatus().equals(AppUserStatusEnum.LOGOUT.getCode())) { recordLogService.recordLogininfor(body.getCellPhone(), Constants.LOGIN_FAIL, "账号已注销"); - throw new ServiceException("账号已注销"); + throw new ServiceException("账号已注销",500); } // 查询系统用户信息 SysUser sysUser = sysUserClient.getSysUser(appUser.getUserId()).getData(); if (StringUtils.isNull(sysUser)) { recordLogService.recordLogininfor(body.getCellPhone(), Constants.LOGIN_FAIL, "登录用户不存在"); - throw new ServiceException("登录用户:" + body.getCellPhone() + " 不存在"); + throw new ServiceException("登录用户:" + body.getCellPhone() + " 不存在",500); } passwordService.validate(sysUser, body.getPassword()); // if (!sysUser.getPassword().equals(body.getPassword())){ diff --git a/xinquan-modules/xinquan-meditation/src/main/java/com/xinquan/meditation/service/impl/MeditationServiceImpl.java b/xinquan-modules/xinquan-meditation/src/main/java/com/xinquan/meditation/service/impl/MeditationServiceImpl.java index 8415501..2735f72 100644 --- a/xinquan-modules/xinquan-meditation/src/main/java/com/xinquan/meditation/service/impl/MeditationServiceImpl.java +++ b/xinquan-modules/xinquan-meditation/src/main/java/com/xinquan/meditation/service/impl/MeditationServiceImpl.java @@ -32,6 +32,7 @@ import com.xinquan.order.api.feign.RemoteOrderService; import com.xinquan.system.api.domain.AppUser; import com.xinquan.meditation.api.domain.MeditationQuestion; +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.domain.dto.AppUserDTO; @@ -65,6 +66,7 @@ private final MeditationQuestionLikeService meditationQuestionLikeService; private final MeditationUserFavoriteService meditationUserFavoriteService; private final RemoteOrderService remoteOrderService; + private final MeditationMapper meditationMapper; /** * 获取私人订制 * @@ -119,15 +121,13 @@ if (loginUser==null){ return new ArrayList<>(); } - Long userId = loginUser.getUserid(); - List<Order> orderList = remoteOrderService.getOrderListByType(userId, - OrderFromEnum.MEDITATION.getCode(), - SecurityConstants.INNER).getData(); - List<Long> meditationIdList = orderList.stream().map(Order::getBusinessId) - .collect(Collectors.toList()); + Long userId = loginUser.getUserid(); + List<Order> data1 = remoteOrderService.getMeditationIsBuyAll(userId).getData(); + List<Long> meditationIdList = data1.stream().map(Order::getBusinessId).collect(Collectors.toList()); if (CollUtils.isNotEmpty(meditationIdList)) { + Set<Long> meditationIdSet = new HashSet<>(meditationIdList); voList = voList.stream() - .filter(meditationVO -> meditationIdList.contains(meditationVO.getId())) + .filter(meditationVO -> meditationIdSet.contains(meditationVO.getId())) .peek(meditationVO -> meditationVO.setIsBuy(1)) .collect(Collectors.toList()); } @@ -156,15 +156,10 @@ meditationLambdaQueryWrapper.orderByDesc(Meditation::getSortNum).last("limit 8"); } List<Meditation> list =this.list(meditationLambdaQueryWrapper); - List<Meditation> meditations = new ArrayList<>(); - for (Meditation meditation : list) { - if (meditation.getListingStatus()==1){ - meditations.add(meditation); - } - } - if (CollUtils.isNotEmpty(meditations)) { + + if (CollUtils.isNotEmpty(list)) { // 对象拷贝 - voList = BeanUtils.copyList(meditations, ClientMeditationVO.class); + voList = BeanUtils.copyList(list, ClientMeditationVO.class); } handlePaidMeditation(voList); return voList; @@ -306,11 +301,13 @@ if (tokenService.getLoginUser()!=null){ data1 = remoteOrderService.getMeditationIsBuyAll(tokenService.getLoginUser().getUserid()).getData(); } + List<AppUserViewingHistory> data2 = remoteAppUserService.getMeditationHistoryCountAll().getData(); + boolean temp = tokenService.getLoginUser()!=null; for (Meditation record : page.getRecords()) { - Long data = remoteAppUserService.getMeditationHistoryCount(record.getId()).getData(); - record.setRealLearnedNum(Integer.valueOf(data+"")); + List<AppUserViewingHistory> collect = data2.stream().filter(e -> e.getBizId().equals(record.getId())).collect(Collectors.toList()); + record.setRealLearnedNum(collect.size()); record.setRealLearnedNum(record.getVirtualLearnedNum()+record.getRealLearnedNum()); - if (tokenService.getLoginUser()!=null){ + if (temp){ Order order = data1.stream().filter(e -> e.getBusinessId().equals(record.getId())).findFirst().orElse(null); if (order==null){ record.setIsBuy(2); @@ -320,8 +317,8 @@ }else{ record.setIsBuy(2); } - this.updateById(record); } + this.updateBatchById(page.getRecords()); // 将实体类转换为VO pageDTO = PageDTO.of(page, ClientMeditationVO.class); return pageDTO; @@ -456,7 +453,7 @@ } } - + this.updateById(meditation); return R.ok(vo); } @Override 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