!819 CRM:【线索】

Merge pull request !819 from Minh-X/develop
This commit is contained in:
芋道源码 2024-01-09 05:40:45 +00:00 committed by Gitee
commit e4936725f5
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
11 changed files with 165 additions and 66 deletions

View File

@ -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<Long> createClue(@Valid @RequestBody CrmClueCreateReqVO createReqVO) {
public CommonResult<Long> createClue(@Valid @RequestBody CrmClueSaveReqVO createReqVO) {
return success(clueService.createClue(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新线索")
@PreAuthorize("@ss.hasPermission('crm:clue:update')")
public CommonResult<Boolean> updateClue(@Valid @RequestBody CrmClueUpdateReqVO updateReqVO) {
public CommonResult<Boolean> updateClue(@Valid @RequestBody CrmClueSaveReqVO updateReqVO) {
clueService.updateClue(updateReqVO);
return success(true);
}
@ -96,4 +97,12 @@ public class CrmClueController {
return success(true);
}
@PostMapping("/transform")
@Operation(summary = "线索转化为客户")
@PreAuthorize("@ss.hasPermission('crm:clue:update')")
public CommonResult<Boolean> translate(@Valid @RequestBody CrmClueTransformReqVO reqVO) {
clueService.translate(reqVO, getLoginUserId());
return success(Boolean.TRUE);
}
}

View File

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

View File

@ -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 {
}

View File

@ -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;
}

View File

@ -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<Long> ids;
}

View File

@ -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;
}

View File

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

View File

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

View File

@ -1,10 +1,8 @@
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.controller.admin.contact.vo.CrmContactSaveReqVO;
import cn.iocoder.yudao.module.crm.dal.dataobject.clue.CrmClueDO;
import jakarta.validation.Valid;
@ -24,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);
/**
* 删除线索
@ -73,4 +71,11 @@ public interface CrmClueService {
*/
void transferClue(CrmClueTransferReqVO reqVO, Long userId);
/**
* 线索转化为客户
*
* @param reqVO 线索编号
* @param userId 用户编号
*/
void translate(CrmClueTransformReqVO reqVO, Long userId);
}

View File

@ -3,11 +3,10 @@ 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.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;
import cn.iocoder.yudao.module.crm.dal.mysql.clue.CrmClueMapper;
import cn.iocoder.yudao.module.crm.enums.common.CrmBizTypeEnum;
@ -15,15 +14,20 @@ 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;
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;
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,27 +43,33 @@ public class CrmClueServiceImpl implements CrmClueService {
@Resource
private CrmCustomerService customerService;
@Resource
private CrmPermissionService crmPermissionService;
@Resource
private AdminUserApi adminUserApi;
@Override
public Long createClue(CrmClueCreateReqVO createReqVO) {
// 校验客户是否存在
customerService.validateCustomer(createReqVO.getCustomerId());
public Long createClue(CrmClueSaveReqVO createReqVO) {
// 校验关联数据
validateRelationDataExists(createReqVO);
// 插入
CrmClueDO clue = CrmClueConvert.INSTANCE.convert(createReqVO);
clueMapper.insert(clue);
System.out.println(1);
// 返回
return clue.getId();
}
@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());
// 校验客户是否存在
customerService.validateCustomer(updateReqVO.getCustomerId());
// 校验关联数据
validateRelationDataExists(updateReqVO);
// 更新
CrmClueDO updateObj = CrmClueConvert.INSTANCE.convert(updateReqVO);
@ -108,12 +118,42 @@ 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<CrmClueDO> 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);
});
}
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);
}
}
}

View File

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