From 4237cfb4a9e71687847a78975eebee2faab264b5 Mon Sep 17 00:00:00 2001 From: min Date: Mon, 8 Jan 2024 01:29:15 +0800 Subject: [PATCH] =?UTF-8?q?CRM=EF=BC=9A=E3=80=90=E7=BA=BF=E7=B4=A2?= =?UTF-8?q?=E3=80=91=E7=BA=BF=E7=B4=A2=E8=BD=AC=E5=8C=96=E4=B8=BA=E5=AE=A2?= =?UTF-8?q?=E6=88=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/clue/CrmClueController.java | 8 ++++++ .../admin/clue/vo/CrmClueTransformReqVO.java | 19 +++++++++++++ .../convert/customer/CrmCustomerConvert.java | 3 +++ .../crm/service/clue/CrmClueService.java | 12 ++++++--- .../crm/service/clue/CrmClueServiceImpl.java | 27 ++++++++++++++----- 5 files changed, 59 insertions(+), 10 deletions(-) create mode 100644 yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/clue/vo/CrmClueTransformReqVO.java diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/clue/CrmClueController.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/clue/CrmClueController.java index 7227b3d12..6acd79057 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/clue/CrmClueController.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/clue/CrmClueController.java @@ -96,4 +96,12 @@ public class CrmClueController { return success(true); } + @PostMapping("/transform") + @Operation(summary = "线索转化为客户") + @PreAuthorize("@ss.hasPermission('crm:clue:update')") + public CommonResult translate(@Valid @RequestBody CrmClueTransformReqVO reqVO) { + clueService.translate(reqVO, getLoginUserId()); + return success(Boolean.TRUE); + } + } diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/clue/vo/CrmClueTransformReqVO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/clue/vo/CrmClueTransformReqVO.java new file mode 100644 index 000000000..2da96d051 --- /dev/null +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/clue/vo/CrmClueTransformReqVO.java @@ -0,0 +1,19 @@ +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; + +/** + * @author min + */ +@Schema(description = "管理后台 - 线索转化为客户 Request VO") +@Data +public class CrmClueTransformReqVO { + + @Schema(description = "线索编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "[1024, 1025]") + @NotEmpty(message = "线索编号不能为空") Set ids; + +} diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/convert/customer/CrmCustomerConvert.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/convert/customer/CrmCustomerConvert.java index 09636e4e7..211faf8f1 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/convert/customer/CrmCustomerConvert.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/convert/customer/CrmCustomerConvert.java @@ -7,6 +7,7 @@ import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerSaveR import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerTransferReqVO; import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.poolconfig.CrmCustomerPoolConfigRespVO; import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.poolconfig.CrmCustomerPoolConfigSaveReqVO; +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.customer.CrmCustomerPoolConfigDO; import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionTransferReqBO; @@ -77,4 +78,6 @@ public interface CrmCustomerConvert { CrmCustomerPoolConfigDO convert(CrmCustomerPoolConfigSaveReqVO updateReqVO); + @Mapping(ignore = true, target = "id") + CrmCustomerSaveReqVO convert(CrmClueDO bean); } diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/clue/CrmClueService.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/clue/CrmClueService.java index f5dd48bfa..aa87d8398 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/clue/CrmClueService.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/clue/CrmClueService.java @@ -1,10 +1,7 @@ package cn.iocoder.yudao.module.crm.service.clue; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.crm.controller.admin.clue.vo.CrmClueCreateReqVO; -import cn.iocoder.yudao.module.crm.controller.admin.clue.vo.CrmCluePageReqVO; -import cn.iocoder.yudao.module.crm.controller.admin.clue.vo.CrmClueTransferReqVO; -import cn.iocoder.yudao.module.crm.controller.admin.clue.vo.CrmClueUpdateReqVO; +import cn.iocoder.yudao.module.crm.controller.admin.clue.vo.*; import cn.iocoder.yudao.module.crm.dal.dataobject.clue.CrmClueDO; import jakarta.validation.Valid; @@ -73,4 +70,11 @@ public interface CrmClueService { */ void transferClue(CrmClueTransferReqVO reqVO, Long userId); + /** + * 线索转化为客户 + * + * @param reqVO 线索编号 + * @param userId 用户编号 + */ + void translate(CrmClueTransformReqVO reqVO, Long userId); } diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/clue/CrmClueServiceImpl.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/clue/CrmClueServiceImpl.java index c3af9e414..141a4d6a2 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/clue/CrmClueServiceImpl.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/clue/CrmClueServiceImpl.java @@ -3,11 +3,9 @@ package cn.iocoder.yudao.module.crm.service.clue; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.ListUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.crm.controller.admin.clue.vo.CrmClueCreateReqVO; -import cn.iocoder.yudao.module.crm.controller.admin.clue.vo.CrmCluePageReqVO; -import cn.iocoder.yudao.module.crm.controller.admin.clue.vo.CrmClueTransferReqVO; -import cn.iocoder.yudao.module.crm.controller.admin.clue.vo.CrmClueUpdateReqVO; +import cn.iocoder.yudao.module.crm.controller.admin.clue.vo.*; import cn.iocoder.yudao.module.crm.convert.clue.CrmClueConvert; +import cn.iocoder.yudao.module.crm.convert.customer.CrmCustomerConvert; import cn.iocoder.yudao.module.crm.dal.dataobject.clue.CrmClueDO; import cn.iocoder.yudao.module.crm.dal.mysql.clue.CrmClueMapper; import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum; @@ -17,6 +15,7 @@ import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerService; import cn.iocoder.yudao.module.crm.service.permission.CrmPermissionService; import jakarta.annotation.Resource; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; import java.util.Collection; @@ -108,12 +107,28 @@ public class CrmClueServiceImpl implements CrmClueService { validateClueExists(reqVO.getId()); // 2.1 数据权限转移 - crmPermissionService.transferPermission( - CrmClueConvert.INSTANCE.convert(reqVO, userId).setBizType(CrmBizTypeEnum.CRM_LEADS.getType())); + crmPermissionService.transferPermission(CrmClueConvert.INSTANCE.convert(reqVO, userId).setBizType(CrmBizTypeEnum.CRM_LEADS.getType())); // 2.2 设置新的负责人 clueMapper.updateOwnerUserIdById(reqVO.getId(), reqVO.getNewOwnerUserId()); // 3. TODO 记录转移日志 } + @Override + @Transactional(rollbackFor = Exception.class) + public void translate(CrmClueTransformReqVO reqVO, Long userId) { + List clues = getClueList(reqVO.getIds(), userId); + // 不存在抛出异常 + if (CollUtil.isEmpty(clues)) { + throw exception(CLUE_NOT_EXISTS); + } + // 遍历线索,创建对应的客户 + clues.forEach(clueDO -> { + // 创建客户 + customerService.createCustomer(CrmCustomerConvert.INSTANCE.convert(clueDO), userId); + // 更新线索状态 + clueDO.setTransformStatus(Boolean.TRUE); + clueMapper.updateById(clueDO); + }); + } }