|
@@ -19,6 +19,8 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.DigestUtils;
|
|
import org.springframework.util.DigestUtils;
|
|
|
import org.springframework.util.StringUtils;
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
|
|
+import java.util.Collections;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -169,7 +171,7 @@ public class AdminServiceImpl extends ServiceImpl<AppUserMapper, AppUser> implem
|
|
|
if (Integer.valueOf(1).equals(admin.getAdminRole())) {
|
|
if (Integer.valueOf(1).equals(admin.getAdminRole())) {
|
|
|
throw new BusinessException(ResultCode.ADMIN_CANNOT_DELETE);
|
|
throw new BusinessException(ResultCode.ADMIN_CANNOT_DELETE);
|
|
|
}
|
|
}
|
|
|
- removeById(id);
|
|
|
|
|
|
|
+ logicDeleteAdminsAndReleaseUniqueFields(Collections.singletonList(id));
|
|
|
LogUtil.info(AdminServiceImpl.class, "删除管理员[{}]", id);
|
|
LogUtil.info(AdminServiceImpl.class, "删除管理员[{}]", id);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -181,20 +183,35 @@ public class AdminServiceImpl extends ServiceImpl<AppUserMapper, AppUser> implem
|
|
|
*/
|
|
*/
|
|
|
@Override
|
|
@Override
|
|
|
public void batchDeleteAdmin(List<Long> ids) {
|
|
public void batchDeleteAdmin(List<Long> ids) {
|
|
|
- for (Long id : ids) {
|
|
|
|
|
- AppUser admin = getById(id);
|
|
|
|
|
- if (admin != null && Integer.valueOf(1).equals(admin.getAdminRole())) {
|
|
|
|
|
|
|
+ if (ids == null || ids.isEmpty()) {
|
|
|
|
|
+ throw new BusinessException(ResultCode.PARAM_ERROR);
|
|
|
|
|
+ }
|
|
|
|
|
+ List<AppUser> admins = lambdaQuery()
|
|
|
|
|
+ .in(AppUser::getId, ids)
|
|
|
|
|
+ .eq(AppUser::getUserType, 3)
|
|
|
|
|
+ .list();
|
|
|
|
|
+ for (AppUser admin : admins) {
|
|
|
|
|
+ if (Integer.valueOf(1).equals(admin.getAdminRole())) {
|
|
|
throw new BusinessException(ResultCode.ADMIN_CANNOT_DELETE);
|
|
throw new BusinessException(ResultCode.ADMIN_CANNOT_DELETE);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- // 仅删除 userType=3 的记录,防止误删其他类型用户
|
|
|
|
|
- LambdaQueryWrapper<AppUser> wrapper = new LambdaQueryWrapper<AppUser>()
|
|
|
|
|
- .in(AppUser::getId, ids)
|
|
|
|
|
- .eq(AppUser::getUserType, 3);
|
|
|
|
|
- remove(wrapper);
|
|
|
|
|
|
|
+ if (!admins.isEmpty()) {
|
|
|
|
|
+ logicDeleteAdminsAndReleaseUniqueFields(ids);
|
|
|
|
|
+ }
|
|
|
LogUtil.info(AdminServiceImpl.class, "批量删除管理员,ID列表:{}", ids);
|
|
LogUtil.info(AdminServiceImpl.class, "批量删除管理员,ID列表:{}", ids);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private void logicDeleteAdminsAndReleaseUniqueFields(List<Long> ids) {
|
|
|
|
|
+ lambdaUpdate()
|
|
|
|
|
+ .in(AppUser::getId, ids)
|
|
|
|
|
+ .eq(AppUser::getUserType, 3)
|
|
|
|
|
+ .set(AppUser::getUsername, null)
|
|
|
|
|
+ .set(AppUser::getPhone, null)
|
|
|
|
|
+ .set(AppUser::getDeleted, 1)
|
|
|
|
|
+ .set(AppUser::getUpdateTime, LocalDateTime.now())
|
|
|
|
|
+ .update();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 修改管理员状态(禁用/启用)
|
|
* 修改管理员状态(禁用/启用)
|
|
|
* 不允许禁用当前登录账号自身
|
|
* 不允许禁用当前登录账号自身
|