|
@@ -21,6 +21,7 @@ import java.time.temporal.ChronoUnit;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
+import java.util.function.Function;
|
|
|
|
|
|
/**
|
|
|
* Author: malijun
|
|
@@ -78,7 +79,7 @@ public class GetMeterInfo {
|
|
|
MeterInfoVo meterInfoVo = new MeterInfoVo();
|
|
|
meterInfoVo.setDate(dateTime1);
|
|
|
meterInfoVo.setName(meterInfoEquipment.getName());
|
|
|
- meterInfoVo.setRdl(meterInfoEquipment.getRfdl().divide(BigDecimal.valueOf(10000), 4, RoundingMode.HALF_EVEN));
|
|
|
+ meterInfoVo.setRdl(meterInfoEquipment.getRfdl().divide(BigDecimal.valueOf(10000), 2, RoundingMode.HALF_EVEN));
|
|
|
meterInfoVos.add(meterInfoVo);
|
|
|
}
|
|
|
}
|
|
@@ -247,7 +248,8 @@ public class GetMeterInfo {
|
|
|
//条件构造器批量查询
|
|
|
List<MeterInfoEquipment> meterInfoEquipments = meterInfoEquipmentService.list(new QueryWrapper<MeterInfoEquipment>()
|
|
|
.in("date", dateTimes)
|
|
|
- .eq("equipment_nem_code", id)
|
|
|
+ .eq(StringUtil.isNotBlank(windId), "powerstation_nem_code", windId)
|
|
|
+ .eq(StringUtil.isNotBlank(id),"equipment_nem_code", id)
|
|
|
);
|
|
|
//遍历每月
|
|
|
for (int i = 0; i <= between; i++) {
|
|
@@ -269,13 +271,14 @@ public class GetMeterInfo {
|
|
|
//循环遍历当月每一天,累加每日发电量到月发电量
|
|
|
for (int j = 0; j <= betweenDay; j++) {
|
|
|
DateTime dateTime3 = DateUtil.offsetDay(dateTime1, j);
|
|
|
- MeterInfoEquipment meterInfoEquipment = findMeterInfoEquipment(meterInfoEquipments, equipment.getNemCode(), dateTime3);
|
|
|
+// MeterInfoEquipment meterInfoEquipment = findMeterInfoEquipment(meterInfoEquipments, equipment.getNemCode(), dateTime3);
|
|
|
+ MeterInfoEquipment meterInfoEquipment = findObjectByCodeAndDate(meterInfoEquipments, equipment.getNemCode(), dateTime3.toLocalDateTime(), MeterInfoEquipment::getEquipmentNemCode, MeterInfoEquipment::getDate);
|
|
|
if (meterInfoEquipment != null) {
|
|
|
ydl = ydl.add(meterInfoEquipment.getRfdl());
|
|
|
}
|
|
|
}
|
|
|
//VO对象赋值月发电量,添加入VO对象集合
|
|
|
- meterInfoVo.setRdl(ydl);
|
|
|
+ meterInfoVo.setRdl(ydl.divide(BigDecimal.valueOf(10000),2,RoundingMode.HALF_EVEN));
|
|
|
meterInfoVos.add(meterInfoVo);
|
|
|
}
|
|
|
}
|
|
@@ -343,7 +346,8 @@ public class GetMeterInfo {
|
|
|
for (int j = 0; j <= betweenDay; j++) {
|
|
|
DateTime dateTime3 = DateUtil.offsetDay(dateTime1, j);
|
|
|
//调用方法,根据时间和code查询集合中的某个对象
|
|
|
- MeterInfoBottomcode meterInfoBottomcode = findMeterInfoBottomcode(meterInfoBottomcodes, meterPoint.getNemCode(), dateTime3);
|
|
|
+// MeterInfoBottomcode meterInfoBottomcode = findMeterInfoBottomcode(meterInfoBottomcodes, meterPoint.getNemCode(), dateTime3);
|
|
|
+ MeterInfoBottomcode meterInfoBottomcode = findObjectByCodeAndDate(meterInfoBottomcodes, meterPoint.getNemCode(), dateTime3.toLocalDateTime(), MeterInfoBottomcode::getCode, MeterInfoBottomcode::getStartTime);
|
|
|
if (meterInfoBottomcode != null) {
|
|
|
//当月第一天底码,起码
|
|
|
if (j == 0) {
|
|
@@ -420,7 +424,8 @@ public class GetMeterInfo {
|
|
|
BigDecimal ydl = BigDecimal.valueOf(0);
|
|
|
for (int j = 0; j <= betweenDay; j++) {
|
|
|
DateTime dateTime3 = DateUtil.offsetDay(dateTime1, j);
|
|
|
- MeterInfoCalculating meterInfoCalculating = findMeterInfoCalculating(meterInfoCalculatings, meterPoint.getNemCode(), dateTime3);
|
|
|
+// meterInfoCalculating = findMeterInfoCalculating(meterInfoCalculatings, meterPoint.getNemCode(), dateTime3);
|
|
|
+ MeterInfoCalculating meterInfoCalculating = findObjectByCodeAndDate(meterInfoCalculatings, meterPoint.getNemCode(), dateTime3.toLocalDateTime(), MeterInfoCalculating::getCode, MeterInfoCalculating::getDate);
|
|
|
if (meterInfoCalculating != null) {
|
|
|
ydl = ydl.add(meterInfoCalculating.getValue());
|
|
|
}
|
|
@@ -434,6 +439,245 @@ public class GetMeterInfo {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ //获取风机发电量,每年
|
|
|
+ public ArrayList<MeterInfoVo> getEquipmentInfoYearByWindId(String windId, String id, long startTime, long endTime) {
|
|
|
+ //时间戳转为字符串
|
|
|
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ String format1 = simpleDateFormat.format(new Date(startTime));
|
|
|
+ String format2 = simpleDateFormat.format(new Date(endTime));
|
|
|
+ //字符串转为DateTime类型
|
|
|
+ DateTime startDateTime1 = DateUtil.parse(format1);
|
|
|
+ DateTime endDateTime1 = DateUtil.parse(format2);
|
|
|
+ //开始时间年的第一天,结束时间年的最后一天
|
|
|
+ DateTime startDateTime = DateUtil.beginOfYear(startDateTime1);
|
|
|
+ DateTime endDateTime = DateUtil.endOfYear(endDateTime1);
|
|
|
+ //转为LocalDateTime类型计算间隔数
|
|
|
+ LocalDateTime day1 = LocalDateTimeUtil.of(startDateTime);
|
|
|
+ LocalDateTime day2 = LocalDateTimeUtil.of(endDateTime);
|
|
|
+ //开始时间到结束时间间隔年
|
|
|
+ long between = ChronoUnit.YEARS.between(day1, day2);
|
|
|
+ //开始时间到结束时间间隔天数
|
|
|
+ long betweenDays = ChronoUnit.DAYS.between(day1, day2);
|
|
|
+
|
|
|
+ //VO对象集合
|
|
|
+ ArrayList<MeterInfoVo> meterInfoVos = new ArrayList<>();
|
|
|
+
|
|
|
+ //条件构造器查询
|
|
|
+ List<Equipment> equipments = equipmentService.list(new QueryWrapper<Equipment>()
|
|
|
+ .eq(StringUtil.isNotBlank(windId), "windpowerstation_id", windId)
|
|
|
+ .eq(StringUtil.isNotBlank(id), "nem_code", id)
|
|
|
+ );
|
|
|
+ //要查询的时间集合,以便后面批量查询
|
|
|
+ List<DateTime> dateTimes = new ArrayList<>();
|
|
|
+ for (int i = 0; i <= betweenDays; i++) {
|
|
|
+ DateTime dateTime4 = DateUtil.offsetDay(startDateTime, i);
|
|
|
+ dateTimes.add(dateTime4);
|
|
|
+ }
|
|
|
+ //条件构造器批量查询
|
|
|
+ List<MeterInfoEquipment> meterInfoEquipments = meterInfoEquipmentService.list(new QueryWrapper<MeterInfoEquipment>()
|
|
|
+ .in("date", dateTimes)
|
|
|
+ .eq(StringUtil.isNotBlank(windId),"powerstation_nem_code", windId)
|
|
|
+ .eq(StringUtil.isNotBlank(id),"equipment_nem_code", id)
|
|
|
+ );
|
|
|
+ //遍历每年
|
|
|
+ for (int i = 0; i <= between; i++) {
|
|
|
+ //每年的第一天,每月的最后一天
|
|
|
+ DateTime dateTime1 = DateUtil.offsetMonth(startDateTime, i * 12);
|
|
|
+ DateTime dateTime2 = DateUtil.endOfYear(dateTime1);
|
|
|
+ //转为LocalDateTime类型计算这个的天数
|
|
|
+ LocalDateTime day3 = LocalDateTimeUtil.of(dateTime1);
|
|
|
+ LocalDateTime day4 = LocalDateTimeUtil.of(dateTime2);
|
|
|
+ long betweenDay = ChronoUnit.DAYS.between(day3, day4);
|
|
|
+ //遍历风机集合
|
|
|
+ for (Equipment equipment : equipments) {
|
|
|
+ //每台风机,VO对象先存月时间,名称
|
|
|
+ MeterInfoVo meterInfoVo = new MeterInfoVo();
|
|
|
+ meterInfoVo.setDate(dateTime1);
|
|
|
+ meterInfoVo.setName(equipment.getName());
|
|
|
+ //初始化月发电量
|
|
|
+ BigDecimal ndl = BigDecimal.valueOf(0);
|
|
|
+ //循环遍历当年每一天,累加每日发电量到年发电量
|
|
|
+ for (int j = 0; j <= betweenDay; j++) {
|
|
|
+ DateTime dateTime3 = DateUtil.offsetDay(dateTime1, j);
|
|
|
+// MeterInfoEquipment meterInfoEquipment = findMeterInfoEquipment(meterInfoEquipments, equipment.getNemCode(), dateTime3);
|
|
|
+ MeterInfoEquipment meterInfoEquipment = findObjectByCodeAndDate(meterInfoEquipments, equipment.getNemCode(), dateTime3.toLocalDateTime(), MeterInfoEquipment::getEquipmentNemCode, MeterInfoEquipment::getDate);
|
|
|
+ if (meterInfoEquipment != null) {
|
|
|
+ ndl = ndl.add(meterInfoEquipment.getRfdl());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //VO对象赋值月发电量,添加入VO对象集合
|
|
|
+ meterInfoVo.setRdl(ndl.divide(BigDecimal.valueOf(10000),2,RoundingMode.HALF_EVEN));
|
|
|
+ meterInfoVos.add(meterInfoVo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return meterInfoVos;
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取底码数据,每年
|
|
|
+ public ArrayList<MeterInfoVo> getBottomInfoYearByWindId(String windId, String meterType, String meterClass, String name, long startTime, long endTime) {
|
|
|
+ //时间戳转为字符串
|
|
|
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ String format1 = simpleDateFormat.format(new Date(startTime));
|
|
|
+ String format2 = simpleDateFormat.format(new Date(endTime));
|
|
|
+ //字符串转为DateTime类型
|
|
|
+ DateTime startDateTime1 = DateUtil.parse(format1);
|
|
|
+ DateTime endDateTime1 = DateUtil.parse(format2);
|
|
|
+ //开始时间月的第一天,结束时间月的最后一天
|
|
|
+ DateTime startDateTime = DateUtil.beginOfYear(startDateTime1);
|
|
|
+ DateTime endDateTime = DateUtil.endOfYear(endDateTime1);
|
|
|
+ //转为LocalDateTime类型,计算间隔数
|
|
|
+ LocalDateTime day1 = LocalDateTimeUtil.of(startDateTime);
|
|
|
+ LocalDateTime day2 = LocalDateTimeUtil.of(endDateTime);
|
|
|
+ //相隔年数
|
|
|
+ long between = ChronoUnit.YEARS.between(day1, day2);
|
|
|
+ //相隔天数
|
|
|
+ long betweenDays = ChronoUnit.DAYS.between(day1, day2);
|
|
|
+ //VO对象集合
|
|
|
+ ArrayList<MeterInfoVo> meterInfoVos = new ArrayList<>();
|
|
|
+ //条件构造器查询
|
|
|
+ List<MeterPoint> meterPoints = meterPointService.list(new QueryWrapper<MeterPoint>()
|
|
|
+ .eq("windpowerstation_id", windId)
|
|
|
+ .like("property", "CD")
|
|
|
+ .eq(StringUtil.isNotBlank(meterType), "meter_type", meterType)
|
|
|
+ .eq(StringUtil.isNotBlank(meterClass), "meter_class", meterClass)
|
|
|
+ .eq(StringUtil.isNotBlank(name), "name", name)
|
|
|
+
|
|
|
+ );
|
|
|
+ //时间集合,以便后面批量查询
|
|
|
+ List<DateTime> dateTimes = new ArrayList<>();
|
|
|
+ for (int i = 0; i <= betweenDays; i++) {
|
|
|
+ DateTime dateTime4 = DateUtil.offsetDay(startDateTime, i);
|
|
|
+ dateTimes.add(dateTime4);
|
|
|
+ }
|
|
|
+ //条件构造器批量查询
|
|
|
+ List<MeterInfoBottomcode> meterInfoBottomcodes = meterInfoBottomcodeService.list(new QueryWrapper<MeterInfoBottomcode>()
|
|
|
+ .in("start_time", dateTimes));
|
|
|
+
|
|
|
+ //遍历每年
|
|
|
+ for (int i = 0; i <= between; i++) {
|
|
|
+ //每年第一天和最后一天
|
|
|
+ DateTime dateTime1 = DateUtil.offsetMonth(startDateTime, i * 12);
|
|
|
+ DateTime dateTime2 = DateUtil.endOfYear(dateTime1);
|
|
|
+ //转为LocalDateTime计算当年天数
|
|
|
+ LocalDateTime day3 = LocalDateTimeUtil.of(dateTime1);
|
|
|
+ LocalDateTime day4 = LocalDateTimeUtil.of(dateTime2);
|
|
|
+ long betweenDay = ChronoUnit.DAYS.between(day3, day4);
|
|
|
+ //遍历测点,累加每天到年
|
|
|
+ for (MeterPoint meterPoint : meterPoints) {
|
|
|
+ //每台风机VO对象,先赋值时间,名称
|
|
|
+ MeterInfoVo meterInfoVo = new MeterInfoVo();
|
|
|
+ meterInfoVo.setDate(dateTime1);
|
|
|
+ meterInfoVo.setName(meterPoint.getName());
|
|
|
+ //初始化月发电量
|
|
|
+ BigDecimal ndl = BigDecimal.valueOf(0);
|
|
|
+ //循环遍历当月每一天,日发电量累加到月发电量
|
|
|
+ for (int j = 0; j <= betweenDay; j++) {
|
|
|
+ DateTime dateTime3 = DateUtil.offsetDay(dateTime1, j);
|
|
|
+ //调用方法,根据时间和code查询集合中的某个对象
|
|
|
+// MeterInfoBottomcode meterInfoBottomcode = findMeterInfoBottomcode(meterInfoBottomcodes, meterPoint.getNemCode(), dateTime3);
|
|
|
+ MeterInfoBottomcode meterInfoBottomcode = findObjectByCodeAndDate(meterInfoBottomcodes, meterPoint.getNemCode(), dateTime3.toLocalDateTime(), MeterInfoBottomcode::getCode, MeterInfoBottomcode::getStartTime);
|
|
|
+ if (meterInfoBottomcode != null) {
|
|
|
+ //当月第一天底码,起码
|
|
|
+ if (j == 0) {
|
|
|
+ meterInfoVo.setStartCode(meterInfoBottomcode.getStartValue());
|
|
|
+ }
|
|
|
+ ndl = ndl.add(meterInfoBottomcode.getDayValue());
|
|
|
+ //每天赋值一次止码,最后一天的止码为当月止码
|
|
|
+ meterInfoVo.setEndCode(meterInfoBottomcode.getEndValue());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ meterInfoVo.setRdl(ndl);
|
|
|
+ meterInfoVos.add(meterInfoVo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return meterInfoVos;
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取计算场站指标,每年
|
|
|
+ public ArrayList<MeterInfoVo> getCalculatingInfoYearByWindId(String windId, String meterType, String meterClass, String name, long startTime, long endTime) {
|
|
|
+ //时间戳转为字符串
|
|
|
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ String format1 = simpleDateFormat.format(new Date(startTime));
|
|
|
+ String format2 = simpleDateFormat.format(new Date(endTime));
|
|
|
+ //字符串转为DateTime类型
|
|
|
+ DateTime startDateTime1 = DateUtil.parse(format1);
|
|
|
+ DateTime endDateTime1 = DateUtil.parse(format2);
|
|
|
+ //开始时间月的第一天,结束时间月的最后一天
|
|
|
+ DateTime startDateTime = DateUtil.beginOfYear(startDateTime1);
|
|
|
+ DateTime endDateTime = DateUtil.endOfYear(endDateTime1);
|
|
|
+ //转为LocalDateTime计算间隔数
|
|
|
+ LocalDateTime day1 = LocalDateTimeUtil.of(startDateTime);
|
|
|
+ LocalDateTime day2 = LocalDateTimeUtil.of(endDateTime);
|
|
|
+ //相隔年数
|
|
|
+ long between = ChronoUnit.YEARS.between(day1, day2);
|
|
|
+ //相隔天数
|
|
|
+ long betweenDays = ChronoUnit.DAYS.between(day1, day2);
|
|
|
+ //VO对象集合
|
|
|
+ ArrayList<MeterInfoVo> meterInfoVos = new ArrayList<>();
|
|
|
+ //条件构造器查询计算点
|
|
|
+ List<MeterPoint> meterPoints = meterPointService.list(new QueryWrapper<MeterPoint>()
|
|
|
+ .eq("windpowerstation_id", windId)
|
|
|
+ .like("property", "JSD%")
|
|
|
+ .eq(StringUtil.isNotBlank(meterType), "meter_type", meterType)
|
|
|
+ .eq(StringUtil.isNotBlank(meterClass), "meter_class", meterClass)
|
|
|
+ .eq(StringUtil.isNotBlank(name), "name", name)
|
|
|
+
|
|
|
+ );
|
|
|
+
|
|
|
+ //时间集合,以便后面批量查询
|
|
|
+ List<DateTime> dateTimes = new ArrayList<>();
|
|
|
+ for (int i = 0; i <= betweenDays; i++) {
|
|
|
+ DateTime dateTime4 = DateUtil.offsetDay(startDateTime, i);
|
|
|
+ dateTimes.add(dateTime4);
|
|
|
+ }
|
|
|
+ //批量查询拿到计算点数据
|
|
|
+ List<MeterInfoCalculating> meterInfoCalculatings = meterInfoCalculatingService.list(new QueryWrapper<MeterInfoCalculating>()
|
|
|
+ .in("date", dateTimes));
|
|
|
+
|
|
|
+ //遍历每年
|
|
|
+ for (int i = 0; i <= between; i++) {
|
|
|
+ //每月开始时间和结束时间
|
|
|
+ DateTime dateTime1 = DateUtil.offsetMonth(startDateTime, i * 12);
|
|
|
+ DateTime dateTime2 = DateUtil.endOfYear(dateTime1);
|
|
|
+ //转为LocalDateTime类型计算间隔数
|
|
|
+ LocalDateTime day3 = LocalDateTimeUtil.of(dateTime1);
|
|
|
+ LocalDateTime day4 = LocalDateTimeUtil.of(dateTime2);
|
|
|
+ //当年天数
|
|
|
+ long betweenDay = ChronoUnit.DAYS.between(day3, day4);
|
|
|
+ //循环遍历每个测点
|
|
|
+ for (MeterPoint meterPoint : meterPoints) {
|
|
|
+ MeterInfoVo meterInfoVo = new MeterInfoVo();
|
|
|
+ meterInfoVo.setDate(dateTime1);
|
|
|
+ meterInfoVo.setName(meterPoint.getName());
|
|
|
+ BigDecimal ndl = BigDecimal.valueOf(0);
|
|
|
+ for (int j = 0; j <= betweenDay; j++) {
|
|
|
+ DateTime dateTime3 = DateUtil.offsetDay(dateTime1, j);
|
|
|
+// meterInfoCalculating = findMeterInfoCalculating(meterInfoCalculatings, meterPoint.getNemCode(), dateTime3);
|
|
|
+ MeterInfoCalculating meterInfoCalculating = findObjectByCodeAndDate(meterInfoCalculatings, meterPoint.getNemCode(), dateTime3.toLocalDateTime(), MeterInfoCalculating::getCode, MeterInfoCalculating::getDate);
|
|
|
+ if (meterInfoCalculating != null) {
|
|
|
+ ndl = ndl.add(meterInfoCalculating.getValue());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ meterInfoVo.setRdl(ndl);
|
|
|
+ meterInfoVos.add(meterInfoVo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return meterInfoVos;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //三个辅助方法合并成一个通用方法
|
|
|
+ @Nullable
|
|
|
+ private <T> T findObjectByCodeAndDate(@NotNull List<T> objects, String code, LocalDateTime date, Function<T, String> getCodeFunction, Function<T, LocalDateTime> getDateFunction) {
|
|
|
+ for (T object : objects) {
|
|
|
+ if (getCodeFunction.apply(object).equals(code) && getDateFunction.apply(object).toLocalDate().isEqual(date.toLocalDate())) {
|
|
|
+ return object;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
// 辅助方法,根据日期和NemCode查找对象
|
|
|
@Nullable
|
|
|
private MeterInfoCalculating findMeterInfoCalculating(@NotNull List<MeterInfoCalculating> meterInfoCalculatings, String nemCode, DateTime date) {
|