mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-23 07:41:53 +08:00
✨ CRM:完善商机的跟进记录
This commit is contained in:
parent
df2441def9
commit
d9b0c9b4cf
@ -20,7 +20,7 @@ public interface ErrorCodeConstants {
|
||||
|
||||
// ========== 商机管理 1-020-002-000 ==========
|
||||
ErrorCode BUSINESS_NOT_EXISTS = new ErrorCode(1_020_002_000, "商机不存在");
|
||||
ErrorCode BUSINESS_CONTRACT_EXISTS = new ErrorCode(1_020_002_001, "商机已关联合同,不能删除");
|
||||
ErrorCode BUSINESS_DELETE_FAIL_CONTRACT_EXISTS = new ErrorCode(1_020_002_001, "商机已关联合同,不能删除");
|
||||
|
||||
// ========== 联系人管理 1-020-003-000 ==========
|
||||
ErrorCode CONTACT_NOT_EXISTS = new ErrorCode(1_020_003_000, "联系人不存在");
|
||||
|
@ -91,6 +91,8 @@ public interface LogRecordConstants {
|
||||
String CRM_BUSINESS_DELETE_SUCCESS = "删除了商机【{{#businessName}}】";
|
||||
String CRM_BUSINESS_TRANSFER_SUB_TYPE = "转移商机";
|
||||
String CRM_BUSINESS_TRANSFER_SUCCESS = "将商机【{{#business.name}}】的负责人从【{getAdminUserById{#business.ownerUserId}}】变更为了【{getAdminUserById{#reqVO.newOwnerUserId}}】";
|
||||
String CRM_BUSINESS_FOLLOW_UP_SUB_TYPE = "商机跟进";
|
||||
String CRM_BUSINESS_FOLLOW_UP_SUCCESS = "商机跟进【{{#businessName}}】";
|
||||
|
||||
// ======================= CRM_CONTRACT 合同 =======================
|
||||
|
||||
|
@ -65,7 +65,7 @@ public class CrmBusinessRespVO {
|
||||
private String statusName;
|
||||
|
||||
@Schema
|
||||
@ExcelProperty("1赢单2输单3无效")
|
||||
@ExcelProperty("结束状态")
|
||||
private Integer endStatus;
|
||||
|
||||
@ExcelProperty("结束时的备注")
|
||||
|
@ -1,16 +1,11 @@
|
||||
package cn.iocoder.yudao.module.crm.convert.business;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
||||
import cn.iocoder.yudao.module.crm.controller.admin.business.vo.business.CrmBusinessTransferReqVO;
|
||||
import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessDO;
|
||||
import cn.iocoder.yudao.module.crm.service.followup.bo.CrmUpdateFollowUpReqBO;
|
||||
import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionTransferReqBO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 商机 Convert
|
||||
*
|
||||
@ -24,11 +19,4 @@ public interface CrmBusinessConvert {
|
||||
@Mapping(target = "bizId", source = "reqVO.id")
|
||||
CrmPermissionTransferReqBO convert(CrmBusinessTransferReqVO reqVO, Long userId);
|
||||
|
||||
@Mapping(target = "id", source = "reqBO.bizId")
|
||||
CrmBusinessDO convert(CrmUpdateFollowUpReqBO reqBO);
|
||||
|
||||
default List<CrmBusinessDO> convertList(List<CrmUpdateFollowUpReqBO> list) {
|
||||
return CollectionUtils.convertList(list, INSTANCE::convert);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -9,9 +9,9 @@ import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessProductDO;
|
||||
import cn.iocoder.yudao.module.crm.dal.dataobject.contact.CrmContactDO;
|
||||
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
|
||||
import cn.iocoder.yudao.module.crm.service.business.bo.CrmBusinessUpdateProductReqBO;
|
||||
import cn.iocoder.yudao.module.crm.service.followup.bo.CrmUpdateFollowUpReqBO;
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
@ -41,9 +41,19 @@ public interface CrmBusinessService {
|
||||
/**
|
||||
* 更新商机相关跟进信息
|
||||
*
|
||||
* @param updateFollowUpReqBOList 跟进信息
|
||||
* @param id 编号
|
||||
* @param contactNextTime 下次联系时间
|
||||
* @param contactLastContent 最后联系内容
|
||||
*/
|
||||
void updateBusinessFollowUpBatch(List<CrmUpdateFollowUpReqBO> updateFollowUpReqBOList);
|
||||
void updateBusinessFollowUp(Long id, LocalDateTime contactNextTime, String contactLastContent);
|
||||
|
||||
/**
|
||||
* 更新商机的下次联系时间
|
||||
*
|
||||
* @param ids 编号数组
|
||||
* @param contactNextTime 下次联系时间
|
||||
*/
|
||||
void updateBusinessContactNextTime(Collection<Long> ids, LocalDateTime contactNextTime);
|
||||
|
||||
/**
|
||||
* 删除商机
|
||||
|
@ -22,7 +22,6 @@ import cn.iocoder.yudao.module.crm.service.contact.CrmContactBusinessService;
|
||||
import cn.iocoder.yudao.module.crm.service.contact.CrmContactService;
|
||||
import cn.iocoder.yudao.module.crm.service.contract.CrmContractService;
|
||||
import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerService;
|
||||
import cn.iocoder.yudao.module.crm.service.followup.bo.CrmUpdateFollowUpReqBO;
|
||||
import cn.iocoder.yudao.module.crm.service.permission.CrmPermissionService;
|
||||
import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionCreateReqBO;
|
||||
import cn.iocoder.yudao.module.crm.service.product.CrmProductService;
|
||||
@ -37,12 +36,13 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
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.*;
|
||||
import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.BUSINESS_CONTRACT_EXISTS;
|
||||
import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.BUSINESS_DELETE_FAIL_CONTRACT_EXISTS;
|
||||
import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.BUSINESS_NOT_EXISTS;
|
||||
import static cn.iocoder.yudao.module.crm.enums.LogRecordConstants.*;
|
||||
|
||||
@ -139,6 +139,28 @@ public class CrmBusinessServiceImpl implements CrmBusinessService {
|
||||
LogRecordContext.putVariable("businessName", oldBusiness.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
@LogRecord(type = CRM_BUSINESS_TYPE, subType = CRM_BUSINESS_FOLLOW_UP_SUB_TYPE, bizNo = "{{#id}",
|
||||
success = CRM_BUSINESS_FOLLOW_UP_SUCCESS)
|
||||
@CrmPermission(bizType = CrmBizTypeEnum.CRM_BUSINESS, bizId = "#id", level = CrmPermissionLevelEnum.WRITE)
|
||||
public void updateBusinessFollowUp(Long id, LocalDateTime contactNextTime, String contactLastContent) {
|
||||
// 1. 校验存在
|
||||
CrmBusinessDO business = validateBusinessExists(id);
|
||||
|
||||
// 2. 更新联系人的跟进信息
|
||||
businessMapper.updateById(new CrmBusinessDO().setId(id).setFollowUpStatus(true).setContactNextTime(contactNextTime)
|
||||
.setContactLastTime(LocalDateTime.now()));
|
||||
|
||||
// 3. 记录操作日志上下文
|
||||
LogRecordContext.putVariable("businessName", business.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
@CrmPermission(bizType = CrmBizTypeEnum.CRM_BUSINESS, bizId = "#ids", level = CrmPermissionLevelEnum.WRITE)
|
||||
public void updateBusinessContactNextTime(Collection<Long> ids, LocalDateTime contactNextTime) {
|
||||
businessMapper.updateBatch(convertList(ids, id -> new CrmBusinessDO().setId(id).setContactNextTime(contactNextTime)));
|
||||
}
|
||||
|
||||
private void updateBusinessProduct(Long id, List<CrmBusinessProductDO> newList) {
|
||||
List<CrmBusinessProductDO> oldList = businessProductMapper.selectListByBusinessId(id);
|
||||
List<List<CrmBusinessProductDO>> diffList = diffList(oldList, newList, // id 不同,就认为是不同的记录
|
||||
@ -189,20 +211,15 @@ public class CrmBusinessServiceImpl implements CrmBusinessService {
|
||||
business.setTotalPrice(business.getTotalProductPrice().subtract(discountPrice));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateBusinessFollowUpBatch(List<CrmUpdateFollowUpReqBO> updateFollowUpReqBOList) {
|
||||
businessMapper.updateBatch(CrmBusinessConvert.INSTANCE.convertList(updateFollowUpReqBOList));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@LogRecord(type = CRM_BUSINESS_TYPE, subType = CRM_BUSINESS_DELETE_SUB_TYPE, bizNo = "{{#id}}",
|
||||
success = CRM_BUSINESS_DELETE_SUCCESS)
|
||||
@CrmPermission(bizType = CrmBizTypeEnum.CRM_BUSINESS, bizId = "#id", level = CrmPermissionLevelEnum.OWNER)
|
||||
public void deleteBusiness(Long id) {
|
||||
// 校验存在
|
||||
// 1.1 校验存在
|
||||
CrmBusinessDO business = validateBusinessExists(id);
|
||||
// TODO @商机待定:需要校验有没关联合同。CrmContractDO 的 businessId 字段
|
||||
// 1.2 校验是否关联合同
|
||||
validateContractExists(id);
|
||||
|
||||
// 删除
|
||||
@ -222,7 +239,7 @@ public class CrmBusinessServiceImpl implements CrmBusinessService {
|
||||
*/
|
||||
private void validateContractExists(Long businessId) {
|
||||
if (contractService.getContractCountByBusinessId(businessId) > 0) {
|
||||
throw exception(BUSINESS_CONTRACT_EXISTS);
|
||||
throw exception(BUSINESS_DELETE_FAIL_CONTRACT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -72,13 +72,12 @@ public interface CrmContactService {
|
||||
void updateContactFollowUp(Long id, LocalDateTime contactNextTime, String contactLastContent);
|
||||
|
||||
/**
|
||||
* 更新联系人相关跟进信息
|
||||
* 更新联系人的下次联系时间
|
||||
*
|
||||
* @param ids 编号数组
|
||||
* @param contactNextTime 下次联系时间
|
||||
* @param contactLastContent 最后联系内容
|
||||
*/
|
||||
void updateContactFollowUpBatch(Collection<Long> ids, LocalDateTime contactNextTime, String contactLastContent);
|
||||
void updateContactContactNextTime(Collection<Long> ids, LocalDateTime contactNextTime);
|
||||
|
||||
/**
|
||||
* 获得联系人
|
||||
|
@ -225,7 +225,7 @@ public class CrmContactServiceImpl implements CrmContactService {
|
||||
success = CRM_CONTACT_FOLLOW_UP_SUCCESS)
|
||||
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CONTACT, bizId = "#id", level = CrmPermissionLevelEnum.WRITE)
|
||||
public void updateContactFollowUp(Long id, LocalDateTime contactNextTime, String contactLastContent) {
|
||||
// 1.1 校验存在
|
||||
// 1. 校验存在
|
||||
CrmContactDO contact = validateContactExists(id);
|
||||
|
||||
// 2. 更新联系人的跟进信息
|
||||
@ -238,9 +238,8 @@ public class CrmContactServiceImpl implements CrmContactService {
|
||||
|
||||
@Override
|
||||
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CONTACT, bizId = "#ids", level = CrmPermissionLevelEnum.WRITE)
|
||||
public void updateContactFollowUpBatch(Collection<Long> ids, LocalDateTime contactNextTime, String contactLastContent) {
|
||||
contactMapper.updateBatch(convertList(ids, id -> new CrmContactDO().setId(id).setContactLastTime(LocalDateTime.now())
|
||||
.setContactNextTime(contactNextTime).setContactLastContent(contactLastContent)));
|
||||
public void updateContactContactNextTime(Collection<Long> ids, LocalDateTime contactNextTime) {
|
||||
contactMapper.updateBatch(convertList(ids, id -> new CrmContactDO().setId(id).setContactNextTime(contactNextTime)));
|
||||
}
|
||||
|
||||
//======================= 查询相关 =======================
|
||||
|
@ -26,11 +26,9 @@ import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
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.convertList;
|
||||
import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.FOLLOW_UP_RECORD_DELETE_DENIED;
|
||||
import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.FOLLOW_UP_RECORD_NOT_EXISTS;
|
||||
|
||||
@ -77,7 +75,7 @@ public class CrmFollowUpRecordServiceImpl implements CrmFollowUpRecordService {
|
||||
.setContactLastTime(LocalDateTime.now())
|
||||
.setContactNextTime(record.getNextTime()).setContactLastContent(record.getContent());
|
||||
if (ObjUtil.equal(CrmBizTypeEnum.CRM_BUSINESS.getType(), record.getBizType())) { // 更新商机跟进信息
|
||||
businessService.updateBusinessFollowUpBatch(Collections.singletonList(updateFollowUpReqBO));
|
||||
businessService.updateBusinessFollowUp(record.getBizId(), record.getNextTime(), record.getContent());
|
||||
}
|
||||
if (ObjUtil.equal(CrmBizTypeEnum.CRM_CLUE.getType(), record.getBizType())) { // 更新线索跟进信息
|
||||
clueService.updateClueFollowUp(record.getBizId(), record.getNextTime(), record.getContent());
|
||||
@ -92,14 +90,13 @@ public class CrmFollowUpRecordServiceImpl implements CrmFollowUpRecordService {
|
||||
customerService.updateCustomerFollowUp(record.getBizId(), record.getNextTime(), record.getContent());
|
||||
}
|
||||
|
||||
// 3.1 更新 contactIds 对应的记录,不更新 lastTime 和 lastContent
|
||||
// 3.1 更新 contactIds 对应的记录,只更新 nextTime
|
||||
if (CollUtil.isNotEmpty(createReqVO.getContactIds())) {
|
||||
contactService.updateContactFollowUpBatch(createReqVO.getContactIds(), null, null);
|
||||
contactService.updateContactContactNextTime(createReqVO.getContactIds(), createReqVO.getNextTime());
|
||||
}
|
||||
// 3.2 需要更新 businessIds 对应的记录,不更新 lastTime 和 lastContent
|
||||
// 3.2 需要更新 businessIds 对应的记录,只更新 nextTime
|
||||
if (CollUtil.isNotEmpty(createReqVO.getBusinessIds())) {
|
||||
businessService.updateBusinessFollowUpBatch(convertList(createReqVO.getBusinessIds(),
|
||||
businessId -> updateFollowUpReqBO.setBizId(businessId).setContactLastTime(null).setContactLastContent(null)));
|
||||
businessService.updateBusinessContactNextTime(createReqVO.getBusinessIds(), createReqVO.getNextTime());
|
||||
}
|
||||
return record.getId();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user