Procházet zdrojové kódy

设备电量数据,10分钟获取一次
meter_code 测点数据10分钟获取一次

malijun před 1 rokem
rodič
revize
f7f3bd8cd6

+ 1 - 1
electricity/meter/logs/2023-04/error-2023-04-27.1.log

@@ -109,7 +109,7 @@ Warnings:
 	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582) ~[spring-beans-5.3.24.jar:5.3.24]
 	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.24.jar:5.3.24]
 	... 87 more
-2023-04-27 17:19:45.651 ERROR main prepareTestInstance(TestContextManager.java:252) Caught exception while allowing TestExecutionListener [org.springframework.test.context.web.ServletTestExecutionListener@9ef8eb7] to prepare test instance [com.gyee.gaia.meter.service.AdapterServiceTest@34e990cc]
+2023-04-27 17:19:45.651 ERROR main prepareTestInstance(TestContextManager.java:252) Caught exception while allowing TestExecutionListener [org.springframework.test.context.web.ServletTestExecutionListener@9ef8eb7] to prepare test instance [com.gyee.gaia.meter.service.SaveMeterInfoHistoryTest@34e990cc]
 java.lang.IllegalStateException: Failed to load ApplicationContext
 	at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:98) ~[spring-test-5.3.24.jar:5.3.24]
 	at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:124) ~[spring-test-5.3.24.jar:5.3.24]

+ 1 - 1
electricity/meter/logs/2023-04/warn-2023-04-27.1.log

@@ -143,7 +143,7 @@ Warnings:
 	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582) ~[spring-beans-5.3.24.jar:5.3.24]
 	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.24.jar:5.3.24]
 	... 87 more
-2023-04-27 17:19:45.651 ERROR main prepareTestInstance(TestContextManager.java:252) Caught exception while allowing TestExecutionListener [org.springframework.test.context.web.ServletTestExecutionListener@9ef8eb7] to prepare test instance [com.gyee.gaia.meter.service.AdapterServiceTest@34e990cc]
+2023-04-27 17:19:45.651 ERROR main prepareTestInstance(TestContextManager.java:252) Caught exception while allowing TestExecutionListener [org.springframework.test.context.web.ServletTestExecutionListener@9ef8eb7] to prepare test instance [com.gyee.gaia.meter.service.SaveMeterInfoHistoryTest@34e990cc]
 java.lang.IllegalStateException: Failed to load ApplicationContext
 	at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:98) ~[spring-test-5.3.24.jar:5.3.24]
 	at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:124) ~[spring-test-5.3.24.jar:5.3.24]

Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 567 - 0
electricity/meter/logs/2023-05/warn-2023-05-09.1.log


Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 234 - 567
electricity/meter/logs/warn.log


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

@@ -60,7 +60,7 @@ public class MeterInfoEquipment extends Model<MeterInfoEquipment> implements Ser
     /**
      * 日期;日期
      */
