|
@@ -2,17 +2,22 @@ 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;
|
|
|
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.TestingPointServiceImpl;
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
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;
|
|
|
|
|
@@ -29,6 +34,9 @@ class AdapterServiceTest {
|
|
|
@Resource
|
|
|
TestingPointServiceImpl testingPointService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ EquipmentServiceImpl equipmentService;
|
|
|
+
|
|
|
|
|
|
//测试获取和保存数据
|
|
|
@Test
|
|
@@ -49,62 +57,174 @@ class AdapterServiceTest {
|
|
|
@Test
|
|
|
void saveEquipmentRfdl() {
|
|
|
|
|
|
- /*
|
|
|
- //1,powerstation获取宁夏公司所有风电场站id
|
|
|
-
|
|
|
- //2,project获取每个风电场站下所有项目期次id
|
|
|
-
|
|
|
- //3,line获取每个风电期次下的所有风电线路id
|
|
|
-
|
|
|
- //4,equipment获取每个风电线路下的所有风机id
|
|
|
-
|
|
|
- //5,根据每个风机id和uniform_code (AI064),在testingpoint中获取code
|
|
|
- */
|
|
|
-
|
|
|
- //5,在testingpoint中根据 uniform_code=AI064 和code like "%_FJ_%" 取出所有风机的电量测点code
|
|
|
+ //1,在testingpoint中根据 uniform_code=AI064 和code like "%_FJ_%" 取出所有风机的电量测点code
|
|
|
List<TestingPoint> list = testingPointService.list(new QueryWrapper<TestingPoint>().eq("uniform_code", "AI064").like("code", "%_FJ_%"));
|
|
|
|
|
|
//所有风机总共407个电量测点code
|
|
|
System.out.println(list.size());
|
|
|
- String pointcode = list.get(0).getCode();
|
|
|
-
|
|
|
|
|
|
- //6,时间
|
|
|
- String strsss = "2023-04-1";
|
|
|
- DateTime dateTime = DateUtil.parse(strsss);
|
|
|
- System.out.println(dateTime);
|
|
|
- long time = dateTime.getTime();
|
|
|
- System.out.println(time);
|
|
|
+ //2,遍历list,每次取出一个code
|
|
|
+ for (TestingPoint testingPoint : list) {
|
|
|
+ //获取测点code
|
|
|
+ String pointcode = testingPoint.getCode();
|
|
|
+ //获取设备ID
|
|
|
+ String thingId = testingPoint.getThingId();
|
|
|
+
|
|
|
+ //6,设置取值开始日期前一天
|
|
|
+ String str = "2023-04-30";
|
|
|
+
|
|
|
+ DateTime dateTime = DateUtil.parse(str);
|
|
|
+ DateTime dateTime2 = DateUtil.endOfDay(dateTime);
|
|
|
+ System.out.println("前一天天结束时间" + dateTime2);
|
|
|
+
|
|
|
+ //指定日期到现在天数
|
|
|
+ LocalDateTime day1 = LocalDateTimeUtil.of(dateTime);
|
|
|
+ LocalDateTime day2 = LocalDateTime.now();
|
|
|
+ System.out.println(day2);
|
|
|
+ long between = ChronoUnit.DAYS.between(day1, day2);
|
|
|
+ System.out.println(between);
|
|
|
+
|
|
|
+ for (int i = 1; i < between; i++) {
|
|
|
+
|
|
|
+
|
|
|
+ DateTime dateTime1 = DateUtil.offsetMillisecond(dateTime2, 1);
|
|
|
+ System.out.println("第一天开始" + dateTime1);
|
|
|
+
|
|
|
+ dateTime2 = DateUtil.endOfDay(dateTime1);
|
|
|
+ System.out.println("第一天结束" + dateTime2);
|
|
|
+
|
|
|
+ //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);
|
|
|
+ meterInfoEquipment.insert();
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+// //测点code
|
|
|
+// String pointcode = list.get(0).getCode();
|
|
|
+// //设备ID
|
|
|
+// String thingId = list.get(0).getThingId();
|
|
|
+//
|
|
|
+//
|
|
|
+// //6,时间
|
|
|
+// String strsss = "2023-04-1";
|
|
|
+// DateTime dateTime = DateUtil.parse(strsss);
|
|
|
+// System.out.println(dateTime);
|
|
|
+// long time = dateTime.getTime();
|
|
|
+// System.out.println(time);
|
|
|
+//
|
|
|
+// DateTime dateTime1 = DateUtil.beginOfDay(dateTime);
|
|
|
+// System.out.println("第一天开始" + dateTime1);
|
|
|
+//
|
|
|
+// DateTime dateTime2 = DateUtil.endOfDay(dateTime1);
|
|
|
+// System.out.println("第一天结束" + dateTime2);
|
|
|
+
|
|
|
+
|
|
|
+// //6,根据code和日期开始时间00:00:00获取日期开始点发电量(集合)
|
|
|
+// Map<String, PointData> historySection1 = adapter.getHistorySection(pointcode, dateTime1.getTime());
|
|
|
+// PointData pointData1 = historySection1.get(pointcode);
|
|
|
+// double value1 = pointData1.getValue();
|
|
|
+// System.out.println(value1);
|
|
|
+//
|
|
|
+// //7,根据code和日期结束时间23:59:59获取日期结束点发电量(集合)
|
|
|
+// Map<String, PointData> historySection2 = adapter.getHistorySection(pointcode, dateTime2.getTime());
|
|
|
+// PointData pointData2 = historySection2.get(pointcode);
|
|
|
+// double value2 = pointData2.getValue();
|
|
|
+// System.out.println(value2);
|
|
|
+//
|
|
|
+//
|
|
|
+// //8,结束点发电量减去开始点发电量得到日发电量(单位Kwh)
|
|
|
+// BigDecimal bigDecimal1 = new BigDecimal(Double.toString(value1));
|
|
|
+// System.out.println(bigDecimal1);
|
|
|
+// 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(dateTime2.toLocalDateTime());
|
|
|
+// meterInfoEquipment.setRfdl(rfdl);
|
|
|
+// meterInfoEquipment.insert();
|
|
|
|
|
|
- DateTime dateTime1 = DateUtil.beginOfDay(dateTime);
|
|
|
- System.out.println("第一天开始" + dateTime1);
|
|
|
|
|
|
- DateTime dateTime2 = DateUtil.endOfDay(dateTime1);
|
|
|
- System.out.println("第一天结束" + dateTime2);
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- //6,根据code和日期开始时间00:00:00获取日期开始点发电量
|
|
|
- List<PointData> historySection1 = adapter.getHistorySnap(pointcode, dateTime1.getTime(),DateUtil.offsetSecond(dateTime1, 1).getTime());
|
|
|
- System.out.println(historySection1);
|
|
|
-
|
|
|
- //7,根据code和日期结束时间23:59:59获取日期结束点发电量
|
|
|
- List<PointData> historySection2 = adapter.getHistorySnap(pointcode, dateTime2.getTime(),DateUtil.offsetSecond(dateTime2, 1).getTime());
|
|
|
- System.out.println(historySection2);
|
|
|
+ }
|
|
|
|
|
|
|
|
|
- dateTime1 = DateUtil.offsetSecond(dateTime2, 1);
|
|
|
- System.out.println("第二天开始" + dateTime1);
|
|
|
+ /*
|
|
|
+ //1,powerstation获取宁夏公司所有风电场站id
|
|
|
|
|
|
- dateTime2 = DateUtil.endOfDay(dateTime1);
|
|
|
- System.out.println("第二天结束" + dateTime2);
|
|
|
+ //2,project获取每个风电场站下所有项目期次id
|
|
|
|
|
|
+ //3,line获取每个风电期次下的所有风电线路id
|
|
|
|
|
|
- //7,根据code和日期结束时间23:59:59获取日期结束点发电量
|
|
|
+ //4,equipment获取每个风电线路下的所有风机id
|
|
|
|
|
|
- //8,结束点发电量减去开始点发电量得到日发电量(应该要乘倍率?)
|
|
|
+ //5,根据每个风机id和uniform_code (AI064),在testingpoint中获取code
|
|
|
+ */
|
|
|
|
|
|
- //9,company_nem_code (powerstation_nem_code project_nem_code line_nem_code equipment_nem_code )都在basic equipment中叫project_id name date rfdl 存入meterInfo表中
|
|
|
|
|
|
- }
|
|
|
+// @Test
|
|
|
+// void test() throws FileNotFoundException {
|
|
|
+//
|
|
|
+// //6,设置取值开始日期前一天
|
|
|
+// String str = "2023-05-01";
|
|
|
+//
|
|
|
+// DateTime dateTime = DateUtil.parse(str);
|
|
|
+//
|
|
|
+// LocalDateTime day1 = LocalDateTimeUtil.of(dateTime);
|
|
|
+//
|
|
|
+// LocalDateTime day2 = LocalDateTime.now();
|
|
|
+// System.out.println(day2);
|
|
|
+// long between = ChronoUnit.DAYS.between(day1, day2);
|
|
|
+// System.out.println(between);
|
|
|
+//
|
|
|
+//
|
|
|
+// for (int i = 0; i <= between; i++) {
|
|
|
+// System.out.println(i);
|
|
|
+// int i1 = DateUtil.lengthOfMonth(DateUtil.month(dateTime), false);
|
|
|
+// System.out.println(i1);
|
|
|
+//
|
|
|
+//
|
|
|
+// }
|
|
|
+//
|
|
|
+// }
|
|
|
}
|
|
|
+
|