CRM:优化 CRM 跟进记录的实现

This commit is contained in:
YunaiV 2024-02-24 15:46:57 +08:00
parent 3f8fa6b1bc
commit 29f1eb2c18
12 changed files with 50 additions and 84 deletions

View File

@ -126,15 +126,6 @@ public class CrmBusinessController {
return businessVO;
}
// TODO 芋艿处理下
@GetMapping("/list-by-ids")
@Operation(summary = "获得商机列表")
@Parameter(name = "ids", description = "编号", required = true, example = "[1024]")
@PreAuthorize("@ss.hasPermission('crm:business:query')")
public CommonResult<List<CrmBusinessRespVO>> getContactListByIds(@RequestParam("ids") List<Long> ids) {
return success(BeanUtils.toBean(businessService.getBusinessList(ids, getLoginUserId()), CrmBusinessRespVO.class));
}
@GetMapping("/simple-all-list")
@Operation(summary = "获得联系人的精简列表")
@PreAuthorize("@ss.hasPermission('crm:contact:query')")

View File

@ -105,15 +105,6 @@ public class CrmContactController {
return buildContactDetailList(singletonList(contact)).get(0);
}
@GetMapping("/list-by-ids")
@Operation(summary = "获得联系人列表")
@Parameter(name = "ids", description = "编号", required = true, example = "[1024]")
@PreAuthorize("@ss.hasPermission('crm:contact:query')")
public CommonResult<List<CrmContactRespVO>> getContactListByIds(@RequestParam("ids") List<Long> ids) {
List<CrmContactDO> list = contactService.getContactListByIds(ids, getLoginUserId());
return success(BeanUtils.toBean(list, CrmContactRespVO.class));
}
@GetMapping("/simple-all-list")
@Operation(summary = "获得联系人的精简列表")
@PreAuthorize("@ss.hasPermission('crm:contact:query')")

View File

