瀏覽代碼

按照标本类型统计库存数2.0

hyy 8 月之前
父節點
當前提交
e8ad8d05e8

+ 10 - 5
yudao-module-museums/yudao-module-museums-biz/src/main/java/cn/iocoder/yudao/module/museums/controller/admin/specimeninfo/SpecimenInfoController.java

@@ -227,38 +227,43 @@ public class SpecimenInfoController {
     @Operation(summary = "按标本类别统计库存数")
     @PreAuthorize("@ss.hasPermission('museums:specimen-info:query')")
     public CommonResult<Map<String, Object>> getSpecimenTypeStatistics() {
+        // 从服务层获取标本类别的统计数据
         List<Map<String, Object>> specimenTypeStatistics = specimenInfoService.getAllSpecimenTypeStatistics();
         Map<String, Object> result = new HashMap<>();
 
-        // 使用 HashMap 而不是 Map.of
+        // 映射标本类型,使用 HashMap 代替 Map.of
         Map<Integer, String> typeMapping = new HashMap<>();
         typeMapping.put(0, "矿物");
         typeMapping.put(1, "岩石矿石");
         typeMapping.put(2, "化石");
         typeMapping.put(3, "陨石");
 
+        // 存储统计结果的 Map
+        Map<String, Integer> samples = new HashMap<>();
         int totalCount = 0;
 
-        // 将统计结果填充到 Map
+        // 将统计结果填充到 samples
         for (Map<String, Object> specimen : specimenTypeStatistics) {
             Integer type = (Integer) specimen.get("specimen_type");
             Integer count = ((Long) specimen.get("count")).intValue(); // 处理 Long 转换
             String typeName = typeMapping.get(type);
 
             if (typeName != null) {
-                result.put(typeName, count);
+                samples.put(typeName, count);
                 totalCount += count; // 统计总数
             }
         }
 
-        // 将总数放入结果中
-        result.put("标本总数", totalCount);
+        // 将总数和样本统计信息放入结果中
+        samples.put("标本总数", totalCount);
+        result.put("samples", samples); // 将样本统计信息放入结果的 data 中
 
         return success(result);
     }
 
 
 
+
     //根据出、回、入库的登记信息统计本馆标本历年增减情况。
     @GetMapping("/statistics/yearly")
     @Operation(summary = "根据出、回、入库登记统计标本历年增减情况")