Browse Source

返回该年月份标本数量的接口

hyy 9 months ago
parent
commit
d0be04c18e
10 changed files with 252 additions and 57 deletions
  1. 52 4
      yudao-module-museums/yudao-module-museums-biz/src/main/java/cn/iocoder/yudao/module/museums/controller/admin/specimeninfo/SpecimenInfoController.java
  2. 54 7
      yudao-module-museums/yudao-module-museums-biz/src/main/java/cn/iocoder/yudao/module/museums/controller/admin/specimenoutbound/SpecimenOutboundController.java
  3. 6 0
      yudao-module-museums/yudao-module-museums-biz/src/main/java/cn/iocoder/yudao/module/museums/dal/mysql/specimeninfo/SpecimenInfoMapper.java
  4. 15 11
      yudao-module-museums/yudao-module-museums-biz/src/main/java/cn/iocoder/yudao/module/museums/dal/mysql/specimenoutbound/SpecimenOutboundMapper.java
  5. 10 3
      yudao-module-museums/yudao-module-museums-biz/src/main/java/cn/iocoder/yudao/module/museums/service/specimeninfo/SpecimenInfoService.java
  6. 35 23
      yudao-module-museums/yudao-module-museums-biz/src/main/java/cn/iocoder/yudao/module/museums/service/specimeninfo/SpecimenInfoServiceImpl.java
  7. 14 2
      yudao-module-museums/yudao-module-museums-biz/src/main/java/cn/iocoder/yudao/module/museums/service/specimenoutbound/SpecimenOutboundService.java
  8. 9 7
      yudao-module-museums/yudao-module-museums-biz/src/main/java/cn/iocoder/yudao/module/museums/service/specimenoutbound/SpecimenOutboundServiceImpl.java
  9. 17 0
      yudao-module-museums/yudao-module-museums-biz/src/main/resources/mapper/specimeninfo/SpecimenInfoMapper.xml
  10. 40 0
      yudao-module-museums/yudao-module-museums-biz/src/main/resources/mapper/specimenoutbound/SpecimenOutboundMapper.xml

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

@@ -17,6 +17,7 @@ import java.net.URLEncoder;
 import java.time.LocalDateTime;
 import java.util.*;
 import java.io.IOException;
+import java.util.stream.Collectors;
 
 import cn.iocoder.yudao.framework.common.pojo.PageParam;
 import cn.iocoder.yudao.framework.common.pojo.PageResult;
@@ -166,6 +167,25 @@ public class SpecimenInfoController {
         return success(specimenInfoService.importSpecimenImages(file));
     }
 
