!829 CRM:【线索】

Merge pull request !829 from Minh-X/develop
This commit is contained in:
芋道源码 2024-01-15 04:22:23 +00:00 committed by Gitee
commit 4ca1f72d4f
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
6 changed files with 94 additions and 144 deletions

View File

@ -14,6 +14,8 @@ public interface ErrorCodeConstants {
// ========== 线索管理 1-020-001-000 ==========
ErrorCode CLUE_NOT_EXISTS = new ErrorCode(1_020_001_000, "线索不存在");
ErrorCode ANY_CLUE_NOT_EXISTS = new ErrorCode(1_020_001_001, "线索【{}】不存在");
ErrorCode ANY_CLUE_ALREADY_TRANSLATED = new ErrorCode(1_020_001_002, "线索【{}】已经转化过了,请勿重复转化");
// ========== 商机管理 1-020-002-000 ==========
ErrorCode BUSINESS_NOT_EXISTS = new ErrorCode(1_020_002_000, "商机不存在");

View File

@ -84,8 +84,8 @@ public class CrmClueController {
pageReqVO.setPageSize(PAGE_SIZE_NONE);
List<CrmClueDO> list = clueService.getCluePage(pageReqVO, getLoginUserId()).getList();
// 导出 Excel
List<CrmClueExcelVO> datas = BeanUtils.toBean(list, CrmClueExcelVO.class);
ExcelUtils.write(response, "线索.xls", "数据", CrmClueExcelVO.class, datas);
List<CrmClueRespVO> datas = BeanUtils.toBean(list, CrmClueRespVO.class);
ExcelUtils.write(response, "线索.xls", "数据", CrmClueRespVO.class, datas);
}
@PutMapping("/transfer")

View File

@ -1,53 +0,0 @@
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 java.time.LocalDateTime;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
/**
* 线索 Base VO提供给添加修改详细的子 VO 使用
* 如果子 VO 存在差异的字段请不要添加到这里影响 Swagger 文档生成
*/
@Data
public class CrmClueBaseVO {
@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;
}

View File

@ -1,66 +0,0 @@
package cn.iocoder.yudao.module.crm.controller.admin.clue.vo;
import cn.iocoder.yudao.module.infra.enums.DictTypeConstants;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
import java.time.LocalDateTime;
import java.time.LocalDateTime;
import java.time.LocalDateTime;
import java.time.LocalDateTime;
import com.alibaba.excel.annotation.ExcelProperty;
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
/**
* 线索 Excel VO
*
* @author Wanwan
*/
@Data
public class CrmClueExcelVO {
@ExcelProperty("编号")
private Long id;
@ExcelProperty(value = "转化状态", converter = DictConvert.class)
@DictFormat(DictTypeConstants.BOOLEAN_STRING)
private Boolean transformStatus;
@ExcelProperty(value = "跟进状态", converter = DictConvert.class)
@DictFormat(DictTypeConstants.BOOLEAN_STRING)
private Boolean followUpStatus;
@ExcelProperty("线索名称")
private String name;
// TODO 这里需要导出成客户名称
@ExcelProperty("客户id")
private Long customerId;
@ExcelProperty("下次联系时间")
private LocalDateTime contactNextTime;
@ExcelProperty("电话")
private String telephone;
@ExcelProperty("手机号")
private String mobile;
@ExcelProperty("地址")
private String address;
@ExcelProperty("负责人的用户编号")
private Long ownerUserId;
@ExcelProperty("最后跟进时间")
private LocalDateTime contactLastTime;
@ExcelProperty("备注")
private String remark;
@ExcelProperty("创建时间")
private LocalDateTime createTime;
}

View File

@ -1,27 +1,80 @@
package cn.iocoder.yudao.module.crm.controller.admin.clue.vo;
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
import cn.iocoder.yudao.module.infra.enums.DictTypeConstants;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import lombok.Data;
import lombok.ToString;
import org.springframework.format.annotation.DateTimeFormat;
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;
@Schema(description = "管理后台 - 线索 Response VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class CrmClueRespVO extends CrmClueBaseVO {
@ExcelIgnoreUnannotated
public class CrmClueRespVO {
@Schema(description = "编号,主键自增", requiredMode = Schema.RequiredMode.REQUIRED, example = "10969")
@ExcelProperty("编号")
private Long id;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
private LocalDateTime createTime;
@Schema(description = "转化状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
@ExcelProperty(value = "转化状态", converter = DictConvert.class)
@DictFormat(DictTypeConstants.BOOLEAN_STRING)
private Boolean transformStatus;
@Schema(description = "跟进状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
@ExcelProperty(value = "跟进状态", converter = DictConvert.class)
@DictFormat(DictTypeConstants.BOOLEAN_STRING)
private Boolean followUpStatus;
@Schema(description = "线索名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "线索xxx")
@ExcelProperty("线索名称")
private String name;
@Schema(description = "客户 id", requiredMode = Schema.RequiredMode.REQUIRED, example = "520")
// TODO 这里需要导出成客户名称
@ExcelProperty("客户id")
private Long customerId;
@Schema(description = "下次联系时间", example = "2023-10-18 01:00:00")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
@ExcelProperty("下次联系时间")
private LocalDateTime contactNextTime;
@Schema(description = "电话", example = "18000000000")
@ExcelProperty("电话")
private String telephone;
@Schema(description = "手机号", example = "18000000000")
@ExcelProperty("手机号")
private String mobile;
@Schema(description = "地址", example = "北京市海淀区")
@ExcelProperty("地址")
private String address;
@Schema(description = "负责人编号")
@ExcelProperty("负责人的用户编号")
private Long ownerUserId;
@Schema(description = "最后跟进时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
@ExcelProperty("最后跟进时间")
private LocalDateTime contactLastTime;
@Schema(description = "备注", example = "随便")
@ExcelProperty("备注")
private String remark;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("创建时间")
private LocalDateTime createTime;
}

View File

@ -27,9 +27,12 @@ import org.springframework.validation.annotation.Validated;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
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.framework.common.util.collection.CollectionUtils.convertSet;
import static cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants.*;
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.USER_NOT_EXISTS;
/**
@ -132,15 +135,26 @@ public class CrmClueServiceImpl implements CrmClueService {
@Transactional(rollbackFor = Exception.class)
public void translateCustomer(CrmClueTransformReqVO reqVO, Long userId) {
// 校验线索都存在
List<CrmClueDO> clues = getClueList(reqVO.getIds(), userId);
if (CollUtil.isEmpty(clues)) {
throw exception(CLUE_NOT_EXISTS);
Set<Long> clueIds = reqVO.getIds();
List<CrmClueDO> clues = getClueList(clueIds, userId);
if (CollUtil.isEmpty(clues) || ObjectUtil.notEqual(clues.size(), clueIds.size())) {
// 提示不存在的线索编号
clueIds.removeAll(convertSet(clues, CrmClueDO::getId));
throw exception(ANY_CLUE_NOT_EXISTS, clueIds.stream().map(String::valueOf).collect(Collectors.joining(",")));
}
// TODO @min如果已经转化则不能重复转化
// 遍历线索(过滤掉已转化的线索)创建对应的客户
clues.stream().filter(clue -> ObjectUtil.notEqual(Boolean.TRUE, clue.getTransformStatus()))
.forEach(clue -> {
// 过滤出未转化的客户
List<CrmClueDO> unTransformClues = clues.stream()
.filter(clue -> ObjectUtil.notEqual(Boolean.TRUE, clue.getTransformStatus())).toList();
// 传入的线索中包含已经转化的情况抛出业务异常
if (ObjectUtil.notEqual(clues.size(), unTransformClues.size())) {
// 提示已经转化的线索编号
clueIds.removeAll(convertSet(unTransformClues, CrmClueDO::getId));
throw exception(ANY_CLUE_ALREADY_TRANSLATED, clueIds.stream().map(String::valueOf).collect(Collectors.joining(",")));
}
// 遍历线索(未转化的线索)创建对应的客户
unTransformClues.forEach(clue -> {
// 1. 创建客户
CrmCustomerSaveReqVO customerSaveReqVO = BeanUtils.toBean(clue, CrmCustomerSaveReqVO.class).setId(null);
Long customerId = customerService.createCustomer(customerSaveReqVO, userId);