malijun 1 年之前
父节点
当前提交
5d98c3c18b

文件差异内容过多而无法显示
+ 2505 - 0
electricity/meter/logs/2023-05/warn-2023-05-15.1.log


文件差异内容过多而无法显示
+ 117 - 2505
electricity/meter/logs/warn.log


+ 7 - 5
electricity/meter/src/main/java/com/gyee/gaia/meter/job/MeterJob.java

@@ -12,21 +12,23 @@ import javax.annotation.Resource;
 @Component
 public class MeterJob {
 
-    @Resource
-    SaveEquipmentRfdl saveEquipmentRfdl;
+
     @Resource
     SaveCalculatingFJFDL saveCalculatingFJFDL;
     @Resource
-    SaveBottomcode saveBottomcode;
-    @Resource
     SaveCalculating saveCalculating;
+    @Resource
+    SaveEquipmentRfdl saveEquipmentRfdl;
+    @Resource
+    SaveBottomcode saveBottomcode;
+
 
 
     @XxlJob("MeterJob")
     void meterJob(){
         saveEquipmentRfdl.saveEquipmentRfdl();
+        saveBottomcode.saveBottomCode();
         saveCalculatingFJFDL.saveCalculatingFJFDL();
-        saveBottomcode.saveBottomcode();
         saveCalculating.saveCalculating();
         saveCalculating.saveCalculating();
         saveCalculating.saveCalculating();

+ 71 - 38
electricity/meter/src/main/java/com/gyee/gaia/meter/job/SaveBottomcode.java

@@ -17,9 +17,8 @@ import org.springframework.stereotype.Component;
 import javax.annotation.Resource;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
-import java.time.LocalDateTime;
+import java.util.ArrayList;
 import java.util.List;
-import java.util.Map;
 
 /**
  * Author: malijun
@@ -39,11 +38,7 @@ public class SaveBottomcode {
     Adapter adapter;
 
     @XxlJob("SaveBottomcode")
-    void saveBottomcode() {
-
-        //获取当前日期,当日开始时间
-        DateTime nowDateTime = DateUtil.parse(DateUtil.now());
-        DateTime startDateTime = DateUtil.beginOfDay(nowDateTime);
+    void saveBottomCode() {
 
         //1,查询所有风电场
         List<PowerStation> powerStationList = powerStationService.list(new QueryWrapper<PowerStation>().like("nem_code", "_FDC_"));
@@ -52,53 +47,89 @@ public class SaveBottomcode {
 
             //2,根据场站ID得到场站下所有测点
             List<MeterPoint> meterPointList = meterPointService.list(new QueryWrapper<MeterPoint>().eq("windpowerstation_id", powerStation.getId()).eq("property", "CD"));
-            System.out.println(powerStation.getNemCode() + "场站测点数量" + meterPointList.size());
 
             //3,遍历测点,拿到每个测点的nem_code
             for (MeterPoint meterPoint : meterPointList) {
-
+                System.out.println(meterPoint);
                 //获取测点code
                 String pointcode = meterPoint.getNemCode();
 
-                //根据测点code,时间00:00:01,用适配器section接口获取数据
-                Map<String, PointData> historySection1 = adapter.getHistorySection(pointcode, DateUtil.offsetSecond(startDateTime, 1).getTime());
-
-                double value1 = 0;
-                if (historySection1.size() > 0) {
-                    value1 = historySection1.get(pointcode).getValue();
-                }
-                BigDecimal bigDecimal1 = BigDecimal.valueOf(value1);
-
-                //除以系数
-                bigDecimal1 = bigDecimal1.divide(meterPoint.getXs(), 4, RoundingMode.HALF_EVEN);
-
-                //根据测点code,用适配器latest接口获取最新数据和时间,存入数据库结束值
-                Map<String, PointData> historyLatest2 = adapter.getHistoryLatest(pointcode);
-                double value2 = 0;
-                if (historyLatest2.size() > 0) {
-                    value2 = historyLatest2.get(pointcode).getValue();
+                //2,获取当前日期,当日开始时间
+                DateTime nowDateTime = DateUtil.parse(DateUtil.now());
+                DateTime startDateTime = DateUtil.beginOfDay(nowDateTime);
+
+
+                //开始时间00:00:01
+                DateTime dateTime1 = DateUtil.offsetSecond(startDateTime, 1);
+                //结束时间第二天00:00:01
+                DateTime dateTime2 = DateUtil.offsetSecond(DateUtil.offsetDay(startDateTime, 1), 1);
+
+                //从适配器拿当日数据
+                List<PointData> historyRaw = adapter.getHistoryRaw(pointcode, dateTime1.getTime(), dateTime2.getTime());
+
+                //定义开始值,结束值,日发电量值,给0,避免适配器拿不到数
+                BigDecimal bigDecimal1 = new BigDecimal(0);
+                BigDecimal bigDecimal2 = new BigDecimal(0);
+                BigDecimal rfdl = new BigDecimal(0);
+
+                //适配器拿到开始值和结束值,除以系数(四舍五入保留4位),乘倍率得到日电量
+                if (historyRaw.size() > 0) {
+                    bigDecimal1 = new BigDecimal(Double.toString(historyRaw.get(0).getValue()));
+                    bigDecimal1 = bigDecimal1.divide(meterPoint.getXs(), 4, RoundingMode.HALF_EVEN);
+                    bigDecimal2 = new BigDecimal(Double.toString(historyRaw.get(historyRaw.size() - 1).getValue()));
+                    bigDecimal2 = bigDecimal2.divide(meterPoint.getXs(), 4, RoundingMode.HALF_EVEN);
+                    rfdl = bigDecimal2.subtract(bigDecimal1).multiply(meterPoint.getMagnification());
+
+                    //如果日电量大于3000000千瓦时,或者小于0,说明数据异常,进行数据处理
+                    if (rfdl.doubleValue() > 3000000 || rfdl.doubleValue() < 0) {
+
+                        //数组集合存当日所有数据
+                        ArrayList<Double> arrayList = new ArrayList<>();
+                        for (PointData pointData : historyRaw) {
+                            arrayList.add(pointData.getValue());
+                        }
+                        //定义突变数据索引
+                        int index = -1;
+                        // 定义增长阈值
+                        double threshold = 3000000.0;
+                        //遍历数组集合,拿到当前值和前一个值,相减得到变化值
+                        for (int j = 1; j < arrayList.size(); j++) {
+                            double current = arrayList.get(j);
+                            double previous = arrayList.get(j - 1);
+                            double difference = (current - previous) / meterPoint.getXs().doubleValue() * meterPoint.getMagnification().doubleValue();
+                            //如果变化值大于阈值,或者小于0,返回突变数据索引
+                            if (difference > threshold || difference < 0) {
+                                index = j;
+                                break;
+                            }
+                        }
+                        //如果突变数据索引不等于-1说明有突变数据,进行如下数据处理
+                        if (index != -1) {
+                            double valueGrow2 = arrayList.get(index);
+                            BigDecimal bigDecimalGrow2 = new BigDecimal(Double.toString(valueGrow2));
+                            bigDecimalGrow2 = bigDecimalGrow2.divide(meterPoint.getXs(), 4, RoundingMode.HALF_EVEN);
+                            double valueGrow1 = arrayList.get(index - 1);
+                            BigDecimal bigDecimalGrow1 = new BigDecimal(Double.toString(valueGrow1));
+                            bigDecimalGrow1 = bigDecimalGrow1.divide(meterPoint.getXs(), 4, RoundingMode.HALF_EVEN);
+                            //(结束值-突变值)+(突变值前值-开始值)
+                            rfdl = (bigDecimal2.subtract(bigDecimalGrow2).add(bigDecimalGrow1).subtract(bigDecimal1)).multiply(meterPoint.getMagnification());
+                        }
+                    }
                 }
-                BigDecimal bigDecimal2 = BigDecimal.valueOf(value2);
-
-                //除以系数
-                bigDecimal2 = bigDecimal2.divide(meterPoint.getXs(), 4, RoundingMode.HALF_EVEN);
-
-                //乘倍率,计算日电量单位:千瓦时
-                BigDecimal rfdl = bigDecimal2.subtract(bigDecimal1).multiply(meterPoint.getMagnification());
 
                 MeterInfoBottomcode meterInfoBottomcode = new MeterInfoBottomcode();
                 meterInfoBottomcode.setName(meterPoint.getName());
-                meterInfoBottomcode.setStartTime(DateUtil.offsetSecond(startDateTime, 1).toLocalDateTime());
+                meterInfoBottomcode.setStartTime(dateTime1.toLocalDateTime());
                 meterInfoBottomcode.setStartValue(bigDecimal1);
-                meterInfoBottomcode.setEndTime(LocalDateTime.now());
+                meterInfoBottomcode.setEndTime(nowDateTime.toLocalDateTime());
                 meterInfoBottomcode.setEndValue(bigDecimal2);
                 meterInfoBottomcode.setDayValue(rfdl);
-                meterInfoBottomcode.setCode(meterPoint.getNemCode());
+                meterInfoBottomcode.setCode(pointcode);
                 meterInfoBottomcode.setWindpowerstationId(meterPoint.getWindpowerstationId());
 
+                //判断有无数据,插入或者更新
                 QueryWrapper<MeterInfoBottomcode> queryWrapper = new QueryWrapper<>();
-                queryWrapper.eq("start_time", DateUtil.offsetSecond(startDateTime, 1).toLocalDateTime()).eq("code", meterPoint.getNemCode());
-
+                queryWrapper.eq("start_time", dateTime1.toLocalDateTime()).eq("code", meterPoint.getNemCode());
                 List<MeterInfoBottomcode> list = meterInfoBottomcodeService.list(queryWrapper);
                 if (list.size() > 0) {
                     meterInfoBottomcode.update(queryWrapper);
@@ -109,6 +140,8 @@ public class SaveBottomcode {
 
             }
         }
+
+
     }
 
 

+ 1 - 0
electricity/meter/src/main/java/com/gyee/gaia/meter/job/SaveCalculating.java

@@ -92,6 +92,7 @@ public class SaveCalculating {
                     meterInfoCalculating.setCode(meterPoint.getNemCode());
                     meterInfoCalculating.setDate(dateTime1.toLocalDateTime());
                     meterInfoCalculating.setValue(bigDecimal1);
+                    meterInfoCalculating.setUpdateTime(nowDateTime.toLocalDateTime());
                     meterInfoCalculating.setWindpowerstationId(meterPoint.getWindpowerstationId());
 
                     QueryWrapper<MeterInfoCalculating> queryWrapper = new QueryWrapper<>();

+ 1 - 0
electricity/meter/src/main/java/com/gyee/gaia/meter/job/SaveCalculatingFJFDL.java

@@ -66,6 +66,7 @@ public class SaveCalculatingFJFDL {
             meterInfoCalculating.setDate(dateTime1.toLocalDateTime());
             meterInfoCalculating.setValue(bigDecimal.divide(BigDecimal.valueOf(10000), 4, RoundingMode.HALF_EVEN));
             meterInfoCalculating.setCode(meterPoint.getNemCode());
+            meterInfoCalculating.setUpdateTime(nowDateTime.toLocalDateTime());
             meterInfoCalculating.setWindpowerstationId(meterPoint.getWindpowerstationId());
 
 

+ 73 - 43
electricity/meter/src/main/java/com/gyee/gaia/meter/job/SaveEquipmentRfdl.java

@@ -16,8 +16,8 @@ import org.springframework.stereotype.Component;
 
 import javax.annotation.Resource;
 import java.math.BigDecimal;
+import java.util.ArrayList;
 import java.util.List;
-import java.util.Map;
 
 /**
  * Author: malijun
@@ -42,56 +42,87 @@ public class SaveEquipmentRfdl {
         //1,在testingpoint中根据 uniform_code=AI064 和code like "%_FJ_%" 取出所有风机的电量测点code
         List<TestingPoint> testingPointList = testingPointService.list(new QueryWrapper<TestingPoint>().eq("uniform_code", "AI064").like("code", "%_FJ_%"));
 
-        //2,获取当前日期,当日开始时间
-        DateTime nowDateTime = DateUtil.parse(DateUtil.now());
-        DateTime startDateTime = DateUtil.beginOfDay(nowDateTime);
-
-        //3,遍历测点集合,每次取出一个code
+        //2,遍历list,每次取出一个code
         for (TestingPoint testingPoint : testingPointList) {
-
             //获取测点code
             String pointcode = testingPoint.getCode();
-
-            //4,根据code和日期开始时间00:00:01获取日期开始点发电量
-            Map<String, PointData> historySection1 = adapter.getHistorySection(pointcode, DateUtil.offsetSecond(startDateTime, 1).getTime());
-
-            double value1 = 0;
-            if (historySection1.size() > 0) {
-                value1 = historySection1.get(pointcode).getValue();
-            }
-
-            BigDecimal bigDecimal1 = BigDecimal.valueOf(value1);
-
-            //5,根据code获取最新时间点发电量
-            Map<String, PointData> historyLatest2 = adapter.getHistoryLatest(pointcode);
-
-            double value2 = 0;
-            if (historyLatest2.size() > 0) {
-                value2 = historyLatest2.get(pointcode).getValue();
+            //获取设备ID
+            String thingId = testingPoint.getThingId();
+
+            //2,获取当前日期,当日开始时间
+            DateTime nowDateTime = DateUtil.parse(DateUtil.now());
+            DateTime startDateTime = DateUtil.beginOfDay(nowDateTime);
+
+
+            //开始时间00:00:01
+            DateTime dateTime1 = DateUtil.offsetSecond(startDateTime, 1);
+            //结束时间第二天00:00:01
+            DateTime dateTime2 = DateUtil.offsetSecond(DateUtil.offsetDay(startDateTime, 1), 1);
+
+            //8,通过适配器拿到一天的发电量数据,
+            List<PointData> historyRaw = adapter.getHistoryRaw(pointcode, dateTime1.getTime(), dateTime2.getTime());
+
+            //定义日发电量,先给0
+            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);
+
+                //如果日发电量大于50000千瓦时或者小于0,说明数据异常进行处理
+                if (rfdl.doubleValue() > 50000 || rfdl.doubleValue() < 0) {
+
+                    //数据集合放所有数据
+                    ArrayList<Double> arrayList = new ArrayList<>();
+                    for (PointData pointData : historyRaw) {
+                        arrayList.add(pointData.getValue());
+                    }
+
+                    //定义突变值索引
+                    int index = -1;
+                    //定于阈值
+                    double threshold =50000;
+                    //遍历数组集合,拿出当前数和前值相减得到变化值
+                    for (int j = 1; j < arrayList.size(); j++) {
+                        double difference = arrayList.get(j) - arrayList.get(j - 1);
+                        //如果变化值difference大于阈值或者小于0,返回当前突变数据的索引
+                        if (difference > threshold || difference < 0) {
+                            index = j;
+                            break;
+                        }
+                    }
+
+                    //如果突变值索引不等于-1,进行数据处理
+                    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));
+                    }
+                }
             }
-
-            BigDecimal bigDecimal2 = BigDecimal.valueOf(value2);
-
-            //6,结束点发电量减去开始点发电量得到日发电量(单位Kwh)
-            BigDecimal rfdl = bigDecimal2.subtract(bigDecimal1);
-
-            //7,company_nem_code   (powerstation_nem_code project_nem_code line_nem_code equipment_nem_code )都在basic equipment中叫project_id    name date rfdl 存入meterInfo表中
-
-            //8,根据设备在equipment表中拿到设备对象
-            Equipment equipment = equipmentService.getOne(new QueryWrapper<Equipment>().eq("nem_code", testingPoint.getThingId()));
+            //9,company_nem_code   (powerstation_nem_code project_nem_code line_nem_code equipment_nem_code )都在basic equipment中叫project_id    name date rfdl 存入meterInfo表中
+            Equipment thingId1 = equipmentService.getOne(new QueryWrapper<Equipment>().eq("nem_code", thingId));
 
             MeterInfoEquipment meterInfoEquipment = new MeterInfoEquipment();
-            meterInfoEquipment.setPowerstationNemCode(equipment.getWindpowerstationId());
-            meterInfoEquipment.setProjectNemCode(equipment.getProjectId());
-            meterInfoEquipment.setLineNemCode(equipment.getLineId());
-            meterInfoEquipment.setEquipmentNemCode(equipment.getNemCode());
-            meterInfoEquipment.setName(equipment.getName());
-            meterInfoEquipment.setDate(DateUtil.offsetSecond(startDateTime, 1).toLocalDateTime());
+            meterInfoEquipment.setPowerstationNemCode(thingId1.getWindpowerstationId());
+            meterInfoEquipment.setProjectNemCode(thingId1.getProjectId());
+            meterInfoEquipment.setLineNemCode(thingId1.getLineId());
+            meterInfoEquipment.setEquipmentNemCode(thingId1.getNemCode());
+            meterInfoEquipment.setName(thingId1.getName());
+            meterInfoEquipment.setDate(dateTime1.toLocalDateTime());
+            meterInfoEquipment.setUpdateTime(nowDateTime.toLocalDateTime());
             meterInfoEquipment.setRfdl(rfdl);
 
-
+            //判断当前数据是否存在,更新或者插入
             QueryWrapper<MeterInfoEquipment> queryWrapper = new QueryWrapper<>();
-            queryWrapper.eq("equipment_nem_code", equipment.getNemCode()).eq("date", DateUtil.offsetSecond(startDateTime, 1).toLocalDateTime());
+            queryWrapper.eq("equipment_nem_code", thingId1.getNemCode()).eq("date", dateTime1.toLocalDateTime());
             List<MeterInfoEquipment> list = meterInfoEquipmentService.list(queryWrapper);
             if (list.size() > 0) {
                 meterInfoEquipment.update(queryWrapper);
@@ -99,7 +130,6 @@ public class SaveEquipmentRfdl {
                 meterInfoEquipment.insert();
             }
 
-
         }
     }
 

+ 80 - 55
electricity/meter/src/main/java/com/gyee/gaia/meter/service/SaveMeterInfoHistoryTest.java

@@ -18,10 +18,7 @@ import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.time.LocalDateTime;
 import java.time.temporal.ChronoUnit;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 /**
  * Author: malijun
@@ -49,7 +46,6 @@ class SaveMeterInfoHistoryTest {
     MeterInfoCalculatingServiceImpl meterInfoCalculatingService;
 
 
-
     @Value("${start.time}")
     private String startTimeString;
     @Value("${end.time}")
@@ -63,8 +59,6 @@ class SaveMeterInfoHistoryTest {
         //1,在testingpoint中根据 uniform_code=AI064 和code like "%_FJ_%" 取出所有风机的电量测点code
         List<TestingPoint> testingPointList = testingPointService.list(new QueryWrapper<TestingPoint>().eq("uniform_code", "AI064").like("code", "%_FJ_%"));
 
-        //所有风机总共407个电量测点code
-
         //2,遍历list,每次取出一个code
         for (TestingPoint testingPoint : testingPointList) {
             //获取测点code
@@ -87,30 +81,50 @@ class SaveMeterInfoHistoryTest {
 
             for (int i = 0; i <= between; i++) {
 
-
                 //开始时间00:00:01
                 DateTime dateTime1 = DateUtil.offsetSecond(DateUtil.offsetDay(startDateTime, i), 1);
                 //结束时间第二天00:00:01
                 DateTime dateTime2 = DateUtil.offsetSecond(DateUtil.offsetDay(startDateTime, i + 1), 1);
 
-                //6,根据code和日期开始时间00:00:00获取日期开始点发电量
-                Map<String, PointData> historySection1 = adapter.getHistorySection(pointcode, dateTime1.getTime());
-                double value1 = historySection1.get(pointcode).getValue();
+                //8,结束点发电量减去开始点发电量得到日发电量(单位Kwh)
+                List<PointData> historyRaw = adapter.getHistoryRaw(pointcode, dateTime1.getTime(), dateTime2.getTime());
 
-                //7,根据code和日期结束时间23:59:59获取日期结束点发电量
-                Map<String, PointData> historySection2 = adapter.getHistorySection(pointcode, dateTime2.getTime());
-                double value2 = historySection2.get(pointcode).getValue();
+                BigDecimal rfdl = new BigDecimal(0);
 
-                //8,结束点发电量减去开始点发电量得到日发电量(单位Kwh)
-                BigDecimal bigDecimal1 = new BigDecimal(Double.toString(value1));
-                BigDecimal bigDecimal2 = new BigDecimal(Double.toString(value2));
-                BigDecimal rfdl = bigDecimal2.subtract(bigDecimal1);
+                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 < 0) {
+                                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));
+                        }
+                    }
+                }
                 //9,company_nem_code   (powerstation_nem_code project_nem_code line_nem_code equipment_nem_code )都在basic equipment中叫project_id    name date rfdl 存入meterInfo表中
                 Equipment thingId1 = equipmentService.getOne(new QueryWrapper<Equipment>().eq("nem_code", thingId));
 
-
                 MeterInfoEquipment meterInfoEquipment = new MeterInfoEquipment();
                 meterInfoEquipment.setPowerstationNemCode(thingId1.getWindpowerstationId());
                 meterInfoEquipment.setProjectNemCode(thingId1.getProjectId());
@@ -127,14 +141,10 @@ class SaveMeterInfoHistoryTest {
                 } else {
                     meterInfoEquipment.insert();
                 }
-
-
             }
         }
-
     }
 
-    //读取时间段内meter_point表中所有电计量测点数据存入pg数据库
     @Test
     void saveBottomCode() {
 
@@ -172,25 +182,46 @@ class SaveMeterInfoHistoryTest {
                     //结束时间第二天00:00:01
                     DateTime dateTime2 = DateUtil.offsetSecond(DateUtil.offsetDay(startDateTime, i + 1), 1);
 
-                    //6,根据测点code和日期开始时间00:00:01获取日期开始点发电量
-                    Map<String, PointData> historySection1 = adapter.getHistorySection(pointcode, dateTime1.getTime());
-
-                    //7,根据测点code和日期结束时间第二点00:00:01获取日期结束点发电量
-                    Map<String, PointData> historySection2 = adapter.getHistorySection(pointcode, dateTime2.getTime());
-
-                    BigDecimal bigDecimal1 = meterPoint.getInitialValue();
-                    BigDecimal bigDecimal2 = meterPoint.getInitialValue();
-
-
-                    if (historySection1.size() > 0 && historySection2.size() > 0) {
-                        double value1 = historySection1.get(pointcode).getValue();
-                        double value2 = historySection2.get(pointcode).getValue();
-                        bigDecimal1 = new BigDecimal(Double.toString(value1));
-                        bigDecimal2 = new BigDecimal(Double.toString(value2));
+                    List<PointData> historyRaw = adapter.getHistoryRaw(pointcode, dateTime1.getTime(), dateTime2.getTime());
+                    BigDecimal bigDecimal1 = new BigDecimal(0);
+                    BigDecimal bigDecimal2 = new BigDecimal(0);
+                    BigDecimal rfdl = new BigDecimal(0);
+
+                    if (historyRaw.size() > 0) {
+                        bigDecimal1 = new BigDecimal(Double.toString(historyRaw.get(0).getValue()));
+                        bigDecimal1 = bigDecimal1.divide(meterPoint.getXs(), 4, RoundingMode.HALF_EVEN);
+                        bigDecimal2 = new BigDecimal(Double.toString(historyRaw.get(historyRaw.size() - 1).getValue()));
+                        bigDecimal2 = bigDecimal2.divide(meterPoint.getXs(), 4, RoundingMode.HALF_EVEN);
+                        rfdl = bigDecimal2.subtract(bigDecimal1).multiply(meterPoint.getMagnification());
+
+                        if (rfdl.doubleValue() > 5000000||rfdl.doubleValue()<0) {
+
+                            ArrayList<Double> arrayList = new ArrayList<>();
+                            for (PointData pointData : historyRaw) {
+                                arrayList.add(pointData.getValue());
+                            }
+                            int index = -1;
+                            // 定义增长阈值
+                            double threshold = 50000.0;
+
+                            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 > threshold) {
+                                    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)).multiply(meterPoint.getMagnification());
+                            }
+                        }
                     }
-                    bigDecimal1 = bigDecimal1.divide(meterPoint.getXs(), 4, RoundingMode.HALF_EVEN);
-                    bigDecimal2 = bigDecimal2.divide(meterPoint.getXs(), 4, RoundingMode.HALF_EVEN);
-                    BigDecimal rfdl = bigDecimal2.subtract(bigDecimal1).multiply(meterPoint.getMagnification());
 
                     MeterInfoBottomcode meterInfoBottomcode = new MeterInfoBottomcode();
                     meterInfoBottomcode.setName(meterPoint.getName());
@@ -210,11 +241,14 @@ class SaveMeterInfoHistoryTest {
                     } else {
                         meterInfoBottomcode.insert();
                     }
+
                 }
-            }
 
 
+            }
         }
+
+
     }
 
     //项目期期风机总发电量
@@ -343,7 +377,7 @@ class SaveMeterInfoHistoryTest {
                         }
 
                     } catch (Exception e) {
-                        System.out.println("获取数据异常:"+e.getMessage());
+                        System.out.println("获取数据异常:" + e.getMessage());
 
                     }
                     try {
@@ -363,14 +397,11 @@ class SaveMeterInfoHistoryTest {
                         } else {
                             meterInfoCalculating.insert();
                         }
-                    }catch (Exception e) {
+                    } catch (Exception e) {
                         System.out.println("存入异常  :" + e.getMessage());
                     }
 
 
-
-
-
                 }
             }
 
@@ -380,10 +411,9 @@ class SaveMeterInfoHistoryTest {
 
     }
 
-
-    //调用所有
+    //调用上面4个,第四个需要3次
     @Test
-    void saveCalculating3(){
+    void saveCalculating3() {
         this.saveEquipmentRfdl();
         this.saveBottomCode();
         this.saveCalculatingProjectFDL();
@@ -392,14 +422,9 @@ class SaveMeterInfoHistoryTest {
         this.saveCalculating();
 
 
-
     }
 
 
-
-
-
-
 }
 
 

+ 0 - 4
electricity/meter/src/main/resources/application.properties

@@ -1,12 +1,8 @@
 ##需要动态配置的属性##
 
 #动态配置适配器的地址
-#equipment可用
 #adapter.url=http://192.168.10.18:8011/ts
-#adapter.url=http://192.168.1.82:8011/ts
-#bottomcode可用
 #adapter.url=http://192.168.10.18:8013/ts
-#新
 adapter.url=http://192.168.1.67:8011/ts
 
 #动态配置开始日期