|
@@ -41,6 +41,7 @@ import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
import java.math.RoundingMode;
|
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.time.Duration;
|
|
import java.time.Duration;
|
|
|
|
|
+import java.time.Instant;
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.ZoneId;
|
|
import java.time.ZoneId;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
import java.time.format.DateTimeFormatter;
|
|
@@ -251,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 {
|
|
@@ -270,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)) {
|
|
@@ -281,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("原密码错误");
|
|
|
}
|
|
}
|
|
@@ -490,8 +490,10 @@ public class StoreUserServiceImpl extends ServiceImpl<StoreUserMapper, StoreUser
|
|
|
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 (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 为准
|
|
// 状态筛选:选「注销中/已注销」时以 store_user 为准(已由 subAccountMap 限定);否则以 role.status 为准
|
|
|
int rowStatus;
|
|
int rowStatus;
|
|
|
if (status != null && (status == -1 || status == 2)) {
|
|
if (status != null && (status == -1 || status == 2)) {
|
|
@@ -584,13 +586,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<>();
|
|
@@ -618,64 +624,83 @@ 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("用户不存在");
|
|
|
|
|
- }
|
|
|
|
|
- // 仅当「即将禁用」时校验:主账号且该店铺下在 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) {
|
|
|
|
|
- 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);
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
- int newStatus = storeUser.getStatus() == 0 ? 1 : 0;
|
|
|
|
|
- // 是否既是主账号又在 store_platform_user_role 中有记录(即也是子账号)
|
|
|
|
|
- long roleCount = storePlatformUserRoleMapper.selectCount(new LambdaQueryWrapper<StorePlatformUserRole>().eq(StorePlatformUserRole::getUserId, storeUser.getId()));
|
|
|
|
|
- boolean isBothMainAndSub = (storeUser.getAccountType() != null && storeUser.getAccountType() == 1) && roleCount > 0;
|
|
|
|
|
- if (isBothMainAndSub && newStatus == 1) {
|
|
|
|
|
- // 既是主账号也是子账号且本次为禁用:只禁用子账号角色,不更新 store_user,主账号保持启用
|
|
|
|
|
LambdaUpdateWrapper<StorePlatformUserRole> roleUpdateWrapper = new LambdaUpdateWrapper<>();
|
|
LambdaUpdateWrapper<StorePlatformUserRole> roleUpdateWrapper = new LambdaUpdateWrapper<>();
|
|
|
- roleUpdateWrapper.eq(StorePlatformUserRole::getUserId, storeUser.getId()).set(StorePlatformUserRole::getStatus, 1);
|
|
|
|
|
|
|
+ roleUpdateWrapper.eq(StorePlatformUserRole::getUserId, storeUser.getId())
|
|
|
|
|
+ .eq(StorePlatformUserRole::getDeleteFlag, 0)
|
|
|
|
|
+ .set(StorePlatformUserRole::getStatus, currentStatus);
|
|
|
storePlatformUserRoleMapper.update(null, roleUpdateWrapper);
|
|
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();
|
|
StoreUserVo vo = new StoreUserVo();
|
|
|
vo.setId(storeUser.getId());
|
|
vo.setId(storeUser.getId());
|
|
|
- vo.setStatus(1);
|
|
|
|
|
- vo.setSwitchStatus(false);
|
|
|
|
|
|
|
+ vo.setStatus(newStatus);
|
|
|
|
|
+ vo.setSwitchStatus(newStatus == 0);
|
|
|
return R.data(vo);
|
|
return R.data(vo);
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
- if (newStatus == 1) {
|
|
|
|
|
- baseRedisService.delete("store_" + storeUser.getPhone());
|
|
|
|
|
- }
|
|
|
|
|
- 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("更新失败");
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // 本次为禁用
|
|
|
|
|
+ if (newStatus == 0) {
|
|
|
|
|
+ // 2 对于主账号:有关联子账号则禁止禁用,请先删除主账号下的子账号
|
|
|
|
|
+ if (isMainAccount) {
|
|
|
|
|
+ List<StoreUser> subAccounts = getSubAccountsByMainAccountId(storeUserParam.getId());
|
|
|
|
|
+ if (subAccounts != null && !subAccounts.isEmpty()) {
|
|
|
|
|
+ throw new RuntimeException("请先删除主账号下的子账号后再禁用");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
- LambdaUpdateWrapper<StorePlatformUserRole> roleUpdateWrapper = new LambdaUpdateWrapper<>();
|
|
|
|
|
- roleUpdateWrapper.eq(StorePlatformUserRole::getUserId, storeUser.getId()).set(StorePlatformUserRole::getStatus, newStatus);
|
|
|
|
|
- storePlatformUserRoleMapper.update(null, roleUpdateWrapper);
|
|
|
|
|
- // 返回更新后的状态,供前端及时展示
|
|
|
|
|
|
|
+ // 启用/禁用:更新 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
|
|
* @param
|
|
|
* @param
|
|
* @param
|
|
|
* @param id
|
|
* @param id
|
|
@@ -738,7 +763,10 @@ public class StoreUserServiceImpl extends ServiceImpl<StoreUserMapper, StoreUser
|
|
|
List<StoreUser> subAccountList = distinctUserIds.isEmpty() ? Collections.emptyList() : storeUserMapper.selectBatchIds(distinctUserIds);
|
|
List<StoreUser> subAccountList = distinctUserIds.isEmpty() ? Collections.emptyList() : storeUserMapper.selectBatchIds(distinctUserIds);
|
|
|
Integer statusInt = null;
|
|
Integer statusInt = null;
|
|
|
if (StringUtils.isNotEmpty(status)) {
|
|
if (StringUtils.isNotEmpty(status)) {
|
|
|
- try { statusInt = Integer.parseInt(status.trim()); } catch (NumberFormatException ignored) { }
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ statusInt = Integer.parseInt(status.trim());
|
|
|
|
|
+ } catch (NumberFormatException ignored) {
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
// 与 getStoreUserList 一致:选「注销中/已注销」时只保留对应状态;否则排除注销中、已注销
|
|
// 与 getStoreUserList 一致:选「注销中/已注销」时只保留对应状态;否则排除注销中、已注销
|
|
|
Map<Integer, StoreUser> subAccountMap;
|
|
Map<Integer, StoreUser> subAccountMap;
|
|
@@ -762,8 +790,10 @@ public class StoreUserServiceImpl extends ServiceImpl<StoreUserMapper, StoreUser
|
|
|
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 (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;
|
|
int rowStatus;
|
|
|
if (statusInt != null && (statusInt == -1 || statusInt == 2)) {
|
|
if (statusInt != null && (statusInt == -1 || statusInt == 2)) {
|
|
|
rowStatus = (subAccount.getStatus() != null && subAccount.getStatus() == -1) ? -1
|
|
rowStatus = (subAccount.getStatus() != null && subAccount.getStatus() == -1) ? -1
|
|
@@ -775,7 +805,14 @@ public class StoreUserServiceImpl extends ServiceImpl<StoreUserMapper, StoreUser
|
|
|
if (statusInt != null && !statusInt.equals(rowStatus)) continue;
|
|
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()) {
|
|
@@ -789,24 +826,24 @@ 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.setSubAccountId(subAccount.getId());
|
|
|
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);
|
|
|
int rowStatus = (subAccount.getStatus() != null && subAccount.getStatus() == -1) ? -1
|
|
int 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() == 2) || (subAccount.getLogoutFlag() != null && subAccount.getLogoutFlag() == 1)) ? 2
|
|
|
: (role.getStatus() != null ? role.getStatus() : (subAccount.getStatus() != null ? subAccount.getStatus() : 0));
|
|
: (role.getStatus() != null ? role.getStatus() : (subAccount.getStatus() != null ? subAccount.getStatus() : 0));
|
|
|
vo.setStatus(rowStatus == -1 ? "注销中" : rowStatus == 2 ? "已注销" : (rowStatus == 0 ? "启用" : "禁用"));
|
|
vo.setStatus(rowStatus == -1 ? "注销中" : rowStatus == 2 ? "已注销" : (rowStatus == 0 ? "启用" : "禁用"));
|
|
|
- StoreUser mainAccount = role.getStoreId() == null ? null : mainAccountMap.get(role.getStoreId());
|
|
|
|
|
- if (mainAccount != null) {
|
|
|
|
|
- vo.setParentAccountPhone(mainAccount.getPhone());
|
|
|
|
|
- }
|
|
|
|
|
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");
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1032,94 +1069,90 @@ public class StoreUserServiceImpl extends ServiceImpl<StoreUserMapper, StoreUser
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 删除门店
|
|
|
|
|
|
|
+ * 删除门店
|
|
|
|
|
+ *
|
|
|
* @param storeUserVo
|
|
* @param storeUserVo
|
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public boolean deleteStoreAccountInfo(StoreUserVo storeUserVo) {
|
|
public boolean 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("该主账号下存在关联子账号,禁止删除");
|
|
|
|
|
|
|
+ // 解析用户:优先用子账号联系方式 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 false;
|
|
|
|
|
+ }
|
|
|
|
|
+ // 通过 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) {
|
|
|
|
|
+ log.warn("deleteStoreAccountInfo 用户不存在或已删除,请传子账号联系电话(phone)或用户id");
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
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);
|
|
|
|
|
-
|
|
|
|
|
- long roleCount = storePlatformUserRoleMapper.selectCount(new LambdaQueryWrapper<StorePlatformUserRole>().eq(StorePlatformUserRole::getUserId, storeUser.getId()));
|
|
|
|
|
- if (roleCount != 0||subAccountCount>1){
|
|
|
|
|
- // 2. 逻辑删除 store_platform_user_role 表的记录
|
|
|
|
|
- LambdaUpdateWrapper<StorePlatformUserRole> wrapper = new LambdaUpdateWrapper<>();
|
|
|
|
|
- wrapper.eq(StorePlatformUserRole::getUserId, userId)
|
|
|
|
|
- .eq(StorePlatformUserRole::getDeleteFlag, 0)
|
|
|
|
|
- .set(StorePlatformUserRole::getDeleteFlag, 1);
|
|
|
|
|
- storePlatformUserRoleMapper.update(null,wrapper);
|
|
|
|
|
- log.info("该账号有多个子账号,不删除 store_user 记录: userId={}, count={}", userId, subAccountCount);
|
|
|
|
|
- String tokenKey = "store_" + phone;
|
|
|
|
|
- baseRedisService.delete(tokenKey);
|
|
|
|
|
- return true;
|
|
|
|
|
- }else if (subAccountCount == 1){
|
|
|
|
|
- // 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 表
|
|
|
|
|
|
|
|
|
|
- // 主账号:逻辑删除 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("主账号仅1条 platform 记录,已逻辑删除 store_user: userId={}", userId);
|
|
|
|
|
- } else {
|
|
|
|
|
- log.warn("逻辑删除 store_user 记录失败或记录不存在: userId={}", userId);
|
|
|
|
|
|
|
+ // 删除主账号校验:该主账号下有店铺禁止删除、该主账号下有子账号禁止删除(主账号列表返回的 id 即主账号 id)
|
|
|
|
|
+ if (storeUserVo.getAccountType() != null && storeUserVo.getAccountType() == 1) {
|
|
|
|
|
+ if (storeUser.getStoreId() != null) {
|
|
|
|
|
+ log.error("该主账号下存在店铺,禁止删除");
|
|
|
|
|
+ return false;
|
|
|
}
|
|
}
|
|
|
- return true;
|
|
|
|
|
- } else {
|
|
|
|
|
- // 删除 token
|
|
|
|
|
- String tokenKey = "store_" + phone;
|
|
|
|
|
- baseRedisService.delete(tokenKey);
|
|
|
|
|
|
|
+ Integer mainIdForCheck = storeUserVo.getId();
|
|
|
|
|
+ if (mainIdForCheck != null) {
|
|
|
|
|
+ List<StoreUser> subAccounts = getSubAccountsByMainAccountId(mainIdForCheck);
|
|
|
|
|
+ if (subAccounts != null && !subAccounts.isEmpty()) {
|
|
|
|
|
+ log.error("该主账号下存在关联子账号,禁止删除");
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 主账号 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 false;
|
|
|
|
|
+ }
|
|
|
|
|
+ // 查询主账号下的子账号数量(按 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<>();
|
|
LambdaUpdateWrapper<StoreUser> userUpdateWrapper = new LambdaUpdateWrapper<>();
|
|
|
userUpdateWrapper.eq(StoreUser::getId, userId)
|
|
userUpdateWrapper.eq(StoreUser::getId, userId)
|
|
|
.eq(StoreUser::getDeleteFlag, 0)
|
|
.eq(StoreUser::getDeleteFlag, 0)
|
|
|
.set(StoreUser::getDeleteFlag, 1);
|
|
.set(StoreUser::getDeleteFlag, 1);
|
|
|
- int userUpdateResult = storeUserMapper.update(null, userUpdateWrapper);
|
|
|
|
|
- if (userUpdateResult > 0) {
|
|
|
|
|
- log.info("用户无 platform 记录且非主账号,已逻辑删除 store_user: userId={}", userId);
|
|
|
|
|
- } else {
|
|
|
|
|
- log.warn("逻辑删除 store_user 记录失败或记录不存在: userId={}", userId);
|
|
|
|
|
- }
|
|
|
|
|
- return true;
|
|
|
|
|
|
|
+ storeUserMapper.update(null, userUpdateWrapper);
|
|
|
|
|
+ log.info("主账号下子账号唯一,已逻辑删除 store_platform_user_role 和 store_user: userId={}", userId);
|
|
|
|
|
+ String tokenKey = "store_" + storeUser.getPhone();
|
|
|
|
|
+ baseRedisService.delete(tokenKey);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ log.info("主账号下子账号数不为1,仅逻辑删除 store_platform_user_role,不删 store_user: mainAccountId={}, subAccountCount={}", mainAccountId, subAccountCount);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
|
|
+ return true;
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -1167,8 +1200,8 @@ public class StoreUserServiceImpl extends ServiceImpl<StoreUserMapper, StoreUser
|
|
|
queryWrapper.eq(StoreUser::getAccountType, 2) // 子账号类型
|
|
queryWrapper.eq(StoreUser::getAccountType, 2) // 子账号类型
|
|
|
.eq(StoreUser::getSubAccountId, mainAccountId) // 关联主账号ID
|
|
.eq(StoreUser::getSubAccountId, mainAccountId) // 关联主账号ID
|
|
|
.eq(StoreUser::getDeleteFlag, 0) // 未删除的账号
|
|
.eq(StoreUser::getDeleteFlag, 0) // 未删除的账号
|
|
|
- .orderByDesc(StoreUser::getCreatedTime)// 按创建时间倒序
|
|
|
|
|
- .eq(StoreUser::getAccountType, 2);
|
|
|
|
|
|
|
+ .orderByDesc(StoreUser::getCreatedTime); // 按创建时间倒序
|
|
|
|
|
+
|
|
|
return storeUserMapper.selectList(queryWrapper);
|
|
return storeUserMapper.selectList(queryWrapper);
|
|
|
}
|
|
}
|
|
|
|
|
|