|
@@ -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()));
|
|
|
+ }
|
|
|
+
|
|
|
}
|