|
@@ -0,0 +1,173 @@
|
|
|
|
+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.MeterInfoBottomcode;
|
|
|
|
+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.service.impl.MeterInfoBottomcodeServiceImpl;
|
|
|
|
+import com.gyee.gaia.meter.service.impl.MeterPointServiceImpl;
|
|
|
|
+import com.gyee.gaia.meter.service.impl.PowerStationServiceImpl;
|
|
|
|
+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.math.RoundingMode;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * Author: malijun
|
|
|
|
+ * Data : 2023: 05: 09
|
|
|
|
+ **/
|
|
|
|
+
|
|
|
|
+@Component
|
|
|
|
+public class SaveMeterInfoBottomcode10Min {
|
|
|
|
+ private static final Logger logger = LoggerFactory.getLogger(SaveMeterInfoBottomcode10Min.class);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @Resource
|
|
|
|
+ PowerStationServiceImpl powerStationService;
|
|
|
|
+
|
|
|
|
+ @Resource
|
|
|
|
+ MeterPointServiceImpl meterPointService;
|
|
|
|
+
|
|
|
|
+ @Resource
|
|
|
|
+ MeterInfoBottomcodeServiceImpl meterInfoBottomcodeService;
|
|
|
|
+
|
|
|
|
+ @Resource
|
|
|
|
+ Adapter adapter;
|
|
|
|
+
|
|
|
|
+ @XxlJob("SaveMeterInfoBottomcode10Min")
|
|
|
|
+ void saveBottomcode() {
|
|
|
|
+ XxlJobHelper.log("开始执行保存底层设备信息定时任务,hello");
|
|
|
|
+
|
|
|
|
+ //获取当前日期,当日开始时间
|
|
|
|
+ String nowString = DateUtil.now();
|
|
|
|
+ DateTime nowDateTime = DateUtil.parse(nowString);
|
|
|
|
+ DateTime startDateTime = DateUtil.beginOfDay(nowDateTime);
|
|
|
|
+
|
|
|
|
+ //类似之前代码,获取场站,遍历场站,根据场站ID获取测点code
|
|
|
|
+ //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()));
|
|
|
|
+ System.out.println(powerStation.getNemCode() + "场站测点数量" + meterPointList.size());
|
|
|
|
+
|
|
|
|
+ //3,遍历测点,拿到每个测点的nem_code
|
|
|
|
+ for (MeterPoint meterPoint : meterPointList) {
|
|
|
|
+ //获取测点code
|
|
|
|
+ String pointcode = meterPoint.getNemCode();
|
|
|
|
+
|
|
|
|
+ if (null == pointcode) {
|
|
|
|
+
|
|
|
|
+ BigDecimal bigDecimal1 = meterPoint.getInitialValue();
|
|
|
|
+ bigDecimal1 = bigDecimal1.divide(meterPoint.getXs(), 4, RoundingMode.HALF_EVEN);
|
|
|
|
+ BigDecimal bigDecimal2 = meterPoint.getInitialValue();
|
|
|
|
+ bigDecimal2 = bigDecimal2.divide(meterPoint.getXs(), 4, RoundingMode.HALF_EVEN);
|
|
|
|
+ BigDecimal rfdl = bigDecimal2.subtract(bigDecimal1).multiply(meterPoint.getMagnification());
|
|
|
|
+
|
|
|
|
+ MeterInfoBottomcode meterInfoBottomcode = new MeterInfoBottomcode();
|
|
|
|
+ //name
|
|
|
|
+ meterInfoBottomcode.setName(meterPoint.getName());
|
|
|
|
+ //开始时间,当日开始时间
|
|
|
|
+ meterInfoBottomcode.setStartTime(startDateTime.toLocalDateTime());
|
|
|
|
+ //开始值,section接口获取当日00:00:01数据
|
|
|
|
+ meterInfoBottomcode.setStartValue(bigDecimal1);
|
|
|
|
+ //最新时间,latest返回的时间
|
|
|
|
+ meterInfoBottomcode.setEndTime(startDateTime.toLocalDateTime());
|
|
|
|
+ //最新值,latest返回的值
|
|
|
|
+ meterInfoBottomcode.setEndValue(bigDecimal2);
|
|
|
|
+ //日电量
|
|
|
|
+ meterInfoBottomcode.setDayValue(rfdl);
|
|
|
|
+ //code,meter.getCode
|
|
|
|
+ meterInfoBottomcode.setCode(null);
|
|
|
|
+ //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();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ } else {
|
|
|
|
+ //根据测点code,用适配器section接口获取当日00:00:01数据,存入数据库当天开始值
|
|
|
|
+ Map<String, PointData> historySection1 = adapter.getHistorySection(pointcode, startDateTime.getTime());
|
|
|
|
+ double value1 = 0;
|
|
|
|
+ if (historySection1.size() > 0) {
|
|
|
|
+ value1 = historySection1.get(pointcode).getValue();
|
|
|
|
+ }
|
|
|
|
+ BigDecimal bigDecimal1 = BigDecimal.valueOf(value1);
|
|
|
|
+ bigDecimal1 = bigDecimal1.divide(meterPoint.getXs(), 4, RoundingMode.HALF_EVEN);
|
|
|
|
+
|
|
|
|
+ //根据测点code,用适配器latest接口获取最新数据和时间,存入数据库结束值
|
|
|
|
+ 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);
|
|
|
|
+ bigDecimal2 = bigDecimal2.divide(meterPoint.getXs(), 4, RoundingMode.HALF_EVEN);
|
|
|
|
+ DateTime enddateTime = new DateTime(ts);
|
|
|
|
+ //计算日电量
|
|
|
|
+ BigDecimal rfdl = bigDecimal2.subtract(bigDecimal1).multiply(meterPoint.getMagnification());
|
|
|
|
+
|
|
|
|
+ MeterInfoBottomcode meterInfoBottomcode = new MeterInfoBottomcode();
|
|
|
|
+
|
|
|
|
+ //name
|
|
|
|
+ meterInfoBottomcode.setName(meterPoint.getName());
|
|
|
|
+ //开始时间,当日开始时间
|
|
|
|
+ meterInfoBottomcode.setStartTime(startDateTime.toLocalDateTime());
|
|
|
|
+ //开始值,section接口获取当日00:00:01数据
|
|
|
|
+ meterInfoBottomcode.setStartValue(bigDecimal1);
|
|
|
|
+ //最新时间,latest返回的时间
|
|
|
|
+ meterInfoBottomcode.setEndTime(enddateTime.toLocalDateTime());
|
|
|
|
+ //最新值,latest返回的值
|
|
|
|
+ meterInfoBottomcode.setEndValue(bigDecimal2);
|
|
|
|
+ //日电量
|
|
|
|
+ meterInfoBottomcode.setDayValue(rfdl);
|
|
|
|
+ //code,meter.getCode
|
|
|
|
+ meterInfoBottomcode.setCode(meterPoint.getNemCode());
|
|
|
|
+ //windpowerstation_id,meter.getWindpowerstationId,
|
|
|
|
+ meterInfoBottomcode.setWindpowerstationId(meterPoint.getWindpowerstationId());
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ QueryWrapper<MeterInfoBottomcode> queryWrapper = new QueryWrapper<>();
|
|
|
|
+ queryWrapper.eq("start_time", startDateTime.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();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|