📖 CRM:线索的转化逻辑

This commit is contained in:
YunaiV 2024-02-19 20:41:10 +08:00
parent fe330482b3
commit 38e410cae0
8 changed files with 45 additions and 56 deletions

View File

@ -16,8 +16,8 @@ public interface ErrorCodeConstants {
// ========== 线索管理 1-020-001-000 ========== // ========== 线索管理 1-020-001-000 ==========
ErrorCode CLUE_NOT_EXISTS = new ErrorCode(1_020_001_000, "线索不存在"); ErrorCode CLUE_NOT_EXISTS = new ErrorCode(1_020_001_000, "线索不存在");
ErrorCode CLUE_ANY_CLUE_NOT_EXISTS = new ErrorCode(1_020_001_001, "线索【{}】不存在"); ErrorCode CLUE_NOT_EXISTS_ANY = new ErrorCode(1_020_001_001, "线索【{}】不存在");
ErrorCode CLUE_ANY_CLUE_ALREADY_TRANSLATED = new ErrorCode(1_020_001_002, "线索【{}】已经转化过了,请勿重复转化"); ErrorCode CLUE_TRANSFORM_FAIL_ALREADY = new ErrorCode(1_020_001_002, "线索【{}】已经转化过了,请勿重复转化");
// ========== 商机管理 1-020-002-000 ========== // ========== 商机管理 1-020-002-000 ==========
ErrorCode BUSINESS_NOT_EXISTS = new ErrorCode(1_020_002_000, "商机不存在"); ErrorCode BUSINESS_NOT_EXISTS = new ErrorCode(1_020_002_000, "商机不存在");
@ -25,7 +25,6 @@ public interface ErrorCodeConstants {
// TODO @lilleo商机状态商机类型都单独错误码段 // TODO @lilleo商机状态商机类型都单独错误码段
// ========== 联系人管理 1-020-003-000 ========== // ========== 联系人管理 1-020-003-000 ==========
ErrorCode CONTACT_NOT_EXISTS = new ErrorCode(1_020_003_000, "联系人不存在"); ErrorCode CONTACT_NOT_EXISTS = new ErrorCode(1_020_003_000, "联系人不存在");
ErrorCode CONTACT_BUSINESS_LINK_NOT_EXISTS = new ErrorCode(1_020_003_001, "联系人商机关联不存在"); ErrorCode CONTACT_BUSINESS_LINK_NOT_EXISTS = new ErrorCode(1_020_003_001, "联系人商机关联不存在");

View File

@ -7,6 +7,7 @@ import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
import cn.iocoder.yudao.framework.common.util.number.NumberUtils; import cn.iocoder.yudao.framework.common.util.number.NumberUtils;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.ip.core.utils.AreaUtils;
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import cn.iocoder.yudao.module.crm.controller.admin.clue.vo.*; import cn.iocoder.yudao.module.crm.controller.admin.clue.vo.*;
import cn.iocoder.yudao.module.crm.dal.dataobject.clue.CrmClueDO; import cn.iocoder.yudao.module.crm.dal.dataobject.clue.CrmClueDO;
@ -35,8 +36,7 @@ import java.util.stream.Stream;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.pojo.PageParam.PAGE_SIZE_NONE; import static cn.iocoder.yudao.framework.common.pojo.PageParam.PAGE_SIZE_NONE;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertListByFlatMap; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
@ -60,7 +60,7 @@ public class CrmClueController {
@Operation(summary = "创建线索") @Operation(summary = "创建线索")
@PreAuthorize("@ss.hasPermission('crm:clue:create')") @PreAuthorize("@ss.hasPermission('crm:clue:create')")
public CommonResult<Long> createClue(@Valid @RequestBody CrmClueSaveReqVO createReqVO) { public CommonResult<Long> createClue(@Valid @RequestBody CrmClueSaveReqVO createReqVO) {
return success(clueService.createClue(createReqVO, getLoginUserId())); return success(clueService.createClue(createReqVO));
} }
@PutMapping("/update") @PutMapping("/update")
@ -86,7 +86,14 @@ public class CrmClueController {
@PreAuthorize("@ss.hasPermission('crm:clue:query')") @PreAuthorize("@ss.hasPermission('crm:clue:query')")
public CommonResult<CrmClueRespVO> getClue(@RequestParam("id") Long id) { public CommonResult<CrmClueRespVO> getClue(@RequestParam("id") Long id) {
CrmClueDO clue = clueService.getClue(id); CrmClueDO clue = clueService.getClue(id);
return success(BeanUtils.toBean(clue, CrmClueRespVO.class)); return success(buildClueDetail(clue));
}
public CrmClueRespVO buildClueDetail(CrmClueDO clue) {
if (clue == null) {
return null;
}
return buildClueDetailList(Collections.singletonList(clue)).get(0);
} }
@GetMapping("/page") @GetMapping("/page")
@ -121,6 +128,7 @@ public class CrmClueController {
Map<Long, DeptRespDTO> deptMap = deptApi.getDeptMap(convertSet(userMap.values(), AdminUserRespDTO::getDeptId)); Map<Long, DeptRespDTO> deptMap = deptApi.getDeptMap(convertSet(userMap.values(), AdminUserRespDTO::getDeptId));
// 2. 转换成 VO // 2. 转换成 VO
return BeanUtils.toBean(list, CrmClueRespVO.class, clueVO -> { return BeanUtils.toBean(list, CrmClueRespVO.class, clueVO -> {
clueVO.setAreaName(AreaUtils.format(clueVO.getAreaId()));
// 2.1 设置客户名称 // 2.1 设置客户名称
MapUtils.findAndThen(customerMap, clueVO.getCustomerId(), customer -> clueVO.setCustomerName(customer.getName())); MapUtils.findAndThen(customerMap, clueVO.getCustomerId(), customer -> clueVO.setCustomerName(customer.getName()));
// 2.2 设置创建人负责人名称 // 2.2 设置创建人负责人名称
@ -141,11 +149,12 @@ public class CrmClueController {
return success(true); return success(true);
} }
@PostMapping("/transform") @PutMapping("/transform")
@Operation(summary = "线索转化为客户") @Operation(summary = "线索转化为客户")
@Parameter(name = "ids", description = "线索编号数组", required = true)
@PreAuthorize("@ss.hasPermission('crm:clue:update')") @PreAuthorize("@ss.hasPermission('crm:clue:update')")
public CommonResult<Boolean> translateCustomer(@Valid @RequestBody CrmClueTranslateReqVO reqVO) { public CommonResult<Boolean> transformClue(@RequestParam("ids") List<Long> ids) {
clueService.translateCustomer(reqVO, getLoginUserId()); clueService.transformClue(ids, getLoginUserId());
return success(Boolean.TRUE); return success(Boolean.TRUE);
} }

View File

@ -17,6 +17,9 @@ public class CrmCluePageReqVO extends PageParam {
@Schema(description = "线索名称", example = "线索xxx") @Schema(description = "线索名称", example = "线索xxx")
private String name; private String name;
@Schema(description = "转化状态", example = "2048")
private Boolean transformStatus;
@Schema(description = "电话", example = "18000000000") @Schema(description = "电话", example = "18000000000")
private String telephone; private String telephone;

View File

@ -13,6 +13,7 @@ import com.mzt.logapi.starter.annotation.DiffLogField;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.Email; import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size; import jakarta.validation.constraints.Size;
import lombok.Data; import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat; import org.springframework.format.annotation.DateTimeFormat;
@ -45,6 +46,7 @@ public class CrmClueSaveReqVO {
private LocalDateTime contactNextTime; private LocalDateTime contactNextTime;
@Schema(description = "负责人编号", example = "2048") @Schema(description = "负责人编号", example = "2048")
@NotNull(message = "负责人编号不能为空")
private Long ownerUserId; private Long ownerUserId;
@Schema(description = "手机号", example = "18000000000") @Schema(description = "手机号", example = "18000000000")

View File

@ -1,17 +0,0 @@
package cn.iocoder.yudao.module.crm.controller.admin.clue.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotEmpty;
import lombok.Data;
import java.util.Set;
@Schema(description = "管理后台 - 线索转化为客户 Request VO")
@Data
public class CrmClueTranslateReqVO {
@Schema(description = "线索编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "[1024, 1025]")
@NotEmpty(message = "线索编号不能为空")
private Set<Long> ids;
}

View File

@ -36,6 +36,7 @@ public interface CrmClueMapper extends BaseMapperX<CrmClueDO> {
// 拼接自身的查询条件 // 拼接自身的查询条件
query.selectAll(CrmClueDO.class) query.selectAll(CrmClueDO.class)
.likeIfPresent(CrmClueDO::getName, pageReqVO.getName()) .likeIfPresent(CrmClueDO::getName, pageReqVO.getName())
.eqIfPresent(CrmClueDO::getTransformStatus, pageReqVO.getTransformStatus())
.likeIfPresent(CrmClueDO::getTelephone, pageReqVO.getTelephone()) .likeIfPresent(CrmClueDO::getTelephone, pageReqVO.getTelephone())
.likeIfPresent(CrmClueDO::getMobile, pageReqVO.getMobile()) .likeIfPresent(CrmClueDO::getMobile, pageReqVO.getMobile())
.eqIfPresent(CrmClueDO::getIndustryId, pageReqVO.getIndustryId()) .eqIfPresent(CrmClueDO::getIndustryId, pageReqVO.getIndustryId())

View File

@ -4,7 +4,6 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.crm.controller.admin.clue.vo.CrmCluePageReqVO; 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.CrmClueSaveReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.clue.vo.CrmClueTransferReqVO; import cn.iocoder.yudao.module.crm.controller.admin.clue.vo.CrmClueTransferReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.clue.vo.CrmClueTranslateReqVO;
import cn.iocoder.yudao.module.crm.dal.dataobject.clue.CrmClueDO; import cn.iocoder.yudao.module.crm.dal.dataobject.clue.CrmClueDO;
import cn.iocoder.yudao.module.crm.service.followup.bo.CrmUpdateFollowUpReqBO; import cn.iocoder.yudao.module.crm.service.followup.bo.CrmUpdateFollowUpReqBO;
import jakarta.validation.Valid; import jakarta.validation.Valid;
@ -23,10 +22,9 @@ public interface CrmClueService {
* 创建线索 * 创建线索
* *
* @param createReqVO 创建信息 * @param createReqVO 创建信息
* @param userId 用户编号
* @return 编号 * @return 编号
*/ */
Long createClue(@Valid CrmClueSaveReqVO createReqVO, Long userId); Long createClue(@Valid CrmClueSaveReqVO createReqVO);
/** /**
* 更新线索 * 更新线索
@ -85,10 +83,10 @@ public interface CrmClueService {
/** /**
* 线索转化为客户 * 线索转化为客户
* *
* @param reqVO 线索编号 * @param ids 线索编号数组
* @param userId 用户编号 * @param userId 用户编号
*/ */
void translateCustomer(CrmClueTranslateReqVO reqVO, Long userId); void transformClue(List<Long> ids, Long userId);
/** /**
* 获得分配给我的线索数量 * 获得分配给我的线索数量

View File

@ -10,7 +10,6 @@ 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.CrmCluePageReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.clue.vo.CrmClueSaveReqVO; 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.clue.vo.CrmClueTransferReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.clue.vo.CrmClueTranslateReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerSaveReqVO; 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.convert.clue.CrmClueConvert;
import cn.iocoder.yudao.module.crm.dal.dataobject.clue.CrmClueDO; import cn.iocoder.yudao.module.crm.dal.dataobject.clue.CrmClueDO;
@ -36,14 +35,16 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.*; 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.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*; 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.ErrorCodeConstants.*;
import static cn.iocoder.yudao.module.crm.enums.LogRecordConstants.*; import static cn.iocoder.yudao.module.crm.enums.LogRecordConstants.*;
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.USER_NOT_EXISTS; import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.USER_NOT_EXISTS;
import static java.util.Collections.singletonList;
/** /**
* 线索 Service 实现类 * 线索 Service 实现类
@ -71,17 +72,13 @@ public class CrmClueServiceImpl implements CrmClueService {
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@LogRecord(type = CRM_LEADS_TYPE, subType = CRM_LEADS_CREATE_SUB_TYPE, bizNo = "{{#clue.id}}", @LogRecord(type = CRM_LEADS_TYPE, subType = CRM_LEADS_CREATE_SUB_TYPE, bizNo = "{{#clue.id}}",
success = CRM_LEADS_CREATE_SUCCESS) success = CRM_LEADS_CREATE_SUCCESS)
public Long createClue(CrmClueSaveReqVO createReqVO, Long userId) { public Long createClue(CrmClueSaveReqVO createReqVO) {
// 1.1 校验关联数据 // 1.1 校验关联数据
validateRelationDataExists(createReqVO); validateRelationDataExists(createReqVO);
// 1.2 校验负责人是否存在 // 1.2 校验负责人是否存在
if (createReqVO.getOwnerUserId() != null) { adminUserApi.validateUser(createReqVO.getOwnerUserId());
adminUserApi.validateUserList(singletonList(createReqVO.getOwnerUserId()));
} else {
createReqVO.setOwnerUserId(userId); // 如果没有设置负责人那么默认操作人为负责人
}
// 2. 插入 // 2. 插入线索
CrmClueDO clue = BeanUtils.toBean(createReqVO, CrmClueDO.class) CrmClueDO clue = BeanUtils.toBean(createReqVO, CrmClueDO.class)
.setContactLastTime(LocalDateTime.now()); .setContactLastTime(LocalDateTime.now());
clueMapper.insert(clue); clueMapper.insert(clue);
@ -103,12 +100,12 @@ public class CrmClueServiceImpl implements CrmClueService {
@CrmPermission(bizType = CrmBizTypeEnum.CRM_LEADS, bizId = "#updateReq.id", level = CrmPermissionLevelEnum.OWNER) @CrmPermission(bizType = CrmBizTypeEnum.CRM_LEADS, bizId = "#updateReq.id", level = CrmPermissionLevelEnum.OWNER)
public void updateClue(CrmClueSaveReqVO updateReq) { public void updateClue(CrmClueSaveReqVO updateReq) {
Assert.notNull(updateReq.getId(), "线索编号不能为空"); Assert.notNull(updateReq.getId(), "线索编号不能为空");
// 1. 校验线索是否存在 // 1.1 校验线索是否存在
CrmClueDO oldClue = validateClueExists(updateReq.getId()); CrmClueDO oldClue = validateClueExists(updateReq.getId());
// 2. 校验关联数据 // 1.2 校验关联数据
validateRelationDataExists(updateReq); validateRelationDataExists(updateReq);
// 3. 更新 // 2. 更新线索
CrmClueDO updateObj = BeanUtils.toBean(updateReq, CrmClueDO.class); CrmClueDO updateObj = BeanUtils.toBean(updateReq, CrmClueDO.class);
clueMapper.updateById(updateObj); clueMapper.updateById(updateObj);
@ -130,7 +127,6 @@ public class CrmClueServiceImpl implements CrmClueService {
// 3. 记录操作日志上下文 // 3. 记录操作日志上下文
LogRecordContext.putVariable(DiffParseFunction.OLD_OBJECT, BeanUtils.toBean(oldClue, CrmUpdateFollowUpReqBO.class)); LogRecordContext.putVariable(DiffParseFunction.OLD_OBJECT, BeanUtils.toBean(oldClue, CrmUpdateFollowUpReqBO.class));
LogRecordContext.putVariable("clueName", oldClue.getName()); LogRecordContext.putVariable("clueName", oldClue.getName());
} }
@Override @Override
@ -155,12 +151,11 @@ public class CrmClueServiceImpl implements CrmClueService {
LogRecordContext.putVariable("clueName", clue.getName()); LogRecordContext.putVariable("clueName", clue.getName());
} }
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@LogRecord(type = CRM_LEADS_TYPE, subType = CRM_LEADS_TRANSFER_SUB_TYPE, bizNo = "{{#reqVO.id}}", @LogRecord(type = CRM_LEADS_TYPE, subType = CRM_LEADS_TRANSFER_SUB_TYPE, bizNo = "{{#reqVO.id}}",
success = CRM_LEADS_TRANSFER_SUCCESS) success = CRM_LEADS_TRANSFER_SUCCESS)
@CrmPermission(bizType = CrmBizTypeEnum.CRM_LEADS, bizId = "#id", level = CrmPermissionLevelEnum.OWNER) @CrmPermission(bizType = CrmBizTypeEnum.CRM_LEADS, bizId = "#reqVO.id", level = CrmPermissionLevelEnum.OWNER)
public void transferClue(CrmClueTransferReqVO reqVO, Long userId) { public void transferClue(CrmClueTransferReqVO reqVO, Long userId) {
// 1 校验线索是否存在 // 1 校验线索是否存在
CrmClueDO clue = validateClueExists(reqVO.getId()); CrmClueDO clue = validateClueExists(reqVO.getId());
@ -176,20 +171,19 @@ public class CrmClueServiceImpl implements CrmClueService {
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@CrmPermission(bizType = CrmBizTypeEnum.CRM_LEADS, bizId = "#id", level = CrmPermissionLevelEnum.OWNER) @CrmPermission(bizType = CrmBizTypeEnum.CRM_LEADS, bizId = "#ids", level = CrmPermissionLevelEnum.OWNER)
public void translateCustomer(CrmClueTranslateReqVO reqVO, Long userId) { public void transformClue(List<Long> ids, Long userId) {
// 1.1 校验线索都存在 // 1.1 校验线索都存在
Set<Long> clueIds = reqVO.getIds(); List<CrmClueDO> clues = getClueList(ids, userId);
List<CrmClueDO> clues = getClueList(clueIds, userId); if (CollUtil.isEmpty(clues) || ObjectUtil.notEqual(clues.size(), ids.size())) {
if (CollUtil.isEmpty(clues) || ObjectUtil.notEqual(clues.size(), clueIds.size())) { ids.removeAll(convertSet(clues, CrmClueDO::getId));
clueIds.removeAll(convertSet(clues, CrmClueDO::getId)); throw exception(CLUE_NOT_EXISTS_ANY, ids);
throw exception(CLUE_ANY_CLUE_NOT_EXISTS, clueIds);
} }
// 1.2 存在已经转化的直接提示哈避免操作的用户以为都转化成功了 // 1.2 存在已经转化的直接提示哈避免操作的用户以为都转化成功了
List<CrmClueDO> translatedClues = filterList(clues, List<CrmClueDO> translatedClues = filterList(clues,
clue -> ObjectUtil.equal(Boolean.TRUE, clue.getTransformStatus())); clue -> ObjectUtil.equal(Boolean.TRUE, clue.getTransformStatus()));
if (CollUtil.isNotEmpty(translatedClues)) { if (CollUtil.isNotEmpty(translatedClues)) {
throw exception(CLUE_ANY_CLUE_ALREADY_TRANSLATED, convertSet(translatedClues, CrmClueDO::getId)); throw exception(CLUE_TRANSFORM_FAIL_ALREADY, convertSet(translatedClues, CrmClueDO::getId));
} }
// 2.1 遍历线索(未转化的线索)创建对应的客户 // 2.1 遍历线索(未转化的线索)创建对应的客户