mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-20 11:05:18 +08:00
新增 批量查询枪口列表接口
This commit is contained in:
@@ -128,4 +128,11 @@ public interface PileConnectorInfoMapper {
|
||||
* @return
|
||||
*/
|
||||
PileConnectorInfoVO getConnectorInfoByParams(@Param("dto") QueryConnectorInfoDTO dto);
|
||||
|
||||
/**
|
||||
* 通过站点idList查询枪口列表信息
|
||||
* @param stationIds
|
||||
* @return
|
||||
*/
|
||||
List<ConnectorInfoVO> batchSelectConnectorList(@Param("stationIds") List<String> stationIds);
|
||||
}
|
||||
|
||||
@@ -114,6 +114,13 @@ public interface PileConnectorInfoService {
|
||||
|
||||
List<ConnectorInfoVO> getConnectorListForLianLian(Long stationId);
|
||||
|
||||
/**
|
||||
* 根据站点idList批量查询枪口数据
|
||||
* @param stationIds
|
||||
* @return
|
||||
*/
|
||||
List<ConnectorInfoVO> batchSelectConnectorList(List<String> stationIds);
|
||||
|
||||
List<ConnectorInfoVO> selectConnectorInfoList(String pileSn);
|
||||
|
||||
PageResponse selectStationConnectorList(QueryConnectorListDTO dto);
|
||||
|
||||
@@ -46,10 +46,7 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -484,10 +481,67 @@ public class PileConnectorInfoServiceImpl implements PileConnectorInfoService {
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ConnectorInfoVO> getConnectorListForLianLian(Long stationId) {
|
||||
return getUniAppConnectorList(stationId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量查询枪口列表接口
|
||||
* @param stationIds
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<ConnectorInfoVO> batchSelectConnectorList(List<String> stationIds){
|
||||
List<ConnectorInfoVO> resultList = new ArrayList<>();
|
||||
Map<String, List<ConnectorInfoVO>> map = new LinkedHashMap<>();
|
||||
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);
|
||||
}
|
||||
}
|
||||
// 先将已经有数据的stationId进行收集
|
||||
List<String> hasDataStationIds = new ArrayList<>(map.keySet());
|
||||
Collection<List<ConnectorInfoVO>> values = map.values();
|
||||
// 筛选出没有数据的stationIds
|
||||
List<String> noDataStationIds = stationIds.stream()
|
||||
.filter(x -> !hasDataStationIds.contains(x))
|
||||
.collect(Collectors.toList());
|
||||
if (CollectionUtils.isNotEmpty(noDataStationIds)) {
|
||||
// 重新查询数据库
|
||||
// 通过stationIds批量查询数据库
|
||||
List<ConnectorInfoVO> newConnectorInfoList = pileConnectorInfoMapper.batchSelectConnectorList(noDataStationIds);
|
||||
|
||||
values.add(newConnectorInfoList);
|
||||
|
||||
// 设置缓存
|
||||
// 先将list根据站点id分组
|
||||
Map<String, List<ConnectorInfoVO>> collect = newConnectorInfoList.stream()
|
||||
.collect(Collectors.groupingBy(ConnectorInfoVO::getStationId));
|
||||
// 循环map并设置缓存
|
||||
for (Map.Entry<String, List<ConnectorInfoVO>> entry : collect.entrySet()) {
|
||||
String stationId = entry.getKey();
|
||||
List<ConnectorInfoVO> voList = entry.getValue();
|
||||
|
||||
String redisKey = baseRedisKey + stationId;
|
||||
redisCache.setCacheObject(redisKey, voList, CacheConstants.cache_expire_time_1h);
|
||||
}
|
||||
}
|
||||
|
||||
// 最终将 values 中的所有 ConnectorInfoVO 元素收集到 resultList
|
||||
values.forEach(resultList::addAll);
|
||||
|
||||
return resultList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ConnectorInfoVO> selectConnectorInfoList(String pileSn) {
|
||||
// log.info("查询充电枪口详情-selectConnectorInfoList, param:{}", pileSn);
|
||||
|
||||
Reference in New Issue
Block a user