Forráskód Böngészése

按故障类型统计设备数-运营首页

tanbin 1 éve
szülő
commit
4b80c3046b

+ 23 - 0
device-api-service/src/main/java/com/xy/service/DeviceFaultInfoServiceImpl.java

@@ -75,13 +75,36 @@ public class DeviceFaultInfoServiceImpl extends ServiceImpl<DeviceFaultInfoMappe
     @PostMapping("countByDevice")
     @ApiOperation("按故障类型统计设备数")
     public R<List<DeviceFaultInfoDto.CountByDeviceVO>> countByDevice() {
+        List<DeviceFaultInfoDto.CountByDeviceVO> list = countDeviceByType();
+        return R.ok(list);
+    }
+
+    public List<DeviceFaultInfoDto.CountByDeviceVO> countDeviceByType() {
         List<DeviceFaultInfoDto.CountByDeviceVO> list = deviceDataMapper.deviceFaultInfoCount();
+        if (CollUtil.isEmpty(list)) {
+            return list;
+        }
         list.forEach(d -> {
             SysCodeConfigureRedis s = SysCodeConfigureUtils.get(d.getEventCode());
             if (s != null) {
                 d.setEventName(s.getTitle());
             }
         });
+
+        return list;
+    }
+
+    @PostMapping("countByDeviceHomePage")
+    @ApiOperation("按故障类型统计设备数-运营首页")
+    public R<List<DeviceFaultInfoDto.CountByDeviceVO>> countByDeviceHomePage() {
+        List<DeviceFaultInfoDto.CountByDeviceVO> list = countDeviceByType();
+        if (CollUtil.isEmpty(list)) {
+            return R.ok(list);
+        }
+        //最多只取5个
+        if (list.size() > 5) {
+            list = CollUtil.sub(list, 0, 5);
+        }
         return R.ok(list);
     }