Commit 4ca1f72d4f6ad2935532ea4cad222205a936d7a5
Committed by
Gitee
!829 CRM:【线索】
Merge pull request !829 from Minh-X/develop
Showing
6 changed files
with
95 additions
and
145 deletions
yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/ErrorCodeConstants.java
| @@ -14,6 +14,8 @@ public interface ErrorCodeConstants { | @@ -14,6 +14,8 @@ public interface ErrorCodeConstants { | ||
| 14 | 14 | ||
| 15 | // ========== 线索管理 1-020-001-000 ========== | 15 | // ========== 线索管理 1-020-001-000 ========== |
| 16 | ErrorCode CLUE_NOT_EXISTS = new ErrorCode(1_020_001_000, "线索不存在"); | 16 | ErrorCode CLUE_NOT_EXISTS = new ErrorCode(1_020_001_000, "线索不存在"); |
| 17 | + ErrorCode ANY_CLUE_NOT_EXISTS = new ErrorCode(1_020_001_001, "线索【{}】不存在"); | ||
| 18 | + ErrorCode ANY_CLUE_ALREADY_TRANSLATED = new ErrorCode(1_020_001_002, "线索【{}】已经转化过了,请勿重复转化"); | ||
| 17 | 19 | ||
| 18 | // ========== 商机管理 1-020-002-000 ========== | 20 | // ========== 商机管理 1-020-002-000 ========== |
| 19 | ErrorCode BUSINESS_NOT_EXISTS = new ErrorCode(1_020_002_000, "商机不存在"); | 21 | ErrorCode BUSINESS_NOT_EXISTS = new ErrorCode(1_020_002_000, "商机不存在"); |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/clue/CrmClueController.java
| @@ -84,8 +84,8 @@ public class CrmClueController { | @@ -84,8 +84,8 @@ public class CrmClueController { | ||
| 84 | pageReqVO.setPageSize(PAGE_SIZE_NONE); | 84 | pageReqVO.setPageSize(PAGE_SIZE_NONE); |
| 85 | List<CrmClueDO> list = clueService.getCluePage(pageReqVO, getLoginUserId()).getList(); | 85 | List<CrmClueDO> list = clueService.getCluePage(pageReqVO, getLoginUserId()).getList(); |
| 86 | // 导出 Excel | 86 | // 导出 Excel |
| 87 | - List<CrmClueExcelVO> datas = BeanUtils.toBean(list, CrmClueExcelVO.class); | ||
| 88 | - ExcelUtils.write(response, "线索.xls", "数据", CrmClueExcelVO.class, datas); | 87 | + List<CrmClueRespVO> datas = BeanUtils.toBean(list, CrmClueRespVO.class); |
| 88 | + ExcelUtils.write(response, "线索.xls", "数据", CrmClueRespVO.class, datas); | ||
| 89 | } | 89 | } |
| 90 | 90 | ||
| 91 | @PutMapping("/transfer") | 91 | @PutMapping("/transfer") |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/clue/vo/CrmClueBaseVO.java deleted
| 1 | -package cn.iocoder.yudao.module.crm.controller.admin.clue.vo; | ||
| 2 | - | ||
| 3 | -import cn.iocoder.yudao.framework.common.validation.Mobile; | ||
| 4 | -import cn.iocoder.yudao.framework.common.validation.Telephone; | ||
| 5 | -import io.swagger.v3.oas.annotations.media.Schema; | ||
| 6 | -import jakarta.validation.constraints.NotEmpty; | ||
| 7 | -import lombok.Data; | ||
| 8 | -import org.springframework.format.annotation.DateTimeFormat; | ||
| 9 | - | ||
| 10 | -import java.time.LocalDateTime; | ||
| 11 | - | ||
| 12 | -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | ||
| 13 | - | ||
| 14 | -/** | ||
| 15 | - * 线索 Base VO,提供给添加、修改、详细的子 VO 使用 | ||
| 16 | - * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 | ||
| 17 | - */ | ||
| 18 | -@Data | ||
| 19 | -public class CrmClueBaseVO { | ||
| 20 | - | ||
| 21 | - @Schema(description = "线索名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "线索xxx") | ||
| 22 | - @NotEmpty(message = "线索名称不能为空") | ||
| 23 | - private String name; | ||
| 24 | - | ||
| 25 | - @Schema(description = "客户 id", requiredMode = Schema.RequiredMode.REQUIRED, example = "520") | ||
| 26 | - private Long customerId; | ||
| 27 | - | ||
| 28 | - @Schema(description = "下次联系时间", example = "2023-10-18 01:00:00") | ||
| 29 | - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | ||
| 30 | - private LocalDateTime contactNextTime; | ||
| 31 | - | ||
| 32 | - @Schema(description = "电话", example = "18000000000") | ||
| 33 | - @Telephone | ||
| 34 | - private String telephone; | ||
| 35 | - | ||
| 36 | - @Schema(description = "手机号", example = "18000000000") | ||
| 37 | - @Mobile | ||
| 38 | - private String mobile; | ||
| 39 | - | ||
| 40 | - @Schema(description = "地址", example = "北京市海淀区") | ||
| 41 | - private String address; | ||
| 42 | - | ||
| 43 | - @Schema(description = "最后跟进时间") | ||
| 44 | - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | ||
| 45 | - private LocalDateTime contactLastTime; | ||
| 46 | - | ||
| 47 | - @Schema(description = "负责人编号") | ||
| 48 | - private Long ownerUserId; | ||
| 49 | - | ||
| 50 | - @Schema(description = "备注", example = "随便") | ||
| 51 | - private String remark; | ||
| 52 | - | ||
| 53 | -} |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/clue/vo/CrmClueExcelVO.java deleted
| 1 | -package cn.iocoder.yudao.module.crm.controller.admin.clue.vo; | ||
| 2 | - | ||
| 3 | -import cn.iocoder.yudao.module.infra.enums.DictTypeConstants; | ||
| 4 | -import io.swagger.v3.oas.annotations.media.Schema; | ||
| 5 | -import lombok.*; | ||
| 6 | -import java.util.*; | ||
| 7 | -import java.time.LocalDateTime; | ||
| 8 | -import java.time.LocalDateTime; | ||
| 9 | -import java.time.LocalDateTime; | ||
| 10 | -import java.time.LocalDateTime; | ||
| 11 | - | ||
| 12 | -import com.alibaba.excel.annotation.ExcelProperty; | ||
| 13 | -import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; | ||
| 14 | -import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; | ||
| 15 | - | ||
| 16 | -/** | ||
| 17 | - * 线索 Excel VO | ||
| 18 | - * | ||
| 19 | - * @author Wanwan | ||
| 20 | - */ | ||
| 21 | -@Data | ||
| 22 | -public class CrmClueExcelVO { | ||
| 23 | - | ||
| 24 | - @ExcelProperty("编号") | ||
| 25 | - private Long id; | ||
| 26 | - | ||
| 27 | - @ExcelProperty(value = "转化状态", converter = DictConvert.class) | ||
| 28 | - @DictFormat(DictTypeConstants.BOOLEAN_STRING) | ||
| 29 | - private Boolean transformStatus; | ||
| 30 | - | ||
| 31 | - @ExcelProperty(value = "跟进状态", converter = DictConvert.class) | ||
| 32 | - @DictFormat(DictTypeConstants.BOOLEAN_STRING) | ||
| 33 | - private Boolean followUpStatus; | ||
| 34 | - | ||
| 35 | - @ExcelProperty("线索名称") | ||
| 36 | - private String name; | ||
| 37 | - | ||
| 38 | - // TODO 这里需要导出成客户名称 | ||
| 39 | - @ExcelProperty("客户id") | ||
| 40 | - private Long customerId; | ||
| 41 | - | ||
| 42 | - @ExcelProperty("下次联系时间") | ||
| 43 | - private LocalDateTime contactNextTime; | ||
| 44 | - | ||
| 45 | - @ExcelProperty("电话") | ||
| 46 | - private String telephone; | ||
| 47 | - | ||
| 48 | - @ExcelProperty("手机号") | ||
| 49 | - private String mobile; | ||
| 50 | - | ||
| 51 | - @ExcelProperty("地址") | ||
| 52 | - private String address; | ||
| 53 | - | ||
| 54 | - @ExcelProperty("负责人的用户编号") | ||
| 55 | - private Long ownerUserId; | ||
| 56 | - | ||
| 57 | - @ExcelProperty("最后跟进时间") | ||
| 58 | - private LocalDateTime contactLastTime; | ||
| 59 | - | ||
| 60 | - @ExcelProperty("备注") | ||
| 61 | - private String remark; | ||
| 62 | - | ||
| 63 | - @ExcelProperty("创建时间") | ||
| 64 | - private LocalDateTime createTime; | ||
| 65 | - | ||
| 66 | -} |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/clue/vo/CrmClueRespVO.java
| 1 | package cn.iocoder.yudao.module.crm.controller.admin.clue.vo; | 1 | package cn.iocoder.yudao.module.crm.controller.admin.clue.vo; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; | ||
| 4 | +import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; | ||
| 5 | +import cn.iocoder.yudao.module.infra.enums.DictTypeConstants; | ||
| 6 | +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; | ||
| 7 | +import com.alibaba.excel.annotation.ExcelProperty; | ||
| 3 | import io.swagger.v3.oas.annotations.media.Schema; | 8 | import io.swagger.v3.oas.annotations.media.Schema; |
| 4 | -import lombok.*; | 9 | +import lombok.Data; |
| 10 | +import lombok.ToString; | ||
| 11 | +import org.springframework.format.annotation.DateTimeFormat; | ||
| 5 | 12 | ||
| 6 | -import jakarta.validation.constraints.NotNull; | ||
| 7 | import java.time.LocalDateTime; | 13 | import java.time.LocalDateTime; |
| 8 | 14 | ||
| 15 | +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | ||
| 16 | + | ||
| 9 | @Schema(description = "管理后台 - 线索 Response VO") | 17 | @Schema(description = "管理后台 - 线索 Response VO") |
| 10 | @Data | 18 | @Data |
| 11 | -@EqualsAndHashCode(callSuper = true) | ||
| 12 | @ToString(callSuper = true) | 19 | @ToString(callSuper = true) |
| 13 | -public class CrmClueRespVO extends CrmClueBaseVO { | 20 | +@ExcelIgnoreUnannotated |
| 21 | +public class CrmClueRespVO { | ||
| 14 | 22 | ||
| 15 | @Schema(description = "编号,主键自增", requiredMode = Schema.RequiredMode.REQUIRED, example = "10969") | 23 | @Schema(description = "编号,主键自增", requiredMode = Schema.RequiredMode.REQUIRED, example = "10969") |
| 24 | + @ExcelProperty("编号") | ||
| 16 | private Long id; | 25 | private Long id; |
| 17 | 26 | ||
| 18 | - @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) | ||
| 19 | - private LocalDateTime createTime; | ||
| 20 | - | ||
| 21 | @Schema(description = "转化状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "true") | 27 | @Schema(description = "转化状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "true") |
| 28 | + @ExcelProperty(value = "转化状态", converter = DictConvert.class) | ||
| 29 | + @DictFormat(DictTypeConstants.BOOLEAN_STRING) | ||
| 22 | private Boolean transformStatus; | 30 | private Boolean transformStatus; |
| 23 | 31 | ||
| 24 | @Schema(description = "跟进状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "true") | 32 | @Schema(description = "跟进状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "true") |
| 33 | + @ExcelProperty(value = "跟进状态", converter = DictConvert.class) | ||
| 34 | + @DictFormat(DictTypeConstants.BOOLEAN_STRING) | ||
| 25 | private Boolean followUpStatus; | 35 | private Boolean followUpStatus; |
| 26 | 36 | ||
| 37 | + @Schema(description = "线索名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "线索xxx") | ||
| 38 | + @ExcelProperty("线索名称") | ||
| 39 | + private String name; | ||
| 40 | + | ||
| 41 | + @Schema(description = "客户 id", requiredMode = Schema.RequiredMode.REQUIRED, example = "520") | ||
| 42 | + // TODO 这里需要导出成客户名称 | ||
| 43 | + @ExcelProperty("客户id") | ||
| 44 | + private Long customerId; | ||
| 45 | + | ||
| 46 | + @Schema(description = "下次联系时间", example = "2023-10-18 01:00:00") | ||
| 47 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | ||
| 48 | + @ExcelProperty("下次联系时间") | ||
| 49 | + private LocalDateTime contactNextTime; | ||
| 50 | + | ||
| 51 | + @Schema(description = "电话", example = "18000000000") | ||
| 52 | + @ExcelProperty("电话") | ||
| 53 | + private String telephone; | ||
| 54 | + | ||
| 55 | + @Schema(description = "手机号", example = "18000000000") | ||
| 56 | + @ExcelProperty("手机号") | ||
| 57 | + private String mobile; | ||
| 58 | + | ||
| 59 | + @Schema(description = "地址", example = "北京市海淀区") | ||
| 60 | + @ExcelProperty("地址") | ||
| 61 | + private String address; | ||
| 62 | + | ||
| 63 | + @Schema(description = "负责人编号") | ||
| 64 | + @ExcelProperty("负责人的用户编号") | ||
| 65 | + private Long ownerUserId; | ||
| 66 | + | ||
| 67 | + @Schema(description = "最后跟进时间") | ||
| 68 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | ||
| 69 | + @ExcelProperty("最后跟进时间") | ||
| 70 | + private LocalDateTime contactLastTime; | ||
| 71 | + | ||
| 72 | + @Schema(description = "备注", example = "随便") | ||
| 73 | + @ExcelProperty("备注") | ||
| 74 | + private String remark; | ||
| 75 | + | ||
| 76 | + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) | ||
| 77 | + @ExcelProperty("创建时间") | ||
| 78 | + private LocalDateTime createTime; | ||
| 79 | + | ||
| 27 | } | 80 | } |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/clue/CrmClueServiceImpl.java
| @@ -27,9 +27,12 @@ import org.springframework.validation.annotation.Validated; | @@ -27,9 +27,12 @@ import org.springframework.validation.annotation.Validated; | ||
| 27 | import java.util.Collection; | 27 | import java.util.Collection; |
| 28 | import java.util.List; | 28 | import java.util.List; |
| 29 | import java.util.Objects; | 29 | import java.util.Objects; |
| 30 | +import java.util.Set; | ||
| 31 | +import java.util.stream.Collectors; | ||
| 30 | 32 | ||
| 31 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | 33 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 32 | -import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.CLUE_NOT_EXISTS; | 34 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; |
| 35 | +import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*; | ||
| 33 | import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.USER_NOT_EXISTS; | 36 | import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.USER_NOT_EXISTS; |
| 34 | 37 | ||
| 35 | /** | 38 | /** |
| @@ -132,23 +135,34 @@ public class CrmClueServiceImpl implements CrmClueService { | @@ -132,23 +135,34 @@ public class CrmClueServiceImpl implements CrmClueService { | ||
| 132 | @Transactional(rollbackFor = Exception.class) | 135 | @Transactional(rollbackFor = Exception.class) |
| 133 | public void translateCustomer(CrmClueTransformReqVO reqVO, Long userId) { | 136 | public void translateCustomer(CrmClueTransformReqVO reqVO, Long userId) { |
| 134 | // 校验线索都存在 | 137 | // 校验线索都存在 |
| 135 | - List<CrmClueDO> clues = getClueList(reqVO.getIds(), userId); | ||
| 136 | - if (CollUtil.isEmpty(clues)) { | ||
| 137 | - throw exception(CLUE_NOT_EXISTS); | 138 | + Set<Long> clueIds = reqVO.getIds(); |
| 139 | + List<CrmClueDO> clues = getClueList(clueIds, userId); | ||
| 140 | + if (CollUtil.isEmpty(clues) || ObjectUtil.notEqual(clues.size(), clueIds.size())) { | ||
| 141 | + // 提示不存在的线索编号 | ||
| 142 | + clueIds.removeAll(convertSet(clues, CrmClueDO::getId)); | ||
| 143 | + throw exception(ANY_CLUE_NOT_EXISTS, clueIds.stream().map(String::valueOf).collect(Collectors.joining(","))); | ||
| 144 | + } | ||
| 145 | + | ||
| 146 | + // 过滤出未转化的客户 | ||
| 147 | + List<CrmClueDO> unTransformClues = clues.stream() | ||
| 148 | + .filter(clue -> ObjectUtil.notEqual(Boolean.TRUE, clue.getTransformStatus())).toList(); | ||
| 149 | + // 传入的线索中包含已经转化的情况,抛出业务异常 | ||
| 150 | + if (ObjectUtil.notEqual(clues.size(), unTransformClues.size())) { | ||
| 151 | + // 提示已经转化的线索编号 | ||
| 152 | + clueIds.removeAll(convertSet(unTransformClues, CrmClueDO::getId)); | ||
| 153 | + throw exception(ANY_CLUE_ALREADY_TRANSLATED, clueIds.stream().map(String::valueOf).collect(Collectors.joining(","))); | ||
| 138 | } | 154 | } |
| 139 | - // TODO @min:如果已经转化,则不能重复转化 | ||
| 140 | - | ||
| 141 | - // 遍历线索(过滤掉已转化的线索),创建对应的客户 | ||
| 142 | - clues.stream().filter(clue -> ObjectUtil.notEqual(Boolean.TRUE, clue.getTransformStatus())) | ||
| 143 | - .forEach(clue -> { | ||
| 144 | - // 1. 创建客户 | ||
| 145 | - CrmCustomerSaveReqVO customerSaveReqVO = BeanUtils.toBean(clue, CrmCustomerSaveReqVO.class).setId(null); | ||
| 146 | - Long customerId = customerService.createCustomer(customerSaveReqVO, userId); | ||
| 147 | - // TODO @puhui999:如果有跟进记录,需要一起转过去; | ||
| 148 | - // 2. 更新线索 | ||
| 149 | - clueMapper.updateById(new CrmClueDO().setId(clue.getId()) | ||
| 150 | - .setTransformStatus(Boolean.TRUE).setCustomerId(customerId)); | ||
| 151 | - }); | 155 | + |
| 156 | + // 遍历线索(未转化的线索),创建对应的客户 | ||
| 157 | + unTransformClues.forEach(clue -> { | ||
| 158 | + // 1. 创建客户 | ||
| 159 | + CrmCustomerSaveReqVO customerSaveReqVO = BeanUtils.toBean(clue, CrmCustomerSaveReqVO.class).setId(null); | ||
| 160 | + Long customerId = customerService.createCustomer(customerSaveReqVO, userId); | ||
| 161 | + // TODO @puhui999:如果有跟进记录,需要一起转过去; | ||
| 162 | + // 2. 更新线索 | ||
| 163 | + clueMapper.updateById(new CrmClueDO().setId(clue.getId()) | ||
| 164 | + .setTransformStatus(Boolean.TRUE).setCustomerId(customerId)); | ||
| 165 | + }); | ||
| 152 | } | 166 | } |
| 153 | 167 | ||
| 154 | private void validateRelationDataExists(CrmClueSaveReqVO reqVO) { | 168 | private void validateRelationDataExists(CrmClueSaveReqVO reqVO) { |