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