|
@@ -90,7 +90,7 @@ public class LeanModelStatistics {
|
|
|
/**
|
|
|
* 设备启停统计数据
|
|
|
*/
|
|
|
- @Scheduled(fixedDelay = 10000)
|
|
|
+ @Scheduled(fixedDelay = 20000)
|
|
|
public void t3(){
|
|
|
deviceStatistics();
|
|
|
}
|
|
@@ -196,7 +196,7 @@ public class LeanModelStatistics {
|
|
|
// 运行时常
|
|
|
BigDecimal runTime = new BigDecimal("300");
|
|
|
// 电流
|
|
|
- BigDecimal selectricCurrent = fpgGatherData.getRunCurrent().compareTo(new BigDecimal("0.00")) > 0 ? fpgGatherData.getRunCurrent().divide(new BigDecimal(12), 6, RoundingMode.HALF_UP) : fpgGatherData.getRunCurrent();
|
|
|
+ BigDecimal selectricCurrent = fpgGatherData.getRunCurrent();
|
|
|
// 设备启停统计 start
|
|
|
String startStopMonKey = "total_startstop";
|
|
|
DeviceStatiscsModelData startStopStatiscsData = new DeviceStatiscsModelData(fpgGatherData, startStopMonKey, dayDate, classs, curentDate, curentDate);
|
|
@@ -207,10 +207,17 @@ public class LeanModelStatistics {
|
|
|
// 查找设备运行记录
|
|
|
DeviceStatiscsModelMongodb startStopMongo = mongoTemplate.findOne(queryStartStop, DeviceStatiscsModelMongodb.class, startStopMonKey);
|
|
|
if(startStopMongo != null){
|
|
|
- if(fpgGatherData.getRunCurrent().compareTo(new BigDecimal(systemVariable.getDefaultValue())) < 0){ // 设备停止运行 直接更新停止时间结束不用统计任何东西
|
|
|
+ int timeRes = compareDatesByTimeStamp(DateUtils.str2Date(startStopMongo.getDeviceStartTime(), DateUtils.datetimeFormat.get()), DateUtils.str2Date(startStopMongo.getDeviceStopTimeBank(), DateUtils.datetimeFormat.get()));
|
|
|
+ Date deviceStopTimeEnd = DateUtils.addHours(fpgGatherData.getCreateTime(), 8);
|
|
|
+ if (fpgGatherData.getRunCurrent().compareTo(new BigDecimal(systemVariable.getDefaultValue())) < 0) { // 设备停止运行 直接更新停止时间结束不用统计任何东西
|
|
|
UpdateDefinition updateStartStop = new Update()
|
|
|
- .set("updateTime", curentDate).set("deviceStopTime", DateUtils.date2Str(curentDate, DateUtils.datetimeFormat.get()));
|
|
|
+ .set("updateTime", curentDate).set("deviceStopTime", deviceStopTimeEnd).set("deviceStopTimeBank", deviceStopTimeEnd);
|
|
|
mongoTemplate.updateFirst(queryStartStop, updateStartStop, DeviceStatiscsModelMongodb.class, startStopMonKey);
|
|
|
+ } else if(fpgGatherData.getRunCurrent().compareTo(new BigDecimal(systemVariable.getDefaultValue())) > 0 && timeRes != 0){ // 设备重新启动
|
|
|
+ startStopStatiscsData.setPower(runPower);
|
|
|
+ startStopStatiscsData.setIngTime(runTime);
|
|
|
+ startStopStatiscsData.setSelectricCurrent(selectricCurrent);
|
|
|
+ mongoTemplate.insert(startStopStatiscsData, startStopMonKey);
|
|
|
return;
|
|
|
} else { // 设备运行累加
|
|
|
// 历史数据
|
|
@@ -218,23 +225,30 @@ public class LeanModelStatistics {
|
|
|
BigDecimal oldRunTime = startStopMongo.getIngTime() == null ? new BigDecimal("0.00") : startStopMongo.getIngTime();
|
|
|
BigDecimal oldSelectricCurrent = startStopMongo.getSelectricCurrent() == null ? new BigDecimal("0.00") : startStopMongo.getSelectricCurrent();
|
|
|
// 更新启动运行数据
|
|
|
+ Date deviceStopTime = DateUtils.addHours(fpgGatherData.getCreateTime(), 8);
|
|
|
UpdateDefinition updateStartStop = new Update()
|
|
|
.set("power", oldPower.add(runPower))
|
|
|
.set("selectricCurrent", oldSelectricCurrent.add(selectricCurrent))
|
|
|
.set("ingTime", oldRunTime.add(runTime))
|
|
|
+ .set("deviceStopTime", deviceStopTime)
|
|
|
.set("updateTime", curentDate);
|
|
|
mongoTemplate.updateFirst(queryStartStop, updateStartStop, FpgStatiscsModelMongodb.class, startStopMonKey);
|
|
|
}
|
|
|
} else { // 直接插入
|
|
|
if(fpgGatherData.getRunCurrent().compareTo(new BigDecimal(systemVariable.getDefaultValue())) > 0){ // 运行中计入启停记录
|
|
|
startStopStatiscsData.setPower(runPower);
|
|
|
- startStopStatiscsData.setDeviceStopTime(null);
|
|
|
startStopStatiscsData.setIngTime(runTime);
|
|
|
- startStopStatiscsData.setSelectricCurrent(runTime);
|
|
|
+ startStopStatiscsData.setSelectricCurrent(selectricCurrent);
|
|
|
mongoTemplate.insert(startStopStatiscsData, startStopMonKey);
|
|
|
}
|
|
|
}
|
|
|
// 设备启停统计 end
|
|
|
+ // 设备停止运行不统计
|
|
|
+ if (fpgGatherData.getRunCurrent().compareTo(new BigDecimal(systemVariable.getDefaultValue())) < 0) { // 设备停止运行
|
|
|
+ fpgGatherData.setFpgTotalUpdatetime(new Date());
|
|
|
+ fpgGatherData.setId(fpgGatherData.getId());
|
|
|
+ return;
|
|
|
+ }
|
|
|
// 日统计尖峰平谷数据(功率+占比+电流+运行时长) start
|
|
|
String dayPowerproportioncurrentRunMonKey = "total_day_powerproportioncurrent";
|
|
|
DeviceStatiscsModelData dayPowerproportioncurrentRunData = new DeviceStatiscsModelData(fpgGatherData, dayPowerproportioncurrentRunMonKey, dayDate, classs, curentDate, curentDate);
|
|
@@ -305,6 +319,30 @@ public class LeanModelStatistics {
|
|
|
}
|
|
|
mongoTemplate.updateFirst(queryDayPowerproportioncurrentRun, update, DeviceStatiscsModelMongodb.class, dayPowerproportioncurrentRunMonKey);
|
|
|
} else { // 为空直接插入
|
|
|
+ // 尖峰平谷判定
|
|
|
+ if("tops".equals(jfpgStr.get())){ // 尖
|
|
|
+ // 功率处理
|
|
|
+ dayPowerproportioncurrentRunData.setTopsPower(runPower);
|
|
|
+ dayPowerproportioncurrentRunData.setTopsIngTime(runTime);
|
|
|
+// dayPowerproportioncurrentRunData.setTopsSelectricCurrent(selectricCurrent);
|
|
|
+ } else if("peaks".equals(jfpgStr.get())){ // 峰
|
|
|
+ // 功率处理
|
|
|
+ dayPowerproportioncurrentRunData.setPeaksPower(runPower);
|
|
|
+ dayPowerproportioncurrentRunData.setPeaksIngTime(runTime);
|
|
|
+// dayPowerproportioncurrentRunData.setPeaksSelectricCurrent(selectricCurrent);
|
|
|
+ } else if("flat".equals(jfpgStr.get())){ // 平
|
|
|
+ // 功率处理
|
|
|
+ dayPowerproportioncurrentRunData.setFlatPower(runPower);
|
|
|
+ dayPowerproportioncurrentRunData.setFlatIngTime(runTime);
|
|
|
+// dayPowerproportioncurrentRunData.setFlatSelectricCurrent(selectricCurrent);
|
|
|
+ } else if("valleys".equals(jfpgStr.get())){ // 谷
|
|
|
+ dayPowerproportioncurrentRunData.setValleysPower(runPower);
|
|
|
+ dayPowerproportioncurrentRunData.setValleysIngTime(runTime);
|
|
|
+// dayPowerproportioncurrentRunData.setValleysSelectricCurrent(selectricCurrent);
|
|
|
+ }
|
|
|
+ dayPowerproportioncurrentRunData.setPower(runPower);
|
|
|
+ dayPowerproportioncurrentRunData.setIngTime(runTime);
|
|
|
+// dayPowerproportioncurrentRunData.setSelectricCurrent(selectricCurrent);
|
|
|
mongoTemplate.insert(dayPowerproportioncurrentRunData, dayPowerproportioncurrentRunMonKey);
|
|
|
}
|
|
|
// 日统计尖峰平谷数据(功率+占比+电流+运行时长) end
|
|
@@ -319,6 +357,26 @@ public class LeanModelStatistics {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ // 验证时间
|
|
|
+ public static int compareDatesByTimeStamp(Date date1, Date date2) {
|
|
|
+ if (date1 == null && date2 == null) {
|
|
|
+ return 0;
|
|
|
+ } else if (date1 == null) {
|
|
|
+ return -1;
|
|
|
+ } else if (date2 == null) {
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+ long timeStamp1 = date1.getTime();
|
|
|
+ long timeStamp2 = date2.getTime();
|
|
|
+ if (timeStamp1 < timeStamp2) {
|
|
|
+ return -1;
|
|
|
+ } else if (timeStamp1 > timeStamp2) {
|
|
|
+ return 1;
|
|
|
+ } else {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// 精益模型统计数据
|
|
|
public void leanModel(){
|
|
|
log.info("峰平谷模型");
|
|
@@ -332,6 +390,13 @@ public class LeanModelStatistics {
|
|
|
List<PeaksAndValleysTimeConfig> peaksAndValleysTimeConfiglist = peaksAndValleysTimeConfigService.list();
|
|
|
// 存储fpgGather数据id集合
|
|
|
List<FpgGatherData> fpgGatherUpdateList= new ArrayList<>();
|
|
|
+
|
|
|
+ // 系统变量查询
|
|
|
+ QueryWrapper<SystemVariable> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq("variable_address", "sys_run_current_limit");
|
|
|
+ queryWrapper.eq("status", 0);
|
|
|
+ SystemVariable systemVariable = systemVariableService.getOne(queryWrapper);
|
|
|
+
|
|
|
// 遍历设备集合
|
|
|
fpgLeanModellist.forEach(fpgLeanModeInfo -> {
|
|
|
LambdaQueryWrapper<FpgGatherData> fpgGatherQuery = new LambdaQueryWrapper<FpgGatherData>().isNull(FpgGatherData::getFpgModelUpdatetime).isNotNull(FpgGatherData::getRunCurrent).isNotNull(FpgGatherData::getActivePower);
|
|
@@ -345,6 +410,12 @@ public class LeanModelStatistics {
|
|
|
fpgGatherList.forEach(fpgGatherData -> { // 循环处理采集数据处理
|
|
|
fpgGatherData.setFpgModelUpdatetime(new Date());
|
|
|
try {
|
|
|
+ BigDecimal runTime = new BigDecimal("300");
|
|
|
+ // 设备停止运行不统计
|
|
|
+ if (fpgGatherData.getRunCurrent().compareTo(new BigDecimal(systemVariable.getDefaultValue())) < 0) { // 设备停止运行
|
|
|
+ fpgGatherUpdateList.add(fpgGatherData);
|
|
|
+ return;
|
|
|
+ }
|
|
|
String finalDatestr = "";
|
|
|
// 统计单位
|
|
|
if("minute".equals(fpgLeanModeInfo.getTotalUnit())){ // 分钟
|
|
@@ -419,8 +490,7 @@ public class LeanModelStatistics {
|
|
|
// 功率 5 分钟上报一次 除以 12
|
|
|
BigDecimal activePower = fpgGatherData.getActivePower() == null ? new BigDecimal("0.00") : fpgGatherData.getActivePower().divide(new BigDecimal("12"), 6, RoundingMode.HALF_UP);
|
|
|
// 电流
|
|
|
- BigDecimal selectricCurrent = fpgGatherData.getRunCurrent() == null ? new BigDecimal("0.00") : fpgGatherData.getRunCurrent().divide(new BigDecimal("12"), 6, RoundingMode.HALF_UP);
|
|
|
- BigDecimal runTime = new BigDecimal("300");
|
|
|
+ BigDecimal selectricCurrent = fpgGatherData.getRunCurrent() == null ? new BigDecimal("0.00") : fpgGatherData.getRunCurrent();
|
|
|
BigDecimal oldPower = fpgStatiscsModelMongo.getPower() == null ? new BigDecimal("0.00") : fpgStatiscsModelMongo.getPower();
|
|
|
BigDecimal oldingTime = fpgStatiscsModelMongo.getIngTime() == null ? new BigDecimal("0.00") : fpgStatiscsModelMongo.getIngTime();
|
|
|
// 总运行时间处理
|