|
@@ -3,13 +3,12 @@ package cn.iocoder.yudao.module.crm.service.business;
|
|
|
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.business.vo.CrmBusinessCreateReqVO;
|
|
|
-import cn.iocoder.yudao.module.crm.controller.admin.business.vo.CrmBusinessExportReqVO;
|
|
|
-import cn.iocoder.yudao.module.crm.controller.admin.business.vo.CrmBusinessPageReqVO;
|
|
|
-import cn.iocoder.yudao.module.crm.controller.admin.business.vo.CrmBusinessUpdateReqVO;
|
|
|
+import cn.iocoder.yudao.module.crm.controller.admin.business.vo.*;
|
|
|
import cn.iocoder.yudao.module.crm.convert.business.CrmBusinessConvert;
|
|
|
import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessDO;
|
|
|
import cn.iocoder.yudao.module.crm.dal.mysql.business.CrmBusinessMapper;
|
|
|
+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.BUSINESS_NOT_EXISTS;
|
|
|
+import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*;
|
|
|
+import static cn.iocoder.yudao.module.crm.framework.utils.AuthUtil.isReadAndWrite;
|
|
|
|
|
|
/**
|
|
|
* 商机 Service 实现类
|
|
@@ -32,6 +32,9 @@ public class CrmBusinessServiceImpl implements CrmBusinessService {
|
|
|
@Resource
|
|
|
private CrmBusinessMapper businessMapper;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private AdminUserApi adminUserApi;
|
|
|
+
|
|
|
@Override
|
|
|
public Long createBusiness(CrmBusinessCreateReqVO createReqVO) {
|
|
|
// 插入
|
|
@@ -58,10 +61,12 @@ public class CrmBusinessServiceImpl implements CrmBusinessService {
|
|
|
businessMapper.deleteById(id);
|
|
|
}
|
|
|
|
|
|
- private void validateBusinessExists(Long id) {
|
|
|
- if (businessMapper.selectById(id) == null) {
|
|
|
+ private CrmBusinessDO validateBusinessExists(Long id) {
|
|
|
+ CrmBusinessDO crmBusiness = businessMapper.selectById(id);
|
|
|
+ if (crmBusiness == null) {
|
|
|
throw exception(BUSINESS_NOT_EXISTS);
|
|
|
}
|
|
|
+ return crmBusiness;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -87,4 +92,26 @@ public class CrmBusinessServiceImpl implements CrmBusinessService {
|
|
|
return businessMapper.selectList(exportReqVO);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void businessTransfer(CrmBusinessTransferReqVO reqVO, Long userId) {
|
|
|
+ // 1. 校验商机是否存在
|
|
|
+ CrmBusinessDO business = validateBusinessExists(reqVO.getId());
|
|
|
+ // 1.2. 校验用户是否拥有读写权限
|
|
|
+ if (!isReadAndWrite(business.getRwUserIds(), userId)) {
|
|
|
+ throw exception(BUSINESS_TRANSFER_FAIL_PERMISSION_DENIED);
|
|
|
+ }
|
|
|
+ // 2. 校验新负责人是否存在
|
|
|
+ AdminUserRespDTO user = adminUserApi.getUser(reqVO.getOwnerUserId());
|
|
|
+ if (user == null) {
|
|
|
+ throw exception(BUSINESS_TRANSFER_FAIL_OWNER_USER_NOT_EXISTS);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3. 更新新的负责人
|
|
|
+ CrmBusinessDO updateBusiness = CrmBusinessConvert.INSTANCE.convert(business, reqVO, userId);
|
|
|
+ businessMapper.updateById(updateBusiness);
|
|
|
+
|
|
|
+ // 4. TODO 记录商机转移日志
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
}
|