From e97b216eb86eee22f0feab5886fae5038e8cc468 Mon Sep 17 00:00:00 2001 From: caihaohan Date: Tue, 9 Apr 2024 09:30:32 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BA=95=E5=8F=A3=E5=AE=9E=E6=97=B6?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/entity/KhOilRealtimeData.java | 28 +++++++- .../impl/KhOilRealtimeDataServiceImpl.java | 40 ++++++++---- .../jero/modules/utils/RandomNumberUtil.java | 65 +++++++++++++++++++ 3 files changed, 119 insertions(+), 14 deletions(-) create mode 100644 kh-modules/src/main/java/com/jero/modules/utils/RandomNumberUtil.java diff --git a/kh-modules/src/main/java/com/jero/modules/entity/KhOilRealtimeData.java b/kh-modules/src/main/java/com/jero/modules/entity/KhOilRealtimeData.java index 01cd5599..57152db9 100644 --- a/kh-modules/src/main/java/com/jero/modules/entity/KhOilRealtimeData.java +++ b/kh-modules/src/main/java/com/jero/modules/entity/KhOilRealtimeData.java @@ -4,6 +4,10 @@ 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.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.ApiModelProperty; import lombok.Data; @@ -158,6 +162,28 @@ public class KhOilRealtimeData implements Serializable { * 设备唯一标识 */ @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"; + } + } diff --git a/kh-modules/src/main/java/com/jero/modules/service/impl/KhOilRealtimeDataServiceImpl.java b/kh-modules/src/main/java/com/jero/modules/service/impl/KhOilRealtimeDataServiceImpl.java index f56fd4c8..68d1c938 100644 --- a/kh-modules/src/main/java/com/jero/modules/service/impl/KhOilRealtimeDataServiceImpl.java +++ b/kh-modules/src/main/java/com/jero/modules/service/impl/KhOilRealtimeDataServiceImpl.java @@ -3,12 +3,14 @@ package com.jero.modules.service.impl; import com.jero.modules.entity.KhOilRealtimeData; import com.jero.modules.mapper.KhOilRealtimeDataMapper; 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.transaction.annotation.Transactional; import com.jero.common.exception.JeroBootException; -import java.util.List; -import java.util.Date; -import java.util.Map; + +import java.util.*; + import com.github.javafaker.Faker; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; @@ -28,8 +30,6 @@ import javax.servlet.http.HttpServletRequest; @Transactional(rollbackFor = JeroBootException.class) public class KhOilRealtimeDataServiceImpl extends ServiceImpl implements IKhOilRealtimeDataService { - private final Faker faker = new Faker(); - /** * 列表查询 * @@ -70,14 +70,28 @@ public class KhOilRealtimeDataServiceImpl extends ServiceImpl realtimeDataResults(String id) { KhOilRealtimeData khOilRealtimeData = new KhOilRealtimeData(); - - - - return null; + Map result = new HashMap<>(); + khOilRealtimeData.mockKhOilRealtimeData(); + result.put("油井实时参数", khOilRealtimeData); + Map> chartTwo = new HashMap<>(); + Integer[] arr = {0, 25, 50, 75, 100, 125, 150, 175, 200, 225, 250}; + List chartTwoX = Arrays.asList(arr); + List chartTwoUp = RandomNumberUtil.generateFakeDataList(arr.length, Integer.class); + List chartTwoDown = RandomNumberUtil.generateFakeDataList(arr.length, Integer.class); + chartTwo.put("X轴", chartTwoX); + chartTwo.put("上冲程", chartTwoUp); + chartTwo.put("下冲程", chartTwoDown); + result.put("实时示功图", chartTwo); + Map> chartThree = new HashMap<>(); + List chartThreeX = RandomNumberUtil.getLast30DaysFormattedDatesAscending(); + List charThreeMax = RandomNumberUtil.generateFakeDataList(chartThreeX.size(), Integer.class); + List 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); - } + } diff --git a/kh-modules/src/main/java/com/jero/modules/utils/RandomNumberUtil.java b/kh-modules/src/main/java/com/jero/modules/utils/RandomNumberUtil.java new file mode 100644 index 00000000..4824d147 --- /dev/null +++ b/kh-modules/src/main/java/com/jero/modules/utils/RandomNumberUtil.java @@ -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 List generateFakeDataList(int size, Class type) { + List 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 getLast30DaysFormattedDatesAscending() { + List 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; + } + + +}