fix(file): 修复文件锁定逻辑中的竞态条件问题

- 添加了 Redis 键不存在时的条件检查分支
- 实现了 setIfAbsent 原子操作避免并发锁定冲突
- 移除了冗余的锁定失败兜底错误提示
- 优化了分布式锁的实现机制
This commit is contained in:
曹鹏飞 2026-06-10 08:25:07 +08:00
parent 5bc84a02f3
commit 7bd3cb7134
1 changed files with 2 additions and 2 deletions

View File

@ -653,9 +653,9 @@ public class QmsFileControllerService {
User lockedUser = userService.getById(lockedUserId);
VUtil.trueThrowBusinessError(true).throwMessage("文件已被用户【" + lockedUser.getUserName() + "】锁定");
}
}else {
redisTemplate.opsForValue().setIfAbsent(key, currentUserId, 15, TimeUnit.SECONDS);
}
// key 在两次 Redis 操作间隙恰好过期仍属于锁定失败需兜底报错
VUtil.trueThrowBusinessError(true).throwMessage("文件已被锁定");
} else {
file.setCurrentLockUserName(UserUtil.getUserName());
fileService.updateById(file);