Commit 4237cfb4a9e71687847a78975eebee2faab264b5
1 parent
63db275a
CRM:【线索】线索转化为客户
Showing
5 changed files
with
59 additions
and
10 deletions
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 { | @@ -96,4 +96,12 @@ public class CrmClueController { | ||
| 96 | return success(true); | 96 | return success(true); |
| 97 | } | 97 | } |
| 98 | 98 | ||
| 99 | + @PostMapping("/transform") | ||
| 100 | + @Operation(summary = "线索转化为客户") | ||
| 101 | + @PreAuthorize("@ss.hasPermission('crm:clue:update')") | ||
| 102 | + public CommonResult<Boolean> translate(@Valid @RequestBody CrmClueTransformReqVO reqVO) { | ||
| 103 | + clueService.translate(reqVO, getLoginUserId()); | ||
| 104 | + return success(Boolean.TRUE); | ||
| 105 | + } | ||
| 106 | + | ||
| 99 | } | 107 | } |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/clue/vo/CrmClueTransformReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.crm.controller.admin.clue.vo; | ||
| 2 | + | ||
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | ||
| 4 | +import jakarta.validation.constraints.NotEmpty; | ||
| 5 | +import lombok.Data; | ||
| 6 | + | ||
| 7 | +import java.util.Set; | ||
| 8 | + | ||
| 9 | +/** | ||
| 10 | + * @author min | ||
| 11 | + */ | ||
| 12 | +@Schema(description = "管理后台 - 线索转化为客户 Request VO") | ||
| 13 | +@Data | ||
| 14 | +public class CrmClueTransformReqVO { | ||
| 15 | + | ||
| 16 | + @Schema(description = "线索编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "[1024, 1025]") | ||
| 17 | + @NotEmpty(message = "线索编号不能为空") Set<Long> ids; | ||
| 18 | + | ||
| 19 | +} |
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 | @@ -7,6 +7,7 @@ import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerSaveR | ||
| 7 | import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerTransferReqVO; | 7 | import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerTransferReqVO; |
| 8 | import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.poolconfig.CrmCustomerPoolConfigRespVO; | 8 | import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.poolconfig.CrmCustomerPoolConfigRespVO; |
| 9 | import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.poolconfig.CrmCustomerPoolConfigSaveReqVO; | 9 | import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.poolconfig.CrmCustomerPoolConfigSaveReqVO; |
| 10 | +import cn.iocoder.yudao.module.crm.dal.dataobject.clue.CrmClueDO; | ||
| 10 | import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO; | 11 | import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO; |
| 11 | import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerPoolConfigDO; | 12 | import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerPoolConfigDO; |
| 12 | import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionTransferReqBO; | 13 | import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionTransferReqBO; |
| @@ -77,4 +78,6 @@ public interface CrmCustomerConvert { | @@ -77,4 +78,6 @@ public interface CrmCustomerConvert { | ||
| 77 | 78 | ||
| 78 | CrmCustomerPoolConfigDO convert(CrmCustomerPoolConfigSaveReqVO updateReqVO); | 79 | CrmCustomerPoolConfigDO convert(CrmCustomerPoolConfigSaveReqVO updateReqVO); |
| 79 | 80 | ||
| 81 | + @Mapping(ignore = true, target = "id") | ||
| 82 | + CrmCustomerSaveReqVO convert(CrmClueDO bean); | ||
| 80 | } | 83 | } |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/clue/CrmClueService.java
| 1 | package cn.iocoder.yudao.module.crm.service.clue; | 1 | package cn.iocoder.yudao.module.crm.service.clue; |
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | -import cn.iocoder.yudao.module.crm.controller.admin.clue.vo.CrmClueCreateReqVO; | ||
| 5 | -import cn.iocoder.yudao.module.crm.controller.admin.clue.vo.CrmCluePageReqVO; | ||
| 6 | -import cn.iocoder.yudao.module.crm.controller.admin.clue.vo.CrmClueTransferReqVO; | ||
| 7 | -import cn.iocoder.yudao.module.crm.controller.admin.clue.vo.CrmClueUpdateReqVO; | 4 | +import cn.iocoder.yudao.module.crm.controller.admin.clue.vo.*; |
| 8 | import cn.iocoder.yudao.module.crm.dal.dataobject.clue.CrmClueDO; | 5 | import cn.iocoder.yudao.module.crm.dal.dataobject.clue.CrmClueDO; |
| 9 | import jakarta.validation.Valid; | 6 | import jakarta.validation.Valid; |
| 10 | 7 | ||
| @@ -73,4 +70,11 @@ public interface CrmClueService { | @@ -73,4 +70,11 @@ public interface CrmClueService { | ||
| 73 | */ | 70 | */ |
| 74 | void transferClue(CrmClueTransferReqVO reqVO, Long userId); | 71 | void transferClue(CrmClueTransferReqVO reqVO, Long userId); |
| 75 | 72 | ||
| 73 | + /** | ||
| 74 | + * 线索转化为客户 | ||
| 75 | + * | ||
| 76 | + * @param reqVO 线索编号 | ||
| 77 | + * @param userId 用户编号 | ||
| 78 | + */ | ||
| 79 | + void translate(CrmClueTransformReqVO reqVO, Long userId); | ||
| 76 | } | 80 | } |
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; | @@ -3,11 +3,9 @@ package cn.iocoder.yudao.module.crm.service.clue; | ||
| 3 | import cn.hutool.core.collection.CollUtil; | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | import cn.hutool.core.collection.ListUtil; | 4 | import cn.hutool.core.collection.ListUtil; |
| 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 6 | -import cn.iocoder.yudao.module.crm.controller.admin.clue.vo.CrmClueCreateReqVO; | ||
| 7 | -import cn.iocoder.yudao.module.crm.controller.admin.clue.vo.CrmCluePageReqVO; | ||
| 8 | -import cn.iocoder.yudao.module.crm.controller.admin.clue.vo.CrmClueTransferReqVO; | ||
| 9 | -import cn.iocoder.yudao.module.crm.controller.admin.clue.vo.CrmClueUpdateReqVO; | 6 | +import cn.iocoder.yudao.module.crm.controller.admin.clue.vo.*; |
| 10 | import cn.iocoder.yudao.module.crm.convert.clue.CrmClueConvert; | 7 | import cn.iocoder.yudao.module.crm.convert.clue.CrmClueConvert; |
| 8 | +import cn.iocoder.yudao.module.crm.convert.customer.CrmCustomerConvert; | ||
| 11 | import cn.iocoder.yudao.module.crm.dal.dataobject.clue.CrmClueDO; | 9 | import cn.iocoder.yudao.module.crm.dal.dataobject.clue.CrmClueDO; |
| 12 | import cn.iocoder.yudao.module.crm.dal.mysql.clue.CrmClueMapper; | 10 | import cn.iocoder.yudao.module.crm.dal.mysql.clue.CrmClueMapper; |
| 13 | import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum; | 11 | import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum; |
| @@ -17,6 +15,7 @@ import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerService; | @@ -17,6 +15,7 @@ import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerService; | ||
| 17 | import cn.iocoder.yudao.module.crm.service.permission.CrmPermissionService; | 15 | import cn.iocoder.yudao.module.crm.service.permission.CrmPermissionService; |
| 18 | import jakarta.annotation.Resource; | 16 | import jakarta.annotation.Resource; |
| 19 | import org.springframework.stereotype.Service; | 17 | import org.springframework.stereotype.Service; |
| 18 | +import org.springframework.transaction.annotation.Transactional; | ||
| 20 | import org.springframework.validation.annotation.Validated; | 19 | import org.springframework.validation.annotation.Validated; |
| 21 | 20 | ||
| 22 | import java.util.Collection; | 21 | import java.util.Collection; |
| @@ -108,12 +107,28 @@ public class CrmClueServiceImpl implements CrmClueService { | @@ -108,12 +107,28 @@ public class CrmClueServiceImpl implements CrmClueService { | ||
| 108 | validateClueExists(reqVO.getId()); | 107 | validateClueExists(reqVO.getId()); |
| 109 | 108 | ||
| 110 | // 2.1 数据权限转移 | 109 | // 2.1 数据权限转移 |
| 111 | - crmPermissionService.transferPermission( | ||
| 112 | - CrmClueConvert.INSTANCE.convert(reqVO, userId).setBizType(CrmBizTypeEnum.CRM_LEADS.getType())); | 110 | + crmPermissionService.transferPermission(CrmClueConvert.INSTANCE.convert(reqVO, userId).setBizType(CrmBizTypeEnum.CRM_LEADS.getType())); |
| 113 | // 2.2 设置新的负责人 | 111 | // 2.2 设置新的负责人 |
| 114 | clueMapper.updateOwnerUserIdById(reqVO.getId(), reqVO.getNewOwnerUserId()); | 112 | clueMapper.updateOwnerUserIdById(reqVO.getId(), reqVO.getNewOwnerUserId()); |
| 115 | 113 | ||
| 116 | // 3. TODO 记录转移日志 | 114 | // 3. TODO 记录转移日志 |
| 117 | } | 115 | } |
| 118 | 116 | ||
| 117 | + @Override | ||
| 118 | + @Transactional(rollbackFor = Exception.class) | ||
| 119 | + public void translate(CrmClueTransformReqVO reqVO, Long userId) { | ||
| 120 | + List<CrmClueDO> clues = getClueList(reqVO.getIds(), userId); | ||
| 121 | + // 不存在抛出异常 | ||
| 122 | + if (CollUtil.isEmpty(clues)) { | ||
| 123 | + throw exception(CLUE_NOT_EXISTS); | ||
| 124 | + } | ||
| 125 | + // 遍历线索,创建对应的客户 | ||
| 126 | + clues.forEach(clueDO -> { | ||
| 127 | + // 创建客户 | ||
| 128 | + customerService.createCustomer(CrmCustomerConvert.INSTANCE.convert(clueDO), userId); | ||
| 129 | + // 更新线索状态 | ||
| 130 | + clueDO.setTransformStatus(Boolean.TRUE); | ||
| 131 | + clueMapper.updateById(clueDO); | ||
| 132 | + }); | ||
| 133 | + } | ||
| 119 | } | 134 | } |