Parcourir la source

首页数据查询

HuRongxin il y a 1 mois
Parent
commit
e3edad8d80

+ 5 - 2
ruoyi-admin/src/main/java/org/dromara/web/controller/IndexController.java

@@ -8,6 +8,7 @@ import org.dromara.common.core.utils.SpringUtils;
 import org.dromara.common.core.utils.StringUtils;
 import org.dromara.web.domain.bo.HospitalRecordBo;
 import org.dromara.web.domain.vo.HospitalRecordVo;
+import org.dromara.web.service.IIndexService;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RestController;
 
@@ -21,6 +22,8 @@ import org.springframework.web.bind.annotation.RestController;
 @RestController
 public class IndexController {
 
+    private final IIndexService indexService;
+
 
     /**
      * 访问首页,提示语
@@ -33,9 +36,9 @@ public class IndexController {
     /**
      * 查询首页数据
      */
-    @GetMapping("/queryData")
+    @GetMapping("/index/queryData")
     public R queryData() {
-        return R.ok();
+        return R.ok(indexService.queryData());
     }
 
 }

+ 1 - 0
ruoyi-admin/src/main/java/org/dromara/web/domain/EnteralNutrition.java

@@ -52,6 +52,7 @@ public class EnteralNutrition extends TenantEntity {
      * 营养产品
      */
     private String nutritionProduct;
+
     private Long nutritionProductId;
 
     /**

+ 12 - 1
ruoyi-admin/src/main/java/org/dromara/web/domain/vo/indexData/IndexDataVo.java

@@ -2,7 +2,9 @@ package org.dromara.web.domain.vo.indexData;
 
 import lombok.Data;
 
+import java.math.BigDecimal;
 import java.util.List;
+import java.util.Map;
 
 @Data
 public class IndexDataVo {
@@ -17,5 +19,14 @@ public class IndexDataVo {
 
     List<FocusPatientVo> focusPatientVoList;
 
-    List<IncomeDetailsVo>incomeDetailsVoList;
+    Map<String, List<BigDecimal>> monthlyData;
+
+    // 定义累加变量
+    private BigDecimal totalCollectedSum;
+
+    private BigDecimal nutritionProductsSum;
+
+    private BigDecimal dietaryIncomeSum;
+
+    private BigDecimal screeningAssessmentSum;
 }

+ 17 - 2
ruoyi-admin/src/main/java/org/dromara/web/mapper/EnteralNutritionMapper.java

@@ -6,6 +6,8 @@ import org.dromara.common.mybatis.core.mapper.BaseMapperPlus;
 import org.dromara.web.domain.EnteralNutrition;
 import org.dromara.web.domain.vo.EnteralNutritionQueryOneVo;
 import org.dromara.web.domain.vo.EnteralNutritionVo;
+import org.dromara.web.domain.vo.indexData.PrescriptionOverviewVo;
+import org.springframework.stereotype.Repository;
 
 import java.util.List;
 
@@ -15,6 +17,7 @@ import java.util.List;
  * @author Lion Li
  * @date 2025-07-22
  */
+@Repository
 public interface EnteralNutritionMapper extends BaseMapperPlus<EnteralNutrition, EnteralNutritionVo> {
 
     @Select("<script>" +
@@ -53,7 +56,7 @@ public interface EnteralNutritionMapper extends BaseMapperPlus<EnteralNutrition,
         "LEFT JOIN settlement se ON en.settlement_id = se.id AND IFNULL(se.del_Flag, '0') != '1' " +
         "LEFT JOIN sys_user su ON en.config_by = su.user_id AND IFNULL(su.del_Flag, '0') != '1' " +
         "LEFT JOIN sys_user syu ON en.execute_by = syu.user_id AND IFNULL(syu.del_Flag, '0') != '1' " +
-        "LEFT JOIN treatment_user tu ON se.patient_id = tu.id AND IFNULL(tu.del_Flag, '0') != '1' " +
+        "LEFT JOIN patient_medical_record tu ON se.patient_id = tu.id AND IFNULL(tu.del_Flag, '0') != '1' " +
         "LEFT JOIN sys_dept sd ON se.door_id = sd.dept_id AND IFNULL(sd.del_Flag, '0') != '1' " +
         "WHERE 1 = 1 " +
         "<if test='prescriptionType != null and prescriptionType != \"\"'> and en.prescription_type = #{prescriptionType} </if> " +
@@ -85,7 +88,7 @@ public interface EnteralNutritionMapper extends BaseMapperPlus<EnteralNutrition,
         "LEFT JOIN settlement se ON en.settlement_id = se.id AND IFNULL(se.del_Flag, '0') != '1' " +
         "LEFT JOIN sys_user su ON en.config_by = su.user_id AND IFNULL(su.del_Flag, '0') != '1' " +
         "LEFT JOIN sys_user syu ON en.execute_by = syu.user_id AND IFNULL(syu.del_Flag, '0') != '1' " +
-        "LEFT JOIN treatment_user tu ON se.patient_id = tu.id AND IFNULL(tu.del_Flag, '0') != '1' " +
+        "LEFT JOIN patient_medical_record tu ON se.patient_id = tu.id AND IFNULL(tu.del_Flag, '0') != '1' " +
         "LEFT JOIN sys_dept sd ON se.door_id = sd.dept_id AND IFNULL(sd.del_Flag, '0') != '1' " +
         "WHERE 1 = 1 " +
         "<if test='prescriptionType != null and prescriptionType != \"\"'> and en.prescription_type = #{prescriptionType} </if> " +
@@ -110,5 +113,17 @@ public interface EnteralNutritionMapper extends BaseMapperPlus<EnteralNutrition,
                              @Param("endTime") String endTime, @Param("exeBeginTime") String exeBeginTime,
                              @Param("exeEndTime") String exeEndTime);
 
+@Select(
+    """
+           SELECT
+           COUNT(*) AS total,
+           COUNT(CASE WHEN config_status = '1' THEN 1 END) AS completed,
+           COUNT(CASE WHEN config_status = '0' THEN 1 END) AS pending
+           FROM enteral_nutrition
+           WHERE prescription_type = '3'
+           AND del_flag = '0'
+        """
+     )
+    PrescriptionOverviewVo  selectCount();
 
 }

+ 5 - 5
ruoyi-admin/src/main/java/org/dromara/web/mapper/HospitalMealPlanMapper.java

@@ -59,7 +59,7 @@ public interface HospitalMealPlanMapper extends BaseMapperPlus<HospitalMealPlan,
         "LEFT JOIN settlement se ON hmp.settlement_id = se.id AND IFNULL(se.del_Flag, '0') != '1' " +
         "LEFT JOIN sys_user su ON hmr.make_by = su.user_id AND IFNULL(su.del_Flag, '0') != '1' " +
         "LEFT JOIN sys_user syu ON hmr.execute_by = syu.user_id AND IFNULL(syu.del_Flag, '0') != '1' " +
-        "LEFT JOIN treatment_user tu ON se.patient_id = tu.id AND IFNULL(tu.del_Flag, '0') != '1' " +
+        "LEFT JOIN patient_medical_record tu ON se.patient_id = tu.id AND IFNULL(tu.del_Flag, '0') != '1' " +
         "LEFT JOIN sys_dept sd ON se.door_id = sd.dept_id AND IFNULL(sd.del_Flag, '0') != '1' " +
         "WHERE 1 = 1 " +
         "<if test='prescriptionType != null and prescriptionType != \"\"'> and se.charge_type = #{prescriptionType} </if> " +
@@ -92,7 +92,7 @@ public interface HospitalMealPlanMapper extends BaseMapperPlus<HospitalMealPlan,
         "LEFT JOIN settlement se ON hmp.settlement_id = se.id AND IFNULL(se.del_Flag, '0') != '1' " +
         "LEFT JOIN sys_user su ON hmr.make_by = su.user_id AND IFNULL(su.del_Flag, '0') != '1' " +
         "LEFT JOIN sys_user syu ON hmr.execute_by = syu.user_id AND IFNULL(syu.del_Flag, '0') != '1' " +
-        "LEFT JOIN treatment_user tu ON se.patient_id = tu.id AND IFNULL(tu.del_Flag, '0') != '1' " +
+        "LEFT JOIN patient_medical_record tu ON se.patient_id = tu.id AND IFNULL(tu.del_Flag, '0') != '1' " +
         "LEFT JOIN sys_dept sd ON se.door_id = sd.dept_id AND IFNULL(sd.del_Flag, '0') != '1' " +
         "WHERE 1 = 1 " +
         "<if test='prescriptionType != null and prescriptionType != \"\"'> and se.charge_type = #{prescriptionType} </if> " +
@@ -127,7 +127,7 @@ public interface HospitalMealPlanMapper extends BaseMapperPlus<HospitalMealPlan,
 //            `doctor_dept`.`dept_name` AS `calculationDoctorDepartment`,
 //            `sys_user`.`user_name` AS `calculationDoctor`,
 //            `patient_dept`.`dept_name` AS `patientDepartment`,
-//            `treatment_user`.`treat_name` AS `patientName`,
+//            `patient_medical_record`.`treat_name` AS `patientName`,
 //            `settlement`.`payment_status` AS `payStatus`,
 //            JSON_ARRAYAGG(
 //                JSON_OBJECT(
@@ -150,8 +150,8 @@ public interface HospitalMealPlanMapper extends BaseMapperPlus<HospitalMealPlan,
 //            ON `doctor_dept`.`dept_id` = `hospital_meal_plan`.`create_dept`
 //        LEFT JOIN `sys_user`
 //            ON `sys_user`.`user_id` = `hospital_meal_plan`.`create_by`
-//        LEFT JOIN `treatment_user`
-//            ON `treatment_user`.`id` = `hospital_meal_plan`.`patient_id`
+//        LEFT JOIN `patient_medical_record`
+//            ON `patient_medical_record`.`id` = `hospital_meal_plan`.`patient_id`
 //        LEFT JOIN `hospital_meal_recipe`
 //            ON `hospital_meal_recipe`.`plan_id` = `hospital_meal_plan`.`id`
 //        LEFT JOIN `sys_recipe`

+ 94 - 0
ruoyi-admin/src/main/java/org/dromara/web/mapper/PatientMedicalRecordMapper.java

@@ -1,13 +1,19 @@
 package org.dromara.web.mapper;
 
 
+import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
 import org.apache.ibatis.annotations.Select;
 import org.dromara.common.mybatis.core.mapper.BaseMapperPlus;
 import org.dromara.web.domain.PatientMedicalRecord;
 import org.dromara.web.domain.vo.PatientMedicalRecordVo;
+import org.dromara.web.domain.vo.indexData.FocusPatientVo;
+import org.dromara.web.domain.vo.indexData.IncomeDetailsVo;
 import org.dromara.web.domain.vo.indexData.PatientOverviewVo;
 import org.springframework.stereotype.Repository;
 
+import java.util.List;
+import java.util.Map;
+
 /**
  * 【请填写功能名称】Mapper接口
  *
@@ -33,4 +39,92 @@ public interface PatientMedicalRecordMapper extends BaseMapperPlus<PatientMedica
         ") latest_rec ON sp.treat_num = latest_rec.treat_num  " +
         "WHERE sp.del_flag = '0'")
     PatientOverviewVo selectCount();
+    @Select("SELECT   " +
+        "    sp.patient_name AS name,  " +
+        "    ROUND(  " +
+        "        CASE   " +
+        "            WHEN sp.age LIKE '%岁%月' THEN   " +
+        "                CAST(SUBSTRING_INDEX(sp.age, '岁', 1) AS UNSIGNED) +   " +
+        "                CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(sp.age, '岁', -1), '月', 1) AS UNSIGNED) / 12.0  " +
+        "            WHEN sp.age LIKE '%岁' THEN   " +
+        "                CAST(SUBSTRING_INDEX(sp.age, '岁', 1) AS UNSIGNED)  " +
+        "            WHEN sp.age LIKE '%月' THEN   " +
+        "                CAST(SUBSTRING_INDEX(sp.age, '月', 1) AS UNSIGNED) / 12.0  " +
+        "            ELSE   " +
+        "                CAST(sp.age AS UNSIGNED)  " +
+        "        END  " +
+        "    ) AS age,  " +
+        "    sdl.label_name AS disease,  " +
+        "    nd.medical_order AS reason  " +
+        "FROM sys_patient sp  " +
+        "INNER JOIN (  " +
+        "    SELECT pmr1.*   " +
+        "    FROM patient_medical_record pmr1  " +
+        "    INNER JOIN (  " +
+        "        SELECT treat_num, MAX(id) as max_id  " +
+        "        FROM patient_medical_record  " +
+        "        WHERE del_flag = '0'   " +
+        "          AND type = '1'   " +
+        "          AND treatment_user_status = '0'  " +
+        "        GROUP BY treat_num  " +
+        "    ) pmr2 ON pmr1.id = pmr2.max_id  " +
+        "    WHERE pmr1.del_flag = '0'   " +
+        "      AND pmr1.type = '1'   " +
+        "      AND pmr1.treatment_user_status = '0'  " +
+        ") latest_pmr ON sp.treat_num = latest_pmr.treat_num  " +
+        "LEFT JOIN nutrition_diagnosis nd ON latest_pmr.id = nd.treatment_user_id   " +
+        "    AND nd.del_flag = '0'  " +
+        "LEFT JOIN sys_disease_label sdl ON nd.diagnosis_lable_id = sdl.label_id   " +
+        "    AND sdl.del_flag = '0'  " +
+        "WHERE sp.del_flag = '0'  " +
+        "ORDER BY latest_pmr.create_time DESC")
+    List<FocusPatientVo>selectFocusPatients();
+    @InterceptorIgnore(tenantLine = "true")
+    @Select("WITH months AS (  " +
+        "    SELECT 1 AS month_num, '1月' AS month_name UNION SELECT 2, '2月' UNION SELECT 3, '3月' UNION SELECT 4, '4月'   " +
+        "    UNION SELECT 5, '5月' UNION SELECT 6, '6月' UNION SELECT 7, '7月' UNION SELECT 8, '8月'  " +
+        "    UNION SELECT 9, '9月' UNION SELECT 10, '10月' UNION SELECT 11, '11月' UNION SELECT 12, '12月'  " +
+        "),  " +
+        "year_months AS (  " +
+        "    SELECT   " +
+        "        m.month_name,  " +
+        "        CONCAT(YEAR(CURDATE()), '-', LPAD(m.month_num, 2, '0')) AS month_code  " +
+        "    FROM months m  " +
+        "),  " +
+        "charge_data AS (  " +
+        "    SELECT  " +
+        "        DATE_FORMAT(cr.create_time, '%m') AS month_num,  " +
+        "        SUM(CASE   " +
+        "            WHEN s.charge_type IN ('2', '3', '4') THEN s.receivable_amount   " +
+        "            ELSE 0   " +
+        "        END) AS nutritionProducts,  " +
+        "        SUM(CASE   " +
+        "            WHEN s.charge_type = '5' THEN s.receivable_amount   " +
+        "            ELSE 0   " +
+        "        END) AS dietaryIncome,  " +
+        "        SUM(CASE   " +
+        "            WHEN s.charge_type = '0' THEN s.receivable_amount   " +
+        "            ELSE 0   " +
+        "        END) AS screeningAssessment,  " +
+        "        SUM(CASE   " +
+        "            WHEN s.charge_type IN ('2', '3', '4', '5', '0') THEN s.receivable_amount   " +
+        "            ELSE 0   " +
+        "        END) AS totalCollected  " +
+        "    FROM charge_record cr  " +
+        "    INNER JOIN settlement s ON cr.settlement_id = s.id  " +
+        "    WHERE cr.del_flag = '0'  " +
+        "        AND s.del_flag = '0'  " +
+        "        AND YEAR(cr.create_time) = YEAR(CURDATE())  " +
+        "    GROUP BY DATE_FORMAT(cr.create_time, '%m')  " +
+        ")  " +
+        "SELECT   " +
+        "    ym.month_name AS month,  " +
+        "    COALESCE(cd.nutritionProducts, 0) AS nutritionProducts,  " +
+        "    COALESCE(cd.dietaryIncome, 0) AS dietaryIncome,  " +
+        "    COALESCE(cd.screeningAssessment, 0) AS screeningAssessment,  " +
+        "    COALESCE(cd.totalCollected, 0) AS totalCollected  " +
+        "FROM year_months ym  " +
+        "LEFT JOIN charge_data cd ON ym.month_code LIKE CONCAT('%-', LPAD(cd.month_num, 2, '0'))  " +
+        "ORDER BY ym.month_code ")
+    List<Map<String, Object>>selectIncomeList();
 }

+ 23 - 3
ruoyi-admin/src/main/java/org/dromara/web/mapper/ProductInOutRecordMapper.java

@@ -6,6 +6,7 @@ import org.dromara.web.domain.ProductInOutRecord;
 import org.dromara.web.domain.vo.FoodStockBalanceVo;
 import org.dromara.web.domain.vo.ProductInOutRecordVo;
 import org.dromara.common.mybatis.core.mapper.BaseMapperPlus;
+import org.dromara.web.domain.vo.indexData.StorageOverviewVo;
 import org.springframework.stereotype.Repository;
 
 import java.util.List;
@@ -18,7 +19,7 @@ import java.util.List;
  */
 @Repository
 public interface ProductInOutRecordMapper extends BaseMapperPlus<ProductInOutRecord, ProductInOutRecordVo> {
-    @Select(" <script> SELECT  pr.product_id AS productId, pr.category_id AS categoryId, pr.location_id AS locationId,pr.serial_no AS serialNo,pr.product_name AS productName, pr.product_type as productType, " +
+    @Select(" <script> SELECT  pr.product_id AS productId, pr.category_id AS categoryId, pr.location_id AS locationId,pr.serial_no AS serialNo,pr.product_name AS productName, pr.product_type as productType,pr.line_no as lineNo ,  " +
         "pr.category_name AS categoryName,pr.location_name AS locationName,pr.product_no AS productNo,SUM( CASE WHEN pr.type = '0' THEN pr.num ELSE - pr.num END ) AS stockNum," +
         "pr.product_batch_no as productBatchNo,pr.unit, ANY_VALUE(pr.specs_name) as specsName, ANY_VALUE(pr.line_no) as lineNo,ANY_VALUE(pr.invoice_no) as invoiceNo, pr.price, " +
         "ANY_VALUE(pr.warning_month) as warningMonth,ANY_VALUE(pr.manufacture_date) as manufactureDate,ANY_VALUE(pr.expiration_date) as expirationDate  " +
@@ -28,7 +29,7 @@ public interface ProductInOutRecordMapper extends BaseMapperPlus<ProductInOutRec
         "<if test='categoryId != null '> and (pr.category_id = #{categoryId}) </if>" +
         "<if test='productType != null and productType != \"\"'> and (pr.product_type = #{productType}) </if>" +
         "<if test='searchValue != null and searchValue != \"\"'> and (pr.product_name like concat('%', #{searchValue}, '%')) </if>" +
-        "GROUP BY pr.product_id,pr.category_id,pr.location_id,pr.serial_no,pr.product_name,pr.category_name,pr.location_name,pr.product_no,pr.product_batch_no,pr.unit,pr.product_type,pr.price  " +
+        "GROUP BY pr.product_id,pr.category_id,pr.location_id,pr.serial_no,pr.product_name,pr.category_name,pr.location_name,pr.product_no,pr.product_batch_no,pr.unit,pr.product_type,pr.price,pr.line_no  " +
         "<if test='offset != null and rows != null'>LIMIT #{offset}, #{rows}</if>" +
         "</script>" )
     List<ProductInOutRecordVo> queryStockBalance( @Param("productType") String productType,@Param("locationId") Long locationId, @Param("categoryId") Long categoryId, @Param("searchValue") String searchValue, @Param("offset") Integer offset, @Param("rows") Integer rows);
@@ -39,8 +40,27 @@ public interface ProductInOutRecordMapper extends BaseMapperPlus<ProductInOutRec
         "<if test='productType != null and productType != \"\"'> and (pr.product_type = #{productType}) </if>" +
         "    <if test='searchValue != null and searchValue != \"\"'> " +
         "        AND (pr.product_name LIKE CONCAT('%', #{searchValue}, '%') ) </if> " +
-        "    GROUP BY pr.product_id,pr.category_id,pr.location_id,pr.serial_no,pr.product_name,pr.category_name,pr.location_name,pr.product_no,pr.product_batch_no,pr.unit " +
+        "    GROUP BY pr.product_id,pr.category_id,pr.location_id,pr.serial_no,pr.product_name,pr.category_name,pr.location_name,pr.product_no,pr.product_batch_no,pr.unit,pr.line_no " +
         ") AS grouped_data " +
         "</script>" )
     Integer queryStockBalanceCount(@Param("productType") String productType, @Param("locationId") Long locationId, @Param("categoryId") Long categoryId,@Param("searchValue") String searchValue);
+
+    @Select("SELECT  " +
+        "    COUNT(DISTINCT CASE WHEN days_to_expire <= 30 THEN batch_product_id END) AS expiringLicenses,  " +
+        "    COUNT(DISTINCT CASE WHEN warning_month <= 1 THEN batch_product_id END) AS expiringValidity,  " +
+        "    COUNT(DISTINCT CASE WHEN current_stock <= alert_num THEN batch_product_id END) AS inventoryAlerts  " +
+        "FROM (  " +
+        "    SELECT   " +
+        "        CONCAT(product_id, '-', COALESCE(product_batch_no, ''), '-', COALESCE(serial_no, '')) AS batch_product_id,  " +
+        "        alert_num,  " +
+        "        warning_month,  " +
+        "        DATEDIFF(expiration_date, CURDATE()) AS days_to_expire,  " +
+        "        SUM(CASE WHEN type = '0' THEN num ELSE -num END) AS current_stock  " +
+        "    FROM product_in_out_record   " +
+        "    WHERE del_flag = '0'   " +
+        "      AND status = '0'  " +
+        "    GROUP BY product_id, product_batch_no, serial_no, alert_num, warning_month, expiration_date  " +
+        ") AS stock_summary  " +
+        "WHERE current_stock > 0 ")
+    StorageOverviewVo selectCount();
 }

+ 93 - 2
ruoyi-admin/src/main/java/org/dromara/web/service/impl/IndexServiceImpl.java

@@ -2,18 +2,31 @@ package org.dromara.web.service.impl;
 
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
-import org.dromara.web.domain.vo.indexData.IndexDataVo;
-import org.dromara.web.domain.vo.indexData.PatientOverviewVo;
+import org.dromara.web.domain.vo.indexData.*;
+import org.dromara.web.mapper.EnteralNutritionMapper;
 import org.dromara.web.mapper.PatientMedicalRecordMapper;
+import org.dromara.web.mapper.ProductInOutRecordMapper;
 import org.dromara.web.service.IIndexService;
 import org.springframework.stereotype.Service;
 
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
 @Slf4j
 @RequiredArgsConstructor
 @Service
 public class IndexServiceImpl implements IIndexService {
 
     private final PatientMedicalRecordMapper patientMedicalRecordMapper;
+
+    private final EnteralNutritionMapper enteralNutritionMapper;
+
+    private final ProductInOutRecordMapper productInOutRecordMapper;
+
     @Override
     public IndexDataVo queryData() {
         IndexDataVo indexDataVo = new IndexDataVo();
@@ -22,9 +35,87 @@ public class IndexServiceImpl implements IIndexService {
         PatientOverviewVo patientOverviewVo = patientMedicalRecordMapper.selectCount();
         indexDataVo.setPatientOverviewVo(patientOverviewVo);
 
+        //查询处方配置数
+        PrescriptionOverviewVo prescriptionOverviewVo = enteralNutritionMapper.selectCount();
+        indexDataVo.setPrescriptionOverviewVo(prescriptionOverviewVo);
+
+        //查询关注患者
+        List<FocusPatientVo> focusPatientVos = patientMedicalRecordMapper.selectFocusPatients();
+        indexDataVo.setFocusPatientVoList(focusPatientVos);
+        //查询仓储情况总数
+        StorageOverviewVo storageOverviewVo = productInOutRecordMapper.selectCount();
+        indexDataVo.setStorageOverviewVo(storageOverviewVo);
+
+        List<Map<String, Object>> mapList = patientMedicalRecordMapper.selectIncomeList();
+        // 定义累加变量
+        BigDecimal totalCollectedSum = BigDecimal.ZERO;
+        BigDecimal nutritionProductsSum = BigDecimal.ZERO;
+        BigDecimal dietaryIncomeSum = BigDecimal.ZERO;
+        BigDecimal screeningAssessmentSum = BigDecimal.ZERO;
+
+        Map<String, List<BigDecimal>> monthlyData = new LinkedHashMap<>();
+// 初始化每个字段的空列表
+        List<BigDecimal> totalCollectedList = new ArrayList<>();
+        List<BigDecimal> nutritionProductsList = new ArrayList<>();
+        List<BigDecimal> dietaryIncomeList = new ArrayList<>();
+        List<BigDecimal> screeningAssessmentList = new ArrayList<>();
 
+// 如果需要处理月份顺序,可以先对原始数据按月份排序
+        List<Map<String, Object>> sortedList = mapList.stream().sorted((m1, m2) -> {
+            String month1 = (String) m1.get("month");
+            String month2 = (String) m2.get("month");
+            // 这里可以添加月份排序逻辑,如果需要按月份顺序排列
+
+            // 提取月份数字部分
+            int num1 = Integer.parseInt(month1.replaceAll("[^0-9]", ""));
+            int num2 = Integer.parseInt(month2.replaceAll("[^0-9]", ""));
+
+            return Integer.compare(num1, num2);
+        }).collect(Collectors.toList());
+        BigDecimal totalCollected = BigDecimal.ZERO;
+        BigDecimal nutritionProducts = BigDecimal.ZERO;
+        BigDecimal dietaryIncome = BigDecimal.ZERO;
+        BigDecimal screeningAssessment = BigDecimal.ZERO;
+        for (Map<String, Object> row : sortedList) {
+            // 获取各项金额(处理可能的null值)
+            totalCollected = getBigDecimalValue(row.get("totalCollected"));
+            nutritionProducts = getBigDecimalValue(row.get("nutritionProducts"));
+            dietaryIncome = getBigDecimalValue(row.get("dietaryIncome"));
+            screeningAssessment = getBigDecimalValue(row.get("screeningAssessment"));
+
+            // 添加到各自的列表中
+            totalCollectedList.add(totalCollected);
+            nutritionProductsList.add(nutritionProducts);
+            dietaryIncomeList.add(dietaryIncome);
+            screeningAssessmentList.add(screeningAssessment);
+
+            // 累加到总和(保持不变)
+            totalCollectedSum = totalCollectedSum.add(totalCollected);
+            nutritionProductsSum = nutritionProductsSum.add(nutritionProducts);
+            dietaryIncomeSum = dietaryIncomeSum.add(dietaryIncome);
+            screeningAssessmentSum = screeningAssessmentSum.add(screeningAssessment);
+        }
+
+        // 将列表放入最终的map中
+        monthlyData.put("totalCollected", totalCollectedList);
+        monthlyData.put("nutritionProducts", nutritionProductsList);
+        monthlyData.put("dietaryIncome", dietaryIncomeList);
+        monthlyData.put("screeningAssessment", screeningAssessmentList);
+        indexDataVo.setMonthlyData(monthlyData);
+        indexDataVo.setTotalCollectedSum(totalCollectedSum);
+        indexDataVo.setNutritionProductsSum(nutritionProductsSum);
+        indexDataVo.setDietaryIncomeSum(dietaryIncomeSum);
+        indexDataVo.setScreeningAssessmentSum(screeningAssessmentSum);
 
         /**/
         return indexDataVo;
     }
+
+    // 处理BigDecimal null值
+    private BigDecimal getBigDecimalValue(Object value) {
+        if (value == null) {
+            return BigDecimal.ZERO;
+        }
+        return (BigDecimal) value;
+    }
 }

+ 8 - 2
ruoyi-admin/src/main/java/org/dromara/web/service/impl/ProductInOutRecordServiceImpl.java

@@ -180,8 +180,14 @@ public class ProductInOutRecordServiceImpl implements IProductInOutRecordService
         } else {
             bo.setCategoryName(suppliesCategoryMap.get(bo.getCategoryId()));
         }
-        bo.setUnit(specMap.get(bo.getUnit()));
-        bo.setPreUnit(packgeMap.get(bo.getPreUnit()));
+
+        if (StockOperType.OPER_TYPE_ZERO.getCode().equals(bo.getType())){
+            bo.setUnit(specMap.get(bo.getUnit()));
+            bo.setPreUnit(packgeMap.get(bo.getPreUnit()));
+        }else{
+            bo.setUnit(bo.getUnit());
+            bo.setPreUnit(bo.getPreUnit());
+        }
         // 转换并验证实体
         ProductInOutRecord record = MapstructUtils.convert(bo, ProductInOutRecord.class);
         validEntityBeforeSave(record);