From f4ef6d1f4489e0d4cbba1845792945b924c16228 Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期三, 14 十月 2026 18:29:56 +0800
Subject: [PATCH] feat: 客户签订合同统计 + MES 首页质检合格率

---
 yudao-module-crm/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/contract/CrmContractMapper.java |   48 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 48 insertions(+), 0 deletions(-)

diff --git a/yudao-module-crm/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/contract/CrmContractMapper.java b/yudao-module-crm/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/contract/CrmContractMapper.java
index 8b635f1..296d4d5 100644
--- a/yudao-module-crm/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/contract/CrmContractMapper.java
+++ b/yudao-module-crm/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/contract/CrmContractMapper.java
@@ -13,11 +13,17 @@
 import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum;
 import cn.iocoder.yudao.module.crm.enums.common.CrmSceneTypeEnum;
 import cn.iocoder.yudao.module.crm.util.CrmPermissionUtils;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import org.apache.ibatis.annotations.Mapper;
 
 import java.math.BigDecimal;
 import java.time.LocalDateTime;
+import java.util.Collection;
+import java.util.Collections;
 import java.util.List;
+import java.util.Map;
+
+import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
 
 /**
  * CRM 鍚堝悓 Mapper
@@ -70,6 +76,7 @@
                 CrmContractDO::getId, userId, pageReqVO.getSceneType());
         // 鎷兼帴鑷韩鐨勬煡璇㈡潯浠�
         query.selectAll(CrmContractDO.class)
+                .inIfPresent(CrmContractDO::getId, pageReqVO.getIds())
                 .likeIfPresent(CrmContractDO::getNo, pageReqVO.getNo())
                 .likeIfPresent(CrmContractDO::getName, pageReqVO.getName())
                 .eqIfPresent(CrmContractDO::getCustomerId, pageReqVO.getCustomerId())
@@ -206,4 +213,45 @@
                 .reduce(BigDecimal.ZERO, BigDecimal::add);
     }
 
+    // ========== 鎸夊鎴锋壒閲忕粺璁★紙瀹㈡埛鍒楄〃灞曠ず銆岀璁㈠悎鍚屻�嶏級 ==========
+
+    /**
+     * 鎵归噺缁熻鍚勫鎴枫�屽凡绛捐銆嶏紙瀹℃牳閫氳繃锛夌殑鍚堝悓鏁伴噺
+     *
+     * @param customerIds 瀹㈡埛缂栧彿闆嗗悎
+     * @return key锛氬鎴风紪鍙凤紝value锛氬悎鍚屾暟閲忋�傛病鏈夊悎鍚岀殑瀹㈡埛涓嶅湪 map 涓�
+     */
+    default Map<Long, Long> selectContractCountMapByCustomerIds(Collection<Long> customerIds) {
+        if (CollUtil.isEmpty(customerIds)) {
+            return Collections.emptyMap();
+        }
+        List<Map<String, Object>> result = selectMaps(new QueryWrapper<CrmContractDO>()
+                .select("customer_id, COUNT(*) AS total")
+                .eq("audit_status", CrmAuditStatusEnum.APPROVE.getStatus())
+                .groupBy("customer_id")
+                .in("customer_id", customerIds));
+        return convertMap(result, obj -> (Long) obj.get("customer_id"),
+                obj -> ((Number) obj.get("total")).longValue());
+    }
+
+    /**
+     * 鎵归噺缁熻鍚勫鎴枫�屽凡绛捐銆嶏紙瀹℃牳閫氳繃锛夌殑鍚堝悓閲戦鍚堣
+     *
+     * @param customerIds 瀹㈡埛缂栧彿闆嗗悎
+     * @return key锛氬鎴风紪鍙凤紝value锛氶噾棰濆悎璁°�傛病鏈夊悎鍚岀殑瀹㈡埛涓嶅湪 map 涓�
+     */
+    default Map<Long, BigDecimal> selectContractPriceMapByCustomerIds(Collection<Long> customerIds) {
+        if (CollUtil.isEmpty(customerIds)) {
+            return Collections.emptyMap();
+        }
+        // 閲戦鐢� IFNULL 鍏滃簳锛歝onvertMap 鍐呴儴鏄� Collectors.toMap锛寁alue 涓� null 浼氭姏 NPE
+        List<Map<String, Object>> result = selectMaps(new QueryWrapper<CrmContractDO>()
+                .select("customer_id, IFNULL(SUM(total_price), 0) AS total_price")
+                .eq("audit_status", CrmAuditStatusEnum.APPROVE.getStatus())
+                .groupBy("customer_id")
+                .in("customer_id", customerIds));
+        return convertMap(result, obj -> (Long) obj.get("customer_id"),
+                obj -> (BigDecimal) obj.get("total_price"));
+    }
+
 }

--
Gitblit v1.9.3