public
TStationStatusInfoTotal queryStationStatus(List<String> stationIds) {TStationStatusInfoTotal stations = new TStationStatusInfoTotal();
//使用pipeline hgetall
Jedis jedis = jedisPool.getResource();
Pipeline jcp = jedis.pipelined();
/**
* 通过stationIDs获取connectionIDs
* 注 :以下connectionIDs 简称 cIds ps:cIds存储格式以逗号分隔 eg:1001,1002,1003
* stationIDs简称 sIds
*/
Map<String, Response<Map<String, String>>> responses = new HashMap<String, Response<Map<String, String>>>(stationIds.size());
for (String key : stationIds) {//遍历stationIds
responses.put(key, jcp.hgetAll(RedisKeysDefine.STATION_HASH_KEY+key));// 根据stationId put电站下的所属cIds 及其他属性
}
jcp.sync();
/**
* 查询所有stationIds接口状态
*/
Map<String, Map<String, Response<Map<String, String>>>> stationResls = new HashMap<String, Map<String, Response<Map<String, String>>>>();
for (String k : responses.keySet()) {//遍历单个电站下的属性 eg:cIds status
Map<String, String> rr = responses.get(k).get();
Map<String, Response<Map<String, String>>> connectRes = new HashMap<String, Response<Map<String, String>>>();
if(rr !=null){
String cIds=rr.get(RedisKeysDefine.STA_HASH_COLUMN_CONNECTOR_IDS);//从单个电站下取出cIds
String[] arr=cIds.split(",");
for (String connectId : arr) {//遍历cIds
connectRes.put(connectId, jcp.hgetAll(RedisKeysDefine.RT_HASH_KEY+connectId));//根据cId put接口下的所有属性
}
stationResls.put(k,connectRes);
}
}
jcp.sync();
jedis.close();
List<TStationStatusInfo> sInfols=new ArrayList<TStationStatusInfo>();
for (String k : stationResls.keySet()){
Map<String, Response<Map<String, String>>> cRes2 = stationResls.get(k);
List<TConnectorStatusInfo> cInfols = new ArrayList<TConnectorStatusInfo>();
for (String cId : cRes2.keySet()) {
Map<String, String> cc = cRes2.get(cId).get();
if(cc != null ){
TConnectorStatusInfo info = new TConnectorStatusInfo();
info.setConnectorID(cId);
String value = cc.get(RedisKeysDefine.RT_HASH_COLUMN_STATUS);
if(value!=null){
info.setStatus(Integer.parseInt(value));
}
value = cc.get(RedisKeysDefine.RT_HASH_COLUMN_PARKSTATUS);
if(value!=null){
info.setParkStatus(Integer.parseInt(value));
}
value = cc.get(RedisKeysDefine.RT_HASH_COLUMN_PARKSTATUS);
if(value!=null){
info.setLockStatus(Integer.parseInt(value));
}
cInfols.add(info);
}
}
TStationStatusInfo sInfo=new TStationStatusInfo();
sInfo.setStationID(k);
sInfo.setConnectorStatusInfos(cInfols);
sInfols.add(sInfo);
}
stations.setTotal(stationIds.size());
stations.setStationStatusInfos(sInfols);
return stations;
}