📖 CRM:code review 线索模块

This commit is contained in:
YunaiV 2024-01-09 13:52:04 +08:00
parent e4936725f5
commit 6a93484260
7 changed files with 32 additions and 26 deletions

View File

@ -5,7 +5,6 @@ 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;
@ -100,6 +99,7 @@ public class CrmClueController {
@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

@ -4,31 +4,26 @@ 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")
@Schema(description = "编号", 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")
// TODO @min是不是不传递 customerId
@Schema(description = "客户 id", example = "520")
private Long customerId;
@Schema(description = "下次联系时间", example = "2023-10-18 01:00:00")
@ -50,9 +45,10 @@ public class CrmClueSaveReqVO {
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime contactLastTime;
@Schema(description = "负责人编号")
@Schema(description = "负责人编号", example = "2048")
private Long ownerUserId;
@Schema(description = "备注", example = "随便")
private String remark;
}

View File

@ -6,14 +6,11 @@ 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;
@NotEmpty(message = "线索编号不能为空") Set<Long> ids; // TODO @min应该空行噢
}

View File

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

View File

@ -78,6 +78,8 @@ public interface CrmCustomerConvert {
CrmCustomerPoolConfigDO convert(CrmCustomerPoolConfigSaveReqVO updateReqVO);
// TODO @min使用 BeanUtils 拷贝哈我们慢慢简单的对象不再直接基于 convert 做啦
@Mapping(ignore = true, target = "id")
CrmCustomerSaveReqVO convert(CrmClueDO bean);
}

View File

@ -1,8 +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.*;
import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.CrmContactSaveReqVO;
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.CrmClueTransformReqVO;
import cn.iocoder.yudao.module.crm.dal.dataobject.clue.CrmClueDO;
import jakarta.validation.Valid;
@ -78,4 +80,5 @@ public interface CrmClueService {
* @param userId 用户编号
*/
void translate(CrmClueTransformReqVO reqVO, Long userId);
}

View File

@ -3,8 +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.*;
import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.CrmContactSaveReqVO;
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.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;
@ -51,6 +53,7 @@ public class CrmClueServiceImpl implements CrmClueService {
private AdminUserApi adminUserApi;
@Override
// TODO @min补充相关几个方法的操作日志
public Long createClue(CrmClueSaveReqVO createReqVO) {
// 校验关联数据
validateRelationDataExists(createReqVO);
@ -58,7 +61,6 @@ public class CrmClueServiceImpl implements CrmClueService {
// 插入
CrmClueDO clue = CrmClueConvert.INSTANCE.convert(createReqVO);
clueMapper.insert(clue);
System.out.println(1);
// 返回
return clue.getId();
}
@ -128,18 +130,20 @@ public class CrmClueServiceImpl implements CrmClueService {
@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 -> {
clues.forEach(clue -> {
// 创建客户
customerService.createCustomer(CrmCustomerConvert.INSTANCE.convert(clueDO), userId);
customerService.createCustomer(CrmCustomerConvert.INSTANCE.convert(clue), userId);
// 更新线索状态
clueDO.setTransformStatus(Boolean.TRUE);
clueMapper.updateById(clueDO);
// TODO @min新建一个 CrmClueDO 去更新尽量规避直接用原本的对象去更新因为这样万一并发更新会存在覆盖的问题
clue.setTransformStatus(Boolean.TRUE);
clueMapper.updateById(clue);
});
}
@ -156,4 +160,5 @@ public class CrmClueServiceImpl implements CrmClueService {
throw exception(USER_NOT_EXISTS);
}
}
}