|
@@ -3,15 +3,12 @@ package cn.iocoder.yudao.module.crm.service.clue;
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.collection.ListUtil;
|
|
|
import cn.hutool.core.lang.Assert;
|
|
|
-import cn.hutool.core.util.ObjectUtil;
|
|
|
-import cn.hutool.extra.spring.SpringUtil;
|
|
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
|
|
import cn.iocoder.yudao.module.crm.controller.admin.clue.vo.CrmCluePageReqVO;
|
|
|
import cn.iocoder.yudao.module.crm.controller.admin.clue.vo.CrmClueSaveReqVO;
|
|
|
import cn.iocoder.yudao.module.crm.controller.admin.clue.vo.CrmClueTransferReqVO;
|
|
|
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerSaveReqVO;
|
|
|
-import cn.iocoder.yudao.module.crm.convert.clue.CrmClueConvert;
|
|
|
import cn.iocoder.yudao.module.crm.dal.dataobject.clue.CrmClueDO;
|
|
|
import cn.iocoder.yudao.module.crm.dal.dataobject.followup.CrmFollowUpRecordDO;
|
|
|
import cn.iocoder.yudao.module.crm.dal.mysql.clue.CrmClueMapper;
|
|
@@ -25,6 +22,7 @@ import cn.iocoder.yudao.module.crm.service.followup.bo.CrmFollowUpCreateReqBO;
|
|
|
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;
|
|
@@ -37,12 +35,13 @@ import org.springframework.validation.annotation.Validated;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.Collection;
|
|
|
import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
import java.util.Objects;
|
|
|
|
|
|
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.*;
|
|
|
+import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
|
|
|
+import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.singleton;
|
|
|
+import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.CLUE_NOT_EXISTS;
|
|
|
+import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.CLUE_TRANSFORM_FAIL_ALREADY;
|
|
|
import static cn.iocoder.yudao.module.crm.enums.LogRecordConstants.*;
|
|
|
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.USER_NOT_EXISTS;
|
|
|
|
|
@@ -60,18 +59,18 @@ public class CrmClueServiceImpl implements CrmClueService {
|
|
|
|
|
|
@Resource
|
|
|
private CrmCustomerService customerService;
|
|
|
-
|
|
|
@Resource
|
|
|
private CrmPermissionService crmPermissionService;
|
|
|
@Resource
|
|
|
private CrmFollowUpRecordService followUpRecordService;
|
|
|
+
|
|
|
@Resource
|
|
|
private AdminUserApi adminUserApi;
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- @LogRecord(type = CRM_LEADS_TYPE, subType = CRM_LEADS_CREATE_SUB_TYPE, bizNo = "{{#clue.id}}",
|
|
|
- success = CRM_LEADS_CREATE_SUCCESS)
|
|
|
+ @LogRecord(type = CRM_CLUE_TYPE, subType = CRM_CLUE_CREATE_SUB_TYPE, bizNo = "{{#clue.id}}",
|
|
|
+ success = CRM_CLUE_CREATE_SUCCESS)
|
|
|
public Long createClue(CrmClueSaveReqVO createReqVO) {
|
|
|
// 1.1 校验关联数据
|
|
|
validateRelationDataExists(createReqVO);
|
|
@@ -84,7 +83,7 @@ public class CrmClueServiceImpl implements CrmClueService {
|
|
|
clueMapper.insert(clue);
|
|
|
|
|
|
// 3. 创建数据权限
|
|
|
- CrmPermissionCreateReqBO createReqBO = new CrmPermissionCreateReqBO().setBizType(CrmBizTypeEnum.CRM_LEADS.getType())
|
|
|
+ CrmPermissionCreateReqBO createReqBO = new CrmPermissionCreateReqBO().setBizType(CrmBizTypeEnum.CRM_CLUE.getType())
|
|
|
.setBizId(clue.getId()).setUserId(clue.getOwnerUserId()).setLevel(CrmPermissionLevelEnum.OWNER.getLevel());
|
|
|
crmPermissionService.createPermission(createReqBO);
|
|
|
|
|
@@ -95,9 +94,9 @@ public class CrmClueServiceImpl implements CrmClueService {
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- @LogRecord(type = CRM_LEADS_TYPE, subType = CRM_LEADS_UPDATE_SUB_TYPE, bizNo = "{{#updateReqVO.id}}",
|
|
|
- success = CRM_LEADS_UPDATE_SUCCESS)
|
|
|
- @CrmPermission(bizType = CrmBizTypeEnum.CRM_LEADS, bizId = "#updateReq.id", level = CrmPermissionLevelEnum.OWNER)
|
|
|
+ @LogRecord(type = CRM_CLUE_TYPE, subType = CRM_CLUE_UPDATE_SUB_TYPE, bizNo = "{{#updateReqVO.id}}",
|
|
|
+ success = CRM_CLUE_UPDATE_SUCCESS)
|
|
|
+ @CrmPermission(bizType = CrmBizTypeEnum.CRM_CLUE, bizId = "#updateReq.id", level = CrmPermissionLevelEnum.OWNER)
|
|
|
public void updateClue(CrmClueSaveReqVO updateReq) {
|
|
|
Assert.notNull(updateReq.getId(), "线索编号不能为空");
|
|
|
// 1.1 校验线索是否存在
|
|
@@ -114,15 +113,25 @@ public class CrmClueServiceImpl implements CrmClueService {
|
|
|
LogRecordContext.putVariable("clueName", oldClue.getName());
|
|
|
}
|
|
|
|
|
|
+ private void validateRelationDataExists(CrmClueSaveReqVO reqVO) {
|
|
|
+ // 校验负责人
|
|
|
+ if (Objects.nonNull(reqVO.getOwnerUserId()) &&
|
|
|
+ Objects.isNull(adminUserApi.getUser(reqVO.getOwnerUserId()))) {
|
|
|
+ throw exception(USER_NOT_EXISTS);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
- @LogRecord(type = CRM_LEADS_TYPE, subType = CRM_LEADS_UPDATE_SUB_TYPE, bizNo = "{{#updateReq.bizId}",
|
|
|
- success = CRM_LEADS_UPDATE_SUCCESS)
|
|
|
- public void updateClueFollowUp(CrmUpdateFollowUpReqBO updateReq) {
|
|
|
+ @LogRecord(type = CRM_CLUE_TYPE, subType = CRM_CLUE_FOLLOW_UP_SUB_TYPE, bizNo = "{{#id}",
|
|
|
+ success = CRM_CLUE_FOLLOW_UP_SUCCESS)
|
|
|
+ @CrmPermission(bizType = CrmBizTypeEnum.CRM_CLUE, bizId = "#id", level = CrmPermissionLevelEnum.WRITE)
|
|
|
+ public void updateClueFollowUp(Long id, LocalDateTime contactNextTime, String contactLastContent) {
|
|
|
// 校验线索是否存在
|
|
|
- CrmClueDO oldClue = validateClueExists(updateReq.getBizId());
|
|
|
+ CrmClueDO oldClue = validateClueExists(id);
|
|
|
|
|
|
// 更新
|
|
|
- clueMapper.updateById(BeanUtils.toBean(updateReq, CrmClueDO.class).setId(updateReq.getBizId()));
|
|
|
+ clueMapper.updateById(new CrmClueDO().setId(id).setFollowUpStatus(true).setContactNextTime(contactNextTime)
|
|
|
+ .setContactLastTime(LocalDateTime.now()).setContactLastContent(contactLastContent));
|
|
|
|
|
|
// 3. 记录操作日志上下文
|
|
|
LogRecordContext.putVariable(DiffParseFunction.OLD_OBJECT, BeanUtils.toBean(oldClue, CrmUpdateFollowUpReqBO.class));
|
|
@@ -131,9 +140,9 @@ public class CrmClueServiceImpl implements CrmClueService {
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- @LogRecord(type = CRM_LEADS_TYPE, subType = CRM_LEADS_DELETE_SUB_TYPE, bizNo = "{{#id}}",
|
|
|
- success = CRM_LEADS_DELETE_SUCCESS)
|
|
|
- @CrmPermission(bizType = CrmBizTypeEnum.CRM_LEADS, bizId = "#id", level = CrmPermissionLevelEnum.OWNER)
|
|
|
+ @LogRecord(type = CRM_CLUE_TYPE, subType = CRM_CLUE_DELETE_SUB_TYPE, bizNo = "{{#id}}",
|
|
|
+ success = CRM_CLUE_DELETE_SUCCESS)
|
|
|
+ @CrmPermission(bizType = CrmBizTypeEnum.CRM_CLUE, bizId = "#id", level = CrmPermissionLevelEnum.OWNER)
|
|
|
public void deleteClue(Long id) {
|
|
|
// 1. 校验存在
|
|
|
CrmClueDO clue = validateClueExists(id);
|
|
@@ -142,28 +151,29 @@ public class CrmClueServiceImpl implements CrmClueService {
|
|
|
clueMapper.deleteById(id);
|
|
|
|
|
|
// 3. 删除数据权限
|
|
|
- crmPermissionService.deletePermission(CrmBizTypeEnum.CRM_LEADS.getType(), id);
|
|
|
+ crmPermissionService.deletePermission(CrmBizTypeEnum.CRM_CLUE.getType(), id);
|
|
|
|
|
|
// 4. 删除跟进
|
|
|
- followUpRecordService.deleteFollowUpRecordByBiz(CrmBizTypeEnum.CRM_LEADS.getType(), id);
|
|
|
+ followUpRecordService.deleteFollowUpRecordByBiz(CrmBizTypeEnum.CRM_CLUE.getType(), id);
|
|
|
|
|
|
- // 记录操作日志上下文
|
|
|
+ // 5. 记录操作日志上下文
|
|
|
LogRecordContext.putVariable("clueName", clue.getName());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- @LogRecord(type = CRM_LEADS_TYPE, subType = CRM_LEADS_TRANSFER_SUB_TYPE, bizNo = "{{#reqVO.id}}",
|
|
|
- success = CRM_LEADS_TRANSFER_SUCCESS)
|
|
|
- @CrmPermission(bizType = CrmBizTypeEnum.CRM_LEADS, bizId = "#reqVO.id", level = CrmPermissionLevelEnum.OWNER)
|
|
|
+ @LogRecord(type = CRM_CLUE_TYPE, subType = CRM_CLUE_TRANSFER_SUB_TYPE, bizNo = "{{#reqVO.id}}",
|
|
|
+ success = CRM_CLUE_TRANSFER_SUCCESS)
|
|
|
+ @CrmPermission(bizType = CrmBizTypeEnum.CRM_CLUE, bizId = "#reqVO.id", level = CrmPermissionLevelEnum.OWNER)
|
|
|
public void transferClue(CrmClueTransferReqVO reqVO, Long userId) {
|
|
|
// 1 校验线索是否存在
|
|
|
CrmClueDO clue = validateClueExists(reqVO.getId());
|
|
|
|
|
|
// 2.1 数据权限转移
|
|
|
- crmPermissionService.transferPermission(CrmClueConvert.INSTANCE.convert(reqVO, userId).setBizType(CrmBizTypeEnum.CRM_LEADS.getType()));
|
|
|
+ crmPermissionService.transferPermission(new CrmPermissionTransferReqBO(userId, CrmBizTypeEnum.CRM_CLUE.getType(),
|
|
|
+ reqVO.getId(), reqVO.getNewOwnerUserId(), reqVO.getOldOwnerPermissionLevel()));
|
|
|
// 2.2 设置新的负责人
|
|
|
- clueMapper.updateOwnerUserIdById(reqVO.getId(), reqVO.getNewOwnerUserId());
|
|
|
+ clueMapper.updateById(new CrmClueDO().setId(reqVO.getId()).setOwnerUserId(reqVO.getNewOwnerUserId()));
|
|
|
|
|
|
// 3. 记录转移日志
|
|
|
LogRecordContext.putVariable("clue", clue);
|
|
@@ -171,69 +181,32 @@ public class CrmClueServiceImpl implements CrmClueService {
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- @CrmPermission(bizType = CrmBizTypeEnum.CRM_LEADS, bizId = "#ids", level = CrmPermissionLevelEnum.OWNER)
|
|
|
- public void transformClue(List<Long> ids, Long userId) {
|
|
|
+ @LogRecord(type = CRM_CLUE_TYPE, subType = CRM_CLUE_TRANSLATE_SUB_TYPE, bizNo = "{{#id}}",
|
|
|
+ success = CRM_CLUE_TRANSLATE_SUCCESS)
|
|
|
+ @CrmPermission(bizType = CrmBizTypeEnum.CRM_CLUE, bizId = "#id", level = CrmPermissionLevelEnum.OWNER)
|
|
|
+ public void transformClue(Long id, Long userId) {
|
|
|
// 1.1 校验线索都存在
|
|
|
- List<CrmClueDO> clues = getClueList(ids, userId);
|
|
|
- if (CollUtil.isEmpty(clues) || ObjectUtil.notEqual(clues.size(), ids.size())) {
|
|
|
- ids.removeAll(convertSet(clues, CrmClueDO::getId));
|
|
|
- throw exception(CLUE_NOT_EXISTS_ANY, ids);
|
|
|
- }
|
|
|
- // 1.2 存在已经转化的,直接提示哈。避免操作的用户,以为都转化成功了
|
|
|
- List<CrmClueDO> translatedClues = filterList(clues,
|
|
|
- clue -> ObjectUtil.equal(Boolean.TRUE, clue.getTransformStatus()));
|
|
|
- if (CollUtil.isNotEmpty(translatedClues)) {
|
|
|
- throw exception(CLUE_TRANSFORM_FAIL_ALREADY, convertSet(translatedClues, CrmClueDO::getId));
|
|
|
+ CrmClueDO clue = validateClueExists(id);
|
|
|
+ // 1.2 存在已经转化的
|
|
|
+ if (clue.getTransformStatus()) {
|
|
|
+ throw exception(CLUE_TRANSFORM_FAIL_ALREADY);
|
|
|
}
|
|
|
|
|
|
// 2.1 遍历线索(未转化的线索),创建对应的客户
|
|
|
- clues.forEach(clue -> {
|
|
|
- Long customerId = customerService.createCustomer(BeanUtils.toBean(clue, CrmCustomerCreateReqBO.class), userId);
|
|
|
- clue.setCustomerId(customerId);
|
|
|
- });
|
|
|
+ Long customerId = customerService.createCustomer(BeanUtils.toBean(clue, CrmCustomerCreateReqBO.class), userId);
|
|
|
// 2.2 更新线索
|
|
|
- clueMapper.updateBatch(convertList(clues, clue -> new CrmClueDO().setId(clue.getId())
|
|
|
- .setTransformStatus(Boolean.TRUE).setCustomerId(clue.getCustomerId())));
|
|
|
+ clueMapper.updateById(new CrmClueDO().setId(id).setTransformStatus(Boolean.TRUE).setCustomerId(customerId));
|
|
|
// 2.3 复制跟进记录
|
|
|
- copyFollowUpRecords(clues);
|
|
|
-
|
|
|
- // 3. 记录操作日志
|
|
|
- for (CrmClueDO clue : clues) {
|
|
|
- getSelf().translateCustomerLog(clue);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 线索被转换客户后,需要将线索的跟进记录,复制到客户上
|
|
|
- *
|
|
|
- * @param clues 被转化的线索
|
|
|
- */
|
|
|
- private void copyFollowUpRecords(List<CrmClueDO> clues) {
|
|
|
List<CrmFollowUpRecordDO> followUpRecords = followUpRecordService.getFollowUpRecordByBiz(
|
|
|
- CrmBizTypeEnum.CRM_LEADS.getType(), convertSet(clues, CrmClueDO::getId));
|
|
|
- if (CollUtil.isEmpty(followUpRecords)) {
|
|
|
- return;
|
|
|
+ CrmBizTypeEnum.CRM_CLUE.getType(), singleton(clue.getId()));
|
|
|
+ if (CollUtil.isNotEmpty(followUpRecords)) {
|
|
|
+ followUpRecordService.createFollowUpRecordBatch(convertList(followUpRecords, record ->
|
|
|
+ BeanUtils.toBean(record, CrmFollowUpCreateReqBO.class)
|
|
|
+ .setBizType(CrmBizTypeEnum.CRM_CUSTOMER.getType()).setBizId(customerId)));
|
|
|
}
|
|
|
- // 创建跟进
|
|
|
- Map<Long, CrmClueDO> clueMap = convertMap(clues, CrmClueDO::getId);
|
|
|
- followUpRecordService.createFollowUpRecordBatch(convertList(followUpRecords, followUpRecord ->
|
|
|
- BeanUtils.toBean(followUpRecord, CrmFollowUpCreateReqBO.class).setBizType(CrmBizTypeEnum.CRM_CUSTOMER.getType())
|
|
|
- .setBizId(clueMap.get(followUpRecord.getBizId()).getCustomerId())));
|
|
|
- }
|
|
|
-
|
|
|
- @LogRecord(type = CRM_LEADS_TYPE, subType = CRM_LEADS_TRANSLATE_SUB_TYPE, bizNo = "{{#clue.id}}",
|
|
|
- success = CRM_LEADS_TRANSLATE_SUCCESS)
|
|
|
- public void translateCustomerLog(CrmClueDO clue) {
|
|
|
- // 记录操作日志上下文
|
|
|
- LogRecordContext.putVariable("clue", clue);
|
|
|
- }
|
|
|
|
|
|
- private void validateRelationDataExists(CrmClueSaveReqVO reqVO) {
|
|
|
- // 校验负责人
|
|
|
- if (Objects.nonNull(reqVO.getOwnerUserId()) &&
|
|
|
- Objects.isNull(adminUserApi.getUser(reqVO.getOwnerUserId()))) {
|
|
|
- throw exception(USER_NOT_EXISTS);
|
|
|
- }
|
|
|
+ // 3. 记录操作日志上下文
|
|
|
+ LogRecordContext.putVariable("clueName", clue.getName());
|
|
|
}
|
|
|
|
|
|
private CrmClueDO validateClueExists(Long id) {
|
|
@@ -245,7 +218,7 @@ public class CrmClueServiceImpl implements CrmClueService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- @CrmPermission(bizType = CrmBizTypeEnum.CRM_LEADS, bizId = "#id", level = CrmPermissionLevelEnum.READ)
|
|
|
+ @CrmPermission(bizType = CrmBizTypeEnum.CRM_CLUE, bizId = "#id", level = CrmPermissionLevelEnum.READ)
|
|
|
public CrmClueDO getClue(Long id) {
|
|
|
return clueMapper.selectById(id);
|
|
|
}
|
|
@@ -263,18 +236,9 @@ public class CrmClueServiceImpl implements CrmClueService {
|
|
|
return clueMapper.selectPage(pageReqVO, userId);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 获得自身的代理对象,解决 AOP 生效问题
|
|
|
- *
|
|
|
- * @return 自己
|
|
|
- */
|
|
|
- private CrmClueServiceImpl getSelf() {
|
|
|
- return SpringUtil.getBean(getClass());
|
|
|
- }
|
|
|
-
|
|
|
@Override
|
|
|
- public Long getFollowLeadsCount(Long userId) {
|
|
|
- return clueMapper.selectFollowLeadsCount(userId);
|
|
|
+ public Long getFollowClueCount(Long userId) {
|
|
|
+ return clueMapper.selectCountByFollow(userId);
|
|
|
}
|
|
|
|
|
|
}
|