|
@@ -0,0 +1,94 @@
|
|
|
|
+package com.gyee.gaia.meter.service;
|
|
|
|
+
|
|
|
|
+import cn.hutool.core.date.DateTime;
|
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
|
+import cn.hutool.core.date.LocalDateTimeUtil;
|
|
|
|
+import com.gyee.gaia.meter.adapter.Adapter;
|
|
|
|
+import com.gyee.gaia.meter.entity.PointData;
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
|
+import org.springframework.boot.test.context.SpringBootTest;
|
|
|
|
+
|
|
|
|
+import javax.annotation.Resource;
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
|
+import java.time.temporal.ChronoUnit;
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.List;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * Author: malijun
|
|
|
|
+ * Data : 2023: 05: 23
|
|
|
|
+ **/
|
|
|
|
+@SpringBootTest
|
|
|
|
+public class OneTest {
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @Value("${start.time}")
|
|
|
|
+ private String startTimeString;
|
|
|
|
+ @Value("${end.time}")
|
|
|
|
+ private String endTimeString;
|
|
|
|
+ @Resource
|
|
|
|
+ Adapter adapter;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @org.junit.jupiter.api.Test
|
|
|
|
+ void test() {
|
|
|
|
+ //设置取值开始时间
|
|
|
|
+ String startString = startTimeString;
|
|
|
|
+ DateTime startDateTime = DateUtil.parse(startString);
|
|
|
|
+
|
|
|
|
+ //设置取值结束时间
|
|
|
|
+ String endDateString = endTimeString;
|
|
|
|
+ DateTime endDateTime = DateUtil.parse(endDateString);
|
|
|
|
+
|
|
|
|
+ //指定开始日期到结束日期的天数
|
|
|
|
+ LocalDateTime day1 = LocalDateTimeUtil.of(startDateTime);
|
|
|
|
+ LocalDateTime day2 = LocalDateTimeUtil.of(endDateTime);
|
|
|
|
+ long between = ChronoUnit.DAYS.between(day1, day2);
|
|
|
|
+
|
|
|
|
+ for (int i = 0; i <= between; i++) {
|
|
|
|
+
|
|
|
|
+ DateTime dateTime1 = DateUtil.offsetDay(startDateTime, i);
|
|
|
|
+ DateTime dateTime2 = DateUtil.offsetDay(startDateTime, i + 1);
|
|
|
|
+
|
|
|
|
+ //8,结束点发电量减去开始点发电量得到日发电量(单位Kwh)
|
|
|
|
+ List<PointData> historyRaw = adapter.getHistoryRaw("SBQFJ.NX_GD_SBQF_FJ_P2_L4_043_AI0064", dateTime1.getTime(), dateTime2.getTime());
|
|
|
|
+
|
|
|
|
+ BigDecimal rfdl = new BigDecimal(0);
|
|
|
|
+
|
|
|
|
+ if (historyRaw.size() > 0) {
|
|
|
|
+ BigDecimal bigDecimal1 = new BigDecimal(Double.toString(historyRaw.get(0).getValue()));
|
|
|
|
+ BigDecimal bigDecimal2 = new BigDecimal(Double.toString(historyRaw.get(historyRaw.size() - 1).getValue()));
|
|
|
|
+ rfdl = bigDecimal2.subtract(bigDecimal1);
|
|
|
|
+
|
|
|
|
+ if (rfdl.doubleValue() > 50000 || rfdl.doubleValue() < 0) {
|
|
|
|
+
|
|
|
|
+ ArrayList<Double> arrayList = new ArrayList<>();
|
|
|
|
+ for (PointData pointData : historyRaw) {
|
|
|
|
+ arrayList.add(pointData.getValue());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ int index = -1;
|
|
|
|
+ for (int j = 1; j < arrayList.size(); j++) {
|
|
|
|
+ double current = arrayList.get(j);
|
|
|
|
+ double previous = arrayList.get(j - 1);
|
|
|
|
+ double difference = current - previous;
|
|
|
|
+ if (difference > 50000 || difference < -1) {
|
|
|
|
+ index = j;
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (index != -1) {
|
|
|
|
+ double valueGrow2 = arrayList.get(index);
|
|
|
|
+ BigDecimal bigDecimalGrow2 = new BigDecimal(Double.toString(valueGrow2));
|
|
|
|
+ double valueGrow1 = arrayList.get(index - 1);
|
|
|
|
+ BigDecimal bigDecimalGrow1 = new BigDecimal(Double.toString(valueGrow1));
|
|
|
|
+ rfdl = (bigDecimal2.subtract(bigDecimalGrow2)).add(bigDecimalGrow1.subtract(bigDecimal1));
|
|
|
|
+ System.out.println("重新赋值后:"+rfdl);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|