|
@@ -601,140 +601,86 @@ public class EdosUtil implements IRealTimeDataBaseUtil {
|
|
|
public List<PointData> getRealData(String... pointids) throws Exception {
|
|
|
|
|
|
|
|
|
- if(StringUtils.notEmp(pointids) )
|
|
|
- {
|
|
|
- List<String> idls=new ArrayList<>();
|
|
|
- for(String str:pointids)
|
|
|
- {
|
|
|
- if(StringUtils.notEmp(str) && !V2Config.getInitialcode().equals(str))
|
|
|
- {
|
|
|
- idls.add(str);
|
|
|
- }
|
|
|
+ String pointIdString = StringUtil.join(pointids, ",");
|
|
|
+ Optional<String> keys = Optional.ofNullable(pointIdString);
|
|
|
+ String url = baseURL + "/latest?null=0";
|
|
|
+ try {
|
|
|
+ if (keys.isPresent())
|
|
|
+ url = url + "&keys=" + keys.get();
|
|
|
+ else {
|
|
|
+ return ErrorRequest.RequestListError(pointids);
|
|
|
}
|
|
|
- if(!idls.isEmpty() )
|
|
|
- {
|
|
|
- String pointIdString = StringUtil.join(idls.toArray(), ",");
|
|
|
- Optional<String> keys = Optional.ofNullable(pointIdString);
|
|
|
- String url = baseURL + "/latest?null=0";
|
|
|
- try {
|
|
|
- if (keys.isPresent())
|
|
|
- url = url + "&keys=" + keys.get();
|
|
|
- else {
|
|
|
- return ErrorRequest.RequestListError(pointids);
|
|
|
+ ResponseEntity<JSONObject> resp = restTemplate.getForEntity(url, JSONObject.class);
|
|
|
+ JSONObject jsonObject = resp.getBody();
|
|
|
+ if (jsonObject != null) {
|
|
|
+ //对结果进行有序返回
|
|
|
+ int len = pointids.length;
|
|
|
+ List<PointData> result = new ArrayList<>();
|
|
|
+ HashMap<String, PointData> pointDataHashMap = new HashMap<>();
|
|
|
+ for (int i = 0; i < len; i++) {
|
|
|
+
|
|
|
+ if (pointDataHashMap.containsKey(pointids[i]) == false){
|
|
|
+ PointData pd = new PointData();
|
|
|
+ pd.setPointName(pointids[i]);
|
|
|
+ pd.setEdnaId(pointids[i]);
|
|
|
+ result.add(pd);
|
|
|
+
|
|
|
+ pointDataHashMap.put(pd.getPointName(), pd);
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ result.add(pointDataHashMap.get(pointids[i]));
|
|
|
}
|
|
|
- ResponseEntity<JSONObject> resp = restTemplate.getForEntity(url, JSONObject.class);
|
|
|
- JSONObject jsonObject = resp.getBody();
|
|
|
- if (jsonObject != null) {
|
|
|
- //对结果进行有序返回
|
|
|
- int len = idls.size();
|
|
|
- List<PointData> result = new ArrayList<>();
|
|
|
- HashMap<String, PointData> pointDataHashMap = new HashMap<>();
|
|
|
- for (int i = 0; i < len; i++) {
|
|
|
-
|
|
|
-
|
|
|
- PointData pd = new PointData();
|
|
|
- pd.setPointName(pointids[i]);
|
|
|
- pd.setEdnaId(pointids[i]);
|
|
|
- pd.setPointValueInDouble(0.0);
|
|
|
- pd.setPointTime(0l);
|
|
|
- result.add(pd);
|
|
|
-
|
|
|
- pointDataHashMap.put(pd.getPointName(), pd);
|
|
|
-
|
|
|
-// if (pointDataHashMap.containsKey(idls.get(i)) == false){
|
|
|
-// PointData pd = new PointData();
|
|
|
-// pd.setPointName(idls.get(i));
|
|
|
-// pd.setEdnaId(idls.get(i));
|
|
|
-// result.add(pd);
|
|
|
-//
|
|
|
-// pointDataHashMap.put(pd.getPointName(), pd);
|
|
|
-// }
|
|
|
-// else{
|
|
|
-// result.add(pointDataHashMap.get(idls.get(i)));
|
|
|
-// }
|
|
|
|
|
|
- }
|
|
|
- Iterator<String> sIterator = jsonObject.keySet().iterator();
|
|
|
- while (sIterator.hasNext()) {
|
|
|
- // 获得key
|
|
|
- String key = sIterator.next();
|
|
|
- PointData pointData = pointDataHashMap.get(key);
|
|
|
- if (pointData == null)
|
|
|
- continue;
|
|
|
- // 根据key获得value, value也可以是JSONObject,JSONArray,使用对应的参数接收即可
|
|
|
- JSONObject jsonData = jsonObject.getJSONObject(key);
|
|
|
- Long ts = jsonData.getLong("ts");
|
|
|
- String pointValue = null;
|
|
|
- if (jsonData.containsKey("doubleValue")) {
|
|
|
- pointValue = jsonData.getString("doubleValue");
|
|
|
- } else if (jsonData.containsKey("booleanValue")) {
|
|
|
- pointValue = jsonData.getString("booleanValue");
|
|
|
- } else if (jsonData.containsKey("longValue")) {
|
|
|
- pointValue = jsonData.getString("longValue");
|
|
|
- } else if (jsonData.containsKey("stringValue")) {
|
|
|
- pointValue = jsonData.getString("stringValue");
|
|
|
- }
|
|
|
+ }
|
|
|
+ Iterator<String> sIterator = jsonObject.keySet().iterator();
|
|
|
+ while (sIterator.hasNext()) {
|
|
|
+ // 获得key
|
|
|
+ String key = sIterator.next();
|
|
|
+ PointData pointData = pointDataHashMap.get(key);
|
|
|
+ if (pointData == null)
|
|
|
+ continue;
|
|
|
+ // 根据key获得value, value也可以是JSONObject,JSONArray,使用对应的参数接收即可
|
|
|
+ JSONObject jsonData = jsonObject.getJSONObject(key);
|
|
|
+ Long ts = jsonData.getLong("ts");
|
|
|
+ String pointValue = null;
|
|
|
+ if (jsonData.containsKey("doubleValue")) {
|
|
|
+ pointValue = jsonData.getString("doubleValue");
|
|
|
+ } else if (jsonData.containsKey("booleanValue")) {
|
|
|
+ pointValue = jsonData.getString("booleanValue");
|
|
|
+ } else if (jsonData.containsKey("longValue")) {
|
|
|
+ pointValue = jsonData.getString("longValue");
|
|
|
+ } else if (jsonData.containsKey("stringValue")) {
|
|
|
+ pointValue = jsonData.getString("stringValue");
|
|
|
+ }
|
|
|
// pointData.setPointValue(pointValue);
|
|
|
// pointData.setPointValueInDouble(Double.parseDouble(pointValue));
|
|
|
|
|
|
- if(pointValue.equals("true"))
|
|
|
- {
|
|
|
- pointData.setPointValueInDouble(1.0);
|
|
|
- }else if(pointValue.equals("false"))
|
|
|
- {
|
|
|
- pointData.setPointValueInDouble(0.0);
|
|
|
- }else
|
|
|
- {
|
|
|
- pointData.setPointValueInDouble(Double.parseDouble(pointValue));
|
|
|
- }
|
|
|
- pointData.setPointValue(pointValue);
|
|
|
- // //System.out.println("key= " + key + ", ts = " + ts + ", value = " + pointValue);
|
|
|
- }
|
|
|
- return result;
|
|
|
-
|
|
|
- } else {
|
|
|
- return ErrorRequest.RequestListError(pointids);
|
|
|
- }
|
|
|
-
|
|
|
- } catch (HttpClientErrorException exception) {
|
|
|
- if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
|
|
|
- //System.out.println("404请求错误");
|
|
|
- return ErrorRequest.RequestListError(pointids);
|
|
|
- } else {
|
|
|
- throw exception;
|
|
|
+ if(pointValue.equals("true"))
|
|
|
+ {
|
|
|
+ pointData.setPointValueInDouble(1.0);
|
|
|
+ }else if(pointValue.equals("false"))
|
|
|
+ {
|
|
|
+ pointData.setPointValueInDouble(0.0);
|
|
|
+ }else
|
|
|
+ {
|
|
|
+ pointData.setPointValueInDouble(Double.parseDouble(pointValue));
|
|
|
}
|
|
|
+ pointData.setPointValue(pointValue);
|
|
|
+ // //System.out.println("key= " + key + ", ts = " + ts + ", value = " + pointValue);
|
|
|
}
|
|
|
- }else
|
|
|
- {
|
|
|
+ return result;
|
|
|
|
|
|
- List<PointData> pols=new ArrayList<>();
|
|
|
-
|
|
|
- for(String str:pointids)
|
|
|
- {
|
|
|
- PointData po=new PointData();
|
|
|
- po.setEdnaId(str);
|
|
|
- po.setPointValueInDouble(0.0);
|
|
|
- po.setPointTime(0l);
|
|
|
- pols.add(po);
|
|
|
-
|
|
|
- }
|
|
|
- return pols;
|
|
|
+ } else {
|
|
|
+ return ErrorRequest.RequestListError(pointids);
|
|
|
}
|
|
|
- }else
|
|
|
- {
|
|
|
-
|
|
|
- List<PointData> pols=new ArrayList<>();
|
|
|
-
|
|
|
- for(String str:pointids)
|
|
|
- {
|
|
|
- PointData po=new PointData();
|
|
|
- po.setEdnaId(str);
|
|
|
- po.setPointValueInDouble(0.0);
|
|
|
- po.setPointTime(0l);
|
|
|
- pols.add(po);
|
|
|
|
|
|
+ } catch (HttpClientErrorException exception) {
|
|
|
+ if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
|
|
|
+ //System.out.println("404请求错误");
|
|
|
+ return ErrorRequest.RequestListError(pointids);
|
|
|
+ } else {
|
|
|
+ throw exception;
|
|
|
}
|
|
|
- return pols;
|
|
|
}
|
|
|
|
|
|
|
|
@@ -746,143 +692,88 @@ public class EdosUtil implements IRealTimeDataBaseUtil {
|
|
|
public List<PointData> getRealData(List<String> pointids) throws Exception {
|
|
|
|
|
|
|
|
|
- if(StringUtils.notEmp(pointids) )
|
|
|
- {
|
|
|
- List<String> idls=new ArrayList<>();
|
|
|
- for(String str:pointids)
|
|
|
- {
|
|
|
- if(StringUtils.notEmp(str) && !V2Config.getInitialcode().equals(str))
|
|
|
- {
|
|
|
- idls.add(str);
|
|
|
- }
|
|
|
+ String pointIdString = StringUtil.join(pointids.toArray(), ",");
|
|
|
+ Optional<String> keys = Optional.ofNullable(pointIdString);
|
|
|
+ String url = baseURL + "/latest?null=0";
|
|
|
+ try {
|
|
|
+ if (keys.isPresent())
|
|
|
+ url = url + "&keys=" + keys.get();
|
|
|
+ else {
|
|
|
+ String[] arr = new String[pointids.size()];
|
|
|
+ return ErrorRequest.RequestListError(pointids.toArray(arr));
|
|
|
}
|
|
|
- if(!idls.isEmpty() )
|
|
|
- {
|
|
|
- String pointIdString = StringUtil.join(idls.toArray(), ",");
|
|
|
- Optional<String> keys = Optional.ofNullable(pointIdString);
|
|
|
- String url = baseURL + "/latest?null=0";
|
|
|
- try {
|
|
|
- if (keys.isPresent())
|
|
|
- url = url + "&keys=" + keys.get();
|
|
|
- else {
|
|
|
- String[] arr = new String[idls.size()];
|
|
|
- return ErrorRequest.RequestListError(idls.toArray(arr));
|
|
|
- }
|
|
|
-
|
|
|
- ResponseEntity<JSONObject> resp = restTemplate.getForEntity(url, JSONObject.class);
|
|
|
- JSONObject jsonObject = resp.getBody();
|
|
|
- if (jsonObject != null) {
|
|
|
-
|
|
|
-
|
|
|
- //对结果进行有序返回
|
|
|
- int len = pointids.size();
|
|
|
- List<PointData> result = new ArrayList<>();
|
|
|
- HashMap<String, PointData> pointDataHashMap = new HashMap<>();
|
|
|
- for (int i = 0; i < len; i++) {
|
|
|
-
|
|
|
- PointData pd = new PointData();
|
|
|
- pd.setPointName(pointids.get(i));
|
|
|
- pd.setEdnaId(pointids.get(i));
|
|
|
- pd.setPointValueInDouble(0.0);
|
|
|
- pd.setPointTime(0l);
|
|
|
- result.add(pd);
|
|
|
-
|
|
|
- pointDataHashMap.put(pd.getPointName(), pd);
|
|
|
|
|
|
+ ResponseEntity<JSONObject> resp = restTemplate.getForEntity(url, JSONObject.class);
|
|
|
+ JSONObject jsonObject = resp.getBody();
|
|
|
+ if (jsonObject != null) {
|
|
|
|
|
|
-// if (pointDataHashMap.containsKey(idls.get(i)) == false){
|
|
|
-// PointData pd = new PointData();
|
|
|
-// pd.setPointName(idls.get(i));
|
|
|
-// pd.setEdnaId(idls.get(i));
|
|
|
-// result.add(pd);
|
|
|
-//
|
|
|
-// pointDataHashMap.put(pd.getPointName(), pd);
|
|
|
-// }
|
|
|
-// else{
|
|
|
-// result.add(pointDataHashMap.get(idls.get(i)));
|
|
|
-// }
|
|
|
- }
|
|
|
- Iterator<String> sIterator = jsonObject.keySet().iterator();
|
|
|
- while (sIterator.hasNext()) {
|
|
|
- // 获得key
|
|
|
- String key = sIterator.next();
|
|
|
- PointData pointData = pointDataHashMap.get(key);
|
|
|
- if (pointData == null)
|
|
|
- continue;
|
|
|
- // 根据key获得value, value也可以是JSONObject,JSONArray,使用对应的参数接收即可
|
|
|
- JSONObject jsonData = jsonObject.getJSONObject(key);
|
|
|
- Long ts = jsonData.getLong("ts");
|
|
|
- String pointValue = null;
|
|
|
- if (jsonData.containsKey("doubleValue")) {
|
|
|
- pointValue = jsonData.getString("doubleValue");
|
|
|
- } else if (jsonData.containsKey("booleanValue")) {
|
|
|
- pointValue = jsonData.getString("booleanValue");
|
|
|
- } else if (jsonData.containsKey("longValue")) {
|
|
|
- pointValue = jsonData.getString("longValue");
|
|
|
- } else if (jsonData.containsKey("stringValue")) {
|
|
|
- pointValue = jsonData.getString("stringValue");
|
|
|
- }
|
|
|
- if(pointValue.equals("true"))
|
|
|
- {
|
|
|
- pointData.setPointValueInDouble(1.0);
|
|
|
- }else if(pointValue.equals("false"))
|
|
|
- {
|
|
|
- pointData.setPointValueInDouble(0.0);
|
|
|
- }else
|
|
|
- {
|
|
|
- pointData.setPointValueInDouble(Double.parseDouble(pointValue));
|
|
|
- }
|
|
|
- pointData.setPointValue(pointValue);
|
|
|
|
|
|
- // //System.out.println("key= " + key + ", ts = " + ts + ", value = " + pointValue);
|
|
|
- }
|
|
|
- return result;
|
|
|
+ //对结果进行有序返回
|
|
|
+ int len = pointids.size();
|
|
|
+ List<PointData> result = new ArrayList<>();
|
|
|
+ HashMap<String, PointData> pointDataHashMap = new HashMap<>();
|
|
|
+ for (int i = 0; i < len; i++) {
|
|
|
+ if (pointDataHashMap.containsKey(pointids.get(i)) == false){
|
|
|
+ PointData pd = new PointData();
|
|
|
+ pd.setPointName(pointids.get(i));
|
|
|
+ pd.setEdnaId(pointids.get(i));
|
|
|
+ result.add(pd);
|
|
|
|
|
|
- } else {
|
|
|
- String[] arr = new String[pointids.size()];
|
|
|
- return ErrorRequest.RequestListError(pointids.toArray(arr));
|
|
|
+ pointDataHashMap.put(pd.getPointName(), pd);
|
|
|
}
|
|
|
-
|
|
|
- } catch (HttpClientErrorException exception) {
|
|
|
- if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
|
|
|
- //System.out.println("404请求错误");
|
|
|
- String[] arr = new String[pointids.size()];
|
|
|
- return ErrorRequest.RequestListError(pointids.toArray(arr));
|
|
|
- } else {
|
|
|
- throw exception;
|
|
|
+ else{
|
|
|
+ result.add(pointDataHashMap.get(pointids.get(i)));
|
|
|
}
|
|
|
}
|
|
|
- }else
|
|
|
- {
|
|
|
-
|
|
|
- List<PointData> pols=new ArrayList<>();
|
|
|
-
|
|
|
- for(String str:pointids)
|
|
|
- {
|
|
|
- PointData po=new PointData();
|
|
|
- po.setEdnaId(str);
|
|
|
- po.setPointValueInDouble(0.0);
|
|
|
- po.setPointTime(0l);
|
|
|
- pols.add(po);
|
|
|
+ Iterator<String> sIterator = jsonObject.keySet().iterator();
|
|
|
+ while (sIterator.hasNext()) {
|
|
|
+ // 获得key
|
|
|
+ String key = sIterator.next();
|
|
|
+ PointData pointData = pointDataHashMap.get(key);
|
|
|
+ if (pointData == null)
|
|
|
+ continue;
|
|
|
+ // 根据key获得value, value也可以是JSONObject,JSONArray,使用对应的参数接收即可
|
|
|
+ JSONObject jsonData = jsonObject.getJSONObject(key);
|
|
|
+ Long ts = jsonData.getLong("ts");
|
|
|
+ String pointValue = null;
|
|
|
+ if (jsonData.containsKey("doubleValue")) {
|
|
|
+ pointValue = jsonData.getString("doubleValue");
|
|
|
+ } else if (jsonData.containsKey("booleanValue")) {
|
|
|
+ pointValue = jsonData.getString("booleanValue");
|
|
|
+ } else if (jsonData.containsKey("longValue")) {
|
|
|
+ pointValue = jsonData.getString("longValue");
|
|
|
+ } else if (jsonData.containsKey("stringValue")) {
|
|
|
+ pointValue = jsonData.getString("stringValue");
|
|
|
+ }
|
|
|
+ if(pointValue.equals("true"))
|
|
|
+ {
|
|
|
+ pointData.setPointValueInDouble(1.0);
|
|
|
+ }else if(pointValue.equals("false"))
|
|
|
+ {
|
|
|
+ pointData.setPointValueInDouble(0.0);
|
|
|
+ }else
|
|
|
+ {
|
|
|
+ pointData.setPointValueInDouble(Double.parseDouble(pointValue));
|
|
|
+ }
|
|
|
+ pointData.setPointValue(pointValue);
|
|
|
|
|
|
+ // //System.out.println("key= " + key + ", ts = " + ts + ", value = " + pointValue);
|
|
|
}
|
|
|
- return pols;
|
|
|
- }
|
|
|
- }else
|
|
|
- {
|
|
|
-
|
|
|
- List<PointData> pols=new ArrayList<>();
|
|
|
+ return result;
|
|
|
|
|
|
- for(String str:pointids)
|
|
|
- {
|
|
|
- PointData po=new PointData();
|
|
|
- po.setEdnaId(str);
|
|
|
- po.setPointValueInDouble(0.0);
|
|
|
- po.setPointTime(0l);
|
|
|
- pols.add(po);
|
|
|
+ } else {
|
|
|
+ String[] arr = new String[pointids.size()];
|
|
|
+ return ErrorRequest.RequestListError(pointids.toArray(arr));
|
|
|
+ }
|
|
|
|
|
|
+ } catch (HttpClientErrorException exception) {
|
|
|
+ if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
|
|
|
+ //System.out.println("404请求错误");
|
|
|
+ String[] arr = new String[pointids.size()];
|
|
|
+ return ErrorRequest.RequestListError(pointids.toArray(arr));
|
|
|
+ } else {
|
|
|
+ throw exception;
|
|
|
}
|
|
|
- return pols;
|
|
|
}
|
|
|
|
|
|
}
|