| | |
| | | package com.xinquan.user.controller.client; |
| | | |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.xinquan.common.core.domain.R; |
| | | import com.xinquan.common.core.utils.page.BeanUtils; |
| | | import com.xinquan.common.core.utils.page.PageDTO; |
| | | import com.xinquan.common.core.web.domain.BaseModel; |
| | | import com.xinquan.common.security.utils.SecurityUtils; |
| | | import com.xinquan.order.api.feign.RemoteOrderService; |
| | | import com.xinquan.system.api.RemoteBannerService; |
| | | 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.UserLevelSetting; |
| | | import com.xinquan.system.api.domain.vo.*; |
| | | import com.xinquan.user.domain.dto.UserAnswerDTO; |
| | | import com.xinquan.user.domain.vo.AppUserVO; |
| | | import com.xinquan.user.domain.vo.TagVO; |
| | | 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 java.math.BigDecimal; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.HashSet; |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | import static com.xinquan.common.core.enums.TreeLevelEnum.TOWERING_TREES; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | public class ClientAppUserController { |
| | | |
| | | private final AppUserService appUserService; |
| | | @Resource |
| | | private AppUserViewingHistoryService appUserViewingHistoryService; |
| | | |
| | | @Resource |
| | | private AppUserTreeService appUserTreeService; |
| | | @Resource |
| | | private RemoteBannerService remoteBannerService; |
| | | @Resource |
| | | private RemoteOrderService remoteOrderService; |
| | | public static void main(String[] args) { |
| | | LocalDateTime dateTime = LocalDateTime.now(); |
| | | DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); |
| | | String formattedDateTime = dateTime.format(formatter); |
| | | System.err.println(formattedDateTime); |
| | | } |
| | | /** |
| | | * 爱心助力榜单-分页 |
| | | * |
| | | * @param pageCurr 分页参数,当前页码 |
| | | * @param pageSize 分页参数,每页数量 |
| | | * @return 课程分页列表 |
| | | */ |
| | | @PostMapping("/myInviteRankList") |
| | | @ApiOperation(value = "我的助力-分页", tags = {"个人中心"}) |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "分页参数,当前页码", name = "pageCurr", required = true, dataType = "Integer"), |
| | | @ApiImplicitParam(value = "分页参数,每页数量", name = "pageSize", required = true, dataType = "Integer") |
| | | }) |
| | | public R<PageDTO<InviteRankListVO>> myInviteRankList( |
| | | @RequestParam(value = "pageCurr", defaultValue = "1") Integer pageCurr, |
| | | @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) { |
| | | Long userId = SecurityUtils.getUserId(); |
| | | if (userId == 0)return R.tokenError("登录失效"); |
| | | Page<AppUser> page = appUserService.lambdaQuery().ne(AppUser::getUserStatus, 3) |
| | | .eq(AppUser::getInviteUserId, userId) |
| | | .page(new Page<>(pageCurr, pageSize)); |
| | | // 查询登录用户邀请了哪些人 |
| | | List<Long> collect = page.getRecords().stream().map(AppUser::getId).collect(Collectors.toList()); |
| | | if (collect.isEmpty())return R.ok(PageDTO.empty(page)); |
| | | StringBuilder stringBuilder = new StringBuilder(); |
| | | collect.forEach(id -> stringBuilder.append(id).append(",")); |
| | | // 去除最后一位 |
| | | StringBuilder stringBuilder1 = stringBuilder.deleteCharAt(stringBuilder.length() - 1); |
| | | String[] split = stringBuilder1.toString().split(","); |
| | | for (int i = 0; i < page.getRecords().size(); i++) { |
| | | AppUser appUser = page.getRecords().get(i); |
| | | appUser.setMoney(new BigDecimal(split[i])); |
| | | } |
| | | // 根据佣金金额 从大到小排序 |
| | | page.getRecords().sort((o1, o2) -> o2.getMoney().compareTo(o1.getMoney())); |
| | | return R.ok(PageDTO.of(page, InviteRankListVO.class)); |
| | | } |
| | | /** |
| | | * 爱心助力榜单-分页 |
| | | * |
| | | * @param pageCurr 分页参数,当前页码 |
| | | * @param pageSize 分页参数,每页数量 |
| | | * @return 课程分页列表 |
| | | */ |
| | | @PostMapping("/inviteRankList") |
| | | @ApiOperation(value = "爱心助力榜单-分页", tags = {"个人中心"}) |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "分页参数,当前页码", name = "pageCurr", required = true, dataType = "Integer"), |
| | | @ApiImplicitParam(value = "分页参数,每页数量", name = "pageSize", required = true, dataType = "Integer") |
| | | }) |
| | | public R<PageDTO<InviteRankListVO>> inviteRankList( |
| | | @RequestParam(value = "pageCurr", defaultValue = "1") Integer pageCurr, |
| | | @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) { |
| | | Page<AppUser> page = appUserService.lambdaQuery().ne(AppUser::getUserStatus, 3) |
| | | .page(new Page<>(pageCurr, pageSize)); |
| | | for (AppUser appUser : page.getRecords()) { |
| | | int size = appUserService.lambdaQuery().ne(AppUser::getUserStatus, 3) |
| | | .eq(AppUser::getInviteUserId, appUser.getId()) |
| | | .list().size(); |
| | | appUser.setCount(size); |
| | | } |
| | | // 根据帮助人数 从大到小排序 |
| | | page.getRecords().sort((o1, o2) -> o2.getCount() - o1.getCount()); |
| | | return R.ok(PageDTO.of(page, InviteRankListVO.class)) ; |
| | | } |
| | | @PostMapping("/getUserInfo") |
| | | @ApiOperation(value = "获取用户信息", tags = {"个人中心"}) |
| | | public R<AppUserInfoVO> getUserInfo() { |
| | | Long userId = SecurityUtils.getUserId(); |
| | | if (userId == 0)return R.tokenError("登录失效"); |
| | | AppUserInfoVO appUserInfoVO = new AppUserInfoVO(); |
| | | AppUserVO currentUser = appUserService.getCurrentUser(); |
| | | DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); |
| | | if (currentUser.getVipExpireTime() == null){ |
| | | appUserInfoVO.setIsVip(2); |
| | | }else if (currentUser.getVipExpireTime().isAfter(LocalDateTime.now())){ |
| | | appUserInfoVO.setIsVip(1); |
| | | String formattedDateTime =currentUser.getVipExpireTime().format(formatter); |
| | | appUserInfoVO.setVipExpireTime(formattedDateTime); |
| | | }else{ |
| | | String formattedDateTime =currentUser.getVipExpireTime().format(formatter); |
| | | appUserInfoVO.setVipExpireTime(formattedDateTime); |
| | | appUserInfoVO.setIsVip(2); |
| | | } |
| | | // 查询用户累计学习天数 |
| | | List<AppUserViewingHistory> com = appUserViewingHistoryService.cumulative(userId); |
| | | appUserInfoVO.setCumulative(com.size()); |
| | | // 查询用户今日学习多少分钟 |
| | | int temp = appUserViewingHistoryService.today(userId); |
| | | if (temp == 0){ |
| | | appUserInfoVO.setToday(0); |
| | | }else if (temp<60){ |
| | | // 不足一分钟按一分钟计算 |
| | | appUserInfoVO.setToday(1); |
| | | }else{ |
| | | appUserInfoVO.setToday(temp/60); |
| | | } |
| | | // 查询用户连续观看天数 |
| | | List<AppUserViewingHistory> list = appUserViewingHistoryService.lambdaQuery().eq(AppUserViewingHistory::getAppUserId, userId) |
| | | .eq(AppUserViewingHistory::getViewingType, 1) |
| | | .orderByDesc(BaseModel::getCreateTime).list(); |
| | | Set<LocalDate> viewingDates = list.stream() |
| | | .map(record -> LocalDate.parse(record.getCreateTime().toLocalDate().toString(), formatter)) |
| | | .collect(Collectors.toCollection(HashSet::new)); |
| | | // 获取今天的日期 |
| | | LocalDate today = LocalDate.now(); |
| | | // 计算连续观看天数 |
| | | int consecutiveDays = 0; |
| | | LocalDate currentDate = today; |
| | | // 如果今天没有观看 也进入循环判断 |
| | | while (viewingDates.contains(currentDate)||LocalDate.parse(currentDate.toString(), formatter).equals(today)) { |
| | | if (!viewingDates.contains(currentDate)){ |
| | | // 如果今天没有观看 |
| | | currentDate = currentDate.minusDays(1); |
| | | continue; |
| | | } |
| | | consecutiveDays++; |
| | | currentDate = currentDate.minusDays(1); |
| | | } |
| | | appUserInfoVO.setToday(consecutiveDays); |
| | | List<AppUserTree> list1 = appUserTreeService.lambdaQuery().eq(AppUserTree::getAppUserId, userId) |
| | | .list(); |
| | | // 查询用户等级最高的那颗树苗 |
| | | AppUserTree tree = list1.stream().max((o1, o2) -> { |
| | | if (o1.getTreeLevelType() > o2.getTreeLevelType()) { |
| | | return 1; |
| | | } else if (o1.getTreeLevelType() < o2.getTreeLevelType()) { |
| | | return -1; |
| | | } else { |
| | | return 0; |
| | | } |
| | | }).orElse(null); |
| | | // 查询疗愈等级 名称 图标 |
| | | int level = 1; |
| | | if (tree != null){ |
| | | level = tree.getTreeLevelType(); |
| | | } |
| | | appUserInfoVO.setLevel(level); |
| | | // 根据等级查询疗愈名称和图标 |
| | | UserLevelSetting data = remoteBannerService.getIconNameByLevel(level).getData(); |
| | | appUserInfoVO.setLevelName(data.getLevelName()); |
| | | appUserInfoVO.setLevelIcon(data.getLevelIcon()); |
| | | return R.ok(appUserInfoVO); |
| | | } |
| | | @PostMapping("/getUserDetail") |
| | | @ApiOperation(value = "获取个人资料", tags = {"个人中心"}) |
| | | public R<AppUser> getUserDetail() { |
| | | Long userId = SecurityUtils.getUserId(); |
| | | if (userId == 0)return R.tokenError("登录失效"); |
| | | AppUser appUser = appUserService.lambdaQuery().eq(AppUser::getId, userId).one(); |
| | | return R.ok(appUser); |
| | | } |
| | | @PostMapping("/getTotalEnergyValue") |
| | | @ApiOperation(value = "获取用户当前累计能量值",tags = "树苗打卡站") |
| | | public R getTotalEnergyValue() { |
| | | Long userId = SecurityUtils.getUserId(); |
| | | if (userId==0)return R.tokenError("登录失效"); |
| | | AppUser byId = appUserService.getById(userId); |
| | | return R.ok(byId.getTotalEnergyValue()); |
| | | } |
| | | @PostMapping("/updateUserDetail") |
| | | @ApiOperation(value = "修改个人资料", tags = {"个人中心"}) |
| | | public R<AppUser> updateUserDetail(UpdateAppUserDTO dto) { |
| | | Long userId = SecurityUtils.getUserId(); |
| | | if (userId == 0)return R.tokenError("登录失效"); |
| | | AppUser byId = appUserService.getById(userId); |
| | | BeanUtils.copyProperties(dto, byId); |
| | | // LambdaUpdateWrapper<AppUser> updateWrapper = new LambdaUpdateWrapper<>(AppUser.class); |
| | | // updateWrapper.set(AppUser::getNickname, byId.getNickname()); |
| | | // updateWrapper.set(AppUser::getSignature, byId.getSignature()); |
| | | // updateWrapper.set(AppUser::getAvatar, byId.getAvatar()); |
| | | // updateWrapper.set(AppUser::getGender, byId.getGender()); |
| | | // updateWrapper.set(AppUser::getBirthday, byId.getBirthday()); |
| | | // updateWrapper.set(AppUser::getEducation, byId.getEducation()); |
| | | // updateWrapper.set(AppUser::getIndustry, byId.getIndustry()); |
| | | // updateWrapper.set(AppUser::getCompany, byId.getCompany()); |
| | | // updateWrapper.set(AppUser::getOccupation, byId.getOccupation()); |
| | | // updateWrapper.set(AppUser::getLocation, byId.getLocation()); |
| | | // updateWrapper.set(AppUser::getHometown, byId.getHometown()); |
| | | // appUserService.update(byId, ) |
| | | return R.ok(); |
| | | } |
| | | /** |
| | | * 获取当前登录用户信息 |
| | | * |
| | | * @return 用户信息 |
| | | * @see com.xinquan.user.domain.vo.AppUserVO |
| | | * @see AppUserVO |
| | | */ |
| | | @PostMapping("/getCurrentUser") |
| | | @ApiOperation(value = "获取当前用户信息", tags = {"用户端-用户信息相关接口"}) |
| | |
| | | } |
| | | |
| | | /** |
| | | * 通过手机号查询用户端用户信息 |
| | | * |
| | | * @return 用户信息 |
| | | * @see AppUserVO |
| | | */ |
| | | @PostMapping("/getUserByPhone") |
| | | @ApiOperation(value = "根据用户手机号查询用户信息") |
| | | public R<AppUserDetailVO> getCurrentUser(String phone) { |
| | | AppUser one = appUserService.lambdaQuery().eq(AppUser::getCellPhone, phone).one(); |
| | | AppUserDetailVO appUserDetailVO = new AppUserDetailVO(); |
| | | appUserDetailVO.setId(one.getId()); |
| | | appUserDetailVO.setCellPhone(one.getCellPhone()); |
| | | appUserDetailVO.setAvatar(one.getAvatar()); |
| | | appUserDetailVO.setNickname(one.getNickname()); |
| | | return R.ok(appUserDetailVO); |
| | | } |
| | | @PostMapping("/getUserBalance") |
| | | @ApiOperation(value = "查询当前用户余额") |
| | | public R<String> getUserBalance() { |
| | | Long userId = SecurityUtils.getUserId(); |
| | | if (userId == 0)return R.tokenError("登录失效"); |
| | | AppUser one = appUserService.lambdaQuery().eq(AppUser::getUserId, userId).one(); |
| | | return R.ok(one.getBalance().toString()); |
| | | } |
| | | |
| | | /** |
| | | * 获取问题二的标签列表 |
| | | * |
| | | * @return List<TagVO> |