|
@@ -10,6 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.text.DecimalFormat;
|
|
|
+import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.util.ArrayList;
|
|
@@ -120,6 +121,57 @@ public class LampInfoLogServiceImpl implements LampInfoLogService {
|
|
|
return lampLogVO;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public LampLogVO getMonthLightTimeLogList(Integer lampId) {
|
|
|
+ LampInfoLogDTO beforeLog = lampInfoLogDao.getBeforeMonthLampInfoLog(lampId);
|
|
|
+ List<LampInfoLogDTO> logList = lampInfoLogDao.getMonthLampInfoLogList(lampId);
|
|
|
+
|
|
|
+ // 按时间分组,取每一天的最后一笔记录
|
|
|
+ Map<LocalDate, LampInfoLogDTO> logs = logList.stream()
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ log -> parseLocalDate(log.getUpdateTime(), "yyyy-MM-dd HH:mm:ss"),
|
|
|
+ log -> log,
|
|
|
+ (existing, replacement) -> existing.getUpdateTime().compareTo(replacement.getUpdateTime()) > 0 ? existing : replacement
|
|
|
+ ));
|
|
|
+
|
|
|
+ // 初始化 dataList 和 dateList
|
|
|
+ List<Object> dataList = new ArrayList<>();
|
|
|
+ List<Object> dateList = new ArrayList<>();
|
|
|
+
|
|
|
+ String endDate = ToolUtils.getNowDate();
|
|
|
+ String startDate = ToolUtils.getNowDate(System.currentTimeMillis() - 29L * 24 * 3600 * 1000);
|
|
|
+ LocalDate first = parseLocalDate(startDate, "yyyy-MM-dd");
|
|
|
+ LocalDate end = parseLocalDate(endDate, "yyyy-MM-dd");
|
|
|
+
|
|
|
+
|
|
|
+ Integer lightTime = beforeLog == null ? 0 : beforeLog.getWorkTimeTotal();
|
|
|
+ DecimalFormat df = new DecimalFormat("0.##");
|
|
|
+ for (LocalDate date = first; !date.isAfter(end); date = date.plusDays(1)) {
|
|
|
+ LampInfoLogDTO current = logs.get(date);
|
|
|
+
|
|
|
+ if (current != null) {
|
|
|
+ int value = current.getWorkTimeTotal() - lightTime;
|
|
|
+ if (value < 0) value = current.getWorkTimeTotal();
|
|
|
+ dataList.add(df.format(value / 60.0));
|
|
|
+ lightTime = current.getWorkTimeTotal();
|
|
|
+ } else {
|
|
|
+ dataList.add("0");
|
|
|
+ }
|
|
|
+ String timeStr = date.toString();
|
|
|
+ dateList.add(timeStr);
|
|
|
+ }
|
|
|
+
|
|
|
+ LampLogVO lampLogVO = new LampLogVO();
|
|
|
+ lampLogVO.setDateList(dateList);
|
|
|
+ lampLogVO.setDataList(dataList);
|
|
|
+ return lampLogVO;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static LocalDate parseLocalDate(String dateStr, String format) {
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern(format);
|
|
|
+ return LocalDate.parse(dateStr, formatter);
|
|
|
+ }
|
|
|
+
|
|
|
private static LocalDateTime parseLocalDateTime(String dateStr) {
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
return LocalDateTime.parse(dateStr, formatter).withMinute(0).withSecond(0);
|