Kaynağa Gözat

pms 瑞都看板 设备新类别统计 柱形图

zhangcl 2 gün önce
ebeveyn
işleme
11bf0b1549

+ 48 - 12
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/stat/IotStaticController.java

@@ -4973,7 +4973,7 @@ public class IotStaticController {
 
     @GetMapping("/new/classify")
     @PermitAll
-    public CommonResult<List<ImmutableMap>> classifyStat() {
+    public CommonResult<List<NewClassifyVo>> classifyStat() {
         Set<Long> allRhChildDeptIds = deptService.getChildDeptIdListFromCache(163l);
         allRhChildDeptIds.add(163L);
         // 包含设备的部门id集合
@@ -4981,17 +4981,53 @@ public class IotStaticController {
         deviceReqVO.setDeptIds(new ArrayList<>(allRhChildDeptIds));
         List<IotDeviceDO> devices = iotDeviceMapper.selectListAlone(deviceReqVO);
         Map<String, Long> assetCountMap = devices.stream().collect(Collectors.groupingBy(IotDeviceDO::getYfClass, Collectors.counting()));
-        List<ImmutableMap> abcList = new ArrayList();
-        assetCountMap.forEach((k, v)->{
-            if (StringUtils.isNotBlank(k)) {
-                String last = StringUtils.substringAfterLast(k, ",");
-                List<IotYfClassifyDO> yfClass = iotYfClassifyMapper.selectList("code", last);
-                if (CollUtil.isNotEmpty(yfClass)) {
-                    abcList.add(ImmutableMap.of("name", yfClass.get(0).getName(),"count", v));
-                }
-            }
-        });
-        return success(abcList);
+        // 获取新分类编码集合 主设备类别前置
+        List<DictDataDO> newClassifyDictData = dictDataService.getDictDataListByDictType("rq_iot_rd_device_new_classify");
+        Set<String> newClassifies = newClassifyDictData.stream()
+                .map(DictDataDO::getValue)
+                .filter(StringUtils::isNotBlank)
+                .collect(Collectors.toSet());
+
+        // 流式处理:构建临时对象 → 排序 → 映射为 ImmutableMap
+        List<NewClassifyVo> result = assetCountMap.entrySet().stream()
+                .filter(e -> StringUtils.isNotBlank(e.getKey()))
+                .map(e -> {
+                    String code = StringUtils.substringAfterLast(e.getKey(), ",");
+                    List<IotYfClassifyDO> yfClass = iotYfClassifyMapper.selectList("code", code);
+                    if (CollUtil.isEmpty(yfClass)) {
+                        return null; // 无对应分类名称则跳过
+                    }
+                    // 临时对象,携带 code、name、count
+                    Map<String, Object> temp = new HashMap<>(3);
+                    temp.put("code", code);
+                    temp.put("name", yfClass.get(0).getName());
+                    temp.put("count", e.getValue());
+                    return temp;
+                })
+                .filter(Objects::nonNull)
+                .sorted((a, b) -> {
+                    boolean aIn = newClassifies.contains(a.get("code"));
+                    boolean bIn = newClassifies.contains(b.get("code"));
+                    // 优先排列在集合中的分类
+                    if (aIn != bIn) {
+                        return aIn ? -1 : 1;
+                    }
+                    // 同样状态按 count 降序
+                    return Long.compare((Long) b.get("count"), (Long) a.get("count"));
+                })
+                .map(m -> {
+                    NewClassifyVo vo = new NewClassifyVo();
+                    vo.setClassName((String) m.get("name"));
+                    // Long 转 Integer(假设数量在 int 范围内)
+                    vo.setCount(((Long) m.get("count")).intValue());
+                    // 根据 code 是否在主设备集合中设置 type
+                    String code = (String) m.get("code");
+                    vo.setType(newClassifies.contains(code) ? "top" : "");
+                    return vo;
+                })
+                .collect(Collectors.toList());
+
+        return success(result);
     }
 }
 

+ 25 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/stat/vo/NewClassifyVo.java

@@ -0,0 +1,25 @@
+package cn.iocoder.yudao.module.pms.controller.admin.stat.vo;
+
+import lombok.Data;
+import lombok.ToString;
+
+/**
+ * 设备新分类 数量统计
+ */
+@Data
+@ToString(callSuper = true)
+public class NewClassifyVo {
+
+    /**
+     * 新分类名称
+     */
+    private String className;
+    /**
+     * 新分类包含的设备数量
+     */
+    private Integer count;
+    /**
+     * 新分类分组
+     */
+    private String type;
+}