|
@@ -1,10 +1,16 @@
|
|
|
package com.kym.common.cache;
|
|
package com.kym.common.cache;
|
|
|
|
|
|
|
|
|
|
+import cn.hutool.extra.spring.SpringUtil;
|
|
|
|
|
+import com.alibaba.fastjson2.JSONObject;
|
|
|
import com.kym.common.utils.PlatformConvertUtil;
|
|
import com.kym.common.utils.PlatformConvertUtil;
|
|
|
import com.kym.entity.admin.Platform;
|
|
import com.kym.entity.admin.Platform;
|
|
|
|
|
+import com.kym.entity.common.RedisKeys;
|
|
|
|
|
+import org.springframework.boot.context.event.ApplicationStartedEvent;
|
|
|
|
|
+import org.springframework.context.ApplicationListener;
|
|
|
|
|
+import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
-import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 平台配置缓存
|
|
* 平台配置缓存
|
|
@@ -14,20 +20,15 @@ import java.util.concurrent.ConcurrentHashMap;
|
|
|
public enum PlatformCache {
|
|
public enum PlatformCache {
|
|
|
INSTANCE;
|
|
INSTANCE;
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * 充电口ID-平台映射
|
|
|
|
|
- */
|
|
|
|
|
- private static ConcurrentHashMap<String, String> CONNECTOR_ID_PLATFORM_NAME_MAPPING = new ConcurrentHashMap<>();
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 站点ID-平台映射
|
|
|
|
|
- */
|
|
|
|
|
- private static ConcurrentHashMap<String, String> STATION_ID_PLATFORM_NAME_MAPPING = new ConcurrentHashMap<>();
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 平台名称-平台配置映射
|
|
|
|
|
|
|
+ * 保存站点id-平台映射
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param map
|
|
|
*/
|
|
*/
|
|
|
- private static ConcurrentHashMap<String, Platform> PLATFORM_CONFIG_MAPPING = new ConcurrentHashMap<>();
|
|
|
|
|
|
|
+ public void putStationId2PlatformName(Map<String, String> map) {
|
|
|
|
|
+ map.forEach((k, v) -> PlatformCacheInjector.redisTemplate.opsForValue().set(RedisKeys.STATION_ID_PLATFORM_NAME + k, v));
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 站点ID获取平台名称
|
|
* 站点ID获取平台名称
|
|
@@ -36,37 +37,46 @@ public enum PlatformCache {
|
|
|
* @return
|
|
* @return
|
|
|
*/
|
|
*/
|
|
|
public String getPlatformNameByStationId(String stationId) {
|
|
public String getPlatformNameByStationId(String stationId) {
|
|
|
- return STATION_ID_PLATFORM_NAME_MAPPING.get(stationId);
|
|
|
|
|
|
|
+ return PlatformCacheInjector.redisTemplate.opsForValue().get(RedisKeys.STATION_ID_PLATFORM_NAME + stationId);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public void putConnectorId2PlatformName(Map<String, String> data) {
|
|
|
|
|
- CONNECTOR_ID_PLATFORM_NAME_MAPPING.putAll(data);
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 枪号-平台名称映射
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param map
|
|
|
|
|
+ */
|
|
|
|
|
+ public void putConnectorId2PlatformName(Map<String, String> map) {
|
|
|
|
|
+ map.forEach((k, v) -> PlatformCacheInjector.redisTemplate.opsForValue().set(RedisKeys.CONNECTOR_ID_PLATFORM_NAME + k, v));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 保存站点id-平台映射
|
|
|
|
|
|
|
+ * 根据枪号获取平台名称
|
|
|
*
|
|
*
|
|
|
- * @param data
|
|
|
|
|
|
|
+ * @param connectorId
|
|
|
|
|
+ * @return
|
|
|
*/
|
|
*/
|
|
|
- public void putStationId2PlatformName(Map<String, String> data) {
|
|
|
|
|
- STATION_ID_PLATFORM_NAME_MAPPING.putAll(data);
|
|
|
|
|
|
|
+ public String getPlatformNameByConnectorId(String connectorId) {
|
|
|
|
|
+ connectorId = PlatformConvertUtil.parse2LocalConnectorId(connectorId);
|
|
|
|
|
+ return PlatformCacheInjector.redisTemplate.opsForValue().get(RedisKeys.CONNECTOR_ID_PLATFORM_NAME + connectorId);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public void putPlatformName2Config(Map<String, Platform> data) {
|
|
|
|
|
- PLATFORM_CONFIG_MAPPING.putAll(data);
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
- public String getPlatformNameByConnectorId(String connectorId) {
|
|
|
|
|
- connectorId = PlatformConvertUtil.parse2LocalConnectorId(connectorId);
|
|
|
|
|
- return CONNECTOR_ID_PLATFORM_NAME_MAPPING.get(connectorId);
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 保存平台名称-配置
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param map
|
|
|
|
|
+ */
|
|
|
|
|
+ public void putPlatformName2Config(Map<String, Platform> map) {
|
|
|
|
|
+ map.forEach((k, v) -> PlatformCacheInjector.redisTemplate.opsForValue().set(RedisKeys.PLATFORM_NAME_CONFIG + k, JSONObject.toJSONString(v)));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
public Platform getPlatformByName(String... platformName) {
|
|
public Platform getPlatformByName(String... platformName) {
|
|
|
var name = "EN_PLUS";
|
|
var name = "EN_PLUS";
|
|
|
if (platformName.length > 0 && platformName[0] != null) {
|
|
if (platformName.length > 0 && platformName[0] != null) {
|
|
|
name = platformName[0];
|
|
name = platformName[0];
|
|
|
}
|
|
}
|
|
|
- return PLATFORM_CONFIG_MAPPING.get(name);
|
|
|
|
|
|
|
+ return JSONObject.parseObject(PlatformCacheInjector.redisTemplate.opsForValue().get(RedisKeys.PLATFORM_NAME_CONFIG + name), Platform.class);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -78,7 +88,17 @@ public enum PlatformCache {
|
|
|
public Platform getPlatformByConnectorId(String connectorId) {
|
|
public Platform getPlatformByConnectorId(String connectorId) {
|
|
|
connectorId = PlatformConvertUtil.parse2LocalConnectorId(connectorId);
|
|
connectorId = PlatformConvertUtil.parse2LocalConnectorId(connectorId);
|
|
|
var platformName = getPlatformNameByConnectorId(connectorId);
|
|
var platformName = getPlatformNameByConnectorId(connectorId);
|
|
|
- return PLATFORM_CONFIG_MAPPING.get(platformName);
|
|
|
|
|
|
|
+ return getPlatformByName(platformName);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Component
|
|
|
|
|
+ public static class PlatformCacheInjector implements ApplicationListener<ApplicationStartedEvent> {
|
|
|
|
|
+ private static final StringRedisTemplate redisTemplate = SpringUtil.getBean(StringRedisTemplate.class);
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onApplicationEvent(ApplicationStartedEvent event) {
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|