feat: 油井数据改为支持轮询两个redis库中的所有数据并自动切换

This commit is contained in:
2024-05-11 15:13:49 +08:00
parent 360b7b16f9
commit c4923bf6d4
2 changed files with 26 additions and 20 deletions
@@ -199,14 +199,17 @@ public class KhOilRealtimeData implements Serializable {
this.id = "default"; this.id = "default";
} }
private static int dbIndex = 0;
public void mockKhOilRealtimeRedisData(boolean db1) { private static boolean db1Select = true;
public void mockKhOilRealtimeRedisData() {
Map<String, List<Double>> map = new HashMap<>(); Map<String, List<Double>> map = new HashMap<>();
JSONArray data = new JSONArray(); JSONArray data = new JSONArray();
// 连接到Redis服务器 // 连接到Redis服务器
try (Jedis jedis = new Jedis("1.15.107.30", 6379)) { try (Jedis jedis = new Jedis("1.15.107.30", 6379)) {
jedis.auth("kld4...."); jedis.auth("kld4....");
if (db1) { if (db1Select) {
// 去db1取数据 // 去db1取数据
jedis.select(1); jedis.select(1);
} else { } else {
@@ -224,23 +227,29 @@ public class KhOilRealtimeData implements Serializable {
List<Double> values = jsonObject.getJSONArray("Values").toJavaList(Double.class); List<Double> values = jsonObject.getJSONArray("Values").toJavaList(Double.class);
map.put(name, values); map.put(name, values);
} }
this.oilPressure = map.get("YouYa").get(0); int size = map.get("YouYa").size();
this.currentA = map.get("DianLiu_A").get(0); this.oilPressure = map.get("YouYa").get(dbIndex);
this.currentB = map.get("DianLiu_B").get(0); this.currentA = map.get("DianLiu_A").get(dbIndex);
this.currentC = map.get("DianLiu_C").get(0); this.currentB = map.get("DianLiu_B").get(dbIndex);
this.activePower = map.get("YouGongGongLv").get(0); this.currentC = map.get("DianLiu_C").get(dbIndex);
this.powerFactor = map.get("GongLvYinShu").get(0); this.activePower = map.get("YouGongGongLv").get(dbIndex);
this.casingPressure = map.get("TaoYa").get(0); this.powerFactor = map.get("GongLvYinShu").get(dbIndex);
this.voltageA = map.get("DianYa_A").get(0); this.casingPressure = map.get("TaoYa").get(dbIndex);
this.voltageB = map.get("DianYa_B").get(0); this.voltageA = map.get("DianYa_A").get(dbIndex);
this.voltageC = map.get("DianYa_C").get(0); this.voltageB = map.get("DianYa_B").get(dbIndex);
this.reactivePower = map.get("WuGongGongLv").get(0); this.voltageC = map.get("DianYa_C").get(dbIndex);
this.outputFrequency = (int) Double.parseDouble(String.valueOf(map.get("ShuChuPinLv").get(0))); this.reactivePower = map.get("WuGongGongLv").get(dbIndex);
this.strokeCount = (int) Double.parseDouble(String.valueOf(map.get("ChongCi").get(0))); this.outputFrequency = (int) Double.parseDouble(String.valueOf(map.get("ShuChuPinLv").get(dbIndex)));
this.stroke = map.get("ChongCheng").get(0); this.strokeCount = (int) Double.parseDouble(String.valueOf(map.get("ChongCi").get(dbIndex)));
this.stroke = map.get("ChongCheng").get(dbIndex);
this.minLoad = 0; this.minLoad = 0;
this.maxLoad = 0; this.maxLoad = 0;
this.deviceId = "default"; this.deviceId = "default";
this.id = "default"; this.id = "default";
dbIndex += 1;
if (dbIndex >= size) {
dbIndex = 0;
db1Select = !db1Select;
}
} }
} }
@@ -28,8 +28,6 @@ import javax.servlet.http.HttpServletRequest;
@Transactional(rollbackFor = JeroBootException.class) @Transactional(rollbackFor = JeroBootException.class)
public class KhOilRealtimeDataServiceImpl extends ServiceImpl<KhOilRealtimeDataMapper, KhOilRealtimeData> implements IKhOilRealtimeDataService { public class KhOilRealtimeDataServiceImpl extends ServiceImpl<KhOilRealtimeDataMapper, KhOilRealtimeData> implements IKhOilRealtimeDataService {
private static boolean dbSelect = true;
/** /**
* 列表查询 * 列表查询
* *
@@ -71,8 +69,7 @@ public class KhOilRealtimeDataServiceImpl extends ServiceImpl<KhOilRealtimeDataM
public Map<String, Object> realtimeDataResults(String id) { public Map<String, Object> realtimeDataResults(String id) {
KhOilRealtimeData khOilRealtimeData = new KhOilRealtimeData(); KhOilRealtimeData khOilRealtimeData = new KhOilRealtimeData();
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
dbSelect = !dbSelect; khOilRealtimeData.mockKhOilRealtimeRedisData();
khOilRealtimeData.mockKhOilRealtimeRedisData(dbSelect);
result.put("油井实时参数", khOilRealtimeData); result.put("油井实时参数", khOilRealtimeData);
Map<String, Object> chartTwo = new HashMap<>(); Map<String, Object> chartTwo = new HashMap<>();
Integer[] arr = {0, 25, 50, 75, 100, 125, 150, 175, 200, 225, 250}; Integer[] arr = {0, 25, 50, 75, 100, 125, 150, 175, 200, 225, 250};