-    private String date;
+    private LocalDateTime date;
 
     /**
      * 日发电量;日发电量,单位kwh

+ 11 - 9
electricity/meter/src/main/java/com/gyee/gaia/meter/job/SaveMeterInfoBottomcode10Min.java

@@ -20,6 +20,7 @@ import org.springframework.stereotype.Component;
 import javax.annotation.Resource;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
+import java.time.LocalDateTime;
 import java.util.List;
 import java.util.Map;
 
@@ -47,7 +48,7 @@ public class SaveMeterInfoBottomcode10Min {
 
     @XxlJob("SaveMeterInfoBottomcode10Min")
     void saveBottomcode() {
-        XxlJobHelper.log("开始执行保存底层设备信息定时任务,hello");
+        XxlJobHelper.log("hello,开始执行保存底码信息定时任务");
 
         //获取当前日期,当日开始时间
         String nowString = DateUtil.now();
@@ -81,11 +82,11 @@ public class SaveMeterInfoBottomcode10Min {
                     //name
                     meterInfoBottomcode.setName(meterPoint.getName());
                     //开始时间,当日开始时间
-                    meterInfoBottomcode.setStartTime(startDateTime.toLocalDateTime());
+                    meterInfoBottomcode.setStartTime(DateUtil.offsetSecond(startDateTime, 1).toLocalDateTime());
                     //开始值,section接口获取当日00:00:01数据
                     meterInfoBottomcode.setStartValue(bigDecimal1);
                     //最新时间,latest返回的时间
-                    meterInfoBottomcode.setEndTime(startDateTime.toLocalDateTime());
+                    meterInfoBottomcode.setEndTime(LocalDateTime.now());
                     //最新值,latest返回的值
                     meterInfoBottomcode.setEndValue(bigDecimal2);
                     //日电量
@@ -96,18 +97,18 @@ public class SaveMeterInfoBottomcode10Min {
                     meterInfoBottomcode.setWindpowerstationId(meterPoint.getWindpowerstationId());
 
                     QueryWrapper<MeterInfoBottomcode> queryWrapper = new QueryWrapper<>();
-                    queryWrapper.eq("start_time", startDateTime.toLocalDateTime()).eq("name", meterPoint.getName()).eq("end_time",startDateTime.toLocalDateTime()).eq("windpowerstation_id", meterPoint.getWindpowerstationId());
+                    queryWrapper.eq("start_time", DateUtil.offsetSecond(startDateTime, 1).toLocalDateTime()).eq("name", meterPoint.getName()).eq("windpowerstation_id", meterPoint.getWindpowerstationId());
                     List<MeterInfoBottomcode> list = meterInfoBottomcodeService.list(queryWrapper);
                     System.out.println(list.size());
                     if (list.size() > 0) {
                         meterInfoBottomcode.update(queryWrapper);
-                    }else {
+                    } else {
                         meterInfoBottomcode.insert();
                     }
 
                 } else {
                     //根据测点code,用适配器section接口获取当日00:00:01数据,存入数据库当天开始值
-                    Map<String, PointData> historySection1 = adapter.getHistorySection(pointcode, startDateTime.getTime());
+                    Map<String, PointData> historySection1 = adapter.getHistorySection(pointcode, DateUtil.offsetSecond(startDateTime, 1).getTime());
                     double value1 = 0;
                     if (historySection1.size() > 0) {
                         value1 = historySection1.get(pointcode).getValue();
@@ -134,11 +135,12 @@ public class SaveMeterInfoBottomcode10Min {
                     //name
                     meterInfoBottomcode.setName(meterPoint.getName());
                     //开始时间,当日开始时间
-                    meterInfoBottomcode.setStartTime(startDateTime.toLocalDateTime());
+                    meterInfoBottomcode.setStartTime(DateUtil.offsetSecond(startDateTime, 1).toLocalDateTime());
                     //开始值,section接口获取当日00:00:01数据
                     meterInfoBottomcode.setStartValue(bigDecimal1);
                     //最新时间,latest返回的时间
-                    meterInfoBottomcode.setEndTime(enddateTime.toLocalDateTime());
+//                    meterInfoBottomcode.setEndTime(enddateTime.toLocalDateTime());
+                    meterInfoBottomcode.setEndTime(LocalDateTime.now());
                     //最新值,latest返回的值
                     meterInfoBottomcode.setEndValue(bigDecimal2);
                     //日电量
@@ -150,7 +152,7 @@ public class SaveMeterInfoBottomcode10Min {
 
 
                     QueryWrapper<MeterInfoBottomcode> queryWrapper = new QueryWrapper<>();
-                    queryWrapper.eq("start_time", startDateTime.toLocalDateTime()).eq("code", meterPoint.getNemCode());
+                    queryWrapper.eq("start_time", DateUtil.offsetSecond(startDateTime, 1).toLocalDateTime()).eq("code", meterPoint.getNemCode());
                     List<MeterInfoBottomcode> list = meterInfoBottomcodeService.list(queryWrapper);
                     System.out.println(list.size());
                     if (list.size() > 0) {

+ 117 - 0
electricity/meter/src/main/java/com/gyee/gaia/meter/job/SaveMeterInfoEquipment10Min.java

@@ -0,0 +1,117 @@
+package com.gyee.gaia.meter.job;
+
+import cn.hutool.core.date.DateTime;
+import cn.hutool.core.date.DateUtil;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.gyee.gaia.meter.adapter.Adapter;
+import com.gyee.gaia.meter.entity.Equipment;
+import com.gyee.gaia.meter.entity.MeterInfoEquipment;
+import com.gyee.gaia.meter.entity.PointData;
+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.List;
+import java.util.Map;
+
+/**
+ * Author: malijun
+ * Data  : 2023: 05: 09
+ **/
+
+@Component
+public class SaveMeterInfoEquipment10Min {
+    private static final Logger logger = LoggerFactory.getLogger(SaveMeterInfoEquipment10Min.class);
+
+    @Resource
+    Adapter adapter;
+
+    @Resource
+    TestingPointServiceImpl testingPointService;
+
+    @Resource
+    EquipmentServiceImpl equipmentService;
+
+    @Resource
+    MeterInfoEquipmentServiceImpl meterInfoEquipmentService;
+
+    @XxlJob("SaveMeterInfoEquipment10Min")
+    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();
+            }
+            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()));
+
+            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.setRfdl(rfdl);
+
+
+            QueryWrapper<MeterInfoEquipment> queryWrapper = new QueryWrapper<>();
+            queryWrapper.eq("equipment_nem_code", equipment.getNemCode()).eq("date",startDateTime.toLocalDateTime());
+            List<MeterInfoEquipment> list = meterInfoEquipmentService.list(queryWrapper);
+            System.out.println(list.size());
+            if (list.size() > 0) {
+                meterInfoEquipment.update(queryWrapper);
+            } else {
+                meterInfoEquipment.insert();
+            }
+
+
+        }
+    }
+
+
+}
+
+
+

