Преглед на файлове

按照标本类型统计库存数

hyy преди 8 месеца
родител
ревизия
8f97514a5d

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

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

+ 18 - 7
yudao-module-museums/yudao-module-museums-biz/src/main/java/cn/iocoder/yudao/module/museums/dal/mysql/specimeninfo/SpecimenInfoMapper.java

@@ -85,15 +85,22 @@ public interface SpecimenInfoMapper extends BaseMapperX<SpecimenInfoDO> {
             "WHERE specimen_type = #{specimen_type} " +
             "AND deleted = 0")
     List<SpecimenInfoDO> selectSpecimenTypeStatistics(int specimen_type);
+//    /**
+//     * 根据标本类别统计各类标本库存数量
+//     *
+//     * @return 各类标本的库存数量统计
+//     */
+//@Select("SELECT specimen_type, COUNT(*) AS count FROM museums_specimen_info " +
+//        "WHERE deleted = 0 " +
+//        "GROUP BY specimen_type")
+//List<Map<String, Object>> selectAllSpecimenTypeStatistics();
+
     /**
-     * 根据标本类别统计各类标本库存数量
-     *
-     * @return 各类标本的库存数量统计
+     * 查询各类标本的数量统计
+     * @return 各类标本的类型及数量
      */
-@Select("SELECT specimen_type, COUNT(*) AS count FROM museums_specimen_info " +
-        "WHERE deleted = 0 " +
-        "GROUP BY specimen_type")
-List<Map<String, Object>> selectAllSpecimenTypeStatistics();
+    @Select("SELECT specimen_type, COUNT(*) as count FROM specimen_info GROUP BY specimen_type")
+    List<Map<String, Object>> selectAllSpecimenTypeStatistics();
 
     /**
      * 根据年份统计标本来源增减情况
@@ -152,4 +159,8 @@ List<Map<String, Object>> selectAllSpecimenTypeStatistics();
 
     // 根据多个 ID 查询标本信息
     List<SpecimenInfoDO> selectByIds(List<Long> ids);
+
+
+
+
 }

+ 9 - 0
yudao-module-museums/yudao-module-museums-biz/src/main/resources/mapper/specimeninfo/SpecimenInfoMapper.xml

@@ -56,4 +56,13 @@
         </foreach>
     </select>
 
+
+
+        <select id="selectAllSpecimenTypeStatistics" resultType="map">
+            SELECT specimen_type, COUNT(*) as count
+            FROM museums_specimen_info
+            GROUP BY specimen_type
+        </select>
+
+
 </mapper>