From 4237cfb4a9e71687847a78975eebee2faab264b5 Mon Sep 17 00:00:00 2001 From: min Date: Mon, 8 Jan 2024 01:29:15 +0800 Subject: [PATCH 1/3] =?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); + }); + } } From 4d68e5e747124913b72fffc9bcc445d65e210a9b Mon Sep 17 00:00:00 2001 From: min Date: Tue, 9 Jan 2024 00:19:38 +0800 Subject: [PATCH 2/3] =?UTF-8?q?CRM=EF=BC=9A=E3=80=90=E7=BA=BF=E7=B4=A2?= =?UTF-8?q?=E3=80=91=E5=88=9B=E5=BB=BA=E7=BA=BF=E7=B4=A2=E6=97=B6=E5=AE=A2?= =?UTF-8?q?=E6=88=B7=E6=94=B9=E4=B8=BA=E9=9D=9E=E5=BF=85=E5=A1=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/admin/clue/vo/CrmClueBaseVO.java | 7 ++++--- .../crm/service/clue/CrmClueServiceImpl.java | 14 ++++++++++---- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/clue/vo/CrmClueBaseVO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/clue/vo/CrmClueBaseVO.java index b7ff0ef3e..1531bb210 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/clue/vo/CrmClueBaseVO.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/clue/vo/CrmClueBaseVO.java @@ -3,11 +3,10 @@ package cn.iocoder.yudao.module.crm.controller.admin.clue.vo; import cn.iocoder.yudao.framework.common.validation.Mobile; import cn.iocoder.yudao.framework.common.validation.Telephone; import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotEmpty; import lombok.Data; import org.springframework.format.annotation.DateTimeFormat; -import jakarta.validation.constraints.NotEmpty; -import jakarta.validation.constraints.NotNull; import java.time.LocalDateTime; import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; @@ -24,7 +23,6 @@ public class CrmClueBaseVO { private String name; @Schema(description = "客户 id", requiredMode = Schema.RequiredMode.REQUIRED, example = "520") - @NotNull(message = "客户不能为空") private Long customerId; @Schema(description = "下次联系时间", example = "2023-10-18 01:00:00") @@ -46,6 +44,9 @@ public class CrmClueBaseVO { @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) private LocalDateTime contactLastTime; + @Schema(description = "负责人编号") + private Long ownerUserId; + @Schema(description = "备注", example = "随便") private String remark; 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 141a4d6a2..fdc2168e2 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 @@ -20,6 +20,7 @@ import org.springframework.validation.annotation.Validated; import java.util.Collection; import java.util.List; +import java.util.Objects; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.CLUE_NOT_EXISTS; @@ -43,11 +44,14 @@ public class CrmClueServiceImpl implements CrmClueService { @Override public Long createClue(CrmClueCreateReqVO createReqVO) { - // 校验客户是否存在 - customerService.validateCustomer(createReqVO.getCustomerId()); + // 如果传入客户,校验客户是否存在 + if (Objects.nonNull(createReqVO.getCustomerId())) { + customerService.validateCustomer(createReqVO.getCustomerId()); + } // 插入 CrmClueDO clue = CrmClueConvert.INSTANCE.convert(createReqVO); clueMapper.insert(clue); + System.out.println(1); // 返回 return clue.getId(); } @@ -57,8 +61,10 @@ public class CrmClueServiceImpl implements CrmClueService { public void updateClue(CrmClueUpdateReqVO updateReqVO) { // 校验存在 validateClueExists(updateReqVO.getId()); - // 校验客户是否存在 - customerService.validateCustomer(updateReqVO.getCustomerId()); + // 如果传入客户,校验客户是否存在 + if (Objects.nonNull(updateReqVO.getCustomerId())) { + customerService.validateCustomer(updateReqVO.getCustomerId()); + } // 更新 CrmClueDO updateObj = CrmClueConvert.INSTANCE.convert(updateReqVO); From 81f838c5d251e69fa6cc38e51a92040674d6c73d Mon Sep 17 00:00:00 2001 From: min Date: Tue, 9 Jan 2024 01:28:21 +0800 Subject: [PATCH 3/3] =?UTF-8?q?CRM=EF=BC=9A=E3=80=90=E7=BA=BF=E7=B4=A2?= =?UTF-8?q?=E3=80=91=E5=88=9B=E5=BB=BA=E3=80=81=E6=9B=B4=E6=96=B0=E7=BA=BF?= =?UTF-8?q?=E7=B4=A2=E6=97=B6=E6=B7=BB=E5=8A=A0=E6=A0=A1=E9=AA=8C=EF=BC=8C?= =?UTF-8?q?=E6=94=B9=E7=94=A8=E7=9B=B8=E5=90=8Cvo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/clue/CrmClueController.java | 5 +- .../admin/clue/vo/CrmClueCreateReqVO.java | 14 ----- .../admin/clue/vo/CrmClueSaveReqVO.java | 58 +++++++++++++++++++ .../admin/clue/vo/CrmClueUpdateReqVO.java | 20 ------- .../crm/convert/clue/CrmClueConvert.java | 5 +- .../crm/service/clue/CrmClueService.java | 5 +- .../crm/service/clue/CrmClueServiceImpl.java | 41 +++++++++---- .../service/clue/CrmClueServiceImplTest.java | 9 ++- 8 files changed, 100 insertions(+), 57 deletions(-) delete mode 100644 yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/clue/vo/CrmClueCreateReqVO.java create mode 100644 yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/clue/vo/CrmClueSaveReqVO.java delete mode 100644 yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/clue/vo/CrmClueUpdateReqVO.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 6acd79057..25f4910bf 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 @@ -5,6 +5,7 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; 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.contact.vo.CrmContactSaveReqVO; 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.service.clue.CrmClueService; @@ -38,14 +39,14 @@ public class CrmClueController { @PostMapping("/create") @Operation(summary = "创建线索") @PreAuthorize("@ss.hasPermission('crm:clue:create')") - public CommonResult createClue(@Valid @RequestBody CrmClueCreateReqVO createReqVO) { + public CommonResult createClue(@Valid @RequestBody CrmClueSaveReqVO createReqVO) { return success(clueService.createClue(createReqVO)); } @PutMapping("/update") @Operation(summary = "更新线索") @PreAuthorize("@ss.hasPermission('crm:clue:update')") - public CommonResult updateClue(@Valid @RequestBody CrmClueUpdateReqVO updateReqVO) { + public CommonResult updateClue(@Valid @RequestBody CrmClueSaveReqVO updateReqVO) { clueService.updateClue(updateReqVO); return success(true); } diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/clue/vo/CrmClueCreateReqVO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/clue/vo/CrmClueCreateReqVO.java deleted file mode 100644 index a23837499..000000000 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/clue/vo/CrmClueCreateReqVO.java +++ /dev/null @@ -1,14 +0,0 @@ -package cn.iocoder.yudao.module.crm.controller.admin.clue.vo; - -import lombok.*; -import java.util.*; -import io.swagger.v3.oas.annotations.media.Schema; -import jakarta.validation.constraints.*; - -@Schema(description = "管理后台 - 线索创建 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class CrmClueCreateReqVO extends CrmClueBaseVO { - -} diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/clue/vo/CrmClueSaveReqVO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/clue/vo/CrmClueSaveReqVO.java new file mode 100644 index 000000000..8106fec2e --- /dev/null +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/clue/vo/CrmClueSaveReqVO.java @@ -0,0 +1,58 @@ +package cn.iocoder.yudao.module.crm.controller.admin.clue.vo; + +import cn.iocoder.yudao.framework.common.validation.Mobile; +import cn.iocoder.yudao.framework.common.validation.Telephone; +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotEmpty; +import jakarta.validation.constraints.NotNull; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; +import org.springframework.format.annotation.DateTimeFormat; + +import java.time.LocalDateTime; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +/** + * @author minhx + */ +@Schema(description = "管理后台 - CRM 线索 创建/更新 Request VO") +@Data +public class CrmClueSaveReqVO { + + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10969") + private Long id; + + @Schema(description = "线索名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "线索xxx") + @NotEmpty(message = "线索名称不能为空") + private String name; + + @Schema(description = "客户 id", requiredMode = Schema.RequiredMode.REQUIRED, example = "520") + private Long customerId; + + @Schema(description = "下次联系时间", example = "2023-10-18 01:00:00") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private LocalDateTime contactNextTime; + + @Schema(description = "电话", example = "18000000000") + @Telephone + private String telephone; + + @Schema(description = "手机号", example = "18000000000") + @Mobile + private String mobile; + + @Schema(description = "地址", example = "北京市海淀区") + private String address; + + @Schema(description = "最后跟进时间") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private LocalDateTime contactLastTime; + + @Schema(description = "负责人编号") + private Long ownerUserId; + + @Schema(description = "备注", example = "随便") + private String remark; +} diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/clue/vo/CrmClueUpdateReqVO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/clue/vo/CrmClueUpdateReqVO.java deleted file mode 100644 index 996c38130..000000000 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/clue/vo/CrmClueUpdateReqVO.java +++ /dev/null @@ -1,20 +0,0 @@ -package cn.iocoder.yudao.module.crm.controller.admin.clue.vo; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; - -import jakarta.validation.constraints.NotNull; - -@Schema(description = "管理后台 - 线索更新 Request VO") -@Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class CrmClueUpdateReqVO extends CrmClueBaseVO { - - @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10969") - @NotNull(message = "编号不能为空") - private Long id; - -} diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/convert/clue/CrmClueConvert.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/convert/clue/CrmClueConvert.java index 2649065a1..561b658e3 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/convert/clue/CrmClueConvert.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/convert/clue/CrmClueConvert.java @@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.crm.convert.clue; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.crm.controller.admin.clue.vo.*; +import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.CrmContactSaveReqVO; import cn.iocoder.yudao.module.crm.dal.dataobject.clue.CrmClueDO; import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionTransferReqBO; import org.mapstruct.Mapper; @@ -20,9 +21,7 @@ public interface CrmClueConvert { CrmClueConvert INSTANCE = Mappers.getMapper(CrmClueConvert.class); - CrmClueDO convert(CrmClueCreateReqVO bean); - - CrmClueDO convert(CrmClueUpdateReqVO bean); + CrmClueDO convert(CrmClueSaveReqVO bean); CrmClueRespVO 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 aa87d8398..08fd34032 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 @@ -2,6 +2,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.*; +import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.CrmContactSaveReqVO; import cn.iocoder.yudao.module.crm.dal.dataobject.clue.CrmClueDO; import jakarta.validation.Valid; @@ -21,14 +22,14 @@ public interface CrmClueService { * @param createReqVO 创建信息 * @return 编号 */ - Long createClue(@Valid CrmClueCreateReqVO createReqVO); + Long createClue(@Valid CrmClueSaveReqVO createReqVO); /** * 更新线索 * * @param updateReqVO 更新信息 */ - void updateClue(@Valid CrmClueUpdateReqVO updateReqVO); + void updateClue(@Valid CrmClueSaveReqVO updateReqVO); /** * 删除线索 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 fdc2168e2..13c238d9c 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 @@ -4,6 +4,7 @@ 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.*; +import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.CrmContactSaveReqVO; 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; @@ -13,6 +14,7 @@ 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.permission.CrmPermissionService; +import cn.iocoder.yudao.module.system.api.user.AdminUserApi; import jakarta.annotation.Resource; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -24,6 +26,8 @@ import java.util.Objects; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.CLUE_NOT_EXISTS; +import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.CUSTOMER_NOT_EXISTS; +import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.USER_NOT_EXISTS; /** * 线索 Service 实现类 @@ -39,15 +43,18 @@ public class CrmClueServiceImpl implements CrmClueService { @Resource private CrmCustomerService customerService; + @Resource private CrmPermissionService crmPermissionService; + @Resource + private AdminUserApi adminUserApi; + @Override - public Long createClue(CrmClueCreateReqVO createReqVO) { - // 如果传入客户,校验客户是否存在 - if (Objects.nonNull(createReqVO.getCustomerId())) { - customerService.validateCustomer(createReqVO.getCustomerId()); - } + public Long createClue(CrmClueSaveReqVO createReqVO) { + // 校验关联数据 + validateRelationDataExists(createReqVO); + // 插入 CrmClueDO clue = CrmClueConvert.INSTANCE.convert(createReqVO); clueMapper.insert(clue); @@ -58,13 +65,11 @@ public class CrmClueServiceImpl implements CrmClueService { @Override @CrmPermission(bizType = CrmBizTypeEnum.CRM_LEADS, bizId = "#updateReqVO.id", level = CrmPermissionLevelEnum.WRITE) - public void updateClue(CrmClueUpdateReqVO updateReqVO) { - // 校验存在 + public void updateClue(CrmClueSaveReqVO updateReqVO) { + // 校验线索是否存在 validateClueExists(updateReqVO.getId()); - // 如果传入客户,校验客户是否存在 - if (Objects.nonNull(updateReqVO.getCustomerId())) { - customerService.validateCustomer(updateReqVO.getCustomerId()); - } + // 校验关联数据 + validateRelationDataExists(updateReqVO); // 更新 CrmClueDO updateObj = CrmClueConvert.INSTANCE.convert(updateReqVO); @@ -137,4 +142,18 @@ public class CrmClueServiceImpl implements CrmClueService { clueMapper.updateById(clueDO); }); } + + private void validateRelationDataExists(CrmClueSaveReqVO reqVO) { + // 校验客户 + if (Objects.nonNull(reqVO.getCustomerId()) && + Objects.isNull(customerService.getCustomer(reqVO.getCustomerId()))) { + throw exception(CUSTOMER_NOT_EXISTS); + } + // 校验负责人 + // 2. 校验负责人 + if (Objects.nonNull(reqVO.getOwnerUserId()) && + Objects.isNull(adminUserApi.getUser(reqVO.getOwnerUserId()))) { + throw exception(USER_NOT_EXISTS); + } + } } diff --git a/yudao-module-crm/yudao-module-crm-biz/src/test/java/cn/iocoder/yudao/module/crm/service/clue/CrmClueServiceImplTest.java b/yudao-module-crm/yudao-module-crm-biz/src/test/java/cn/iocoder/yudao/module/crm/service/clue/CrmClueServiceImplTest.java index 8b07804c2..9738c67b3 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/test/java/cn/iocoder/yudao/module/crm/service/clue/CrmClueServiceImplTest.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/test/java/cn/iocoder/yudao/module/crm/service/clue/CrmClueServiceImplTest.java @@ -2,9 +2,8 @@ package cn.iocoder.yudao.module.crm.service.clue; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; -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.CrmClueUpdateReqVO; +import cn.iocoder.yudao.module.crm.controller.admin.clue.vo.CrmClueSaveReqVO; import cn.iocoder.yudao.module.crm.dal.dataobject.clue.CrmClueDO; import cn.iocoder.yudao.module.crm.dal.mysql.clue.CrmClueMapper; import jakarta.annotation.Resource; @@ -43,7 +42,7 @@ public class CrmClueServiceImplTest extends BaseDbUnitTest { @Test public void testCreateClue_success() { // 准备参数 - CrmClueCreateReqVO reqVO = randomPojo(CrmClueCreateReqVO.class); + CrmClueSaveReqVO reqVO = randomPojo(CrmClueSaveReqVO.class); // 调用 Long clueId = clueService.createClue(reqVO); @@ -60,7 +59,7 @@ public class CrmClueServiceImplTest extends BaseDbUnitTest { CrmClueDO dbClue = randomPojo(CrmClueDO.class); clueMapper.insert(dbClue);// @Sql: 先插入出一条存在的数据 // 准备参数 - CrmClueUpdateReqVO reqVO = randomPojo(CrmClueUpdateReqVO.class, o -> { + CrmClueSaveReqVO reqVO = randomPojo(CrmClueSaveReqVO.class, o -> { o.setId(dbClue.getId()); // 设置更新的 ID }); @@ -74,7 +73,7 @@ public class CrmClueServiceImplTest extends BaseDbUnitTest { @Test public void testUpdateClue_notExists() { // 准备参数 - CrmClueUpdateReqVO reqVO = randomPojo(CrmClueUpdateReqVO.class); + CrmClueSaveReqVO reqVO = randomPojo(CrmClueSaveReqVO.class); // 调用, 并断言异常 assertServiceException(() -> clueService.updateClue(reqVO), CLUE_NOT_EXISTS);