|
|
@@ -83,7 +83,9 @@ public class AsyncYhjService {
|
|
|
Long startTime = start.toInstant(ZoneOffset.of("+8")).toEpochMilli();
|
|
|
Long endTime = end.toInstant(ZoneOffset.of("+8")).toEpochMilli();
|
|
|
TwinCalcHourYhj calcYhj = new TwinCalcHourYhj();
|
|
|
- String[] fields = {"Formula_data_set_1", "Formula_data_act_5"};
|
|
|
+ calcYhj.setCloseTime(0L);
|
|
|
+ calcYhj.setOpenTime(0L);
|
|
|
+ String[] fields = {"Formula_data_set_1", "Formula_data_act_5", "Formula_data_act_2"};
|
|
|
|
|
|
String sql = "select %s from " + yhj.getDevicePath() + " where time>%s and time <=%s";
|
|
|
|
|
|
@@ -114,15 +116,16 @@ public class AsyncYhjService {
|
|
|
}
|
|
|
for (int j = 0; j < columnNames.size(); j++) {
|
|
|
String name = columnNames.getStr(j);
|
|
|
- if (name.contains("Formula_data_set_1")) {
|
|
|
- //如果是版距,则需要记录变化
|
|
|
- if (curr[j] != null && last[j] != null && curr[j].intValue() != last[j].intValue()) {
|
|
|
- //这里要用j+1才行
|
|
|
- calcLength(j + 1, last, first, total);
|
|
|
- combo(calcYhj, start, yhj, last[j], total[j + 1]);
|
|
|
- total[j + 1] = 0;
|
|
|
- }
|
|
|
- }
|
|
|
+// 版距暂时没用,取消掉
|
|
|
+// if (name.contains("Formula_data_set_1")) {
|
|
|
+// //如果是版距,则需要记录变化
|
|
|
+// if (curr[j] != null && last[j] != null && curr[j].intValue() != last[j].intValue()) {
|
|
|
+// //这里要用j+1才行
|
|
|
+// calcLength(j + 1, last, first, total);
|
|
|
+// combo(calcYhj, start, yhj, last[j], total[j + 1]);
|
|
|
+// total[j + 1] = 0;
|
|
|
+// }
|
|
|
+// }
|
|
|
if (name.contains("Formula_data_act_5")) {
|
|
|
//如果是米长,则需要记录是否清0
|
|
|
//如果当前值为小于上一个,且上一个值不为0,则计算
|
|
|
@@ -132,6 +135,33 @@ public class AsyncYhjService {
|
|
|
cloneArray(curr, first);
|
|
|
}
|
|
|
}
|
|
|
+ if (name.contains("Formula_data_act_2")) {
|
|
|
+ //如果是速度,则需要判断是否为0
|
|
|
+ //这里稍微有点复杂,需要根据 curr[j]=0 则判断是close,否则为open,统计数据需要存 timestamps.get(i)-timestamps.get(i-1)
|
|
|
+ if (curr[j] != null && last[j] != null) {
|
|
|
+ // 计算时间差(毫秒)
|
|
|
+ Long timeDiff = timestamps.getLong(i) - timestamps.getLong(i - 1);
|
|
|
+ if (last[j] > 0) {
|
|
|
+ // 上一时刻是开启状态
|
|
|
+ if (curr[j] > 0) {
|
|
|
+ // 保持开启状态,统计运行时间
|
|
|
+ calcYhj.addOpenTime(timeDiff);
|
|
|
+ } else {
|
|
|
+ // 从开启切换到关闭,统计运行时间
|
|
|
+ calcYhj.addOpenTime(timeDiff);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 上一时刻是关闭状态
|
|
|
+ if (curr[j] > 0) {
|
|
|
+ // 从关闭切换到开启,统计关机时间(从上次关机到这次启动的时间)
|
|
|
+ calcYhj.addCloseTime(timeDiff);
|
|
|
+ } else {
|
|
|
+ // 保持关闭状态,统计关机时间
|
|
|
+ calcYhj.addCloseTime(timeDiff);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
//将本次的值,设为上一条记录了
|
|
|
cloneArray(curr, last);
|
|
|
@@ -144,8 +174,24 @@ public class AsyncYhjService {
|
|
|
calcLength(j + 1, over, first, total);
|
|
|
combo(calcYhj, start, yhj, over[j], total[j + 1]);
|
|
|
}
|
|
|
+ // 处理速度的最后运行时间或关机时间统计
|
|
|
+ if (name.contains("Formula_data_act_2")) {
|
|
|
+ // 根据最后状态统计运行时间或关机时间
|
|
|
+ if (over[j] != null && timestamps.size() >= 2) {
|
|
|
+ // 计算最后两个时间点之间的差值
|
|
|
+ Long lastTimeDiff = timestamps.getLong(timestamps.size() - 1) - timestamps.getLong(timestamps.size() - 2);
|
|
|
+ if (over[j] > 0) {
|
|
|
+ // 如果最后时刻设备在运行,则统计运行时间
|
|
|
+ calcYhj.addOpenTime(lastTimeDiff);
|
|
|
+ } else {
|
|
|
+ // 如果最后时刻设备在停止状态,则统计关机时间
|
|
|
+ calcYhj.addCloseTime(lastTimeDiff);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+
|
|
|
return new AsyncResult<>(calcYhj);
|
|
|
}
|
|
|
|