Prechádzať zdrojové kódy

feat(customer): 实现客户数据权限控制功能

- 在CustomerInfoController中添加数据权限注解和登录用户辅助类
- 实现基于用户角色的数据权限过滤逻辑,限制客户查看权限
- 添加员工服务远程调用以获取当前用户对应的员工信息
- 在CustomerInfoServiceImpl中实现详细的数据权限SQL过滤条件
- 优化供应商信息查询时的空对象过滤处理
hurx 14 hodín pred
rodič
commit
5716f7869a

+ 19 - 0
ruoyi-modules/ruoyi-customer/src/main/java/org/dromara/customer/controller/CustomerInfoController.java

@@ -15,6 +15,7 @@ import org.dromara.common.log.annotation.Log;
 import org.dromara.common.log.enums.BusinessType;
 import org.dromara.common.mybatis.core.page.PageQuery;
 import org.dromara.common.mybatis.core.page.TableDataInfo;
+import org.dromara.common.satoken.utils.LoginHelper;
 import org.dromara.common.web.core.BaseController;
 import org.dromara.customer.domain.bo.*;
 import org.dromara.customer.domain.dto.ReleaseToPoolDto;
@@ -25,6 +26,7 @@ import org.dromara.customer.service.ICustomerInfoService;
 import org.dromara.system.api.*;
 import org.dromara.system.api.domain.vo.RemoteComCompanyVo;
 import org.dromara.system.api.domain.vo.RemoteComCustomerLevelVo;
+import org.dromara.system.api.domain.vo.RemoteComStaffVo;
 import org.springframework.http.MediaType;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
@@ -80,8 +82,25 @@ public class CustomerInfoController extends BaseController {
      * <p>数据权限通过框架 @DataPermission 注解自动处理,
      * 根据角色数据范围(全部/本部门/本部门及以下/仅本人)自动过滤</p>
      */
+//    @DataPermission({
+//        @DataColumn(key = "deptName", value = "create_dept"),
+//        @DataColumn(key = "userName", value = "create_by"),
+//        @DataColumn(key = "salesPersonName", value = "sales_person_id"),
+//        @DataColumn(key = "serviceStaffName", value = "service_staff_id")
+//    })
     @GetMapping("/list")
     public TableDataInfo<CustomerInfoVo> list(CustomerInfoBo bo, PageQuery pageQuery) {
+        Long userId = LoginHelper.getLoginUser().getUserId();
+        RemoteComStaffVo remoteComStaffVo = remoteComStaffService.selectStaffByUserId(userId);
+
+        // 设置数据权限过滤:只能查看自己创建的、或者是业务负责人、或者是客服支持的客户
+        if (remoteComStaffVo != null && remoteComStaffVo.getStaffId() != null) {
+            Long staffId = remoteComStaffVo.getStaffId();
+            // 将权限条件传递到查询条件中
+            bo.setCreateBy(userId);
+            bo.setSalesPersonId(staffId);
+            bo.setServiceStaffId(staffId);
+        }
         return customerInfoService.queryPageList(bo, pageQuery);
     }
 

+ 14 - 4
ruoyi-modules/ruoyi-customer/src/main/java/org/dromara/customer/dubbo/RemoteSupplierInfoServiceImpl.java

@@ -11,9 +11,7 @@ import org.dromara.customer.api.domain.dto.SupplierAreaDTO;
 import org.dromara.customer.api.domain.dto.SupplierAuthorizeDTO;
 import org.dromara.customer.domain.ContractSupply;
 import org.dromara.customer.domain.SupplierContact;
-import org.dromara.customer.domain.SupplierInfo;
 import org.dromara.customer.domain.SupplyArea;
-import org.dromara.customer.domain.vo.SupplyAreaVo;
 import org.dromara.customer.service.*;
 import org.springframework.stereotype.Service;
 
@@ -61,12 +59,15 @@ public class RemoteSupplierInfoServiceImpl implements RemoteSupplierInfoService
     }
 
     @Override
