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