|
@@ -8,7 +8,6 @@ import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.CrmContactBusines
|
|
|
import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.CrmContactPageReqVO;
|
|
|
import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.CrmContactSaveReqVO;
|
|
|
import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.CrmContactTransferReqVO;
|
|
|
-import cn.iocoder.yudao.module.crm.convert.contact.CrmContactConvert;
|
|
|
import cn.iocoder.yudao.module.crm.dal.dataobject.contact.CrmContactDO;
|
|
|
import cn.iocoder.yudao.module.crm.dal.mysql.contact.CrmContactMapper;
|
|
|
import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum;
|
|
@@ -17,9 +16,9 @@ import cn.iocoder.yudao.module.crm.framework.permission.core.annotations.CrmPerm
|
|
|
import cn.iocoder.yudao.module.crm.service.business.CrmBusinessService;
|
|
|
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.permission.bo.CrmPermissionTransferReqBO;
|
|
|
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
|
|
|
import com.mzt.logapi.context.LogRecordContext;
|
|
|
import com.mzt.logapi.service.impl.DiffParseFunction;
|
|
@@ -30,14 +29,15 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
|
|
+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.pojo.PageParam.PAGE_SIZE_NONE;
|
|
|
+import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
|
|
|
import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*;
|
|
|
import static cn.iocoder.yudao.module.crm.enums.LogRecordConstants.*;
|
|
|
-import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.USER_NOT_EXISTS;
|
|
|
import static java.util.Collections.singletonList;
|
|
|
|
|
|
/**
|
|
@@ -73,7 +73,7 @@ public class CrmContactServiceImpl implements CrmContactService {
|
|
|
success = CRM_CONTACT_CREATE_SUCCESS)
|
|
|
public Long createContact(CrmContactSaveReqVO createReqVO, Long userId) {
|
|
|
createReqVO.setId(null);
|
|
|
- // 1. 校验
|
|
|
+ // 1. 校验关联数据
|
|
|
validateRelationDataExists(createReqVO);
|
|
|
|
|
|
// 2. 插入联系人
|
|
@@ -102,8 +102,9 @@ public class CrmContactServiceImpl implements CrmContactService {
|
|
|
success = CRM_CONTACT_UPDATE_SUCCESS)
|
|
|
@CrmPermission(bizType = CrmBizTypeEnum.CRM_CONTACT, bizId = "#updateReqVO.id", level = CrmPermissionLevelEnum.WRITE)
|
|
|
public void updateContact(CrmContactSaveReqVO updateReqVO) {
|
|
|
- // 1. 校验存在
|
|
|
+ // 1.1 校验存在
|
|
|
CrmContactDO oldContact = validateContactExists(updateReqVO.getId());
|
|
|
+ // 1.2 校验关联数据
|
|
|
validateRelationDataExists(updateReqVO);
|
|
|
|
|
|
// 2. 更新联系人
|
|
@@ -123,15 +124,15 @@ public class CrmContactServiceImpl implements CrmContactService {
|
|
|
private void validateRelationDataExists(CrmContactSaveReqVO saveReqVO) {
|
|
|
// 1. 校验客户
|
|
|
if (saveReqVO.getCustomerId() != null && customerService.getCustomer(saveReqVO.getCustomerId()) == null) {
|
|
|
- throw exception(CUSTOMER_NOT_EXISTS);
|
|
|
+ customerService.validateCustomer(saveReqVO.getCustomerId());
|
|
|
}
|
|
|
// 2. 校验负责人
|
|
|
- if (saveReqVO.getOwnerUserId() != null && adminUserApi.getUser(saveReqVO.getOwnerUserId()) == null) {
|
|
|
- throw exception(USER_NOT_EXISTS);
|
|
|
+ if (saveReqVO.getOwnerUserId() != null) {
|
|
|
+ adminUserApi.validateUser(saveReqVO.getOwnerUserId());
|
|
|
}
|
|
|
// 3. 直属上级
|
|
|
- if (saveReqVO.getParentId() != null && contactMapper.selectById(saveReqVO.getParentId()) == null) {
|
|
|
- throw exception(CONTACT_NOT_EXISTS);
|
|
|
+ if (saveReqVO.getParentId() != null) {
|
|
|
+ validateContactExists(saveReqVO.getParentId());
|
|
|
}
|
|
|
// 4. 如果有关联商机,则需要校验存在
|
|
|
if (saveReqVO.getBusinessId() != null && businessService.getBusiness(saveReqVO.getBusinessId()) == null) {
|
|
@@ -165,11 +166,11 @@ public class CrmContactServiceImpl implements CrmContactService {
|
|
|
}
|
|
|
|
|
|
private CrmContactDO validateContactExists(Long id) {
|
|
|
- CrmContactDO contactDO = contactMapper.selectById(id);
|
|
|
- if (contactDO == null) {
|
|
|
+ CrmContactDO contact = contactMapper.selectById(id);
|
|
|
+ if (contact == null) {
|
|
|
throw exception(CONTACT_NOT_EXISTS);
|
|
|
}
|
|
|
- return contactDO;
|
|
|
+ return contact;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -182,10 +183,10 @@ public class CrmContactServiceImpl implements CrmContactService {
|
|
|
CrmContactDO contact = validateContactExists(reqVO.getId());
|
|
|
|
|
|
// 2.1 数据权限转移
|
|
|
- permissionService.transferPermission(
|
|
|
- CrmContactConvert.INSTANCE.convert(reqVO, userId).setBizType(CrmBizTypeEnum.CRM_CONTACT.getType()));
|
|
|
+ permissionService.transferPermission(new CrmPermissionTransferReqBO(userId, CrmBizTypeEnum.CRM_CONTACT.getType(),
|
|
|
+ reqVO.getId(), reqVO.getNewOwnerUserId(), reqVO.getOldOwnerPermissionLevel()));
|
|
|
// 2.2 设置新的负责人
|
|
|
- contactMapper.updateOwnerUserIdById(reqVO.getId(), reqVO.getNewOwnerUserId());
|
|
|
+ contactMapper.updateById(new CrmContactDO().setId(reqVO.getId()).setOwnerUserId(reqVO.getNewOwnerUserId()));
|
|
|
|
|
|
// 3. 记录转移日志
|
|
|
LogRecordContext.putVariable("contact", contact);
|
|
@@ -194,11 +195,30 @@ public class CrmContactServiceImpl implements CrmContactService {
|
|
|
@Override
|
|
|
public void updateOwnerUserIdByCustomerId(Long customerId, Long ownerUserId) {
|
|
|
contactMapper.updateOwnerUserIdByCustomerId(customerId, ownerUserId);
|
|
|
+ // TODO @puhui999:操作日志、数据权限;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void updateContactFollowUpBatch(List<CrmUpdateFollowUpReqBO> updateFollowUpReqBOList) {
|
|
|
- contactMapper.updateBatch(CrmContactConvert.INSTANCE.convertList(updateFollowUpReqBOList));
|
|
|
+ @LogRecord(type = CRM_CONTACT_TYPE, subType = CRM_CONTACT_FOLLOW_UP_SUB_TYPE, bizNo = "{{#id}",
|
|
|
+ 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 校验存在
|
|
|
+ CrmContactDO contact = validateContactExists(id);
|
|
|
+
|
|
|
+ // 2. 更新联系人的跟进信息
|
|
|
+ contactMapper.updateById(new CrmContactDO().setId(id).setContactNextTime(contactNextTime)
|
|
|
+ .setContactLastTime(LocalDateTime.now()).setContactLastContent(contactLastContent));
|
|
|
+
|
|
|
+ // 3. 记录操作日志上下文
|
|
|
+ LogRecordContext.putVariable("contactName", contact.getName());
|
|
|
+ }
|
|
|
+
|
|
|
+ @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)));
|
|
|
}
|
|
|
|
|
|
//======================= 查询相关 =======================
|
|
@@ -226,12 +246,7 @@ public class CrmContactServiceImpl implements CrmContactService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<CrmContactDO> getContactList() {
|
|
|
- return contactMapper.selectList();
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public List<CrmContactDO> getSimpleContactList(Long userId) {
|
|
|
+ public List<CrmContactDO> getContactList(Long userId) {
|
|
|
CrmContactPageReqVO reqVO = new CrmContactPageReqVO();
|
|
|
reqVO.setPageSize(PAGE_SIZE_NONE); // 不分页
|
|
|
return contactMapper.selectPage(reqVO, userId).getList();
|