Parcourir la source

膳食库存报表

Huanyi il y a 1 mois
Parent
commit
c5d539abbc

+ 1 - 1
ruoyi-admin/src/main/java/org/dromara/web/controller/ReportController.java

@@ -66,7 +66,7 @@ public class ReportController {
 
     @GetMapping("/dietaryInventory")
     @SaCheckPermission("report:dietaryInventory:list")
-    public TableDataInfo listPageDietaryInventory(DietaryInventoryBo bo, PageQuery pageQuery) {
+    public TableDataInfo<DietaryInventoryVo> listPageDietaryInventory(DietaryInventoryBo bo, PageQuery pageQuery) {
         return reportService.listPageDietaryInventory(bo, pageQuery);
     }
 

+ 23 - 0
ruoyi-admin/src/main/java/org/dromara/web/domain/bo/DietaryInventoryBo.java

@@ -2,6 +2,8 @@ package org.dromara.web.domain.bo;
 
 import lombok.Data;
 
+import java.util.Date;
+
 /**
  * @Author: Huanyi
  * @CreateTime: 2025-08-18
@@ -11,4 +13,25 @@ import lombok.Data;
 
 @Data
 public class DietaryInventoryBo {
+
+    /**
+     * 最早统计日期
+     */
+    private Date statisticalDateEarliest;
+
+    /**
+     * 最晚统计日期
+     */
+    private Date statisticalDateLatest;
+
+    /**
+     * 食物分类ID
+     */
+    private Long categoryId;
+
+    /**
+     * 食材名称
+     */
+    private String foodName;
+
 }

+ 61 - 0
ruoyi-admin/src/main/java/org/dromara/web/domain/vo/DietaryInventoryVo.java

@@ -2,6 +2,9 @@ package org.dromara.web.domain.vo;
 
 import lombok.Data;
 
+import java.math.BigDecimal;
+import java.util.Date;
+
 /**
  * @Author: Huanyi
  * @CreateTime: 2025-08-19
@@ -12,6 +15,64 @@ import lombok.Data;
 @Data
 public class DietaryInventoryVo {
 
+    /**
+     * 统计日期
+     */
+    private Date statisticalDate;
+
+    /**
+     * 食材名称
+     */
+    private String foodName;
+
+    /**
+     * 食材大类
+     */
+    private String foodFirstCategory;
+
+    /**
+     * 食材亚类
+     */
+    private String foodSecondCategory;
+
+    /**
+     * 库存单位
+     */
+    private String inventoryUnit;
+
+    /**
+     * 手动入库数量
+     */
+    private BigDecimal manualInventoryQuantity;
+
+    /**
+     * 入库总量
+     */
+    private BigDecimal inventoryTotal;
+
+    /**
+     * 手动出库数量
+     */
+    private BigDecimal manualOutboundQuantity;
+
+    /**
+     * 处方出库数量
+     */
+    private BigDecimal nutritionOutboundQuantity;
+
+    /**
+     * 出库总量
+     */
+    private BigDecimal outboundTotal;
+
+    /**
+     * 制餐耗损
+     */
+    private BigDecimal mealPreparationLoss;
 
+    /**
+     * 退费耗损
+     */
+    private BigDecimal refundLoss;
 
 }

+ 79 - 1
ruoyi-admin/src/main/java/org/dromara/web/service/impl/ReportServiceImpl.java

@@ -10,6 +10,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.dromara.common.core.domain.R;
+import org.dromara.common.core.utils.StringUtils;
 import org.dromara.common.mybatis.core.page.PageQuery;
 import org.dromara.common.mybatis.core.page.TableDataInfo;
 import org.dromara.system.domain.SysDept;
