fixed: 异步删除用户信息.
This commit is contained in:
@@ -61,4 +61,29 @@ public interface FavoriteDAO extends IMapper<FavoriteDO> {
|
|||||||
return this.delete(wrapper);
|
return this.delete(wrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过 userId 删除收藏
|
||||||
|
*
|
||||||
|
* @param userId userId
|
||||||
|
* @return effect
|
||||||
|
*/
|
||||||
|
default int deleteFavoriteByUserId(Long userId) {
|
||||||
|
LambdaQueryWrapper<FavoriteDO> wrapper = this.lambda()
|
||||||
|
.eq(FavoriteDO::getUserId, userId);
|
||||||
|
return this.delete(wrapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过 userId 删除收藏
|
||||||
|
*
|
||||||
|
* @param type type
|
||||||
|
* @param userIdList userIdList
|
||||||
|
* @return effect
|
||||||
|
*/
|
||||||
|
default int deleteFavoriteByUserIdList(List<Long> userIdList) {
|
||||||
|
LambdaQueryWrapper<FavoriteDO> wrapper = this.lambda()
|
||||||
|
.in(FavoriteDO::getUserId, userIdList);
|
||||||
|
return this.delete(wrapper);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ public interface FavoriteCacheKeyDefine {
|
|||||||
.key("favorite:{}:{}")
|
.key("favorite:{}:{}")
|
||||||
.desc("收藏信息 ${type} ${userId}")
|
.desc("收藏信息 ${type} ${userId}")
|
||||||
.type(Long.class)
|
.type(Long.class)
|
||||||
.timeout(8, TimeUnit.HOURS)
|
.timeout(3, TimeUnit.DAYS)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,9 +21,6 @@ import java.util.List;
|
|||||||
@Schema(name = "FavoriteQueryRequest", description = "收藏 查询请求对象")
|
@Schema(name = "FavoriteQueryRequest", description = "收藏 查询请求对象")
|
||||||
public class FavoriteQueryRequest extends PageRequest {
|
public class FavoriteQueryRequest extends PageRequest {
|
||||||
|
|
||||||
@Schema(description = "id")
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
@Schema(description = "用户id")
|
@Schema(description = "用户id")
|
||||||
private Long userId;
|
private Long userId;
|
||||||
|
|
||||||
@@ -33,7 +30,4 @@ public class FavoriteQueryRequest extends PageRequest {
|
|||||||
@Schema(description = "收藏类型")
|
@Schema(description = "收藏类型")
|
||||||
private String type;
|
private String type;
|
||||||
|
|
||||||
@Schema(description = "用户id")
|
|
||||||
private List<Long> userIdList;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,6 +70,13 @@ public interface SystemUserService {
|
|||||||
*/
|
*/
|
||||||
Integer deleteSystemUserById(Long id);
|
Integer deleteSystemUserById(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除 id 删除用户拓展信息
|
||||||
|
*
|
||||||
|
* @param id
|
||||||
|
*/
|
||||||
|
void deleteSystemUserRel(Long id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 重置密码
|
* 重置密码
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -112,20 +112,17 @@ public class FavoriteServiceImpl implements FavoriteService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Async("asyncExecutor")
|
|
||||||
public void deleteFavoriteByUserId(Long userId) {
|
public void deleteFavoriteByUserId(Long userId) {
|
||||||
if (userId == null) {
|
if (userId == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// 删除库
|
||||||
|
favoriteDAO.deleteFavoriteByUserId(userId);
|
||||||
// 删除缓存
|
// 删除缓存
|
||||||
List<String> favoriteKeyList = Arrays.stream(FavoriteTypeEnum.values())
|
List<String> favoriteKeyList = Arrays.stream(FavoriteTypeEnum.values())
|
||||||
.map(s -> FavoriteCacheKeyDefine.FAVORITE.format(s, userId))
|
.map(s -> FavoriteCacheKeyDefine.FAVORITE.format(s, userId))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
redisTemplate.delete(favoriteKeyList);
|
redisTemplate.delete(favoriteKeyList);
|
||||||
// 删除库
|
|
||||||
FavoriteQueryRequest request = new FavoriteQueryRequest();
|
|
||||||
request.setUserId(userId);
|
|
||||||
favoriteDAO.delete(this.buildQueryWrapper(request));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -134,6 +131,8 @@ public class FavoriteServiceImpl implements FavoriteService {
|
|||||||
if (Lists.isEmpty(userIdList)) {
|
if (Lists.isEmpty(userIdList)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// 删除库
|
||||||
|
favoriteDAO.deleteFavoriteByUserIdList(userIdList);
|
||||||
// 删除缓存
|
// 删除缓存
|
||||||
List<String> favoriteKeyList = new ArrayList<>();
|
List<String> favoriteKeyList = new ArrayList<>();
|
||||||
for (Long userId : userIdList) {
|
for (Long userId : userIdList) {
|
||||||
@@ -142,10 +141,6 @@ public class FavoriteServiceImpl implements FavoriteService {
|
|||||||
.forEach(favoriteKeyList::add);
|
.forEach(favoriteKeyList::add);
|
||||||
}
|
}
|
||||||
redisTemplate.delete(favoriteKeyList);
|
redisTemplate.delete(favoriteKeyList);
|
||||||
// 删除库
|
|
||||||
FavoriteQueryRequest request = new FavoriteQueryRequest();
|
|
||||||
request.setUserIdList(userIdList);
|
|
||||||
favoriteDAO.delete(this.buildQueryWrapper(request));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -156,11 +151,9 @@ public class FavoriteServiceImpl implements FavoriteService {
|
|||||||
*/
|
*/
|
||||||
private LambdaQueryWrapper<FavoriteDO> buildQueryWrapper(FavoriteQueryRequest request) {
|
private LambdaQueryWrapper<FavoriteDO> buildQueryWrapper(FavoriteQueryRequest request) {
|
||||||
return favoriteDAO.wrapper()
|
return favoriteDAO.wrapper()
|
||||||
.eq(FavoriteDO::getId, request.getId())
|
|
||||||
.eq(FavoriteDO::getUserId, request.getUserId())
|
.eq(FavoriteDO::getUserId, request.getUserId())
|
||||||
.eq(FavoriteDO::getRelId, request.getRelId())
|
.eq(FavoriteDO::getRelId, request.getRelId())
|
||||||
.eq(FavoriteDO::getType, request.getType())
|
.eq(FavoriteDO::getType, request.getType());
|
||||||
.in(FavoriteDO::getUserId, request.getUserIdList());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -96,7 +96,6 @@ public class PreferenceServiceImpl implements PreferenceService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Async("asyncExecutor")
|
|
||||||
public void deletePreferenceByUserId(Long userId) {
|
public void deletePreferenceByUserId(Long userId) {
|
||||||
// 删除
|
// 删除
|
||||||
int effect = preferenceDAO.deleteByUserId(userId);
|
int effect = preferenceDAO.deleteByUserId(userId);
|
||||||
|
|||||||
@@ -14,8 +14,10 @@ import com.orion.ops.framework.redis.core.utils.RedisStrings;
|
|||||||
import com.orion.ops.framework.redis.core.utils.RedisUtils;
|
import com.orion.ops.framework.redis.core.utils.RedisUtils;
|
||||||
import com.orion.ops.framework.security.core.utils.SecurityUtils;
|
import com.orion.ops.framework.security.core.utils.SecurityUtils;
|
||||||
import com.orion.ops.module.infra.convert.SystemUserConvert;
|
import com.orion.ops.module.infra.convert.SystemUserConvert;
|
||||||
|
import com.orion.ops.module.infra.dao.OperatorLogDAO;
|
||||||
import com.orion.ops.module.infra.dao.SystemUserDAO;
|
import com.orion.ops.module.infra.dao.SystemUserDAO;
|
||||||
import com.orion.ops.module.infra.dao.SystemUserRoleDAO;
|
import com.orion.ops.module.infra.dao.SystemUserRoleDAO;
|
||||||
|
import com.orion.ops.module.infra.define.cache.TipsCacheKeyDefine;
|
||||||
import com.orion.ops.module.infra.define.cache.UserCacheKeyDefine;
|
import com.orion.ops.module.infra.define.cache.UserCacheKeyDefine;
|
||||||
import com.orion.ops.module.infra.entity.domain.SystemUserDO;
|
import com.orion.ops.module.infra.entity.domain.SystemUserDO;
|
||||||
import com.orion.ops.module.infra.entity.request.user.*;
|
import com.orion.ops.module.infra.entity.request.user.*;
|
||||||
@@ -25,10 +27,11 @@ import com.orion.ops.module.infra.service.AuthenticationService;
|
|||||||
import com.orion.ops.module.infra.service.FavoriteService;
|
import com.orion.ops.module.infra.service.FavoriteService;
|
||||||
import com.orion.ops.module.infra.service.PreferenceService;
|
import com.orion.ops.module.infra.service.PreferenceService;
|
||||||
import com.orion.ops.module.infra.service.SystemUserService;
|
import com.orion.ops.module.infra.service.SystemUserService;
|
||||||
|
import com.orion.spring.SpringHolder;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.data.redis.core.RedisTemplate;
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
|
import org.springframework.scheduling.annotation.Async;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -51,6 +54,9 @@ public class SystemUserServiceImpl implements SystemUserService {
|
|||||||
@Resource
|
@Resource
|
||||||
private SystemUserRoleDAO systemUserRoleDAO;
|
private SystemUserRoleDAO systemUserRoleDAO;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private OperatorLogDAO operatorLogDAO;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private FavoriteService favoriteService;
|
private FavoriteService favoriteService;
|
||||||
|
|
||||||
@@ -166,7 +172,6 @@ public class SystemUserServiceImpl implements SystemUserService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
|
||||||
public Integer deleteSystemUserById(Long id) {
|
public Integer deleteSystemUserById(Long id) {
|
||||||
if (id.equals(SecurityUtils.getLoginUserId())) {
|
if (id.equals(SecurityUtils.getLoginUserId())) {
|
||||||
throw ErrorCode.UNSUPPOETED.exception();
|
throw ErrorCode.UNSUPPOETED.exception();
|
||||||
@@ -179,15 +184,30 @@ public class SystemUserServiceImpl implements SystemUserService {
|
|||||||
// 删除用户
|
// 删除用户
|
||||||
int effect = systemUserDAO.deleteById(id);
|
int effect = systemUserDAO.deleteById(id);
|
||||||
log.info("SystemUserService-deleteSystemUserById id: {}, effect: {}", id, effect);
|
log.info("SystemUserService-deleteSystemUserById id: {}, effect: {}", id, effect);
|
||||||
|
// 异步删除额外信息
|
||||||
|
SpringHolder.getBean(SystemUserService.class).deleteSystemUserRel(id);
|
||||||
|
return effect;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Async("asyncExecutor")
|
||||||
|
public void deleteSystemUserRel(Long id) {
|
||||||
|
log.info("SystemUserService-deleteSystemUserRel id: {}", id);
|
||||||
|
// 删除用户缓存 需要扫描的 key 让其自动过期
|
||||||
|
redisTemplate.delete(Lists.of(
|
||||||
|
// 用户缓存
|
||||||
|
UserCacheKeyDefine.USER_INFO.format(id),
|
||||||
|
// 用户提示
|
||||||
|
TipsCacheKeyDefine.TIPS.format(id)
|
||||||
|
));
|
||||||
// 删除角色关联
|
// 删除角色关联
|
||||||
effect += systemUserRoleDAO.deleteByUserId(id);
|
systemUserRoleDAO.deleteByUserId(id);
|
||||||
// 删除用户缓存 其他的会自动过期
|
// 删除操作日志
|
||||||
redisTemplate.delete(UserCacheKeyDefine.USER_INFO.format(id));
|
operatorLogDAO.deleteByUserId(id);
|
||||||
// 删除用户收藏
|
// 删除用户收藏
|
||||||
favoriteService.deleteFavoriteByUserId(id);
|
favoriteService.deleteFavoriteByUserId(id);
|
||||||
// 删除用户偏好
|
// 删除用户偏好
|
||||||
preferenceService.deletePreferenceByUserId(id);
|
preferenceService.deletePreferenceByUserId(id);
|
||||||
return effect;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user