|
@@ -11,6 +11,9 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
|
|
+import java.time.LocalDate;
|
|
|
|
+import java.time.YearMonth;
|
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -51,6 +54,9 @@ public class HistoryLoopHealthLevelController {
|
|
public String query(@RequestBody JSONObject request) throws Exception {
|
|
public String query(@RequestBody JSONObject request) throws Exception {
|
|
log.info("调用query接口:{}", JSON.toJSONString(request));
|
|
log.info("调用query接口:{}", JSON.toJSONString(request));
|
|
|
|
|
|
|
|
+ DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM");
|
|
|
|
+ DateTimeFormatter dateFormatterDay = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
|
+
|
|
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
|
|
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
|
|
SimpleDateFormat formatMonth = new SimpleDateFormat("yyyy-MM");
|
|
SimpleDateFormat formatMonth = new SimpleDateFormat("yyyy-MM");
|
|
|
|
|
|
@@ -87,8 +93,108 @@ public class HistoryLoopHealthLevelController {
|
|
beginDate = formatMonth.format(beginDated);
|
|
beginDate = formatMonth.format(beginDated);
|
|
endDate = formatMonth.format(endDated);
|
|
endDate = formatMonth.format(endDated);
|
|
loopHealthLevelMap = dashboardService.getLoopHealthLevelsMonth(deviceName, sysName, beginDate,endDate);
|
|
loopHealthLevelMap = dashboardService.getLoopHealthLevelsMonth(deviceName, sysName, beginDate,endDate);
|
|
|
|
+ if (loopHealthLevelMap.size() == 0){
|
|
|
|
+ YearMonth startMonth = YearMonth.parse(beginDate, dateFormatter);
|
|
|
|
+ YearMonth endMonth = YearMonth.parse(endDate, dateFormatter);
|
|
|
|
+ YearMonth currentYearMonth = startMonth.plusMonths(1);
|
|
|
|
+
|
|
|
|
+ ArrayList<LoopHealthLevel> aList = new ArrayList<>();
|
|
|
|
+ ArrayList<LoopHealthLevel> bList = new ArrayList<>();
|
|
|
|
+ ArrayList<LoopHealthLevel> cList = new ArrayList<>();
|
|
|
|
+ ArrayList<LoopHealthLevel> dList = new ArrayList<>();
|
|
|
|
+ while (!currentYearMonth.isAfter(endMonth)){
|
|
|
|
+ LoopHealthLevel loopHealthLevelA = new LoopHealthLevel();
|
|
|
|
+ loopHealthLevelA.setLevel("A");
|
|
|
|
+ loopHealthLevelA.setNumber("0");
|
|
|
|
+ loopHealthLevelA.setTime(currentYearMonth.format(dateFormatter));
|
|
|
|
+ aList.add(loopHealthLevelA);
|
|
|
|
+
|
|
|
|
+ LoopHealthLevel loopHealthLevelB = new LoopHealthLevel();
|
|
|
|
+ loopHealthLevelB.setLevel("B");
|
|
|
|
+ loopHealthLevelB.setNumber("0");
|
|
|
|
+ loopHealthLevelB.setTime(currentYearMonth.format(dateFormatter));
|
|
|
|
+ bList.add(loopHealthLevelB);
|
|
|
|
+
|
|
|
|
+ LoopHealthLevel loopHealthLevelC = new LoopHealthLevel();
|
|
|
|
+ loopHealthLevelC.setLevel("C");
|
|
|
|
+ loopHealthLevelC.setNumber("0");
|
|
|
|
+ loopHealthLevelC.setTime(currentYearMonth.format(dateFormatter));
|
|
|
|
+ cList.add(loopHealthLevelC);
|
|
|
|
+
|
|
|
|
+ LoopHealthLevel loopHealthLevelD = new LoopHealthLevel();
|
|
|
|
+ loopHealthLevelD.setLevel("D");
|
|
|
|
+ loopHealthLevelD.setNumber("0");
|
|
|
|
+ loopHealthLevelD.setTime(currentYearMonth.format(dateFormatter));
|
|
|
|
+ dList.add(loopHealthLevelD);
|
|
|
|
+
|
|
|
|
+ currentYearMonth = currentYearMonth.plusMonths(1);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ loopHealthLevelMap.put("A",aList);
|
|
|
|
+ loopHealthLevelMap.put("B",bList);
|
|
|
|
+ loopHealthLevelMap.put("C",cList);
|
|
|
|
+ loopHealthLevelMap.put("D",dList);
|
|
|
|
+ }
|
|
}else {
|
|
}else {
|
|
loopHealthLevelMap = dashboardService.getLoopHealthLevels(deviceName, sysName, beginDate,endDate);
|
|
loopHealthLevelMap = dashboardService.getLoopHealthLevels(deviceName, sysName, beginDate,endDate);
|
|
|
|
+ if (loopHealthLevelMap.size() == 0){
|
|
|
|
+
|
|
|
|
+ ArrayList<LoopHealthLevel> aList = new ArrayList<>();
|
|
|
|
+ ArrayList<LoopHealthLevel> bList = new ArrayList<>();
|
|
|
|
+ ArrayList<LoopHealthLevel> cList = new ArrayList<>();
|
|
|
|
+ ArrayList<LoopHealthLevel> dList = new ArrayList<>();
|
|
|
|
+
|
|
|
|
+ // 解析为 LocalDate 对象
|
|
|
|
+ LocalDate start = LocalDate.parse(beginDate, dateFormatterDay);
|
|
|
|
+ LocalDate end = LocalDate.parse(endDate, dateFormatterDay);
|
|
|
|
+
|
|
|
|
+ // 获取输入日期的月份和年份
|
|
|
|
+ int year = end.getYear();
|
|
|
|
+ int month = end.getMonthValue();
|
|
|
|
+
|
|
|
|
+ // 创建该月份的开始和结束日期
|
|
|
|
+ LocalDate monthStart = LocalDate.of(year, month, 1);
|
|
|
|
+ LocalDate monthEnd = monthStart.withDayOfMonth(monthStart.lengthOfMonth());
|
|
|
|
+
|
|
|
|
+ // 如果 endDate 之后的月份,则将结束日期限制在该月的最后一天
|
|
|
|
+ if (end.isAfter(monthEnd)) {
|
|
|
|
+ end = monthEnd;
|
|
|
|
+ }
|
|
|
|
+ LocalDate currentDate = start;
|
|
|
|
+ while (!currentDate.isAfter(end)) {
|
|
|
|
+ if (!currentDate.isBefore(monthStart) && !currentDate.isAfter(monthEnd)) {
|
|
|
|
+ LoopHealthLevel loopHealthLevelA = new LoopHealthLevel();
|
|
|
|
+ loopHealthLevelA.setLevel("A");
|
|
|
|
+ loopHealthLevelA.setNumber("0");
|
|
|
|
+ loopHealthLevelA.setTime(currentDate.format(dateFormatterDay));
|
|
|
|
+ aList.add(loopHealthLevelA);
|
|
|
|
+
|
|
|
|
+ LoopHealthLevel loopHealthLevelB = new LoopHealthLevel();
|
|
|
|
+ loopHealthLevelB.setLevel("B");
|
|
|
|
+ loopHealthLevelB.setNumber("0");
|
|
|
|
+ loopHealthLevelB.setTime(currentDate.format(dateFormatterDay));
|
|
|
|
+ bList.add(loopHealthLevelB);
|
|
|
|
+
|
|
|
|
+ LoopHealthLevel loopHealthLevelC = new LoopHealthLevel();
|
|
|
|
+ loopHealthLevelC.setLevel("C");
|
|
|
|
+ loopHealthLevelC.setNumber("0");
|
|
|
|
+ loopHealthLevelC.setTime(currentDate.format(dateFormatterDay));
|
|
|
|
+ cList.add(loopHealthLevelC);
|
|
|
|
+
|
|
|
|
+ LoopHealthLevel loopHealthLevelD = new LoopHealthLevel();
|
|
|
|
+ loopHealthLevelD.setLevel("D");
|
|
|
|
+ loopHealthLevelD.setNumber("0");
|
|
|
|
+ loopHealthLevelD.setTime(currentDate.format(dateFormatterDay));
|
|
|
|
+ dList.add(loopHealthLevelD);
|
|
|
|
+ }
|
|
|
|
+ currentDate = currentDate.plusDays(1);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ loopHealthLevelMap.put("A",aList);
|
|
|
|
+ loopHealthLevelMap.put("B",bList);
|
|
|
|
+ loopHealthLevelMap.put("C",cList);
|
|
|
|
+ loopHealthLevelMap.put("D",dList);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
for (String key : loopHealthLevelMap.keySet()) {
|
|
for (String key : loopHealthLevelMap.keySet()) {
|