Переглянути джерело

系统组件只需要top10

wukai 2 тижнів тому
батько
коміт
dd44721d85

+ 8 - 6
jjt-biz/src/main/java/com/jjt/biz/controller/AlarmRecordController.java

@@ -17,7 +17,6 @@ import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiParam;
 import org.springframework.jdbc.core.JdbcTemplate;
-import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
@@ -148,8 +147,9 @@ public class AlarmRecordController extends BaseController {
 //            BizSortVO vo = new BizSortVO(true);
 //            list.add(vo);
 //        }
-        list.sort(Comparator.comparing(BizSortVO::getNum));
-        return AjaxResult.success(list);
+        list.sort(Comparator.comparing(BizSortVO::getNum).reversed());
+        List<BizSortVO> top10List = list.stream().limit(10).sorted(Comparator.comparing(BizSortVO::getNum)).collect(Collectors.toList());
+        return AjaxResult.success(top10List);
     }
 
     @ApiOperation("系统压力排名")
@@ -343,17 +343,19 @@ public class AlarmRecordController extends BaseController {
         List<Map<String, Object>> errList = jdbcTemplate.queryForList(errSql, v.toArray());
         AtomicInteger index = new AtomicInteger();
         totList.forEach(map -> {
-            Map<String, Object> errMap = errList.get(index.get());
             Map<String, Object> data = new HashMap<>(16);
             LocalDateTime time = (LocalDateTime) map.get("CREATE_TIME");
             String formatTime = time.format(DateTimeFormatter.ofPattern("MM-dd HH:mm"));
-            BigDecimal error = (BigDecimal) errMap.get("D_VALUE");
             BigDecimal max = (BigDecimal) map.get("MAX_V");
             BigDecimal avg = (BigDecimal) map.get("AVG_V");
             data.put("time", formatTime);
             data.put("max", max);
             data.put("avg", avg.setScale(2, RoundingMode.HALF_UP));
-            data.put("error", error);
+            if (index.get() < errList.size()) {
+                Map<String, Object> errMap = errList.get(index.get());
+                BigDecimal error = (BigDecimal) errMap.get("D_VALUE");
+                data.put("error", error);
+            }
             dataList.add(data);
             index.getAndIncrement();
         });