修复:修复后台用户停用删除不落库

This commit is contained in:
xiaowang
2026-03-26 17:09:16 +08:00
parent c0eae0ef03
commit 5ca2fbfa95
3 changed files with 119 additions and 27 deletions
@@ -1,6 +1,7 @@
package com.xiaowang.yuminailcore.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -54,7 +55,6 @@ import java.util.stream.Collectors;
@Service
@RequiredArgsConstructor
public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements UserService {
private static final String VIP_LEVEL_NORMAL = "普通";
private static final String PHONE_REGEX = "^1[3-9]\\d{9}$";
private static final String DELETED_PHONE_MARKER = "_deleted_";
@@ -62,7 +62,6 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
private static final Set<String> MANAGED_DEFAULT_PERMISSION_CODES = PermissionPolicy.getManagedDefaultPermissionCodes();
private static final Map<String, PermissionSeed> DEFAULT_PERMISSION_SEEDS = buildDefaultPermissionSeeds();
// 注入用户数据访问层、JWT工具类和店铺服务
private final UserMapper userMapper;
private final JwtUtil jwtUtil;
private final ShopService shopService;
@@ -417,12 +416,18 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
return false;
}
userDO.setAccount(buildDeletedAccount(userDO));
userDO.setPhone(buildDeletedPhone(userDO));
userDO.setStatus(0);
userDO.setIsDelete(1);
userDO.setUpdateTime(LocalDateTime.now());
return userMapper.updateById(userDO) > 0;
LocalDateTime now = LocalDateTime.now();
return userMapper.update(
null,
new LambdaUpdateWrapper<UserDO>()
.eq(UserDO::getId, id)
.eq(UserDO::getIsDelete, 0)
.set(UserDO::getAccount, buildDeletedAccount(userDO))
.set(UserDO::getPhone, buildDeletedPhone(userDO))
.set(UserDO::getStatus, 0)
.set(UserDO::getIsDelete, 1)
.set(UserDO::getUpdateTime, now)
) > 0;
}
/**
@@ -274,22 +274,26 @@ public class UserShopBindingSupport {
if (userId == null || shopId == null || shopId <= 0) {
return false;
}
List<UserShopBindingDO> bindings = userShopBindingMapper.selectList(new LambdaQueryWrapper<UserShopBindingDO>()
long bindingCount = userShopBindingMapper.selectCount(new LambdaQueryWrapper<UserShopBindingDO>()
.eq(UserShopBindingDO::getUserId, userId)
.eq(UserShopBindingDO::getShopId, shopId)
.eq(UserShopBindingDO::getIsDelete, 0));
if (bindings.isEmpty()) {
if (bindingCount <= 0) {
return false;
}
Integer normalizedStatus = Integer.valueOf(1).equals(status) ? 1 : 0;
LocalDateTime now = LocalDateTime.now();
for (UserShopBindingDO binding : bindings) {
binding.setStatus(normalizedStatus);
binding.setUpdateTime(now);
userShopBindingMapper.updateById(binding);
}
int updated = userShopBindingMapper.update(
null,
new LambdaUpdateWrapper<UserShopBindingDO>()
.eq(UserShopBindingDO::getUserId, userId)
.eq(UserShopBindingDO::getShopId, shopId)
.eq(UserShopBindingDO::getIsDelete, 0)
.set(UserShopBindingDO::getStatus, normalizedStatus)
.set(UserShopBindingDO::getUpdateTime, now)
);
refreshLegacyPrimaryShop(userId);
return true;
return updated > 0;
}
@Transactional(rollbackFor = Exception.class)
@@ -297,21 +301,25 @@ public class UserShopBindingSupport {
if (userId == null || shopId == null || shopId <= 0) {
return false;
}
List<UserShopBindingDO> bindings = userShopBindingMapper.selectList(new LambdaQueryWrapper<UserShopBindingDO>()
long bindingCount = userShopBindingMapper.selectCount(new LambdaQueryWrapper<UserShopBindingDO>()
.eq(UserShopBindingDO::getUserId, userId)
.eq(UserShopBindingDO::getShopId, shopId)
.eq(UserShopBindingDO::getIsDelete, 0));
if (bindings.isEmpty()) {
if (bindingCount <= 0) {
return false;
}
LocalDateTime now = LocalDateTime.now();
for (UserShopBindingDO binding : bindings) {
binding.setIsDelete(1);
binding.setUpdateTime(now);
userShopBindingMapper.updateById(binding);
}
int updated = userShopBindingMapper.update(
null,
new LambdaUpdateWrapper<UserShopBindingDO>()
.eq(UserShopBindingDO::getUserId, userId)
.eq(UserShopBindingDO::getShopId, shopId)
.eq(UserShopBindingDO::getIsDelete, 0)
.set(UserShopBindingDO::getIsDelete, 1)
.set(UserShopBindingDO::getUpdateTime, now)
);
refreshLegacyPrimaryShop(userId);
return true;
return updated > 0;
}
@Transactional(rollbackFor = Exception.class)
@@ -327,11 +335,17 @@ public class UserShopBindingSupport {
}
Set<Long> affectedUserIds = new LinkedHashSet<>();
for (UserShopBindingDO binding : bindings) {
binding.setIsDelete(1);
binding.setUpdateTime(LocalDateTime.now());
userShopBindingMapper.updateById(binding);
affectedUserIds.add(binding.getUserId());
}
LocalDateTime now = LocalDateTime.now();
userShopBindingMapper.update(
null,
new LambdaUpdateWrapper<UserShopBindingDO>()
.eq(UserShopBindingDO::getShopId, shopId)
.eq(UserShopBindingDO::getIsDelete, 0)
.set(UserShopBindingDO::getIsDelete, 1)
.set(UserShopBindingDO::getUpdateTime, now)
);
affectedUserIds.forEach(this::refreshLegacyPrimaryShop);
}