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 a504419c9..eced81ba3 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 @@ -2,10 +2,10 @@ package cn.iocoder.yudao.module.crm.controller.admin.clue; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; 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.convert.clue.CrmClueConvert; import cn.iocoder.yudao.module.crm.dal.dataobject.clue.CrmClueDO; import cn.iocoder.yudao.module.crm.service.clue.CrmClueService; import io.swagger.v3.oas.annotations.Operation; @@ -65,7 +65,7 @@ public class CrmClueController { @PreAuthorize("@ss.hasPermission('crm:clue:query')") public CommonResult getClue(@RequestParam("id") Long id) { CrmClueDO clue = clueService.getClue(id); - return success(CrmClueConvert.INSTANCE.convert(clue)); + return success(BeanUtils.toBean(clue, CrmClueRespVO.class)); } @GetMapping("/page") @@ -73,7 +73,7 @@ public class CrmClueController { @PreAuthorize("@ss.hasPermission('crm:clue:query')") public CommonResult> getCluePage(@Valid CrmCluePageReqVO pageVO) { PageResult pageResult = clueService.getCluePage(pageVO, getLoginUserId()); - return success(CrmClueConvert.INSTANCE.convertPage(pageResult)); + return success(BeanUtils.toBean(pageResult, CrmClueRespVO.class)); } @GetMapping("/export-excel") @@ -84,7 +84,7 @@ public class CrmClueController { pageReqVO.setPageSize(PAGE_SIZE_NONE); List list = clueService.getCluePage(pageReqVO, getLoginUserId()).getList(); // 导出 Excel - List datas = CrmClueConvert.INSTANCE.convertList02(list); + List datas = BeanUtils.toBean(list, CrmClueExcelVO.class); ExcelUtils.write(response, "线索.xls", "数据", CrmClueExcelVO.class, datas); } @@ -99,9 +99,8 @@ public class CrmClueController { @PostMapping("/transform") @Operation(summary = "线索转化为客户") @PreAuthorize("@ss.hasPermission('crm:clue:update')") - // TODO @min:方法改成 translateCustomer - public CommonResult translate(@Valid @RequestBody CrmClueTransformReqVO reqVO) { - clueService.translate(reqVO, getLoginUserId()); + public CommonResult translateCustomer(@Valid @RequestBody CrmClueTransformReqVO reqVO) { + clueService.translateCustomer(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/CrmClueSaveReqVO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/clue/vo/CrmClueSaveReqVO.java index f95799734..adbc650b9 100644 --- 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 @@ -22,10 +22,6 @@ public class CrmClueSaveReqVO { @NotEmpty(message = "线索名称不能为空") private String name; - // TODO @min:是不是不传递 customerId? - @Schema(description = "客户 id", 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; 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 index fa698eec9..68bb02b3f 100644 --- 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 @@ -11,6 +11,7 @@ import java.util.Set; public class CrmClueTransformReqVO { @Schema(description = "线索编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "[1024, 1025]") - @NotEmpty(message = "线索编号不能为空") Set ids; // TODO @min:应该空行噢 + @NotEmpty(message = "线索编号不能为空") + private Set ids; } 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 db4e281a3..39e607bcb 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 @@ -1,18 +1,11 @@ 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.CrmClueExcelVO; -import cn.iocoder.yudao.module.crm.controller.admin.clue.vo.CrmClueRespVO; -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.dal.dataobject.clue.CrmClueDO; import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionTransferReqBO; import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.factory.Mappers; -import java.util.List; - /** * 线索 Convert * @@ -23,15 +16,6 @@ public interface CrmClueConvert { CrmClueConvert INSTANCE = Mappers.getMapper(CrmClueConvert.class); - // TODO @min:这几个 convert,都使用 BeanUtils 替代哈 - CrmClueDO convert(CrmClueSaveReqVO bean); - - CrmClueRespVO convert(CrmClueDO bean); - - PageResult convertPage(PageResult page); - - List convertList02(List list); - @Mapping(target = "bizId", source = "reqVO.id") CrmPermissionTransferReqBO convert(CrmClueTransferReqVO reqVO, Long userId); 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 f3902a81c..fcda32ff3 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 @@ -79,6 +79,6 @@ public interface CrmClueService { * @param reqVO 线索编号 * @param userId 用户编号 */ - void translate(CrmClueTransformReqVO reqVO, Long userId); + void translateCustomer(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 8018f42f3..b87fd547e 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 @@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.crm.service.clue; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.ListUtil; +import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.module.crm.controller.admin.clue.vo.CrmCluePageReqVO; @@ -29,7 +30,6 @@ 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; /** @@ -60,7 +60,7 @@ public class CrmClueServiceImpl implements CrmClueService { validateRelationDataExists(createReqVO); // 插入 - CrmClueDO clue = CrmClueConvert.INSTANCE.convert(createReqVO); + CrmClueDO clue = BeanUtils.toBean(createReqVO, CrmClueDO.class); clueMapper.insert(clue); // 返回 return clue.getId(); @@ -75,7 +75,7 @@ public class CrmClueServiceImpl implements CrmClueService { validateRelationDataExists(updateReqVO); // 更新 - CrmClueDO updateObj = CrmClueConvert.INSTANCE.convert(updateReqVO); + CrmClueDO updateObj = BeanUtils.toBean(updateReqVO, CrmClueDO.class); clueMapper.updateById(updateObj); } @@ -130,7 +130,7 @@ public class CrmClueServiceImpl implements CrmClueService { @Override @Transactional(rollbackFor = Exception.class) - public void translate(CrmClueTransformReqVO reqVO, Long userId) { + public void translateCustomer(CrmClueTransformReqVO reqVO, Long userId) { // 校验线索都存在 List clues = getClueList(reqVO.getIds(), userId); if (CollUtil.isEmpty(clues)) { @@ -138,29 +138,25 @@ public class CrmClueServiceImpl implements CrmClueService { } // TODO @min:如果已经转化,则不能重复转化 - // 遍历线索,创建对应的客户 - clues.forEach(clue -> { - clue.setId(null); - // 创建客户 - // TODO @puhui999:上面的 id 置空,适合 bean copy 后,在设置为 null,不直接修改 clu 哈 - customerService.createCustomer(BeanUtils.toBean(clue, CrmCustomerSaveReqVO.class), userId); - // 更新线索状态 - // TODO @min:新建一个 CrmClueDO 去更新。尽量规避直接用原本的对象去更新。因为这样万一并发更新,会存在覆盖的问题。 - // TODO @min:customerId 没有更新进去 - // TODO @puhui999:如果有跟进记录,需要一起转过去; - clue.setTransformStatus(Boolean.TRUE); - clueMapper.updateById(clue); - }); + // 遍历线索(过滤掉已转化的线索),创建对应的客户 + clues.stream().filter(clue -> ObjectUtil.notEqual(Boolean.TRUE, clue.getTransformStatus())) + .forEach(clue -> { + // 1.创建客户 + CrmCustomerSaveReqVO customerSaveReqVO = BeanUtils.toBean(clue, CrmCustomerSaveReqVO.class) + .setId(null); + Long customerId = customerService.createCustomer(customerSaveReqVO, userId); + // TODO @puhui999:如果有跟进记录,需要一起转过去; + // 2.更新线索,新建一个 CrmClueDO 去更新。尽量规避直接用原本的对象去更新。因为这样万一并发更新,会存在覆盖的问题。 + clueMapper.updateById(BeanUtils.toBean(clue, CrmClueDO.class) + // 线索状态设置为已转化 + .setTransformStatus(Boolean.TRUE) + // 设置关联的客户编号 + .setCustomerId(customerId)); + }); } 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);