feat(test): 添加谐波分析测试功能并重构设备测试类
- 添加新的BaseJunitTest测试类用于谐波分析功能测试 - 在AppTest中添加压降落点区域判定算法实现 - 重构AppTest类的依赖注入方式,从构造器注入改为字段注入 - 添加多个InfluxDB数据写入测试方法用于设备通信状态记录 - 实现完整的谐波报表生成功能包括Excel导出和数据处理逻辑 - 添加设备单位数据映射和统计方法用于报表展示 - 实现自定义报表模板解析和数据填充功能 - 添加数据库查询优化和并发处理支持
This commit is contained in:
@@ -8,7 +8,7 @@ microservice:
|
||||
gateway:
|
||||
url: @gateway.url@
|
||||
server:
|
||||
port: 10220
|
||||
port: 20220
|
||||
#feign接口开启服务熔断降级处理
|
||||
feign:
|
||||
sentinel:
|
||||
@@ -45,8 +45,8 @@ spring:
|
||||
|
||||
#项目日志的配置
|
||||
logging:
|
||||
# config: http://@nacos.url@/nacos/v1/cs/configs?tenant=@nacos.namespace@&username=@nacos.username@&password=@nacos.password@&group=DEFAULT_GROUP&dataId=logback.xml
|
||||
config: http://@nacos.url@/nacos/v1/cs/configs?tenant=@nacos.namespace@&group=DEFAULT_GROUP&dataId=logback.xml
|
||||
config: http://@nacos.url@/nacos/v1/cs/configs?tenant=@nacos.namespace@&username=@nacos.username@&password=@nacos.password@&group=DEFAULT_GROUP&dataId=logback.xml
|
||||
# config: http://@nacos.url@/nacos/v1/cs/configs?tenant=@nacos.namespace@&group=DEFAULT_GROUP&dataId=logback.xml
|
||||
level:
|
||||
root: warn
|
||||
|
||||
|
||||
@@ -3,12 +3,12 @@ package com.njcn;
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import com.njcn.csdevice.CsDeviceBootApplication;
|
||||
import com.njcn.csdevice.pojo.dto.PqsCommunicateDto;
|
||||
import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO;
|
||||
import com.njcn.csdevice.service.*;
|
||||
import com.njcn.influx.pojo.po.PqsCommunicate;
|
||||
import com.njcn.influx.query.InfluxQueryWrapper;
|
||||
import com.njcn.csdevice.service.DeviceFtpService;
|
||||
import com.njcn.csdevice.service.ICsCommunicateService;
|
||||
import com.njcn.csdevice.service.IRStatIntegrityDService;
|
||||
import com.njcn.csdevice.service.IRStatOnlineRateDService;
|
||||
import com.njcn.influx.utils.InfluxDbUtils;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.influxdb.InfluxDB;
|
||||
@@ -20,12 +20,15 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
@@ -37,7 +40,7 @@ import static org.junit.Assert.assertTrue;
|
||||
@WebAppConfiguration
|
||||
@SpringBootTest(classes = CsDeviceBootApplication.class)
|
||||
@Slf4j
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class AppTest{
|
||||
|
||||
@Autowired
|
||||
@@ -46,9 +49,69 @@ public class AppTest{
|
||||
@Autowired
|
||||
private ICsCommunicateService csCommunicateService;
|
||||
|
||||
private final IRStatIntegrityDService statIntegrityDService;
|
||||
private final IRStatOnlineRateDService statOnlineRateDService;
|
||||
@Autowired
|
||||
private IRStatIntegrityDService statIntegrityDService;
|
||||
|
||||
@Autowired
|
||||
private IRStatOnlineRateDService statOnlineRateDService;
|
||||
|
||||
public static void main(String[] args) {
|
||||
String eventValue = "122.5493";
|
||||
String persistTime = "0.2410";
|
||||
String data = determineDropZone(eventValue, persistTime);
|
||||
System.out.println("data==:" + data);
|
||||
}
|
||||
|
||||
|
||||
public static String determineDropZone(String eventValue, String persistTime) {
|
||||
if (eventValue != null && !eventValue.trim().isEmpty() && persistTime != null && !persistTime.trim().isEmpty()) {
|
||||
BigDecimal vvm;
|
||||
BigDecimal vvtm;
|
||||
try {
|
||||
vvm = (new BigDecimal(eventValue.trim())).divide(new BigDecimal("100"), 6, RoundingMode.HALF_UP);
|
||||
vvtm = new BigDecimal(persistTime.trim());
|
||||
} catch (Exception var6) {
|
||||
Exception e = var6;
|
||||
log.error("判定压降落点区域入参解析失败,eventValue={}, persistTime={}", new Object[]{eventValue, persistTime, e});
|
||||
return null;
|
||||
}
|
||||
|
||||
if (vvtm.compareTo(new BigDecimal("0.001")) >= 0 && vvm.compareTo(BigDecimal.ZERO) != 0) {
|
||||
if (inRange(vvm, "0.9", "1") && inRange(vvtm, "0.001", "60")) {
|
||||
return "A区";
|
||||
} else if (inRange(vvm, "0", "0.9") && inRange(vvtm, "0.001", "0.05")) {
|
||||
return "A区";
|
||||
} else if (inRange(vvm, "0.5", "0.7") && inRange(vvtm, "0.05", "0.2")) {
|
||||
return "B区";
|
||||
} else if (inRange(vvm, "0.7", "0.8") && inRange(vvtm, "0.05", "0.5")) {
|
||||
return "B区";
|
||||
} else if (inRange(vvm, "0.8", "0.9") && inRange(vvtm, "0.05", "60")) {
|
||||
return "B区";
|
||||
} else if (inRange(vvm, "0", "0.5") && inRange(vvtm, "0.05", "1")) {
|
||||
return "C区";
|
||||
} else if (inRange(vvm, "0.5", "0.7") && inRange(vvtm, "0.2", "1")) {
|
||||
return "C区";
|
||||
} else if (inRange(vvm, "0.7", "0.8") && inRange(vvtm, "0.5", "1")) {
|
||||
return "C区";
|
||||
} else if (inRange(vvm, "0", "0.8") && inRange(vvtm, "1", "60")) {
|
||||
return "D区";
|
||||
} else {
|
||||
log.warn("压降落点区域未匹配任何规则,eventValue={}, persistTime={}", eventValue, persistTime);
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
return "A区";
|
||||
}
|
||||
} else {
|
||||
log.warn("判定压降落点区域入参为空,eventValue={}, persistTime={}", eventValue, persistTime);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean inRange(BigDecimal value, String lowerInclusive, String upperExclusive) {
|
||||
return value.compareTo(new BigDecimal(lowerInclusive)) >= 0
|
||||
&& value.compareTo(new BigDecimal(upperExclusive)) < 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rigorous Test :-)
|
||||
@@ -59,7 +122,6 @@ public class AppTest{
|
||||
assertTrue( true );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 测试下载文件
|
||||
*/
|
||||
@@ -95,18 +157,76 @@ public class AppTest{
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
InfluxDbUtils influxDbUtils = new InfluxDbUtils("admin", "123456", "http://192.168.1.24:8086", "pqsbase_zl", "");
|
||||
|
||||
|
||||
public static void test2() {
|
||||
InfluxDbUtils influxDbUtils = new InfluxDbUtils("admin", "123456", "http://192.168.1.103:18086", "pqsbase", "");
|
||||
Map<String, String> tags = new HashMap<>();
|
||||
tags.put("dev_id","da7aa071bf89864bedea8833133676b7");
|
||||
tags.put("dev_id","0eb0262f706445ac9c69931a60357561");
|
||||
Map<String,Object> fields = new HashMap<>();
|
||||
fields.put("type",1);
|
||||
fields.put("description","通讯正常");
|
||||
long time = LocalDateTime.parse("2025-08-02 18:00:00", DateTimeFormatter.ofPattern(DatePattern.NORM_DATETIME_PATTERN)).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
|
||||
// fields.put("type",1);
|
||||
// fields.put("description","通讯正常");
|
||||
fields.put("type",0);
|
||||
fields.put("description","通讯中断");
|
||||
long time = LocalDateTime.parse("2024-01-06 06:00:00", DateTimeFormatter.ofPattern(DatePattern.NORM_DATETIME_PATTERN)).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
|
||||
Point point = influxDbUtils.pointBuilder("pqs_communicate", time, TimeUnit.MILLISECONDS, tags, fields);
|
||||
BatchPoints batchPoints = BatchPoints.database(influxDbUtils.getDbName()).retentionPolicy("").consistency(InfluxDB.ConsistencyLevel.ALL).build();
|
||||
batchPoints.point(point);
|
||||
influxDbUtils.batchInsert(influxDbUtils.getDbName(), "", InfluxDB.ConsistencyLevel.ALL, TimeUnit.MILLISECONDS, Collections.singletonList(batchPoints.lineProtocol()));
|
||||
|
||||
}
|
||||
|
||||
public static void test22() {
|
||||
InfluxDbUtils influxDbUtils = new InfluxDbUtils("admin", "123456", "http://192.168.1.103:18086", "pqsbase", "");
|
||||
Map<String, String> tags = new HashMap<>();
|
||||
tags.put("dev_id","0eb0262f706445ac9c69931a60357561");
|
||||
Map<String,Object> fields = new HashMap<>();
|
||||
fields.put("type",1);
|
||||
fields.put("description","通讯正常");
|
||||
// fields.put("type",0);
|
||||
// fields.put("description","通讯中断");
|
||||
long time = LocalDateTime.parse("2024-01-06 12:00:00", DateTimeFormatter.ofPattern(DatePattern.NORM_DATETIME_PATTERN)).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
|
||||
Point point = influxDbUtils.pointBuilder("pqs_communicate", time, TimeUnit.MILLISECONDS, tags, fields);
|
||||
BatchPoints batchPoints = BatchPoints.database(influxDbUtils.getDbName()).retentionPolicy("").consistency(InfluxDB.ConsistencyLevel.ALL).build();
|
||||
batchPoints.point(point);
|
||||
influxDbUtils.batchInsert(influxDbUtils.getDbName(), "", InfluxDB.ConsistencyLevel.ALL, TimeUnit.MILLISECONDS, Collections.singletonList(batchPoints.lineProtocol()));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void test3() {
|
||||
InfluxDbUtils influxDbUtils = new InfluxDbUtils("admin", "123456", "http://192.168.1.103:18086", "pqsbase", "");
|
||||
Map<String, String> tags = new HashMap<>();
|
||||
tags.put("dev_id","0eb0262f706445ac9c69931a60357561");
|
||||
Map<String,Object> fields = new HashMap<>();
|
||||
fields.put("type",0);
|
||||
fields.put("description","通讯中断");
|
||||
// fields.put("type",1);
|
||||
// fields.put("description","通讯正常");
|
||||
long time = LocalDateTime.parse("2024-01-06 18:00:00", DateTimeFormatter.ofPattern(DatePattern.NORM_DATETIME_PATTERN)).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
|
||||
Point point = influxDbUtils.pointBuilder("pqs_communicate", time, TimeUnit.MILLISECONDS, tags, fields);
|
||||
BatchPoints batchPoints = BatchPoints.database(influxDbUtils.getDbName()).retentionPolicy("").consistency(InfluxDB.ConsistencyLevel.ALL).build();
|
||||
batchPoints.point(point);
|
||||
influxDbUtils.batchInsert(influxDbUtils.getDbName(), "", InfluxDB.ConsistencyLevel.ALL, TimeUnit.MILLISECONDS, Collections.singletonList(batchPoints.lineProtocol()));
|
||||
|
||||
}
|
||||
|
||||
public static void test33() {
|
||||
InfluxDbUtils influxDbUtils = new InfluxDbUtils("admin", "123456", "http://192.168.1.103:18086", "pqsbase", "");
|
||||
Map<String, String> tags = new HashMap<>();
|
||||
tags.put("dev_id","0eb0262f706445ac9c69931a60357561");
|
||||
Map<String,Object> fields = new HashMap<>();
|
||||
// fields.put("type",0);
|
||||
// fields.put("description","通讯中断");
|
||||
fields.put("type",1);
|
||||
fields.put("description","通讯正常");
|
||||
long time = LocalDateTime.parse("2024-01-06 22:00:00", DateTimeFormatter.ofPattern(DatePattern.NORM_DATETIME_PATTERN)).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
|
||||
Point point = influxDbUtils.pointBuilder("pqs_communicate", time, TimeUnit.MILLISECONDS, tags, fields);
|
||||
BatchPoints batchPoints = BatchPoints.database(influxDbUtils.getDbName()).retentionPolicy("").consistency(InfluxDB.ConsistencyLevel.ALL).build();
|
||||
batchPoints.point(point);
|
||||
influxDbUtils.batchInsert(influxDbUtils.getDbName(), "", InfluxDB.ConsistencyLevel.ALL, TimeUnit.MILLISECONDS, Collections.singletonList(batchPoints.lineProtocol()));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user