@@ -64,6 +65,8 @@ public class ReportServiceImpl implements ReportService {
     private final NutritionEducationMapper nutritionEducationMapper;
     private final SysScreeningAssessmentConfigMapper sysScreeningAssessmentConfigMapper;
     private final SysDiseaseLabelMapper sysDiseaseLabelMapper;
+    private final FoodIngredientStockMapper foodIngredientStockMapper;
+    private final SysFoodCategoryMapper sysFoodCategoryMapper;
 
     @Override
     public R getNutritionalQualityControl(Timestamp start, Timestamp end) {
@@ -304,7 +307,82 @@ public class ReportServiceImpl implements ReportService {
 
     @Override
     public TableDataInfo listPageDietaryInventory(DietaryInventoryBo bo, PageQuery pageQuery) {
-        return null;
+
+        Map<String, String> unitMap = new HashMap<>();
+        Map<Long, String> categoryMap = new HashMap<>();
+        sysDictDataMapper.selectDictDataByType("product_package_unit").forEach(e -> unitMap.put(e.getDictValue(), e.getDictLabel()));
+        sysFoodCategoryMapper.selectList().forEach(e -> categoryMap.put(e.getFoodCategoryId(), e.getName()));
+
+        List<Long> ids = new ArrayList<>();
+
+        Page<SysFoodIngredient> page = sysFoodIngredientMapper.selectPage(
+            pageQuery.build(),
+            Wrappers.lambdaQuery(SysFoodIngredient.class)
+                .like(StringUtils.isNotEmpty(bo.getFoodName()), SysFoodIngredient::getName, bo.getFoodName())
+        );
+        page.getRecords().forEach(e -> ids.add(e.getFoodIngredientId()));
+
+        List<FoodIngredientStock> stocks = foodIngredientStockMapper.selectList(
+            Wrappers.lambdaQuery(FoodIngredientStock.class)
+                .in(!ids.isEmpty(), FoodIngredientStock::getFoodId, ids)
+                .ge(bo.getStatisticalDateEarliest() != null, FoodIngredientStock::getCreateTime, bo.getStatisticalDateEarliest())
+                .le(bo.getStatisticalDateLatest() != null, FoodIngredientStock::getCreateTime, bo.getStatisticalDateEarliest())
+        );
+
+        return TableDataInfo.build(page.convert(ingredient -> {
+            DietaryInventoryVo vo = new DietaryInventoryVo();
+            vo.setStatisticalDate(new Date());
+            vo.setFoodName(ingredient.getName());
+
+            BigDecimal manualInventoryQuantity = new BigDecimal("0");
+            BigDecimal inventoryTotal = new BigDecimal("0");
+            BigDecimal outboundTotal = new BigDecimal("0");
+            BigDecimal manualOutboundQuantity = new BigDecimal("0");
+            BigDecimal nutritionOutboundQuantity = new BigDecimal("0");
+            BigDecimal refundLoss = new BigDecimal("0");
+            BigDecimal mealPreparationLoss = new BigDecimal("0");
+            for (FoodIngredientStock stock : stocks) {
+                if (Objects.equals(stock.getFoodId(), ingredient.getFoodIngredientId())) {
+
+//                    if (foodFirstCategory == null) foodFirstCategory = stock.getMainClassName();
+//                    if (foodSecondCategory == null) foodSecondCategory = stock.getSubClassName();
+//                    if (unit == null) unit = unitMap.get(stock.getStockUnit());
+
+                    switch (stock.getType()) {
+                        case "0" -> {
+                            manualInventoryQuantity = manualInventoryQuantity.add(stock.getNum());
+                            inventoryTotal = inventoryTotal.add(stock.getNum());
+                        }
+                        case "1" -> {
+                            outboundTotal = outboundTotal.add(stock.getNum());
+                            manualOutboundQuantity = manualInventoryQuantity.add(stock.getNum());
+                        }
+                        case "2" -> {
+                            outboundTotal = outboundTotal.add(stock.getNum());
+                            nutritionOutboundQuantity = nutritionOutboundQuantity.add(stock.getNum());
+                            mealPreparationLoss = mealPreparationLoss.add(stock.getNum());
+                        }
+                        case "3" -> {
+                            refundLoss = refundLoss.add(stock.getNum());
+                        }
+                    }
+
+                }
+            }
+
+            String[] categoryIds = ingredient.getFoodCategoryId().split(",");
+            vo.setFoodFirstCategory(categoryMap.get(Long.valueOf(categoryIds[0])));
+            vo.setFoodSecondCategory(categoryMap.get(Long.valueOf(categoryIds[1])));
+            vo.setInventoryUnit(unitMap.get(ingredient.getUnit()));
+            vo.setManualInventoryQuantity(manualInventoryQuantity);
+            vo.setInventoryTotal(inventoryTotal);
+            vo.setManualOutboundQuantity(manualOutboundQuantity);
+            vo.setNutritionOutboundQuantity(nutritionOutboundQuantity);
+            vo.setOutboundTotal(outboundTotal);
+            vo.setMealPreparationLoss(new BigDecimal("5").multiply(mealPreparationLoss));
+            vo.setRefundLoss(refundLoss);
+            return vo;
+        }));
     }
 
     @Override