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);