Эх сурвалжийг харах

CRM-线索:完善线索转客户

puhui999 1 жил өмнө
parent
commit
8675d13548
11 өөрчлөгдсөн 360 нэмэгдсэн , 36 устгасан
  1. 1 1
      yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/clue/CrmClueController.java
  2. 13 0
      yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/followup/CrmFollowUpRecordMapper.java
  3. 2 1
      yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/clue/CrmClueService.java
  4. 56 33
      yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/clue/CrmClueServiceImpl.java
  5. 10 0
      yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerService.java
  6. 22 0
      yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerServiceImpl.java
  7. 125 0
      yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/bo/CrmCustomerCreateReqBO.java
  8. 28 0
      yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/followup/CrmFollowUpRecordService.java
  9. 23 0
      yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/followup/CrmFollowUpRecordServiceImpl.java
  10. 78 0
      yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/followup/bo/CrmFollowUpCreateReqBO.java
  11. 2 1
      yudao-module-crm/yudao-module-crm-biz/src/test/java/cn/iocoder/yudao/module/crm/service/clue/CrmClueServiceImplTest.java

+ 1 - 1
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/clue/CrmClueController.java

@@ -39,7 +39,7 @@ public class CrmClueController {
     @Operation(summary = "创建线索")
     @PreAuthorize("@ss.hasPermission('crm:clue:create')")
     public CommonResult<Long> createClue(@Valid @RequestBody CrmClueSaveReqVO createReqVO) {
-        return success(clueService.createClue(createReqVO));
+        return success(clueService.createClue(createReqVO, getLoginUserId()));
     }
 
     @PutMapping("/update")

+ 13 - 0
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/followup/CrmFollowUpRecordMapper.java

@@ -7,6 +7,9 @@ import cn.iocoder.yudao.module.crm.controller.admin.followup.vo.CrmFollowUpRecor
 import cn.iocoder.yudao.module.crm.dal.dataobject.followup.CrmFollowUpRecordDO;
 import org.apache.ibatis.annotations.Mapper;
 
+import java.util.Collection;
+import java.util.List;
+
 /**
  * 跟进记录 Mapper
  *
@@ -22,4 +25,14 @@ public interface CrmFollowUpRecordMapper extends BaseMapperX<CrmFollowUpRecordDO
                 .orderByDesc(CrmFollowUpRecordDO::getId));
     }
 
+    default void deleteByBiz(Integer bizType, Long bizId) {
+        delete(new LambdaQueryWrapperX<CrmFollowUpRecordDO>().eq(CrmFollowUpRecordDO::getBizType, bizType)
+                .eq(CrmFollowUpRecordDO::getBizId, bizId));
+    }
+
+    default List<CrmFollowUpRecordDO> selectListByBiz(Integer bizType, Collection<Long> bizIds) {
+        return selectList(new LambdaQueryWrapperX<CrmFollowUpRecordDO>().eq(CrmFollowUpRecordDO::getBizType, bizType)
+                .in(CrmFollowUpRecordDO::getBizId, bizIds));
+    }
+
 }

+ 2 - 1
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/clue/CrmClueService.java

@@ -23,9 +23,10 @@ public interface CrmClueService {
      * 创建线索
      *
      * @param createReqVO 创建信息
+     * @param userId      用户编号
      * @return 编号
      */
-    Long createClue(@Valid CrmClueSaveReqVO createReqVO);
+    Long createClue(@Valid CrmClueSaveReqVO createReqVO, Long userId);
 
     /**
      * 更新线索

+ 56 - 33
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/clue/CrmClueServiceImpl.java

@@ -3,10 +3,9 @@ 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.ObjUtil;
 import cn.hutool.core.util.ObjectUtil;
-import cn.hutool.core.util.StrUtil;
 import cn.iocoder.yudao.framework.common.pojo.PageResult;
-import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
 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;
@@ -15,11 +14,16 @@ import cn.iocoder.yudao.module.crm.controller.admin.clue.vo.CrmClueTransformReqV
 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.customer.CrmCustomerDO;
+import cn.iocoder.yudao.module.crm.dal.dataobject.followup.CrmFollowUpRecordDO;
 import cn.iocoder.yudao.module.crm.dal.mysql.clue.CrmClueMapper;
 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;
 import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerService;
+import cn.iocoder.yudao.module.crm.service.customer.bo.CrmCustomerCreateReqBO;
+import cn.iocoder.yudao.module.crm.service.followup.CrmFollowUpRecordService;
+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;
@@ -32,17 +36,14 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.validation.annotation.Validated;
 
-import java.util.Collection;
-import java.util.List;
-import java.util.Objects;
-import java.util.Set;
+import java.util.*;
 
 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.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
+import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*;
 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;
 
 /**
  * 线索 Service 实现类
@@ -61,7 +62,8 @@ public class CrmClueServiceImpl implements CrmClueService {
 
     @Resource
     private CrmPermissionService crmPermissionService;
-
+    @Resource
+    private CrmFollowUpRecordService followUpRecordService;
     @Resource
     private AdminUserApi adminUserApi;
 
@@ -69,21 +71,23 @@ public class CrmClueServiceImpl implements CrmClueService {
     @Transactional(rollbackFor = Exception.class)
     @LogRecord(type = CRM_LEADS_TYPE, subType = CRM_LEADS_CREATE_SUB_TYPE, bizNo = "{{#clue.id}}",
             success = CRM_LEADS_CREATE_SUCCESS)
-    public Long createClue(CrmClueSaveReqVO createReqVO) {
+    public Long createClue(CrmClueSaveReqVO createReqVO, Long userId) {
         // 1. 校验关联数据
         validateRelationDataExists(createReqVO);
 
         // 2. 插入
         CrmClueDO clue = BeanUtils.toBean(createReqVO, CrmClueDO.class);
+        if (ObjUtil.isNull(createReqVO.getOwnerUserId())) {
+            clue.setOwnerUserId(userId); // 如果没有设置负责人那么默认操作人为负责人
+        } else {
+            // 校验负责人是否存在
+            adminUserApi.validateUserList(singletonList(createReqVO.getOwnerUserId()));
+        }
         clueMapper.insert(clue);
 
         // 3. 创建数据权限
-        CrmPermissionCreateReqBO createReqBO = new CrmPermissionCreateReqBO()
-                .setBizType(CrmBizTypeEnum.CRM_LEADS.getType())
-                .setBizId(clue.getId())
-                // 设置当前操作的人为负责人
-                .setUserId(getLoginUserId())
-                .setLevel(CrmPermissionLevelEnum.OWNER.getLevel());
+        CrmPermissionCreateReqBO createReqBO = new CrmPermissionCreateReqBO().setBizType(CrmBizTypeEnum.CRM_LEADS.getType())
+                .setBizId(clue.getId()).setUserId(clue.getOwnerUserId()).setLevel(CrmPermissionLevelEnum.OWNER.getLevel());
         crmPermissionService.createPermission(createReqBO);
 
         // 4. 记录操作日志上下文
@@ -132,7 +136,10 @@ public class CrmClueServiceImpl implements CrmClueService {
         // 3. 删除数据权限
         crmPermissionService.deletePermission(CrmBizTypeEnum.CRM_LEADS.getType(), id);
 
-        // 4. 记录操作日志上下文
+        // 4. 删除跟进
+        followUpRecordService.deleteFollowUpRecordByBiz(CrmBizTypeEnum.CRM_LEADS.getType(), id);
+
+        // 记录操作日志上下文
         LogRecordContext.putVariable("clueName", clue.getName());
     }
 
@@ -179,31 +186,47 @@ public class CrmClueServiceImpl implements CrmClueService {
     @Override
     @Transactional(rollbackFor = Exception.class)
     public void translateCustomer(CrmClueTransformReqVO reqVO, Long userId) {
-        // 校验线索都存在
+        // 1.1 校验线索都存在
         Set<Long> clueIds = reqVO.getIds();
         List<CrmClueDO> clues = getClueList(clueIds, userId);
         if (CollUtil.isEmpty(clues) || ObjectUtil.notEqual(clues.size(), clueIds.size())) {
             clueIds.removeAll(convertSet(clues, CrmClueDO::getId));
-            throw exception(CLUE_ANY_CLUE_NOT_EXISTS, StrUtil.join(",", clueIds));
+            throw exception(CLUE_ANY_CLUE_NOT_EXISTS, clueIds);
         }
-
-        // 存在已经转化的,直接提示哈。避免操作的用户,以为都转化成功了
-        List<CrmClueDO> translatedClues = CollectionUtils.filterList(clues,
+        // 1.2 存在已经转化的,直接提示哈。避免操作的用户,以为都转化成功了
+        List<CrmClueDO> translatedClues = filterList(clues,
                 clue -> ObjectUtil.equal(Boolean.TRUE, clue.getTransformStatus()));
         if (CollUtil.isNotEmpty(translatedClues)) {
-            throw exception(CLUE_ANY_CLUE_ALREADY_TRANSLATED, StrUtil.join(",", convertSet(translatedClues, CrmClueDO::getId)));
+            throw exception(CLUE_ANY_CLUE_ALREADY_TRANSLATED, convertSet(translatedClues, CrmClueDO::getId));
+        }
+
+        // 2. 遍历线索(未转化的线索),创建对应的客户
+        List<CrmClueDO> translateClues = filterList(clues, clue -> ObjUtil.equal(Boolean.FALSE, clue.getTransformStatus()));
+        List<CrmCustomerDO> customers = customerService.createCustomerBatch(convertList(translateClues, clue ->
+                BeanUtils.toBean(clue, CrmCustomerCreateReqBO.class)), userId);
+
+        Map<Long, Long> clueCustomerIdMap = new HashMap<>(translateClues.size());
+        // 2.1 更新线索
+        clueMapper.updateBatch(convertList(customers, customer -> {
+            CrmClueDO firstClue = findFirst(translateClues, clue -> ObjUtil.equal(clue.getName(), customer.getName()));
+            clueCustomerIdMap.put(firstClue.getId(), customer.getId());
+            return new CrmClueDO().setId(firstClue.getId()).setTransformStatus(Boolean.TRUE).setCustomerId(customer.getId());
+        }));
+        // 2.3 复制跟进
+        updateFollowUpRecords(clueCustomerIdMap);
+    }
+
+    private void updateFollowUpRecords(Map<Long, Long> clueCustomerIdMap) {
+        List<CrmFollowUpRecordDO> followUpRecords = followUpRecordService.getFollowUpRecordByBiz(
+                CrmBizTypeEnum.CRM_LEADS.getType(), clueCustomerIdMap.keySet());
+        if (CollUtil.isEmpty(followUpRecords)) {
+            return;
         }
 
-        // 遍历线索(未转化的线索),创建对应的客户
-        reqVO.getIds().forEach(id -> {
-            // 1. 创建客户
-            CrmCustomerSaveReqVO customerSaveReqVO = BeanUtils.toBean(id, CrmCustomerSaveReqVO.class).setId(null);
-            Long customerId = customerService.createCustomer(customerSaveReqVO, userId);
-            // TODO @puhui999:如果有跟进记录,需要一起转过去;提问:艿艿这里是复制线索所有的跟进吗?还是直接把线索相关的跟进 bizType、bizId 全改为关联客户?
-            // 2. 更新线索
-            clueMapper.updateById(new CrmClueDO().setId(id)
-                    .setTransformStatus(Boolean.TRUE).setCustomerId(customerId));
-        });
+        // 创建跟进
+        followUpRecordService.createFollowUpRecordBatch(convertList(followUpRecords, followUpRecord ->
+                BeanUtils.toBean(followUpRecord, CrmFollowUpCreateReqBO.class).setBizType(CrmBizTypeEnum.CRM_CUSTOMER.getType())
+                        .setBizId(clueCustomerIdMap.get(followUpRecord.getBizId()))));
     }
 
     private void validateRelationDataExists(CrmClueSaveReqVO reqVO) {

+ 10 - 0
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerService.java

@@ -6,6 +6,7 @@ import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerPageR
 import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerSaveReqVO;
 import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerTransferReqVO;
 import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
+import cn.iocoder.yudao.module.crm.service.customer.bo.CrmCustomerCreateReqBO;
 import cn.iocoder.yudao.module.crm.service.followup.bo.CrmUpdateFollowUpReqBO;
 import jakarta.validation.Valid;
 
@@ -98,6 +99,15 @@ public interface CrmCustomerService {
      */
     void updateCustomerFollowUp(CrmUpdateFollowUpReqBO customerUpdateFollowUpReqBO);
 
+    /**
+     * 批量创建客户
+     *
+     * @param customerCreateReqBOs 请求
+     * @param userId               用户编号
+     * @return 客户列表
+     */
+    List<CrmCustomerDO> createCustomerBatch(List<CrmCustomerCreateReqBO> customerCreateReqBOs, Long userId);
+
     // ==================== 公海相关操作 ====================
 
     /**

+ 22 - 0
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerServiceImpl.java

@@ -21,6 +21,7 @@ import cn.iocoder.yudao.module.crm.framework.permission.core.util.CrmPermissionU
 import cn.iocoder.yudao.module.crm.service.business.CrmBusinessService;
 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.bo.CrmCustomerCreateReqBO;
 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;
@@ -42,10 +43,12 @@ 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.*;
 import static cn.iocoder.yudao.module.crm.enums.LogRecordConstants.*;
 import static cn.iocoder.yudao.module.crm.enums.customer.CrmCustomerLimitConfigTypeEnum.CUSTOMER_LOCK_LIMIT;
 import static cn.iocoder.yudao.module.crm.enums.customer.CrmCustomerLimitConfigTypeEnum.CUSTOMER_OWNER_LIMIT;
+import static java.util.Collections.emptyList;
 import static java.util.Collections.singletonList;
 
 /**
@@ -209,6 +212,25 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
         customerMapper.updateById(BeanUtils.toBean(customerUpdateFollowUpReqBO, CrmCustomerDO.class).setId(customerUpdateFollowUpReqBO.getBizId()));
     }
 
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public List<CrmCustomerDO> createCustomerBatch(List<CrmCustomerCreateReqBO> customerCreateReqBOs, Long userId) {
+        if (CollUtil.isEmpty(customerCreateReqBOs)) {
+            return emptyList();
+        }
+
+        // 创建客户
+        List<CrmCustomerDO> customers = convertList(customerCreateReqBOs, customerBO ->
+                BeanUtils.toBean(customerBO, CrmCustomerDO.class).setOwnerUserId(userId));
+        customerMapper.insertBatch(customers);
+
+        // 创建负责人数据权限
+        permissionService.createPermissionBatch(convertList(customers, customer -> new CrmPermissionCreateReqBO()
+                .setBizType(CrmBizTypeEnum.CRM_CUSTOMER.getType()).setBizId(customer.getId()).setUserId(userId)
+                .setLevel(CrmPermissionLevelEnum.OWNER.getLevel())));
+        return customers;
+    }
+
     // ==================== 公海相关操作 ====================
 
     @Override

+ 125 - 0
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/bo/CrmCustomerCreateReqBO.java

@@ -0,0 +1,125 @@
+package cn.iocoder.yudao.module.crm.service.customer.bo;
+
+import cn.iocoder.yudao.framework.common.validation.Mobile;
+import cn.iocoder.yudao.framework.common.validation.Telephone;
+import cn.iocoder.yudao.module.crm.enums.DictTypeConstants;
+import jakarta.validation.constraints.Email;
+import jakarta.validation.constraints.NotEmpty;
+import jakarta.validation.constraints.Size;
+import lombok.Data;
+
+import java.time.LocalDateTime;
+
+/**
+ * 客户创建 Create Req BO
+ *
+ * @author HUIHUI
+ */
+@Data
+public class CrmCustomerCreateReqBO {
+
+    /**
+     * 客户名称
+     */
+    @NotEmpty(message = "客户名称不能为空")
+    private String name;
+    /**
+     * 跟进状态
+     */
+    private Boolean followUpStatus;
+    /**
+     * 锁定状态
+     */
+    private Boolean lockStatus;
+    /**
+     * 成交状态
+     */
+    private Boolean dealStatus;
+    /**
+     * 所属行业
+     *
+     * 对应字典 {@link DictTypeConstants#CRM_CUSTOMER_INDUSTRY}
+     */
+    private Integer industryId;
+    /**
+     * 客户等级
+     *
+     * 对应字典 {@link DictTypeConstants#CRM_CUSTOMER_LEVEL}
+     */
+    private Integer level;
+    /**
+     * 客户来源
+     *
+     * 对应字典 {@link DictTypeConstants#CRM_CUSTOMER_SOURCE}
+     */
+    private Integer source;
+
+    /**
+     * 手机
+     */
+    @Mobile
+    private String mobile;
+    /**
+     * 电话
+     */
+    @Telephone
+    private String telephone;
+    /**
+     * 网址
+     */
+    private String website;
+    /**
+     * QQ
+     */
+    private String qq;
+    /**
+     * wechat
+     */
+    private String wechat;
+
+    /**
+     * 邮箱
+     */
+    @Email(message = "邮箱格式不正确")
+    private String email;
+
+    /**
+     * 客户描述
+     */
+    @Size(max = 4096, message = "客户描述长度不能超过 4096 个字符")
+    private String description;
+    /**
+     * 备注
+     */
+    private String remark;
+    /**
+     * 负责人的用户编号
+     *
+     * 关联 AdminUserDO 的 id 字段
+     */
+    private Long ownerUserId;
+    /**
+     * 所在地
+     *
+     * 关联 {@link cn.iocoder.yudao.framework.ip.core.Area#getId()} 字段
+     */
+    private Integer areaId;
+    /**
+     * 详细地址
+     */
+    private String detailAddress;
+
+    /**
+     * 最后跟进时间
+     */
+    private LocalDateTime contactLastTime;
+    /**
+     * 最后跟进内容
+     */
+    private String contactLastContent;
+    /**
+     * 下次联系时间
+     */
+    private LocalDateTime contactNextTime;
+
+}

+ 28 - 0
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/followup/CrmFollowUpRecordService.java

@@ -4,8 +4,12 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
 import cn.iocoder.yudao.module.crm.controller.admin.followup.vo.CrmFollowUpRecordPageReqVO;
 import cn.iocoder.yudao.module.crm.controller.admin.followup.vo.CrmFollowUpRecordSaveReqVO;
 import cn.iocoder.yudao.module.crm.dal.dataobject.followup.CrmFollowUpRecordDO;
+import cn.iocoder.yudao.module.crm.service.followup.bo.CrmFollowUpCreateReqBO;
 import jakarta.validation.Valid;
 
+import java.util.Collection;
+import java.util.List;
+
 /**
  * 跟进记录 Service 接口
  *
@@ -21,6 +25,13 @@ public interface CrmFollowUpRecordService {
      */
     Long createFollowUpRecord(@Valid CrmFollowUpRecordSaveReqVO createReqVO);
 
+    /**
+     * 创建更进
+     *
+     * @param followUpCreateReqBOs 请求
+     */
+    void createFollowUpRecordBatch(List<CrmFollowUpCreateReqBO> followUpCreateReqBOs);
+
     /**
      * 删除跟进记录 (数据权限基于 bizType、 bizId)
      *
@@ -29,6 +40,14 @@ public interface CrmFollowUpRecordService {
      */
     void deleteFollowUpRecord(Long id, Long userId);
 
+    /**
+     * 删除跟进
+     *
+     * @param bizType 模块类型
+     * @param bizId   模块数据编号
+     */
+    void deleteFollowUpRecordByBiz(Integer bizType, Long bizId);
+
     /**
      * 获得跟进记录
      *
@@ -45,4 +64,13 @@ public interface CrmFollowUpRecordService {
      */
     PageResult<CrmFollowUpRecordDO> getFollowUpRecordPage(CrmFollowUpRecordPageReqVO pageReqVO);
 
+    /**
+     * 获取跟进记录
+     *
+     * @param bizType 模块类型
+     * @param bizIds  模块数据编号
+     * @return 跟进列表
+     */
+    List<CrmFollowUpRecordDO> getFollowUpRecordByBiz(Integer bizType, Collection<Long> bizIds);
+
 }

