|
@@ -1,6 +1,7 @@
|
|
|
package org.jeecg.modules.fpgJob;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import lombok.Data;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.jeecg.common.util.DateUtils;
|
|
|
import org.jeecg.common.util.oConvertUtils;
|
|
@@ -133,7 +134,7 @@ public class LeanModelStatistics {
|
|
|
// 获取当前时间
|
|
|
LocalDateTime newTime = LocalDateTime.now().plusHours(8);
|
|
|
Date curentDate = Date.from(newTime.atZone(ZoneId.systemDefault()).toInstant());
|
|
|
- // 峰平谷精益模型配置获取
|
|
|
+ // 峰平谷设备列表
|
|
|
List<DeviceInformation> deviceInformationllist = deviceInformationService.list();
|
|
|
// 尖峰平谷时段配置
|
|
|
List<PeaksAndValleysTimeConfig> peaksAndValleysTimeConfiglist = peaksAndValleysTimeConfigService.list();
|
|
@@ -141,14 +142,15 @@ public class LeanModelStatistics {
|
|
|
//遍历设备集合
|
|
|
deviceInformationllist.forEach(deviceInformationlinfo -> {
|
|
|
// 查询采集点
|
|
|
- LambdaQueryWrapper<DevicePoint> devicePointQuery = new LambdaQueryWrapper<DevicePoint>().eq(DevicePoint::getDeviceId, deviceInformationlinfo.getId());
|
|
|
- List<DevicePoint> devicePointList = devicePointService.list(devicePointQuery);
|
|
|
- if(oConvertUtils.listIsEmpty(devicePointList)){
|
|
|
- return;
|
|
|
- }
|
|
|
+// LambdaQueryWrapper<DevicePoint> devicePointQuery = new LambdaQueryWrapper<DevicePoint>().eq(DevicePoint::getDeviceId, deviceInformationlinfo.getId());
|
|
|
+// List<DevicePoint> devicePointList = devicePointService.list(devicePointQuery);
|
|
|
+// if(oConvertUtils.listIsEmpty(devicePointList)){
|
|
|
+// return;
|
|
|
+// }
|
|
|
// 采集点组合
|
|
|
- List<String> idsPoint = devicePointList.stream().map(DevicePoint::getId).collect(Collectors.toList());
|
|
|
- LambdaQueryWrapper<FpgGatherData> fpgGatherQuery = new LambdaQueryWrapper<FpgGatherData>().eq(FpgGatherData::getFpgModelState, "0").in(FpgGatherData::getDevicePointId, idsPoint);
|
|
|
+// List<String> idsPoint = devicePointList.stream().map(DevicePoint::getId).collect(Collectors.toList());
|
|
|
+ // 查询设备对应数据
|
|
|
+ LambdaQueryWrapper<FpgGatherData> fpgGatherQuery = new LambdaQueryWrapper<FpgGatherData>().eq(FpgGatherData::getFpgTotalUpdatetime, null).in(FpgGatherData::getDeviceInformationId, deviceInformationlinfo.getId());
|
|
|
List<FpgGatherData> fpgGatherList = fpgGatherDataService.list(fpgGatherQuery);
|
|
|
// 处理数据业务逻辑
|
|
|
fpgGatherList.forEach(fpgGatherData -> { // 循环处理采集数据处理
|
|
@@ -178,7 +180,7 @@ public class LeanModelStatistics {
|
|
|
// 功率
|
|
|
BigDecimal runPower = fpgGatherData.getActivePower();
|
|
|
// 运行时常
|
|
|
- BigDecimal runTime = new BigDecimal("1");
|
|
|
+ BigDecimal runTime = new BigDecimal("3000");
|
|
|
// 电流
|
|
|
BigDecimal selectricCurrent = fpgGatherData.getRunCurrent();
|
|
|
// 设备启停统计 start
|
|
@@ -188,7 +190,7 @@ public class LeanModelStatistics {
|
|
|
Query queryStartStop = new Query()
|
|
|
.addCriteria(Criteria.where("deviceRegionId").is(fpgGatherData.getDeviceRegionId()))
|
|
|
.addCriteria(Criteria.where("deviceInformationId").is(fpgGatherData.getDeviceInformationId()));
|
|
|
- // 设备停止
|
|
|
+ // 设备停止 start
|
|
|
if(fpgGatherData.getRunCurrent().compareTo(new BigDecimal("5")) < 0){ // 设备停止运行 直接更新停止时间结束不用统计任何东西
|
|
|
// queryStartStop.addCriteria(Criteria.where("deviceStopTime").is(null));
|
|
|
UpdateDefinition updateStartStop = new Update()
|
|
@@ -205,7 +207,7 @@ public class LeanModelStatistics {
|
|
|
BigDecimal oldSelectricCurrent = startStopMongo.getSelectricCurrent() == null ? new BigDecimal("0.00") : startStopMongo.getSelectricCurrent();
|
|
|
// 更新启动运行数据
|
|
|
UpdateDefinition updateStartStop = new Update()
|
|
|
- .set("power", oldPower.add(runPower))
|
|
|
+ .set("power", oldPower.add(runPower.divide(new BigDecimal("12"))))
|
|
|
.set("selectricCurrent", oldSelectricCurrent.add(selectricCurrent))
|
|
|
.set("ingTime", oldRunTime.add(runTime))
|
|
|
.set("updateTime", curentDate);
|
|
@@ -237,7 +239,7 @@ public class LeanModelStatistics {
|
|
|
if("tops".equals(jfpgStr.get())){ // 尖
|
|
|
// 功率处理
|
|
|
BigDecimal oldtopsPower = dayPowerproportioncurrentMongo.getTopsPower() == null ? new BigDecimal("0.00") : dayPowerproportioncurrentMongo.getTopsPower();
|
|
|
- BigDecimal topsPower = oldtopsPower.add(runPower);
|
|
|
+ BigDecimal topsPower = oldtopsPower.add(runPower.divide(new BigDecimal("12")));
|
|
|
((Update) update).set("topsPower", topsPower);
|
|
|
// 运行时常处理
|
|
|
BigDecimal oldtopsIngTime = dayPowerproportioncurrentMongo.getTopsIngTime() == null ? new BigDecimal("0.00") : dayPowerproportioncurrentMongo.getTopsIngTime();
|
|
@@ -249,7 +251,7 @@ public class LeanModelStatistics {
|
|
|
} else if("peaks".equals(jfpgStr.get())){ // 峰
|
|
|
// 功率处理
|
|
|
BigDecimal oldpeaksPower = dayPowerproportioncurrentMongo.getPeaksPower() == null ? new BigDecimal("0.00") : dayPowerproportioncurrentMongo.getPeaksPower();
|
|
|
- BigDecimal peaksPower = oldpeaksPower.add(runPower);
|
|
|
+ BigDecimal peaksPower = oldpeaksPower.add(runPower.divide(new BigDecimal("12")));
|
|
|
((Update) update).set("peaksPower", peaksPower);
|
|
|
// 运行时常处理
|
|
|
BigDecimal oldpeaksIngTime = dayPowerproportioncurrentMongo.getPeaksIngTime() == null ? new BigDecimal("0.00") : dayPowerproportioncurrentMongo.getPeaksIngTime();
|
|
@@ -261,7 +263,7 @@ public class LeanModelStatistics {
|
|
|
} else if("flat".equals(jfpgStr.get())){ // 平
|
|
|
// 功率处理
|
|
|
BigDecimal oldflatPower = dayPowerproportioncurrentMongo.getFlatPower() == null ? new BigDecimal("0.00") : dayPowerproportioncurrentMongo.getFlatPower();
|
|
|
- BigDecimal flatPower = oldflatPower.add(runPower);
|
|
|
+ BigDecimal flatPower = oldflatPower.add(runPower.divide(new BigDecimal("12")));
|
|
|
((Update) update).set("flatPower", flatPower);
|
|
|
// 运行时常处理
|
|
|
BigDecimal oldflatIngTime = dayPowerproportioncurrentMongo.getFlatIngTime() == null ? new BigDecimal("0.00") : dayPowerproportioncurrentMongo.getFlatIngTime();
|
|
@@ -273,7 +275,7 @@ public class LeanModelStatistics {
|
|
|
} else if("valleys".equals(jfpgStr.get())){ // 谷
|
|
|
// 功率处理
|
|
|
BigDecimal oldvalleysPower = dayPowerproportioncurrentMongo.getValleysPower() == null ? new BigDecimal("0.00") : dayPowerproportioncurrentMongo.getValleysPower();
|
|
|
- BigDecimal valleysPower = oldvalleysPower.add(runPower);
|
|
|
+ BigDecimal valleysPower = oldvalleysPower.add(runPower.divide(new BigDecimal("12")));
|
|
|
((Update) update).set("valleysPower", oldvalleysPower.add(runPower));
|
|
|
// 运行时常处理
|
|
|
BigDecimal oldvalleysIngTime = dayPowerproportioncurrentMongo.getValleysIngTime() == null ? new BigDecimal("0.00") : dayPowerproportioncurrentMongo.getValleysIngTime();
|
|
@@ -288,6 +290,10 @@ public class LeanModelStatistics {
|
|
|
mongoTemplate.insert(dayPowerproportioncurrentRunData, dayPowerproportioncurrentRunMonKey);
|
|
|
}
|
|
|
// 日统计尖峰平谷数据(功率+占比+电流+运行时长) end
|
|
|
+ // 执行完成数据 标记已处理
|
|
|
+ fpgGatherData.setFpgTotalUpdatetime(new Date());
|
|
|
+ fpgGatherData.setId(fpgGatherData.getId());
|
|
|
+ fpgGatherDataService.updateById(fpgGatherData);
|
|
|
} catch (Exception e) {
|
|
|
log.error(e.getMessage());
|
|
|
}
|
|
@@ -306,9 +312,11 @@ public class LeanModelStatistics {
|
|
|
Date curentDate = Date.from(newTime.atZone(ZoneId.systemDefault()).toInstant());
|
|
|
// 尖峰平谷时段配置
|
|
|
List<PeaksAndValleysTimeConfig> peaksAndValleysTimeConfiglist = peaksAndValleysTimeConfigService.list();
|
|
|
- //遍历设备集合
|
|
|
+ // 存储fpgGather数据id集合
|
|
|
+ List<FpgGatherData> fpgGatherUpdateList= new ArrayList<>();
|
|
|
+ // 遍历设备集合
|
|
|
fpgLeanModellist.forEach(fpgLeanModeInfo -> {
|
|
|
- LambdaQueryWrapper<FpgGatherData> fpgGatherQuery = new LambdaQueryWrapper<FpgGatherData>().eq(FpgGatherData::getFpgModelState, "0");
|
|
|
+ LambdaQueryWrapper<FpgGatherData> fpgGatherQuery = new LambdaQueryWrapper<FpgGatherData>().eq(FpgGatherData::getFpgModelUpdatetime, null);
|
|
|
// 检测是否配置设备特殊条件
|
|
|
if(oConvertUtils.isNotEmpty(fpgLeanModeInfo.getDeviceInformationIds()) && oConvertUtils.isNotEmpty(fpgLeanModeInfo.getDeviceInformationIds())){
|
|
|
fpgGatherQuery.in(FpgGatherData::getDeviceInformationId, Arrays.asList(fpgLeanModeInfo.getDeviceInformationIds().split(",")));
|
|
@@ -316,9 +324,8 @@ public class LeanModelStatistics {
|
|
|
List<FpgGatherData> fpgGatherList = fpgGatherDataService.list(fpgGatherQuery);
|
|
|
// 处理数据业务逻辑
|
|
|
fpgGatherList.forEach(fpgGatherData -> { // 循环处理采集数据处理
|
|
|
+ fpgGatherData.setFpgModelUpdatetime(new Date());
|
|
|
try {
|
|
|
- // 变更记录状态
|
|
|
-// fpgGatherDataService.updateById(fpgGatherData);
|
|
|
String finalDatestr = "";
|
|
|
// 统计单位
|
|
|
if("minute".equals(fpgLeanModeInfo.getTotalUnit())){ // 分钟
|
|
@@ -360,6 +367,7 @@ public class LeanModelStatistics {
|
|
|
fpgStatiscsModelData.setSelectricCurrent(fpgGatherData.getRunCurrent());
|
|
|
fpgStatiscsModelData.setPower(fpgGatherData.getActivePower());
|
|
|
mongoTemplate.insert(fpgStatiscsModelData, "leanmodel_" + fpgLeanModeInfo.getLeanModelCode());
|
|
|
+ fpgGatherUpdateList.add(fpgGatherData);
|
|
|
return;
|
|
|
}
|
|
|
// 定义尖峰平谷
|
|
@@ -389,11 +397,11 @@ public class LeanModelStatistics {
|
|
|
// 基础数据变更不受条件影响
|
|
|
UpdateDefinition update = new Update();
|
|
|
((Update) update).set("updateTime", curentDate);
|
|
|
- // 功率
|
|
|
- BigDecimal activePower = fpgGatherData.getActivePower() == null ? new BigDecimal("0.00") : fpgGatherData.getActivePower();
|
|
|
+ // 功率 5 分钟上报一次 除以 12
|
|
|
+ BigDecimal activePower = fpgGatherData.getActivePower() == null ? new BigDecimal("0.00") : fpgGatherData.getActivePower().divide(new BigDecimal("12"));
|
|
|
// 电流
|
|
|
BigDecimal selectricCurrent = fpgGatherData.getRunCurrent() == null ? new BigDecimal("0.00") : fpgGatherData.getRunCurrent();
|
|
|
- BigDecimal runTime = new BigDecimal("1");
|
|
|
+ BigDecimal runTime = new BigDecimal("3000");
|
|
|
BigDecimal oldPower = fpgStatiscsModelMongo.getPower() == null ? new BigDecimal("0.00") : fpgStatiscsModelMongo.getPower();
|
|
|
BigDecimal oldingTime = fpgStatiscsModelMongo.getIngTime() == null ? new BigDecimal("0.00") : fpgStatiscsModelMongo.getIngTime();
|
|
|
// 总运行时间处理
|
|
@@ -484,8 +492,10 @@ public class LeanModelStatistics {
|
|
|
((Update) update).set("valleysAmount", oldvalleysPower.add(activePower).multiply(fpgLeanModeInfo.getValleysPrice()));
|
|
|
}
|
|
|
}
|
|
|
+ fpgGatherUpdateList.add(fpgGatherData);
|
|
|
mongoTemplate.updateFirst(query, update, FpgStatiscsModelMongodb.class, "leanmodel_" + fpgLeanModeInfo.getLeanModelCode());
|
|
|
} else { // 为空直接插入
|
|
|
+ fpgGatherUpdateList.add(fpgGatherData);
|
|
|
// 将点位数据存入mongo中
|
|
|
mongoTemplate.insert(fpgStatiscsModelData, "leanmodel_" + fpgLeanModeInfo.getLeanModelCode());
|
|
|
}
|
|
@@ -494,6 +504,10 @@ public class LeanModelStatistics {
|
|
|
}
|
|
|
});
|
|
|
});
|
|
|
+ // 数据处理完成标记已完成信息,以免重复处理
|
|
|
+ fpgGatherUpdateList.forEach(fpgGatherData -> {
|
|
|
+ fpgGatherDataService.updateById(fpgGatherData);
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
/**
|