Browse Source

Merge branch 'master' of http://124.70.43.205:3000/GYEE_R.D/gaia

xushili 1 year ago
parent
commit
1c854ed6f9

File diff suppressed because it is too large
+ 2505 - 0
electricity/meter/logs/2023-05/warn-2023-05-15.1.log


File diff suppressed because it is too large
+ 117 - 2505
electricity/meter/logs/warn.log


+ 1 - 1
electricity/meter/src/main/java/com/gyee/gaia/meter/entity/MeterInfoBottomcode.java

@@ -15,7 +15,7 @@ import java.time.LocalDateTime;
  * 风机日发电量表
  * </p>
  */
-@TableName("meter_info_bottomcode")
+@TableName("pro_meter_bottomcode")
 @Data
 public class MeterInfoBottomcode extends Model<MeterInfoBottomcode> implements Serializable {
 

+ 1 - 1
electricity/meter/src/main/java/com/gyee/gaia/meter/entity/MeterInfoCalculating.java

@@ -15,7 +15,7 @@ import java.time.LocalDateTime;
  * 线路日发电量表
  * </p>
  */
-@TableName("meter_info_calculating")
+@TableName("pro_meter_calculating")
 @Data
 public class MeterInfoCalculating extends Model<MeterInfoCalculating> implements Serializable {
 

+ 1 - 5
electricity/meter/src/main/java/com/gyee/gaia/meter/entity/MeterInfoEquipment.java

@@ -15,7 +15,7 @@ import java.time.LocalDateTime;
  * 风机日发电量表
  * </p>
  */
-@TableName("meter_info_equipment")
+@TableName("pro_meter_equipment")
 @Data
 public class MeterInfoEquipment extends Model<MeterInfoEquipment> implements Serializable {
 
@@ -27,10 +27,6 @@ public class MeterInfoEquipment extends Model<MeterInfoEquipment> implements Ser
     @TableId(value = "id", type = IdType.AUTO)
     private Integer id;
 
-    /**
-     * 公司编码;公司编码
-     */
-    private String companyNemCode;
 
     /**
      * 场站编码;场站编码

+ 0 - 6
electricity/meter/src/main/java/com/gyee/gaia/meter/entity/MeterPoint.java

@@ -1,7 +1,6 @@
 package com.gyee.gaia.meter.entity;
 
 import com.baomidou.mybatisplus.annotation.TableName;
-import com.gyee.gaia.common.utils.StringUtil;
 import lombok.Data;
 
 import java.io.Serializable;
@@ -154,9 +153,4 @@ public class MeterPoint implements Serializable {
     private String formula;
 
 
-    public String getFormula2() {
-        return StringUtil.replace(formula,"DL\\.","DL_");
-    }
-
-
 }

+ 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 - 57
electricity/meter/src/main/java/com/gyee/gaia/meter/job/SaveBottomcode.java

@@ -11,18 +11,14 @@ import com.gyee.gaia.meter.entity.PowerStation;
 import com.gyee.gaia.meter.service.impl.MeterInfoBottomcodeServiceImpl;
 import com.gyee.gaia.meter.service.impl.MeterPointServiceImpl;
 import com.gyee.gaia.meter.service.impl.PowerStationServiceImpl;
-import com.xxl.job.core.context.XxlJobHelper;
 import com.xxl.job.core.handler.annotation.XxlJob;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 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
@@ -31,31 +27,19 @@ import java.util.Map;
 
 @Component
 public class SaveBottomcode {
-    private static final Logger logger = LoggerFactory.getLogger(SaveBottomcode.class);
-
 
     @Resource
     PowerStationServiceImpl powerStationService;
-
     @Resource
     MeterPointServiceImpl meterPointService;
-
     @Resource
     MeterInfoBottomcodeServiceImpl meterInfoBottomcodeService;
-
     @Resource
     Adapter adapter;
 
     @XxlJob("SaveBottomcode")
-    void saveBottomcode() {
-        XxlJobHelper.log("hello,开始执行保存底码信息定时任务");
-
-        //获取当前日期,当日开始时间
-        String nowString = DateUtil.now();
-        DateTime nowDateTime = DateUtil.parse(nowString);
-        DateTime startDateTime = DateUtil.beginOfDay(nowDateTime);
+    void saveBottomCode() {
 
-        //类似之前代码,获取场站,遍历场站,根据场站ID获取测点code
         //1,查询所有风电场
         List<PowerStation> powerStationList = powerStationService.list(new QueryWrapper<PowerStation>().like("nem_code", "_FDC_"));
 
@@ -63,62 +47,90 @@ 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,用适配器section接口获取当日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();
+                //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 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;
-                long ts = 0;
-                if (historyLatest2.size() > 0) {
-                    value2 = historyLatest2.get(pointcode).getValue();
-                    ts = historyLatest2.get(pointcode).getTs();
-                }
-                BigDecimal bigDecimal2 = BigDecimal.valueOf(value2);
-                bigDecimal2 = bigDecimal2.divide(meterPoint.getXs(), 4, RoundingMode.HALF_EVEN);
-                DateTime enddateTime = new DateTime(ts);
-                //计算日电量
-                BigDecimal rfdl = bigDecimal2.subtract(bigDecimal1).multiply(meterPoint.getMagnification());
 
                 MeterInfoBottomcode meterInfoBottomcode = new MeterInfoBottomcode();
-
-                //name
                 meterInfoBottomcode.setName(meterPoint.getName());
-                //开始时间,当日开始时间
-                meterInfoBottomcode.setStartTime(DateUtil.offsetSecond(startDateTime, 1).toLocalDateTime());
-                //开始值,section接口获取当日00:00:01数据
+                meterInfoBottomcode.setStartTime(dateTime1.toLocalDateTime());
                 meterInfoBottomcode.setStartValue(bigDecimal1);
-                //最新时间,latest返回的时间
-//                    meterInfoBottomcode.setEndTime(enddateTime.toLocalDateTime());
-                meterInfoBottomcode.setEndTime(LocalDateTime.now());
-                //最新值,latest返回的值
+                meterInfoBottomcode.setEndTime(nowDateTime.toLocalDateTime());
                 meterInfoBottomcode.setEndValue(bigDecimal2);
-                //日电量
                 meterInfoBottomcode.setDayValue(rfdl);
-                //code,meter.getCode
-                meterInfoBottomcode.setCode(meterPoint.getNemCode());
-                //windpowerstation_id,meter.getWindpowerstationId,
+                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);
-                System.out.println(list.size());
                 if (list.size() > 0) {
                     meterInfoBottomcode.update(queryWrapper);
                 } else {
@@ -128,6 +140,8 @@ public class SaveBottomcode {
 
             }
         }
+
+
     }
 
 

+ 18 - 27
electricity/meter/src/main/java/com/gyee/gaia/meter/job/SaveCalculating.java

@@ -38,72 +38,63 @@ public class SaveCalculating {
     void saveCalculating() {
 
         //获取当前日期,当日开始时间
-        String nowString = DateUtil.now();
-        DateTime nowDateTime = DateUtil.parse(nowString);
+        DateTime nowDateTime = DateUtil.parse(DateUtil.now());
         DateTime startDateTime = DateUtil.beginOfDay(nowDateTime);
 
+        //meterPoint表中,有公式的计算点
         List<MeterPoint> meterPointJSDList = meterPointService.list(new QueryWrapper<MeterPoint>().eq("property", "JSD").ne("formula", ""));
-        System.out.println("有公式数量" + meterPointJSDList.size());
 
         for (MeterPoint meterPoint : meterPointJSDList) {
-            String formula1 = meterPoint.getFormula();
-            System.out.println("转换前的公式:" + formula1);
-            String formula3 = formula1.replaceAll("DL\\.", "DL_");
-            String formula2 = formula3.replaceAll("DJL.", "DJL_");
 
-            //分割公式字符串,得到每一的个ode
-//            String[] meterPointCodes = formula2.split("[+\\-*/]");
+            //原始公式
+            String formula1 = meterPoint.getFormula();
+            //.转换为_后的公式
+            String formula2 = formula1.replaceAll("DL\\.", "DL_").replaceAll("DJL\\.", "DJL_");
 
+            //分割原始公式字符串,得到每一的个code
             String[] meterPointCodes = StringUtils.split(formula1, "[+\\-*/()]");
+
+            //过滤掉长度小于10的,剩余就是测点
             meterPointCodes = Arrays.stream(meterPointCodes)
                     .filter(meterPointCode -> !(meterPointCode.length() < 10))
                     .toArray(String[]::new);
-            System.out.println("公式中测点数:" + meterPointCodes.length);
-            System.out.println(Arrays.toString(meterPointCodes));
 
+            //map存公式中测点的数据
             HashMap<String, Object> map = new HashMap<>();
-
             //开始时间
             DateTime dateTime1 = DateUtil.offsetSecond(startDateTime, 1);
 
-            System.out.println("遍历测点集合");
-
-            //遍历code数据,拿到每一个code,用code和时间,在meter_info_bottom中拿到dayValue
+            //遍历code数组,拿到每一个code,用code和时间,在meter_info_bottom中拿到dayValue
             for (String meterPointCode : meterPointCodes) {
-//                String meterPointCode_ = meterPointCode.replace("DL\\.", "DL_");
-                String meterPointCode_1 = meterPointCode.replaceAll("DL.", "DL_");
-                String meterPointCode_ = meterPointCode_1.replaceAll("DJL.", "DJL_");
-                System.out.println("meterPointCode测点:");
 
-                //查询code所在场站
+                String meterPointCode_ = meterPointCode.replaceAll("DL\\.", "DL_").replaceAll("DJL\\.", "DJL_");
 
                 //如果字符串以DL开头,从meter_info_calclating表中取,否则从meter_info_bottom表中取
                 try {
                     if (meterPointCode.startsWith("DL")) {
-                        System.out.println("计算测点DL:" + meterPointCode);
                         MeterInfoCalculating meterInfoCalculating = meterInfoCalculatingService.getOne(new QueryWrapper<MeterInfoCalculating>().eq("code", meterPointCode).eq("date", dateTime1));
-                        System.out.println("测点数据:" + meterInfoCalculating.getValue());
                         map.put(meterPointCode_, meterInfoCalculating.getValue());
                     } else {
-                        System.out.println("计算测点Bottom:" + meterPointCode);
                         MeterInfoBottomcode meterInfoBottomcode = meterInfoBottomcodeService.getOne(new QueryWrapper<MeterInfoBottomcode>().eq("code", meterPointCode).eq("start_time", dateTime1));
-                        System.out.println("测点数据日电量:" + meterInfoBottomcode.getDayValue());
                         map.put(meterPointCode_, meterInfoBottomcode.getDayValue());
                     }
-
-
                 } catch (Exception e) {
                     System.out.println("获取数据异常  :" + e.getMessage());
                 }
+
                 try {
+                    //公式计算
                     BigDecimal bigDecimal1 = (BigDecimal) ScriptShell.parseExpr(formula2, map);
-                    System.out.println(bigDecimal1);
+
+                    //存入数据
                     MeterInfoCalculating meterInfoCalculating = new MeterInfoCalculating();
                     meterInfoCalculating.setName(meterPoint.getName());
                     meterInfoCalculating.setCode(meterPoint.getNemCode());
                     meterInfoCalculating.setDate(dateTime1.toLocalDateTime());
                     meterInfoCalculating.setValue(bigDecimal1);
+                    meterInfoCalculating.setUpdateTime(nowDateTime.toLocalDateTime());
                     meterInfoCalculating.setWindpowerstationId(meterPoint.getWindpowerstationId());
+
                     QueryWrapper<MeterInfoCalculating> queryWrapper = new QueryWrapper<>();
                     queryWrapper.eq("date", dateTime1.toLocalDateTime()).eq("code", meterPoint.getNemCode());
                     List<MeterInfoCalculating> list = meterInfoCalculatingService.list(queryWrapper);

+ 17 - 15
electricity/meter/src/main/java/com/gyee/gaia/meter/job/SaveCalculatingFJFDL.java

@@ -36,38 +36,40 @@ public class SaveCalculatingFJFDL {
     @XxlJob("SaveCalculatingFJFDL")
     void saveCalculatingFJFDL() {
 
-
         //获取当前日期,当日开始时间
-        String nowString = DateUtil.now();
-        DateTime nowDateTime = DateUtil.parse(nowString);
+        DateTime nowDateTime = DateUtil.parse(DateUtil.now());
         DateTime startDateTime = DateUtil.beginOfDay(nowDateTime);
 
-
         //1,所有期次发电量测点
         List<MeterPoint> meterPointList = meterPointService.list(new QueryWrapper<MeterPoint>().eq("property", "JSD_QCFDL"));
         System.out.println(meterPointList.size());
 
-        //遍历期次发电量测点,拿到场站id,
+        //遍历期次发电量测点,拿到项目期次ID
         for (MeterPoint meterPoint : meterPointList) {
             String projectId = meterPoint.getProjectId();
 
-                //开始时间00:00:01
-                DateTime dateTime1 = DateUtil.offsetSecond(startDateTime, 1);
+            //开始时间00:00:01
+            DateTime dateTime1 = DateUtil.offsetSecond(startDateTime, 1);
 
+            //根据时间和项目期次ID查询设备日发电量表
+            List<MeterInfoEquipment> meterInfoEquipments = meterInfoEquipmentService.list(new QueryWrapper<MeterInfoEquipment>().eq("project_nem_code", projectId).eq("date", dateTime1));
 
-                List<MeterInfoEquipment> meterInfoEquipments = meterInfoEquipmentService.list(new QueryWrapper<MeterInfoEquipment>().eq("project_nem_code", projectId).eq("date", dateTime1));
-                BigDecimal bigDecimal = BigDecimal.valueOf(0);
-                for (MeterInfoEquipment meterInfoEquipment : meterInfoEquipments) {
-                    bigDecimal = bigDecimal.add(meterInfoEquipment.getRfdl());
-                }
+            //遍历累加取出的数据
+            BigDecimal bigDecimal = BigDecimal.valueOf(0);
+            for (MeterInfoEquipment meterInfoEquipment : meterInfoEquipments) {
+                bigDecimal = bigDecimal.add(meterInfoEquipment.getRfdl());
+            }
 
+            //存入MeterInfoCalculating表中,单位:万千瓦时
             MeterInfoCalculating meterInfoCalculating = new MeterInfoCalculating();
             meterInfoCalculating.setName(meterPoint.getName());
             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());
 
+
             QueryWrapper<MeterInfoCalculating> queryWrapper = new QueryWrapper<>();
             queryWrapper.eq("date", dateTime1.toLocalDateTime()).eq("code", meterPoint.getNemCode());
             List<MeterInfoCalculating> list = meterInfoCalculatingService.list(queryWrapper);
@@ -79,15 +81,15 @@ public class SaveCalculatingFJFDL {
             }
 
 
-            }
-
-
         }
 
 
     }
 
 
+}
+
+
 
 
 

+ 72 - 49
electricity/meter/src/main/java/com/gyee/gaia/meter/job/SaveEquipmentRfdl.java

@@ -11,16 +11,13 @@ import com.gyee.gaia.meter.entity.TestingPoint;
 import com.gyee.gaia.meter.service.impl.EquipmentServiceImpl;
 import com.gyee.gaia.meter.service.impl.MeterInfoEquipmentServiceImpl;
 import com.gyee.gaia.meter.service.impl.TestingPointServiceImpl;
-import com.xxl.job.core.context.XxlJobHelper;
 import com.xxl.job.core.handler.annotation.XxlJob;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 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
@@ -29,84 +26,110 @@ import java.util.Map;
 
 @Component
 public class SaveEquipmentRfdl {
-    private static final Logger logger = LoggerFactory.getLogger(SaveEquipmentRfdl.class);
 
     @Resource
     Adapter adapter;
-
     @Resource
     TestingPointServiceImpl testingPointService;
-
     @Resource
     EquipmentServiceImpl equipmentService;
-
     @Resource
     MeterInfoEquipmentServiceImpl meterInfoEquipmentService;
 
     @XxlJob("SaveEquipmentRfdl")
     void saveEquipmentRfdl() {
-        XxlJobHelper.log("hello,开始执行保存风机设备电量信息定时任务");
-        
+
         //1,在testingpoint中根据 uniform_code=AI064 和code like "%_FJ_%" 取出所有风机的电量测点code
         List<TestingPoint> testingPointList = testingPointService.list(new QueryWrapper<TestingPoint>().eq("uniform_code", "AI064").like("code", "%_FJ_%"));
-        
-        //获取当前日期,当日开始时间
-        String nowString = DateUtil.now();
-        DateTime nowDateTime = DateUtil.parse(nowString);
-        DateTime startDateTime = DateUtil.beginOfDay(nowDateTime);
 
         //2,遍历list,每次取出一个code
         for (TestingPoint testingPoint : testingPointList) {
             //获取测点code
             String pointcode = testingPoint.getCode();
-
-            //6,根据code和日期开始时间00:00:00获取日期开始点发电量
-            Map<String, PointData> historySection1 = adapter.getHistorySection(pointcode, DateUtil.offsetSecond(startDateTime, 1).getTime());
-            double value1 = 0;
-            if (historySection1.size() > 0) {
-                value1 = historySection1.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 bigDecimal1 = BigDecimal.valueOf(value1);
-
-            //7,根据code和日期结束时间23:59:59获取日期结束点发电量
-            Map<String, PointData> historyLatest2 = adapter.getHistoryLatest(pointcode);
-            double value2 = 0;
-            long ts = 0;
-            if (historyLatest2.size() > 0) {
-                value2 = historyLatest2.get(pointcode).getValue();
-                ts = historyLatest2.get(pointcode).getTs();
-            }
-            BigDecimal bigDecimal2 = BigDecimal.valueOf(value2);
-            DateTime enddateTime = new DateTime(ts);
-
-            //8,结束点发电量减去开始点发电量得到日发电量(单位Kwh)
-            BigDecimal rfdl = bigDecimal2.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 equipment = equipmentService.getOne(new QueryWrapper<Equipment>().eq("nem_code", testingPoint.getThingId()));
+            Equipment thingId1 = equipmentService.getOne(new QueryWrapper<Equipment>().eq("nem_code", thingId));
 
             MeterInfoEquipment meterInfoEquipment = new MeterInfoEquipment();
-            meterInfoEquipment.setCompanyNemCode("NX_GDDL_ZGS");
-            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",startDateTime.toLocalDateTime());
+            queryWrapper.eq("equipment_nem_code", thingId1.getNemCode()).eq("date", dateTime1.toLocalDateTime());
             List<MeterInfoEquipment> list = meterInfoEquipmentService.list(queryWrapper);
-            System.out.println(list.size());
             if (list.size() > 0) {
                 meterInfoEquipment.update(queryWrapper);
             } else {
                 meterInfoEquipment.insert();
             }
 
-
         }
     }
 

+ 0 - 394
electricity/meter/src/main/java/com/gyee/gaia/meter/service/SaveMeterInfoHistoryByMonthTest.java

@@ -1,394 +0,0 @@
-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.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.gyee.gaia.meter.adapter.Adapter;
-import com.gyee.gaia.meter.entity.*;
-import com.gyee.gaia.meter.service.impl.*;
-import com.gyee.gaia.meter.util.ScriptShell;
-import org.apache.commons.lang3.StringUtils;
-import org.junit.jupiter.api.Test;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.boot.test.context.SpringBootTest;
-
-import javax.annotation.Resource;
-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;
-
-/**
- * Author: malijun
- * Data  : 2023: 04: 27
- **/
-@SpringBootTest
-class SaveMeterInfoHistoryByMonthTest {
-
-
-    @Resource
-    Adapter adapter;
-    @Resource
-    TestingPointServiceImpl testingPointService;
-    @Resource
-    EquipmentServiceImpl equipmentService;
-    @Resource
-    PowerStationServiceImpl powerStationService;
-    @Resource
-    MeterPointServiceImpl meterPointService;
-    @Resource
-    MeterInfoBottomcodeServiceImpl meterInfoBottomcodeService;
-    @Resource
-    MeterInfoEquipmentServiceImpl meterInfoEquipmentService;
-    @Resource
-    MeterInfoCalculatingServiceImpl meterInfoCalculatingService;
-
-
-    @Value("${start.time}")
-    private String startTimeString;
-    @Value("${end.time}")
-    private String endTimeString;
-
-    //读取时间段内设备发电量计算肉发电量写入pg数据库
-    @Test
-    void 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_%"));
-
-        //所有风机总共407个电量测点code
-
-        //2,遍历list,每次取出一个code
-        for (TestingPoint testingPoint : testingPointList) {
-            //获取测点code
-            String pointcode = testingPoint.getCode();
-            //获取设备ID
-            String thingId = testingPoint.getThingId();
-
-            //设置取值开始时间
-            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);
-
-
-            //开始时间00:00:01
-            DateTime dateTime1 = DateUtil.offsetSecond(startDateTime, 1);
-            //结束时间第二天00:00:01
-            DateTime dateTime2 = DateUtil.offsetSecond(endDateTime, 1);
-
-            //6,根据code和日期开始时间00:00:00获取日期开始点发电量
-            Map<String, PointData> historySection1 = adapter.getHistorySection(pointcode, dateTime1.getTime());
-            double value1 = historySection1.get(pointcode).getValue();
-
-            //7,根据code和日期结束时间获取日期结束点发电量
-            Map<String, PointData> historySection2 = adapter.getHistorySection(pointcode, dateTime2.getTime());
-            double value2 = historySection2.get(pointcode).getValue();
-
-            //8,结束点发电量减去开始点发电量得到日发电量(单位Kwh)
-            BigDecimal bigDecimal1 = new BigDecimal(Double.toString(value1));
-            BigDecimal bigDecimal2 = new BigDecimal(Double.toString(value2));
-            BigDecimal rfdl = bigDecimal2.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.setCompanyNemCode("NX_GDDL_ZGS");
-            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.setRfdl(rfdl);
-            QueryWrapper<MeterInfoEquipment> queryWrapper = new QueryWrapper<>();
-            queryWrapper.eq("equipment_nem_code", thingId1.getNemCode()).eq("date", dateTime1.toLocalDateTime());
-            List<MeterInfoEquipment> list = meterInfoEquipmentService.list(queryWrapper);
-            if (list.size() > 0) {
-                meterInfoEquipment.update(queryWrapper);
-            } else {
-                meterInfoEquipment.insert();
-            }
-
-
-        }
-
-    }
-
-    //读取时间段内meter_point表中所有电计量测点数据存入pg数据库
-    @Test
-    void saveBottomCode() {
-
-        //1,查询所有风电场
-        List<PowerStation> powerStationList = powerStationService.list(new QueryWrapper<PowerStation>().like("nem_code", "_FDC_"));
-
-        for (PowerStation powerStation : powerStationList) {
-
-            //2,根据场站ID得到场站下所有测点
-            List<MeterPoint> meterPointList = meterPointService.list(new QueryWrapper<MeterPoint>().eq("windpowerstation_id", powerStation.getId()).eq("property", "CD"));
-
-            //3,遍历测点,拿到每个测点的nem_code
-            for (MeterPoint meterPoint : meterPointList) {
-                System.out.println(meterPoint);
-                //获取测点code
-                String pointcode = meterPoint.getNemCode();
-
-                //设置取值开始时间
-                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);
-
-
-                //开始时间00:00:01
-                DateTime dateTime1 = DateUtil.offsetSecond(startDateTime, 1);
-                //结束时间第二天00:00:01
-                DateTime dateTime2 = DateUtil.offsetSecond(endDateTime, 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));
-                }
-                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());
-                meterInfoBottomcode.setStartTime(dateTime1.toLocalDateTime());
-                meterInfoBottomcode.setStartValue(bigDecimal1);
-                meterInfoBottomcode.setEndTime(dateTime2.toLocalDateTime());
-                meterInfoBottomcode.setEndValue(bigDecimal2);
-                meterInfoBottomcode.setDayValue(rfdl);
-                meterInfoBottomcode.setCode(pointcode);
-                meterInfoBottomcode.setWindpowerstationId(meterPoint.getWindpowerstationId());
-
-                QueryWrapper<MeterInfoBottomcode> queryWrapper = new QueryWrapper<>();
-                queryWrapper.eq("start_time", dateTime1.toLocalDateTime()).eq("code", meterPoint.getNemCode());
-                List<MeterInfoBottomcode> list = meterInfoBottomcodeService.list(queryWrapper);
-                if (list.size() > 0) {
-                    meterInfoBottomcode.update(queryWrapper);
-                } else {
-                    meterInfoBottomcode.insert();
-                }
-            }
-        }
-
-
-    }
-
-    //项目期期风机总发电量
-    @Test
-    void saveCalculatingProjectFDL() {
-
-
-        //设置取值开始时间
-        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);
-
-
-        //1,所有期次发电量测点
-        List<MeterPoint> meterPointList = meterPointService.list(new QueryWrapper<MeterPoint>().eq("property", "JSD_QCFDL"));
-
-        //遍历期次发电量测点,拿到场站id,
-        for (MeterPoint meterPoint : meterPointList) {
-            String projectId = meterPoint.getProjectId();
-
-
-            //开始时间00:00:01
-            DateTime dateTime1 = DateUtil.offsetSecond(startDateTime, 1);
-            //结束时间第二天00:00:01
-            DateTime dateTime2 = DateUtil.offsetSecond(startDateTime, 1);
-
-            List<MeterInfoEquipment> meterInfoEquipments = meterInfoEquipmentService.list(new QueryWrapper<MeterInfoEquipment>().eq("project_nem_code", projectId).eq("date", dateTime1));
-            BigDecimal bigDecimal = BigDecimal.valueOf(0);
-            for (MeterInfoEquipment meterInfoEquipment : meterInfoEquipments) {
-                bigDecimal = bigDecimal.add(meterInfoEquipment.getRfdl());
-            }
-
-            MeterInfoCalculating meterInfoCalculating = new MeterInfoCalculating();
-            meterInfoCalculating.setName(meterPoint.getName());
-            meterInfoCalculating.setDate(dateTime1.toLocalDateTime());
-            meterInfoCalculating.setValue(bigDecimal.divide(BigDecimal.valueOf(10000), 4, RoundingMode.HALF_EVEN));
-            meterInfoCalculating.setCode(meterPoint.getNemCode());
-            meterInfoCalculating.setWindpowerstationId(meterPoint.getWindpowerstationId());
-
-            QueryWrapper<MeterInfoCalculating> queryWrapper = new QueryWrapper<>();
-            queryWrapper.eq("date", dateTime1.toLocalDateTime()).eq("code", meterPoint.getNemCode());
-            List<MeterInfoCalculating> list = meterInfoCalculatingService.list(queryWrapper);
-            if (list.size() > 0) {
-                meterInfoCalculating.update(queryWrapper);
-            } else {
-                meterInfoCalculating.insert();
-            }
-
-        }
-
-
-    }
-
-    //用公式计算
-    @Test
-    void saveCalculating() {
-
-        //设置取值开始时间
-        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);
-
-        List<MeterPoint> meterPointJSDList = meterPointService.list(new QueryWrapper<MeterPoint>().eq("property", "JSD").ne("formula", ""));
-
-        for (MeterPoint meterPoint : meterPointJSDList) {
-            String formula1 = meterPoint.getFormula();
-            System.out.println("转换前的公式:" + formula1);
-            String formula3 = formula1.replaceAll("DL\\.", "DL_");
-            String formula2 = formula3.replaceAll("DJL\\.", "DJL_");
-
-            //得到公式字符串(DL.已经替换为DL_)
-//            String formula2 = meterPoint.getFormula2();
-            System.out.println("转换后的公式字符串:" + formula2);
-
-            //分割公式字符串,得到每一的个ode
-            String[] meterPointCodes = StringUtils.split(formula1, "[+\\-*/()]");
-            meterPointCodes = Arrays.stream(meterPointCodes)
-                    .filter(meterPointCode -> !(meterPointCode.length() < 8))
-                    .toArray(String[]::new);
-            System.out.println("过滤后公式中的测点数:" + meterPointCodes.length);
-            System.out.println(Arrays.toString(meterPointCodes));
-
-
-            HashMap<String, Object> map = new HashMap<>();
-            //开始时间
-            DateTime dateTime1 = DateUtil.offsetSecond(startDateTime,1);
-            //遍历code数据,拿到每一个code,用code和时间,在meter_info_bottom中拿到dayValue
-            for (String meterPointCode : meterPointCodes) {
-//                    String meterPointCode_ = meterPointCode.replaceAll("\\.", "_");
-                String meterPointCode_1 = meterPointCode.replaceAll("DL\\.", "DL_");
-                String meterPointCode_ = meterPointCode_1.replaceAll("DJL\\.", "DJL_");
-                System.out.println("要查询的点code:" + meterPointCode);
-                System.out.println("替换后的点code:" + meterPointCode_);
-//
-                try {
-                    if (meterPointCode.startsWith("DL")) {
-                        System.out.println("计算测点DL:" + meterPointCode);
-                        MeterInfoCalculating meterInfoCalculating = meterInfoCalculatingService.getOne(new QueryWrapper<MeterInfoCalculating>().eq("code", meterPointCode).eq("date", dateTime1));
-                        System.out.println("测点数据:" + meterInfoCalculating.getValue());
-                        map.put(meterPointCode_, meterInfoCalculating.getValue());
-                    } else {
-                        System.out.println("计算测点Bottom:" + meterPointCode);
-                        MeterInfoBottomcode meterInfoBottomcode = meterInfoBottomcodeService.getOne(new QueryWrapper<MeterInfoBottomcode>().eq("code", meterPointCode).eq("start_time", dateTime1));
-                        System.out.println("测点数据日电量:" + meterInfoBottomcode.getDayValue());
-                        map.put(meterPointCode_, meterInfoBottomcode.getDayValue());
-                    }
-
-                } catch (Exception e) {
-                    System.out.println("获取数据异常:" + e.getMessage());
-
-                }
-                try {
-                    BigDecimal bigDecimal1 = (BigDecimal) ScriptShell.parseExpr(formula2, map);
-                    System.out.println(bigDecimal1);
-                    MeterInfoCalculating meterInfoCalculating = new MeterInfoCalculating();
-                    meterInfoCalculating.setName(meterPoint.getName());
-                    meterInfoCalculating.setCode(meterPoint.getNemCode());
-                    meterInfoCalculating.setDate(dateTime1.toLocalDateTime());
-                    meterInfoCalculating.setValue(bigDecimal1);
-                    meterInfoCalculating.setWindpowerstationId(meterPoint.getWindpowerstationId());
-                    QueryWrapper<MeterInfoCalculating> queryWrapper = new QueryWrapper<>();
-                    queryWrapper.eq("date", dateTime1.toLocalDateTime()).eq("code", meterPoint.getNemCode());
-                    List<MeterInfoCalculating> list = meterInfoCalculatingService.list(queryWrapper);
-                    if (list.size() > 0) {
-                        meterInfoCalculating.update(queryWrapper);
-                    } else {
-                        meterInfoCalculating.insert();
-                    }
-                } catch (Exception e) {
-                    System.out.println("存入异常  :" + e.getMessage());
-                }
-
-
-            }
-
-
-        }
-
-
-    }
-
-
-    //调用所有
-    @Test
-    void saveCalculating3() {
-        this.saveEquipmentRfdl();
-        this.saveBottomCode();
-        this.saveCalculatingProjectFDL();
-        this.saveCalculating();
-        this.saveCalculating();
-        this.saveCalculating();
-
-
-    }
-
-
-}
-
-
-
-
-
-
-
-
-