@ -187,8 +187,8 @@ public class CrmContractController {
Map<Long, CrmContactDO> contactMap = convertMap(contactService.getContactList(convertSet(contractList,
CrmContractDO::getSignContactId)), CrmContactDO::getId);
// 1.4 获取商机
Map<Long, CrmBusinessDO> businessMap = convertMap(businessService.getBusinessList(convertSet(contractList,
CrmContractDO::getBusinessId)), CrmBusinessDO::getId);
Map<Long, CrmBusinessDO> businessMap = businessService.getBusinessMap(
convertSet(contractList, CrmContractDO::getBusinessId));
// 2. 拼接数据
return BeanUtils.toBean(contractList, CrmContractRespVO.class, contractVO -> {
// 2.1 设置客户信息

View File

@ -4,6 +4,7 @@ import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.crm.controller.admin.business.vo.business.CrmBusinessRespVO;
import cn.iocoder.yudao.module.crm.controller.admin.followup.vo.CrmFollowUpRecordPageReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.followup.vo.CrmFollowUpRecordRespVO;
import cn.iocoder.yudao.module.crm.controller.admin.followup.vo.CrmFollowUpRecordSaveReqVO;
@ -13,6 +14,8 @@ import cn.iocoder.yudao.module.crm.dal.dataobject.followup.CrmFollowUpRecordDO;
import cn.iocoder.yudao.module.crm.service.business.CrmBusinessService;
import cn.iocoder.yudao.module.crm.service.contact.CrmContactService;
import cn.iocoder.yudao.module.crm.service.followup.CrmFollowUpRecordService;
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
@ -26,7 +29,7 @@ import java.util.ArrayList;
import java.util.Map;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSetByFlatMap;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
@ -44,6 +47,9 @@ public class CrmFollowUpRecordController {
@Resource
private CrmBusinessService businessService;
@Resource
private AdminUserApi adminUserApi;
@PostMapping("/create")
@Operation(summary = "创建跟进记录")
@PreAuthorize("@ss.hasPermission('crm:follow-up-record:create')")
@ -74,17 +80,24 @@ public class CrmFollowUpRecordController {
@PreAuthorize("@ss.hasPermission('crm:follow-up-record:query')")
public CommonResult<PageResult<CrmFollowUpRecordRespVO>> getFollowUpRecordPage(@Valid CrmFollowUpRecordPageReqVO pageReqVO) {
PageResult<CrmFollowUpRecordDO> pageResult = followUpRecordService.getFollowUpRecordPage(pageReqVO);
/// 拼接数据
Map<Long, CrmContactDO> contactMap = convertMap(contactService.getContactList(
convertSetByFlatMap(pageResult.getList(), item -> item.getContactIds().stream())), CrmContactDO::getId);
Map<Long, CrmBusinessDO> businessMap = convertMap(businessService.getBusinessList(
convertSetByFlatMap(pageResult.getList(), item -> item.getBusinessIds().stream())), CrmBusinessDO::getId);
// 1.1 查询联系人和商机
Map<Long, CrmContactDO> contactMap = contactService.getContactMap(
convertSetByFlatMap(pageResult.getList(), item -> item.getContactIds().stream()));
Map<Long, CrmBusinessDO> businessMap = businessService.getBusinessMap(
convertSetByFlatMap(pageResult.getList(), item -> item.getBusinessIds().stream()));
// 1.2 查询用户
Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(
convertSet(pageResult.getList(), item -> Long.valueOf(item.getCreator())));
// 2. 拼接数据
PageResult<CrmFollowUpRecordRespVO> voPageResult = BeanUtils.toBean(pageResult, CrmFollowUpRecordRespVO.class, record -> {
record.setContactNames(new ArrayList<>()).setBusinessNames(new ArrayList<>());
record.getContactIds().forEach(id -> MapUtils.findAndThen(contactMap, id,
contact -> record.getContactNames().add(contact.getName())));
record.getContactIds().forEach(id -> MapUtils.findAndThen(businessMap, id,
business -> record.getBusinessNames().add(business.getName())));
// 2.1 设置联系人和商机信息
record.setBusinesses(new ArrayList<>()).setContacts(new ArrayList<>());
record.getContactIds().forEach(id -> MapUtils.findAndThen(contactMap, id, contact ->
record.getContacts().add(new CrmBusinessRespVO().setId(contact.getId()).setName(contact.getName()))));
record.getContactIds().forEach(id -> MapUtils.findAndThen(businessMap, id, business ->
record.getBusinesses().add(new CrmBusinessRespVO().setId(business.getId()).setName(business.getName()))));
// 2.2 设置用户信息
MapUtils.findAndThen(userMap, Long.valueOf(record.getCreator()), user -> record.setCreatorName(user.getNickname()));
});
return success(voPageResult);
}

View File

@ -1,7 +1,9 @@
package cn.iocoder.yudao.module.crm.controller.admin.followup.vo;
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
import cn.iocoder.yudao.module.crm.controller.admin.business.vo.business.CrmBusinessRespVO;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@ -36,19 +38,26 @@ public class CrmFollowUpRecordRespVO {
@Schema(description = "关联的商机编号数组")
private List<Long> businessIds;
@Schema(description = "关联的商机名称数组")
private List<String> businessNames;
@Schema(description = "关联的商机数组")
private List<CrmBusinessRespVO> businesses;
@Schema(description = "关联的联系人编号数组")
private List<Long> contactIds;
@Schema(description = "关联的联系人名称数组")
private List<String> contactNames;
private List<CrmBusinessRespVO> contacts;
@Schema(description = "图片")
private List<String> picUrls;
@Schema(description = "附件")
private List<String> fileUrls;
@Schema(description = "创建人", example = "1024")
@ExcelProperty("创建人")
private String creator;
@Schema(description = "创建人名字", example = "芋道源码")
@ExcelProperty("创建人名字")
private String creatorName;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
private LocalDateTime createTime;

View File

@ -12,7 +12,6 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.apache.ibatis.annotations.Mapper;
import java.util.Collection;
import java.util.List;
/**
* 商机 Mapper
@ -54,15 +53,6 @@ public interface CrmBusinessMapper extends BaseMapperX<CrmBusinessDO> {
return selectJoinPage(pageReqVO, CrmBusinessDO.class, query);
}
default List<CrmBusinessDO> selectBatchIds(Collection<Long> ids, Long userId) {
MPJLambdaWrapperX<CrmBusinessDO> query = new MPJLambdaWrapperX<>();
// 拼接数据权限的查询条件
CrmPermissionUtils.appendPermissionCondition(query, CrmBizTypeEnum.CRM_BUSINESS.getType(), ids, userId);
// 拼接自身的查询条件
query.selectAll(CrmBusinessDO.class).in(CrmBusinessDO::getId, ids).orderByDesc(CrmBusinessDO::getId);
return selectJoinList(CrmBusinessDO.class, query);
}
default Long selectCountByStatusTypeId(Long statusTypeId) {
return selectCount(CrmBusinessDO::getStatusTypeId, statusTypeId);
}

View File

@ -69,14 +69,6 @@ public interface CrmContactMapper extends BaseMapperX<CrmContactDO> {
return selectJoinPage(pageReqVO, CrmContactDO.class, query);
}
default List<CrmContactDO> selectBatchIds(Collection<Long> ids, Long ownerUserId) {
MPJLambdaWrapperX<CrmContactDO> query = new MPJLambdaWrapperX<>();
// 拼接数据权限的查询条件
CrmPermissionUtils.appendPermissionCondition(query, CrmBizTypeEnum.CRM_CONTACT.getType(), ids, ownerUserId);
query.selectAll(CrmContactDO.class).in(CrmContactDO::getId, ids).orderByDesc(CrmContactDO::getId);
return selectJoinList(CrmContactDO.class, query);
}
default List<CrmContactDO> selectListByCustomerId(Long customerId) {
return selectList(CrmContactDO::getCustomerId, customerId);
}

View File

@ -16,6 +16,9 @@ import jakarta.validation.Valid;
import java.time.LocalDateTime;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
/**
* 商机 Service 接口
@ -101,15 +104,17 @@ public interface CrmBusinessService {
* @param ids 编号
* @return 商机列表
*/
List<CrmBusinessDO> getBusinessList(Collection<Long> ids, Long userId);
List<CrmBusinessDO> getBusinessList(Collection<Long> ids);
/**
* 获得商机列表
* 获得商机 Map
*
* @param ids 编号
* @return 商机列表
* @return 商机 Map
*/
List<CrmBusinessDO> getBusinessList(Collection<Long> ids);
default Map<Long, CrmBusinessDO> getBusinessMap(Collection<Long> ids) {
return convertMap(getBusinessList(ids), CrmBusinessDO::getId);
}
/**
* 获得指定商机编号的产品列表

View File

@ -322,14 +322,6 @@ public class CrmBusinessServiceImpl implements CrmBusinessService {
return validateBusinessExists(id);
}
@Override
public List<CrmBusinessDO> getBusinessList(Collection<Long> ids, Long userId) {
if (CollUtil.isEmpty(ids)) {
return ListUtil.empty();
}
return businessMapper.selectBatchIds(ids, userId);
}
@Override
public List<CrmBusinessDO> getBusinessList(Collection<Long> ids) {
if (CollUtil.isEmpty(ids)) {

View File

@ -95,15 +95,6 @@ public interface CrmContactService {
*/
void validateContact(Long id);
/**
* 获得联系人列表
*
* @param ids 编号
* @param userId 用户编号
* @return 联系人列表
*/
List<CrmContactDO> getContactListByIds(Collection<Long> ids, Long userId);
/**
* 获得联系人列表
*

View File

@ -257,14 +257,6 @@ public class CrmContactServiceImpl implements CrmContactService {
validateContactExists(id);
}
@Override
public List<CrmContactDO> getContactListByIds(Collection<Long> ids, Long userId) {
if (CollUtil.isEmpty(ids)) {
return ListUtil.empty();
}
return contactMapper.selectBatchIds(ids, userId);
}
@Override
public List<CrmContactDO> getContactList(Collection<Long> ids) {
if (CollUtil.isEmpty(ids)) {

View File

@ -69,6 +69,9 @@ public class CrmFollowUpRecordServiceImpl implements CrmFollowUpRecordService {
crmFollowUpRecordMapper.insert(record);
// 2. 更新 bizId 对应的记录
if (ObjUtil.equal(CrmBizTypeEnum.CRM_CUSTOMER.getType(), record.getBizType())) { // 更新客户跟进信息
customerService.updateCustomerFollowUp(record.getBizId(), record.getNextTime(), record.getContent());
}
if (ObjUtil.equal(CrmBizTypeEnum.CRM_BUSINESS.getType(), record.getBizType())) { // 更新商机跟进信息
businessService.updateBusinessFollowUp(record.getBizId(), record.getNextTime(), record.getContent());
}
@ -81,9 +84,6 @@ public class CrmFollowUpRecordServiceImpl implements CrmFollowUpRecordService {
if (ObjUtil.equal(CrmBizTypeEnum.CRM_CONTRACT.getType(), record.getBizType())) { // 更新合同跟进信息
contractService.updateContractFollowUp(record.getBizId(), record.getNextTime(), record.getContent());
}
if (ObjUtil.equal(CrmBizTypeEnum.CRM_CUSTOMER.getType(), record.getBizType())) { // 更新客户跟进信息
customerService.updateCustomerFollowUp(record.getBizId(), record.getNextTime(), record.getContent());
}
// 3.1 更新 contactIds 对应的记录只更新 nextTime
if (CollUtil.isNotEmpty(createReqVO.getContactIds())) {