diff --git a/src/main/java/com/qniao/iot/IotMonitoringDataJob.java b/src/main/java/com/qniao/iot/IotMonitoringDataJob.java index e86e355..bfa36a2 100644 --- a/src/main/java/com/qniao/iot/IotMonitoringDataJob.java +++ b/src/main/java/com/qniao/iot/IotMonitoringDataJob.java @@ -2,6 +2,7 @@ package com.qniao.iot; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.StrUtil; import cn.hutool.db.Db; import cn.hutool.http.HttpUtil; import cn.hutool.json.JSONArray; @@ -168,6 +169,10 @@ public class IotMonitoringDataJob { lastWorkingStatState.update(machineWorkingStat); lastPwStatState.update(machinePwrStat); Long reportTime = receivedEvent.getReportTime(); + String reportTimeStr = StrUtil.toString(reportTime); + if(reportTimeStr.length() == 10) { + reportTime = reportTime * 1000; + } // 1树根 0机智云 Integer dataSource = receivedEvent.getDataSource(); // 当前数据 @@ -201,15 +206,21 @@ public class IotMonitoringDataJob { if (lastWorkingStat == 1) { // 如果上次是工作中,那就进行累加 if (lastReportTime != null) { - nowDeviceState.setTheDayDuration(lastedDeviceState.getTheDayDuration() + workingDuration); + /*nowDeviceState.setTheDayDuration(lastedDeviceState.getTheDayDuration() + workingDuration); nowDeviceState.setTheDayJobDuration(lastedDeviceState.getTheDayJobDuration() + workingDuration); - nowDeviceState.setJobDurationTotal(lastedDeviceState.getJobDurationTotal() + workingDuration); + nowDeviceState.setJobDurationTotal(lastedDeviceState.getJobDurationTotal() + workingDuration);*/ if (dataSource == 1) { // 树根 + nowDeviceState.setTheDayDuration(lastedDeviceState.getTheDayDuration() + workingDuration); + nowDeviceState.setTheDayJobDuration(lastedDeviceState.getTheDayJobDuration() + workingDuration); + nowDeviceState.setJobDurationTotal(lastedDeviceState.getJobDurationTotal() + workingDuration); nowDeviceState.setTheDayJobCount(onData.getTheDayJobCount() + receivedEvent.getCurrJobCount()); nowDeviceState.setJobTotal(onData.getJobTotal() + receivedEvent.getCurrJobCount()); } else { // 机智云 + nowDeviceState.setTheDayDuration(lastedDeviceState.getTheDayDuration() + receivedEvent.getCurrJobDuration()); + nowDeviceState.setTheDayJobDuration(lastedDeviceState.getTheDayJobDuration() + receivedEvent.getCurrJobDuration()); + nowDeviceState.setJobDurationTotal(lastedDeviceState.getJobDurationTotal() + receivedEvent.getCurrJobDuration()); nowDeviceState.setTheDayJobCount(lastedDeviceState.getTheDayJobCount() + receivedEvent.getCurrJobCount()); nowDeviceState.setJobTotal(lastedDeviceState.getJobTotal() + receivedEvent.getCurrJobCount()); } @@ -226,6 +237,7 @@ public class IotMonitoringDataJob { deviceTotalDataStat.update(nowDeviceState); } else { if (machineWorkingStat.equals(1)) { + // 工作 if (dataSource == 1) { // 树根(今日当前数 + 这次信息点距离上次信息点生产的数量) nowDeviceState.setTheDayJobCount(onData.getTheDayJobCount() + receivedEvent.getCurrJobCount()); @@ -241,6 +253,7 @@ public class IotMonitoringDataJob { nowDeviceState.setJobDurationTotal(lastedDeviceState.getJobDurationTotal() + workingDuration); nowDeviceState.setReportTime(reportTime); } else { + // 待机或开机 nowDeviceState = lastedDeviceState; } deviceTotalDataStat.update(nowDeviceState); diff --git a/src/test/java/Demo2.java b/src/test/java/Demo2.java index e7f2ac2..22243d9 100644 --- a/src/test/java/Demo2.java +++ b/src/test/java/Demo2.java @@ -1,3 +1,4 @@ +import cn.hutool.core.util.StrUtil; import cn.hutool.http.HttpUtil; import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; @@ -16,8 +17,13 @@ public class Demo2 { System.out.println(data);*/ - LocalDate reportDate = new java.util.Date(1660531324418L) + /*LocalDate reportDate = new java.util.Date(1660531324418L) .toInstant().atOffset(ZoneOffset.of("+8")).toLocalDate(); - System.out.println(reportDate); + System.out.println(reportDate);*/ + + + Long a = 1660570366L; + System.out.println(StrUtil.toString(a).length()); + System.out.println(a * 1000); } }