feat: 油井两张动态图表改为从redis中获取数据

This commit is contained in:
2024-05-16 10:03:50 +08:00
parent c4923bf6d4
commit 4a5ba60fbf
3 changed files with 85 additions and 39 deletions
@@ -7,6 +7,9 @@ import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.jero.modules.utils.RandomNumberUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
@@ -17,10 +20,8 @@ import org.springframework.format.annotation.DateTimeFormat;
import redis.clients.jedis.Jedis;
import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.text.SimpleDateFormat;
import java.util.*;
/**
* @author: Mzaxd
@@ -203,8 +204,14 @@ public class KhOilRealtimeData implements Serializable {
private static boolean db1Select = true;
public void mockKhOilRealtimeRedisData() {
private static ObjectMapper mapper = new ObjectMapper();
public void mockKhOilRealtimeRedisData(Map<String, Object> result) throws JsonProcessingException {
Map<String, List<Double>> map = new HashMap<>();
List<List<Double>> ShangChongCheng = new ArrayList<>();
List<List<Double>> XiaChongCheng = new ArrayList<>();
List<List<Double>> ZuiDaZaiHe = new ArrayList<>();
List<List<Double>> ZuiXiaoZaiHe = new ArrayList<>();
JSONArray data = new JSONArray();
// 连接到Redis服务器
try (Jedis jedis = new Jedis("1.15.107.30", 6379)) {
@@ -221,11 +228,25 @@ public class KhOilRealtimeData implements Serializable {
data = JSON.parseArray(jsonData);
}
ObjectMapper mapper = new ObjectMapper();
for (Object item : data) {
JSONObject jsonObject = (JSONObject) item;
String name = jsonObject.getString("Name");
List<Double> values = jsonObject.getJSONArray("Values").toJavaList(Double.class);
map.put(name, values);
if (!name.equals("ShiShiShiGongTu") && !name.equals("ZaiHeFenBuTu")) {
List<Double> values = jsonObject.getJSONArray("Values").toJavaList(Double.class);
map.put(name, values);
}
switch (name) {
case "ShiShiShiGongTu":
ShangChongCheng = mapper.readValue(jsonObject.getString("ShangChongCheng"), new TypeReference<List<List<Double>>>(){});
XiaChongCheng = mapper.readValue(jsonObject.getString("XiaChongCheng"), new TypeReference<List<List<Double>>>(){});
break;
case "ZaiHeFenBuTu":
ZuiDaZaiHe = mapper.readValue(jsonObject.getString("ZuiDaZaiHe"), new TypeReference<List<List<Double>>>(){});
ZuiXiaoZaiHe = mapper.readValue(jsonObject.getString("ZuiXiaoZaiHe"), new TypeReference<List<List<Double>>>(){});
break;
}
}
int size = map.get("YouYa").size();
this.oilPressure = map.get("YouYa").get(dbIndex);
@@ -246,6 +267,32 @@ public class KhOilRealtimeData implements Serializable {
this.maxLoad = 0;
this.deviceId = "default";
this.id = "default";
Map<String, Object> chartTwo = new HashMap<>();
Integer[] arr = {0, 25, 50, 75, 100, 125, 150, 175, 200, 225, 250};
List<Integer> chartTwoX = Arrays.asList(arr);
List<Double> chartTwoUp = ShangChongCheng != null ? ShangChongCheng.get(dbIndex) : null;
List<Double> chartTwoDown = XiaChongCheng != null ? XiaChongCheng.get(dbIndex) : null;
chartTwo.put("X轴", chartTwoX);
chartTwo.put("上冲程", chartTwoUp);
chartTwo.put("下冲程", chartTwoDown);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
chartTwo.put("时间", sdf.format(new Date()));
chartTwo.put("冲程", chartTwoUp.get(0));
chartTwo.put("冲次", chartTwoDown.get(0));
result.put("实时示功图", chartTwo);
Map<String, List<?>> chartThree = new HashMap<>();
List<String> chartThreeX = RandomNumberUtil.getLast30DaysFormattedDatesAscending();
List<Double> chartThreeMax = ZuiDaZaiHe != null ? ZuiDaZaiHe.get(dbIndex) : null;
List<Double> chartThreeMin = ZuiXiaoZaiHe != null ? ZuiXiaoZaiHe.get(dbIndex) : null;
chartThree.put("X轴", chartThreeX);
chartThree.put("最大载荷", chartThreeMax);
chartThree.put("最小载荷", chartThreeMin);
result.put("载荷分布图", chartThree);
dbIndex += 1;
if (dbIndex >= size) {
dbIndex = 0;
@@ -0,0 +1,22 @@
package com.jero.modules.entity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class OilRealTimeRedisData {
private List<List<Double>> ShangChongCheng;
private List<List<Double>> XiaCongCheng;
private List<List<Double>> ChanYouLiang;
private List<List<Double>> ChanQiLiang;
private List<List<Double>> ZuiDaZaiHe;
private List<List<Double>> ZuiXiaoZaiHe;
}
@@ -1,6 +1,8 @@
package com.jero.modules.service.impl;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.jero.modules.entity.KhOilRealtimeData;
import com.jero.modules.entity.OilRealTimeRedisData;
import com.jero.modules.mapper.KhOilRealtimeDataMapper;
import com.jero.modules.service.IKhOilRealtimeDataService;
import com.jero.modules.utils.RandomNumberUtil;
@@ -8,12 +10,14 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.jero.common.exception.JeroBootException;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.*;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jero.common.system.query.QueryGenerator;
import redis.clients.jedis.Jedis;
import javax.servlet.http.HttpServletRequest;
@@ -69,39 +73,12 @@ public class KhOilRealtimeDataServiceImpl extends ServiceImpl<KhOilRealtimeDataM
public Map<String, Object> realtimeDataResults(String id) {
KhOilRealtimeData khOilRealtimeData = new KhOilRealtimeData();
Map<String, Object> result = new HashMap<>();
khOilRealtimeData.mockKhOilRealtimeRedisData();
try {
khOilRealtimeData.mockKhOilRealtimeRedisData(result);
} catch (Exception e) {
log.error("从redis获取数据错误", e);
}
result.put("油井实时参数", khOilRealtimeData);
Map<String, Object> chartTwo = new HashMap<>();
Integer[] arr = {0, 25, 50, 75, 100, 125, 150, 175, 200, 225, 250};
List<Integer> chartTwoX = Arrays.asList(arr);
List<Integer> chartTwoUp = RandomNumberUtil.generateFakeDataList(arr.length, Integer.class);
List<Integer> chartTwoDown = this.getRandomMinusDataList(chartTwoUp);
chartTwo.put("X轴", chartTwoX);
chartTwo.put("上冲程", chartTwoUp);
chartTwo.put("下冲程", chartTwoDown);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
chartTwo.put("时间", sdf.format(new Date()));
chartTwo.put("冲程", RandomNumberUtil.getRandomDouble());
chartTwo.put("冲次", RandomNumberUtil.getRandomDouble());
result.put("实时示功图", chartTwo);
Map<String, List<?>> chartThree = new HashMap<>();
List<String> chartThreeX = RandomNumberUtil.getLast30DaysFormattedDatesAscending();
List<Integer> chartThreeMax = RandomNumberUtil.generateFakeDataList(chartThreeX.size(), Integer.class);
List<Integer> chartThreeMin = this.getRandomMinusDataList(chartThreeMax);
chartThree.put("X轴", chartThreeX);
chartThree.put("最大载荷", chartThreeMax);
chartThree.put("最小载荷", chartThreeMin);
result.put("载荷分布图", chartThree);
return result;
}
private List<Integer> getRandomMinusDataList(List<Integer> originList) {
List<Integer> data = new ArrayList<>();
for (Integer originData : originList) {
data.add(originData - RandomNumberUtil.getRandomIntBetween(5, 40));
}
return data;
}
}