Merge remote-tracking branch 'yudao/develop' into develop

# Conflicts:
#	yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/convert/customer/CrmCustomerConvert.java
This commit is contained in:
puhui999 2024-01-10 21:13:33 +08:00
commit ad4044f932
11 changed files with 176 additions and 63 deletions

View File

@ -38,14 +38,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 +96,13 @@ public class CrmClueController {
return success(true);
}
@PostMapping("/transform")
@Operation(summary = "线索转化为客户")
@PreAuthorize("@ss.hasPermission('crm:clue:update')")
// TODO @min方法改成 translateCustomer
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,54 @@
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;
@Schema(description = "管理后台 - CRM 线索 创建/更新 Request VO")
@Data
public class CrmClueSaveReqVO {
@Schema(description = "编号", example = "10969")
private Long id;
@Schema(description = "线索名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "线索xxx")
@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;
@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 = "负责人编号", example = "2048")
private Long ownerUserId;
@Schema(description = "备注", example = "随便")
private String remark;
}

View File

@ -0,0 +1,16 @@
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;
@Schema(description = "管理后台 - 线索转化为客户 Request VO")
@Data
public class CrmClueTransformReqVO {
@Schema(description = "线索编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "[1024, 1025]")
@NotEmpty(message = "线索编号不能为空") Set<Long> ids; // TODO @min应该空行噢
}

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

@ -1,7 +1,10 @@
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.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;
@ -20,9 +23,8 @@ public interface CrmClueConvert {
CrmClueConvert INSTANCE = Mappers.getMapper(CrmClueConvert.class);
CrmClueDO convert(CrmClueCreateReqVO bean);
CrmClueDO convert(CrmClueUpdateReqVO bean);
// TODO @min这几个 convert都使用 BeanUtils 替代哈
CrmClueDO convert(CrmClueSaveReqVO bean);
CrmClueRespVO convert(CrmClueDO bean);

View File

@ -4,6 +4,9 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.ip.core.utils.AreaUtils;
import cn.iocoder.yudao.module.crm.controller.admin.customer.vo.CrmCustomerRespVO;
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.service.permission.bo.CrmPermissionTransferReqBO;
import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
@ -66,4 +69,12 @@ public interface CrmCustomerConvert {
return result;
}
CrmCustomerPoolConfigRespVO convert(CrmCustomerPoolConfigDO customerPoolConfig);
CrmCustomerPoolConfigDO convert(CrmCustomerPoolConfigSaveReqVO updateReqVO);
// TODO @min使用 BeanUtils 拷贝哈我们慢慢简单的对象不再直接基于 convert 做啦
@Mapping(ignore = true, target = "id")
CrmCustomerSaveReqVO convert(CrmClueDO bean);
}

View File

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

View File

@ -3,11 +3,12 @@ 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.CrmClueSaveReqVO;
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.CrmClueTransformReqVO;
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 +16,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,13 +45,19 @@ 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());
// TODO @min补充相关几个方法的操作日志
public Long createClue(CrmClueSaveReqVO createReqVO) {
// 校验关联数据
validateRelationDataExists(createReqVO);
// 插入
CrmClueDO clue = CrmClueConvert.INSTANCE.convert(createReqVO);
clueMapper.insert(clue);
@ -55,11 +67,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());
// 校验客户是否存在
customerService.validateCustomer(updateReqVO.getCustomerId());
// 校验关联数据
validateRelationDataExists(updateReqVO);
// 更新
CrmClueDO updateObj = CrmClueConvert.INSTANCE.convert(updateReqVO);
@ -108,12 +120,47 @@ 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);
}
// TODO @min如果已经转化则不能重复转化
// 遍历线索创建对应的客户
clues.forEach(clue -> {
// 创建客户
customerService.createCustomer(CrmCustomerConvert.INSTANCE.convert(clue), userId);
// 更新线索状态
// TODO @min新建一个 CrmClueDO 去更新尽量规避直接用原本的对象去更新因为这样万一并发更新会存在覆盖的问题
// TODO @puhui999如果有跟进记录需要一起转过去
clue.setTransformStatus(Boolean.TRUE);
clueMapper.updateById(clue);
});
}
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);