|
@@ -36,6 +36,7 @@ import java.util.ArrayList;
|
|
|
import java.util.LinkedHashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.concurrent.ConcurrentHashMap;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Slf4j
|
|
@@ -98,20 +99,7 @@ public class WxMaConfiguration {
|
|
|
}
|
|
|
|
|
|
public static WxMaService getMaService(String appid) {
|
|
|
- // 从缓存获取
|
|
|
- WxMaService wxService = maServices.get(appid);
|
|
|
- if (wxService != null) {
|
|
|
- return wxService;
|
|
|
- }
|
|
|
-
|
|
|
- // 缓存未命中,查询数据库
|
|
|
- synchronized (WxMaConfiguration.class) {
|
|
|
- // 双重检查
|
|
|
- wxService = maServices.get(appid);
|
|
|
- if (wxService != null) {
|
|
|
- return wxService;
|
|
|
- }
|
|
|
-
|
|
|
+ return maServices.computeIfAbsent(appid,e->{
|
|
|
// 查询数据库
|
|
|
FsCoursePlaySourceConfigMapper configMapper = SpringUtils.getBean(FsCoursePlaySourceConfigMapper.class);
|
|
|
Wrapper<FsCoursePlaySourceConfig> queryWrapper = Wrappers.<FsCoursePlaySourceConfig>lambdaQuery()
|
|
@@ -122,11 +110,8 @@ public class WxMaConfiguration {
|
|
|
throw new IllegalArgumentException(String.format("未找到对应appid=[%s]的配置,请核实!", appid));
|
|
|
}
|
|
|
|
|
|
- WxMaService service = getWxMaService(config.getAppid(), config.getSecret(), config.getToken(), config.getAesKey(), config.getMsgDataFormat());
|
|
|
- maServices.put(appid, service);
|
|
|
- log.info("Initialized WxMaService for appid: {}", appid);
|
|
|
- return service;
|
|
|
- }
|
|
|
+ return getWxMaService(config.getAppid(), config.getSecret(), config.getToken(), config.getAesKey(), config.getMsgDataFormat());
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -165,7 +150,7 @@ public class WxMaConfiguration {
|
|
|
s -> s.getWxMaConfig().getAppid(),
|
|
|
a -> a,
|
|
|
(existing, replacement) -> replacement,
|
|
|
- LinkedHashMap::new
|
|
|
+ ConcurrentHashMap::new
|
|
|
));
|
|
|
}
|
|
|
|