|
@@ -0,0 +1,56 @@
|
|
|
+package com.example.opc_da.util;
|
|
|
+
|
|
|
+import com.cqcy.ei.influxdb.entity.Item;
|
|
|
+import com.cqcy.ei.influxdb.service.QueryService;
|
|
|
+import com.example.opc_common.util.Blank;
|
|
|
+import com.example.opc_da.config.SpringContextUtils;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+public class ItemUtil {
|
|
|
+
|
|
|
+ private QueryService queryService = SpringContextUtils.getBean(QueryService.class);
|
|
|
+
|
|
|
+ public List<? extends ItemParent> gen(List<? extends ItemParent> tList) {
|
|
|
+ if (Blank.isNotEmpty(tList)) {
|
|
|
+ //Map<dataSourceId,items>
|
|
|
+ Map<String, List<String>> itemData = new HashMap<>();
|
|
|
+ for (ItemParent m : tList) {
|
|
|
+ String dataSourceId = m.getDataSourceId().toString();
|
|
|
+ List<String> items = itemData.get(dataSourceId);
|
|
|
+ if (Blank.isEmpty(items)) {
|
|
|
+ items = new ArrayList<>();
|
|
|
+ }
|
|
|
+ items.add(m.getItemReadName());
|
|
|
+ itemData.put(dataSourceId, items);
|
|
|
+ }
|
|
|
+ //根据分组信息,查询对应的数据项值,并转换为相应的map格式
|
|
|
+ Map<String, Map<String, Item>> mapData = new HashMap<>();
|
|
|
+ for (String dataSourceId : itemData.keySet()) {
|
|
|
+ Map<String, Item> map = new HashMap<>();
|
|
|
+ List<Item> itemDataByLast = queryService.getItemDataByLast(itemData.get(dataSourceId), dataSourceId);
|
|
|
+ if (Blank.isNotEmpty(itemDataByLast)) {
|
|
|
+ for (Item item : itemDataByLast) {
|
|
|
+ map.put(item.getName(), item);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ mapData.put(dataSourceId, map);
|
|
|
+ }
|
|
|
+ //将返回的值赋值给对应的数据项中
|
|
|
+ for (int i = 0; i < tList.size(); i++) {
|
|
|
+ ItemParent m = tList.get(i);
|
|
|
+ Item item = mapData.get(m.getDataSourceId().toString()).get(m.getItemReadName());
|
|
|
+ if (Blank.isNotEmpty(item)) {
|
|
|
+ m.setDataValue(item.getValue());
|
|
|
+ m.setDataTime(item.getTime());
|
|
|
+ }
|
|
|
+// tList.set(i, m);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return tList;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|