Skip to content

Commit

Permalink
修复多实例情况下,消息类型错误。
Browse files Browse the repository at this point in the history
  • Loading branch information
lWoHvYe committed Apr 1, 2022
1 parent cd1dbfe commit 369bcca
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,10 @@ public void sendSyncDelayMsg(String routeKey, AmqpMsgEntity commonEntity) {
commonEntity.setExpire(500L).setTimeUnit(TimeUnit.MILLISECONDS);
sendDelayMsg(RabbitMqConfig.TOPIC_SYNC_DELAY_EXCHANGE, routeKey, commonEntity);
}

public void sendSyncDelayMsgEntity(String routeKey, AmqpMsgEntity commonEntity) {
// 延时500ms
commonEntity.setExpire(500L).setTimeUnit(TimeUnit.MILLISECONDS);
sendDelayMsgEntity(RabbitMqConfig.TOPIC_SYNC_DELAY_EXCHANGE, routeKey, commonEntity);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public void cleanUserCache(String userName, Boolean doSync) {
if (StringUtils.isNotEmpty(userName)) {
if (Boolean.TRUE.equals(doSync)) { // 广播事件
var amqpMsg = new AmqpMsgEntity().setMsgType("sp").setMsgData(userName).setExtraData("cleanUserCache").setOrigin(LocalCoreConfig.ORIGIN);
rabbitMQProducerService.sendSyncDelayMsg(RabbitMqConfig.SP_SYNC_ROUTE_KEY, amqpMsg);
rabbitMQProducerService.sendSyncDelayMsgEntity(RabbitMqConfig.SP_SYNC_ROUTE_KEY, amqpMsg);
}
userLRUCache.invalidate(userName); // 清除单个key
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ public interface UserRepository extends JpaRepository<User, Long>, JpaSpecificat
void updateEmail(String username, String email);

@Modifying
@Query(value = "update sys_user set enabled = ?2 where username = ?1", nativeQuery = true)
void updateEnabled(String username, Boolean enabled);
@Query(value = "update sys_user set enabled = ?3 where username = ?1 and enabled = ?2", nativeQuery = true)
void updateEnabled(String username, Boolean expectStatus, Boolean enabled);

/**
* 根据角色查询用户
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ public void updateEmail(String username, String email) {
@CacheEvict(allEntries = true)
public void updateEnabled(String username, Boolean enabled) {
Assert.hasText(username, "用户名不可为空");
userRepository.updateEnabled(username, enabled);
userRepository.updateEnabled(username, !enabled, enabled);
// 状态更新后,需清除相关信息
flushCache(username);
}
Expand Down

0 comments on commit 369bcca

Please sign in to comment.