| 
					
				 | 
			
			
				@@ -3,13 +3,12 @@ package cn.iocoder.yudao.module.crm.service.contact; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 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.contact.vo.ContactCreateReqVO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-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.controller.admin.contact.vo.ContactUpdateReqVO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import cn.iocoder.yudao.module.crm.convert.contact.ContactConvert; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import cn.iocoder.yudao.module.crm.dal.dataobject.contact.ContactDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import cn.iocoder.yudao.module.crm.dal.mysql.contact.ContactMapper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import cn.iocoder.yudao.module.system.api.user.AdminUserApi; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.stereotype.Service; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.validation.annotation.Validated; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -18,7 +17,8 @@ import java.util.Collection; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import java.util.List; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.CONTACT_NOT_EXISTS; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import static cn.iocoder.yudao.module.crm.framework.utils.AuthUtil.isReadAndWrite; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  * crm联系人 Service 实现类 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -32,6 +32,9 @@ public class ContactServiceImpl implements ContactService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Resource 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private ContactMapper contactMapper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Resource 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private AdminUserApi adminUserApi; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     public Long createContact(ContactCreateReqVO createReqVO) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         // TODO @customerId:需要校验存在 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -61,10 +64,12 @@ public class ContactServiceImpl implements ContactService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         contactMapper.deleteById(id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    private void validateContactExists(Long id) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if (contactMapper.selectById(id) == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private ContactDO validateContactExists(Long id) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        ContactDO contact = contactMapper.selectById(id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (contact == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             throw exception(CONTACT_NOT_EXISTS); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return contact; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Override 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -90,4 +95,26 @@ public class ContactServiceImpl implements ContactService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return contactMapper.selectList(exportReqVO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public void contactTransfer(CrmContactTransferReqVO reqVO, Long userId) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // 1. 校验联系人是否存在 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        ContactDO contact = validateContactExists(reqVO.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // 1.2. 校验用户是否拥有读写权限 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (!isReadAndWrite(contact.getRwUserIds(), userId)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            throw exception(CONTACT_TRANSFER_FAIL_PERMISSION_DENIED); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // 2. 校验新负责人是否存在 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        AdminUserRespDTO user = adminUserApi.getUser(reqVO.getOwnerUserId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (user == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            throw exception(CONTACT_TRANSFER_FAIL_OWNER_USER_NOT_EXISTS); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // 3. 更新新的负责人 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        ContactDO updateContract = ContactConvert.INSTANCE.convert(contact, reqVO, userId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        contactMapper.updateById(updateContract); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // 4. TODO 记录联系人转移日志 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 |