|
@@ -252,12 +252,10 @@ public class StoreUserServiceImpl extends ServiceImpl<StoreUserMapper, StoreUser
|
|
|
public Map<String, String> changePhoneVerification(String phone, String oldPassword, String verificationCode) {
|
|
public Map<String, String> changePhoneVerification(String phone, String oldPassword, String verificationCode) {
|
|
|
Map<String, String> changePhoneMap = new HashMap<>();
|
|
Map<String, String> changePhoneMap = new HashMap<>();
|
|
|
if (oldPassword != null && !oldPassword.equals("")) {
|
|
if (oldPassword != null && !oldPassword.equals("")) {
|
|
|
- LambdaQueryWrapper<StoreUser> userLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
- userLambdaQueryWrapper.eq(StoreUser::getPhone, phone);
|
|
|
|
|
- StoreUser storeUser = this.getOne(userLambdaQueryWrapper);
|
|
|
|
|
- // 由于password字段使用了EncryptTypeHandler,查询时密码会被自动解密
|
|
|
|
|
- // 所以这里直接比较解密后的密码和用户输入的明文密码
|
|
|
|
|
- if (storeUser != null && storeUser.getPassword() != null && storeUser.getPassword().equals(oldPassword)) {
|
|
|
|
|
|
|
+ LambdaUpdateWrapper<StoreUser> userLambdaUpdateWrapper = new LambdaUpdateWrapper<>();
|
|
|
|
|
+ userLambdaUpdateWrapper.eq(StoreUser::getPhone, phone);
|
|
|
|
|
+ StoreUser storeUser = this.getOne(userLambdaUpdateWrapper);
|
|
|
|
|
+ if (storeUser.getPassword().equals(oldPassword)) {
|
|
|
changePhoneMap.put("passwordStatus", "1");
|
|
changePhoneMap.put("passwordStatus", "1");
|
|
|
return changePhoneMap;
|
|
return changePhoneMap;
|
|
|
} else {
|
|
} else {
|
|
@@ -271,7 +269,7 @@ public class StoreUserServiceImpl extends ServiceImpl<StoreUserMapper, StoreUser
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void passwordVerification(String phone, String password, String newPassword, String confirmNewPassword) {
|
|
private void passwordVerification(String phone, String password, String newPassword, String confirmNewPassword) {
|
|
|
- LambdaUpdateWrapper<StoreUser> wrapperFans = new LambdaUpdateWrapper<>();
|
|
|
|
|
|
|
+ LambdaQueryWrapper<StoreUser> wrapperFans = new LambdaQueryWrapper<>();
|
|
|
wrapperFans.eq(StoreUser::getPhone, phone);
|
|
wrapperFans.eq(StoreUser::getPhone, phone);
|
|
|
StoreUser storeUser = this.getOne(wrapperFans);
|
|
StoreUser storeUser = this.getOne(wrapperFans);
|
|
|
if (!newPassword.equals(confirmNewPassword)) {
|
|
if (!newPassword.equals(confirmNewPassword)) {
|
|
@@ -282,9 +280,10 @@ public class StoreUserServiceImpl extends ServiceImpl<StoreUserMapper, StoreUser
|
|
|
log.info("该手机号没有注册过账户");
|
|
log.info("该手机号没有注册过账户");
|
|
|
throw new RuntimeException("该手机号没有注册过账户");
|
|
throw new RuntimeException("该手机号没有注册过账户");
|
|
|
} else {
|
|
} else {
|
|
|
- wrapperFans.eq(StoreUser::getPassword, password);
|
|
|
|
|
- StoreUser storeUserPw = this.getOne(wrapperFans);
|
|
|
|
|
- if (storeUserPw == null || storeUserPw.getPassword().equals("")) {
|
|
|
|
|
|
|
+ // 由于password字段使用了EncryptTypeHandler,查询时密码会被自动解密
|
|
|
|
|
+ // 所以这里直接比较解密后的密码和用户输入的明文密码
|
|
|
|
|
+ String dbPassword = storeUser.getPassword();
|
|
|
|
|
+ if (dbPassword == null || dbPassword.isEmpty() || !dbPassword.equals(password)) {
|
|
|
log.info("原密码错误");
|
|
log.info("原密码错误");
|
|
|
throw new RuntimeException("原密码错误");
|
|
throw new RuntimeException("原密码错误");
|
|
|
}
|
|
}
|
|
@@ -403,7 +402,6 @@ public class StoreUserServiceImpl extends ServiceImpl<StoreUserMapper, StoreUser
|
|
|
return R.data(vo);
|
|
return R.data(vo);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public R<IPage<StoreUserVo>> getStoreUserList(int pageNum, int pageSize, String id, String phone, Integer status, Integer accountType, String mainAccountId, String mainAccountPhone) {
|
|
public R<IPage<StoreUserVo>> getStoreUserList(int pageNum, int pageSize, String id, String phone, Integer status, Integer accountType, String mainAccountId, String mainAccountPhone) {
|
|
|
IPage<StoreUser> page = new Page<>(pageNum, pageSize);
|
|
IPage<StoreUser> page = new Page<>(pageNum, pageSize);
|
|
@@ -455,17 +453,57 @@ public class StoreUserServiceImpl extends ServiceImpl<StoreUserMapper, StoreUser
|
|
|
return R.data(storeUserVoIPage);
|
|
return R.data(storeUserVoIPage);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // 按 (userId, role_id) 去重,同一用户同一角色只保留一条(保留 id 最小的一条)
|
|
|
|
|
+ userRoles = userRoles.stream()
|
|
|
|
|
+ .sorted(Comparator.comparing(StorePlatformUserRole::getId, Comparator.nullsLast(Comparator.naturalOrder())))
|
|
|
|
|
+ .collect(Collectors.toMap(
|
|
|
|
|
+ r -> (r.getUserId() != null ? r.getUserId() : 0) + "_" + (r.getRoleId() != null ? r.getRoleId() : ""),
|
|
|
|
|
+ r -> r,
|
|
|
|
|
+ (a, b) -> a
|
|
|
|
|
+ ))
|
|
|
|
|
+ .values().stream()
|
|
|
|
|
+ .sorted(Comparator.comparing(StorePlatformUserRole::getId, Comparator.nullsLast(Comparator.naturalOrder())))
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+
|
|
|
// 按子账号 id/phone/status 过滤:批量查 store_user,只保留对应子账号满足条件的 role
|
|
// 按子账号 id/phone/status 过滤:批量查 store_user,只保留对应子账号满足条件的 role
|
|
|
List<Integer> distinctUserIds = userRoles.stream().map(StorePlatformUserRole::getUserId).filter(Objects::nonNull).distinct().collect(Collectors.toList());
|
|
List<Integer> distinctUserIds = userRoles.stream().map(StorePlatformUserRole::getUserId).filter(Objects::nonNull).distinct().collect(Collectors.toList());
|
|
|
List<StoreUser> subAccountList = distinctUserIds.isEmpty() ? Collections.emptyList() : storeUserMapper.selectBatchIds(distinctUserIds);
|
|
List<StoreUser> subAccountList = distinctUserIds.isEmpty() ? Collections.emptyList() : storeUserMapper.selectBatchIds(distinctUserIds);
|
|
|
- Map<Integer, StoreUser> subAccountMap = subAccountList == null ? new HashMap<>() : subAccountList.stream().filter(u -> u.getDeleteFlag() != null && u.getDeleteFlag() == 0).collect(Collectors.toMap(StoreUser::getId, u -> u, (a, b) -> a));
|
|
|
|
|
|
|
+ // 根据 status 参数决定子账号池:选「注销中/已注销」时只保留对应状态;否则排除注销中、已注销
|
|
|
|
|
+ Map<Integer, StoreUser> subAccountMap;
|
|
|
|
|
+ if (status != null && (status == -1 || status == 2)) {
|
|
|
|
|
+ final int filterStatus = status;
|
|
|
|
|
+ subAccountMap = subAccountList == null ? new HashMap<>() : subAccountList.stream()
|
|
|
|
|
+ .filter(u -> u.getDeleteFlag() != null && u.getDeleteFlag() == 0)
|
|
|
|
|
+ .filter(u -> {
|
|
|
|
|
+ if (filterStatus == -1) return u.getStatus() != null && u.getStatus() == -1;
|
|
|
|
|
+ return (u.getStatus() != null && u.getStatus() == 2) || (u.getLogoutFlag() != null && u.getLogoutFlag() == 1);
|
|
|
|
|
+ })
|
|
|
|
|
+ .collect(Collectors.toMap(StoreUser::getId, u -> u, (a, b) -> a));
|
|
|
|
|
+ } else {
|
|
|
|
|
+ subAccountMap = subAccountList == null ? new HashMap<>() : subAccountList.stream()
|
|
|
|
|
+ .filter(u -> u.getDeleteFlag() != null && u.getDeleteFlag() == 0
|
|
|
|
|
+ && (u.getLogoutFlag() == null || u.getLogoutFlag() == 0)
|
|
|
|
|
+ && (u.getStatus() == null || (u.getStatus() != -1 && u.getStatus() != 2)))
|
|
|
|
|
+ .collect(Collectors.toMap(StoreUser::getId, u -> u, (a, b) -> a));
|
|
|
|
|
+ }
|
|
|
List<StorePlatformUserRole> filteredRoles = new ArrayList<>();
|
|
List<StorePlatformUserRole> filteredRoles = new ArrayList<>();
|
|
|
for (StorePlatformUserRole role : userRoles) {
|
|
for (StorePlatformUserRole role : userRoles) {
|
|
|
StoreUser subAccount = subAccountMap.get(role.getUserId());
|
|
StoreUser subAccount = subAccountMap.get(role.getUserId());
|
|
|
if (subAccount == null) continue;
|
|
if (subAccount == null) continue;
|
|
|
- if (StringUtils.isNotEmpty(id) && (subAccount.getId() == null || !String.valueOf(subAccount.getId()).contains(id))) continue;
|
|
|
|
|
- if (StringUtils.isNotEmpty(phone) && (subAccount.getPhone() == null || !subAccount.getPhone().contains(phone))) continue;
|
|
|
|
|
- if (status != null && !status.equals(subAccount.getStatus())) continue;
|
|
|
|
|
|
|
+ if (StringUtils.isNotEmpty(id) && (subAccount.getId() == null || !String.valueOf(subAccount.getId()).contains(id)))
|
|
|
|
|
+ continue;
|
|
|
|
|
+ if (StringUtils.isNotEmpty(phone) && (subAccount.getPhone() == null || !subAccount.getPhone().contains(phone)))
|
|
|
|
|
+ continue;
|
|
|
|
|
+ // 状态筛选:选「注销中/已注销」时以 store_user 为准(已由 subAccountMap 限定);否则以 role.status 为准
|
|
|
|
|
+ int rowStatus;
|
|
|
|
|
+ if (status != null && (status == -1 || status == 2)) {
|
|
|
|
|
+ rowStatus = (subAccount.getStatus() != null && subAccount.getStatus() == -1) ? -1
|
|
|
|
|
+ : ((subAccount.getStatus() != null && subAccount.getStatus() == 2) || (subAccount.getLogoutFlag() != null && subAccount.getLogoutFlag() == 1)) ? 2
|
|
|
|
|
+ : (subAccount.getStatus() != null ? subAccount.getStatus() : 0);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ rowStatus = role.getStatus() != null ? role.getStatus() : (subAccount.getStatus() != null ? subAccount.getStatus() : 0);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (status != null && !status.equals(rowStatus)) continue;
|
|
|
filteredRoles.add(role);
|
|
filteredRoles.add(role);
|
|
|
}
|
|
}
|
|
|
filteredRoles.sort(Comparator.comparing(StorePlatformUserRole::getId, Comparator.nullsLast(Comparator.naturalOrder())));
|
|
filteredRoles.sort(Comparator.comparing(StorePlatformUserRole::getId, Comparator.nullsLast(Comparator.naturalOrder())));
|
|
@@ -496,13 +534,19 @@ public class StoreUserServiceImpl extends ServiceImpl<StoreUserMapper, StoreUser
|
|
|
for (StorePlatformUserRole role : pageRoles) {
|
|
for (StorePlatformUserRole role : pageRoles) {
|
|
|
StoreUser subAccount = subAccountMap.get(role.getUserId());
|
|
StoreUser subAccount = subAccountMap.get(role.getUserId());
|
|
|
if (subAccount == null) continue;
|
|
if (subAccount == null) continue;
|
|
|
|
|
+ StoreUser mainAccount = role.getStoreId() == null ? null : mainAccountMap.get(role.getStoreId());
|
|
|
StoreUserVo storeUserVo = new StoreUserVo();
|
|
StoreUserVo storeUserVo = new StoreUserVo();
|
|
|
BeanUtils.copyProperties(subAccount, storeUserVo);
|
|
BeanUtils.copyProperties(subAccount, storeUserVo);
|
|
|
- storeUserVo.setSwitchStatus(subAccount.getStatus() != null && subAccount.getStatus() == 0);
|
|
|
|
|
|
|
+ // 分页列表:账号ID、parentAccountId 均为主账号 id(与主账号联系电话对应),子账号 id 放入 subAccountId
|
|
|
|
|
+ Integer mainId = mainAccount != null ? mainAccount.getId() : subAccount.getSubAccountId();
|
|
|
|
|
+ storeUserVo.setId(mainId != null ? mainId : subAccount.getId());
|
|
|
|
|
+ storeUserVo.setSubAccountId(subAccount.getId());
|
|
|
|
|
+ storeUserVo.setParentAccountId(mainId);
|
|
|
|
|
+ int rowStatus = role.getStatus() != null ? role.getStatus() : (subAccount.getStatus() != null ? subAccount.getStatus() : 0);
|
|
|
|
|
+ storeUserVo.setStatus(rowStatus);
|
|
|
|
|
+ storeUserVo.setSwitchStatus(rowStatus == 0);
|
|
|
storeUserVo.setPhone(subAccount.getPhone());
|
|
storeUserVo.setPhone(subAccount.getPhone());
|
|
|
- StoreUser mainAccount = role.getStoreId() == null ? null : mainAccountMap.get(role.getStoreId());
|
|
|
|
|
if (mainAccount != null) {
|
|
if (mainAccount != null) {
|
|
|
- storeUserVo.setParentAccountId(mainAccount.getId());
|
|
|
|
|
storeUserVo.setParentAccountPhone(mainAccount.getPhone());
|
|
storeUserVo.setParentAccountPhone(mainAccount.getPhone());
|
|
|
storeUserVo.setParentAccountName(mainAccount.getName());
|
|
storeUserVo.setParentAccountName(mainAccount.getName());
|
|
|
}
|
|
}
|
|
@@ -514,13 +558,15 @@ public class StoreUserServiceImpl extends ServiceImpl<StoreUserMapper, StoreUser
|
|
|
return R.data(storeUserVoIPage);
|
|
return R.data(storeUserVoIPage);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 主账号分支:直接查库返回最新 status,主账号页面展示子账号数量(按 store_platform_user_role 统计)
|
|
|
|
|
|
|
+ // 主账号分支:直接查库返回最新 status,主账号页面展示子账号数量(按 store_platform_user_role 统计);排除注销中、已注销
|
|
|
LambdaQueryWrapper<StoreUser> storeUserLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
LambdaQueryWrapper<StoreUser> storeUserLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
storeUserLambdaQueryWrapper.eq(StoreUser::getDeleteFlag, 0)
|
|
storeUserLambdaQueryWrapper.eq(StoreUser::getDeleteFlag, 0)
|
|
|
.like(StringUtils.isNotEmpty(id), StoreUser::getId, id)
|
|
.like(StringUtils.isNotEmpty(id), StoreUser::getId, id)
|
|
|
.like(StringUtils.isNotEmpty(phone), StoreUser::getPhone, phone)
|
|
.like(StringUtils.isNotEmpty(phone), StoreUser::getPhone, phone)
|
|
|
.eq(status != null, StoreUser::getStatus, status)
|
|
.eq(status != null, StoreUser::getStatus, status)
|
|
|
.eq(StoreUser::getAccountType, 1)
|
|
.eq(StoreUser::getAccountType, 1)
|
|
|
|
|
+ .and(w -> w.isNull(StoreUser::getLogoutFlag).or().eq(StoreUser::getLogoutFlag, 0))
|
|
|
|
|
+ .and(w -> w.isNull(StoreUser::getStatus).or().in(StoreUser::getStatus, 0, 1))
|
|
|
.orderByDesc(StoreUser::getCreatedTime);
|
|
.orderByDesc(StoreUser::getCreatedTime);
|
|
|
|
|
|
|
|
IPage<StoreUser> storeUsers = storeUserMapper.selectPage(page, storeUserLambdaQueryWrapper);
|
|
IPage<StoreUser> storeUsers = storeUserMapper.selectPage(page, storeUserLambdaQueryWrapper);
|
|
@@ -546,13 +592,17 @@ public class StoreUserServiceImpl extends ServiceImpl<StoreUserMapper, StoreUser
|
|
|
return R.data(storeUserVoIPage);
|
|
return R.data(storeUserVoIPage);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /** 按 store_platform_user_role 统计该店铺下子账号数量(排除主账号自身,按 distinct user_id 计) */
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 按 store_platform_user_role 统计该店铺下子账号数量(排除主账号自身,按 distinct user_id 计)
|
|
|
|
|
+ */
|
|
|
private int countSubAccountUserIdsByStoreId(Integer storeId, Integer excludeUserId) {
|
|
private int countSubAccountUserIdsByStoreId(Integer storeId, Integer excludeUserId) {
|
|
|
List<Integer> userIds = getSubAccountUserIdsByStoreId(storeId, excludeUserId);
|
|
List<Integer> userIds = getSubAccountUserIdsByStoreId(storeId, excludeUserId);
|
|
|
return userIds == null ? 0 : userIds.size();
|
|
return userIds == null ? 0 : userIds.size();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /** 按 store_platform_user_role 查询该店铺下子账号 userId 列表(排除主账号自身) */
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 按 store_platform_user_role 查询该店铺下子账号 userId 列表(排除主账号自身)
|
|
|
|
|
+ */
|
|
|
private List<Integer> getSubAccountUserIdsByStoreId(Integer storeId, Integer excludeUserId) {
|
|
private List<Integer> getSubAccountUserIdsByStoreId(Integer storeId, Integer excludeUserId) {
|
|
|
if (storeId == null) return Collections.emptyList();
|
|
if (storeId == null) return Collections.emptyList();
|
|
|
LambdaQueryWrapper<StorePlatformUserRole> w = new LambdaQueryWrapper<>();
|
|
LambdaQueryWrapper<StorePlatformUserRole> w = new LambdaQueryWrapper<>();
|
|
@@ -581,48 +631,84 @@ public class StoreUserServiceImpl extends ServiceImpl<StoreUserMapper, StoreUser
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * web端切换商家端用户状态(主账号底下有子账号时禁止禁用;子账号无限制)
|
|
|
|
|
- * @param storeUserParam
|
|
|
|
|
- * @return
|
|
|
|
|
|
|
+ * web端切换商家端用户状态(主账号底下有子账号时禁止禁用;子账号无限制)。
|
|
|
|
|
+ * 若同一账号既是主账号又是子账号:禁用时只禁用子账号角色,主账号保持启用。
|
|
|
*/
|
|
*/
|
|
|
@Override
|
|
@Override
|
|
|
- public R<StoreUserVo> switchingStates(StoreUser storeUserParam) {
|
|
|
|
|
- StoreUser storeUser = storeUserMapper.selectById(storeUserParam.getId());
|
|
|
|
|
- if (storeUser == null) {
|
|
|
|
|
- throw new RuntimeException("用户不存在");
|
|
|
|
|
|
|
+ public R<StoreUserVo> switchingStates(StoreUserVo storeUserParam) {
|
|
|
|
|
+ // 默认传 0 表示执行禁用(状态改为 1),分页列表展示为禁用;传 1 表示执行启用(状态改为 0),分页列表展示为启用
|
|
|
|
|
+ int currentStatus = storeUserParam.getStatus() != null ? storeUserParam.getStatus() : 0;
|
|
|
|
|
+ int newStatus = (currentStatus == 0) ? 1 : 0;
|
|
|
|
|
+ boolean isMainAccount = storeUserParam.getAccountType() != null && storeUserParam.getAccountType() == 1;
|
|
|
|
|
+
|
|
|
|
|
+ if(storeUserParam.getAccountType()==2){
|
|
|
|
|
+ StoreUser storeUser = storeUserMapper.selectById(storeUserParam.getSubAccountId());
|
|
|
|
|
+ if (storeUser == null) {
|
|
|
|
|
+ throw new RuntimeException("用户不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ // 统计该用户在 platform 中未删除的角色数,用于判断是否「既是主账号也是子账号」
|
|
|
|
|
+ long roleCount = storePlatformUserRoleMapper.selectCount(
|
|
|
|
|
+ new LambdaQueryWrapper<StorePlatformUserRole>()
|
|
|
|
|
+ .eq(StorePlatformUserRole::getUserId, storeUser.getId())
|
|
|
|
|
+ .eq(StorePlatformUserRole::getDeleteFlag, 0));
|
|
|
|
|
+ log.info("员工状态的status roleCount={}",roleCount);
|
|
|
|
|
+ boolean isBothMainAndSub = isMainAccount && roleCount > 0;
|
|
|
|
|
+ // 1 既是主账号也是子账号且本次为禁用:只禁用子账号角色,不更新 store_user,主账号保持启用;子账号在列表上按 role.status 展示为禁用
|
|
|
|
|
+ if (isBothMainAndSub) {
|
|
|
|
|
+ LambdaUpdateWrapper<StorePlatformUserRole> roleUpdateWrapper = new LambdaUpdateWrapper<>();
|
|
|
|
|
+ roleUpdateWrapper.eq(StorePlatformUserRole::getUserId, storeUser.getId())
|
|
|
|
|
+ .eq(StorePlatformUserRole::getDeleteFlag, 0)
|
|
|
|
|
+ .set(StorePlatformUserRole::getStatus, currentStatus);
|
|
|
|
|
+ storePlatformUserRoleMapper.update(null, roleUpdateWrapper);
|
|
|
|
|
+ StoreUserVo vo = new StoreUserVo();
|
|
|
|
|
+ vo.setId(storeUser.getId());
|
|
|
|
|
+ vo.setStatus(newStatus);
|
|
|
|
|
+ vo.setSwitchStatus(newStatus == 0);
|
|
|
|
|
+ return R.data(vo);
|
|
|
|
|
+ }
|
|
|
|
|
+ LambdaUpdateWrapper<StorePlatformUserRole> roleUpdateWrapper = new LambdaUpdateWrapper<>();
|
|
|
|
|
+ roleUpdateWrapper.eq(StorePlatformUserRole::getUserId, storeUser.getId())
|
|
|
|
|
+ .eq(StorePlatformUserRole::getDeleteFlag, 0)
|
|
|
|
|
+ .set(StorePlatformUserRole::getStatus, currentStatus);
|
|
|
|
|
+ storePlatformUserRoleMapper.update(null, roleUpdateWrapper);
|
|
|
|
|
+ baseRedisService.delete("store_" + storeUser.getPhone());
|
|
|
|
|
+ LambdaUpdateWrapper<StoreUser> userUpdateWrapper = new LambdaUpdateWrapper<>();
|
|
|
|
|
+ userUpdateWrapper.eq(StoreUser::getId, storeUser.getId()).set(StoreUser::getStatus, currentStatus);
|
|
|
|
|
+ storeUserMapper.update(null, userUpdateWrapper);
|
|
|
|
|
+ StoreUserVo vo = new StoreUserVo();
|
|
|
|
|
+ vo.setId(storeUser.getId());
|
|
|
|
|
+ vo.setStatus(newStatus);
|
|
|
|
|
+ vo.setSwitchStatus(newStatus == 0);
|
|
|
|
|
+ return R.data(vo);
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
- // 仅当「即将禁用」时校验:主账号且该店铺下在 store_platform_user_role 中有关联子账号则禁止禁用
|
|
|
|
|
- if (storeUser.getStatus() != null && storeUser.getStatus() == 0) {
|
|
|
|
|
- if (storeUser.getAccountType() != null && storeUser.getAccountType() == 1) {
|
|
|
|
|
- int subCount = countSubAccountUserIdsByStoreId(storeUser.getStoreId(), storeUser.getId());
|
|
|
|
|
- if (subCount > 0) {
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // 本次为禁用
|
|
|
|
|
+ if (newStatus == 0) {
|
|
|
|
|
+ // 2 对于主账号:有关联子账号则禁止禁用,请先删除主账号下的子账号
|
|
|
|
|
+ if (isMainAccount) {
|
|
|
|
|
+ List<StoreUser> subAccounts = getSubAccountsByMainAccountId(storeUserParam.getId());
|
|
|
|
|
+ if (subAccounts != null && !subAccounts.isEmpty()) {
|
|
|
throw new RuntimeException("请先删除主账号下的子账号后再禁用");
|
|
throw new RuntimeException("请先删除主账号下的子账号后再禁用");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- // 禁用时删除 token
|
|
|
|
|
- baseRedisService.delete("store_" + storeUser.getPhone());
|
|
|
|
|
}
|
|
}
|
|
|
- // 根据当前状态切另一个状态
|
|
|
|
|
- int newStatus = storeUser.getStatus() == 0 ? 1 : 0;
|
|
|
|
|
- LambdaUpdateWrapper<StoreUser> queryWrapper = new LambdaUpdateWrapper<>();
|
|
|
|
|
- queryWrapper.eq(StoreUser::getId, storeUser.getId())
|
|
|
|
|
- .set(StoreUser::getStatus, newStatus);
|
|
|
|
|
- int updateCount = storeUserMapper.update(null, queryWrapper);
|
|
|
|
|
- if (updateCount <= 0) {
|
|
|
|
|
- throw new RuntimeException("更新失败");
|
|
|
|
|
- }
|
|
|
|
|
- // 返回更新后的状态,供前端及时展示
|
|
|
|
|
|
|
+ // 启用/禁用:更新 store_user 的 status(禁用 0→1,启用 1→0),列表即时展示用返回的 vo
|
|
|
|
|
+ LambdaUpdateWrapper<StoreUser> userUpdateWrapper = new LambdaUpdateWrapper<>();
|
|
|
|
|
+ userUpdateWrapper.eq(StoreUser::getId, storeUserParam.getId()).set(StoreUser::getStatus, newStatus);
|
|
|
|
|
+ storeUserMapper.update(null, userUpdateWrapper);
|
|
|
StoreUserVo vo = new StoreUserVo();
|
|
StoreUserVo vo = new StoreUserVo();
|
|
|
- vo.setId(storeUser.getId());
|
|
|
|
|
|
|
+ vo.setId(storeUserParam.getId());
|
|
|
vo.setStatus(newStatus);
|
|
vo.setStatus(newStatus);
|
|
|
vo.setSwitchStatus(newStatus == 0);
|
|
vo.setSwitchStatus(newStatus == 0);
|
|
|
return R.data(vo);
|
|
return R.data(vo);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 分页查询
|
|
|
|
|
- * @param pageNum
|
|
|
|
|
- * @param pageSize
|
|
|
|
|
|
|
+ * 分页查询
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param
|
|
|
|
|
+ * @param
|
|
|
* @param id
|
|
* @param id
|
|
|
* @param phone
|
|
* @param phone
|
|
|
* @param status
|
|
* @param status
|
|
@@ -632,7 +718,7 @@ public class StoreUserServiceImpl extends ServiceImpl<StoreUserMapper, StoreUser
|
|
|
@Override
|
|
@Override
|
|
|
public String exportExcel(String id, String phone, String status, Integer accountType) throws IOException {
|
|
public String exportExcel(String id, String phone, String status, Integer accountType) throws IOException {
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
- // 主账号导出:与 getStoreUserList 主账号分支一致,子账号数量按 store_platform_user_role 统计
|
|
|
|
|
|
|
+ // 主账号导出:与 getStoreUserList 主账号分支一致,子账号数量按 store_platform_user_role 统计;排除注销中、已注销
|
|
|
if (accountType == 1) {
|
|
if (accountType == 1) {
|
|
|
LambdaQueryWrapper<StoreUser> wrapper = new LambdaQueryWrapper<>();
|
|
LambdaQueryWrapper<StoreUser> wrapper = new LambdaQueryWrapper<>();
|
|
|
wrapper.eq(StoreUser::getDeleteFlag, 0)
|
|
wrapper.eq(StoreUser::getDeleteFlag, 0)
|
|
@@ -640,6 +726,8 @@ public class StoreUserServiceImpl extends ServiceImpl<StoreUserMapper, StoreUser
|
|
|
.like(StringUtils.isNotEmpty(phone), StoreUser::getPhone, phone)
|
|
.like(StringUtils.isNotEmpty(phone), StoreUser::getPhone, phone)
|
|
|
.eq(StringUtils.isNotEmpty(status), StoreUser::getStatus, status)
|
|
.eq(StringUtils.isNotEmpty(status), StoreUser::getStatus, status)
|
|
|
.eq(StoreUser::getAccountType, 1)
|
|
.eq(StoreUser::getAccountType, 1)
|
|
|
|
|
+ .and(w -> w.isNull(StoreUser::getLogoutFlag).or().eq(StoreUser::getLogoutFlag, 0))
|
|
|
|
|
+ .and(w -> w.isNull(StoreUser::getStatus).or().in(StoreUser::getStatus, 0, 1))
|
|
|
.orderByDesc(StoreUser::getCreatedTime);
|
|
.orderByDesc(StoreUser::getCreatedTime);
|
|
|
List<StoreUser> storeUsers = storeUserMapper.selectList(wrapper);
|
|
List<StoreUser> storeUsers = storeUserMapper.selectList(wrapper);
|
|
|
List<StoreUserExcelVo> storeUserExcelVoList = new ArrayList<>();
|
|
List<StoreUserExcelVo> storeUserExcelVoList = new ArrayList<>();
|
|
@@ -666,19 +754,71 @@ public class StoreUserServiceImpl extends ServiceImpl<StoreUserMapper, StoreUser
|
|
|
String filePath = ExcelGenerator.generateExcel(excelPath + excelGeneratePath + fileName + ".xlsx", new ArrayList<StoreSubExcelVo>(), StoreSubExcelVo.class);
|
|
String filePath = ExcelGenerator.generateExcel(excelPath + excelGeneratePath + fileName + ".xlsx", new ArrayList<StoreSubExcelVo>(), StoreSubExcelVo.class);
|
|
|
return aliOSSUtil.uploadFile(new File(filePath), "excel/" + fileName + ".xlsx");
|
|
return aliOSSUtil.uploadFile(new File(filePath), "excel/" + fileName + ".xlsx");
|
|
|
}
|
|
}
|
|
|
|
|
+ // 按 (userId, role_id) 去重,与 getStoreUserList 子账号分页一致
|
|
|
|
|
+ userRoles = userRoles.stream()
|
|
|
|
|
+ .sorted(Comparator.comparing(StorePlatformUserRole::getId, Comparator.nullsLast(Comparator.naturalOrder())))
|
|
|
|
|
+ .collect(Collectors.toMap(
|
|
|
|
|
+ r -> (r.getUserId() != null ? r.getUserId() : 0) + "_" + (r.getRoleId() != null ? r.getRoleId() : ""),
|
|
|
|
|
+ r -> r,
|
|
|
|
|
+ (a, b) -> a
|
|
|
|
|
+ ))
|
|
|
|
|
+ .values().stream()
|
|
|
|
|
+ .sorted(Comparator.comparing(StorePlatformUserRole::getId, Comparator.nullsLast(Comparator.naturalOrder())))
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
List<Integer> distinctUserIds = userRoles.stream().map(StorePlatformUserRole::getUserId).filter(Objects::nonNull).distinct().collect(Collectors.toList());
|
|
List<Integer> distinctUserIds = userRoles.stream().map(StorePlatformUserRole::getUserId).filter(Objects::nonNull).distinct().collect(Collectors.toList());
|
|
|
List<StoreUser> subAccountList = distinctUserIds.isEmpty() ? Collections.emptyList() : storeUserMapper.selectBatchIds(distinctUserIds);
|
|
List<StoreUser> subAccountList = distinctUserIds.isEmpty() ? Collections.emptyList() : storeUserMapper.selectBatchIds(distinctUserIds);
|
|
|
- Map<Integer, StoreUser> subAccountMap = subAccountList == null ? new HashMap<>() : subAccountList.stream().filter(u -> u.getDeleteFlag() != null && u.getDeleteFlag() == 0).collect(Collectors.toMap(StoreUser::getId, u -> u, (a, b) -> a));
|
|
|
|
|
|
|
+ Integer statusInt = null;
|
|
|
|
|
+ if (StringUtils.isNotEmpty(status)) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ statusInt = Integer.parseInt(status.trim());
|
|
|
|
|
+ } catch (NumberFormatException ignored) {
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ // 与 getStoreUserList 一致:选「注销中/已注销」时只保留对应状态;否则排除注销中、已注销
|
|
|
|
|
+ Map<Integer, StoreUser> subAccountMap;
|
|
|
|
|
+ if (statusInt != null && (statusInt == -1 || statusInt == 2)) {
|
|
|
|
|
+ final int filterStatus = statusInt;
|
|
|
|
|
+ subAccountMap = subAccountList == null ? new HashMap<>() : subAccountList.stream()
|
|
|
|
|
+ .filter(u -> u.getDeleteFlag() != null && u.getDeleteFlag() == 0)
|
|
|
|
|
+ .filter(u -> {
|
|
|
|
|
+ if (filterStatus == -1) return u.getStatus() != null && u.getStatus() == -1;
|
|
|
|
|
+ return (u.getStatus() != null && u.getStatus() == 2) || (u.getLogoutFlag() != null && u.getLogoutFlag() == 1);
|
|
|
|
|
+ })
|
|
|
|
|
+ .collect(Collectors.toMap(StoreUser::getId, u -> u, (a, b) -> a));
|
|
|
|
|
+ } else {
|
|
|
|
|
+ subAccountMap = subAccountList == null ? new HashMap<>() : subAccountList.stream()
|
|
|
|
|
+ .filter(u -> u.getDeleteFlag() != null && u.getDeleteFlag() == 0
|
|
|
|
|
+ && (u.getLogoutFlag() == null || u.getLogoutFlag() == 0)
|
|
|
|
|
+ && (u.getStatus() == null || (u.getStatus() != -1 && u.getStatus() != 2)))
|
|
|
|
|
+ .collect(Collectors.toMap(StoreUser::getId, u -> u, (a, b) -> a));
|
|
|
|
|
+ }
|
|
|
List<StorePlatformUserRole> filteredRoles = new ArrayList<>();
|
|
List<StorePlatformUserRole> filteredRoles = new ArrayList<>();
|
|
|
for (StorePlatformUserRole role : userRoles) {
|
|
for (StorePlatformUserRole role : userRoles) {
|
|
|
StoreUser subAccount = subAccountMap.get(role.getUserId());
|
|
StoreUser subAccount = subAccountMap.get(role.getUserId());
|
|
|
if (subAccount == null) continue;
|
|
if (subAccount == null) continue;
|
|
|
- if (StringUtils.isNotEmpty(id) && (subAccount.getId() == null || !String.valueOf(subAccount.getId()).contains(id))) continue;
|
|
|
|
|
- if (StringUtils.isNotEmpty(phone) && (subAccount.getPhone() == null || !subAccount.getPhone().contains(phone))) continue;
|
|
|
|
|
- if (status != null && !status.equals(subAccount.getStatus())) continue;
|
|
|
|
|
|
|
+ if (StringUtils.isNotEmpty(id) && (subAccount.getId() == null || !String.valueOf(subAccount.getId()).contains(id)))
|
|
|
|
|
+ continue;
|
|
|
|
|
+ if (StringUtils.isNotEmpty(phone) && (subAccount.getPhone() == null || !subAccount.getPhone().contains(phone)))
|
|
|
|
|
+ continue;
|
|
|
|
|
+ int rowStatus;
|
|
|
|
|
+ if (statusInt != null && (statusInt == -1 || statusInt == 2)) {
|
|
|
|
|
+ rowStatus = (subAccount.getStatus() != null && subAccount.getStatus() == -1) ? -1
|
|
|
|
|
+ : ((subAccount.getStatus() != null && subAccount.getStatus() == 2) || (subAccount.getLogoutFlag() != null && subAccount.getLogoutFlag() == 1)) ? 2
|
|
|
|
|
+ : (subAccount.getStatus() != null ? subAccount.getStatus() : 0);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ rowStatus = role.getStatus() != null ? role.getStatus() : (subAccount.getStatus() != null ? subAccount.getStatus() : 0);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (statusInt != null && !statusInt.equals(rowStatus)) continue;
|
|
|
filteredRoles.add(role);
|
|
filteredRoles.add(role);
|
|
|
}
|
|
}
|
|
|
- filteredRoles.sort(Comparator.comparing(StorePlatformUserRole::getId, Comparator.nullsLast(Comparator.naturalOrder())));
|
|
|
|
|
|
|
+ // 子账号导出与列表一致:按创建时间从近到远(降序)
|
|
|
|
|
+ filteredRoles.sort(Comparator.comparing(
|
|
|
|
|
+ (StorePlatformUserRole r) -> {
|
|
|
|
|
+ StoreUser sub = subAccountMap.get(r.getUserId());
|
|
|
|
|
+ return sub != null && sub.getCreatedTime() != null ? sub.getCreatedTime() : new Date(0L);
|
|
|
|
|
+ },
|
|
|
|
|
+ Comparator.nullsLast(Comparator.reverseOrder())
|
|
|
|
|
+ ).thenComparing(StorePlatformUserRole::getId, Comparator.nullsLast(Comparator.reverseOrder())));
|
|
|
List<Integer> storeIds = filteredRoles.stream().map(StorePlatformUserRole::getStoreId).filter(Objects::nonNull).distinct().collect(Collectors.toList());
|
|
List<Integer> storeIds = filteredRoles.stream().map(StorePlatformUserRole::getStoreId).filter(Objects::nonNull).distinct().collect(Collectors.toList());
|
|
|
Map<Integer, StoreUser> mainAccountMap = new HashMap<>();
|
|
Map<Integer, StoreUser> mainAccountMap = new HashMap<>();
|
|
|
if (!storeIds.isEmpty()) {
|
|
if (!storeIds.isEmpty()) {
|
|
@@ -692,21 +832,23 @@ public class StoreUserServiceImpl extends ServiceImpl<StoreUserMapper, StoreUser
|
|
|
for (StorePlatformUserRole role : filteredRoles) {
|
|
for (StorePlatformUserRole role : filteredRoles) {
|
|
|
StoreUser subAccount = subAccountMap.get(role.getUserId());
|
|
StoreUser subAccount = subAccountMap.get(role.getUserId());
|
|
|
if (subAccount == null) continue;
|
|
if (subAccount == null) continue;
|
|
|
|
|
+ StoreUser mainAccount = role.getStoreId() == null ? null : mainAccountMap.get(role.getStoreId());
|
|
|
StoreSubExcelVo vo = new StoreSubExcelVo();
|
|
StoreSubExcelVo vo = new StoreSubExcelVo();
|
|
|
vo.setSerialNumber(++serialNumber);
|
|
vo.setSerialNumber(++serialNumber);
|
|
|
- vo.setId(subAccount.getId());
|
|
|
|
|
|
|
+ vo.setParentAccountId(mainAccount != null ? mainAccount.getId() : null);
|
|
|
|
|
+ vo.setParentAccountPhone(mainAccount != null ? mainAccount.getPhone() : null);
|
|
|
vo.setPhone(subAccount.getPhone());
|
|
vo.setPhone(subAccount.getPhone());
|
|
|
vo.setCreatedTime(subAccount.getCreatedTime() != null ? subAccount.getCreatedTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime().format(formatter) : null);
|
|
vo.setCreatedTime(subAccount.getCreatedTime() != null ? subAccount.getCreatedTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime().format(formatter) : null);
|
|
|
- vo.setStatus(subAccount.getStatus() == null ? "" : (subAccount.getStatus() == 0 ? "启用" : "禁用"));
|
|
|
|
|
- StoreUser mainAccount = role.getStoreId() == null ? null : mainAccountMap.get(role.getStoreId());
|
|
|
|
|
- if (mainAccount != null) {
|
|
|
|
|
- vo.setParentAccountPhone(mainAccount.getPhone());
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ int rowStatus = (subAccount.getStatus() != null && subAccount.getStatus() == -1) ? -1
|
|
|
|
|
+ : ((subAccount.getStatus() != null && subAccount.getStatus() == 2) || (subAccount.getLogoutFlag() != null && subAccount.getLogoutFlag() == 1)) ? 2
|
|
|
|
|
+ : (role.getStatus() != null ? role.getStatus() : (subAccount.getStatus() != null ? subAccount.getStatus() : 0));
|
|
|
|
|
+ vo.setStatus(rowStatus == -1 ? "注销中" : rowStatus == 2 ? "已注销" : (rowStatus == 0 ? "启用" : "禁用"));
|
|
|
storeSubExcelVoList.add(vo);
|
|
storeSubExcelVoList.add(vo);
|
|
|
}
|
|
}
|
|
|
String fileName = UUID.randomUUID().toString().replace("-", "");
|
|
String fileName = UUID.randomUUID().toString().replace("-", "");
|
|
|
String filePath = ExcelGenerator.generateExcel(excelPath + excelGeneratePath + fileName + ".xlsx", storeSubExcelVoList, StoreSubExcelVo.class);
|
|
String filePath = ExcelGenerator.generateExcel(excelPath + excelGeneratePath + fileName + ".xlsx", storeSubExcelVoList, StoreSubExcelVo.class);
|
|
|
return aliOSSUtil.uploadFile(new File(filePath), "excel/" + fileName + ".xlsx");
|
|
return aliOSSUtil.uploadFile(new File(filePath), "excel/" + fileName + ".xlsx");
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -932,102 +1074,90 @@ public class StoreUserServiceImpl extends ServiceImpl<StoreUserMapper, StoreUser
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 删除门店
|
|
|
|
|
|
|
+ * 删除门店
|
|
|
|
|
+ *
|
|
|
* @param storeUserVo
|
|
* @param storeUserVo
|
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public void deleteStoreAccountInfo(StoreUserVo storeUserVo) {
|
|
|
|
|
- LambdaQueryWrapper<StoreUser> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
- queryWrapper.eq(StoreUser::getId, storeUserVo.getId());
|
|
|
|
|
- queryWrapper.eq(StoreUser::getDeleteFlag, 0);
|
|
|
|
|
- StoreUser storeUser = storeUserMapper.selectOne(queryWrapper);
|
|
|
|
|
- // 主账号删除前校验:底下有店铺或有关联子账号则禁止删除
|
|
|
|
|
- if (storeUser != null && storeUser.getAccountType() != null && storeUser.getAccountType() == 1) {
|
|
|
|
|
- if (storeUser.getStoreId() != null) {
|
|
|
|
|
- throw new RuntimeException("该主账号下存在店铺,禁止删除");
|
|
|
|
|
- }
|
|
|
|
|
- List<StoreUser> subAccounts = getSubAccountsByMainAccountId(storeUser.getId());
|
|
|
|
|
- if (subAccounts != null && !subAccounts.isEmpty()) {
|
|
|
|
|
- throw new RuntimeException("该主账号下存在关联子账号,禁止删除");
|
|
|
|
|
|
|
+ public String deleteStoreAccountInfo(StoreUserVo storeUserVo) {
|
|
|
|
|
+ // 解析用户:优先用子账号联系方式 phone 查;未传 phone 时用 id/subAccountId 查 store_user,后端从库中拿到子账号联系方式(phone)
|
|
|
|
|
+ StoreUser storeUser = null;
|
|
|
|
|
+ if ((storeUserVo.getId() != null || storeUserVo.getSubAccountId() != null)) {
|
|
|
|
|
+ Integer idParam = storeUserVo.getSubAccountId() != null ? storeUserVo.getSubAccountId() : storeUserVo.getId();
|
|
|
|
|
+ storeUser = storeUserMapper.selectOne(new LambdaQueryWrapper<StoreUser>()
|
|
|
|
|
+ .eq(StoreUser::getId, idParam).eq(StoreUser::getDeleteFlag, 0));
|
|
|
|
|
+ if (storeUser != null) {
|
|
|
|
|
+ log.info("deleteStoreAccountInfo 通过 id 查到用户,后端拿到子账号联系方式: userId={}, phone={}", storeUser.getId(), storeUser.getPhone());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ if (storeUserVo == null) {
|
|
|
|
|
+ log.warn("deleteStoreAccountInfo 用户不存在或已删除,请传子账号联系电话(phone)或用户id");
|
|
|
|
|
+ return "删除失败";
|
|
|
|
|
+ }
|
|
|
|
|
+ // 通过 phone 再尝试解析用户(前端可能只传 phone)
|
|
|
|
|
+ if (storeUser == null && storeUserVo.getPhone() != null) {
|
|
|
|
|
+ storeUser = storeUserMapper.selectOne(new LambdaQueryWrapper<StoreUser>()
|
|
|
|
|
+ .eq(StoreUser::getPhone, storeUserVo.getPhone()).eq(StoreUser::getDeleteFlag, 0));
|
|
|
|
|
+ }
|
|
|
if (storeUser == null) {
|
|
if (storeUser == null) {
|
|
|
- return;
|
|
|
|
|
|
|
+ log.warn("deleteStoreAccountInfo 用户不存在或已删除,请传子账号联系电话(phone)或用户id");
|
|
|
|
|
+ return "删除失败";
|
|
|
}
|
|
}
|
|
|
Integer userId = storeUser.getId();
|
|
Integer userId = storeUser.getId();
|
|
|
- String phone = storeUser.getPhone();
|
|
|
|
|
-
|
|
|
|
|
- // 1. 先查询该用户在所有店铺下的子账号数量(未删除的)
|
|
|
|
|
- LambdaQueryWrapper<StorePlatformUserRole> countWrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
- countWrapper.eq(StorePlatformUserRole::getUserId, userId)
|
|
|
|
|
- .eq(StorePlatformUserRole::getDeleteFlag, 0);
|
|
|
|
|
- long subAccountCount = storePlatformUserRoleMapper.selectCount(countWrapper);
|
|
|
|
|
- log.info("用户在所有店铺下的子账号数量: userId={}, count={}", userId, subAccountCount);
|
|
|
|
|
-
|
|
|
|
|
- // 2. 逻辑删除 store_platform_user_role 表的记录
|
|
|
|
|
- LambdaUpdateWrapper<StorePlatformUserRole> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
|
|
- updateWrapper.eq(StorePlatformUserRole::getUserId, userId)
|
|
|
|
|
- .eq(StorePlatformUserRole::getDeleteFlag, 0)
|
|
|
|
|
- .set(StorePlatformUserRole::getDeleteFlag, 1);
|
|
|
|
|
- storePlatformUserRoleMapper.update(null, updateWrapper);
|
|
|
|
|
-
|
|
|
|
|
- // 删除 token
|
|
|
|
|
- String tokenKey = "store_" + phone;
|
|
|
|
|
- baseRedisService.delete(tokenKey);
|
|
|
|
|
-
|
|
|
|
|
- // 3. 如果只是一个账号的子账号(删除前只有1个),则需要进一步判断是否为主账号,再决定是否同时逻辑删除 store_user 表
|
|
|
|
|
- if (subAccountCount == 1) {
|
|
|
|
|
- boolean isMainAccount = storeUser.getStoreId() != null && storeUser.getStoreId() > 0
|
|
|
|
|
- || (storeUser.getAccountType() != null && storeUser.getAccountType() == 1);
|
|
|
|
|
- if (isMainAccount) {
|
|
|
|
|
- // 主账号:物理删除 store_user 及关联数据(主账号校验已通过,无店铺无子账号)
|
|
|
|
|
- nearMeService.removeGeolocation(Boolean.TRUE, userId.toString());
|
|
|
|
|
- storeUserMapper.deleteById(userId);
|
|
|
|
|
- LambdaQueryWrapper<LifeFans> lifeFansWrapper = new LambdaQueryWrapper<LifeFans>()
|
|
|
|
|
- .eq(LifeFans::getFollowedId, "store_" + phone)
|
|
|
|
|
- .or().eq(LifeFans::getFansId, "store_" + phone);
|
|
|
|
|
- lifeFansMapper.delete(lifeFansWrapper);
|
|
|
|
|
- if (storeUser.getStoreId() != null) {
|
|
|
|
|
- storeInfoMapper.deleteById(storeUser.getStoreId());
|
|
|
|
|
- }
|
|
|
|
|
- lifeUserDynamicsMapper.delete(new LambdaQueryWrapper<LifeUserDynamics>().eq(LifeUserDynamics::getPhoneId, "store_" + phone));
|
|
|
|
|
- lifeNoticeMapper.delete(new LambdaQueryWrapper<LifeNotice>().eq(LifeNotice::getReceiverId, "store_" + phone));
|
|
|
|
|
- lifeMessageMapper.delete(new LambdaQueryWrapper<LifeMessage>().eq(LifeMessage::getSenderId, "store_" + phone));
|
|
|
|
|
- lifeMessageMapper.delete(new LambdaQueryWrapper<LifeMessage>().eq(LifeMessage::getReceiverId, "store_" + phone));
|
|
|
|
|
- log.info("主账号仅1条 platform 记录,已物理删除 store_user 及关联数据: userId={}", userId);
|
|
|
|
|
- } else {
|
|
|
|
|
- // 不是主账号,逻辑删除 store_user
|
|
|
|
|
- LambdaUpdateWrapper<StoreUser> userUpdateWrapper = new LambdaUpdateWrapper<>();
|
|
|
|
|
- userUpdateWrapper.eq(StoreUser::getId, userId)
|
|
|
|
|
- .eq(StoreUser::getDeleteFlag, 0)
|
|
|
|
|
- .set(StoreUser::getDeleteFlag, 1);
|
|
|
|
|
- int userUpdateResult = storeUserMapper.update(null, userUpdateWrapper);
|
|
|
|
|
- if (userUpdateResult > 0) {
|
|
|
|
|
- log.info("用户只有一个子账号且不是主账号,已同时逻辑删除 store_user 记录: userId={}", userId);
|
|
|
|
|
- } else {
|
|
|
|
|
- log.warn("逻辑删除 store_user 记录失败或记录不存在: userId={}", userId);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- } else if (subAccountCount == 0) {
|
|
|
|
|
- // 无 platform 记录,全量物理删除
|
|
|
|
|
- nearMeService.removeGeolocation(Boolean.TRUE, userId.toString());
|
|
|
|
|
- storeUserMapper.deleteById(userId);
|
|
|
|
|
- LambdaQueryWrapper<LifeFans> lifeFansWrapper = new LambdaQueryWrapper<LifeFans>()
|
|
|
|
|
- .eq(LifeFans::getFollowedId, "store_" + phone)
|
|
|
|
|
- .or().eq(LifeFans::getFansId, "store_" + phone);
|
|
|
|
|
- lifeFansMapper.delete(lifeFansWrapper);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // 删除主账号校验:该主账号下有店铺禁止删除、该主账号下有子账号禁止删除(主账号列表返回的 id 即主账号 id)
|
|
|
|
|
+ if (storeUserVo.getAccountType() != null && storeUserVo.getAccountType() == 1) {
|
|
|
if (storeUser.getStoreId() != null) {
|
|
if (storeUser.getStoreId() != null) {
|
|
|
- storeInfoMapper.deleteById(storeUser.getStoreId());
|
|
|
|
|
|
|
+ log.error("该主账号下存在店铺,禁止删除");
|
|
|
|
|
+ return "当前账号下存在店铺 禁止删除";
|
|
|
}
|
|
}
|
|
|
- lifeUserDynamicsMapper.delete(new LambdaQueryWrapper<LifeUserDynamics>().eq(LifeUserDynamics::getPhoneId, "store_" + phone));
|
|
|
|
|
- lifeNoticeMapper.delete(new LambdaQueryWrapper<LifeNotice>().eq(LifeNotice::getReceiverId, "store_" + phone));
|
|
|
|
|
- lifeMessageMapper.delete(new LambdaQueryWrapper<LifeMessage>().eq(LifeMessage::getSenderId, "store_" + phone));
|
|
|
|
|
- lifeMessageMapper.delete(new LambdaQueryWrapper<LifeMessage>().eq(LifeMessage::getReceiverId, "store_" + phone));
|
|
|
|
|
- log.info("用户无 platform 记录,已物理删除 store_user 及关联数据: userId={}", userId);
|
|
|
|
|
|
|
+ Integer mainIdForCheck = storeUserVo.getId();
|
|
|
|
|
+ if (mainIdForCheck != null) {
|
|
|
|
|
+ List<StoreUser> subAccounts = getSubAccountsByMainAccountId(mainIdForCheck);
|
|
|
|
|
+ if (subAccounts != null && !subAccounts.isEmpty()) {
|
|
|
|
|
+ log.error("该主账号下存在关联子账号,禁止删除");
|
|
|
|
|
+ return "当前账号下存在子账号禁止删除";
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 主账号 id:优先用子账号 store_user.sub_account_id;无则用前端列表返回的 parentAccountId(与分页接口 records 字段一致)
|
|
|
|
|
+ Integer mainAccountId = storeUser.getSubAccountId() != null ? storeUser.getSubAccountId() : storeUserVo.getParentAccountId();
|
|
|
|
|
+ if (mainAccountId == null) {
|
|
|
|
|
+ log.warn("deleteStoreAccountInfo 无法确定主账号,请传 parentAccountId 或保证子账号 store_user.sub_account_id 有值");
|
|
|
|
|
+ return "删除失败";
|
|
|
|
|
+ }
|
|
|
|
|
+ // 查询主账号下的子账号数量(按 store_user 统计:account_type=2 且 sub_account_id=主账号id)
|
|
|
|
|
+ List<StoreUser> subAccountsUnderMain = getSubAccountsByMainAccountId(mainAccountId);
|
|
|
|
|
+ int subAccountCount = subAccountsUnderMain != null ? subAccountsUnderMain.size() : 0;
|
|
|
|
|
+ log.info("主账号下子账号数量: mainAccountId={}, subAccountCount={}", mainAccountId, subAccountCount);
|
|
|
|
|
+
|
|
|
|
|
+ // 仅删除该主账号对应店铺下的角色:取主账号的 store_id,按 userId + storeId 逻辑删除 store_platform_user_role
|
|
|
|
|
+ StoreUser mainAccount = storeUserMapper.selectById(mainAccountId);
|
|
|
|
|
+ Integer storeId = mainAccount != null ? mainAccount.getStoreId() : null;
|
|
|
|
|
+ LambdaUpdateWrapper<StorePlatformUserRole> roleUpdateWrapper = new LambdaUpdateWrapper<>();
|
|
|
|
|
+ roleUpdateWrapper.eq(StorePlatformUserRole::getUserId, userId).eq(StorePlatformUserRole::getDeleteFlag, 0);
|
|
|
|
|
+ if (storeId != null) {
|
|
|
|
|
+ roleUpdateWrapper.eq(StorePlatformUserRole::getStoreId, storeId);
|
|
|
|
|
+ }
|
|
|
|
|
+ roleUpdateWrapper.set(StorePlatformUserRole::getDeleteFlag, 1);
|
|
|
|
|
+ storePlatformUserRoleMapper.update(null, roleUpdateWrapper);
|
|
|
|
|
+
|
|
|
|
|
+ // 主账号下子账号唯一:逻辑删除 store_platform_user_role 和 store_user;不唯一:只逻辑删除 store_platform_user_role
|
|
|
|
|
+ if (subAccountCount == 1) {
|
|
|
|
|
+ LambdaUpdateWrapper<StoreUser> userUpdateWrapper = new LambdaUpdateWrapper<>();
|
|
|
|
|
+ userUpdateWrapper.eq(StoreUser::getId, userId)
|
|
|
|
|
+ .eq(StoreUser::getDeleteFlag, 0)
|
|
|
|
|
+ .set(StoreUser::getDeleteFlag, 1);
|
|
|
|
|
+ storeUserMapper.update(null, userUpdateWrapper);
|
|
|
|
|
+ log.info("主账号下子账号唯一,已逻辑删除 store_platform_user_role 和 store_user: userId={}", userId);
|
|
|
|
|
+ String tokenKey = "store_" + storeUser.getPhone();
|
|
|
|
|
+ baseRedisService.delete(tokenKey);
|
|
|
} else {
|
|
} else {
|
|
|
- log.info("用户有多个子账号(count={}),仅删除 store_platform_user_role 记录,不删除 store_user: userId={}", subAccountCount, userId);
|
|
|
|
|
|
|
+ log.info("主账号下子账号数不为1,仅逻辑删除 store_platform_user_role,不删 store_user: mainAccountId={}, subAccountCount={}", mainAccountId, subAccountCount);
|
|
|
}
|
|
}
|
|
|
|
|
+ return "删除失败";
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|