| | |
| | | import com.xinquan.common.core.utils.page.CollUtils; |
| | | import com.xinquan.common.security.service.TokenService; |
| | | import com.xinquan.common.security.utils.SecurityUtils; |
| | | import com.xinquan.meditation.api.feign.RemoteMeditationService; |
| | | import com.xinquan.system.api.RemoteUserService; |
| | | import com.xinquan.system.api.domain.SysUser; |
| | | import com.xinquan.system.api.feignClient.SysUserClient; |
| | |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.StringUtils; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | /** |
| | | * <p> |
| | | * 用户信息表 服务实现类 |
| | |
| | | private final AppUserTreeService appUserTreeService; |
| | | private final AppUserQuestionService appUserQuestionService; |
| | | private final TagService tagService; |
| | | @Resource |
| | | private RemoteMeditationService remoteMeditationService; |
| | | /** |
| | | * 获取用户信息 |
| | | * |
| | |
| | | Optional<AppUser> one = this.lambdaQuery() |
| | | .eq(AppUser::getDevice, device) |
| | | .isNull(AppUser::getCellPhone).oneOpt(); |
| | | if (one.isPresent()) { |
| | | initUserTree(one.get().getId()); |
| | | this.updateById(one.get()); |
| | | return one; |
| | | } else { |
| | | |
| | | return this.lambdaQuery() |
| | | .eq(Objects.nonNull(dto.getId()), AppUser::getId, dto.getId()) |
| | | .eq(com.alibaba.nacos.common.utils.StringUtils.isNotBlank(dto.getAppleId()), AppUser::getAppleId, dto.getAppleId()) |
| | | .eq(com.alibaba.nacos.common.utils.StringUtils.isNotBlank(dto.getCellPhone()), AppUser::getCellPhone, |
| | | dto.getCellPhone()) |
| | | .eq(com.alibaba.nacos.common.utils.StringUtils.isNotBlank(dto.getWxOpenId()), AppUser::getWxOpenId, |
| | | dto.getWxOpenId()) |
| | | .ne(AppUser::getUserStatus, AppUserStatusEnum.LOGOUT.getCode()).oneOpt(); |
| | | Optional<AppUser> appUser = this.lambdaQuery() |
| | | .eq(Objects.nonNull(dto.getId()), AppUser::getId, dto.getId()) |
| | | .eq(com.alibaba.nacos.common.utils.StringUtils.isNotBlank(dto.getAppleId()), AppUser::getAppleId, dto.getAppleId()) |
| | | .eq(com.alibaba.nacos.common.utils.StringUtils.isNotBlank(dto.getCellPhone()), AppUser::getCellPhone, |
| | | dto.getCellPhone()) |
| | | .eq(com.alibaba.nacos.common.utils.StringUtils.isNotBlank(dto.getWxOpenId()), AppUser::getWxOpenId, |
| | | dto.getWxOpenId()) |
| | | .ne(AppUser::getUserStatus, AppUserStatusEnum.LOGOUT.getCode()).oneOpt(); |
| | | // 如果不存在 |
| | | if (!appUser.isPresent()){ |
| | | if (one.isPresent()) { |
| | | initUserTree(one.get().getId()); |
| | | this.updateById(one.get()); |
| | | return one; |
| | | } else { |
| | | return this.lambdaQuery() |
| | | .eq(Objects.nonNull(dto.getId()), AppUser::getId, dto.getId()) |
| | | .eq(com.alibaba.nacos.common.utils.StringUtils.isNotBlank(dto.getAppleId()), AppUser::getAppleId, dto.getAppleId()) |
| | | .eq(com.alibaba.nacos.common.utils.StringUtils.isNotBlank(dto.getCellPhone()), AppUser::getCellPhone, |
| | | dto.getCellPhone()) |
| | | .eq(com.alibaba.nacos.common.utils.StringUtils.isNotBlank(dto.getWxOpenId()), AppUser::getWxOpenId, |
| | | dto.getWxOpenId()) |
| | | .ne(AppUser::getUserStatus, AppUserStatusEnum.LOGOUT.getCode()).oneOpt(); |
| | | } |
| | | } |
| | | |
| | | } |
| | | return this.lambdaQuery() |
| | | .eq(Objects.nonNull(dto.getId()), AppUser::getId, dto.getId()) |
| | |
| | | .ne(AppUser::getUserStatus,3).oneOpt(); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * app用户注册 |
| | | * @param appUserDTO |
| | |
| | | */ |
| | | @Override |
| | | public AppUser registerAppUser(AppUserDTO appUserDTO) { |
| | | if (StringUtils.hasLength(appUserDTO.getDevice())){ |
| | | AppUser one = this.lambdaQuery().eq(AppUser::getDevice, appUserDTO.getDevice()) |
| | | .isNull(AppUser::getCellPhone).one(); |
| | | if (one == null){ |
| | | AppUser appUser = BeanUtils.copyBean(appUserDTO, AppUser.class); |
| | | SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss"); |
| | | String format = simpleDateFormat.format(new Date()); |
| | | // 生成四位随机数字 |
| | | String randomCode = String.valueOf((int) ((Math.random() * 9 + 1) * 1000)); |
| | | appUser.setCode("YH"+format+randomCode); |
| | | this.save(appUser); |
| | | remoteMeditationService.addHomeBackgroundMusicDefault(appUser.getId()); |
| | | initUserTree(appUser.getId()); |
| | | return appUser; |
| | | }else{ |
| | | SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss"); |
| | | String format = simpleDateFormat.format(new Date()); |
| | | // 生成四位随机数字 |
| | | String randomCode = String.valueOf((int) ((Math.random() * 9 + 1) * 1000)); |
| | | one.setCode("YH"+format+randomCode); |
| | | this.updateById(one); |
| | | initUserTree(one.getId()); |
| | | return one; |
| | | } |
| | | } |
| | | AppUser appUser = BeanUtils.copyBean(appUserDTO, AppUser.class); |
| | | SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss"); |
| | | String format = simpleDateFormat.format(new Date()); |
| | |
| | | String randomCode = String.valueOf((int) ((Math.random() * 9 + 1) * 1000)); |
| | | appUser.setCode("YH"+format+randomCode); |
| | | this.save(appUser); |
| | | remoteMeditationService.addHomeBackgroundMusicDefault(appUser.getId()); |
| | | |
| | | initUserTree(appUser.getId()); |
| | | return appUser; |
| | | } |
| | |
| | | public AppLoginUser wxLogin(AppWXLoginBody body) { |
| | | AppLoginUser appLoginUser = new AppLoginUser(); |
| | | Optional<AppUser> optionalAppUser = this.getUserByCondition( |
| | | AppUserDTO.builder().wxOpenId(body.getWxOpenId()).build()); |
| | | AppUserDTO.builder().wxOpenId(body.getWxOpenId()).device(body.getDevice()).build()); |
| | | AppUser appUser = new AppUser(); |
| | | SysUser sysUser = new SysUser(); |
| | | // 存在账户,查询关联系统用户 |
| | |
| | | if (appUser.getCellPhone()!=null){ |
| | | appLoginUser.setBindStatus(DisabledEnum.NO.getCode()); |
| | | appLoginUser.setCellPhone(appUser.getCellPhone()); |
| | | }else{ |
| | | appLoginUser.setBindStatus(DisabledEnum.YES.getCode()); |
| | | } |
| | | } else { |
| | | if (org.springframework.util.StringUtils.hasLength(body.getDevice())){ |
| | |
| | | String nickname = "用户" + IdUtil.fastSimpleUUID().substring(0, 6); |
| | | sysUser.setNickName(nickname); |
| | | appUser.setNickname(nickname); |
| | | appUser.setDevice(body.getDevice()); |
| | | appUser.setWxName(body.getNickname()); |
| | | appUser.setAvatar(body.getHeadImgUrl()); |
| | | appUser.setGender(3); |
| | |
| | | appUser.setLevelSettingId(TreeLevelEnum.SEED.getCode()); |
| | | appLoginUser.setBindStatus(DisabledEnum.YES.getCode()); |
| | | this.save(appUser); |
| | | remoteMeditationService.addHomeBackgroundMusicDefault(appUser.getId()); |
| | | |
| | | // 初始化用户树苗 |
| | | initUserTree(appUser.getId()); |
| | | } |
| | |
| | | appUser.setNickname(nickname); |
| | | appUser.setWxName(body.getNickname()); |
| | | appUser.setAvatar(body.getHeadImgUrl()); |
| | | appUser.setDevice(body.getDevice()); |
| | | appUser.setGender(3); |
| | | appUser.setBalance(BigDecimal.ZERO); |
| | | appUser.setSanskritFlag(DisabledEnum.NO.getCode()); |
| | |
| | | appUser.setLevelSettingId(TreeLevelEnum.SEED.getCode()); |
| | | appLoginUser.setBindStatus(DisabledEnum.YES.getCode()); |
| | | this.save(appUser); |
| | | remoteMeditationService.addHomeBackgroundMusicDefault(appUser.getId()); |
| | | |
| | | // 初始化用户树苗 |
| | | initUserTree(appUser.getId()); |
| | | } |
| | |
| | | public AppLoginUser appleLogin(String appleId,String device) { |
| | | AppLoginUser appLoginUser = new AppLoginUser(); |
| | | Optional<AppUser> optionalAppUser = this.getUserByCondition( |
| | | AppUserDTO.builder().appleId(appleId).build()); |
| | | AppUserDTO.builder().appleId(appleId).device(device).build()); |
| | | SysUser sysUser = new SysUser(); |
| | | AppUser appUser = new AppUser(); |
| | | // 存在账户,查询关联系统用户 |
| | |
| | | appUser.setBalance(BigDecimal.ZERO); |
| | | appUser.setIncome(BigDecimal.ZERO); |
| | | appUser.setTotalEnergyValue(0); |
| | | appUser.setDevice(device); |
| | | appUser.setRegisterTime(LocalDateTime.now()); |
| | | appUser.setLevelSettingId(TreeLevelEnum.SEED.getCode()); |
| | | SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss"); |
| | |
| | | String randomCode = String.valueOf((int) ((Math.random() * 9 + 1) * 1000)); |
| | | appUser.setCode("YH" + format + randomCode); |
| | | this.save(appUser); |
| | | remoteMeditationService.addHomeBackgroundMusicDefault(appUser.getId()); |
| | | |
| | | // 初始化用户树苗 |
| | | initUserTree(appUser.getId()); |
| | | } |
| | | }else{ |
| | | // 不存在账户,创建账户 |
| | | // 注册用户信息 |
| | | sysUser = new SysUser(); |
| | | String nickname = "用户" + IdUtil.fastSimpleUUID().substring(0, 6); |
| | | sysUser.setNickName(nickname); |
| | | sysUser.setAvatar("https://xqgwzh.obs.cn-south-1.myhuaweicloud.com/Logo%E7%A1%AE%E8%AE%A4%E7%89%88%281%29.jpg"); |
| | | sysUser.setUserName(nickname); |
| | | sysUser.setUserType("01"); // app用户 |
| | | R<SysUser> registerResult = remoteUserService.registerAppUserInfo(sysUser, |
| | | SecurityConstants.INNER); |
| | | if (registerResult.getCode() == Constants.FAIL) { |
| | | throw new ServiceException(registerResult.getMsg()); |
| | | } |
| | | SysUser sysUserRes = registerResult.getData(); |
| | | appUser = new AppUser(); |
| | | appUser.setAppleId(appleId); |
| | | appUser.setUserId(sysUserRes.getUserId()); |
| | | appUser.setNickname(nickname); |
| | | appUser.setAvatar("https://xqgwzh.obs.cn-south-1.myhuaweicloud.com/Logo%E7%A1%AE%E8%AE%A4%E7%89%88%281%29.jpg"); // TODO 待完善默认头像 |
| | | appUser.setBalance(BigDecimal.ZERO); |
| | | appUser.setSanskritFlag(DisabledEnum.NO.getCode()); |
| | | appUser.setBalance(BigDecimal.ZERO); |
| | | appUser.setIncome(BigDecimal.ZERO); |
| | | appUser.setTotalEnergyValue(0); |
| | | appUser.setDevice(device); |
| | | |
| | | appUser.setRegisterTime(LocalDateTime.now()); |
| | | appUser.setLevelSettingId(TreeLevelEnum.SEED.getCode()); |
| | | SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss"); |
| | | String format = simpleDateFormat.format(new Date()); |
| | | appLoginUser.setBindStatus(DisabledEnum.YES.getCode()); |
| | | // 生成四位随机数字 |
| | | String randomCode = String.valueOf((int) ((Math.random() * 9 + 1) * 1000)); |
| | | appUser.setCode("YH" + format + randomCode); |
| | | this.save(appUser); |
| | | remoteMeditationService.addHomeBackgroundMusicDefault(appUser.getId()); |
| | | |
| | | // 初始化用户树苗 |
| | | initUserTree(appUser.getId()); |
| | | } |
| | | } |
| | | appLoginUser.setUserid(sysUser.getUserId()); |
| | |
| | | public AppLoginUser appCaptchaLogin (AppCaptchaBody body){ |
| | | AppLoginUser appLoginUser = new AppLoginUser(); |
| | | Optional<AppUser> optionalAppUser = this.getUserByCondition( |
| | | AppUserDTO.builder().cellPhone(body.getCellPhone()).build()); |
| | | AppUserDTO.builder().device(body.getDevice()).cellPhone(body.getCellPhone()).build()); |
| | | AppUser appUser = new AppUser(); |
| | | SysUser sysUser = new SysUser(); |
| | | if (optionalAppUser.isPresent()) { |
| | |
| | | String randomCode = String.valueOf((int) ((Math.random() * 9 + 1) * 1000)); |
| | | appUser.setCode("YH" + format + randomCode); |
| | | this.save(appUser); |
| | | remoteMeditationService.addHomeBackgroundMusicDefault(appUser.getId()); |
| | | // 初始化用户树苗 |
| | | initUserTree(appUser.getId()); |
| | | } |
| | |
| | | String randomCode = String.valueOf((int) ((Math.random() * 9 + 1) * 1000)); |
| | | appUser.setCode("YH" + format + randomCode); |
| | | this.save(appUser); |
| | | remoteMeditationService.addHomeBackgroundMusicDefault(appUser.getId()); |
| | | |
| | | // 初始化用户树苗 |
| | | initUserTree(appUser.getId()); |
| | | } |
| | |
| | | * @param appUserId 用户id |
| | | */ |
| | | private void initUserTree(Long appUserId) { |
| | | if (appUserTreeService.lambdaQuery().eq(AppUserTree::getSowAgain,2).eq(AppUserTree::getAppUserId,appUserId).one()!=null){ |
| | | return; |
| | | } |
| | | AppUserTree appUserTree = new AppUserTree(); |
| | | appUserTree.setAppUserId(appUserId); |
| | | appUserTree.setTreeLevelType(TreeLevelEnum.SEED.getCode()); |
| | |
| | | } |
| | | } else { |
| | | Optional<AppUser> userOptional = getAppUserByThirdId(loginType, wxOrAppleId); |
| | | if (loginType.equals(1)) { |
| | | // 微信登录 |
| | | handleUserNotPresent(userOptional, "该用户不存在,请重新进行微信授权登录"); |
| | | } else { |
| | | // 苹果登录 |
| | | handleUserNotPresent(userOptional, "该用户不存在,请重新进行苹果授权登录"); |
| | | if (!userOptional.isPresent()) { |
| | | if (loginType.equals(1)) { |
| | | // 微信登录 |
| | | handleUserNotPresent(userOptional, "该用户不存在,请重新进行微信授权登录"); |
| | | } else { |
| | | // 苹果登录 |
| | | handleUserNotPresent(userOptional, "该用户不存在,请重新进行苹果授权登录"); |
| | | } |
| | | } |
| | | appUser = userOptional.get(); |
| | | appUser.setCellPhone(body.getCellPhone()); |
| | |
| | | // 更新用户信息 |
| | | this.updateById(appUser); |
| | | AppLoginUser appLoginUser = new AppLoginUser(); |
| | | appLoginUser.setAppUserId(appUser.getId()); |
| | | appLoginUser.setBindStatus(1); |
| | | appLoginUser.setCellPhone(body.getCellPhone()); |
| | | appLoginUser.setSysUser(sysUser); |
| | |
| | | if (tokenService.getLoginUser()==null){ |
| | | // 获取当前登录用户 |
| | | if (org.springframework.util.StringUtils.hasLength(dto.getDevice())){ |
| | | SysUser sysUser = new SysUser(); |
| | | AppUser appUser = new AppUser(); |
| | | // 注册用户信息 |
| | | sysUser = new SysUser(); |
| | | String nickname = "用户" + IdUtil.fastSimpleUUID().substring(0, 6); |
| | | sysUser.setNickName(nickname); |
| | | sysUser.setAvatar("https://xqgwzh.obs.cn-south-1.myhuaweicloud.com/Logo%E7%A1%AE%E8%AE%A4%E7%89%88%281%29.jpg"); |
| | | sysUser.setUserName(dto.getDevice()); |
| | | sysUser.setUserType("01"); // app用户 |
| | | // 设置默认密码123456 |
| | | sysUser.setPassword(SecurityUtils.encryptPassword(Constants.DEFAULT_PASSWORD)); |
| | | AppUser one = this.lambdaQuery().eq(AppUser::getDevice, dto.getDevice()) |
| | | .isNull(AppUser::getCellPhone).one(); |
| | | if (one==null){ |
| | | SysUser sysUser = new SysUser(); |
| | | AppUser appUser = new AppUser(); |
| | | // 注册用户信息 |
| | | sysUser = new SysUser(); |
| | | String nickname = "用户" + IdUtil.fastSimpleUUID().substring(0, 6); |
| | | sysUser.setNickName(nickname); |
| | | sysUser.setAvatar("https://xqgwzh.obs.cn-south-1.myhuaweicloud.com/Logo%E7%A1%AE%E8%AE%A4%E7%89%88%281%29.jpg"); |
| | | sysUser.setUserName(nickname); |
| | | sysUser.setUserType("01"); // app用户 |
| | | // 设置默认密码123456 |
| | | sysUser.setPassword(SecurityUtils.encryptPassword(Constants.DEFAULT_PASSWORD)); |
| | | |
| | | R<SysUser> registerResult = remoteUserService.registerAppUserInfo(sysUser, |
| | | SecurityConstants.INNER); |
| | | if (registerResult.getCode() == Constants.FAIL) { |
| | | throw new ServiceException(registerResult.getMsg()); |
| | | } |
| | | SysUser sysUserRes = registerResult.getData(); |
| | | appUser = new AppUser(); |
| | | appUser.setUserId(sysUserRes.getUserId()); |
| | | appUser.setNickname(nickname); |
| | | appUser.setAvatar("https://xqgwzh.obs.cn-south-1.myhuaweicloud.com/Logo%E7%A1%AE%E8%AE%A4%E7%89%88%281%29.jpg"); // TODO 待完善默认头像 |
| | | appUser.setBalance(BigDecimal.ZERO); |
| | | appUser.setSanskritFlag(DisabledEnum.NO.getCode()); |
| | | appUser.setBalance(BigDecimal.ZERO); |
| | | appUser.setIncome(BigDecimal.ZERO); |
| | | appUser.setTotalEnergyValue(0); |
| | | appUser.setRegisterTime(LocalDateTime.now()); |
| | | appUser.setLevelSettingId(TreeLevelEnum.SEED.getCode()); |
| | | SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss"); |
| | | String format = simpleDateFormat.format(new Date()); |
| | | // 生成四位随机数字 |
| | | String randomCode = String.valueOf((int) ((Math.random() * 9 + 1) * 1000)); |
| | | appUser.setCode("YH"+format+randomCode); |
| | | this.save(appUser); |
| | | R<SysUser> registerResult = remoteUserService.registerAppUserInfo(sysUser, |
| | | SecurityConstants.INNER); |
| | | if (registerResult.getCode() == Constants.FAIL) { |
| | | throw new ServiceException(registerResult.getMsg()); |
| | | } |
| | | SysUser sysUserRes = registerResult.getData(); |
| | | appUser = new AppUser(); |
| | | appUser.setUserId(sysUserRes.getUserId()); |
| | | appUser.setNickname(nickname); |
| | | appUser.setAvatar("https://xqgwzh.obs.cn-south-1.myhuaweicloud.com/Logo%E7%A1%AE%E8%AE%A4%E7%89%88%281%29.jpg"); // TODO 待完善默认头像 |
| | | appUser.setBalance(BigDecimal.ZERO); |
| | | appUser.setSanskritFlag(DisabledEnum.NO.getCode()); |
| | | appUser.setBalance(BigDecimal.ZERO); |
| | | appUser.setIncome(BigDecimal.ZERO); |
| | | appUser.setTotalEnergyValue(0); |
| | | appUser.setRegisterTime(LocalDateTime.now()); |
| | | appUser.setLevelSettingId(TreeLevelEnum.SEED.getCode()); |
| | | appUser.setDevice(dto.getDevice()); |
| | | SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss"); |
| | | String format = simpleDateFormat.format(new Date()); |
| | | // 生成四位随机数字 |
| | | String randomCode = String.valueOf((int) ((Math.random() * 9 + 1) * 1000)); |
| | | appUser.setCode("YH"+format+randomCode); |
| | | this.save(appUser); |
| | | Long userId = appUser.getId(); |
| | | List<AppUserQuestion> appUserQuestionList = BeanUtils.copyList( |
| | | dto.getUserAnswerOneDTOList(), AppUserQuestion.class); |
| | |
| | | || appUserQuestion.getAnswer().equals("3")).collect(Collectors.toList()); |
| | | appUser.setTagId(dto.getTagIds()); |
| | | this.updateById(appUser); |
| | | }else{ |
| | | List<AppUserQuestion> appUserQuestionList = BeanUtils.copyList( |
| | | dto.getUserAnswerOneDTOList(), AppUserQuestion.class); |
| | | // 查询用户已填写的答案 |
| | | // 删除之前答案 |
| | | appUserQuestionService.lambdaUpdate().eq(AppUserQuestion::getAppUserId,one.getId()).remove(); |
| | | |
| | | // 根据类型更新答案 |
| | | for (AppUserQuestion appUserQuestion : appUserQuestionList) { |
| | | appUserQuestion.setAppUserId(one.getId()); |
| | | } |
| | | appUserQuestionService.saveBatch(appUserQuestionList); |
| | | // 筛选答案为是和偶尔有的问题,为用户设置对应的标签 |
| | | List<AppUserQuestion> appUserQuestionYesList = appUserQuestionList.stream() |
| | | .filter(appUserQuestion -> appUserQuestion.getAnswer().equals("1") |
| | | || appUserQuestion.getAnswer().equals("3")).collect(Collectors.toList()); |
| | | one.setTagId(dto.getTagIds()); |
| | | this.updateById(one); |
| | | } |
| | | |
| | | } |
| | | }else{ |
| | | Long userId = tokenService.getLoginUser().getUserid(); |
| | |
| | | appUser.setTagId(dto.getTagIds()); |
| | | this.updateById(appUser); |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | /** |