|
|
|
|
@ -7,10 +7,18 @@ import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
|
|
|
|
import cn.iocoder.yudao.module.crm.controller.admin.business.vo.business.CrmBusinessPageReqVO;
|
|
|
|
|
import cn.iocoder.yudao.module.crm.controller.admin.business.vo.business.CrmBusinessSaveReqVO;
|
|
|
|
|
import cn.iocoder.yudao.module.crm.controller.admin.business.vo.business.CrmBusinessTransferReqVO;
|
|
|
|
|
import cn.iocoder.yudao.module.crm.controller.admin.business.vo.product.CrmBusinessProductSaveReqVO;
|
|
|
|
|
import cn.iocoder.yudao.module.crm.controller.admin.product.vo.product.CrmProductSaveReqVO;
|
|
|
|
|
import cn.iocoder.yudao.module.crm.convert.business.CrmBusinessConvert;
|
|
|
|
|
import cn.iocoder.yudao.module.crm.convert.businessproduct.CrmBusinessProductConvert;
|
|
|
|
|
import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessDO;
|
|
|
|
|
import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessProductDO;
|
|
|
|
|
import cn.iocoder.yudao.module.crm.dal.dataobject.contact.CrmContactBusinessDO;
|
|
|
|
|
import cn.iocoder.yudao.module.crm.dal.dataobject.contract.CrmContractDO;
|
|
|
|
|
import cn.iocoder.yudao.module.crm.dal.mysql.business.CrmBusinessMapper;
|
|
|
|
|
import cn.iocoder.yudao.module.crm.dal.mysql.business.CrmBusinessProductMapper;
|
|
|
|
|
import cn.iocoder.yudao.module.crm.dal.mysql.contactbusinesslink.CrmContactBusinessMapper;
|
|
|
|
|
import cn.iocoder.yudao.module.crm.dal.mysql.contract.CrmContractMapper;
|
|
|
|
|
import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum;
|
|
|
|
|
import cn.iocoder.yudao.module.crm.enums.permission.CrmPermissionLevelEnum;
|
|
|
|
|
import cn.iocoder.yudao.module.crm.framework.permission.core.annotations.CrmPermission;
|
|
|
|
|
@ -25,11 +33,14 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Collection;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
|
|
|
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
|
|
|
|
|
import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.BUSINESS_CONTRACT_EXISTS;
|
|
|
|
|
import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.BUSINESS_NOT_EXISTS;
|
|
|
|
|
import static cn.iocoder.yudao.module.crm.enums.LogRecordConstants.*;
|
|
|
|
|
|
|
|
|
|
@ -45,6 +56,13 @@ public class CrmBusinessServiceImpl implements CrmBusinessService {
|
|
|
|
|
@Resource
|
|
|
|
|
private CrmBusinessMapper businessMapper;
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private CrmBusinessProductMapper businessProductMapper;
|
|
|
|
|
@Resource
|
|
|
|
|
private CrmContractMapper contractMapper;
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private CrmContactBusinessMapper contactBusinessMapper;
|
|
|
|
|
@Resource
|
|
|
|
|
private CrmPermissionService permissionService;
|
|
|
|
|
@Resource
|
|
|
|
|
@ -61,17 +79,65 @@ public class CrmBusinessServiceImpl implements CrmBusinessService {
|
|
|
|
|
.setOwnerUserId(userId);
|
|
|
|
|
businessMapper.insert(business);
|
|
|
|
|
// TODO 商机待定:插入商机与产品的关联表;校验商品存在
|
|
|
|
|
|
|
|
|
|
verifyCrmBusinessProduct(business.getId());
|
|
|
|
|
if (!createReqVO.getProducts().isEmpty()) {
|
|
|
|
|
createBusinessProducts(createReqVO.getProducts(), business.getId());
|
|
|
|
|
}
|
|
|
|
|
// TODO 商机待定:在联系人的详情页,如果直接【新建商机】,则需要关联下。这里要搞个 CrmContactBusinessDO 表
|
|
|
|
|
createContactBusiness(business.getId(), createReqVO.getContactId());
|
|
|
|
|
|
|
|
|
|
// 2. 创建数据权限
|
|
|
|
|
// 设置当前操作的人为负责人
|
|
|
|
|
permissionService.createPermission(new CrmPermissionCreateReqBO().setBizType(CrmBizTypeEnum.CRM_BUSINESS.getType())
|
|
|
|
|
.setBizId(business.getId()).setUserId(userId).setLevel(CrmPermissionLevelEnum.OWNER.getLevel())); // 设置当前操作的人为负责人
|
|
|
|
|
.setBizId(business.getId()).setUserId(userId).setLevel(CrmPermissionLevelEnum.OWNER.getLevel()));
|
|
|
|
|
|
|
|
|
|
// 4. 记录操作日志上下文
|
|
|
|
|
LogRecordContext.putVariable("business", business);
|
|
|
|
|
return business.getId();
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @param businessId 商机id
|
|
|
|
|
* @param contactId 联系人id
|
|
|
|
|
* @throws
|
|
|
|
|
* @description 联系人与商机的关联
|
|
|
|
|
* @author lzxhqs
|
|
|
|
|
*/
|
|
|
|
|
private void createContactBusiness(Long businessId, Long contactId) {
|
|
|
|
|
CrmContactBusinessDO contactBusiness = new CrmContactBusinessDO();
|
|
|
|
|
contactBusiness.setBusinessId(businessId);
|
|
|
|
|
contactBusiness.setContactId(contactId);
|
|
|
|
|
contactBusinessMapper.insert(contactBusiness);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param products 产品集合
|
|
|
|
|
* @description 插入商机产品关联表
|
|
|
|
|
* @author lzxhqs
|
|
|
|
|
*/
|
|
|
|
|
private void createBusinessProducts(List<CrmBusinessProductSaveReqVO> products, Long businessId) {
|
|
|
|
|
List<CrmBusinessProductDO> list = new ArrayList<>();
|
|
|
|
|
for (CrmBusinessProductSaveReqVO product : products) {
|
|
|
|
|
CrmBusinessProductDO businessProductDO = CrmBusinessProductConvert.INSTANCE.convert(product);
|
|
|
|
|
businessProductDO.setBusinessId(businessId);
|
|
|
|
|
list.add(businessProductDO);
|
|
|
|
|
}
|
|
|
|
|
businessProductMapper.insertBatch(list);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param id businessId
|
|
|
|
|
* @description 校验管理的产品存在则删除
|
|
|
|
|
* @author lzxhqs
|
|
|
|
|
*/
|
|
|
|
|
private void verifyCrmBusinessProduct(Long id) {
|
|
|
|
|
CrmBusinessProductDO businessProductDO = businessProductMapper.selectByBusinessId(id);
|
|
|
|
|
if (businessProductDO != null) {
|
|
|
|
|
//通过商机Id删除
|
|
|
|
|
businessProductMapper.deleteByBusinessId(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
@ -86,6 +152,10 @@ public class CrmBusinessServiceImpl implements CrmBusinessService {
|
|
|
|
|
CrmBusinessDO updateObj = BeanUtils.toBean(updateReqVO, CrmBusinessDO.class);
|
|
|
|
|
businessMapper.updateById(updateObj);
|
|
|
|
|
// TODO 商机待定:插入商机与产品的关联表;校验商品存在
|
|
|
|
|
verifyCrmBusinessProduct(updateReqVO.getId());
|
|
|
|
|
if (!updateReqVO.getProducts().isEmpty()) {
|
|
|
|
|
createBusinessProducts(updateReqVO.getProducts(), updateReqVO.getId());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO @商机待定:如果状态发生变化,插入商机状态变更记录表
|
|
|
|
|
// 3. 记录操作日志上下文
|
|
|
|
|
@ -102,6 +172,7 @@ public class CrmBusinessServiceImpl implements CrmBusinessService {
|
|
|
|
|
// 校验存在
|
|
|
|
|
CrmBusinessDO business = validateBusinessExists(id);
|
|
|
|
|
// TODO @商机待定:需要校验有没关联合同。CrmContractDO 的 businessId 字段
|
|
|
|
|
validateContractExists(id);
|
|
|
|
|
|
|
|
|
|
// 删除
|
|
|
|
|
businessMapper.deleteById(id);
|
|
|
|
|
@ -112,6 +183,19 @@ public class CrmBusinessServiceImpl implements CrmBusinessService {
|
|
|
|
|
LogRecordContext.putVariable("businessName", business.getName());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param businessId 商机id
|
|
|
|
|
* @throws
|
|
|
|
|
* @description 删除校验合同是关联合同
|
|
|
|
|
* @author lzxhqs
|
|
|
|
|
*/
|
|
|
|
|
private void validateContractExists(Long businessId) {
|
|
|
|
|
CrmContractDO contract = contractMapper.selectByBizId(businessId);
|
|
|
|
|
if(contract != null) {
|
|
|
|
|
throw exception(BUSINESS_CONTRACT_EXISTS);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private CrmBusinessDO validateBusinessExists(Long id) {
|
|
|
|
|
CrmBusinessDO crmBusiness = businessMapper.selectById(id);
|
|
|
|
|
if (crmBusiness == null) {
|
|
|
|
|
|