+ 23 - 0
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/followup/CrmFollowUpRecordServiceImpl.java

@@ -17,6 +17,7 @@ import cn.iocoder.yudao.module.crm.service.clue.CrmClueService;
 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.CrmFollowUpCreateReqBO;
 import cn.iocoder.yudao.module.crm.service.followup.bo.CrmUpdateFollowUpReqBO;
 import cn.iocoder.yudao.module.crm.service.permission.CrmPermissionService;
 import jakarta.annotation.Resource;
@@ -24,6 +25,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.validation.annotation.Validated;
 
 import java.time.LocalDateTime;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
 
@@ -96,6 +98,16 @@ public class CrmFollowUpRecordServiceImpl implements CrmFollowUpRecordService {
         return followUpRecord.getId();
     }
 
+    @Override
+    public void createFollowUpRecordBatch(List<CrmFollowUpCreateReqBO> followUpCreateReqBOs) {
+        if (CollUtil.isEmpty(followUpCreateReqBOs)) {
+            return;
+        }
+
+        List<CrmFollowUpRecordDO> followUpRecords = BeanUtils.toBean(followUpCreateReqBOs, CrmFollowUpRecordDO.class);
+        crmFollowUpRecordMapper.insertBatch(followUpRecords);
+    }
+
     @Override
     public void deleteFollowUpRecord(Long id, Long userId) {
         // 校验存在
@@ -113,6 +125,12 @@ public class CrmFollowUpRecordServiceImpl implements CrmFollowUpRecordService {
         crmFollowUpRecordMapper.deleteById(id);
     }
 
+    @Override
+    public void deleteFollowUpRecordByBiz(Integer bizType, Long bizId) {
+        // 删除
+        crmFollowUpRecordMapper.deleteByBiz(bizType, bizId);
+    }
+
     private CrmFollowUpRecordDO validateFollowUpRecordExists(Long id) {
         CrmFollowUpRecordDO followUpRecord = crmFollowUpRecordMapper.selectById(id);
         if (followUpRecord == null) {
@@ -132,4 +150,9 @@ public class CrmFollowUpRecordServiceImpl implements CrmFollowUpRecordService {
         return crmFollowUpRecordMapper.selectPage(pageReqVO);
     }
 
+    @Override
+    public List<CrmFollowUpRecordDO> getFollowUpRecordByBiz(Integer bizType, Collection<Long> bizIds) {
+        return crmFollowUpRecordMapper.selectListByBiz(bizType, bizIds);
+    }
+
 }

+ 78 - 0
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/followup/bo/CrmFollowUpCreateReqBO.java

@@ -0,0 +1,78 @@
+package cn.iocoder.yudao.module.crm.service.followup.bo;
+
+import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessDO;
+import cn.iocoder.yudao.module.crm.dal.dataobject.contact.CrmContactDO;
+import cn.iocoder.yudao.module.crm.enums.DictTypeConstants;
+import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum;
+import jakarta.validation.constraints.NotEmpty;
+import jakarta.validation.constraints.NotNull;
+import lombok.Data;
+
+import java.time.LocalDateTime;
+import java.util.List;
+
+/**
+ * 跟进信息 Create Req BO
+ *
+ * @author HUIHUI
+ */
+@Data
+public class CrmFollowUpCreateReqBO {
+
+    /**
+     * 数据类型
+     *
+     * 枚举 {@link CrmBizTypeEnum}
+     */
+    @NotNull(message = "数据类型不能为空")
+    private Integer bizType;
+    /**
+     * 数据编号
+     *
+     * 关联 {@link CrmBizTypeEnum} 对应模块 DO 的 id 字段
+     */
+    @NotNull(message = "数据编号不能为空")
+    private Long bizId;
+
+    /**
+     * 跟进类型
+     *
+     * 关联 {@link DictTypeConstants#CRM_FOLLOW_UP_TYPE} 字典
+     */
+    @NotNull(message = "跟进类型不能为空")
+    private Integer type;
+    /**
+     * 跟进内容
+     */
+    @NotEmpty(message = "跟进内容不能为空")
+    private String content;
+    /**
+     * 下次联系时间
+     */
+    @NotNull(message = "下次联系时间不能为空")
+    private LocalDateTime nextTime;
+
+    /**
+     * 图片
+     */
+    private List<String> picUrls;
+    /**
+     * 附件
+     */
+    private List<String> fileUrls;
+
+    /**
+     * 关联的商机编号数组
+     *
+     * 关联 {@link CrmBusinessDO#getId()}
+     */
+    private List<Long> businessIds;
+
+    /**
+     * 关联的联系人编号数组
+     *
+     * 关联 {@link CrmContactDO#getId()}
+     */
+    private List<Long> contactIds;
+
+}

+ 2 - 1
yudao-module-crm/yudao-module-crm-biz/src/test/java/cn/iocoder/yudao/module/crm/service/clue/CrmClueServiceImplTest.java

@@ -15,6 +15,7 @@ import java.util.List;
 
 import static cn.iocoder.yudao.framework.common.pojo.PageParam.PAGE_SIZE_NONE;
 import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId;
+import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
 import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals;
 import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException;
 import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId;
@@ -45,7 +46,7 @@ public class CrmClueServiceImplTest extends BaseDbUnitTest {
         CrmClueSaveReqVO reqVO = randomPojo(CrmClueSaveReqVO.class);
 
         // 调用
-        Long clueId = clueService.createClue(reqVO);
+        Long clueId = clueService.createClue(reqVO, getLoginUserId());
         // 断言
         assertNotNull(clueId);
         // 校验记录的属性是否正确