+ 80 - 56
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,32 +81,51 @@ 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.setCompanyNemCode("NX_GDDL_ZGS");
                 meterInfoEquipment.setPowerstationNemCode(thingId1.getWindpowerstationId());
                 meterInfoEquipment.setProjectNemCode(thingId1.getProjectId());
                 meterInfoEquipment.setLineNemCode(thingId1.getLineId());
@@ -128,14 +141,10 @@ class SaveMeterInfoHistoryTest {
                 } else {
                     meterInfoEquipment.insert();
                 }
-
-
             }
         }
-
     }
 
-    //读取时间段内meter_point表中所有电计量测点数据存入pg数据库
     @Test
     void saveBottomCode() {
 
@@ -173,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());
@@ -211,11 +241,14 @@ class SaveMeterInfoHistoryTest {
                     } else {
                         meterInfoBottomcode.insert();
                     }
+
                 }
-            }
 
 
+            }
         }
+
+
     }
 
     //项目期期风机总发电量
@@ -344,7 +377,7 @@ class SaveMeterInfoHistoryTest {
                         }
 
                     } catch (Exception e) {
-                        System.out.println("获取数据异常:"+e.getMessage());
+                        System.out.println("获取数据异常:" + e.getMessage());
 
                     }
                     try {
@@ -364,14 +397,11 @@ class SaveMeterInfoHistoryTest {
                         } else {
                             meterInfoCalculating.insert();
                         }
-                    }catch (Exception e) {
+                    } catch (Exception e) {
                         System.out.println("存入异常  :" + e.getMessage());
                     }
 
 
-
-
-
                 }
             }
 
@@ -381,10 +411,9 @@ class SaveMeterInfoHistoryTest {
 
     }
 
-
-    //调用所有
+    //调用上面4个,第四个需要3次
     @Test
-    void saveCalculating3(){
+    void saveCalculating3() {
         this.saveEquipmentRfdl();
         this.saveBottomCode();
         this.saveCalculatingProjectFDL();
@@ -393,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
 
 #动态配置开始日期