Browse Source

完善 CRM-客户 数据权限校验

puhui999 1 year ago
parent
commit
c2fd817989
23 changed files with 129 additions and 70 deletions
  1. 1 1
      yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/business/CrmBusinessController.java
  2. 2 2
      yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/ContactController.java
  3. 1 1
      yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/vo/CrmTransferContactReqVO.java
  4. 2 2
      yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contract/ContractController.java
  5. 9 1
      yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contract/vo/CrmTransferContractReqVO.java
  6. 10 1
      yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/CrmCustomerController.java
  7. 28 0
      yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/CrmTransferCustomerReqVO.java
  8. 1 1
      yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/convert/contact/ContactConvert.java
  9. 1 1
      yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/convert/contract/ContractConvert.java
  10. 13 5
      yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/convert/customer/CrmCustomerConvert.java
  11. 5 5
      yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/clue/CrmClueMapper.java
  12. 5 6
      yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/contact/ContactMapper.java
  13. 1 1
      yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/business/CrmBusinessService.java
  14. 1 4
      yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/business/CrmBusinessServiceImpl.java
  15. 1 1
      yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contact/ContactService.java
  16. 1 1
      yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contact/ContactServiceImpl.java
  17. 1 1
      yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contract/ContractService.java
  18. 1 1
      yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contract/ContractServiceImpl.java
  19. 11 5
      yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerService.java
  20. 31 5
      yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerServiceImpl.java
  21. 0 18
      yudao-module-crm/yudao-module-crm-biz/src/test/java/cn/iocoder/yudao/module/crm/service/business/CrmBusinessServiceImplTest.java
  22. 0 6
      yudao-module-crm/yudao-module-crm-biz/src/test/java/cn/iocoder/yudao/module/crm/service/clue/CrmClueServiceImplTest.java
  23. 3 1
      yudao-module-crm/yudao-module-crm-biz/src/test/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerServiceImplTest.java

+ 1 - 1
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/business/CrmBusinessController.java

