|
@@ -0,0 +1,176 @@
|
|
|
|
+package com.gyee.gaia.meter.service.saveHistory;
|
|
|
|
+
|
|
|
|
+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.MeterPoint;
|
|
|
|
+import com.gyee.gaia.meter.entity.PointData;
|
|
|
|
+import com.gyee.gaia.meter.entity.PowerStation;
|
|
|
|
+import com.gyee.gaia.meter.entity.ProMeterLineFDL15Min;
|
|
|
|
+import com.gyee.gaia.meter.service.impl.MeterPointServiceImpl;
|
|
|
|
+import com.gyee.gaia.meter.service.impl.PowerStationServiceImpl;
|
|
|
|
+import com.gyee.gaia.meter.service.impl.ProMeterLineFDL15MinServiceImpl;
|
|
|
|
+import com.xxl.job.core.handler.annotation.XxlJob;
|
|
|
|
+import org.junit.jupiter.api.Test;
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
|
+import org.springframework.boot.test.context.SpringBootTest;
|
|
|
|
+import org.springframework.cloud.context.config.annotation.RefreshScope;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+
|
|
|
|
+import javax.annotation.Resource;
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
+import java.math.RoundingMode;
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
|
+import java.time.temporal.ChronoUnit;
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.List;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * Author: malijun
|
|
|
|
+ * Data : 2023: 04: 27
|
|
|
|
+ **/
|
|
|
|
+@Service
|
|
|
|
+@RefreshScope
|
|
|
|
+class SaveLineFDL15Min {
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @Resource
|
|
|
|
+ Adapter adapter;
|
|
|
|
+ @Resource
|
|
|
|
+ PowerStationServiceImpl powerStationService;
|
|
|
|
+ @Resource
|
|
|
|
+ MeterPointServiceImpl meterPointService;
|
|
|
|
+ @Resource
|
|
|
|
+ ProMeterLineFDL15MinServiceImpl proMeterLineFDL15MinService;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @Value("${start.time}")
|
|
|
|
+ private String startTimeString;
|
|
|
|
+ @Value("${end.time}")
|
|
|
|
+ private String endTimeString;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @XxlJob("SaveLineFDL15Min")
|
|
|
|
+ public void saveSaveLineFDL15Min() {
|
|
|
|
+
|
|
|
|
+ //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")
|
|
|
|
+ .eq("meter_type", "线路")
|
|
|
|
+ .like("meter_class", "集电线路")
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ //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 endDateTime0 = DateUtil.parse(endDateString);
|
|
|
|
+ DateTime endDateTime = DateUtil.endOfDay(endDateTime0);
|
|
|
|
+
|
|
|
|
+ //指定开始日期到结束日期的天数
|
|
|
|
+ LocalDateTime day1 = LocalDateTimeUtil.of(startDateTime);
|
|
|
|
+ LocalDateTime day2 = LocalDateTimeUtil.of(endDateTime);
|
|
|
|
+ long between0 = ChronoUnit.MINUTES.between(day1, day2);
|
|
|
|
+ int between = (int) (between0 / 15);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ for (int i = 0; i <= between; i++) {
|
|
|
|
+
|
|
|
|
+ //开始时间00:00:01
|
|
|
|
+ DateTime dateTime1 = DateUtil.offsetMinute(startDateTime, (i - 1) * 15);
|
|
|
|
+ DateTime dateTime2 = DateUtil.offsetMinute(startDateTime, i * 15);
|
|
|
|
+ BigDecimal bigDecimal1 = new BigDecimal(0);
|
|
|
|
+ BigDecimal bigDecimal2 = new BigDecimal(0);
|
|
|
|
+ BigDecimal rfdl = new BigDecimal(0);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ List<PointData> historyRaw = adapter.getHistoryRaw(pointcode, dateTime1.getTime(), dateTime2.getTime());
|
|
|
|
+
|
|
|
|
+ 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() > 50000 || 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());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ ProMeterLineFDL15Min meterInfoBottomcode = new ProMeterLineFDL15Min();
|
|
|
|
+ meterInfoBottomcode.setName(meterPoint.getDescription());
|
|
|
|
+ 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<ProMeterLineFDL15Min> queryWrapper = new QueryWrapper<>();
|
|
|
|
+ queryWrapper
|
|
|
|
+ .eq("start_time", dateTime1.toLocalDateTime())
|
|
|
|
+ .eq("code", meterPoint.getNemCode());
|
|
|
|
+ List<ProMeterLineFDL15Min> list = proMeterLineFDL15MinService.list(queryWrapper);
|
|
|
|
+ if (list.size() > 0) {
|
|
|
|
+ meterInfoBottomcode.update(queryWrapper);
|
|
|
|
+ } else {
|
|
|
|
+ meterInfoBottomcode.insert();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|