|
|
@@ -3,8 +3,8 @@ package com.kym.service.cache;
|
|
|
import cn.hutool.extra.spring.SpringUtil;
|
|
|
import com.kym.common.exception.BusinessException;
|
|
|
import com.kym.common.utils.CommUtil;
|
|
|
-import com.kym.entity.common.RedisKeys;
|
|
|
import com.kym.entity.WashStation;
|
|
|
+import com.kym.entity.common.RedisKeys;
|
|
|
import com.kym.service.WashStationService;
|
|
|
import org.springframework.boot.context.event.ApplicationStartedEvent;
|
|
|
import org.springframework.context.ApplicationListener;
|
|
|
@@ -20,75 +20,42 @@ import java.util.stream.Collectors;
|
|
|
/**
|
|
|
* @author skyline
|
|
|
* @description 缓存
|
|
|
- * @date 2023-08-25 22:58
|
|
|
*/
|
|
|
public enum KymCache {
|
|
|
INSTANCE;
|
|
|
|
|
|
-
|
|
|
- private static ConcurrentHashMap<String, String> CONNECTOR_ID_SHORT_ID_MAPPING = new ConcurrentHashMap<>();
|
|
|
- private static ConcurrentHashMap<String, String> SHORT_ID_TO_PRODUCT_KEY_AND_DEVICE_NAME_MAPPING = new ConcurrentHashMap<>();
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取枪头状态
|
|
|
- *
|
|
|
- * @param connectorId
|
|
|
- * @return
|
|
|
- */
|
|
|
- public Integer getConnectorStatus(String connectorId) {
|
|
|
- return Integer.valueOf(Objects.requireNonNull(KymCacheInjector.redisTemplate.opsForValue().get(RedisKeys.CONNECTOR_ID_TO_STATUS + connectorId)));
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
- * 缓存枪头状态
|
|
|
- *
|
|
|
- * @param map
|
|
|
+ * 短编号与设备信息映射
|
|
|
*/
|
|
|
- public void putConnectorId2Status(Map<String, Integer> map) {
|
|
|
- map.forEach((k, v) -> KymCacheInjector.redisTemplate.opsForValue().set(RedisKeys.CONNECTOR_ID_TO_STATUS + k, String.valueOf(v)));
|
|
|
- }
|
|
|
+ private static ConcurrentHashMap<String, String> SHORT_ID_TO_PRODUCT_KEY_AND_DEVICE_NAME_MAPPING = new ConcurrentHashMap<>();
|
|
|
|
|
|
|
|
|
/**
|
|
|
- * 缓存枪头短编号
|
|
|
+ * 站点id与商户id映射
|
|
|
*
|
|
|
* @param map
|
|
|
*/
|
|
|
- public void putConnectorId2ShortId(Map<String, String> map) {
|
|
|
- CONNECTOR_ID_SHORT_ID_MAPPING.putAll(map);
|
|
|
- map.forEach((k, v) -> KymCacheInjector.redisTemplate.opsForValue().set(RedisKeys.CONNECTOR_ID_TO_SHORT_ID + k, v));
|
|
|
+ public static void putStationId2MerchantId(Map<String, String> map) {
|
|
|
+ map.forEach((k, v) -> KymCacheInjector.redisTemplate.opsForValue().set(RedisKeys.STATION_ID_TO_MERCHANT_ID + k, v));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 通过设备编号或者枪头编号获取设备短编号
|
|
|
+ * 站点id与站点名称映射
|
|
|
*
|
|
|
- * @param id
|
|
|
- * @return
|
|
|
+ * @param map
|
|
|
*/
|
|
|
- public String getShortIdByEquipmentIdOrConnectorId(String id) {
|
|
|
- var connectorId = getConnectorId(id);
|
|
|
- return KymCacheInjector.redisTemplate.opsForValue().get(RedisKeys.CONNECTOR_ID_TO_SHORT_ID + connectorId);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- public void putConnectorId2StationId(Map<String, String> map) {
|
|
|
- map.forEach((k, v) -> KymCacheInjector.redisTemplate.opsForValue().set(RedisKeys.CONNECTOR_ID_TO_STATION_ID + k, v));
|
|
|
+ public static void putStationId2Name(Map<String, String> map) {
|
|
|
+ map.forEach((k, v) -> KymCacheInjector.redisTemplate.opsForValue().set(RedisKeys.STATION_ID_TO_NAME + k, v));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 通过设备编号或者枪头编号获取站点id
|
|
|
+ * 通过站点id获取商户id
|
|
|
*
|
|
|
- * @param id
|
|
|
+ * @param stationId
|
|
|
* @return
|
|
|
*/
|
|
|
- public String getStationIdByEquipmentIdOrConnectorId(String id) {
|
|
|
- var connectorId = getConnectorId(id);
|
|
|
- return KymCacheInjector.redisTemplate.opsForValue().get(RedisKeys.CONNECTOR_ID_TO_STATION_ID + connectorId);
|
|
|
- }
|
|
|
-
|
|
|
- public static void putStationId2Name(Map<String, String> map) {
|
|
|
- map.forEach((k, v) -> KymCacheInjector.redisTemplate.opsForValue().set(RedisKeys.STATION_ID_TO_NAME + k, v));
|
|
|
+ public String getMerchantIdByStationId(String stationId) {
|
|
|
+ return KymCacheInjector.redisTemplate.opsForValue().get(RedisKeys.STATION_ID_TO_MERCHANT_ID + stationId);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -101,16 +68,6 @@ public enum KymCache {
|
|
|
return KymCacheInjector.redisTemplate.opsForValue().get(RedisKeys.STATION_ID_TO_NAME + stationId);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 通过充电接口id获取站点名称
|
|
|
- *
|
|
|
- * @param connectorId
|
|
|
- * @return
|
|
|
- */
|
|
|
- public String getStationNameByConnectorId(String connectorId) {
|
|
|
- var stationId = getStationIdByEquipmentIdOrConnectorId(connectorId);
|
|
|
- return KymCacheInjector.redisTemplate.opsForValue().get(RedisKeys.STATION_ID_TO_NAME + stationId);
|
|
|
- }
|
|
|
|
|
|
/**
|
|
|
* 操作员对应有权限的站点
|
|
|
@@ -126,46 +83,6 @@ public enum KymCache {
|
|
|
}
|
|
|
|
|
|
|
|
|
- /**
|
|
|
- * 获取运营平台操作员有权限的站点ID
|
|
|
- *
|
|
|
- * @param adminUserId
|
|
|
- * @return
|
|
|
- */
|
|
|
- public List<String> getAdminUserStationIds(Long adminUserId) {
|
|
|
- return KymCacheInjector.redisTemplate.opsForSet().members(RedisKeys.ADMIN_USER_STATION_IDS + adminUserId).stream().toList();
|
|
|
- }
|
|
|
-
|
|
|
- public void putConnectorId2ParkingNo(Map<String, String> map) {
|
|
|
- map.forEach((k, v) -> KymCacheInjector.redisTemplate.opsForValue().set(RedisKeys.CONNECTOR_ID_TO_PARKING_NO + k, v));
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @param id
|
|
|
- * @return
|
|
|
- */
|
|
|
- public String getParkNoByEquipmentIdOrConnectorId(String id) {
|
|
|
- var connectorId = getConnectorId(id);
|
|
|
- return KymCacheInjector.redisTemplate.opsForValue().get(RedisKeys.CONNECTOR_ID_TO_PARKING_NO + connectorId);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 将equipmentId,connectorId,shortId转化成17为的connectorId
|
|
|
- *
|
|
|
- * @param id
|
|
|
- * @return
|
|
|
- */
|
|
|
- public String getConnectorId(String id) {
|
|
|
- return switch (id.length()) {
|
|
|
- case 17 -> id;
|
|
|
- case 16 -> id.concat("1");
|
|
|
- case 6 ->
|
|
|
- CONNECTOR_ID_SHORT_ID_MAPPING.entrySet().stream().filter(entry -> id.equals(entry.getValue())).map(Map.Entry::getKey).findFirst().get();
|
|
|
- default -> null;
|
|
|
- };
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
/**
|
|
|
* 缓存短编号和设备信息
|
|
|
*
|