From 8e4eee5ad4d74e1a4e6ab4de3a9c28000700dce0 Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期二, 03 十一月 2026 13:49:04 +0800
Subject: [PATCH] 修复采购退货页面 ERP 模块已禁用报错
---
yudao-module-erp/src/main/java/cn/iocoder/yudao/module/erp/service/statistics/ErpSaleStatisticsServiceImpl.java | 82 +++++++++++++++++++++++++++++++++++++++++
1 files changed, 82 insertions(+), 0 deletions(-)
diff --git a/yudao-module-erp/src/main/java/cn/iocoder/yudao/module/erp/service/statistics/ErpSaleStatisticsServiceImpl.java b/yudao-module-erp/src/main/java/cn/iocoder/yudao/module/erp/service/statistics/ErpSaleStatisticsServiceImpl.java
index 373d0da..dc1a270 100644
--- a/yudao-module-erp/src/main/java/cn/iocoder/yudao/module/erp/service/statistics/ErpSaleStatisticsServiceImpl.java
+++ b/yudao-module-erp/src/main/java/cn/iocoder/yudao/module/erp/service/statistics/ErpSaleStatisticsServiceImpl.java
@@ -1,11 +1,24 @@
package cn.iocoder.yudao.module.erp.service.statistics;
+import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
+import cn.iocoder.yudao.module.crm.api.customer.CrmCustomerApi;
+import cn.iocoder.yudao.module.crm.api.customer.dto.CrmCustomerRespDTO;
+import cn.iocoder.yudao.module.erp.controller.admin.statistics.vo.sale.ErpSaleCustomerSummaryRespVO;
+import cn.iocoder.yudao.module.erp.controller.admin.statistics.vo.sale.ErpSaleProductSummaryRespVO;
+import cn.iocoder.yudao.module.erp.dal.dataobject.sale.ErpSaleCustomerReceiptStatisticsDO;
+import cn.iocoder.yudao.module.erp.dal.dataobject.sale.ErpSaleCustomerStatisticsDO;
+import cn.iocoder.yudao.module.erp.dal.dataobject.sale.ErpSaleProductStatisticsDO;
import cn.iocoder.yudao.module.erp.dal.mysql.statistics.ErpSaleStatisticsMapper;
+import cn.iocoder.yudao.module.mdm.api.item.MdmItemApi;
+import cn.iocoder.yudao.module.mdm.api.item.dto.MdmItemRespDTO;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.time.LocalDateTime;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
/**
* ERP 閿�鍞粺璁� Service 瀹炵幇绫�
@@ -18,9 +31,78 @@
@Resource
private ErpSaleStatisticsMapper saleStatisticsMapper;
+ @Resource
+ private CrmCustomerApi customerApi;
+
+ @Resource
+ private MdmItemApi mdmItemApi;
+
@Override
public BigDecimal getSalePrice(LocalDateTime beginTime, LocalDateTime endTime) {
return saleStatisticsMapper.getSalePrice(beginTime, endTime);
}
+ @Override
+ public List<ErpSaleCustomerSummaryRespVO> getCustomerSummary(Long customerId, LocalDateTime beginTime, LocalDateTime endTime) {
+ List<ErpSaleCustomerStatisticsDO> saleList = saleStatisticsMapper.selectCustomerStatistics(customerId, beginTime, endTime);
+ if (CollectionUtils.isAnyEmpty(saleList)) {
+ return new ArrayList<>();
+ }
+ // 1. 宸叉敹娆鹃噾棰濇寜瀹㈡埛褰掗泦锛堟敹娆惧崟鍙兘鏃╀簬/鏅氫簬璁㈠崟锛屼笉鍋氳鍗曠骇鍕剧ń锛屽彧鎸夊鎴锋眹鎬伙級
+ Map<Long, BigDecimal> receiptMap = CollectionUtils.convertMap(
+ saleStatisticsMapper.selectCustomerReceiptStatistics(customerId, beginTime, endTime),
+ ErpSaleCustomerReceiptStatisticsDO::getCustomerId,
+ ErpSaleCustomerReceiptStatisticsDO::getReceiptAmount);
+ // 2. 瀹㈡埛鍚嶇О
+ Map<Long, CrmCustomerRespDTO> customerMap = customerApi.getCustomerMap(
+ CollectionUtils.convertSet(saleList, ErpSaleCustomerStatisticsDO::getCustomerId));
+ // 3. 缁勮
+ List<ErpSaleCustomerSummaryRespVO> result = new ArrayList<>(saleList.size());
+ for (ErpSaleCustomerStatisticsDO sale : saleList) {
+ BigDecimal saleAmount = sale.getSaleAmount() == null ? BigDecimal.ZERO : sale.getSaleAmount();
+ BigDecimal receiptAmount = receiptMap.getOrDefault(sale.getCustomerId(), BigDecimal.ZERO);
+ CrmCustomerRespDTO customer = customerMap.get(sale.getCustomerId());
+ ErpSaleCustomerSummaryRespVO vo = new ErpSaleCustomerSummaryRespVO();
+ vo.setCustomerId(sale.getCustomerId());
+ vo.setCustomerName(customer != null ? customer.getName() : "瀹㈡埛(" + sale.getCustomerId() + ")");
+ vo.setOrderCount(sale.getOrderCount());
+ vo.setSaleAmount(saleAmount);
+ vo.setReceiptAmount(receiptAmount);
+ vo.setUnreceivedAmount(saleAmount.subtract(receiptAmount));
+ vo.setLastOrderTime(sale.getLastOrderTime());
+ result.add(vo);
+ }
+ return result;
+ }
+
+ @Override
+ public List<ErpSaleProductSummaryRespVO> getProductSummary(Long productId, LocalDateTime beginTime, LocalDateTime endTime) {
+ List<ErpSaleProductStatisticsDO> saleList = saleStatisticsMapper.selectProductStatistics(productId, beginTime, endTime);
+ if (CollectionUtils.isAnyEmpty(saleList)) {
+ return new ArrayList<>();
+ }
+ // 1. 浜у搧鍚嶇О涓庡弬鑰冩垚鏈环
+ Map<Long, MdmItemRespDTO> itemMap = mdmItemApi.getItemMap(
+ CollectionUtils.convertSet(saleList, ErpSaleProductStatisticsDO::getProductId));
+ // 2. 缁勮锛屾瘺鍒� = 閿�鍞噾棰� - 鏁伴噺 脳 鍙傝�冩垚鏈环
+ List<ErpSaleProductSummaryRespVO> result = new ArrayList<>(saleList.size());
+ for (ErpSaleProductStatisticsDO sale : saleList) {
+ MdmItemRespDTO item = itemMap.get(sale.getProductId());
+ BigDecimal saleAmount = sale.getSaleAmount() == null ? BigDecimal.ZERO : sale.getSaleAmount();
+ BigDecimal costPrice = item != null && item.getCostPrice() != null ? item.getCostPrice() : BigDecimal.ZERO;
+ BigDecimal totalCount = sale.getTotalCount() == null ? BigDecimal.ZERO : sale.getTotalCount();
+ BigDecimal costAmount = costPrice.multiply(totalCount);
+ ErpSaleProductSummaryRespVO vo = new ErpSaleProductSummaryRespVO();
+ vo.setProductId(sale.getProductId());
+ vo.setProductName(item != null ? item.getName() : "浜у搧(" + sale.getProductId() + ")");
+ vo.setOrderCount(sale.getOrderCount());
+ vo.setTotalCount(totalCount);
+ vo.setSaleAmount(saleAmount);
+ vo.setCostAmount(costAmount);
+ vo.setProfitAmount(saleAmount.subtract(costAmount));
+ result.add(vo);
+ }
+ return result;
+ }
+
}
--
Gitblit v1.9.3