| | |
| | | import com.ruoyi.im.dto.RegisterDto; |
| | | import com.ruoyi.im.out.UserAccountOut; |
| | | import com.ruoyi.im.service.ImApiServcie; |
| | | import com.ruoyi.im.service.UserKycService; |
| | | import com.ruoyi.im.util.ConverterUtil; |
| | | import com.ruoyi.im.util.PhoneNumberValidatorUtil; |
| | | import com.ruoyi.im.util.SymmetricCryptoUtil; |
| | | import com.ruoyi.system.domain.UserAccount; |
| | | import com.ruoyi.system.domain.UserKyc; |
| | | import com.ruoyi.system.domain.vo.UserAccountUpdateVo; |
| | | import com.ruoyi.system.domain.vo.UserAccountVo; |
| | | import com.ruoyi.system.service.UserAccountService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | |
| | | @Autowired |
| | | private ImApiServcie imApiServcie; |
| | | |
| | | @Autowired |
| | | private UserKycService userKycService; |
| | | |
| | | /** |
| | | * 获取会员列表 |
| | | */ |
| | |
| | | // 创建查询条件包装器 |
| | | LambdaQueryWrapper<UserAccount> queryWrapper = new LambdaQueryWrapper<>(); |
| | | |
| | | // 只有当 keyword 不为空时才添加 OR 条件 |
| | | if (ObjectUtil.isNotEmpty(vo.getKeywords())) { |
| | | String keywords = vo.getKeywords().trim(); |
| | | if (StringUtils.isNotEmpty(keywords)) { |
| | | queryWrapper.and(wrapper -> wrapper |
| | | .eq(UserAccount::getId, vo.getKeywords()) |
| | | .eq(UserAccount::getInvitationCode, keywords) |
| | | .or() |
| | | .like(UserAccount::getPhoneNumber, vo.getKeywords()) |
| | | // 使用右模糊匹配,可以利用索引 |
| | | .likeRight(UserAccount::getPhoneNumber, keywords) |
| | | .or() |
| | | .like(UserAccount::getAccount, vo.getKeywords()) |
| | | .likeRight(UserAccount::getAccount, keywords) |
| | | .or() |
| | | .like(UserAccount::getNickname, vo.getKeywords()) |
| | | .likeRight(UserAccount::getNickname, keywords) |
| | | ); |
| | | } |
| | | } |
| | | |
| | | // 添加其他条件 |
| | |
| | | queryWrapper.orderByDesc(UserAccount::getCreateTime); |
| | | startPage(); |
| | | List<UserAccount> list = userAccountService.list(queryWrapper); |
| | | |
| | | List<Integer> idList = list.stream() |
| | | .map(UserAccount::getId) |
| | | .collect(Collectors.toList()); |
| | | if(!CollectionUtils.isEmpty(idList)){ |
| | | List<UserKyc> kycList = userKycService.list(new LambdaQueryWrapper<UserKyc>() |
| | | .in(UserKyc::getUserId, idList) |
| | | ); |
| | | |
| | | Map<Integer, UserKyc> kycMap = kycList.stream() |
| | | .collect(Collectors.toMap(UserKyc::getUserId, kyc -> kyc)); |
| | | |
| | | list.forEach(f->{ |
| | | if(ObjectUtil.isNotEmpty(kycMap.get(f.getId()))){ |
| | | f.setName(kycMap.get(f.getId()).getName()); |
| | | f.setIdCard(kycMap.get(f.getId()).getIdCard()); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | PageInfo<UserAccount> pageInfo = new PageInfo<>(list); |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 加载当前层级的直接下级用户 |
| | | * @param userAccountOuts 当前层级的用户列表 |
| | | */ |
| | | private void loadCurrentLevelSubordinates(List<UserAccountOut> userAccountOuts) { |
| | | if (ObjectUtil.isEmpty(userAccountOuts)) { |
| | | return; |
| | |
| | | .collect(Collectors.toList()); |
| | | |
| | | if (accounts.isEmpty()) { |
| | | // 如果没有账号,为所有用户设置空列表 |
| | | userAccountOuts.forEach(user -> user.setSubordinateList(new ArrayList<>())); |
| | | return; |
| | | } |
| | |
| | | |
| | | // 转换为输出对象 |
| | | List<UserAccountOut> allSubordinateOuts = ConverterUtil.convertToList(allSubordinates, UserAccountOut.class); |
| | | |
| | | // 收集所有需要设置 KYC 的用户(当前层级 + 下级) |
| | | List<UserAccountOut> allUsers = new ArrayList<>(); |
| | | allUsers.addAll(userAccountOuts); |
| | | allUsers.addAll(allSubordinateOuts); |
| | | |
| | | // 一次性设置所有用户的 KYC 信息 |
| | | setKycInfoForUsers(allUsers); |
| | | |
| | | // 按邀请人账号分组 |
| | | Map<String, List<UserAccountOut>> subordinateMap = allSubordinateOuts.stream() |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 为用户列表设置 KYC 信息 |
| | | */ |
| | | private void setKycInfoForUsers(List<UserAccountOut> users) { |
| | | if (ObjectUtil.isEmpty(users)) { |
| | | return; |
| | | } |
| | | |
| | | // 收集用户ID |
| | | List<Integer> idList = users.stream() |
| | | .map(UserAccountOut::getId) |
| | | .filter(ObjectUtil::isNotEmpty) |
| | | .collect(Collectors.toList()); |
| | | |
| | | if (idList.isEmpty()) { |
| | | return; |
| | | } |
| | | |
| | | // 批量查询 KYC 信息 |
| | | List<UserKyc> kycList = userKycService.list(new LambdaQueryWrapper<UserKyc>() |
| | | .in(UserKyc::getUserId, idList) |
| | | ); |
| | | |
| | | // 转换为 Map |
| | | Map<Integer, UserKyc> kycMap = kycList.stream() |
| | | .collect(Collectors.toMap(UserKyc::getUserId, kyc -> kyc, (existing, replacement) -> existing)); |
| | | |
| | | // 设置 KYC 信息 |
| | | users.forEach(user -> { |
| | | if (ObjectUtil.isNotEmpty(user.getId()) && ObjectUtil.isNotEmpty(kycMap.get(user.getId()))) { |
| | | UserKyc kyc = kycMap.get(user.getId()); |
| | | user.setName(kyc.getName()); |
| | | user.setIdCard(kyc.getIdCard()); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * 获取用户的下级树形结构 |