|
@@ -116,36 +116,29 @@ public class Tools {
|
|
|
* @param date 字符串格式的 yyyy-mm-dd
|
|
|
* @return list map
|
|
|
*/
|
|
|
- public static List<Map<String, Object>> timePeriod(String date) {
|
|
|
+ public static List<Pair<LocalDateTime, LocalDateTime>> timePeriod(String date) {
|
|
|
LocalDate localDate = LocalDate.parse(date);
|
|
|
return timePeriod(localDate);
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
- * 获取指定日期的时间分段
|
|
|
+ * 获取指定日期的时间分段 早上7点至第二天7点(不含)
|
|
|
* 每小时一条
|
|
|
*
|
|
|
* @param date LocalDate yyyy-mm-dd
|
|
|
* @return LocalDateTime map.get("start") map.get("end")
|
|
|
*/
|
|
|
- public static List<Map<String, Object>> timePeriod(LocalDate date) {
|
|
|
- List<Map<String, Object>> result = new ArrayList<>();
|
|
|
- //获取当天0点
|
|
|
+ public static List<Pair<LocalDateTime, LocalDateTime>> timePeriod(LocalDate date) {
|
|
|
+ List<Pair<LocalDateTime, LocalDateTime>> result = new ArrayList<>();
|
|
|
LocalDateTime ldt = LocalDateTime.of(date, LocalTime.MIN);
|
|
|
- LocalDateTime start = ldt;
|
|
|
- LocalDateTime end = start.plusHours(1);
|
|
|
- do {
|
|
|
- //-1秒 把上一轮最后一条数据取出来
|
|
|
- start = start.minusSeconds(1);
|
|
|
-
|
|
|
- Map<String, Object> map = new HashMap<>(16);
|
|
|
- map.put("start", start);
|
|
|
- map.put("end", end);
|
|
|
- result.add(map);
|
|
|
- start = end;
|
|
|
- end = start.plusHours(1);
|
|
|
- } while (!ldt.plusDays(1).isBefore(end));
|
|
|
+ LocalDateTime start = ldt.plusHours(7);
|
|
|
+ for (int i = 0; i < 24; i++) {
|
|
|
+ //需要减少1秒,取出上一轮最后一条数据
|
|
|
+ Pair<LocalDateTime, LocalDateTime> pair = new Pair<>(start.minusSeconds(1), start.plusHours(1));
|
|
|
+ result.add(pair);
|
|
|
+ start = start.plusHours(1);
|
|
|
+ }
|
|
|
return result;
|
|
|
}
|
|
|
|
|
@@ -154,23 +147,20 @@ public class Tools {
|
|
|
*
|
|
|
* @return LocalDateTime map.get("start") map.get("end")
|
|
|
*/
|
|
|
- public static List<Map<String, Object>> timePeriod() {
|
|
|
- List<Map<String, Object>> result = new ArrayList<>();
|
|
|
+ public static List<Pair<LocalDateTime, LocalDateTime>> timePeriod() {
|
|
|
+ List<Pair<LocalDateTime, LocalDateTime>> result = new ArrayList<>();
|
|
|
//获取当天0点
|
|
|
LocalDateTime ldt = LocalDateTime.now().withMinute(0).withSecond(0).withNano(0);
|
|
|
LocalDateTime start = ldt.withHour(0);
|
|
|
- LocalDateTime end = start.plusHours(2);
|
|
|
- LocalDateTime stop = ldt.minusHours(ldt.getHour() % 2);
|
|
|
+ LocalDateTime end = start.plusHours(1);
|
|
|
+ LocalDateTime stop = ldt.minusHours(1);
|
|
|
do {
|
|
|
//-1秒 把上一轮最后一条数据取出来
|
|
|
start = start.minusSeconds(1);
|
|
|
-
|
|
|
- Map<String, Object> map = new HashMap<>(16);
|
|
|
- map.put("start", start);
|
|
|
- map.put("end", end);
|
|
|
- result.add(map);
|
|
|
+ Pair<LocalDateTime, LocalDateTime> pair = new Pair<>(start, end);
|
|
|
+ result.add(pair);
|
|
|
start = end;
|
|
|
- end = start.plusHours(2);
|
|
|
+ end = start.plusHours(1);
|
|
|
} while (!end.isAfter(stop));
|
|
|
return result;
|
|
|
}
|
|
@@ -195,7 +185,26 @@ public class Tools {
|
|
|
public static Pair<Date, Date> calcDay(LocalDate localDate) {
|
|
|
LocalDateTime ldt = LocalDateTime.of(localDate, LocalTime.MIN);
|
|
|
LocalDateTime start = ldt.plusHours(7);
|
|
|
- LocalDateTime end = start.plusHours(23);
|
|
|
+ LocalDateTime end = start.plusHours(23).plusMinutes(59).plusSeconds(59);
|
|
|
+ Date sTime = Date.from(start.atZone(ZoneId.systemDefault()).toInstant());
|
|
|
+ Date eTime = Date.from(end.atZone(ZoneId.systemDefault()).toInstant());
|
|
|
+ return new Pair<>(sTime, eTime);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取统计时间 当天7天至结束时间(不含)
|
|
|
+ *
|
|
|
+ * @return 开始结束时间对
|
|
|
+ */
|
|
|
+ public static Pair<Date, Date> calcToday() {
|
|
|
+ LocalDateTime end = LocalDateTime.now();
|
|
|
+ LocalDate localDate = end.toLocalDate();
|
|
|
+ if (end.getHour() < 7) {
|
|
|
+ //如果小于7点,则表示生产时间是前一天
|
|
|
+ localDate = localDate.minusDays(1);
|
|
|
+ }
|
|
|
+ //生产时间从7点开始
|
|
|
+ LocalDateTime start = LocalDateTime.of(localDate, LocalTime.MIN).plusHours(7);
|
|
|
Date sTime = Date.from(start.atZone(ZoneId.systemDefault()).toInstant());
|
|
|
Date eTime = Date.from(end.atZone(ZoneId.systemDefault()).toInstant());
|
|
|
return new Pair<>(sTime, eTime);
|