🐛 #1600 修复无法切换到初始公众号配置的问题并完善了removeConfigStorage方法

* 修复无法切换到初始公众号配置的问题

* 完善removeConfigStorage
This commit is contained in:
马肇明 2020-06-03 13:46:43 +08:00 committed by GitHub
parent 1c60839890
commit b52e676040
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -414,7 +414,7 @@ public abstract class BaseWxMpServiceImpl<H, P> implements WxMpService, RequestH
@Override
public void setWxMpConfigStorage(WxMpConfigStorage wxConfigProvider) {
final String defaultMpId = WxMpConfigStorageHolder.get();
final String defaultMpId = wxConfigProvider.getAppId();
this.setMultiConfigStorages(ImmutableMap.of(defaultMpId, wxConfigProvider), defaultMpId);
}
@ -440,6 +440,18 @@ public abstract class BaseWxMpServiceImpl<H, P> implements WxMpService, RequestH
@Override
public void removeConfigStorage(String mpId) {
synchronized (this) {
if (this.configStorageMap.size() == 1) {
this.configStorageMap.remove(mpId);
log.warn("已删除最后一个公众号配置:{}须立即使用setWxMpConfigStorage或setMultiConfigStorages添加配置", mpId);
return;
}
if (WxMpConfigStorageHolder.get().equals(mpId)) {
this.configStorageMap.remove(mpId);
final String defaultMpId = this.configStorageMap.keySet().iterator().next();
WxMpConfigStorageHolder.set(defaultMpId);
log.warn("已删除默认公众号配置,公众号【{}】被设为默认配置", defaultMpId);
return;
}
this.configStorageMap.remove(mpId);
}
}

View File

@ -41,6 +41,7 @@ public class BaseWxMpServiceImplTest {
assertTrue(this.wxService.switchover("another"));
assertThat(WxMpConfigStorageHolder.get()).isEqualTo("another");
assertFalse(this.wxService.switchover("whatever"));
assertFalse(this.wxService.switchover("default"));
}
@Test