|
@@ -70,4 +70,33 @@ public class ConfigUtil {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ public JSONObject generateConfigMiniByKey(String key, String appId) {
|
|
|
+
|
|
|
+ SysConfig sysConfig = sysConfigMapper.selectConfigByConfigKey(key);
|
|
|
+ if (sysConfig == null) {
|
|
|
+ throw new RuntimeException("未找到key为[" + key + "]的配置");
|
|
|
+ }
|
|
|
+
|
|
|
+ String configValue = sysConfig.getConfigValue();
|
|
|
+ if (configValue == null || configValue.trim().isEmpty()) {
|
|
|
+ throw new RuntimeException("key为[" + key + "]的配置值为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (configValue.trim().startsWith("[")) {
|
|
|
+ JSONArray array = JSON.parseArray(configValue);
|
|
|
+
|
|
|
+ return array.stream()
|
|
|
+ .map(obj -> (JSONObject) obj)
|
|
|
+ .filter(json -> appId.equals(json.getString("appid")))
|
|
|
+ .findFirst()
|
|
|
+ .orElseThrow(() -> new RuntimeException("未找到与appId[" + appId + "]匹配的配置"));
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(configValue);
|
|
|
+ if (!appId.equals(jsonObject.getString("appId"))) {
|
|
|
+ throw new RuntimeException("配置的appId与当前appId[" + appId + "]不匹配");
|
|
|
+ }
|
|
|
+ return jsonObject;
|
|
|
+ }
|
|
|
+
|
|
|
}
|