-    public List<Long> getSupplierIdsBySupplyArea(String areaname,String level) {
-        return supplyAreaService.getSupplierIdsBySupplyArea(areaname,level);
+    public List<Long> getSupplierIdsBySupplyArea(String areaname, String level) {
+        return supplyAreaService.getSupplierIdsBySupplyArea(areaname, level);
     }
 
     @Override
     public List<Long> getContractIdBySupplySupplierID(Set<Long> SupplierID) {
+        if (CollUtil.isEmpty(SupplierID)) {
+            return Collections.emptyList();
+        }
         return contractSupplyService.list(
             Wrappers.lambdaQuery(ContractSupply.class)
                 .in(ContractSupply::getSupplierId, SupplierID)
@@ -76,6 +77,9 @@ public class RemoteSupplierInfoServiceImpl implements RemoteSupplierInfoService
 
     @Override
     public Map<Long, Long> contractToSupplierMap(List<Long> contractSupplyIds) {
+        if (CollUtil.isEmpty(contractSupplyIds)) {
+            return Collections.emptyMap();
+        }
         List<ContractSupply> list = contractSupplyService.list(
             new LambdaQueryWrapper<ContractSupply>().in(ContractSupply::getId, contractSupplyIds)
         );
@@ -86,6 +90,9 @@ public class RemoteSupplierInfoServiceImpl implements RemoteSupplierInfoService
 
     @Override
     public Map<Long, String> selectEnterpriseNameByIds(List<Long> ids) {
+        if (CollUtil.isEmpty(ids)) {
+            return Collections.emptyMap();
+        }
         List<ContractSupply> list = contractSupplyService.list(
             new LambdaQueryWrapper<ContractSupply>().in(ContractSupply::getId, ids)
         );
@@ -115,6 +122,9 @@ public class RemoteSupplierInfoServiceImpl implements RemoteSupplierInfoService
 
     @Override
     public Map<Long, SupplierAreaDTO> selectSupplierInfoByContractIds(List<Long> contractSupplyIds) {
+        if (CollUtil.isEmpty(contractSupplyIds)) {
+            return Collections.emptyMap();
+        }
         // 1 查询合同供货
         List<ContractSupply> list = contractSupplyService.list(
             new LambdaQueryWrapper<ContractSupply>()

+ 32 - 2
ruoyi-modules/ruoyi-customer/src/main/java/org/dromara/customer/service/impl/CustomerInfoServiceImpl.java

@@ -746,7 +746,37 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
         Map<String, Object> params = bo.getParams();
         LambdaQueryWrapper<CustomerInfo> lqw = Wrappers.lambdaQuery();
         lqw.orderByDesc(CustomerInfo::getId);
-
+        // 数据权限过滤:只能查看自己创建的、或者是业务负责人、或者是客服支持的客户
+        // 超级管理员或租户管理员可查看全部数据
+        if (!LoginHelper.isSuperAdmin() && !LoginHelper.isTenantAdmin()
+            && (bo.getCreateBy() != null || bo.getSalesPersonId() != null || bo.getServiceStaffId() != null)) {
+            lqw.and(wrapper -> {
+                boolean first = true;
+                if (bo.getCreateBy() != null) {
+                    if (first) {
+                        wrapper.eq(CustomerInfo::getCreateBy, bo.getCreateBy());
+                        first = false;
+                    } else {
+                        wrapper.or().eq(CustomerInfo::getCreateBy, bo.getCreateBy());
+                    }
+                }
+                if (bo.getSalesPersonId() != null) {
+                    if (first) {
+                        wrapper.eq(CustomerInfo::getSalesPersonId, bo.getSalesPersonId());
+                        first = false;
+                    } else {
+                        wrapper.or().eq(CustomerInfo::getSalesPersonId, bo.getSalesPersonId());
+                    }
+                }
+                if (bo.getServiceStaffId() != null) {
+                    if (first) {
+                        wrapper.eq(CustomerInfo::getServiceStaffId, bo.getServiceStaffId());
+                    } else {
+                        wrapper.or().eq(CustomerInfo::getServiceStaffId, bo.getServiceStaffId());
+                    }
+                }
+            });
+        }
         lqw.eq(StringUtils.isNotBlank(bo.getCustomerNo()), CustomerInfo::getCustomerNo, bo.getCustomerNo());
         lqw.eq(bo.getBelongCompanyId() != null, CustomerInfo::getBelongCompanyId, bo.getBelongCompanyId());
         lqw.like(StringUtils.isNotBlank(bo.getCompanyName()), CustomerInfo::getCompanyName, bo.getCompanyName());
@@ -1783,7 +1813,7 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
         }
         return flag;
     }
-    
+
     /**
      * 修改客户信息 客户导入时只需要导入主数据
      *

+ 1 - 1
ruoyi-modules/ruoyi-customer/src/main/java/org/dromara/customer/service/impl/SupplierInfoServiceImpl.java

@@ -824,7 +824,7 @@ public class SupplierInfoServiceImpl extends ServiceImpl<SupplierInfoMapper, Sup
                 vo.setSupplierNo(supplierInfo.getSupplierNo());
 //                vo.setSupplyStatus(supplierInfo.getSupplyStatus());
                 return vo;
-            }).collect(Collectors.toList());
+            }).filter(Objects::nonNull).collect(Collectors.toList());
 
             // 批量处理扩展信息
             supplierVos = batchHandleBaseExtInfo(supplierVos);

+ 1 - 2
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/controller/system/SysDeptController.java

@@ -1,6 +1,5 @@
 package org.dromara.system.controller.system;
 
-import cn.dev33.satoken.annotation.SaCheckPermission;
 import cn.hutool.core.convert.Convert;
 import lombok.RequiredArgsConstructor;
 import org.dromara.common.core.constant.SystemConstants;
@@ -35,7 +34,7 @@ public class SysDeptController extends BaseController {
     /**
      * 获取部门列表
      */
-    @SaCheckPermission("system:dept:list")
+//    @SaCheckPermission("system:dept:list")
     @GetMapping("/list")
     public R<List<SysDeptVo>> list(SysDeptBo dept) {
         List<SysDeptVo> depts = deptService.selectDeptList(dept);