Skip to content

Commit c1f950c

Browse files
Copilotbinarywang
andcommitted
修复代码审查问题:避免通配符导入,使用TreeMap保证租户顺序一致性
Co-authored-by: binarywang <1343140+binarywang@users.noreply.github.com>
1 parent 664a5e4 commit c1f950c

2 files changed

Lines changed: 19 additions & 15 deletions

File tree

  • spring-boot-starters

spring-boot-starters/wx-java-miniapp-multi-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/miniapp/configuration/services/AbstractWxMaConfiguration.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@
1616
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
1717
import org.apache.commons.lang3.StringUtils;
1818

19-
import java.util.*;
19+
import java.util.Collection;
20+
import java.util.HashMap;
21+
import java.util.Map;
22+
import java.util.Set;
23+
import java.util.TreeMap;
2024
import java.util.stream.Collectors;
2125

2226
/**
@@ -98,16 +102,12 @@ private WxMaMultiServices createSharedMultiServices(
98102
WxMaService sharedService = createWxMaServiceByType(storage.getHttpClientType());
99103
configureWxMaService(sharedService, storage);
100104

101-
// 准备所有租户的配置
105+
// 准备所有租户的配置,使用 TreeMap 保证顺序一致性
102106
Map<String, WxMaConfig> configsMap = new HashMap<>();
103-
String defaultTenantId = null;
107+
String defaultTenantId = new TreeMap<>(appsMap).firstKey();
104108

105109
for (Map.Entry<String, WxMaSingleProperties> entry : appsMap.entrySet()) {
106110
String tenantId = entry.getKey();
107-
if (defaultTenantId == null) {
108-
defaultTenantId = tenantId;
109-
}
110-
111111
WxMaSingleProperties wxMaSingleProperties = entry.getValue();
112112
WxMaDefaultConfigImpl config = this.wxMaConfigStorage(wxMaMultiProperties);
113113
this.configApp(config, wxMaSingleProperties);

spring-boot-starters/wx-java-mp-multi-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/configuration/services/AbstractWxMpConfiguration.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,21 @@
88
import lombok.RequiredArgsConstructor;
99
import lombok.extern.slf4j.Slf4j;
1010
import me.chanjar.weixin.mp.api.WxMpService;
11-
import me.chanjar.weixin.mp.api.impl.*;
11+
import me.chanjar.weixin.mp.api.impl.WxMpServiceHttpClientImpl;
12+
import me.chanjar.weixin.mp.api.impl.WxMpServiceHttpComponentsImpl;
13+
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
14+
import me.chanjar.weixin.mp.api.impl.WxMpServiceJoddHttpImpl;
15+
import me.chanjar.weixin.mp.api.impl.WxMpServiceOkHttpImpl;
1216
import me.chanjar.weixin.mp.config.WxMpConfigStorage;
1317
import me.chanjar.weixin.mp.config.WxMpHostConfig;
1418
import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;
1519
import org.apache.commons.lang3.StringUtils;
1620

17-
import java.util.*;
21+
import java.util.Collection;
22+
import java.util.HashMap;
23+
import java.util.Map;
24+
import java.util.Set;
25+
import java.util.TreeMap;
1826
import java.util.stream.Collectors;
1927

2028
/**
@@ -97,16 +105,12 @@ private WxMpMultiServices createSharedMultiServices(
97105
WxMpService sharedService = createWxMpServiceByType(storage.getHttpClientType());
98106
configureWxMpService(sharedService, storage);
99107

100-
// 准备所有租户的配置
108+
// 准备所有租户的配置,使用 TreeMap 保证顺序一致性
101109
Map<String, WxMpConfigStorage> configsMap = new HashMap<>();
102-
String defaultTenantId = null;
110+
String defaultTenantId = new TreeMap<>(appsMap).firstKey();
103111

104112
for (Map.Entry<String, WxMpSingleProperties> entry : appsMap.entrySet()) {
105113
String tenantId = entry.getKey();
106-
if (defaultTenantId == null) {
107-
defaultTenantId = tenantId;
108-
}
109-
110114
WxMpSingleProperties wxMpSingleProperties = entry.getValue();
111115
WxMpDefaultConfigImpl config = this.wxMpConfigStorage(wxMpMultiProperties);
112116
this.configApp(config, wxMpSingleProperties);

0 commit comments

Comments
 (0)