From 9f7fd9ba49b2ad983e57987b9d9c14190244e158 Mon Sep 17 00:00:00 2001
From: huminmin <mac@MacBook-Pro.local>
Date: 星期三, 20 五月 2026 15:35:20 +0800
Subject: [PATCH] 导入销售台账,校验产品以及客户是否存在

---
 src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java |   17 +++++++++++++----
 1 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java b/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java
index 0b66aea..05b1ea7 100644
--- a/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java
+++ b/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java
@@ -1,6 +1,7 @@
 package com.ruoyi.sales.service.impl;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
@@ -347,9 +348,17 @@
             if (CollectionUtils.isEmpty(salesLedgerImportDtoList)) return AjaxResult.error("閿�鍞彴璐︽暟鎹负绌猴紒");
             List<SalesLedgerImportDto> salesLedgerProductImportDtoList = stringListMap.get("閿�鍞骇鍝佹暟鎹�");
             if (CollectionUtils.isEmpty(salesLedgerProductImportDtoList)) return AjaxResult.error("閿�鍞骇鍝佹暟鎹负绌猴紒");
-            // 瀹㈡埛鏁版嵁
-            List<Customer> customers = customerMapper.selectList(new LambdaQueryWrapper<Customer>().in(Customer::getCustomerName,
-                    salesLedgerImportDtoList.stream().map(SalesLedgerImportDto::getCustomerName).collect(Collectors.toList())));
+            // 瀹㈡埛鏁版嵁 - 鍙傝�� listPage 鏌ヨ绉佹捣瀹㈡埛锛坱ype = 0锛�
+            // type = 0锛堢娴峰鎴凤級鎴栬�� type = 1锛堝叕娴峰鎴凤級涓斿凡琚垎閰嶏紝骞朵笖鏄嚜宸遍鐢ㄣ�佽嚜宸卞垱寤烘垨鑰呭叡浜粰鑷繁鐨勫鎴�
+            Long loginUserId = loginUser.getUser().getUserId();
+            List<Customer> customers = customerMapper.selectList(new QueryWrapper<Customer>()
+                    .in("customer_name", salesLedgerImportDtoList.stream()
+                            .map(SalesLedgerImportDto::getCustomerName).collect(Collectors.toList()))
+                    .and(wrapper -> wrapper.eq("type", 0)
+                            .or(wrapper2 -> wrapper2.eq("type", 1).eq("is_assigned", 1)))
+                    .and(wrapper -> wrapper.eq("usage_user", loginUserId)
+                            .or(wrapper2 -> wrapper2.eq("create_user", loginUserId)
+                                    .or(wrapper3 -> wrapper3.exists("select 1 from customer_user cu where cu.customer_id = customer.id and cu.user_id = " + loginUserId)))));
 //            // 瑙勬牸鍨嬪彿鏁版嵁
 //            List<ProductModel> productModels = productModelMapper.selectList(new LambdaQueryWrapper<ProductModel>().in(ProductModel::getModel,
 //                    salesLedgerProductImportDtoList.stream().map(SalesLedgerImportDto::getSpecificationModel).collect(Collectors.toList())));
@@ -376,7 +385,7 @@
                         .filter(customer -> customer.getCustomerName().equals(salesLedger.getCustomerName()))
                         .findFirst();
                 if (customerOptional.isEmpty()) {
-                    throw new RuntimeException("瀹㈡埛:" + salesLedger.getCustomerName() + "涓嶅瓨鍦紒");
+                    throw new RuntimeException("瀹㈡埛:" + salesLedger.getCustomerName() + "涓嶅瓨鍦紒鎴栬�呴潪绉佹捣鐢ㄦ埛");
                 }
                 salesLedger.setCustomerId(customerOptional.get().getId());
                 salesLedger.setCustomerContractNo(customerOptional.get().getTaxpayerIdentificationNumber());

--
Gitblit v1.9.3