+//    @PostMapping("/import-specimen-data")
+//    @Operation(summary = "导入标本及其图片")
+//    @Parameters({
+//            @Parameter(name = "excelFile", description = "Excel 文件", required = true),
+//            @Parameter(name = "imageFile", description = "压缩包文件", required = true),
+//            @Parameter(name = "updateSupport", description = "是否支持更新,默认为 false", example = "true")
+//    })
+//    @PreAuthorize("@ss.hasPermission('museums:specimen-info:import')")
+//    public CommonResult<String> importSpecimenData(@RequestParam("excelFile") MultipartFile excelFile,
+//                                                   @RequestParam("imageFile") MultipartFile imageFile,
+//                                                   @RequestParam(value = "updateSupport", required = false, defaultValue = "false") Boolean updateSupport) {
+//        try {
+//            specimenInfoService.importSpecimenData(excelFile, imageFile, updateSupport);
+//            return CommonResult.success("标本及图片导入成功");
+//        } catch (Exception e) {
+//            return CommonResult.error(500, "导入过程中发生错误: " + e.getMessage());
+//        }
+//    }
+
     @PostMapping("/import-specimen-data")
     @Operation(summary = "导入标本及其图片")
     @Parameters({
@@ -186,17 +206,45 @@ public class SpecimenInfoController {
     }
 
 
+
     //工作台
     //根据入库的登记情况统计本年标本入库信息。
+//    @GetMapping("/statistics/entry/{year}")
+//    @Operation(summary = "统计本年标本入库信息")
+//    @Parameter(name = "year", description = "年份", required = true, example = "2024")
+//    @PreAuthorize("@ss.hasPermission('museums:specimen-info:query')")
+//    public CommonResult<List<SpecimenInfoDO>> getEntryStatistics(@PathVariable int year) {
+//        List<SpecimenInfoDO> entryStatistics = specimenInfoService.getEntryStatistics(year);
+//        return success(entryStatistics);
+//    }
+
     @GetMapping("/statistics/entry/{year}")
-    @Operation(summary = "统计本年标本入库信息")
+    @Operation(summary = "统计本年标本每月入库数量")
     @Parameter(name = "year", description = "年份", required = true, example = "2024")
     @PreAuthorize("@ss.hasPermission('museums:specimen-info:query')")
-    public CommonResult<List<SpecimenInfoDO>> getEntryStatistics(@PathVariable int year) {
-        List<SpecimenInfoDO> entryStatistics = specimenInfoService.getEntryStatistics(year);
-        return success(entryStatistics);
+    public CommonResult<Map<String, Object>> getMonthlyEntryStatistics(@PathVariable int year) {
+        List<Map<String, Object>> entryStatistics = specimenInfoService.getMonthlyEntryStatistics(year);
+
+        // 构造返回格式
+        Map<String, Object> result = new HashMap<>();
+        result.put("code", 200);
+        result.put("year", String.valueOf(year));
+        result.put("data", entryStatistics.stream()
+                .map(stat -> {
+                    Map<String, Object> monthData = new HashMap<>();
+                    monthData.put("number", stat.get("entryCount")); // 获取入库数量
+                    monthData.put("month", stat.get("month") + "月"); // 获取月份并转换格式
+                    return monthData;
+                })
+                .collect(Collectors.toList())
+        );
+        result.put("msg", "统计本年标本入库数量");
+
+        return success(result);
     }
 
+
+
     //根据标本类别指标统计各类标本库存数,第一个是可查询某个标本类别的所有数据,第二个是可查询各个标本类型的库存数
     @GetMapping("/statistics/{specimen_type}")
     @Operation(summary = "按标本类别统计库存数")

+ 54 - 7
yudao-module-museums/yudao-module-museums-biz/src/main/java/cn/iocoder/yudao/module/museums/controller/admin/specimenoutbound/SpecimenOutboundController.java

@@ -164,21 +164,68 @@ public class SpecimenOutboundController {
 
     //工作台
     //根据出库的登记情况统计本年标本出库信息。
+//    @GetMapping("/statistics/outgoing/{year}")
+//    @Operation(summary = "根据出库登记情况统计本年标本出库信息")
+//    @Parameter(name = "year", description = "年份", required = true, example = "2024")
+//    @PreAuthorize("@ss.hasPermission('museums:specimen-outbound:query')")
+//    public CommonResult<List<SpecimenOutboundOutgoingReqVO>> getOutboundStatistics(@PathVariable int year) {
+//        List<SpecimenOutboundOutgoingReqVO> outboundStatistics = specimenOutboundService.getOutboundStatistics(year);
+//        return success(outboundStatistics);
+//    }
+
     @GetMapping("/statistics/outgoing/{year}")
     @Operation(summary = "根据出库登记情况统计本年标本出库信息")
     @Parameter(name = "year", description = "年份", required = true, example = "2024")
     @PreAuthorize("@ss.hasPermission('museums:specimen-outbound:query')")
-    public CommonResult<List<SpecimenOutboundOutgoingReqVO>> getOutboundStatistics(@PathVariable int year) {
-        List<SpecimenOutboundOutgoingReqVO> outboundStatistics = specimenOutboundService.getOutboundStatistics(year);
-        return success(outboundStatistics);
+    public CommonResult<Map<String, Object>> getOutboundStatistics(@PathVariable int year) {
+        List<Map<String, Object>> monthlyStatistics = specimenOutboundService.getMonthlyOutboundStatistics(year);
+
+        // 将数字月份转换为字符串月份
+        for (Map<String, Object> stat : monthlyStatistics) {
+            int monthNum = (int) stat.get("month");
+            String monthStr = monthNum + "月"; // 转换为“1月”、“2月”等格式
+            stat.put("month", monthStr);
+        }
+
+        Map<String, Object> response = new HashMap<>();
+        response.put("code", 200);
+        response.put("year", year);
+        response.put("data", monthlyStatistics);
+        response.put("msg", "统计本年标本出库数量");
+
+        return success(response);
     }
 
+
+//    @GetMapping("/statistics/return/{year}")
+//    @Operation(summary = "统计本年标本回库信息")
+//    @Parameter(name = "year", description = "年份", required = true, example = "2024")
+//    public CommonResult<List<SpecimenOutboundReturnReqVO>> getReturnStatistics(@PathVariable int year) {
+//        List<SpecimenOutboundReturnReqVO> result = specimenOutboundService.getReturnStatistics(year);
+//        return success(result);
+//    }
+
     @GetMapping("/statistics/return/{year}")
-    @Operation(summary = "统计本年标本回库信息")
+    @Operation(summary = "根据回库登记情况统计本年标本回库信息")
     @Parameter(name = "year", description = "年份", required = true, example = "2024")
-    public CommonResult<List<SpecimenOutboundReturnReqVO>> getReturnStatistics(@PathVariable int year) {
-        List<SpecimenOutboundReturnReqVO> result = specimenOutboundService.getReturnStatistics(year);
-        return success(result);
+    @PreAuthorize("@ss.hasPermission('museums:specimen-outbound:query')")
+    public CommonResult<Map<String, Object>> getReturnStatistics(@PathVariable int year) {
+        List<Map<String, Object>> monthlyStatistics = specimenOutboundService.getMonthlyReturnStatistics(year);
+
+        // 将数字月份转换为字符串月份
+        for (Map<String, Object> stat : monthlyStatistics) {
+            int monthNum = (int) stat.get("month");
+            String monthStr = monthNum + "月"; // 转换为“1月”、“2月”等格式
+            stat.put("month", monthStr);
+        }
+
+        Map<String, Object> response = new HashMap<>();
+        response.put("code", 200);
+        response.put("year", year);
+        response.put("data", monthlyStatistics);
+        response.put("msg", "统计本年标本回库数量");
+
+        return success(response);
     }
 
 

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

@@ -160,6 +160,12 @@ public interface SpecimenInfoMapper extends BaseMapperX<SpecimenInfoDO> {
     // 根据多个 ID 查询标本信息
     List<SpecimenInfoDO> selectByIds(List<Long> ids);
 
+//    @Select("SELECT MONTH(entryDate) AS month, COUNT(*) AS entryCount"+
+//    "FROM museums_specimen_info"+
+//    "WHERE YEAR(entryDate) = #{year}"+
+//    "GROUP BY MONTH(entryDate)"+
+//    "ORDER BY month")
+    List<Map<String, Object>> selectMonthlyEntryStatisticsByYear(@Param("year") int year);
 
 
 

+ 15 - 11
yudao-module-museums/yudao-module-museums-biz/src/main/java/cn/iocoder/yudao/module/museums/dal/mysql/specimenoutbound/SpecimenOutboundMapper.java

@@ -46,17 +46,21 @@ public interface SpecimenOutboundMapper extends BaseMapperX<SpecimenOutboundDO>
     }
 
 
-    /**
-     * 根据年份统计已出库和已回库的标本信息
-     *
-     * @param year 年份
-     * @return 标本出库信息列表
-     */
-    @Select("SELECT * FROM museums_specimen_outbound " +
-            "WHERE (status = 3 OR status = 4) " +
-            "AND YEAR(application_date) = #{year} " +
-            "AND deleted = 0")
-    List<SpecimenOutboundOutgoingReqVO> selectOutgoingStatisticsByYear(int year);
+//    /**
+//     * 根据年份统计已出库和已回库的标本信息
+//     *
+//     * @param year 年份
+//     * @return 标本出库信息列表
+//     */
+//    @Select("SELECT * FROM museums_specimen_outbound " +
+//            "WHERE (status = 3 OR status = 4) " +
+//            "AND YEAR(application_date) = #{year} " +
+//            "AND deleted = 0")
+//    List<SpecimenOutboundOutgoingReqVO> selectOutgoingStatisticsByYear(int year);
+      List<Map<String, Object>> selectMonthlyOutboundStatistics(int year);
+      List<Map<String, Object>> getMonthlyReturnStatistics(int year);
+
+
 
     /**
      * 根据年份统计已出库和已回库的标本信息

+ 10 - 3
yudao-module-museums/yudao-module-museums-biz/src/main/java/cn/iocoder/yudao/module/museums/service/specimeninfo/SpecimenInfoService.java

@@ -74,13 +74,20 @@ public interface SpecimenInfoService {
     void importSpecimenData(MultipartFile excelFile, MultipartFile imageFile, boolean updateSupport) throws Exception;
 
     //工作台
+//    /**
+//     * 统计本年标本入库信息
+//     *
+//     * @param year 年份
+//     * @return 标本入库信息列表
+//     */
+//    List<SpecimenInfoDO> getEntryStatistics(int year);
     /**
-     * 统计本年标本入库信息
+     * 统计本年标本每月入库数量
      *
      * @param year 年份
-     * @return 标本入库信息列表
+     * @return 每月标本入库数量列表
      */
-    List<SpecimenInfoDO> getEntryStatistics(int year);
+    List<Map<String, Object>> getMonthlyEntryStatistics(int year);
     /**
      * 按标本类别统计库存数
      *

+ 35 - 23
yudao-module-museums/yudao-module-museums-biz/src/main/java/cn/iocoder/yudao/module/museums/service/specimeninfo/SpecimenInfoServiceImpl.java

@@ -238,7 +238,10 @@ public class SpecimenInfoServiceImpl implements SpecimenInfoService {
             SpecimenInfoDO existSpecimen = specimenInfoMapper.selectBySpecimenNumber(importSpecimen.getSpecimenNumber());
 
             // 1. 校验图片名格式
-            if (!areValidImageNames(importSpecimen.getImageName())) {
+            String[] imageNames = importSpecimen.getImageName().split(","); // 处理多个图片名
+            boolean validImageNames = Arrays.stream(imageNames).allMatch(this::isValidImageName);
+
+            if (!validImageNames) {
                 respVO.getFailureSpecimenNumbers().put(importSpecimen.getSpecimenNumber(), "图片名称格式不正确");
                 return;
             }
@@ -246,16 +249,18 @@ public class SpecimenInfoServiceImpl implements SpecimenInfoService {
             if (existSpecimen == null) {
                 // 2.2.1 不存在则插入
                 SpecimenInfoDO newSpecimen = BeanUtils.toBean(importSpecimen, SpecimenInfoDO.class);
+                newSpecimen.setImagePath(""); // 初始化为空
                 specimenInfoMapper.insert(newSpecimen);
                 respVO.getCreateSpecimenNumbers().add(importSpecimen.getSpecimenNumber());
                 return;
             }
 
             // 2.2.2 如果存在,判断是否允许更新
-            if (!isUpdateSupport) {
-                respVO.getFailureSpecimenNumbers().put(importSpecimen.getSpecimenNumber(), "标本编号已存在,且不支持更新");
-                return;
-            }
+            // 如果需要支持更新,取消注释以下代码
+//        if (!isUpdateSupport) {
+//            respVO.getFailureSpecimenNumbers().put(importSpecimen.getSpecimenNumber(), "标本编号已存在,且不支持更新");
+//            return;
+//        }
 
             // 更新逻辑
             SpecimenInfoDO updateSpecimen = BeanUtils.toBean(importSpecimen, SpecimenInfoDO.class);
@@ -267,8 +272,9 @@ public class SpecimenInfoServiceImpl implements SpecimenInfoService {
         return respVO;
     }
 
+
     // 检查多个图片名称格式
-    private boolean areValidImageNames(String imageNames) {
+    private boolean isValidImageName(String imageNames) {
         if (imageNames == null) return false;
         String[] names = imageNames.split(",");
         for (String name : names) {
@@ -287,7 +293,6 @@ public class SpecimenInfoServiceImpl implements SpecimenInfoService {
         if (!file.getOriginalFilename().endsWith(".zip")) {
             throw exception(UPLOADED_FOLDER_CANNOT_EMPTY);
         }
-
         // 创建临时目录存放解压后的文件
         File tempDir = Files.createTempDirectory("specimen_images").toFile();
         try (ZipInputStream zipInputStream = new ZipInputStream(file.getInputStream())) {
@@ -312,25 +317,25 @@ public class SpecimenInfoServiceImpl implements SpecimenInfoService {
         if (imageFiles != null) {
             for (File imageFile : imageFiles) {
                 String imageName = imageFile.getName();
-//                if (!isValidImageName(imageName)) {
-//                    System.err.println("无效的图片格式: " + imageName);
-//                    continue; // 跳过无效图片
-//                }
+                if (!isValidImageName(imageName)) {
+                    // 如果不符合格式,抛出异常或记录日志
+                    System.err.println("无效的图片格式: " + imageName);
+                    continue;
+                }
 
                 // 根据图片名称查找对应的标本
-                SpecimenInfoDO specimenInfo = specimenInfoMapper.selectByImageName(imageName);
-                if (specimenInfo != null) {
+                List<SpecimenInfoDO> specimenInfoList = (List<SpecimenInfoDO>) specimenInfoMapper.selectByImageName(imageName);
+                for (SpecimenInfoDO specimenInfo : specimenInfoList) {
                     // 上传图片并获取URL
                     String imagePath = fileApi.createFile(Files.readAllBytes(imageFile.toPath()));
 
-                    // 更新标本信息中的图片路径,允许多个路径
-                    String existingImagePaths = specimenInfo.getImagePath();
-                    if (existingImagePaths == null || existingImagePaths.isEmpty()) {
-                        specimenInfo.setImagePath(imagePath);
+                    // 更新标本信息中的图片路径
+                    String currentImagePaths = specimenInfo.getImagePath();
+                    if (currentImagePaths == null || currentImagePaths.isEmpty()) {
+                        specimenInfo.setImagePath(imagePath); // 第一次设置
                     } else {
-                        specimenInfo.setImagePath(existingImagePaths + "," + imagePath);
+                        specimenInfo.setImagePath(currentImagePaths + "," + imagePath); // 追加到已有路径
                     }
-
                     specimenInfoMapper.updateById(specimenInfo);
                 }
             }
@@ -341,6 +346,8 @@ public class SpecimenInfoServiceImpl implements SpecimenInfoService {
         return "标本图片导入成功";
     }
 
+
+
     // 主导入逻辑
     @Override
     @Transactional(rollbackFor = Exception.class) // 事务管理
@@ -361,11 +368,18 @@ public class SpecimenInfoServiceImpl implements SpecimenInfoService {
 
     //工作台
     //根据入库的登记情况统计本年标本入库信息
+//    @Override
+//    public List<SpecimenInfoDO> getEntryStatistics(int year) {
+//        return specimenInfoMapper.selectEntryStatisticsByYear(year);
+//    }
+
     @Override
-    public List<SpecimenInfoDO> getEntryStatistics(int year) {
-        return specimenInfoMapper.selectEntryStatisticsByYear(year);
+    public List<Map<String, Object>> getMonthlyEntryStatistics(int year) {
+        return specimenInfoMapper.selectMonthlyEntryStatisticsByYear(year);
     }
 
+
+
     //按标本类别统计库存数
     @Override
     public List<SpecimenInfoDO> getSpecimenTypeStatistics(int specimen_type) {
@@ -583,6 +597,4 @@ public class SpecimenInfoServiceImpl implements SpecimenInfoService {
         return specimenInfoMapper.getSpecimenRecords(id);
     }
 
-
-
 }

+ 14 - 2
yudao-module-museums/yudao-module-museums-biz/src/main/java/cn/iocoder/yudao/module/museums/service/specimenoutbound/SpecimenOutboundService.java

@@ -8,6 +8,7 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
 
 import java.time.LocalDateTime;
 import java.util.List;
+import java.util.Map;
 
 /**
  * 标本出库回库信息 Service 接口
@@ -95,15 +96,26 @@ public interface SpecimenOutboundService {
      * @param year 年份
      * @return 标本出库信息列表
      */
-    List<SpecimenOutboundOutgoingReqVO> getOutboundStatistics(int year);
+//    List<SpecimenOutboundOutgoingReqVO> getOutboundStatistics(int year);
+
+    //工作台
+    //根据出库的登记情况统计本年标本出库信息
+    List<Map<String, Object>> getMonthlyOutboundStatistics(int year);
 
     /**
      * 根据回库的登记情况统计本年标本回库信息
      * @param year 年份
      * @return 标本回库信息列表
      */
-    List<SpecimenOutboundReturnReqVO> getReturnStatistics(int year);
+//    List<SpecimenOutboundReturnReqVO> getReturnStatistics(int year);
+
 
+    //根据回库的登记情况统计本年标本回库信息
+//    @Override
+//    public List<SpecimenOutboundReturnReqVO> getReturnStatistics(int year) {
+//        return specimenOutboundMapper.selectReturnStatisticsByYear(year);
+//    }
+    List<Map<String, Object>> getMonthlyReturnStatistics(int year);
 
     /**
      * 根据出库信息ID获得标本详细信息

+ 9 - 7
yudao-module-museums/yudao-module-museums-biz/src/main/java/cn/iocoder/yudao/module/museums/service/specimenoutbound/SpecimenOutboundServiceImpl.java

@@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.museums.service.specimenoutbound;
 import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
 import cn.iocoder.yudao.module.museums.dal.dataobject.specimeninfo.SpecimenInfoDO;
 import cn.iocoder.yudao.module.museums.dal.mysql.specimeninfo.SpecimenInfoMapper;
-import org.apache.commons.beanutils.BeanUtilsBean;
 import org.springframework.stereotype.Service;
 import javax.annotation.Resource;
 
@@ -17,9 +16,9 @@ import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
 import cn.iocoder.yudao.module.museums.dal.mysql.specimenoutbound.SpecimenOutboundMapper;
 
 import java.time.LocalDateTime;
-import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
+import java.util.Map;
 import java.util.stream.Collectors;
 
 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
@@ -201,17 +200,20 @@ public class SpecimenOutboundServiceImpl implements SpecimenOutboundService {
     //工作台
     //根据出库的登记情况统计本年标本出库信息
     @Override
-    public List<SpecimenOutboundOutgoingReqVO> getOutboundStatistics(int year) {
-        return specimenOutboundMapper.selectOutgoingStatisticsByYear(year);
+    public List<Map<String, Object>> getMonthlyOutboundStatistics(int year) {
+        return specimenOutboundMapper.selectMonthlyOutboundStatistics(year);
     }
 
     //根据回库的登记情况统计本年标本回库信息
+//    @Override
+//    public List<SpecimenOutboundReturnReqVO> getReturnStatistics(int year) {
+//        return specimenOutboundMapper.selectReturnStatisticsByYear(year);
+//    }
     @Override
-    public List<SpecimenOutboundReturnReqVO> getReturnStatistics(int year) {
-        return specimenOutboundMapper.selectReturnStatisticsByYear(year);
+    public List<Map<String, Object>> getMonthlyReturnStatistics(int year) {
+        return specimenOutboundMapper.getMonthlyReturnStatistics(year);
     }
 
-
 //    @Override
 //    public List<SpecimenOutboundDO> getSpecimenOutboundsByOutboundOrderId(Long outboundOrderId) {
 //        return specimenOutboundMapper.selectByOutboundOrderId(outboundOrderId);

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

@@ -64,5 +64,22 @@
             GROUP BY specimen_type
         </select>
 
+    <select id="selectMonthlyEntryStatisticsByYear" parameterType="int" resultType="map">
+        SELECT
+            MONTH(entry_date) AS month,
+            COUNT(*) AS entryCount
+        FROM
+            museums_specimen_info
+        WHERE
+            YEAR(entry_date) = #{year}
+        GROUP BY
+            MONTH(entry_date)
+        ORDER BY
+            month
+    </select>
+
+
+
+
 
 </mapper>

+ 40 - 0
yudao-module-museums/yudao-module-museums-biz/src/main/resources/mapper/specimenoutbound/SpecimenOutboundMapper.xml

@@ -8,6 +8,46 @@
         代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
         文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
      -->
+    <select id="selectMonthlyOutboundStatistics" resultType="map">
+        SELECT
+            MONTH(outgoing_time) AS month,
+            COUNT(DISTINCT TRIM(SUBSTRING_INDEX(SUBSTRING_INDEX(info_id, ',', numbers.n), ',', -1))) AS number
+        FROM
+            museums_specimen_outbound
+            JOIN
+            (SELECT 1 AS n UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION
+            SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9 UNION SELECT 10) AS numbers
+        ON
+            CHAR_LENGTH(info_id) - CHAR_LENGTH(REPLACE(info_id, ',', '')) >= numbers.n - 1
+        WHERE
+            (status = 3 OR status = 4)
+          AND YEAR(outgoing_time) = #{year}
+          AND deleted = 0
+        GROUP BY
+            MONTH(outgoing_time)
+        ORDER BY
+            month
+    </select>
 
+    <select id="getMonthlyReturnStatistics" resultType="map">
+        SELECT
+            MONTH(return_date) AS month,
+            COUNT(DISTINCT TRIM(SUBSTRING_INDEX(SUBSTRING_INDEX(info_id, ',', numbers.n), ',', -1))) AS number
+        FROM
+            museums_specimen_outbound
+            JOIN
+            (SELECT 1 AS n UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION
+            SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9 UNION SELECT 10) AS numbers
+        ON
+            CHAR_LENGTH(info_id) - CHAR_LENGTH(REPLACE(info_id, ',', '')) >= numbers.n - 1
+        WHERE
+            (status = 4)
+          AND YEAR(return_date) = #{year}
+          AND deleted = 0
+        GROUP BY
+            MONTH(return_date)
+        ORDER BY
+            month
+    </select>
 
 </mapper>