+ 17 - 15
electricity/meter/src/main/java/com/gyee/gaia/meter/service/SaveMeterInfoBottomcode10MinTest.java

@@ -17,6 +17,7 @@ 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.util.List;
 import java.util.Map;
 
@@ -76,11 +77,11 @@ public class SaveMeterInfoBottomcode10MinTest {
                     //name
                     meterInfoBottomcode.setName(meterPoint.getName());
                     //开始时间,当日开始时间
-                    meterInfoBottomcode.setStartTime(startDateTime.toLocalDateTime());
+                    meterInfoBottomcode.setStartTime(DateUtil.offsetSecond(startDateTime, 1).toLocalDateTime());
                     //开始值,section接口获取当日00:00:01数据
                     meterInfoBottomcode.setStartValue(bigDecimal1);
                     //最新时间,latest返回的时间
-                    meterInfoBottomcode.setEndTime(startDateTime.toLocalDateTime());
+                    meterInfoBottomcode.setEndTime(LocalDateTime.now());
                     //最新值,latest返回的值
                     meterInfoBottomcode.setEndValue(bigDecimal2);
                     //日电量
@@ -90,19 +91,19 @@ public class SaveMeterInfoBottomcode10MinTest {
                     //windpowerstation_id,meter.getWindpowerstationId,
                     meterInfoBottomcode.setWindpowerstationId(meterPoint.getWindpowerstationId());
 
-//                    QueryWrapper<MeterInfoBottomcode> queryWrapper = new QueryWrapper<>();
-//                    queryWrapper.eq("start_time", startDateTime.toLocalDateTime()).eq("name", meterPoint.getName()).eq("end_time",startDateTime.toLocalDateTime()).eq("windpowerstation_id", meterPoint.getWindpowerstationId());
-//                    List<MeterInfoBottomcode> list = meterInfoBottomcodeService.list(queryWrapper);
-//                    System.out.println(list.size());
-//                    if (list.size() > 0) {
-//                        meterInfoBottomcode.update(queryWrapper);
-//                    }else {
-//                        meterInfoBottomcode.insert();
-//                    }
+                    QueryWrapper<MeterInfoBottomcode> queryWrapper = new QueryWrapper<>();
+                    queryWrapper.eq("start_time", DateUtil.offsetSecond(startDateTime, 1).toLocalDateTime()).eq("name", meterPoint.getName()).eq("windpowerstation_id", meterPoint.getWindpowerstationId());
+                    List<MeterInfoBottomcode> list = meterInfoBottomcodeService.list(queryWrapper);
+                    System.out.println(list.size());
+                    if (list.size() > 0) {
+                        meterInfoBottomcode.update(queryWrapper);
+                    } else {
+                        meterInfoBottomcode.insert();
+                    }
 
                 } else {
                     //根据测点code,用适配器section接口获取当日00:00:01数据,存入数据库当天开始值
-                    Map<String, PointData> historySection1 = adapter.getHistorySection(pointcode, startDateTime.getTime());
+                    Map<String, PointData> historySection1 = adapter.getHistorySection(pointcode, DateUtil.offsetSecond(startDateTime, 1).getTime());
                     double value1 = 0;
                     if (historySection1.size() > 0) {
                         value1 = historySection1.get(pointcode).getValue();
@@ -129,11 +130,12 @@ public class SaveMeterInfoBottomcode10MinTest {
                     //name
                     meterInfoBottomcode.setName(meterPoint.getName());
                     //开始时间,当日开始时间
-                    meterInfoBottomcode.setStartTime(startDateTime.toLocalDateTime());
+                    meterInfoBottomcode.setStartTime(DateUtil.offsetSecond(startDateTime, 1).toLocalDateTime());
                     //开始值,section接口获取当日00:00:01数据
                     meterInfoBottomcode.setStartValue(bigDecimal1);
                     //最新时间,latest返回的时间
-                    meterInfoBottomcode.setEndTime(enddateTime.toLocalDateTime());
+//                    meterInfoBottomcode.setEndTime(enddateTime.toLocalDateTime());
+                    meterInfoBottomcode.setEndTime(LocalDateTime.now());
                     //最新值,latest返回的值
                     meterInfoBottomcode.setEndValue(bigDecimal2);
                     //日电量
@@ -145,7 +147,7 @@ public class SaveMeterInfoBottomcode10MinTest {
 
 
                     QueryWrapper<MeterInfoBottomcode> queryWrapper = new QueryWrapper<>();
-                    queryWrapper.eq("start_time", startDateTime.toLocalDateTime()).eq("code", meterPoint.getNemCode());
+                    queryWrapper.eq("start_time", DateUtil.offsetSecond(startDateTime, 1).toLocalDateTime()).eq("code", meterPoint.getNemCode());
                     List<MeterInfoBottomcode> list = meterInfoBottomcodeService.list(queryWrapper);
                     System.out.println(list.size());
                     if (list.size() > 0) {

+ 55 - 64
electricity/meter/src/main/java/com/gyee/gaia/meter/service/SaveMeterInfoEquipment10MinTest.java

@@ -2,7 +2,6 @@ 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.Equipment;
@@ -10,15 +9,13 @@ import com.gyee.gaia.meter.entity.MeterInfoEquipment;
 import com.gyee.gaia.meter.entity.PointData;
 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 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.time.LocalDateTime;
-import java.time.temporal.ChronoUnit;
 import java.util.List;
 import java.util.Map;
 
@@ -39,85 +36,79 @@ public class SaveMeterInfoEquipment10MinTest {
     @Resource
     EquipmentServiceImpl equipmentService;
 
-    @Value("${start.time}")
-    private String startTimeString;
-
-    @Value("${end.time}")
-    private String endTimeString;
+    @Resource
+    MeterInfoEquipmentServiceImpl meterInfoEquipmentService;
 
     @Test
     void saveEquipmentRfdl() {
 
 
         //1,在testingpoint中根据 uniform_code=AI064 和code like "%_FJ_%" 取出所有风机的电量测点code
-        List<TestingPoint> list = testingPointService.list(new QueryWrapper<TestingPoint>().eq("uniform_code", "AI064").like("code", "%_FJ_%"));
+        List<TestingPoint> testingPointList = testingPointService.list(new QueryWrapper<TestingPoint>().eq("uniform_code", "AI064").like("code", "%_FJ_%"));
 
         //所有风机总共407个电量测点code
-        System.out.println(list.size());
+        System.out.println(testingPointList.size());
+
+        //获取当前日期,当日开始时间
+        String nowString = DateUtil.now();
+        DateTime nowDateTime = DateUtil.parse(nowString);
+        DateTime startDateTime = DateUtil.beginOfDay(nowDateTime);
 
         //2,遍历list,每次取出一个code
-        for (TestingPoint testingPoint : list) {
+        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);
-            System.out.println(between);
-
-            for (int i = 1; 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();
-
-                //7,根据code和日期结束时间23:59:59获取日期结束点发电量
-                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);
-                System.out.println(rfdl + "Kwh");
-
-
-                //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(DateUtil.format(dateTime2, "yyyy-MM-dd"));
-                meterInfoEquipment.setRfdl(rfdl);
+            //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();
+            }
+            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 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(DateUtil.offsetSecond(startDateTime, 1).toLocalDateTime());
+            meterInfoEquipment.setRfdl(rfdl);
+
+
+            QueryWrapper<MeterInfoEquipment> queryWrapper = new QueryWrapper<>();
+            queryWrapper.eq("equipment_nem_code", thingId1.getNemCode()).eq("date",startDateTime.toLocalDateTime());
+            List<MeterInfoEquipment> list = meterInfoEquipmentService.list(queryWrapper);
+            System.out.println(list.size());
+            if (list.size() > 0) {
+                meterInfoEquipment.update(queryWrapper);
+            } else {
                 meterInfoEquipment.insert();
+            }
 
 
-            }
         }
-
     }
 
 

+ 58 - 47
electricity/meter/src/main/java/com/gyee/gaia/meter/service/AdapterServiceTest.java

@@ -10,6 +10,7 @@ import com.gyee.gaia.meter.service.impl.*;
 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;
@@ -23,36 +24,45 @@ import java.util.Map;
  * Data  : 2023: 04: 27
  **/
 @SpringBootTest
-class AdapterServiceTest {
+class SaveMeterInfoHistoryTest {
+
 
     @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数据库
+    //读取时间段内设备发电量计算肉发电量写入pg数据库
     @Test
     void saveEquipmentRfdl() {
 
 
         //1,在testingpoint中根据 uniform_code=AI064 和code like "%_FJ_%" 取出所有风机的电量测点code
-        List<TestingPoint> list = testingPointService.list(new QueryWrapper<TestingPoint>().eq("uniform_code", "AI064").like("code", "%_FJ_%"));
+        List<TestingPoint> testingPointList = testingPointService.list(new QueryWrapper<TestingPoint>().eq("uniform_code", "AI064").like("code", "%_FJ_%"));
 
         //所有风机总共407个电量测点code
-        System.out.println(list.size());
+        System.out.println(testingPointList.size());
 
         //2,遍历list,每次取出一个code
-        for (TestingPoint testingPoint : list) {
+        for (TestingPoint testingPoint : testingPointList) {
             //获取测点code
             String pointcode = testingPoint.getCode();
             //获取设备ID
@@ -70,9 +80,9 @@ class AdapterServiceTest {
             LocalDateTime day1 = LocalDateTimeUtil.of(startDateTime);
             LocalDateTime day2 = LocalDateTimeUtil.of(endDateTime);
             long between = ChronoUnit.DAYS.between(day1, day2);
-            System.out.println(between);
+            System.out.println("相差天数"+between);
 
-            for (int i = 1; i < between; i++) {
+            for (int i = 0; i <= between; i++) {
 
 
                 //开始时间00:00:01
@@ -106,9 +116,18 @@ class AdapterServiceTest {
                 meterInfoEquipment.setLineNemCode(thingId1.getLineId());
                 meterInfoEquipment.setEquipmentNemCode(thingId1.getNemCode());
                 meterInfoEquipment.setName(thingId1.getName());
-                meterInfoEquipment.setDate(DateUtil.format(dateTime2, "yyyy-MM-dd"));
+                meterInfoEquipment.setDate(dateTime1.toLocalDateTime());
                 meterInfoEquipment.setRfdl(rfdl);
-                meterInfoEquipment.insert();
+//                meterInfoEquipment.insert();
+                QueryWrapper<MeterInfoEquipment> queryWrapper = new QueryWrapper<>();
+                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();
+                }
 
 
             }
@@ -116,14 +135,7 @@ class AdapterServiceTest {
 
     }
 
-
-    @Resource
-    PowerStationServiceImpl powerStationService;
-
-    @Resource
-    MeterPointServiceImpl meterPointService;
-
-    //读取底码数据存入pg数据库,设置开始时间,结束时间
+    //读取时间段内meter_point表中所有电计量测点数据存入pg数据库
     @Test
     void saveBottomCode() {
 
@@ -154,16 +166,14 @@ class AdapterServiceTest {
                 LocalDateTime day1 = LocalDateTimeUtil.of(startDateTime);
                 LocalDateTime day2 = LocalDateTimeUtil.of(endDateTime);
                 long between = ChronoUnit.DAYS.between(day1, day2);
-                System.out.println(between);
-
+                System.out.println("相差天数"+between);
 
                 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);
-
+                    DateTime dateTime2 = DateUtil.offsetSecond(DateUtil.offsetDay(startDateTime, i + 1), 1);
 
                     //没有测点code的字段
                     if (null == pointcode) {
@@ -178,15 +188,22 @@ class AdapterServiceTest {
                         meterInfoBottomcode.setName(meterPoint.getName());
                         meterInfoBottomcode.setStartTime(dateTime1.toLocalDateTime());
                         meterInfoBottomcode.setStartValue(bigDecimal1);
-                        meterInfoBottomcode.setEndTime(dateTime1.toLocalDateTime());
+                        meterInfoBottomcode.setEndTime(dateTime2.toLocalDateTime());
                         meterInfoBottomcode.setEndValue(bigDecimal2);
                         meterInfoBottomcode.setDayValue(rfdl);
                         meterInfoBottomcode.setCode(pointcode);
                         meterInfoBottomcode.setWindpowerstationId(meterPoint.getWindpowerstationId());
-                        meterInfoBottomcode.insert();
-
-
-
+//                        meterInfoBottomcode.insert();
+
+                        QueryWrapper<MeterInfoBottomcode> queryWrapper = new QueryWrapper<>();
+                        queryWrapper.eq("start_time", dateTime1.toLocalDateTime()).eq("name", meterPoint.getName()).eq("end_time",dateTime2.toLocalDateTime()).eq("windpowerstation_id", meterPoint.getWindpowerstationId());
+                        List<MeterInfoBottomcode> list = meterInfoBottomcodeService.list(queryWrapper);
+                        System.out.println(list.size());
+                        if (list.size() > 0) {
+                            meterInfoBottomcode.update(queryWrapper);
+                        } else {
+                            meterInfoBottomcode.insert();
+                        }
 
                     } else {
                         //6,根据测点code和日期开始时间00:00:01获取日期开始点发电量
@@ -211,12 +228,22 @@ class AdapterServiceTest {
                             meterInfoBottomcode.setName(meterPoint.getName());
                             meterInfoBottomcode.setStartTime(dateTime1.toLocalDateTime());
                             meterInfoBottomcode.setStartValue(bigDecimal1);
-                            meterInfoBottomcode.setEndTime(dateTime1.toLocalDateTime());
+                            meterInfoBottomcode.setEndTime(dateTime2.toLocalDateTime());
                             meterInfoBottomcode.setEndValue(bigDecimal2);
                             meterInfoBottomcode.setDayValue(rfdl);
                             meterInfoBottomcode.setCode(pointcode);
                             meterInfoBottomcode.setWindpowerstationId(meterPoint.getWindpowerstationId());
-                            meterInfoBottomcode.insert();
+//                            meterInfoBottomcode.insert();
+
+                            QueryWrapper<MeterInfoBottomcode> queryWrapper = new QueryWrapper<>();
+                            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 {
+                                meterInfoBottomcode.insert();
+                            }
                         }
                     }
                 }
@@ -224,14 +251,6 @@ class AdapterServiceTest {
         }
     }
 
-
-    @Resource
-    MeterInfoBottomcodeServiceImpl meterInfoBottomcodeService;
-
-    @Resource
-    MeterInfoEquipmentServiceImpl meterInfoEquipmentService;
-
-
     //发电量,上网电量,购网电量
     @Test
     void saveCalculating() {
@@ -463,11 +482,6 @@ class AdapterServiceTest {
         }
     }
 
-
-    @Resource
-    MeterInfoCalculatingServiceImpl meterInfoCalculatingService;
-
-
     //综合厂用电量
     @Test
     void saveCalculating1() {
@@ -838,7 +852,6 @@ class AdapterServiceTest {
         }
     }
 
-
     //发电厂用电量
     @Test
     void saveCalculating3() {
@@ -934,7 +947,6 @@ class AdapterServiceTest {
         }
     }
 
-
     //发电厂用电率(%)
     @Test
     void saveCalculating4() {
@@ -1034,7 +1046,6 @@ class AdapterServiceTest {
         }
     }
 
-
     //利用小时
     @Test
     void saveCalculating5() {

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

@@ -1,15 +1,16 @@
 ##需要动态配置的属性##
 
 #动态配置适配器的地址
+#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
 
 #动态配置开始日期
-start.time=2023-05-01 00:00:00
-
+start.time=2023-05-08 00:00:00
 #动态配置结束日期
-end.time=2023-05-08 00:00:00
+end.time=2023-05-09 00:00:00
 
 meter.stations=MHS_FDC,NSS_FDC
 

+ 2 - 2
electricity/meter/src/main/resources/bootstrap.yaml

@@ -86,8 +86,8 @@ xxl:
       appname: meter
       address:
       ip:
-      port: 9021
-      logpath: d:/xxl-job/meter/logs
+      port: 9999
+      logpath: c:/xxl-job/meter/logs
       logretentiondays: 30