| | |
| | | import cn.hutool.core.util.IdUtil; |
| | | import cn.hutool.crypto.SecureUtil; |
| | | import com.alibaba.nacos.common.utils.StringUtils; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.xinquan.common.core.constant.Constants; |
| | |
| | | import com.xinquan.common.core.exception.ServiceException; |
| | | import com.xinquan.common.core.utils.page.BeanUtils; |
| | | 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.system.api.RemoteUserService; |
| | | import com.xinquan.system.api.domain.SysUser; |
| | | import com.xinquan.system.api.feignClient.SysUserClient; |
| | | import com.xinquan.system.api.model.AppCaptchaBody; |
| | | import com.xinquan.system.api.model.AppLoginUser; |
| | | import com.xinquan.system.api.model.AppVerifyCellPhoneBody; |
| | | import com.xinquan.system.api.model.AppWXLoginBody; |
| | | import com.xinquan.system.api.model.*; |
| | | import com.xinquan.system.api.domain.AppUser; |
| | | import com.xinquan.user.api.domain.dto.AppUserDTO; |
| | | import com.xinquan.system.api.domain.AppUserQuestion; |
| | |
| | | import com.xinquan.user.service.AppUserTreeService; |
| | | import com.xinquan.user.service.TagService; |
| | | import java.math.BigDecimal; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.LocalDateTime; |
| | | import java.util.List; |
| | | import java.util.Locale; |
| | | import java.util.Objects; |
| | | import java.util.Optional; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | |
| | | .ne(AppUser::getUserStatus, AppUserStatusEnum.LOGOUT.getCode()).oneOpt(); |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | String randomCode = String.valueOf((int) ((Math.random() * 9 + 1) * 1000)); |
| | | System.err.println(randomCode); |
| | | } |
| | | /** |
| | | * app用户注册 |
| | | * @param appUserDTO |
| | |
| | | @Override |
| | | public AppUser registerAppUser(AppUserDTO appUserDTO) { |
| | | 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); |
| | | return appUser; |
| | | } |
| | |
| | | SysUser sysUserRes = registerResult.getData(); |
| | | appUser = new AppUser(); |
| | | appUser.setUserId(sysUserRes.getUserId()); |
| | | 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); |
| | | appUser.setWxOpenId(body.getWxOpenId()); |
| | | appUser.setNickname(body.getNickname()); |
| | | String nickname = "用户" + IdUtil.fastSimpleUUID().substring(0, 6); |
| | | sysUser.setNickName(nickname); |
| | | appUser.setAvatar(body.getHeadImgUrl()); |
| | | appUser.setGender(body.getSex()); |
| | | appUser.setBalance(BigDecimal.ZERO); |
| | |
| | | } |
| | | SysUser sysUserRes = registerResult.getData(); |
| | | appUser = new AppUser(); |
| | | appUser.setAppleId(appleId); |
| | | appUser.setUserId(sysUserRes.getUserId()); |
| | | appUser.setNickname(nickname); |
| | | appUser.setAvatar("qwer"); // TODO 待完善默认头像 |
| | |
| | | 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); |
| | | // 初始化用户树苗 |
| | | initUserTree(appUser.getId()); |
| | |
| | | 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); |
| | | // 初始化用户树苗 |
| | | initUserTree(appUser.getId()); |
| | |
| | | // 如果存在 更新wxOpenId 或appleId |
| | | if (baseOptionalAppUser.isPresent()) { |
| | | appUser = baseOptionalAppUser.get(); |
| | | switch (body.getLoginType()){ |
| | | case 1: |
| | | this.remove(new LambdaQueryWrapper<AppUser>() |
| | | .eq(AppUser::getWxOpenId,body.getWxOrAppleId()) |
| | | .ne(AppUser::getId,appUser.getId())); |
| | | break; |
| | | case 2: |
| | | this.remove(new LambdaQueryWrapper<AppUser>() |
| | | .eq(AppUser::getAppleId,body.getWxOrAppleId()) |
| | | .ne(AppUser::getId,appUser.getId())); |
| | | break; |
| | | } |
| | | |
| | | if (loginType.equals(1)) { |
| | | appUser.setWxOpenId(wxOrAppleId); |
| | | } else { |
| | | appUser.setAppleId(wxOrAppleId); |
| | | } |
| | | appUser.setEmail(body.getEmail()); |
| | | appUser.setNickname(body.getName()); |
| | | // 查询系统用户 |
| | | sysUser = sysUserClient.getSysUser(appUser.getUserId()).getData(); |
| | | if (Objects.isNull(sysUser)) { |
| | |
| | | } |
| | | } else { |
| | | Optional<AppUser> userOptional = getAppUserByThirdId(loginType, wxOrAppleId); |
| | | |
| | | if (loginType.equals(1)) { |
| | | // 微信登录 |
| | | handleUserNotPresent(userOptional, "该用户不存在,请重新进行微信授权登录"); |
| | |
| | | } |
| | | appUser = userOptional.get(); |
| | | appUser.setCellPhone(body.getCellPhone()); |
| | | appUser.setEmail(body.getEmail()); |
| | | appUser.setNickname(body.getName()); |
| | | // 更新系统用户 |
| | | sysUser = sysUserClient.getSysUser(appUser.getUserId()).getData(); |
| | | if (Objects.isNull(sysUser)) { |
| | |
| | | @Override |
| | | public void saveUserAnswers(UserAnswerDTO dto) { |
| | | // 获取当前登录用户 |
| | | Long userId = SecurityUtils.getUserId(); |
| | | AppUser appUser = this.getUserBySysUserId(userId); |
| | | Long userId = tokenService.getLoginUser().getUserid(); |
| | | AppUser appUser = this.getById(userId); |
| | | List<AppUserQuestion> appUserQuestionList = BeanUtils.copyList( |
| | | dto.getUserAnswerOneDTOList(), AppUserQuestion.class); |
| | | // 查询用户已填写的答案 |
| | |
| | | if (CollUtils.isNotEmpty(baseAppUserQuestionList)) { |
| | | // 根据类型更新答案 |
| | | for (AppUserQuestion appUserQuestion : appUserQuestionList) { |
| | | |
| | | Optional<AppUserQuestion> baseAppUserQuestionOptional = baseAppUserQuestionList.stream() |
| | | .filter(baseAppUserQuestion -> baseAppUserQuestion.getType() |
| | | .equals(appUserQuestion.getType())).findFirst(); |
| | | baseAppUserQuestionOptional.ifPresent( |
| | | userQuestion -> appUserQuestion.setId(userQuestion.getId())); |
| | | appUserQuestion.setAppUserId(userId); |
| | | } |
| | | } |
| | | for (AppUserQuestion appUserQuestion : appUserQuestionList) { |
| | | appUserQuestion.setAppUserId(userId); |
| | | } |
| | | appUserQuestionService.saveOrUpdateBatch(appUserQuestionList); |
| | | // 筛选答案为是和偶尔有的问题,为用户设置对应的标签 |
| | |
| | | // 使用 StringBuilder 提高字符串拼接效率 |
| | | if (CollUtils.isNotEmpty(appUserQuestionYesList)) { |
| | | List<Long> tagIdList = appUserQuestionYesList.stream() |
| | | .map(appUserQuestion -> AnswerTagEnum.getEnumByCode(appUserQuestion.getType()) |
| | | .map(appUserQuestion -> Objects.requireNonNull(AnswerTagEnum.getEnumByCode(appUserQuestion.getType())) |
| | | .getTagId()).collect(Collectors.toList()); |
| | | if (CollUtils.isNotEmpty(tagIdList)) { |
| | | sb.append(CollUtils.join(tagIdList, ",")); |
| | |
| | | this.updateById(appUser); |
| | | } |
| | | |
| | | @Autowired |
| | | private TokenService tokenService; |
| | | /** |
| | | * 获取当前登录用户信息 |
| | | * |
| | |
| | | */ |
| | | @Override |
| | | public AppUserVO getCurrentUser() { |
| | | AppUser appUser = this.getById(SecurityUtils.getUserId()); |
| | | LoginUser loginUser = tokenService.getLoginUser(); |
| | | |
| | | Long userId = loginUser.getUserid(); |
| | | AppUser appUser = this.getById(userId); |
| | | return BeanUtils.copyBean(appUser, AppUserVO.class); |
| | | } |
| | | } |