Commit e5aa7b7a by huangjy

fix:日报周报获取数据问题

parent 8029e14d
......@@ -22,6 +22,7 @@ import com.makeit.utils.LongTimestampUtil;
import com.makeit.utils.data.convert.JsonUtil;
import com.makeit.utils.data.convert.StreamUtil;
import com.makeit.utils.old.StringUtils;
import com.makeit.utils.time.LocalDateTimeUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.RandomUtils;
......@@ -31,6 +32,7 @@ import org.springframework.stereotype.Component;
import java.io.IOException;
import java.time.*;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
......@@ -178,21 +180,39 @@ public class IotProductDeviceService extends IotCommonService {
}
public List<String> getLastDayHourRange(LocalDateTime startDateTime) {
int count = 24;
public List<String> getLastDayHourRange(LocalDateTime startDateTime,long count) {
List<String> list = Lists.newArrayList();
String startTime;
String endTime;
for (int i = count; i > 0; i--) {
startTime = DateUtil.format(startDateTime.minusHours(i), DatePattern.NORM_DATETIME_PATTERN);
endTime = DateUtil.format(startDateTime.minusHours(i - 1), DatePattern.NORM_DATETIME_PATTERN);
for (int i = 1; i <= count; i++) {
startTime = DateUtil.format(startDateTime.plusHours(i - 1), DatePattern.NORM_DATETIME_PATTERN);
endTime = DateUtil.format(startDateTime.plusHours(i), DatePattern.NORM_DATETIME_PATTERN);
list.add(startTime + "~" + endTime);
}
return list;
}
public static void main(String[] args) {
LocalDate now = LocalDate.now();
LocalDateTime start = dayStartNow(now);
LocalDateTime end = dayEndNow(now);
long daysBetween = ChronoUnit.DAYS.between(start, end);
IotProductDeviceService iotProductDeviceService = new IotProductDeviceService();
List<String> lastDayHourRange = iotProductDeviceService.getLastDayHourRange(start,24);
System.out.println(lastDayHourRange);
}
private static LocalDateTime dayStartNow(LocalDate now) {
return LocalDateTimeUtils.getDayStart(now);
}
private static LocalDateTime dayEndNow(LocalDate now) {
return LocalDateTimeUtils.getDayEnd(now);
}
public List<DeviceInfoContentBreathe> getDeviceLogByTimeRangeBreathe(String deviceId, int pageSize, LocalDateTime startTime, LocalDateTime endTime) {
List<String> lastDayHourRange = getLastDayHourRange(startTime);
long daysBetween = ChronoUnit.DAYS.between(startTime, endTime);
List<String> lastDayHourRange = getLastDayHourRange(startTime,daysBetween > 1 ? 24 * daysBetween: 24);
List<DeviceInfoContentBreathe> tempList = Lists.newArrayList();
for (String hour : lastDayHourRange) {
String[] hourRangeArray = hour.split("~");
......@@ -261,24 +281,14 @@ public class IotProductDeviceService extends IotCommonService {
return breatheList;*/
}
public static void main(String[] args) {
LocalDateTime localDateTime = LocalDateTime.now();
long timeStamp = localDateTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
System.out.println(timeStamp);
long timestamp = localDateTime.toInstant(ZoneOffset.of("+8")).toEpochMilli();
System.out.println("LocalDateTime to Timestamp: " + timestamp);
}
public static String formatLongTime(long time) {
return DEFAULT_FORMATTER.format(LocalDateTime.ofInstant(Instant.ofEpochMilli(time), ZoneId.systemDefault()));
}
public List<DeviceInfoContentSpace> getDeviceLogByTimeRangeSpace(String deviceId, int pageSize, LocalDateTime startTime, LocalDateTime endTime) {
List<DeviceInfoContentSpace> deviceInfoContentSpaceList = Lists.newArrayList();
List<String> lastDayHourRange = getLastDayHourRange(startTime);
long daysBetween = ChronoUnit.DAYS.between(startTime, endTime);
List<String> lastDayHourRange = getLastDayHourRange(startTime,daysBetween > 1 ? 24 * daysBetween: 24);
for (String hourRange : lastDayHourRange) {
String[] hourRangeArray = hourRange.split("~");
List<DeviceOperationLogEntity> deviceOperationLogList = getDeviceLogByTimeRange(deviceId, REPORT_PROPERTY, 5000, hourRangeArray[0], hourRangeArray[1]);
......@@ -291,7 +301,8 @@ public class IotProductDeviceService extends IotCommonService {
public List<DeviceInfoContentFall> getDeviceLogByTimeRangeFall(String deviceId, int pageSize, LocalDateTime startTime, LocalDateTime endTime) {
List<DeviceInfoContentFall> deviceInfoContentFallList = Lists.newArrayList();
List<String> lastDayHourRange = getLastDayHourRange(startTime);
long daysBetween = ChronoUnit.DAYS.between(startTime, endTime);
List<String> lastDayHourRange = getLastDayHourRange(startTime,daysBetween > 1 ? 24 * daysBetween: 24);
for (String hourRange : lastDayHourRange) {
String[] hourRangeArray = hourRange.split("~");
List<DeviceOperationLogEntity> deviceOperationLogList = getDeviceLogByTimeRange(deviceId, REPORT_PROPERTY, 5000, hourRangeArray[0], hourRangeArray[1]);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment