From bac50872dc8d80fd8c3879f02aa98084db4d6cc8 Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期一, 26 十月 2026 21:53:07 +0800
Subject: [PATCH] fix(basic): 超级管理员查询客户不再受领用/共享范围限制

---
 src/main/resources/mapper/basic/CustomerMapper.xml                  |   14 ++++++++------
 src/main/java/com/ruoyi/basic/service/impl/CustomerServiceImpl.java |   11 +++++++++--
 2 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/src/main/java/com/ruoyi/basic/service/impl/CustomerServiceImpl.java b/src/main/java/com/ruoyi/basic/service/impl/CustomerServiceImpl.java
index 5a4d19a..b2f407d 100644
--- a/src/main/java/com/ruoyi/basic/service/impl/CustomerServiceImpl.java
+++ b/src/main/java/com/ruoyi/basic/service/impl/CustomerServiceImpl.java
@@ -129,7 +129,8 @@
     @Override
     public IPage<CustomerVo> selectCustomerList(Page<CustomerDto> page, CustomerDto customer) {
         LoginUser loginUser = SecurityUtils.getLoginUser();
-        Long loginUserId = loginUser.getUserId();
+        // 瓒呯骇绠$悊鍛樹笉鍙楀鎴烽鐢�/鍏变韩鑼冨洿闄愬埗锛屽彲鏌ョ湅鍏ㄩ儴瀹㈡埛
+        Long loginUserId = isSuperAdmin(loginUser) ? null : loginUser.getUserId();
         IPage<CustomerVo> customerPage = customerMapper.listPage(page, customer, loginUserId);
 
         List<CustomerVo> records = customerPage.getRecords();
@@ -280,10 +281,16 @@
     @Override
     public List<CustomerVo> selectCustomerLists(CustomerDto customer) {
         LoginUser loginUser = SecurityUtils.getLoginUser();
-        Long loginUserId = loginUser.getUserId();
+        // 瓒呯骇绠$悊鍛樹笉鍙楀鎴烽鐢�/鍏变韩鑼冨洿闄愬埗锛屽彲瀵煎嚭鍏ㄩ儴瀹㈡埛
+        Long loginUserId = isSuperAdmin(loginUser) ? null : loginUser.getUserId();
         return customerMapper.list(customer, loginUserId);
     }
 
+    /** 瓒呯骇绠$悊鍛橈細涓嶅彈瀹㈡埛棰嗙敤/鍏变韩鑼冨洿闄愬埗 */
+    private boolean isSuperAdmin(LoginUser loginUser) {
+        return loginUser != null && loginUser.getUser() != null && loginUser.getUser().isAdmin();
+    }
+
     @Override
     public R importData(MultipartFile file, Integer type) {
         try {
diff --git a/src/main/resources/mapper/basic/CustomerMapper.xml b/src/main/resources/mapper/basic/CustomerMapper.xml
index eccb09f..f05c22d 100644
--- a/src/main/resources/mapper/basic/CustomerMapper.xml
+++ b/src/main/resources/mapper/basic/CustomerMapper.xml
@@ -45,8 +45,9 @@
             </if>
             <!-- 绉佹捣鏌ヨ锛歵ype = 0锛堢娴峰鎴凤級鎴栬�� type = 1锛堝叕娴峰鎴凤級涓斿凡琚垎閰嶏紝骞朵笖鏄嚜宸遍鐢ㄣ�佽嚜宸卞垱寤烘垨鑰呭叡浜粰鑷繁鐨勫鎴� -->
             <if test="c.type != null and c.type == 0">
-                and (
-                    (type = #{c.type} or (type = 1 and is_assigned = 1))
+                and (type = #{c.type} or (type = 1 and is_assigned = 1))
+                <!-- loginUserId 涓虹┖琛ㄧず瓒呯骇绠$悊鍛橈紝涓嶅彈棰嗙敤/鍏变韩鑼冨洿闄愬埗 -->
+                <if test="loginUserId != null">
                     and (
                         c.usage_user = #{loginUserId}
                         or c.create_user = #{loginUserId}
@@ -56,7 +57,7 @@
                             and cu.user_id = #{loginUserId}
                         )
                     )
-                )
+                </if>
             </if>
         </where>
         order by c.id desc
@@ -107,8 +108,9 @@
             </if>
             <!-- 绉佹捣鏌ヨ锛歵ype = 0锛堢娴峰鎴凤級鎴栬�� type = 1锛堝叕娴峰鎴凤級涓斿凡琚垎閰嶏紝骞朵笖鏄嚜宸遍鐢ㄣ�佽嚜宸卞垱寤烘垨鑰呭叡浜粰鑷繁鐨勫鎴� -->
             <if test="c.type != null and c.type == 0">
-                and (
-                    (type = #{c.type} or (type = 1 and is_assigned = 1))
+                and (type = #{c.type} or (type = 1 and is_assigned = 1))
+                <!-- loginUserId 涓虹┖琛ㄧず瓒呯骇绠$悊鍛橈紝涓嶅彈棰嗙敤/鍏变韩鑼冨洿闄愬埗 -->
+                <if test="loginUserId != null">
                     and (
                         c.usage_user = #{loginUserId}
                         or c.create_user = #{loginUserId}
@@ -118,7 +120,7 @@
                             and cu.user_id = #{loginUserId}
                         )
                     )
-                )
+                </if>
             </if>
         </where>
         order by c.id desc

--
Gitblit v1.9.3