|
|
@@ -74,6 +74,8 @@ public class StoreUserServiceImpl extends ServiceImpl<StoreUserMapper, StoreUser
|
|
|
|
|
|
private final LifeMessageMapper lifeMessageMapper;
|
|
|
|
|
|
+ private final StorePlatformUserRoleMapper storePlatformUserRoleMapper;
|
|
|
+
|
|
|
private final NearMeService nearMeService;
|
|
|
|
|
|
private final AliOSSUtil aliOSSUtil;
|
|
|
@@ -404,22 +406,93 @@ public class StoreUserServiceImpl extends ServiceImpl<StoreUserMapper, StoreUser
|
|
|
|
|
|
IPage<StoreUser> page = new Page<>(pageNum, pageSize);
|
|
|
IPage<StoreUserVo> storeUserVoIPage = new Page<>();
|
|
|
-
|
|
|
// 查询子账号(accountType == 2)
|
|
|
if (accountType == 2) {
|
|
|
// 构建子账号查询条件
|
|
|
LambdaQueryWrapper<StoreUser> subAccountWrapper = new LambdaQueryWrapper<>();
|
|
|
subAccountWrapper.eq(StoreUser::getAccountType, 2) // 子账号类型
|
|
|
- .like(!StringUtils.isEmpty(id), StoreUser::getId, id)
|
|
|
- .and(StringUtils.isNotEmpty(phone), qw -> qw
|
|
|
- .like(StoreUser::getPhone, phone) // 子账号手机号模糊匹配
|
|
|
- .or()
|
|
|
- .exists("SELECT 1 FROM store_user su WHERE su.id = " +
|
|
|
- "store_user.sub_account_id AND su.phone LIKE CONCAT('%', '" + phone + "', '%')") // 主账号手机号模糊匹配
|
|
|
- )
|
|
|
- .eq(status != null, StoreUser::getStatus, status)
|
|
|
- .orderByDesc(StoreUser::getCreatedTime);
|
|
|
-
|
|
|
+ .eq(status != null, StoreUser::getStatus, status);
|
|
|
+
|
|
|
+ // 先通过中间表storePlatformUserRole获取所有子账号的userId列表
|
|
|
+ LambdaQueryWrapper<StorePlatformUserRole> roleWrapper = new LambdaQueryWrapper<>();
|
|
|
+ List<StorePlatformUserRole> userRoles = storePlatformUserRoleMapper.selectList(roleWrapper);
|
|
|
+ List<Integer> subAccountUserIds = null;
|
|
|
+ if (!CollectionUtils.isEmpty(userRoles)) {
|
|
|
+ // 提取所有在中间表中的子账号userId
|
|
|
+ subAccountUserIds = userRoles.stream()
|
|
|
+ .map(StorePlatformUserRole::getUserId)
|
|
|
+ .distinct()
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 当id不为空时,通过中间表storePlatformUserRole判断是否为子账号(必须是子账号)
|
|
|
+ if (StringUtils.isNotEmpty(id)) {
|
|
|
+ Integer parsedId = safeParseInt(id);
|
|
|
+ if (parsedId != null) {
|
|
|
+ // 必须通过中间表判断,只有存在中间表中的才是子账号
|
|
|
+ if (subAccountUserIds != null && subAccountUserIds.contains(parsedId)) {
|
|
|
+ // 如果在中间表中存在,说明是子账号,添加ID条件
|
|
|
+ subAccountWrapper.eq(StoreUser::getId, parsedId);
|
|
|
+ } else {
|
|
|
+ // 如果不在中间表中,添加一个无法匹配的条件,避免查询到非子账号
|
|
|
+ subAccountWrapper.eq(StoreUser::getId, -1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 当phone不为空时,对子账号和主账号电话进行模糊查询,并关联storePlatformUserRole
|
|
|
+ if (StringUtils.isNotEmpty(phone)) {
|
|
|
+ if (subAccountUserIds != null && !subAccountUserIds.isEmpty()) {
|
|
|
+ // 先查询主账号phone匹配的主账号ID列表
|
|
|
+ LambdaQueryWrapper<StoreUser> mainAccountWrapper = new LambdaQueryWrapper<>();
|
|
|
+ mainAccountWrapper.eq(StoreUser::getAccountType, 1)
|
|
|
+ .like(StoreUser::getPhone, phone);
|
|
|
+ List<StoreUser> mainAccounts = storeUserMapper.selectList(mainAccountWrapper);
|
|
|
+ List<Integer> mainAccountIds = mainAccounts.stream()
|
|
|
+ .map(StoreUser::getId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 限制查询范围:只查询在中间表中存在的子账号
|
|
|
+ subAccountWrapper.in(StoreUser::getId, subAccountUserIds);
|
|
|
+ // 查询条件:在中间表范围内的子账号中,子账号phone匹配 OR 主账号phone匹配
|
|
|
+ subAccountWrapper.and(wrapper -> {
|
|
|
+ // 子账号本身的phone模糊查询
|
|
|
+ wrapper.like(StoreUser::getPhone, phone);
|
|
|
+ // 或者主账号phone匹配(通过subAccountId关联到主账号)
|
|
|
+ if (!CollectionUtils.isEmpty(mainAccountIds)) {
|
|
|
+ wrapper.or().in(StoreUser::getSubAccountId, mainAccountIds);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ // 如果没有中间表数据,先查询主账号phone匹配的主账号ID
|
|
|
+ LambdaQueryWrapper<StoreUser> mainAccountWrapper = new LambdaQueryWrapper<>();
|
|
|
+ mainAccountWrapper.eq(StoreUser::getAccountType, 1)
|
|
|
+ .like(StoreUser::getPhone, phone);
|
|
|
+ List<StoreUser> mainAccounts = storeUserMapper.selectList(mainAccountWrapper);
|
|
|
+ List<Integer> mainAccountIds = mainAccounts.stream()
|
|
|
+ .map(StoreUser::getId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 查询条件:子账号phone匹配 OR 主账号phone匹配
|
|
|
+ if (!CollectionUtils.isEmpty(mainAccountIds)) {
|
|
|
+ subAccountWrapper.and(wrapper -> {
|
|
|
+ wrapper.like(StoreUser::getPhone, phone)
|
|
|
+ .or().in(StoreUser::getSubAccountId, mainAccountIds);
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ // 如果没有主账号匹配,只查询子账号phone
|
|
|
+ subAccountWrapper.like(StoreUser::getPhone, phone);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // phone为空时,如果中间表有数据,限制只查询中间表中的子账号
|
|
|
+ if (subAccountUserIds != null && !subAccountUserIds.isEmpty()) {
|
|
|
+ subAccountWrapper.in(StoreUser::getId, subAccountUserIds);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ subAccountWrapper.orderByDesc(StoreUser::getCreatedTime);
|
|
|
+
|
|
|
IPage<StoreUser> subAccountsPage = storeUserMapper.selectPage(page, subAccountWrapper);
|
|
|
BeanUtils.copyProperties(subAccountsPage, storeUserVoIPage);
|
|
|
|