|
@@ -8,6 +8,7 @@ import org.springframework.stereotype.Service;
|
|
|
import java.sql.Connection;
|
|
|
import java.sql.PreparedStatement;
|
|
|
import java.sql.ResultSet;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
|
|
@@ -19,17 +20,18 @@ public class PointService {
|
|
|
private Database db;
|
|
|
|
|
|
//外层: key = 分组号(iec104 asduAddress), Value = 该分组下所有点的map结构
|
|
|
- //内层:key = 点名, value = point对象
|
|
|
- private Map<Integer, Map<String, Point>> aiMap;
|
|
|
+ private Map<Integer, ArrayList<Point>> aiMap;
|
|
|
+ private Map<Integer, ArrayList<Point>> diMap;
|
|
|
|
|
|
- private Map<Integer, Map<String, Point>> diMap;
|
|
|
+ private Map<Integer, ArrayList<String>> aiKeyMap;
|
|
|
+ private Map<Integer, ArrayList<String>> diKeyMap;
|
|
|
|
|
|
public void initPointMap() {
|
|
|
aiMap = loadAiPointMap();
|
|
|
diMap = loadDiPointMap();
|
|
|
}
|
|
|
|
|
|
- public Map<Integer, Map<String, Point>> getAiMap(){
|
|
|
+ public Map<Integer, ArrayList<Point>> getAiList(){
|
|
|
|
|
|
if (aiMap == null || aiMap.isEmpty()){
|
|
|
aiMap = loadAiPointMap();
|
|
@@ -38,12 +40,15 @@ public class PointService {
|
|
|
return aiMap;
|
|
|
}
|
|
|
|
|
|
- private Map<Integer, Map<String, Point>> loadAiPointMap() {
|
|
|
- Map<Integer, Map<String, Point>> map = new HashMap<>();
|
|
|
+ private Map<Integer, ArrayList<Point>> loadAiPointMap() {
|
|
|
+ Map<Integer, ArrayList<Point>> map = new HashMap<>();
|
|
|
+ aiKeyMap = new HashMap<>();
|
|
|
+
|
|
|
try {
|
|
|
log.info("加载AI测点......");
|
|
|
Connection conn = db.getConnection();
|
|
|
- String sql = "select * from point where pointtype = 'AI'";
|
|
|
+ //确保地址连续
|
|
|
+ String sql = "select * from point where pointtype = 'AI' order by publicaddr, pointaddr asc";
|
|
|
log.info("执行SQL:" + sql);
|
|
|
PreparedStatement ps = conn.prepareStatement(sql);
|
|
|
ResultSet rs = ps.executeQuery();
|
|
@@ -58,12 +63,16 @@ public class PointService {
|
|
|
point.setOrg(rs.getString("org"));
|
|
|
|
|
|
if (map.containsKey(point.getPublicAddr()) == false) {
|
|
|
- Map<String, Point> subMap = new HashMap<>();
|
|
|
+ ArrayList<Point> subMap = new ArrayList<>();
|
|
|
map.put((Integer)point.getPublicAddr(), subMap);
|
|
|
+ ArrayList<String> lstStr = new ArrayList<>();
|
|
|
+ aiKeyMap.put((Integer)point.getPublicAddr(), lstStr);
|
|
|
}
|
|
|
- Map<String, Point> subMap = map.get(point.getPublicAddr());
|
|
|
- if (subMap.containsKey(point.getPoint()) == false)
|
|
|
- subMap.put(point.getPoint(), point);
|
|
|
+ ArrayList<Point> subMap = map.get(point.getPublicAddr());
|
|
|
+ subMap.add(point);
|
|
|
+ ArrayList<String> lstStr = aiKeyMap.get(point.getPublicAddr());
|
|
|
+ lstStr.add(point.getPoint());
|
|
|
+
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
log.info("sqlite查询失败",e);
|
|
@@ -74,7 +83,7 @@ public class PointService {
|
|
|
return map;
|
|
|
}
|
|
|
|
|
|
- public Map<Integer, Map<String, Point>> getDiMap(){
|
|
|
+ public Map<Integer, ArrayList<Point>> getDiList(){
|
|
|
if (diMap == null || diMap.isEmpty()){
|
|
|
diMap = loadDiPointMap();
|
|
|
}
|
|
@@ -82,12 +91,13 @@ public class PointService {
|
|
|
return diMap;
|
|
|
}
|
|
|
|
|
|
- private Map<Integer, Map<String, Point>> loadDiPointMap() {
|
|
|
- Map<Integer, Map<String, Point>> map = new HashMap<>();
|
|
|
+ private Map<Integer, ArrayList<Point>> loadDiPointMap() {
|
|
|
+ Map<Integer, ArrayList<Point>> map = new HashMap<>();
|
|
|
+ diKeyMap = new HashMap<>();
|
|
|
try {
|
|
|
log.info("加载DI测点......");
|
|
|
Connection conn = db.getConnection();
|
|
|
- String sql = "select * from point where pointtype = 'DI'";
|
|
|
+ String sql = "select * from point where pointtype = 'DI' order by publicaddr, pointaddr";
|
|
|
log.info("执行SQL:" + sql);
|
|
|
PreparedStatement ps = conn.prepareStatement(sql);
|
|
|
ResultSet rs = ps.executeQuery();
|
|
@@ -102,12 +112,15 @@ public class PointService {
|
|
|
point.setOrg(rs.getString("org"));
|
|
|
|
|
|
if (map.containsKey(point.getPublicAddr()) == false) {
|
|
|
- Map<String, Point> subMap = new HashMap<>();
|
|
|
+ ArrayList<Point> subMap = new ArrayList<>();
|
|
|
map.put((Integer)point.getPublicAddr(), subMap);
|
|
|
+ ArrayList<String> lstStr = new ArrayList<>();
|
|
|
+ diKeyMap.put((Integer)point.getPublicAddr(), lstStr);
|
|
|
}
|
|
|
- Map<String, Point> subMap = map.get(point.getPublicAddr());
|
|
|
- if (subMap.containsKey(point.getPoint()) == false)
|
|
|
- subMap.put(point.getPoint(), point);
|
|
|
+ ArrayList<Point> subMap = map.get(point.getPublicAddr());
|
|
|
+ subMap.add(point);
|
|
|
+ ArrayList<String> lstStr = diKeyMap.get(point.getPublicAddr());
|
|
|
+ lstStr.add(point.getPoint());
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
log.info("sqlite查询失败",e);
|
|
@@ -119,5 +132,36 @@ public class PointService {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ public ArrayList<Point> getAiList(int addr) {
|
|
|
+ if (aiMap == null || aiMap.isEmpty()){
|
|
|
+ aiMap = loadAiPointMap();
|
|
|
+ }
|
|
|
+
|
|
|
+ return aiMap.get(addr);
|
|
|
+ }
|
|
|
+
|
|
|
+ public ArrayList<Point> getDiList(int addr) {
|
|
|
+ if (diMap == null || diMap.isEmpty()){
|
|
|
+ diMap = loadDiPointMap();
|
|
|
+ }
|
|
|
+
|
|
|
+ return diMap.get(addr);
|
|
|
+ }
|
|
|
+
|
|
|
+ public ArrayList<String> getAiKeys(int addr) {
|
|
|
+ if (aiKeyMap == null || aiKeyMap.isEmpty()){
|
|
|
+ loadAiPointMap();
|
|
|
+ }
|
|
|
+
|
|
|
+ return aiKeyMap.get(addr);
|
|
|
+ }
|
|
|
+
|
|
|
+ public ArrayList<String> getDiKeys(int addr) {
|
|
|
+ if (diKeyMap == null || diKeyMap.isEmpty()){
|
|
|
+ loadDiPointMap();
|
|
|
+ }
|
|
|
+
|
|
|
+ return diKeyMap.get(addr);
|
|
|
+ }
|
|
|
|
|
|
}
|