|
@@ -4,6 +4,7 @@ import cn.hutool.json.JSONArray;
|
|
|
import cn.hutool.json.JSONObject;
|
|
|
import com.ruoyi.biz.domain.TwinCalc2hr;
|
|
|
import com.ruoyi.biz.domain.TwinDevice;
|
|
|
+import com.ruoyi.biz.domain.TwinPanHeadInfo;
|
|
|
import com.ruoyi.biz.domain.TwinRecordAlarms;
|
|
|
import com.ruoyi.biz.service.IIotService;
|
|
|
import javafx.util.Pair;
|
|
@@ -104,6 +105,7 @@ public class AsyncServiceImpl {
|
|
|
|
|
|
calc2hrList.add(calc2hr);
|
|
|
List<Pair<String, Long>> alarmRecord = (List<Pair<String, Long>>) map.get("alarmRecord");
|
|
|
+
|
|
|
String strStop = "stop";
|
|
|
String strAlarm = "alarm";
|
|
|
alarmRecord.forEach(pair -> {
|
|
@@ -121,8 +123,13 @@ public class AsyncServiceImpl {
|
|
|
recordAlarmsList.add(recordAlarms);
|
|
|
});
|
|
|
|
|
|
+ List<TwinPanHeadInfo> panHeadInfo = (List<TwinPanHeadInfo>) map.get("panHead");
|
|
|
+ panHeadInfo.forEach(info -> info.setDeviceId(twinDevice.getId()));
|
|
|
+
|
|
|
+
|
|
|
result.put("calc", calc2hrList);
|
|
|
result.put("record", recordAlarmsList);
|
|
|
+ result.put("panHead", panHeadInfo);
|
|
|
return new AsyncResult<>(result);
|
|
|
}
|
|
|
|
|
@@ -136,9 +143,11 @@ public class AsyncServiceImpl {
|
|
|
"Alarm_unit_9", "Alarm_unit_10", "Alarm_unit_11", "Alarm_unit_12", "Alarm_unit_13",
|
|
|
"Alarm_unit_14", "Alarm_unit_15", "Alarm_unit_16", "Alarm_unit_17", "Alarm_unit_18",
|
|
|
"Alarm_unit_19", "Alarm_unit_20", "Alarm_unit_21", "Alarm_unit_22", "Alarm_unit_23",
|
|
|
- "Alarm_unit_24", "Alarm_unit_25", "Alarm_unit_26", "Alarm_unit_27", "Capacity_data_33"
|
|
|
+ "Alarm_unit_24", "Alarm_unit_25", "Alarm_unit_26", "Alarm_unit_27", "Capacity_data_33",
|
|
|
+ "Capacity_data_15", "Capacity_data_16", "Capacity_data_17", "Capacity_data_18", "Capacity_data_19"
|
|
|
};
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* 字段列表,方便查找位置
|
|
|
*/
|
|
@@ -160,8 +169,10 @@ public class AsyncServiceImpl {
|
|
|
public Map<String, Object> calc(String table, long startTime, long endTime) {
|
|
|
String sql = "select %s from %s where time>%s and time <=%s";
|
|
|
sql = String.format(sql, Arrays.stream(fields).collect(Collectors.joining(",")), table, startTime, endTime);
|
|
|
+ long s = System.currentTimeMillis();
|
|
|
JSONObject jsonObject = iotService.query(sql);
|
|
|
-
|
|
|
+ long e = System.currentTimeMillis();
|
|
|
+ log.info("接口耗时:{}ms,table:{},time:{}", e - s, table, new Date(endTime));
|
|
|
JSONObject data = jsonObject.getJSONObject("data");
|
|
|
JSONArray values = data.getJSONArray("values");
|
|
|
JSONArray timestamps = data.getJSONArray("timestamps");
|
|
@@ -174,6 +185,8 @@ public class AsyncServiceImpl {
|
|
|
float[] total = new float[12];
|
|
|
//告警数据统计
|
|
|
boolean[] lastAlarms = new boolean[26];
|
|
|
+ //上一个时间点盘头数据
|
|
|
+ int[] lastPanHead = new int[5];
|
|
|
//最后一个值为int型,需要单独计算
|
|
|
int[] alarmsTimes = new int[27];
|
|
|
//米克重
|
|
@@ -189,18 +202,23 @@ public class AsyncServiceImpl {
|
|
|
}
|
|
|
//停机和告警时间记录
|
|
|
List<Pair<String, Long>> alarmRecord = new ArrayList<>();
|
|
|
+ //盘头记录
|
|
|
+ List<TwinPanHeadInfo> panHeadInfo = new ArrayList<>();
|
|
|
|
|
|
for (int i = 0; i < timestamps.size(); i++) {
|
|
|
JSONArray da = values.getJSONArray(i);
|
|
|
//0-data2,1-data37,2-data38,3-data39,4-data42,5-data-43,6data-44
|
|
|
//当前时间数据
|
|
|
float[] curr = {da.getFloat(0), da.getFloat(1), da.getFloat(2), da.getFloat(3), da.getFloat(4), da.getFloat(5), da.getFloat(6)};
|
|
|
+ int[] currPan = {da.getInt(fieldList.indexOf("Capacity_data_15")), da.getInt(fieldList.indexOf("Capacity_data_16")), da.getInt(fieldList.indexOf("Capacity_data_17")),
|
|
|
+ da.getInt(fieldList.indexOf("Capacity_data_18")), da.getInt(fieldList.indexOf("Capacity_data_19"))};
|
|
|
int curr48 = da.getInt(7);
|
|
|
|
|
|
if (i == 0) {
|
|
|
//第一次数据是上次最后一条,只做记录用,不做处理
|
|
|
first = curr.clone();
|
|
|
last = curr.clone();
|
|
|
+ lastPanHead = currPan.clone();
|
|
|
lastMkz = da.getInt(8);
|
|
|
lastFk = da.getFloat(9);
|
|
|
last48 = curr48;
|
|
@@ -209,8 +227,10 @@ public class AsyncServiceImpl {
|
|
|
}
|
|
|
continue;
|
|
|
}
|
|
|
-
|
|
|
+ //计算电量
|
|
|
calcKwh(da, total);
|
|
|
+ //计算盘头
|
|
|
+ calcPan(currPan, lastPanHead, panHeadInfo, timestamps.getLong(i));
|
|
|
|
|
|
for (int j = 0; j < first.length; j++) {
|
|
|
//如果当前值为小于上一个,且上一个值不为0,则计算
|
|
@@ -255,6 +275,7 @@ public class AsyncServiceImpl {
|
|
|
|
|
|
//复制数组,设置last值为当前值
|
|
|
last = curr.clone();
|
|
|
+ lastPanHead = currPan.clone();
|
|
|
lastMkz = da.getInt(8);
|
|
|
lastFk = da.getFloat(9);
|
|
|
for (int j = 0; j < lastAlarms.length; j++) {
|
|
@@ -272,10 +293,33 @@ public class AsyncServiceImpl {
|
|
|
result.put("stop", stopMap);
|
|
|
result.put("alarms", alarmsTimes);
|
|
|
result.put("alarmRecord", alarmRecord);
|
|
|
+ result.put("panHead", panHeadInfo);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 计算盘头信息
|
|
|
+ * 数组 分别是GB1-GB5
|
|
|
+ *
|
|
|
+ * @param currPan 当前剩余圈数
|
|
|
+ * @param lastPanHead 上一条记录剩余圈数
|
|
|
+ * @param panHeadInfo info
|
|
|
+ * @param time 时间戳
|
|
|
+ */
|
|
|
+ private void calcPan(int[] currPan, int[] lastPanHead, List<TwinPanHeadInfo> panHeadInfo, Long time) {
|
|
|
+ //如果当前记录大于上一条记录,则证明是重新叫料了,需要记录下当前值
|
|
|
+ for (int i = 0; i < currPan.length; i++) {
|
|
|
+ if (currPan[i] > lastPanHead[i]) {
|
|
|
+ TwinPanHeadInfo info = new TwinPanHeadInfo();
|
|
|
+ info.setRecordTime(new Date(time));
|
|
|
+ info.setPhNum((long) (i + 1));
|
|
|
+ info.setPhMax((long) currPan[i]);
|
|
|
+ panHeadInfo.add(info);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 能耗计算
|
|
|
* total[9].总电量 total[10].A班电量 total[11].B班电量
|
|
|
*
|