|
@@ -7,7 +7,6 @@ import com.ruoyi.biz.service.IIotService;
|
|
|
import com.ruoyi.biz.tools.Tools;
|
|
|
import com.ruoyi.common.constant.Constants;
|
|
|
import com.ruoyi.common.utils.CacheUtils;
|
|
|
-import javafx.util.Pair;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.scheduling.annotation.AsyncResult;
|
|
@@ -50,7 +49,6 @@ public class AsyncServiceImpl {
|
|
|
public Future<Map<String, List<?>>> process(TwinDevice twinDevice, Date date, long startTime, long endTime, int period) {
|
|
|
Map<String, List<?>> result = new HashMap<>(16);
|
|
|
List<TwinCalcHour> calcHours = new ArrayList<>();
|
|
|
- List<TwinRecordAlarms> recordAlarmsList = new ArrayList<>();
|
|
|
String table = twinDevice.getDevicePath();
|
|
|
TwinCalcHour hour = new TwinCalcHour();
|
|
|
hour.setDeviceId(twinDevice.getDeviceId());
|
|
@@ -68,41 +66,6 @@ public class AsyncServiceImpl {
|
|
|
hour.setOpenTime((long) total[3]);
|
|
|
hour.setCloseTime((long) total[4]);
|
|
|
calcHours.add(hour);
|
|
|
-// Map<String, Long> stop = (Map<String, Long>) map.get("stop");
|
|
|
-// calc2hr.setStop1A(stop.get("stop1_A"));
|
|
|
-// calc2hr.setStop1B(stop.get("stop1_B"));
|
|
|
-// calc2hr.setStop2A(stop.get("stop2_A"));
|
|
|
-// calc2hr.setStop2B(stop.get("stop2_B"));
|
|
|
-// calc2hr.setStop3A(stop.get("stop3_A"));
|
|
|
-// calc2hr.setStop3B(stop.get("stop3_B"));
|
|
|
-
|
|
|
- // int[] alarms = (int[]) map.get("alarms");
|
|
|
- // int alarmsTimes = 0;
|
|
|
- // for (int i = 0; i < alarms.length; i++) {
|
|
|
- // alarmsTimes += alarms[i];
|
|
|
- // }
|
|
|
- // calc2hr.setAlarm((long) alarmsTimes);
|
|
|
- // calc2hr.setRemark(Arrays.toString(alarms));
|
|
|
- //
|
|
|
- // calc2hrList.add(calc2hr);
|
|
|
- // List<Pair<String, Long>> alarmRecord = (List<Pair<String, Long>>) map.get("alarmRecord");
|
|
|
- //
|
|
|
- // String strStop = "stop";
|
|
|
- // String strAlarm = "alarm";
|
|
|
-// alarmRecord.forEach(pair -> {
|
|
|
-// TwinRecordAlarms recordAlarms = new TwinRecordAlarms();
|
|
|
-// recordAlarms.setDeviceId(twinDevice.getId());
|
|
|
-// String key = pair.getKey();
|
|
|
-// if (key.startsWith(strStop)) {
|
|
|
-// recordAlarms.setAlarmType(strStop);
|
|
|
-// recordAlarms.setAlarmCode(Long.parseLong(key.replace(strStop, "")));
|
|
|
-// } else {
|
|
|
-// recordAlarms.setAlarmType(strAlarm);
|
|
|
-// recordAlarms.setAlarmCode(Long.parseLong(key.replace(strAlarm, "")));
|
|
|
-// }
|
|
|
-// recordAlarms.setDataTime(new Date(pair.getValue()));
|
|
|
-// recordAlarmsList.add(recordAlarms);
|
|
|
-// });
|
|
|
|
|
|
List<TwinPanHeadInfo> panHeadInfo = (List<TwinPanHeadInfo>) map.get("panHead");
|
|
|
panHeadInfo.forEach(info -> info.setDeviceId(twinDevice.getDeviceId()));
|
|
@@ -113,10 +76,16 @@ public class AsyncServiceImpl {
|
|
|
stop.setDataDate(date);
|
|
|
stop.setHour(period);
|
|
|
});
|
|
|
-
|
|
|
+ List<TwinRecordAlarms> alarmRecord = (List<TwinRecordAlarms>) map.get("alarmRecord");
|
|
|
+ alarmRecord.forEach(alarm -> {
|
|
|
+ alarm.setDeviceId(twinDevice.getDeviceId());
|
|
|
+ alarm.setDataDate(date);
|
|
|
+ alarm.setHour(period);
|
|
|
+ });
|
|
|
|
|
|
result.put("calc", calcHours);
|
|
|
result.put("stopRecord", stopRecord);
|
|
|
+ result.put("alarmRecord", alarmRecord);
|
|
|
result.put("panHead", panHeadInfo);
|
|
|
return new AsyncResult<>(result);
|
|
|
}
|
|
@@ -172,25 +141,23 @@ public class AsyncServiceImpl {
|
|
|
float[] last = new float[1];
|
|
|
//统计数据,后面2个分别代表0.织造米长 1.重量,2.电量,3.开机时间,4.停机时间
|
|
|
float[] total = new float[5];
|
|
|
- //告警数据统计
|
|
|
- boolean[] lastAlarms = new boolean[26];
|
|
|
//上一个时间点盘头数据
|
|
|
int[] lastPanHead = new int[5];
|
|
|
- //最后一个值为int型,需要单独计算
|
|
|
- int[] alarmsTimes = new int[27];
|
|
|
//米克重
|
|
|
int lastMkz = 0;
|
|
|
//卷曲幅宽
|
|
|
float lastFk = 0f;
|
|
|
int last48 = 0;
|
|
|
- int old48 = -1;
|
|
|
- Object d = CacheUtils.get(Constants.IOT_TOKEN, table);
|
|
|
- if (d != null) {
|
|
|
- //获取存储的最后一次停机状态值
|
|
|
- old48 = (int) d;
|
|
|
- }
|
|
|
+ //上一轮最后一条停机记录
|
|
|
+ JSONArray old = null;
|
|
|
+ //上一轮最后一条告警记录
|
|
|
+// Object oldV = CacheUtils.get(Constants.IOT_TOKEN, table + "-stop");
|
|
|
+// if (oldV != null) {
|
|
|
+// //获取存储的最后一次停机状态值
|
|
|
+// old = (JSONArray) oldV;
|
|
|
+// }
|
|
|
//告警时间记录
|
|
|
- List<Pair<String, Long>> alarmRecord = new ArrayList<>();
|
|
|
+ List<TwinRecordAlarms> alarmRecord = new ArrayList<>();
|
|
|
//停机记录
|
|
|
List<TwinRecordStop> stopRecord = new ArrayList<>();
|
|
|
//盘头记录
|
|
@@ -213,9 +180,6 @@ public class AsyncServiceImpl {
|
|
|
lastMkz = da.getInt(8);
|
|
|
lastFk = da.getFloat(9);
|
|
|
last48 = curr48;
|
|
|
- for (int j = 0; j < lastAlarms.length; j++) {
|
|
|
- lastAlarms[j] = da.getBool(12 + j);
|
|
|
- }
|
|
|
continue;
|
|
|
}
|
|
|
//计算电量
|
|
@@ -232,34 +196,29 @@ public class AsyncServiceImpl {
|
|
|
first[j] = curr[j];
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- calcAlarms(lastAlarms, da, timestamps, values, i, alarmsTimes, alarmRecord);
|
|
|
- System.err.println(new Date(timestamps.getLong(i)));
|
|
|
- calcStops(curr48, last48, timestamps.getLong(i), total, stopRecord, old48, i);
|
|
|
+ calcAlarms(values, old, timestamps.getLong(i), alarmRecord, i);
|
|
|
+ calcStops(curr48, last48, timestamps.getLong(i), total, stopRecord, old, i);
|
|
|
|
|
|
//复制数组,设置last值为当前值
|
|
|
last = curr.clone();
|
|
|
lastPanHead = currPan.clone();
|
|
|
lastMkz = da.getInt(8);
|
|
|
lastFk = da.getFloat(9);
|
|
|
- for (int j = 0; j < lastAlarms.length; j++) {
|
|
|
- lastAlarms[j] = da.getBool(12 + j);
|
|
|
- }
|
|
|
last48 = curr48;
|
|
|
}
|
|
|
//最后再补一次计算
|
|
|
for (int j = 0; j < first.length; j++) {
|
|
|
calcTotal(j, last, first, total, lastMkz, lastFk);
|
|
|
}
|
|
|
+
|
|
|
//存入最后一条记录的停机状态
|
|
|
- CacheUtils.put(Constants.IOT_TOKEN, table, last48);
|
|
|
+// CacheUtils.put(Constants.IOT_TOKEN, table, values.getJSONArray(values.size() - 1));
|
|
|
|
|
|
total[3] = 3600 - total[4];
|
|
|
|
|
|
Map<String, Object> result = new HashMap<>(16);
|
|
|
result.put("total", total);
|
|
|
result.put("stopRecord", stopRecord);
|
|
|
- result.put("alarms", alarmsTimes);
|
|
|
result.put("alarmRecord", alarmRecord);
|
|
|
result.put("panHead", panHeadInfo);
|
|
|
return result;
|
|
@@ -315,14 +274,30 @@ public class AsyncServiceImpl {
|
|
|
* @param time 时间
|
|
|
* @param total 统计
|
|
|
* @param stopRecord 记录
|
|
|
+ * @param oldV 上次的最后一条记录的值
|
|
|
+ * @param i 当前时序
|
|
|
*/
|
|
|
- private void calcStops(int curr, int last, long time, float[] total, List<TwinRecordStop> stopRecord, int old, int i) {
|
|
|
+ private void calcStops(int curr, int last, long time, float[] total, List<TwinRecordStop> stopRecord, JSONArray oldV, int i) {
|
|
|
+ //取消毫秒
|
|
|
+ time = time / 1000 * 1000;
|
|
|
TwinRecordStop stop = new TwinRecordStop();
|
|
|
-
|
|
|
//如果第一条记录为0,需要判断之前有木有没有结束时间的停机
|
|
|
- if (i == 1 && old != -1 && last != old) {
|
|
|
- stop.setStopType(old);
|
|
|
- stop.setEndTime(new Date(time));
|
|
|
+ //暂时取消这个判断
|
|
|
+// if (i == 1 && oldV != null) {
|
|
|
+// int old = oldV.getInt(7);
|
|
|
+// if (last != old) {
|
|
|
+// stop.setStopType(old);
|
|
|
+// stop.setEndTime(new Date(time));
|
|
|
+// stopRecord.add(stop);
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// }
|
|
|
+ //如果第一条记录不为0,则直接记录停机开始时间
|
|
|
+ if (i == 1 && curr != 0) {
|
|
|
+ stop = new TwinRecordStop();
|
|
|
+ //记录停机开始时间
|
|
|
+ stop.setStopType(curr);
|
|
|
+ stop.setStartTime(new Date(time));
|
|
|
stopRecord.add(stop);
|
|
|
return;
|
|
|
}
|
|
@@ -350,55 +325,112 @@ public class AsyncServiceImpl {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 告警次数计算
|
|
|
+ * 告警计算
|
|
|
+ *
|
|
|
+ * @param values 所有记录
|
|
|
+ * @param old 上次存储的
|
|
|
+ * @param time 当前时间
|
|
|
+ * @param alarmRecord 告警记录
|
|
|
+ * @param i 时序
|
|
|
*/
|
|
|
- private void calcAlarms(boolean[] lastAlarms, JSONArray da, JSONArray timestamps, JSONArray values, int i,
|
|
|
- int[] alarmsTimes, List<Pair<String, Long>> alarmRecord) {
|
|
|
- int endNum = timestamps.size();
|
|
|
- if (i + 9 < timestamps.size()) {
|
|
|
- endNum = i + 9;
|
|
|
+ private void calcAlarms(JSONArray values, JSONArray old, long time, List<TwinRecordAlarms> alarmRecord, int i) {
|
|
|
+ JSONArray curr = values.getJSONArray(i);
|
|
|
+ JSONArray last = values.getJSONArray(i - 1);
|
|
|
+ TwinRecordAlarms recordAlarms;
|
|
|
+ int index = 26;
|
|
|
+ /*暂时取消
|
|
|
+ // if (i == 1 && old != null) {
|
|
|
+ // //判断第一条记录为0,并且上一轮存储的值,需要判断之前有没有未结束的告警
|
|
|
+ // int j = 0;
|
|
|
+ // for (; j < index; j++) {
|
|
|
+ // boolean oldV = curr.getBool(j + 12);
|
|
|
+ // boolean lastV = last.getBool(j + 12);
|
|
|
+ // if (oldV && !lastV) {
|
|
|
+ // recordAlarms = new TwinRecordAlarms();
|
|
|
+ // recordAlarms.setAlarmType(j + 1);
|
|
|
+ // recordAlarms.setEndTime(new Date(time));
|
|
|
+ // alarmRecord.add(recordAlarms);
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // //需要单独计算alarm27
|
|
|
+ // //数据位置
|
|
|
+ // int pos = j + 12;
|
|
|
+ // int old27 = curr.getInt(pos);
|
|
|
+ // //上面已经处理过i=0,所以这里i不可能等于0
|
|
|
+ // int last27 = last.getInt(pos);
|
|
|
+ // if (old27 != 0 && last27 == 0) {
|
|
|
+ // recordAlarms = new TwinRecordAlarms();
|
|
|
+ // recordAlarms.setAlarmType(j + 1);
|
|
|
+ // recordAlarms.setEndTime(new Date(time));
|
|
|
+ // alarmRecord.add(recordAlarms);
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ */
|
|
|
+ boolean[] flags = new boolean[index + 1];
|
|
|
+ for (int kk = 0; i < flags.length; i++) {
|
|
|
+ flags[kk] = true;
|
|
|
+ }
|
|
|
+ if (i == 1) {
|
|
|
+ int j = 0;
|
|
|
+ for (; j < index; j++) {
|
|
|
+ boolean currV = curr.getBool(j + 12);
|
|
|
+ if (currV) {
|
|
|
+ flags[j] = false;
|
|
|
+ recordAlarms = new TwinRecordAlarms();
|
|
|
+ recordAlarms.setAlarmType(j + 1);
|
|
|
+ recordAlarms.setStartTime(new Date(time));
|
|
|
+ alarmRecord.add(recordAlarms);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //需要单独计算alarm27
|
|
|
+ //数据位置
|
|
|
+ int pos = j + 12;
|
|
|
+ int curr27 = curr.getInt(pos);
|
|
|
+ if (curr27 != 0) {
|
|
|
+ flags[j] = false;
|
|
|
+ recordAlarms = new TwinRecordAlarms();
|
|
|
+ recordAlarms.setAlarmType(j + 1);
|
|
|
+ recordAlarms.setStartTime(new Date(time));
|
|
|
+ alarmRecord.add(recordAlarms);
|
|
|
+ }
|
|
|
}
|
|
|
int j = 0;
|
|
|
- for (; j < lastAlarms.length; j++) {
|
|
|
- boolean currV = da.getBool(j + 12);
|
|
|
- if (currV && !lastAlarms[j]) {
|
|
|
- //如果当前值为true,上一条为false 则记录一次告警(并且后面连续多次为TRUE)
|
|
|
- boolean numFlag = true;
|
|
|
- for (int k = i + 1; k < endNum; k++) {
|
|
|
- JSONArray nextData = values.getJSONArray(k);
|
|
|
- boolean nextV = nextData.getBool(j + 12);
|
|
|
- if (!nextV) {
|
|
|
- numFlag = false;
|
|
|
- break;
|
|
|
- }
|
|
|
+ for (; j < index; j++) {
|
|
|
+ if (flags[j]) {
|
|
|
+ boolean currV = curr.getBool(j + 12);
|
|
|
+ boolean lastV = last.getBool(j + 12);
|
|
|
+ if (currV && !lastV) {
|
|
|
+ recordAlarms = new TwinRecordAlarms();
|
|
|
+ recordAlarms.setAlarmType(j + 1);
|
|
|
+ recordAlarms.setStartTime(new Date(time));
|
|
|
+ alarmRecord.add(recordAlarms);
|
|
|
}
|
|
|
- if (numFlag) {
|
|
|
- alarmRecord.add(new Pair<>("alarm" + (j + 1), timestamps.getLong(i)));
|
|
|
- alarmsTimes[j] += 1;
|
|
|
+ if (!currV && lastV) {
|
|
|
+ recordAlarms = new TwinRecordAlarms();
|
|
|
+ recordAlarms.setAlarmType(j + 1);
|
|
|
+ recordAlarms.setEndTime(new Date(time));
|
|
|
+ alarmRecord.add(recordAlarms);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- //需要单独计算alarm27
|
|
|
- //数据位置
|
|
|
- int pos = j + 12;
|
|
|
- int alarm27 = da.getInt(pos);
|
|
|
- //上面已经处理过i=0,所以这里i不可能等于0
|
|
|
- JSONArray last = values.getJSONArray(i - 1);
|
|
|
- int last27 = last.getInt(pos);
|
|
|
- if (alarm27 != 0 && last27 == 0) {
|
|
|
- //当前值不为0,上一条为0,则记录一次告警(并且后面连续多次为该值)
|
|
|
- boolean numFlag = true;
|
|
|
- for (int k = i + 1; k < endNum; k++) {
|
|
|
- JSONArray nextData = values.getJSONArray(k);
|
|
|
- int nextV = nextData.getInt(j + 12);
|
|
|
- if (alarm27 != nextV) {
|
|
|
- numFlag = false;
|
|
|
- break;
|
|
|
- }
|
|
|
+ if (flags[j]) {
|
|
|
+ //需要单独计算alarm27
|
|
|
+ //数据位置
|
|
|
+ int pos = j + 12;
|
|
|
+ int alarm27 = curr.getInt(pos);
|
|
|
+ //上面已经处理过i=0,所以这里i不可能等于0
|
|
|
+ int last27 = last.getInt(pos);
|
|
|
+ if (alarm27 != 0 && last27 == 0) {
|
|
|
+ recordAlarms = new TwinRecordAlarms();
|
|
|
+ recordAlarms.setAlarmType(j + 1);
|
|
|
+ recordAlarms.setStartTime(new Date(time));
|
|
|
+ alarmRecord.add(recordAlarms);
|
|
|
}
|
|
|
- if (numFlag) {
|
|
|
- alarmRecord.add(new Pair<>("alarm" + (j + 1), timestamps.getLong(i)));
|
|
|
- alarmsTimes[j] += 1;
|
|
|
+ if (alarm27 == 0 && last27 != 0) {
|
|
|
+ recordAlarms = new TwinRecordAlarms();
|
|
|
+ recordAlarms.setAlarmType(j + 1);
|
|
|
+ recordAlarms.setEndTime(new Date(time));
|
|
|
+ alarmRecord.add(recordAlarms);
|
|
|
}
|
|
|
}
|
|
|
}
|