mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-20 11:05:18 +08:00
update 通过stationIds批量查询枪口列表方法
This commit is contained in:
@@ -494,20 +494,28 @@ public class PileConnectorInfoServiceImpl implements PileConnectorInfoService {
|
||||
@Override
|
||||
public List<ConnectorInfoVO> batchSelectConnectorList(List<String> stationIds){
|
||||
List<ConnectorInfoVO> resultList = new ArrayList<>();
|
||||
Map<String, List<ConnectorInfoVO>> map = new LinkedHashMap<>();
|
||||
Map<String, List<ConnectorInfoVO>> map;
|
||||
String baseRedisKey = CacheConstants.GET_UNIAPP_CONNECTOR_LIST_BY_STATION_ID;
|
||||
// 先查询缓存数据
|
||||
for (String stationId : stationIds) {
|
||||
String redisKey = baseRedisKey + stationId;
|
||||
List<ConnectorInfoVO> list = redisCache.getCacheList(redisKey);
|
||||
if (CollectionUtils.isNotEmpty(list)) {
|
||||
map.put(stationId, list);
|
||||
// 重新设置缓存
|
||||
redisCache.deleteObject(redisKey);
|
||||
redisCache.setCacheList(redisKey, list);
|
||||
redisCache.expire(redisKey, CacheConstants.cache_expire_time_1h);
|
||||
// 先批量查缓存
|
||||
List<String> redisKeys = new ArrayList<>();
|
||||
stationIds.forEach(stationId ->
|
||||
redisKeys.add(CacheConstants.GET_UNIAPP_CONNECTOR_LIST_BY_STATION_ID + stationId));
|
||||
List<Object> redisObjects = redisCache.multiGet(redisKeys);
|
||||
List<ConnectorInfoVO> list = new ArrayList<>();
|
||||
for (Object redisObject : redisObjects) {
|
||||
if (redisObject == null) {
|
||||
continue;
|
||||
}
|
||||
JSONArray array = JSONArray.parseArray(JSON.toJSONString(redisObject));
|
||||
for (Object o : array) {
|
||||
ConnectorInfoVO connectorInfoVO = JSONObject.parseObject(JSON.toJSONString(o), ConnectorInfoVO.class);
|
||||
list.add(connectorInfoVO);
|
||||
}
|
||||
}
|
||||
// 按照stationId分组
|
||||
map = list.stream()
|
||||
.collect(Collectors.groupingBy(ConnectorInfoVO::getStationId));
|
||||
|
||||
// 先将已经有数据的stationId进行收集
|
||||
List<String> hasDataStationIds = new ArrayList<>(map.keySet());
|
||||
List<List<ConnectorInfoVO>> values = new ArrayList<>(map.values());
|
||||
@@ -528,15 +536,19 @@ public class PileConnectorInfoServiceImpl implements PileConnectorInfoService {
|
||||
// 先将list根据站点id分组
|
||||
Map<String, List<ConnectorInfoVO>> collect = newConnectorInfoList.stream()
|
||||
.collect(Collectors.groupingBy(ConnectorInfoVO::getStationId));
|
||||
// 循环map并设置缓存
|
||||
// 循环map并设置缓存key值
|
||||
Map<String, List<ConnectorInfoVO>> redisMap = new LinkedHashMap<>();
|
||||
for (Map.Entry<String, List<ConnectorInfoVO>> entry : collect.entrySet()) {
|
||||
String stationId = entry.getKey();
|
||||
String redisKey = baseRedisKey + stationId;
|
||||
|
||||
List<ConnectorInfoVO> voList = entry.getValue();
|
||||
|
||||
String redisKey = baseRedisKey + stationId;
|
||||
redisCache.setCacheList(redisKey, voList);
|
||||
redisCache.expire(redisKey, CacheConstants.cache_expire_time_1h);
|
||||
redisMap.put(redisKey, voList);
|
||||
}
|
||||
// 批量设置缓存
|
||||
redisCache.batchSetCacheList(redisMap, CacheConstants.cache_expire_time_1h, TimeUnit.SECONDS);
|
||||
// redisCache.multiSave(redisMap, CacheConstants.cache_expire_time_1h);
|
||||
}
|
||||
|
||||
// 最终将 values 中的所有 ConnectorInfoVO 元素收集到 resultList
|
||||
|
||||
Reference in New Issue
Block a user