Commit a877bb47317a96220d8e05c0741bae1e57b447a8

Authored by puhui999
1 parent 4605e931

CRM-客户: 完善客户导入

yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/CrmCustomerController.java
@@ -198,7 +198,7 @@ public class CrmCustomerController { @@ -198,7 +198,7 @@ public class CrmCustomerController {
198 public CommonResult<CrmCustomerImportRespVO> importExcel(@RequestParam("file") MultipartFile file, 198 public CommonResult<CrmCustomerImportRespVO> importExcel(@RequestParam("file") MultipartFile file,
199 @RequestParam(value = "updateSupport", required = false, defaultValue = "false") Boolean updateSupport) throws Exception { 199 @RequestParam(value = "updateSupport", required = false, defaultValue = "false") Boolean updateSupport) throws Exception {
200 List<CrmCustomerImportExcelVO> list = ExcelUtils.read(file, CrmCustomerImportExcelVO.class); 200 List<CrmCustomerImportExcelVO> list = ExcelUtils.read(file, CrmCustomerImportExcelVO.class);
201 - return success(customerService.importCustomerList(list, updateSupport)); 201 + return success(customerService.importCustomerList(list, updateSupport, getLoginUserId()));
202 } 202 }
203 203
204 204
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerService.java
@@ -110,9 +110,10 @@ public interface CrmCustomerService { @@ -110,9 +110,10 @@ public interface CrmCustomerService {
110 * 110 *
111 * @param importCustomers 导入客户列表 111 * @param importCustomers 导入客户列表
112 * @param isUpdateSupport 是否支持更新 112 * @param isUpdateSupport 是否支持更新
  113 + * @param userId 用户编号
113 * @return 导入结果 114 * @return 导入结果
114 */ 115 */
115 - CrmCustomerImportRespVO importCustomerList(List<CrmCustomerImportExcelVO> importCustomers, Boolean isUpdateSupport); 116 + CrmCustomerImportRespVO importCustomerList(List<CrmCustomerImportExcelVO> importCustomers, Boolean isUpdateSupport, Long userId);
116 117
117 // ==================== 公海相关操作 ==================== 118 // ==================== 公海相关操作 ====================
118 119
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerServiceImpl.java
@@ -93,7 +93,7 @@ public class CrmCustomerServiceImpl implements CrmCustomerService { @@ -93,7 +93,7 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
93 validateCustomerExceedOwnerLimit(createReqVO.getOwnerUserId(), 1); 93 validateCustomerExceedOwnerLimit(createReqVO.getOwnerUserId(), 1);
94 94
95 // 2. 插入客户 95 // 2. 插入客户
96 - CrmCustomerDO customer = BeanUtils.toBean(createReqVO, CrmCustomerDO.class) 96 + CrmCustomerDO customer = BeanUtils.toBean(createReqVO, CrmCustomerDO.class).setOwnerUserId(userId)
97 .setLockStatus(false).setDealStatus(false).setContactLastTime(LocalDateTime.now()); 97 .setLockStatus(false).setDealStatus(false).setContactLastTime(LocalDateTime.now());
98 customerMapper.insert(customer); 98 customerMapper.insert(customer);
99 99
@@ -233,7 +233,7 @@ public class CrmCustomerServiceImpl implements CrmCustomerService { @@ -233,7 +233,7 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
233 } 233 }
234 234
235 @Override 235 @Override
236 - public CrmCustomerImportRespVO importCustomerList(List<CrmCustomerImportExcelVO> importCustomers, Boolean isUpdateSupport) { 236 + public CrmCustomerImportRespVO importCustomerList(List<CrmCustomerImportExcelVO> importCustomers, Boolean isUpdateSupport, Long userId) {
237 if (CollUtil.isEmpty(importCustomers)) { 237 if (CollUtil.isEmpty(importCustomers)) {
238 throw exception(CUSTOMER_IMPORT_LIST_IS_EMPTY); 238 throw exception(CUSTOMER_IMPORT_LIST_IS_EMPTY);
239 } 239 }
@@ -250,8 +250,13 @@ public class CrmCustomerServiceImpl implements CrmCustomerService { @@ -250,8 +250,13 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
250 // 判断如果不存在,在进行插入 250 // 判断如果不存在,在进行插入
251 CrmCustomerDO existCustomer = customerMapper.selectByCustomerName(importCustomer.getName()); 251 CrmCustomerDO existCustomer = customerMapper.selectByCustomerName(importCustomer.getName());
252 if (existCustomer == null) { 252 if (existCustomer == null) {
253 - customerMapper.insert(BeanUtils.toBean(importCustomer, CrmCustomerDO.class)); 253 + CrmCustomerDO customer = BeanUtils.toBean(importCustomer, CrmCustomerDO.class).setOwnerUserId(userId)
  254 + .setLockStatus(false).setDealStatus(false).setContactLastTime(LocalDateTime.now());
  255 + customerMapper.insert(customer);
254 respVO.getCreateCustomerNames().add(importCustomer.getName()); 256 respVO.getCreateCustomerNames().add(importCustomer.getName());
  257 + // 创建数据权限
  258 + permissionService.createPermission(new CrmPermissionCreateReqBO().setBizType(CrmBizTypeEnum.CRM_CUSTOMER.getType())
  259 + .setBizId(customer.getId()).setUserId(userId).setLevel(CrmPermissionLevelEnum.OWNER.getLevel())); // 设置当前操作的人为负责人
255 return; 260 return;
256 } 261 }
257 // 如果存在,判断是否允许更新 262 // 如果存在,判断是否允许更新