@@ -92,7 +92,7 @@ public class CrmBusinessController {
     @Operation(summary = "商机转移")
     @PreAuthorize("@ss.hasPermission('crm:business:update')")
     public CommonResult<Boolean> transfer(@Valid @RequestBody CrmTransferBusinessReqVO reqVO) {
-        businessService.businessTransfer(reqVO, getLoginUserId());
+        businessService.transferBusiness(reqVO, getLoginUserId());
         return success(true);
     }
 

+ 2 - 2
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/ContactController.java

@@ -100,8 +100,8 @@ public class ContactController {
     @PutMapping("/transfer")
     @Operation(summary = "联系人转移")
     @PreAuthorize("@ss.hasPermission('crm:contact:update')")
-    public CommonResult<Boolean> transfer(@Valid @RequestBody CrmContactTransferReqVO reqVO) {
-        contactService.contactTransfer(reqVO, getLoginUserId());
+    public CommonResult<Boolean> transfer(@Valid @RequestBody CrmTransferContactReqVO reqVO) {
+        contactService.transferContact(reqVO, getLoginUserId());
         return success(true);
     }
 

+ 1 - 1
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/vo/CrmContactTransferReqVO.java → yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/vo/CrmTransferContactReqVO.java

@@ -7,7 +7,7 @@ import javax.validation.constraints.NotNull;
 
 @Schema(description = "管理后台 - 联系人转移 Request VO")
 @Data
-public class CrmContactTransferReqVO {
+public class CrmTransferContactReqVO {
 
     @Schema(description = "联系人编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430")
     @NotNull(message = "联系人编号不能为空")

+ 2 - 2
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contract/ContractController.java

@@ -90,8 +90,8 @@ public class ContractController {
     @PutMapping("/transfer")
     @Operation(summary = "合同转移")
     @PreAuthorize("@ss.hasPermission('crm:contract:update')")
-    public CommonResult<Boolean> transfer(@Valid @RequestBody CrmContractTransferReqVO reqVO) {
-        contractService.contractTransfer(reqVO, getLoginUserId());
+    public CommonResult<Boolean> transfer(@Valid @RequestBody CrmTransferContractReqVO reqVO) {
+        contractService.transferContract(reqVO, getLoginUserId());
         return success(true);
     }
 

+ 9 - 1
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contract/vo/CrmContractTransferReqVO.java → yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contract/vo/CrmTransferContractReqVO.java

@@ -7,7 +7,7 @@ import javax.validation.constraints.NotNull;
 
 @Schema(description = "管理后台 - 合同转移 Request VO")
 @Data
-public class CrmContractTransferReqVO {
+public class CrmTransferContractReqVO {
 
     @Schema(description = "合同编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430")
     @NotNull(message = "合同编号不能为空")
@@ -17,4 +17,12 @@ public class CrmContractTransferReqVO {
     @NotNull(message = "新负责人的用户编号不能为空")
     private Long ownerUserId;
 
+    @Schema(description = "原负责人移除方式", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430")
+    @NotNull(message = "原负责人移除方式不能为空")
+    private Integer transferType;
+
+    @Schema(description = "权限类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430")
+    @NotNull(message = "权限类型不能为空")
+    private Integer permissionType;
+
 }

+ 10 - 1
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/CrmCustomerController.java

@@ -23,6 +23,7 @@ import java.util.List;
 
 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
 import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
+import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
 
 @Tag(name = "管理后台 - 客户")
 @RestController
@@ -37,7 +38,7 @@ public class CrmCustomerController {
     @Operation(summary = "创建客户")
     @PreAuthorize("@ss.hasPermission('crm:customer:create')")
     public CommonResult<Long> createCustomer(@Valid @RequestBody CrmCustomerCreateReqVO createReqVO) {
-        return success(customerService.createCustomer(createReqVO));
+        return success(customerService.createCustomer(createReqVO, getLoginUserId()));
     }
 
     @PutMapping("/update")
@@ -86,4 +87,12 @@ public class CrmCustomerController {
         ExcelUtils.write(response, "客户.xls", "数据", CrmCustomerExcelVO.class, datas);
     }
 
+    @PutMapping("/transfer")
+    @Operation(summary = "客户转移")
+    @PreAuthorize("@ss.hasPermission('crm:customer:update')")
+    public CommonResult<Boolean> transfer(@Valid @RequestBody CrmTransferCustomerReqVO reqVO) {
+        customerService.transferCustomer(reqVO, getLoginUserId());
+        return success(true);
+    }
+
 }

+ 28 - 0
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/vo/CrmTransferCustomerReqVO.java

@@ -0,0 +1,28 @@
+package cn.iocoder.yudao.module.crm.controller.admin.customer.vo;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+import javax.validation.constraints.NotNull;
+
+@Schema(description = "管理后台 - 客户转移 Request VO")
+@Data
+public class CrmTransferCustomerReqVO {
+
+    @Schema(description = "客户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430")
+    @NotNull(message = "客户编号不能为空")
+    private Long id;
+
+    @Schema(description = "新负责人的用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430")
+    @NotNull(message = "新负责人的用户编号不能为空")
+    private Long ownerUserId;
+
+    @Schema(description = "原负责人移除方式", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430")
+    @NotNull(message = "原负责人移除方式不能为空")
+    private Integer transferType;
+
+    @Schema(description = "权限类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "10430")
+    @NotNull(message = "权限类型不能为空")
+    private Integer permissionType;
+
+}

+ 1 - 1
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/convert/contact/ContactConvert.java

@@ -37,6 +37,6 @@ public interface ContactConvert {
             @Mapping(target = "userId", source = "userId"),
             @Mapping(target = "crmDataId", source = "reqVO.id")
     })
-    TransferCrmPermissionBO convert(CrmContactTransferReqVO reqVO, Long userId);
+    TransferCrmPermissionBO convert(CrmTransferContactReqVO reqVO, Long userId);
 
 }

+ 1 - 1
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/convert/contract/ContractConvert.java

@@ -37,6 +37,6 @@ public interface ContractConvert {
             @Mapping(target = "userId", source = "userId"),
             @Mapping(target = "crmDataId", source = "reqVO.id")
     })
-    TransferCrmPermissionBO convert(CrmContractTransferReqVO reqVO, Long userId);
+    TransferCrmPermissionBO convert(CrmTransferContractReqVO reqVO, Long userId);
 
 }

+ 13 - 5
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/convert/customer/CrmCustomerConvert.java

@@ -1,13 +1,15 @@
 package cn.iocoder.yudao.module.crm.convert.customer;
 
-import java.util.*;
-
 import cn.iocoder.yudao.framework.common.pojo.PageResult;
-
-import org.mapstruct.Mapper;
-import org.mapstruct.factory.Mappers;
 import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.*;
 import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
+import cn.iocoder.yudao.module.crm.service.permission.bo.TransferCrmPermissionBO;
+import org.mapstruct.Mapper;
+import org.mapstruct.Mapping;
+import org.mapstruct.Mappings;
+import org.mapstruct.factory.Mappers;
+
+import java.util.List;
 
 /**
  * 客户 Convert
@@ -29,4 +31,10 @@ public interface CrmCustomerConvert {
 
     List<CrmCustomerExcelVO> convertList02(List<CrmCustomerDO> list);
 
+    @Mappings({
+            @Mapping(target = "userId", source = "userId"),
+            @Mapping(target = "crmDataId", source = "reqVO.id")
+    })
+    TransferCrmPermissionBO convert(CrmTransferCustomerReqVO reqVO, Long userId);
+
 }

+ 5 - 5
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/clue/CrmClueMapper.java

@@ -1,13 +1,14 @@
 package cn.iocoder.yudao.module.crm.dal.mysql.clue;
 
-import java.util.*;
-
 import cn.iocoder.yudao.framework.common.pojo.PageResult;
-import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
 import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
+import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
+import cn.iocoder.yudao.module.crm.controller.admin.clue.vo.CrmClueExportReqVO;
+import cn.iocoder.yudao.module.crm.controller.admin.clue.vo.CrmCluePageReqVO;
 import cn.iocoder.yudao.module.crm.dal.dataobject.clue.CrmClueDO;
 import org.apache.ibatis.annotations.Mapper;
-import cn.iocoder.yudao.module.crm.controller.admin.clue.vo.*;
+
+import java.util.List;
 
 /**
  * 线索 Mapper
@@ -35,7 +36,6 @@ public interface CrmClueMapper extends BaseMapperX<CrmClueDO> {
                 .likeIfPresent(CrmClueDO::getTelephone, reqVO.getTelephone())
                 .likeIfPresent(CrmClueDO::getMobile, reqVO.getMobile())
                 .likeIfPresent(CrmClueDO::getAddress, reqVO.getAddress())
-                .eqIfPresent(CrmClueDO::getOwnerUserId, reqVO.getOwnerUserId())
                 .betweenIfPresent(CrmClueDO::getContactLastTime, reqVO.getContactLastTime())
                 .betweenIfPresent(CrmClueDO::getCreateTime, reqVO.getCreateTime())
                 .orderByDesc(CrmClueDO::getId));

+ 5 - 6
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/contact/ContactMapper.java

@@ -1,13 +1,14 @@
 package cn.iocoder.yudao.module.crm.dal.mysql.contact;
 
-import java.util.*;
-
 import cn.iocoder.yudao.framework.common.pojo.PageResult;
-import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
 import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
+import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
+import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.ContactExportReqVO;
+import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.ContactPageReqVO;
 import cn.iocoder.yudao.module.crm.dal.dataobject.contact.ContactDO;
 import org.apache.ibatis.annotations.Mapper;
-import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.*;
+
+import java.util.List;
 
 /**
  * crm联系人 Mapper
@@ -28,7 +29,6 @@ public interface ContactMapper extends BaseMapperX<ContactDO> {
                 .eqIfPresent(ContactDO::getCustomerId, reqVO.getCustomerId())
                 .eqIfPresent(ContactDO::getAddress, reqVO.getAddress())
                 .eqIfPresent(ContactDO::getRemark, reqVO.getRemark())
-                .eqIfPresent(ContactDO::getOwnerUserId, reqVO.getOwnerUserId())
                 .betweenIfPresent(ContactDO::getCreateTime, reqVO.getCreateTime())
                 .betweenIfPresent(ContactDO::getLastTime, reqVO.getLastTime())
                 .orderByDesc(ContactDO::getId));
@@ -45,7 +45,6 @@ public interface ContactMapper extends BaseMapperX<ContactDO> {
                 .eqIfPresent(ContactDO::getCustomerId, reqVO.getCustomerId())
                 .eqIfPresent(ContactDO::getAddress, reqVO.getAddress())
                 .eqIfPresent(ContactDO::getRemark, reqVO.getRemark())
-                .eqIfPresent(ContactDO::getOwnerUserId, reqVO.getOwnerUserId())
                 .betweenIfPresent(ContactDO::getCreateTime, reqVO.getCreateTime())
                 .betweenIfPresent(ContactDO::getLastTime, reqVO.getLastTime())
                 .orderByDesc(ContactDO::getId));

+ 1 - 1
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/business/CrmBusinessService.java

@@ -76,6 +76,6 @@ public interface CrmBusinessService {
      * @param reqVO  请求
      * @param userId 用户编号
      */
-    void businessTransfer(CrmTransferBusinessReqVO reqVO, Long userId);
+    void transferBusiness(CrmTransferBusinessReqVO reqVO, Long userId);
 
 }

+ 1 - 4
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/business/CrmBusinessServiceImpl.java

@@ -12,7 +12,6 @@ import cn.iocoder.yudao.module.crm.framework.enums.CrmEnum;
 import cn.iocoder.yudao.module.crm.framework.enums.OperationTypeEnum;
 import cn.iocoder.yudao.module.crm.service.permission.CrmPermissionService;
 import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionCreateBO;
-import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.validation.annotation.Validated;
@@ -36,8 +35,6 @@ public class CrmBusinessServiceImpl implements CrmBusinessService {
     @Resource
     private CrmBusinessMapper businessMapper;
 
-    @Resource
-    private AdminUserApi adminUserApi;
     @Resource
     private CrmPermissionService crmPermissionService;
 
@@ -111,7 +108,7 @@ public class CrmBusinessServiceImpl implements CrmBusinessService {
 
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public void businessTransfer(CrmTransferBusinessReqVO reqVO, Long userId) {
+    public void transferBusiness(CrmTransferBusinessReqVO reqVO, Long userId) {
         // 1 校验商机是否存在
         validateBusinessExists(reqVO.getId());
 

+ 1 - 1
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contact/ContactService.java

@@ -76,6 +76,6 @@ public interface ContactService {
      * @param reqVO  请求
      * @param userId 用户编号
      */
-    void contactTransfer(CrmContactTransferReqVO reqVO, Long userId);
+    void transferContact(CrmTransferContactReqVO reqVO, Long userId);
 
 }

+ 1 - 1
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contact/ContactServiceImpl.java

@@ -109,7 +109,7 @@ public class ContactServiceImpl implements ContactService {
     }
 
     @Override
-    public void contactTransfer(CrmContactTransferReqVO reqVO, Long userId) {
+    public void transferContact(CrmTransferContactReqVO reqVO, Long userId) {
         // 1 校验联系人是否存在
         validateContactExists(reqVO.getId());
 

+ 1 - 1
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contract/ContractService.java

@@ -76,6 +76,6 @@ public interface ContractService {
      * @param reqVO  请求
      * @param userId 用户编号
      */
-    void contractTransfer(CrmContractTransferReqVO reqVO, Long userId);
+    void transferContract(CrmTransferContractReqVO reqVO, Long userId);
 
 }

+ 1 - 1
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contract/ContractServiceImpl.java

@@ -107,7 +107,7 @@ public class ContractServiceImpl implements ContractService {
 
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public void contractTransfer(CrmContractTransferReqVO reqVO, Long userId) {
+    public void transferContract(CrmTransferContractReqVO reqVO, Long userId) {
         // 1 校验合同是否存在
         validateContractExists(reqVO.getId());
 

+ 11 - 5
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerService.java

@@ -1,10 +1,7 @@
 package cn.iocoder.yudao.module.crm.service.customer;
 
 import cn.iocoder.yudao.framework.common.pojo.PageResult;
-import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerCreateReqVO;
-import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerExportReqVO;
-import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerPageReqVO;
-import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerUpdateReqVO;
+import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.*;
 import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
 
 import javax.validation.Valid;
@@ -22,9 +19,10 @@ public interface CrmCustomerService {
      * 创建客户
      *
      * @param createReqVO 创建信息
+     * @param userId      用户编号
      * @return 编号
      */
-    Long createCustomer(@Valid CrmCustomerCreateReqVO createReqVO);
+    Long createCustomer(@Valid CrmCustomerCreateReqVO createReqVO, Long userId);
 
     /**
      * 更新客户
@@ -80,4 +78,12 @@ public interface CrmCustomerService {
      */
     CrmCustomerDO validateCustomer(Long customerId);
 
+    /**
+     * 客户转移
+     *
+     * @param reqVO  请求
+     * @param userId 用户编号
+     */
+    void transferCustomer(CrmTransferCustomerReqVO reqVO, Long userId);
+
 }

+ 31 - 5
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerServiceImpl.java

@@ -3,15 +3,18 @@ package cn.iocoder.yudao.module.crm.service.customer;
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.collection.ListUtil;
 import cn.iocoder.yudao.framework.common.pojo.PageResult;
-import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerCreateReqVO;
-import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerExportReqVO;
-import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerPageReqVO;
-import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerUpdateReqVO;
+import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.*;
 import cn.iocoder.yudao.module.crm.convert.customer.CrmCustomerConvert;
 import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
 import cn.iocoder.yudao.module.crm.dal.mysql.customer.CrmCustomerMapper;
+import cn.iocoder.yudao.module.crm.framework.core.annotations.CrmPermission;
+import cn.iocoder.yudao.module.crm.framework.enums.CrmEnum;
+import cn.iocoder.yudao.module.crm.framework.enums.OperationTypeEnum;
+import cn.iocoder.yudao.module.crm.service.permission.CrmPermissionService;
+import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionCreateBO;
 import cn.iocoder.yudao.module.system.api.dept.DeptApi;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.validation.annotation.Validated;
 
 import javax.annotation.Resource;
@@ -35,17 +38,26 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
     private CrmCustomerMapper customerMapper;
     @Resource
     private DeptApi deptApi; // TODO @wanwan:拼接数据,可以放到 controller;所以这里的引入,可以考虑放到 controller 哈;
+    @Resource
+    private CrmPermissionService crmPermissionService;
 
     @Override
-    public Long createCustomer(CrmCustomerCreateReqVO createReqVO) {
+    public Long createCustomer(CrmCustomerCreateReqVO createReqVO, Long userId) {
         // 插入
         CrmCustomerDO customer = CrmCustomerConvert.INSTANCE.convert(createReqVO);
         customerMapper.insert(customer);
+
+        // 创建数据权限
+        crmPermissionService.createCrmPermission(new CrmPermissionCreateBO().setCrmType(CrmEnum.CRM_CUSTOMER.getType())
+                .setCrmDataId(customer.getId()).setOwnerUserId(userId)); // 设置当前操作的人为负责人
+
         // 返回
         return customer.getId();
     }
 
     @Override
+    @Transactional(rollbackFor = Exception.class)
+    @CrmPermission(crmType = CrmEnum.CRM_CUSTOMER, operationType = OperationTypeEnum.UPDATE)
     public void updateCustomer(CrmCustomerUpdateReqVO updateReqVO) {
         // 校验存在
         validateCustomerExists(updateReqVO.getId());
@@ -57,6 +69,8 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
     }
 
     @Override
+    @Transactional(rollbackFor = Exception.class)
+    @CrmPermission(crmType = CrmEnum.CRM_CUSTOMER, operationType = OperationTypeEnum.DELETE)
     public void deleteCustomer(Long id) {
         // 校验存在
         validateCustomerExists(id);
@@ -73,6 +87,7 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
     }
 
     @Override
+    @CrmPermission(crmType = CrmEnum.CRM_CUSTOMER, operationType = OperationTypeEnum.READ)
     public CrmCustomerDO getCustomer(Long id) {
         return customerMapper.selectById(id);
     }
@@ -112,4 +127,15 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
         return customer;
     }
 
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void transferCustomer(CrmTransferCustomerReqVO reqVO, Long userId) {
+        // 1 校验合同是否存在
+        validateCustomer(reqVO.getId());
+
+        // 2. 数据权限转移
+        crmPermissionService.transferCrmPermission(
+                CrmCustomerConvert.INSTANCE.convert(reqVO, userId).setCrmType(CrmEnum.CRM_CUSTOMER.getType()));
+    }
+
 }

+ 0 - 18
yudao-module-crm/yudao-module-crm-biz/src/test/java/cn/iocoder/yudao/module/crm/service/business/CrmBusinessServiceImplTest.java

@@ -115,10 +115,7 @@ public class CrmBusinessServiceImplTest extends BaseDbUnitTest {
            o.setDiscountPercent(null);
            o.setProductPrice(null);
            o.setRemark(null);
-           o.setOwnerUserId(null);
            o.setCreateTime(null);
-           o.setRoUserIds(null);
-           o.setRwUserIds(null);
            o.setEndStatus(null);
            o.setEndRemark(null);
            o.setContactLastTime(null);
@@ -145,14 +142,8 @@ public class CrmBusinessServiceImplTest extends BaseDbUnitTest {
        businessMapper.insert(cloneIgnoreId(dbBusiness, o -> o.setProductPrice(null)));
        // 测试 remark 不匹配
        businessMapper.insert(cloneIgnoreId(dbBusiness, o -> o.setRemark(null)));
-       // 测试 ownerUserId 不匹配
-       businessMapper.insert(cloneIgnoreId(dbBusiness, o -> o.setOwnerUserId(null)));
        // 测试 createTime 不匹配
        businessMapper.insert(cloneIgnoreId(dbBusiness, o -> o.setCreateTime(null)));
-       // 测试 roUserIds 不匹配
-       businessMapper.insert(cloneIgnoreId(dbBusiness, o -> o.setRoUserIds(null)));
-       // 测试 rwUserIds 不匹配
-       businessMapper.insert(cloneIgnoreId(dbBusiness, o -> o.setRwUserIds(null)));
        // 测试 endStatus 不匹配
        businessMapper.insert(cloneIgnoreId(dbBusiness, o -> o.setEndStatus(null)));
        // 测试 endRemark 不匹配
@@ -205,10 +196,7 @@ public class CrmBusinessServiceImplTest extends BaseDbUnitTest {
            o.setDiscountPercent(null);
            o.setProductPrice(null);
            o.setRemark(null);
-           o.setOwnerUserId(null);
            o.setCreateTime(null);
-           o.setRoUserIds(null);
-           o.setRwUserIds(null);
            o.setEndStatus(null);
            o.setEndRemark(null);
            o.setContactLastTime(null);
@@ -235,14 +223,8 @@ public class CrmBusinessServiceImplTest extends BaseDbUnitTest {
        businessMapper.insert(cloneIgnoreId(dbBusiness, o -> o.setProductPrice(null)));
        // 测试 remark 不匹配
        businessMapper.insert(cloneIgnoreId(dbBusiness, o -> o.setRemark(null)));
-       // 测试 ownerUserId 不匹配
-       businessMapper.insert(cloneIgnoreId(dbBusiness, o -> o.setOwnerUserId(null)));
        // 测试 createTime 不匹配
        businessMapper.insert(cloneIgnoreId(dbBusiness, o -> o.setCreateTime(null)));
-       // 测试 roUserIds 不匹配
-       businessMapper.insert(cloneIgnoreId(dbBusiness, o -> o.setRoUserIds(null)));
-       // 测试 rwUserIds 不匹配
-       businessMapper.insert(cloneIgnoreId(dbBusiness, o -> o.setRwUserIds(null)));
        // 测试 endStatus 不匹配
        businessMapper.insert(cloneIgnoreId(dbBusiness, o -> o.setEndStatus(null)));
        // 测试 endRemark 不匹配

+ 0 - 6
yudao-module-crm/yudao-module-crm-biz/src/test/java/cn/iocoder/yudao/module/crm/service/clue/CrmClueServiceImplTest.java

@@ -115,7 +115,6 @@ public class CrmClueServiceImplTest extends BaseDbUnitTest {
            o.setTelephone(null);
            o.setMobile(null);
            o.setAddress(null);
-           o.setOwnerUserId(null);
            o.setContactLastTime(null);
            o.setCreateTime(null);
        });
@@ -136,8 +135,6 @@ public class CrmClueServiceImplTest extends BaseDbUnitTest {
        clueMapper.insert(cloneIgnoreId(dbClue, o -> o.setMobile(null)));
        // 测试 address 不匹配
        clueMapper.insert(cloneIgnoreId(dbClue, o -> o.setAddress(null)));
-       // 测试 ownerUserId 不匹配
-       clueMapper.insert(cloneIgnoreId(dbClue, o -> o.setOwnerUserId(null)));
        // 测试 contactLastTime 不匹配
        clueMapper.insert(cloneIgnoreId(dbClue, o -> o.setContactLastTime(null)));
        // 测试 createTime 不匹配
@@ -169,7 +166,6 @@ public class CrmClueServiceImplTest extends BaseDbUnitTest {
            o.setTelephone(null);
            o.setMobile(null);
            o.setAddress(null);
-           o.setOwnerUserId(null);
            o.setContactLastTime(null);
            o.setCreateTime(null);
        });
@@ -190,8 +186,6 @@ public class CrmClueServiceImplTest extends BaseDbUnitTest {
        clueMapper.insert(cloneIgnoreId(dbClue, o -> o.setMobile(null)));
        // 测试 address 不匹配
        clueMapper.insert(cloneIgnoreId(dbClue, o -> o.setAddress(null)));
-       // 测试 ownerUserId 不匹配
-       clueMapper.insert(cloneIgnoreId(dbClue, o -> o.setOwnerUserId(null)));
        // 测试 contactLastTime 不匹配
        clueMapper.insert(cloneIgnoreId(dbClue, o -> o.setContactLastTime(null)));
        // 测试 createTime 不匹配

+ 3 - 1
yudao-module-crm/yudao-module-crm-biz/src/test/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerServiceImplTest.java

@@ -16,6 +16,7 @@ import javax.annotation.Resource;
 import java.util.List;
 
 import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId;
+import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
 import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals;
 import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException;
 import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId;
@@ -24,6 +25,7 @@ import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.CUSTOMER_NOT_
 import static org.junit.jupiter.api.Assertions.*;
 
 // TODO 芋艿:单测后续补
+
 /**
  * {@link CrmCustomerServiceImpl} 的单元测试类
  *
@@ -44,7 +46,7 @@ public class CrmCustomerServiceImplTest extends BaseDbUnitTest {
         CrmCustomerCreateReqVO reqVO = randomPojo(CrmCustomerCreateReqVO.class);
 
         // 调用
-        Long customerId = customerService.createCustomer(reqVO);
+        Long customerId = customerService.createCustomer(reqVO, getLoginUserId());
         // 断言
         assertNotNull(customerId);
         // 校验记录的属性是否正确