Ver código fonte

设备发电量-1

malijun 1 ano atrás
pai
commit
a9434684c4

+ 94 - 0
electricity/meter/src/main/java/com/gyee/gaia/meter/service/OneTest.java

@@ -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);
+                    }
+                }
+
+            }
+        }
+    }
+}

+ 5 - 4
electricity/meter/src/main/java/com/gyee/gaia/meter/service/SaveMeterInfoHistoryDayTest.java

@@ -106,7 +106,7 @@ class SaveMeterInfoHistoryDayTest {
                             double current = arrayList.get(j);
                             double previous = arrayList.get(j - 1);
                             double difference = current - previous;
-                            if (difference > 50000 || difference < 0) {
+                            if (difference > 50000 || difference < -1) {
                                 index = j;
                                 break;
                             }
@@ -116,7 +116,7 @@ class SaveMeterInfoHistoryDayTest {
                             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));
+                            rfdl = (bigDecimal2.subtract(bigDecimalGrow2)).add(bigDecimalGrow1.subtract(bigDecimal1));
                         }
                     }
                 }
@@ -131,6 +131,7 @@ class SaveMeterInfoHistoryDayTest {
                 meterInfoEquipment.setName(thingId1.getName());
                 meterInfoEquipment.setDate(dateTime1.toLocalDateTime());
                 meterInfoEquipment.setRfdl(rfdl);
+                meterInfoEquipment.setUpdateTime(LocalDateTime.now());
                 QueryWrapper<MeterInfoEquipment> queryWrapper = new QueryWrapper<>();
                 queryWrapper.eq("equipment_nem_code", thingId1.getNemCode()).eq("date", dateTime1.toLocalDateTime());
                 List<MeterInfoEquipment> list = meterInfoEquipmentService.list(queryWrapper);
@@ -418,8 +419,8 @@ class SaveMeterInfoHistoryDayTest {
     //调用上面4个,第四个需要3-4次
     @Test
     void saveCalculating3() {
-//        this.saveEquipmentRfdl();
-//        this.saveBottomCode();
+        this.saveEquipmentRfdl();
+        this.saveBottomCode();
         this.saveCalculatingProjectFDL();
         this.saveCalculating();
         this.saveCalculating();

+ 2 - 2
electricity/meter/src/main/resources/application.properties

@@ -6,9 +6,9 @@
 adapter.url=http://192.168.1.67:8011/ts
 
 #动态配置开始日期
-start.time=2023-05-1
+start.time=2023-03-27
 #动态配置结束日期
-end.time=2023-05-23
+end.time=2023-03-27
 
 meter.stations=MHS_FDC,NSS_FDC
 

+ 0 - 12
electricity/meter/src/main/resources/cross.html

@@ -1,12 +0,0 @@
-<!DOCTYPE html>
-<html>
-<script type="text/javascript">
-  var xhr = new XMLHttpRequest();
-  xhr.open('GET', 'http://192.168.10.24:8021/meterinfo?id=-1'); // 换为自己的接口地址
-  xhr.send(null);
-  xhr.onload = function(e) {
-    var xhr = e.target;
-    console.log(xhr.responseText);
-  }
-</script>
-</html>