feat: 井口实时参数数据
This commit is contained in:
@@ -4,6 +4,10 @@ import com.baomidou.mybatisplus.annotation.IdType;
|
|||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
|
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||||
|
import com.github.javafaker.Faker;
|
||||||
|
import com.jero.modules.utils.RandomNumberUtil;
|
||||||
import io.swagger.annotations.ApiModel;
|
import io.swagger.annotations.ApiModel;
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
@@ -158,6 +162,28 @@ public class KhOilRealtimeData implements Serializable {
|
|||||||
* 设备唯一标识
|
* 设备唯一标识
|
||||||
*/
|
*/
|
||||||
@ApiModelProperty(value = "设备唯一标识")
|
@ApiModelProperty(value = "设备唯一标识")
|
||||||
private int deviceId;
|
private String deviceId;
|
||||||
|
|
||||||
|
public void mockKhOilRealtimeData() {
|
||||||
|
this.oilPressure = RandomNumberUtil.getRandomDouble();
|
||||||
|
this.currentA = RandomNumberUtil.getRandomDouble();
|
||||||
|
this.currentB = RandomNumberUtil.getRandomDouble();
|
||||||
|
this.currentC = RandomNumberUtil.getRandomDouble();
|
||||||
|
this.activePower = RandomNumberUtil.getRandomDouble();
|
||||||
|
this.powerFactor = RandomNumberUtil.getRandomDouble();
|
||||||
|
this.maxLoad = RandomNumberUtil.getRandomDouble();
|
||||||
|
this.stroke = RandomNumberUtil.getRandomDouble();
|
||||||
|
this.casingPressure = RandomNumberUtil.getRandomDouble();
|
||||||
|
this.voltageA = RandomNumberUtil.getRandomDouble();
|
||||||
|
this.voltageB = RandomNumberUtil.getRandomDouble();
|
||||||
|
this.voltageC = RandomNumberUtil.getRandomDouble();
|
||||||
|
this.reactivePower = RandomNumberUtil.getRandomDouble();
|
||||||
|
this.outputFrequency = RandomNumberUtil.getRandomInt();
|
||||||
|
this.minLoad = RandomNumberUtil.getRandomInt();
|
||||||
|
this.strokeCount = RandomNumberUtil.getRandomInt();
|
||||||
|
this.deviceId = "default";
|
||||||
|
this.id = "default";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+27
-13
@@ -3,12 +3,14 @@ package com.jero.modules.service.impl;
|
|||||||
import com.jero.modules.entity.KhOilRealtimeData;
|
import com.jero.modules.entity.KhOilRealtimeData;
|
||||||
import com.jero.modules.mapper.KhOilRealtimeDataMapper;
|
import com.jero.modules.mapper.KhOilRealtimeDataMapper;
|
||||||
import com.jero.modules.service.IKhOilRealtimeDataService;
|
import com.jero.modules.service.IKhOilRealtimeDataService;
|
||||||
|
import com.jero.modules.utils.RandomNumberUtil;
|
||||||
|
import io.swagger.models.auth.In;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import com.jero.common.exception.JeroBootException;
|
import com.jero.common.exception.JeroBootException;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Date;
|
import java.util.*;
|
||||||
import java.util.Map;
|
|
||||||
import com.github.javafaker.Faker;
|
import com.github.javafaker.Faker;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
@@ -28,8 +30,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 final Faker faker = new Faker();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 列表查询
|
* 列表查询
|
||||||
*
|
*
|
||||||
@@ -70,14 +70,28 @@ public class KhOilRealtimeDataServiceImpl extends ServiceImpl<KhOilRealtimeDataM
|
|||||||
@Override
|
@Override
|
||||||
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<>();
|
||||||
|
khOilRealtimeData.mockKhOilRealtimeData();
|
||||||
|
result.put("油井实时参数", khOilRealtimeData);
|
||||||
return null;
|
Map<String, List<Integer>> 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 = RandomNumberUtil.generateFakeDataList(arr.length, Integer.class);
|
||||||
|
chartTwo.put("X轴", chartTwoX);
|
||||||
|
chartTwo.put("上冲程", chartTwoUp);
|
||||||
|
chartTwo.put("下冲程", chartTwoDown);
|
||||||
|
result.put("实时示功图", chartTwo);
|
||||||
|
Map<String, List<?>> chartThree = new HashMap<>();
|
||||||
|
List<String> chartThreeX = RandomNumberUtil.getLast30DaysFormattedDatesAscending();
|
||||||
|
List<Integer> charThreeMax = RandomNumberUtil.generateFakeDataList(chartThreeX.size(), Integer.class);
|
||||||
|
List<Integer> chartThreeMin = RandomNumberUtil.generateFakeDataList(chartThreeX.size(), Integer.class);
|
||||||
|
chartThree.put("X轴", chartThreeX);
|
||||||
|
chartThree.put("最大载荷", charThreeMax);
|
||||||
|
chartThree.put("最小载荷", chartThreeMin);
|
||||||
|
result.put("载荷分布图", chartThree);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private double getRandomDouble() {
|
|
||||||
// 生成一个在0到100之间,小数点后有2位的随机浮点数
|
|
||||||
return faker.number().randomDouble(2, 0, 100);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,65 @@
|
|||||||
|
package com.jero.modules.utils;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
|
import com.github.javafaker.Faker;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author: Mzaxd
|
||||||
|
* @Date: 2024/4/9 9:35
|
||||||
|
*/
|
||||||
|
public class RandomNumberUtil {
|
||||||
|
|
||||||
|
public static final Faker faker = new Faker();
|
||||||
|
|
||||||
|
public static double getRandomDouble() {
|
||||||
|
// 生成一个在0到100之间,小数点后有2位的随机浮点数
|
||||||
|
return faker.number().randomDouble(2, 0, 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getRandomInt() {
|
||||||
|
// 生成一个在0到100之间,小数点后有2位的随机浮点数
|
||||||
|
return faker.number().randomDigit();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 生成指定大小和类型的列表,填充伪随机数据
|
||||||
|
public static <T> List<T> generateFakeDataList(int size, Class<T> type) {
|
||||||
|
List<T> resultList = new ArrayList<>();
|
||||||
|
|
||||||
|
for (int i = 0; i < size; i++) {
|
||||||
|
if (type.equals(Double.class)) {
|
||||||
|
// 对于 Double 类型,生成伪随机双精度值
|
||||||
|
resultList.add(type.cast(faker.number().randomDouble(2, 1, 100)));
|
||||||
|
} else if (type.equals(Integer.class)) {
|
||||||
|
// 对于 Integer 类型,生成伪随机整数值
|
||||||
|
resultList.add(type.cast(faker.number().numberBetween(1, 100)));
|
||||||
|
} else {
|
||||||
|
// 可以扩展更多的类型支持
|
||||||
|
throw new IllegalArgumentException("Unsupported type: " + type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return resultList;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 生成包含今天及之前29天日期的列表,格式为"MM-DD"
|
||||||
|
public static List<String> getLast30DaysFormattedDatesAscending() {
|
||||||
|
List<String> datesList = new ArrayList<>();
|
||||||
|
LocalDate startDate = LocalDate.now().minusDays(29); // 从30天前开始
|
||||||
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM-dd");
|
||||||
|
|
||||||
|
for (int i = 0; i < 30; i++) {
|
||||||
|
LocalDate date = startDate.plusDays(i); // 递增日期
|
||||||
|
String formattedDate = date.format(formatter);
|
||||||
|
datesList.add(formattedDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
return datesList;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user