Browse Source

修复BUG

malijun 1 năm trước cách đây
mục cha
commit
24e0d6b3c4

+ 2 - 0
electricity/meter/src/main/java/com/gyee/gaia/meter/service/meter/SaveBottomcode.java

@@ -78,6 +78,7 @@ public class SaveBottomcode {
                 if (!historySection.isEmpty()) {
                     value0 = historySection.get(pointcode).getValue();
                     bigDecimal1 = new BigDecimal(Double.toString(value0));
+                    BigDecimal bigDecimal10 = new BigDecimal(Double.toString(value0));
                 }
 
                 //从适配器拿当日数据
@@ -90,6 +91,7 @@ public class SaveBottomcode {
 //                    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()));
+                    BigDecimal bigDecimal20 = 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());
 

+ 114 - 92
electricity/meter/src/main/java/com/gyee/gaia/meter/service/saveHistory/ReadFromXLSXTest.java

@@ -26,20 +26,20 @@ import java.util.List;
 /**
  * idea直接运行test,从底码表读取数据保存到pgsql
  * 1,需要手动修改必要参数 例如:
-     //文件路径
-     String fileName = "C:\\Users\\24410\\Desktop\\data.xlsx";
-     //测点code
-     String code = "QSDJL.NX_GD_QSF_DD_P1_L1_001_ZXYG001";
-     //开始日期
-     String StringDate = "2023/6/1";
-     //第几个sheet表
-     int sheetValue = 1;
-     //开始行
-     int startRow = 2;
-     //结束行
-     int endRow = 29;
-     //数据列
-     int valueColumn = 3;
+ * //文件路径
+ * String fileName = "C:\\Users\\24410\\Desktop\\data.xlsx";
+ * //测点code
+ * String code = "QSDJL.NX_GD_QSF_DD_P1_L1_001_ZXYG001";
+ * //开始日期
+ * String StringDate = "2023/6/1";
+ * //第几个sheet表
+ * int sheetValue = 1;
+ * //开始行
+ * int startRow = 2;
+ * //结束行
+ * int endRow = 29;
+ * //数据列
+ * int valueColumn = 3;
  */
 @SpringBootTest
 public class ReadFromXLSXTest {
@@ -53,100 +53,122 @@ public class ReadFromXLSXTest {
     @Test
     public void readDataFromFile() throws IOException {
 
+        //开始日期
+        String StringDate = "2023/8/1";
         //文件路径
         String fileName = "C:\\Users\\24410\\Desktop\\data.xlsx";
+        String fileName1 = "C:\\Users\\24410\\Desktop\\无标题.xlsx";
+
         //测点code
-        String code = "QSDJL.NX_GD_QSF_DD_P1_L1_001_ZXYG001";
-        //开始日期
-        String StringDate = "2023/6/1";
+        String code;
+
         //第几个sheet表
-        int sheetValue = 1;
-        //开始行
-        int startRow = 2;
+        int sheetValue = 9;
         //结束行
-        int endRow = 29;
+        int endRow = 68;
+
+
+
+        //开始行
+        int startRow = 7;
         //数据列
-        int valueColumn = 3;
-
-        //根据code获取测点信息
-        MeterPoint meterPoint = meterPointService.getOne(new QueryWrapper<MeterPoint>().eq("nem_code", code));
-        //时间转为DateTime格式
-        DateTime dateTime = DateUtil.parse(StringDate);
-        //集合存所有记录
-        List<MeterInfoBottomcode> records = new ArrayList<>();
+        int valueColumn;
+
+
         //文件输入流
-        FileInputStream fileInputStream = new FileInputStream(fileName);
+        FileInputStream fileInputStream1 = new FileInputStream(fileName1);
         //XSSFWorkbook格式的文件输入流
-        Workbook workbook = new XSSFWorkbook(fileInputStream);
+        Workbook workbook1 = new XSSFWorkbook(fileInputStream1);
         //第几个sheet表,从0开始
-        Sheet sheet = workbook.getSheetAt(sheetValue - 1);
+        Sheet sheet1 = workbook1.getSheetAt(0);
         //开始天数,遍历累加以便推移时间
-        int day = 0;
         //遍历每行
-        for (int i = startRow-1; i < endRow; i += 2) {
-            //每天时间
-            DateTime dateTime1 = DateUtil.offsetDay(dateTime, day);
-            //创建对象
-            MeterInfoBottomcode record = new MeterInfoBottomcode();
-            //对象赋值,开始时间,截止时间
-            record.setStartTime(dateTime1.toLocalDateTime());
-            record.setEndTime(DateUtil.endOfDay(dateTime1).toLocalDateTime());
-            //对象赋值,名字,编码,场站
-            record.setName(meterPoint.getName());
-            record.setCode(meterPoint.getNemCode());
-            record.setWindpowerstationId(meterPoint.getWindpowerstationId());
-            //对象赋值,止码
-            Row stopCodeRow = sheet.getRow(i);
-            double stopCode = stopCodeRow.getCell(valueColumn - 1).getNumericCellValue();
-            record.setEndValue(BigDecimal.valueOf(stopCode).setScale(4, RoundingMode.HALF_EVEN));
-            //对象赋值,起码,
-            Row electricityRow = sheet.getRow(i + 1);
-            double electricity = electricityRow.getCell(valueColumn - 1).getNumericCellValue();
-            record.setDayValue(BigDecimal.valueOf(electricity).setScale(4, RoundingMode.HALF_EVEN));
-            //对象赋值,起码,第一天止码为上一行,其余为上2行
+        for (int j = 1; j <= sheet1.getLastRowNum(); j++) {
+            Row row = sheet1.getRow(j);
+            code = row.getCell(1).getStringCellValue();
+            valueColumn = (int) row.getCell(2).getNumericCellValue() ;
+
+
+            //根据code获取测点信息
+            MeterPoint meterPoint = meterPointService.getOne(new QueryWrapper<MeterPoint>().eq("nem_code", code));
+            //时间转为DateTime格式
+            DateTime dateTime = DateUtil.parse(StringDate);
+            //集合存所有记录
+            List<MeterInfoBottomcode> records = new ArrayList<>();
+            //文件输入流
+            FileInputStream fileInputStream = new FileInputStream(fileName);
+            //XSSFWorkbook格式的文件输入流
+            Workbook workbook = new XSSFWorkbook(fileInputStream);
+            //第几个sheet表,从0开始
+            Sheet sheet = workbook.getSheetAt(sheetValue - 1);
+            //开始天数,遍历累加以便推移时间
+            int day = 0;
+            //遍历每行
+            for (int i = startRow - 1; i < endRow; i += 2) {
+                //每天时间
+                DateTime dateTime1 = DateUtil.offsetDay(dateTime, day);
+                //创建对象
+                MeterInfoBottomcode record = new MeterInfoBottomcode();
+                //对象赋值,开始时间,截止时间
+                record.setStartTime(dateTime1.toLocalDateTime());
+                record.setEndTime(DateUtil.endOfDay(dateTime1).toLocalDateTime());
+                //对象赋值,名字,编码,场站
+                record.setName(meterPoint.getName());
+                record.setCode(meterPoint.getNemCode());
+                record.setWindpowerstationId(meterPoint.getWindpowerstationId());
+                //对象赋值,止码
+                Row stopCodeRow = sheet.getRow(i);
+                double stopCode = stopCodeRow.getCell(valueColumn - 1).getNumericCellValue();
+                record.setEndValue(BigDecimal.valueOf(stopCode).setScale(4, RoundingMode.HALF_EVEN));
+                //对象赋值,起码,
+                Row electricityRow = sheet.getRow(i + 1);
+                double electricity = electricityRow.getCell(valueColumn - 1).getNumericCellValue();
+                record.setDayValue(BigDecimal.valueOf(electricity).setScale(4, RoundingMode.HALF_EVEN));
+                //对象赋值,起码,第一天止码为上一行,其余为上2行
 //            if (i == startRow-1) {
-            //如果时间为当月第一天,起码为上一行,否则为上2行
-            if (dateTime1.equals(DateUtil.beginOfMonth(dateTime1))) {
-                Row startCodeRow = sheet.getRow(i - 1);
-                double startCode = startCodeRow.getCell(valueColumn - 1).getNumericCellValue();
-                record.setStartValue(BigDecimal.valueOf(startCode).setScale(4, RoundingMode.HALF_EVEN));
-            } else {
-                Row startCodeRow = sheet.getRow(i - 2);
-                double startCode = startCodeRow.getCell(valueColumn - 1).getNumericCellValue();
-                record.setStartValue(BigDecimal.valueOf(startCode).setScale(4, RoundingMode.HALF_EVEN));
+                //如果时间为当月第一天,起码为上一行,否则为上2行
+                if (dateTime1.equals(DateUtil.beginOfMonth(dateTime1))) {
+                    Row startCodeRow = sheet.getRow(i - 1);
+                    double startCode = startCodeRow.getCell(valueColumn - 1).getNumericCellValue();
+                    record.setStartValue(BigDecimal.valueOf(startCode).setScale(4, RoundingMode.HALF_EVEN));
+                } else {
+                    Row startCodeRow = sheet.getRow(i - 2);
+                    double startCode = startCodeRow.getCell(valueColumn - 1).getNumericCellValue();
+                    record.setStartValue(BigDecimal.valueOf(startCode).setScale(4, RoundingMode.HALF_EVEN));
+                }
+                //添加到集合
+                records.add(record);
+
+                day++;
             }
-            //添加到集合
-            records.add(record);
-
-            day++;
-        }
 
-        // 打印每天的数据记录
-        System.setOut(new PrintStream(System.out, true, "UTF-8"));
-        for (MeterInfoBottomcode record : records) {
-            System.out.println("name: " + record.getName());
-            System.out.println("startTime: " + record.getStartTime());
-            System.out.println("起码: " + record.getStartValue());
-            System.out.println("endTime: " + record.getEndTime());
-            System.out.println("止码: " + record.getEndValue());
-            System.out.println("dayValue: " + record.getDayValue());
-            System.out.println("编码: " + record.getCode());
-            System.out.println("场站: " + record.getWindpowerstationId());
-            System.out.println();
-
-
-//            QueryWrapper<MeterInfoBottomcode> queryWrapper = new QueryWrapper<>();
-//            queryWrapper
-//                    .eq("start_time", record.getStartTime())
-//                    .eq("code", record.getCode());
-//            List<MeterInfoBottomcode> list = meterInfoBottomcodeService.list(queryWrapper);
-//            if (list.size() > 0) {
-//                record.update(queryWrapper);
-//            } else {
-//                record.insert();
-//            }
+            // 打印每天的数据记录
+            System.setOut(new PrintStream(System.out, true, "UTF-8"));
+            for (MeterInfoBottomcode record : records) {
+                System.out.println("name: " + record.getName());
+                System.out.println("startTime: " + record.getStartTime());
+                System.out.println("起码: " + record.getStartValue());
+                System.out.println("endTime: " + record.getEndTime());
+                System.out.println("止码: " + record.getEndValue());
+                System.out.println("dayValue: " + record.getDayValue());
+                System.out.println("编码: " + record.getCode());
+                System.out.println("场站: " + record.getWindpowerstationId());
+                System.out.println();
+
+
+            QueryWrapper<MeterInfoBottomcode> queryWrapper = new QueryWrapper<>();
+            queryWrapper
+                    .eq("start_time", record.getStartTime())
+                    .eq("code", record.getCode());
+            List<MeterInfoBottomcode> list = meterInfoBottomcodeService.list(queryWrapper);
+            if (list.size() > 0) {
+                record.update(queryWrapper);
+            } else {
+                record.insert();
+            }
 
 
+            }
         }
 
     }

+ 5 - 3
electricity/meter/src/main/java/com/gyee/gaia/meter/service/saveHistory/SaveMeterInfoHistoryDay.java

@@ -421,6 +421,7 @@ class SaveMeterInfoHistoryDay {
                         value0 = historySection.get(pointcode).getValue();
                     }
                     bigDecimal1 = new BigDecimal(Double.toString(value0));
+                    BigDecimal bigDecimal10 = new BigDecimal(Double.toString(value0));
 
                     List<PointData> historyRaw = adapter.getHistoryRaw(pointcode, dateTime1.getTime(), dateTime2.getTime());
 
@@ -428,6 +429,7 @@ class SaveMeterInfoHistoryDay {
 //                        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()));
+                        BigDecimal bigDecimal20 = 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());
 
@@ -445,7 +447,7 @@ class SaveMeterInfoHistoryDay {
                                 double current = arrayList.get(j);
                                 double previous = arrayList.get(j - 1);
                                 double difference = current - previous;
-                                if (difference > threshold) {
+                                if (difference > threshold || difference<0) {
                                     index = j;
                                     break;
                                 }
@@ -455,7 +457,7 @@ class SaveMeterInfoHistoryDay {
                                 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());
+                                rfdl = (bigDecimal20.subtract(bigDecimalGrow2).add(bigDecimalGrow1).subtract(bigDecimal10)).divide(meterPoint.getXs(), 4, RoundingMode.HALF_EVEN).multiply(meterPoint.getMagnification());
                             }
                         }
                     }
@@ -1415,7 +1417,7 @@ class SaveMeterInfoHistoryDay {
 
                 //避免出现过大错误数据,异常数据给死值4444.4444
                 if (rfdl.doubleValue() > 15000 || rfdl.doubleValue() < 0) {
-                    rfdl = BigDecimal.valueOf(4444.4444);
+                    rfdl = BigDecimal.valueOf(4.4444);
                 }
                 //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));

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 902 - 72
electricity/meter/src/main/java/com/gyee/gaia/meter/service/saveHistory/SaveMeterInfoHistoryDayTest.java


+ 15 - 2
electricity/meter/src/main/java/com/gyee/gaia/meter/service/saveTDengine/TDSaveLLFDLTest.java

@@ -2,9 +2,15 @@ package com.gyee.gaia.meter.service.saveTDengine;
 
 import cn.hutool.core.date.DateTime;
 import cn.hutool.core.date.DateUtil;
+import com.alibaba.nacos.api.NacosFactory;
+import com.alibaba.nacos.api.exception.NacosException;
+import com.alibaba.nacos.api.naming.NamingService;
 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.entity.ModelPowerDetails;
+import com.gyee.gaia.meter.entity.PointDatas;
+import com.gyee.gaia.meter.entity.TDEquipmentMeterInfo;
+import com.gyee.gaia.meter.entity.TestingPoint;
 import com.gyee.gaia.meter.mapper.TDEquipmentMeterInfoMapper;
 import com.gyee.gaia.meter.service.impl.EquipmentServiceImpl;
 import com.gyee.gaia.meter.service.impl.ModelPowerDetailsServiceImpl;
@@ -17,7 +23,8 @@ import org.springframework.boot.test.context.SpringBootTest;
 import javax.annotation.Resource;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.List;
 
 /**
  * Author: malijun
@@ -884,6 +891,12 @@ class TDSaveLLFDLTest {
 
     }
 
+    @Test
+    public void nacos() throws NacosException {
+        NamingService naming = NacosFactory.createNamingService("192.168.1.66");
+        naming.registerInstance("nacos测试", "192.168.10.24", 8081);
+    }
+
 
 }
 

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

@@ -9,11 +9,11 @@ spring:
     nacos:
       discovery:
         # 服务注册地址
-        server-addr: 192.168.1.67:8848
+        server-addr: 192.168.1.66:8848
         group: meter
       config:
         # 配置中心地址
-        server-addr: 192.168.1.67:8848
+        server-addr: 192.168.1.66:8848
         # 配置文件格式
         file-extension: yml
         #开发环境配置命名空间
@@ -24,4 +24,4 @@ spring:
         refresh-enabled: true
         # 共享配置
 #        shared-configs:
-#          - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
+##          - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}

+ 1 - 1
electricity/wind/src/main/resources/bootstrap.yaml

@@ -112,5 +112,5 @@ xxl:
       address:
       ip:
       port: 9133
-      logpath: d:/xxl-job/meter/logs
+      logpath: c:/xxl-job/meter/logs
       logretentiondays: 30

+ 1 - 1
realtime/wind/src/main/resources/bootstrap.yaml

@@ -111,7 +111,7 @@ xxl:
       address:
       ip:
       port: 9132
-      logpath: d:/xxl-job/meter/logs
+      logpath: c:/xxl-job/meter/logs
       logretentiondays: 30
 
 #logging:

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 697283
资源文件/csv/testpoint.csv