|
@@ -9,6 +9,7 @@ import com.influxdb.client.QueryApi;
|
|
|
import com.influxdb.query.FluxTable;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.Assert;
|
|
|
+import vip.xiaonuo.coldchain.core.alarm.enums.SensorAlarmType;
|
|
|
import vip.xiaonuo.coldchain.core.alarm.service.SensorAlarmService;
|
|
|
import vip.xiaonuo.coldchain.core.bean.influxdb.SensorData;
|
|
|
import vip.xiaonuo.coldchain.core.config.JfcloudColdChainConstants;
|
|
@@ -265,17 +266,35 @@ public class JfcloudSensorDataService extends JfcloudFluxDataService<SensorData>
|
|
|
LocalDate lastDayOfLastMonth = LocalDate.now().minusMonths(1).withDayOfMonth(1).plusMonths(1).minusDays(1);
|
|
|
return lastDayOfLastMonth.format(DateTimeFormatter.ISO_DATE) + "T23:59:59Z";
|
|
|
}
|
|
|
+ public long getAlarmCount(String sensorCode, String sensorRoute, SensorAlarmType alarmType, boolean isLastMonth) {
|
|
|
+ // 获取上个月或本月的起始时间和结束时间
|
|
|
+ String startDate;
|
|
|
+ String endDate;
|
|
|
+ if (isLastMonth) {
|
|
|
+ startDate = getFirstDayOfLastMonth();
|
|
|
+ endDate = getLastDayOfLastMonth();
|
|
|
+ } else {
|
|
|
+ startDate = getFirstDayOfCurrentMonth();
|
|
|
+ endDate = getLastDayOfCurrentMonth();
|
|
|
+ }
|
|
|
+ // 根据提供的报警类型计算报警数量
|
|
|
+ return sensorAlarmService.countAlarms(startDate, endDate, sensorCode, sensorRoute, alarmType);
|
|
|
+ }
|
|
|
|
|
|
public long getLastMonthAlarmCount(String sensorCode, String sensorRoute) {
|
|
|
- // 获取上个月的起始时间和结束时间
|
|
|
- String startDate = getFirstDayOfLastMonth();
|
|
|
- String endDate = getLastDayOfLastMonth();
|
|
|
- return sensorAlarmService.countAlarms(startDate, endDate, sensorCode, sensorRoute);
|
|
|
+ return getAlarmCount(sensorCode, sensorRoute, SensorAlarmType.DATA_ALARM, true);
|
|
|
}
|
|
|
|
|
|
public long getCurrentMonthAlarmCount(String sensorCode, String sensorRoute) {
|
|
|
- String startDate = getFirstDayOfCurrentMonth();
|
|
|
- String endDate = getLastDayOfCurrentMonth();
|
|
|
- return sensorAlarmService.countAlarms(startDate, endDate, sensorCode, sensorRoute);
|
|
|
+ return getAlarmCount(sensorCode, sensorRoute, SensorAlarmType.DATA_ALARM, false);
|
|
|
+ }
|
|
|
+
|
|
|
+ public long getCurrentMonthOfflineCount(String sensorCode, String sensorRoute) {
|
|
|
+ return getAlarmCount(sensorCode, sensorRoute, SensorAlarmType.SENSOR_OFFLINE, false);
|
|
|
}
|
|
|
+
|
|
|
+ public long getLastMonthOfflineCount(String sensorCode, String sensorRoute) {
|
|
|
+ return getAlarmCount(sensorCode, sensorRoute, SensorAlarmType.SENSOR_OFFLINE, true);
|
|
|
+ }
|
|
|
+
|
|
|
}
|