CRM:完善联系人的列表

This commit is contained in:
YunaiV 2024-02-20 21:18:45 +08:00
parent 4b41c3c692
commit 66a34a6d90
11 changed files with 213 additions and 233 deletions

View File

@ -2,24 +2,24 @@ package cn.iocoder.yudao.module.crm.controller.admin.contact;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.lang.Assert; import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.NumberUtil;
import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
import cn.iocoder.yudao.framework.common.util.number.NumberUtils; import cn.iocoder.yudao.framework.common.util.number.NumberUtils;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.ip.core.utils.AreaUtils;
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.*; import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.*;
import cn.iocoder.yudao.module.crm.convert.contact.CrmContactConvert;
import cn.iocoder.yudao.module.crm.dal.dataobject.contact.CrmContactDO; import cn.iocoder.yudao.module.crm.dal.dataobject.contact.CrmContactDO;
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO; import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
import cn.iocoder.yudao.module.crm.enums.ErrorCodeConstants;
import cn.iocoder.yudao.module.crm.service.contact.CrmContactBusinessService; import cn.iocoder.yudao.module.crm.service.contact.CrmContactBusinessService;
import cn.iocoder.yudao.module.crm.service.contact.CrmContactService; import cn.iocoder.yudao.module.crm.service.contact.CrmContactService;
import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerService; import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerService;
import cn.iocoder.yudao.module.system.api.dept.DeptApi;
import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
import cn.iocoder.yudao.module.system.api.user.AdminUserApi; import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
import com.google.common.collect.Lists;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
@ -37,12 +37,13 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Stream; import java.util.stream.Stream;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.pojo.PageParam.PAGE_SIZE_NONE; import static cn.iocoder.yudao.framework.common.pojo.PageParam.PAGE_SIZE_NONE;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*;
import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
import static java.util.Collections.singletonList;
@Tag(name = "管理后台 - CRM 联系人") @Tag(name = "管理后台 - CRM 联系人")
@RestController @RestController
@ -60,6 +61,8 @@ public class CrmContactController {
@Resource @Resource
private AdminUserApi adminUserApi; private AdminUserApi adminUserApi;
@Resource
private DeptApi deptApi;
@PostMapping("/create") @PostMapping("/create")
@Operation(summary = "创建联系人") @Operation(summary = "创建联系人")
@ -92,19 +95,14 @@ public class CrmContactController {
@PreAuthorize("@ss.hasPermission('crm:contact:query')") @PreAuthorize("@ss.hasPermission('crm:contact:query')")
public CommonResult<CrmContactRespVO> getContact(@RequestParam("id") Long id) { public CommonResult<CrmContactRespVO> getContact(@RequestParam("id") Long id) {
CrmContactDO contact = contactService.getContact(id); CrmContactDO contact = contactService.getContact(id);
return success(buildContactDetail(contact));
}
private CrmContactRespVO buildContactDetail(CrmContactDO contact) {
if (contact == null) { if (contact == null) {
throw exception(ErrorCodeConstants.CONTACT_NOT_EXISTS); return null;
} }
// 1. 获取用户名 return buildContactDetailList(singletonList(contact)).get(0);
Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(CollUtil.removeNull(Lists.newArrayList(
NumberUtil.parseLong(contact.getCreator()), contact.getOwnerUserId())));
// 2. 获取客户信息
List<CrmCustomerDO> customerList = customerService.getCustomerList(
Collections.singletonList(contact.getCustomerId()));
// 3. 直属上级
List<CrmContactDO> parentContactList = contactService.getContactListByIds(
Collections.singletonList(contact.getParentId()), getLoginUserId());
return success(CrmContactConvert.INSTANCE.convert(contact, userMap, customerList, parentContactList));
} }
@GetMapping("/list-by-ids") @GetMapping("/list-by-ids")
@ -112,7 +110,8 @@ public class CrmContactController {
@Parameter(name = "ids", description = "编号", required = true, example = "[1024]") @Parameter(name = "ids", description = "编号", required = true, example = "[1024]")
@PreAuthorize("@ss.hasPermission('crm:contact:query')") @PreAuthorize("@ss.hasPermission('crm:contact:query')")
public CommonResult<List<CrmContactRespVO>> getContactListByIds(@RequestParam("ids") List<Long> ids) { public CommonResult<List<CrmContactRespVO>> getContactListByIds(@RequestParam("ids") List<Long> ids) {
return success(BeanUtils.toBean(contactService.getContactListByIds(ids, getLoginUserId()), CrmContactRespVO.class)); List<CrmContactDO> list = contactService.getContactListByIds(ids, getLoginUserId());
return success(BeanUtils.toBean(list, CrmContactRespVO.class));
} }
@GetMapping("/simple-all-list") @GetMapping("/simple-all-list")
@ -129,7 +128,7 @@ public class CrmContactController {
@PreAuthorize("@ss.hasPermission('crm:contact:query')") @PreAuthorize("@ss.hasPermission('crm:contact:query')")
public CommonResult<PageResult<CrmContactRespVO>> getContactPage(@Valid CrmContactPageReqVO pageVO) { public CommonResult<PageResult<CrmContactRespVO>> getContactPage(@Valid CrmContactPageReqVO pageVO) {
PageResult<CrmContactDO> pageResult = contactService.getContactPage(pageVO, getLoginUserId()); PageResult<CrmContactDO> pageResult = contactService.getContactPage(pageVO, getLoginUserId());
return success(buildContactDetailPage(pageResult)); return success(new PageResult<>(buildContactDetailList(pageResult.getList()), pageResult.getTotal()));
} }
@GetMapping("/page-by-customer") @GetMapping("/page-by-customer")
@ -137,7 +136,7 @@ public class CrmContactController {
public CommonResult<PageResult<CrmContactRespVO>> getContactPageByCustomer(@Valid CrmContactPageReqVO pageVO) { public CommonResult<PageResult<CrmContactRespVO>> getContactPageByCustomer(@Valid CrmContactPageReqVO pageVO) {
Assert.notNull(pageVO.getCustomerId(), "客户编号不能为空"); Assert.notNull(pageVO.getCustomerId(), "客户编号不能为空");
PageResult<CrmContactDO> pageResult = contactService.getContactPageByCustomerId(pageVO); PageResult<CrmContactDO> pageResult = contactService.getContactPageByCustomerId(pageVO);
return success(buildContactDetailPage(pageResult)); return success(new PageResult<>(buildContactDetailList(pageResult.getList()), pageResult.getTotal()));
} }
@GetMapping("/export-excel") @GetMapping("/export-excel")
@ -147,32 +146,39 @@ public class CrmContactController {
public void exportContactExcel(@Valid CrmContactPageReqVO exportReqVO, public void exportContactExcel(@Valid CrmContactPageReqVO exportReqVO,
HttpServletResponse response) throws IOException { HttpServletResponse response) throws IOException {
exportReqVO.setPageNo(PAGE_SIZE_NONE); exportReqVO.setPageNo(PAGE_SIZE_NONE);
PageResult<CrmContactDO> pageResult = contactService.getContactPage(exportReqVO, getLoginUserId()); List<CrmContactDO> list = contactService.getContactPage(exportReqVO, getLoginUserId()).getList();
ExcelUtils.write(response, "联系人.xls", "数据", CrmContactRespVO.class, ExcelUtils.write(response, "联系人.xls", "数据", CrmContactRespVO.class, buildContactDetailList(list));
buildContactDetailPage(pageResult).getList());
} }
/** private List<CrmContactRespVO> buildContactDetailList(List<CrmContactDO> contactList) {
* 构建详细的联系人分页结果
*
* @param pageResult 简单的联系人分页结果
* @return 详细的联系人分页结果
*/
private PageResult<CrmContactRespVO> buildContactDetailPage(PageResult<CrmContactDO> pageResult) {
List<CrmContactDO> contactList = pageResult.getList();
if (CollUtil.isEmpty(contactList)) { if (CollUtil.isEmpty(contactList)) {
return PageResult.empty(pageResult.getTotal()); return Collections.emptyList();
} }
// 1. 获取客户列表 // 1.1 获取客户列表
List<CrmCustomerDO> crmCustomerDOList = customerService.getCustomerList( Map<Long, CrmCustomerDO> customerMap = customerService.getCustomerMap(
convertSet(contactList, CrmContactDO::getCustomerId)); convertSet(contactList, CrmContactDO::getCustomerId));
// 2. 获取创建人负责人列表 // 1.2 获取创建人负责人列表
Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(convertListByFlatMap(contactList, Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(convertListByFlatMap(contactList,
contact -> Stream.of(NumberUtils.parseLong(contact.getCreator()), contact.getOwnerUserId()))); contact -> Stream.of(NumberUtils.parseLong(contact.getCreator()), contact.getOwnerUserId())));
// 3. 直属上级 Map<Long, DeptRespDTO> deptMap = deptApi.getDeptMap(convertSet(userMap.values(), AdminUserRespDTO::getDeptId));
List<CrmContactDO> parentContactList = contactService.getContactListByIds( // 1.3 直属上级 Map
convertSet(contactList, CrmContactDO::getParentId), getLoginUserId()); Map<Long, CrmContactDO> parentContactMap = contactService.getContactMap(
return CrmContactConvert.INSTANCE.convertPage(pageResult, userMap, crmCustomerDOList, parentContactList); convertSet(contactList, CrmContactDO::getParentId));
// 2. 转换成 VO
return BeanUtils.toBean(contactList, CrmContactRespVO.class, contactVO -> {
contactVO.setAreaName(AreaUtils.format(contactVO.getAreaId()));
// 2.1 设置客户名称
MapUtils.findAndThen(customerMap, contactVO.getCustomerId(), customer -> contactVO.setCustomerName(customer.getName()));
// 2.2 设置创建人负责人名称
MapUtils.findAndThen(userMap, NumberUtils.parseLong(contactVO.getCreator()),
user -> contactVO.setCreatorName(user.getNickname()));
MapUtils.findAndThen(userMap, contactVO.getOwnerUserId(), user -> {
contactVO.setOwnerUserName(user.getNickname());
MapUtils.findAndThen(deptMap, user.getDeptId(), dept -> contactVO.setOwnerUserDeptName(dept.getName()));
});
// 2.3 设置直属上级名称
findAndThen(parentContactMap, contactVO.getParentId(), contact -> contactVO.setParentName(contact.getName()));
});
} }
@PutMapping("/transfer") @PutMapping("/transfer")
@ -183,7 +189,7 @@ public class CrmContactController {
return success(true); return success(true);
} }
// ================== 关联/取关联系人 =================== // ================== 关联/取关商机 ===================
@PostMapping("/create-business-list") @PostMapping("/create-business-list")
@Operation(summary = "创建联系人与商机的关联") @Operation(summary = "创建联系人与商机的关联")

View File

@ -20,29 +20,36 @@ public class CrmContactRespVO {
@Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "3167") @Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "3167")
private Long id; private Long id;
@Schema(description = "姓名", example = "芋艿") @Schema(description = "联系人姓名", example = "芋艿")
@ExcelProperty(value = "姓名", order = 1) @ExcelProperty(value = "联系人姓名", order = 1)
private String name; private String name;
@Schema(description = "客户编号", example = "10795") @Schema(description = "客户编号", example = "10795")
private Long customerId; private Long customerId;
@ExcelProperty(value = "客户名称", order = 2)
@Schema(description = "客户名字", example = "test")
private String customerName;
@Schema(description = "性别") @Schema(description = "最后跟进时间")
@ExcelProperty(value = "性别", converter = DictConvert.class, order = 3) @ExcelProperty(value = "最后跟进时间", order = 6)
@DictFormat(cn.iocoder.yudao.module.system.enums.DictTypeConstants.USER_SEX) private LocalDateTime contactLastTime;
private Integer sex;
@Schema(description = "职位") @Schema(description = "最后跟进内容")
@ExcelProperty(value = "职位", order = 3) @ExcelProperty(value = "最后跟进内容", order = 6)
private String post; private String contactLastContent;
@Schema(description = "是否关键决策人") @Schema(description = "下次联系时间")
@ExcelProperty(value = "是否关键决策人", converter = DictConvert.class, order = 3) @ExcelProperty(value = "下次联系时间", order = 6)
@DictFormat(DictTypeConstants.BOOLEAN_STRING) private LocalDateTime contactNextTime;
private Boolean master;
@Schema(description = "直属上级", example = "23457") @Schema(description = "负责人编号")
private Long parentId; private Long ownerUserId;
@Schema(description = "负责人名字", example = "25682")
@ExcelProperty("负责人名字")
private String ownerUserName;
@Schema(description = "负责人部门")
@ExcelProperty("负责人部门")
private String ownerUserDeptName;
@Schema(description = "手机号", example = "1387171766") @Schema(description = "手机号", example = "1387171766")
@ExcelProperty(value = "手机号", order = 4) @ExcelProperty(value = "手机号", order = 4)
@ -52,6 +59,10 @@ public class CrmContactRespVO {
@ExcelProperty(value = "电话", order = 4) @ExcelProperty(value = "电话", order = 4)
private String telephone; private String telephone;
@Schema(description = "电子邮箱", example = "1111@22.com")
@ExcelProperty(value = "邮箱", order = 4)
private String email;
@Schema(description = "QQ", example = "197272662") @Schema(description = "QQ", example = "197272662")
@ExcelProperty(value = "QQ", order = 4) @ExcelProperty(value = "QQ", order = 4)
private Long qq; private Long qq;
@ -60,53 +71,52 @@ public class CrmContactRespVO {
@ExcelProperty(value = "微信", order = 4) @ExcelProperty(value = "微信", order = 4)
private String wechat; private String wechat;
@Schema(description = "电子邮箱", example = "1111@22.com")
@ExcelProperty(value = "邮箱", order = 4)
private String email;
@Schema(description = "地区编号", example = "20158") @Schema(description = "地区编号", example = "20158")
private Integer areaId; private Integer areaId;
@Schema(description = "地区名", example = "上海上海市浦东新区")
@ExcelProperty(value = "地区", order = 5)
private String areaName;
@Schema(description = "地址") @Schema(description = "地址")
@ExcelProperty(value = "地址", order = 5) @ExcelProperty(value = "地址", order = 5)
private String detailAddress; private String detailAddress;
@Schema(description = "备注", example = "你说的对") @Schema(description = "性别")
@ExcelProperty(value = "备注", order = 6) @ExcelProperty(value = "性别", converter = DictConvert.class, order = 3)
private String remark; @DictFormat(cn.iocoder.yudao.module.system.enums.DictTypeConstants.USER_SEX)
private Integer sex;
@Schema(description = "负责人用户编号", example = "14334") @Schema(description = "是否关键决策人")
private Long ownerUserId; @ExcelProperty(value = "是否关键决策人", converter = DictConvert.class, order = 3)
@DictFormat(DictTypeConstants.BOOLEAN_STRING)
private Boolean master;
@Schema(description = "最后跟进时间") @Schema(description = "职位")
@ExcelProperty(value = "最后跟进时间", order = 6) @ExcelProperty(value = "职位", order = 3)
private LocalDateTime contactLastTime; private String post;
@Schema(description = "下次联系时间")
@ExcelProperty(value = "下次联系时间", order = 6)
private LocalDateTime contactNextTime;
@Schema(description = "创建人", example = "25682")
private String creator;
@Schema(description = "创建人名字", example = "test")
@ExcelProperty(value = "创建人", order = 8)
private String creatorName;
@ExcelProperty(value = "客户名称", order = 2)
@Schema(description = "客户名字", example = "test")
private String customerName;
@Schema(description = "负责人", example = "test")
@ExcelProperty(value = "负责人", order = 7)
private String ownerUserName;
@Schema(description = "直属上级", example = "23457")
private Long parentId;
@Schema(description = "直属上级名", example = "芋头") @Schema(description = "直属上级名", example = "芋头")
@ExcelProperty(value = "直属上级", order = 4) @ExcelProperty(value = "直属上级", order = 4)
private String parentName; private String parentName;
@Schema(description = "地区名", example = "上海上海市浦东新区") @Schema(description = "备注", example = "你说的对")
@ExcelProperty(value = "地区", order = 5) @ExcelProperty(value = "备注", order = 6)
private String areaName; private String remark;
@Schema(description = "创建人", example = "25682")
private String creator;
@Schema(description = "创建人名字", example = "test")
@ExcelProperty(value = "创建人", order = 8)
private String creatorName;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("创建时间")
private LocalDateTime createTime;
@Schema(description = "更新时间", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("更新时间")
private LocalDateTime updateTime;
} }

View File

@ -13,7 +13,6 @@ import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY; import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@Schema(description = "管理后台 - CRM 联系人创建/更新 Request VO") @Schema(description = "管理后台 - CRM 联系人创建/更新 Request VO")
@Data @Data
@ -31,21 +30,15 @@ public class CrmContactSaveReqVO {
@DiffLogField(name = "客户", function = CrmCustomerParseFunction.NAME) @DiffLogField(name = "客户", function = CrmCustomerParseFunction.NAME)
private Long customerId; private Long customerId;
@Schema(description = "性别") @Schema(description = "下次联系时间")
@DiffLogField(name = "性别", function = SysSexParseFunction.NAME) @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY)
private Integer sex; @DiffLogField(name = "下次联系时间")
private LocalDateTime contactNextTime;
@Schema(description = "职位") @Schema(description = "负责人用户编号", example = "14334")
@DiffLogField(name = "职位") @NotNull(message = "负责人不能为空")
private String post; @DiffLogField(name = "负责人", function = SysAdminUserParseFunction.NAME)
private Long ownerUserId;
@Schema(description = "是否关键决策人")
@DiffLogField(name = "关键决策人", function = SysBooleanParseFunction.NAME)
private Boolean master;
@Schema(description = "直属上级", example = "23457")
@DiffLogField(name = "直属上级", function = CrmContactParseFunction.NAME)
private Long parentId;
@Schema(description = "手机号", example = "1387171766") @Schema(description = "手机号", example = "1387171766")
@Mobile @Mobile
@ -78,25 +71,26 @@ public class CrmContactSaveReqVO {
@DiffLogField(name = "地址") @DiffLogField(name = "地址")
private String detailAddress; private String detailAddress;
@Schema(description = "性别")
@DiffLogField(name = "性别", function = SysSexParseFunction.NAME)
private Integer sex;
@Schema(description = "是否关键决策人")
@DiffLogField(name = "关键决策人", function = SysBooleanParseFunction.NAME)
private Boolean master;
@Schema(description = "职位")
@DiffLogField(name = "职位")
private String post;
@Schema(description = "直属上级", example = "23457")
@DiffLogField(name = "直属上级", function = CrmContactParseFunction.NAME)
private Long parentId;
@Schema(description = "备注", example = "你说的对") @Schema(description = "备注", example = "你说的对")
@DiffLogField(name = "备注") @DiffLogField(name = "备注")
private String remark; private String remark;
@Schema(description = "负责人用户编号", example = "14334")
@NotNull(message = "负责人不能为空")
@DiffLogField(name = "负责人", function = SysAdminUserParseFunction.NAME)
private Long ownerUserId;
@Schema(description = "最后跟进时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
@DiffLogField(name = "最后跟进时间")
private LocalDateTime contactLastTime;
@Schema(description = "下次联系时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY)
@DiffLogField(name = "下次联系时间")
private LocalDateTime contactNextTime;
@Schema(description = "关联商机 ID", example = "122233") @Schema(description = "关联商机 ID", example = "122233")
private Long businessId; // 注意该字段用于在商机详情界面新建联系人自动进行关联 private Long businessId; // 注意该字段用于在商机详情界面新建联系人自动进行关联

View File

@ -168,7 +168,7 @@ public class CrmContractController {
Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(convertListByFlatMap(contractList, Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(convertListByFlatMap(contractList,
contact -> Stream.of(NumberUtils.parseLong(contact.getCreator()), contact.getOwnerUserId()))); contact -> Stream.of(NumberUtils.parseLong(contact.getCreator()), contact.getOwnerUserId())));
// 3. 获取联系人 // 3. 获取联系人
Map<Long, CrmContactDO> contactMap = convertMap(contactService.getContactListByIds(convertSet(contractList, Map<Long, CrmContactDO> contactMap = convertMap(contactService.getContactList(convertSet(contractList,
CrmContractDO::getContactId)), CrmContactDO::getId); CrmContractDO::getContactId)), CrmContactDO::getId);
// 4. 获取商机 // 4. 获取商机
Map<Long, CrmBusinessDO> businessMap = convertMap(businessService.getBusinessList(convertSet(contractList, Map<Long, CrmBusinessDO> businessMap = convertMap(businessService.getBusinessList(convertSet(contractList,

View File

@ -75,7 +75,7 @@ public class CrmFollowUpRecordController {
public CommonResult<PageResult<CrmFollowUpRecordRespVO>> getFollowUpRecordPage(@Valid CrmFollowUpRecordPageReqVO pageReqVO) { public CommonResult<PageResult<CrmFollowUpRecordRespVO>> getFollowUpRecordPage(@Valid CrmFollowUpRecordPageReqVO pageReqVO) {
PageResult<CrmFollowUpRecordDO> pageResult = followUpRecordService.getFollowUpRecordPage(pageReqVO); PageResult<CrmFollowUpRecordDO> pageResult = followUpRecordService.getFollowUpRecordPage(pageReqVO);
/// 拼接数据 /// 拼接数据
Map<Long, CrmContactDO> contactMap = convertMap(contactService.getContactListByIds( Map<Long, CrmContactDO> contactMap = convertMap(contactService.getContactList(
convertSetByFlatMap(pageResult.getList(), item -> item.getContactIds().stream())), CrmContactDO::getId); convertSetByFlatMap(pageResult.getList(), item -> item.getContactIds().stream())), CrmContactDO::getId);
Map<Long, CrmBusinessDO> businessMap = convertMap(businessService.getBusinessList( Map<Long, CrmBusinessDO> businessMap = convertMap(businessService.getBusinessList(
convertSetByFlatMap(pageResult.getList(), item -> item.getBusinessIds().stream())), CrmBusinessDO::getId); convertSetByFlatMap(pageResult.getList(), item -> item.getBusinessIds().stream())), CrmBusinessDO::getId);

View File

@ -1,25 +1,16 @@
package cn.iocoder.yudao.module.crm.convert.contact; package cn.iocoder.yudao.module.crm.convert.contact;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.ip.core.utils.AreaUtils;
import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.CrmContactRespVO; import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.CrmContactRespVO;
import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.CrmContactTransferReqVO; import cn.iocoder.yudao.module.crm.controller.admin.contact.vo.CrmContactTransferReqVO;
import cn.iocoder.yudao.module.crm.dal.dataobject.contact.CrmContactDO; import cn.iocoder.yudao.module.crm.dal.dataobject.contact.CrmContactDO;
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
import cn.iocoder.yudao.module.crm.service.followup.bo.CrmUpdateFollowUpReqBO; import cn.iocoder.yudao.module.crm.service.followup.bo.CrmUpdateFollowUpReqBO;
import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionTransferReqBO; import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionTransferReqBO;
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.Mapping; import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers; import org.mapstruct.factory.Mappers;
import java.util.List; import java.util.List;
import java.util.Map;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen;
/** /**
* CRM 联系人 Convert * CRM 联系人 Convert
@ -31,42 +22,9 @@ public interface CrmContactConvert {
CrmContactConvert INSTANCE = Mappers.getMapper(CrmContactConvert.class); CrmContactConvert INSTANCE = Mappers.getMapper(CrmContactConvert.class);
CrmContactRespVO convert(CrmContactDO bean);
@Mapping(target = "bizId", source = "reqVO.id") @Mapping(target = "bizId", source = "reqVO.id")
CrmPermissionTransferReqBO convert(CrmContactTransferReqVO reqVO, Long userId); CrmPermissionTransferReqBO convert(CrmContactTransferReqVO reqVO, Long userId);
default PageResult<CrmContactRespVO> convertPage(PageResult<CrmContactDO> pageResult, Map<Long, AdminUserRespDTO> userMap,
List<CrmCustomerDO> customerList, List<CrmContactDO> parentContactList) {
PageResult<CrmContactRespVO> voPageResult = BeanUtils.toBean(pageResult, CrmContactRespVO.class);
// 拼接关联字段
Map<Long, CrmContactDO> parentContactMap = convertMap(parentContactList, CrmContactDO::getId);
Map<Long, CrmCustomerDO> customerMap = convertMap(customerList, CrmCustomerDO::getId);
voPageResult.getList().forEach(item -> {
setUserInfo(item, userMap);
findAndThen(customerMap, item.getCustomerId(), customer -> item.setCustomerName(customer.getName()));
findAndThen(parentContactMap, item.getParentId(), contactDO -> item.setParentName(contactDO.getName()));
});
return voPageResult;
}
default CrmContactRespVO convert(CrmContactDO contactDO, Map<Long, AdminUserRespDTO> userMap,
List<CrmCustomerDO> customerList, List<CrmContactDO> parentContactList) {
CrmContactRespVO contactVO = convert(contactDO);
setUserInfo(contactVO, userMap);
Map<Long, CrmCustomerDO> customerMap = CollectionUtils.convertMap(customerList, CrmCustomerDO::getId);
Map<Long, CrmContactDO> contactMap = CollectionUtils.convertMap(parentContactList, CrmContactDO::getId);
findAndThen(customerMap, contactDO.getCustomerId(), customer -> contactVO.setCustomerName(customer.getName()));
findAndThen(contactMap, contactDO.getParentId(), contact -> contactVO.setParentName(contact.getName()));
return contactVO;
}
static void setUserInfo(CrmContactRespVO contactRespVO, Map<Long, AdminUserRespDTO> userMap) {
contactRespVO.setAreaName(AreaUtils.format(contactRespVO.getAreaId()));
findAndThen(userMap, contactRespVO.getOwnerUserId(), user -> contactRespVO.setOwnerUserName(user.getNickname()));
findAndThen(userMap, Long.parseLong(contactRespVO.getCreator()), user -> contactRespVO.setCreatorName(user.getNickname()));
}
@Mapping(target = "id", source = "reqBO.bizId") @Mapping(target = "id", source = "reqBO.bizId")
CrmContactDO convert(CrmUpdateFollowUpReqBO reqBO); CrmContactDO convert(CrmUpdateFollowUpReqBO reqBO);

View File

@ -29,77 +29,16 @@ public class CrmContactDO extends BaseDO {
*/ */
@TableId @TableId
private Long id; private Long id;
/**
* 联系人姓名
*/
private String name;
/** /**
* 客户编号 * 客户编号
* *
* 关联 {@link CrmCustomerDO#getId()} * 关联 {@link CrmCustomerDO#getId()}
*/ */
private Long customerId; private Long customerId;
/**
* 手机号
*/
private String mobile;
/**
* 电话
*/
private String telephone;
/**
* 电子邮箱
*/
private String email;
/**
* 所在地
*
* 关联 {@link cn.iocoder.yudao.framework.ip.core.Area#getId()} 字段
*/
private Integer areaId;
/**
* 详细地址
*/
private String detailAddress;
/**
* 备注
*/
private String remark;
/**
* 直属上级
*
* 关联 {@link CrmContactDO#id}
*/
private Long parentId;
/**
* 姓名
*/
private String name;
/**
* 职位
*/
private String post;
/**
* QQ
*/
private Long qq;
/**
* 微信
*/
private String wechat;
/**
* 性别
*
* 枚举 {@link cn.iocoder.yudao.module.system.enums.common.SexEnum}
*/
private Integer sex;
/**
* 是否关键决策人
*/
private Boolean master;
/**
* 负责人用户编号
*
* 关联 AdminUserDO id 字段
*/
private Long ownerUserId;
/** /**
* 最后跟进时间 * 最后跟进时间
@ -114,4 +53,66 @@ public class CrmContactDO extends BaseDO {
*/ */
private LocalDateTime contactNextTime; private LocalDateTime contactNextTime;
/**
* 负责人用户编号
*
* 关联 AdminUserDO id 字段
*/
private Long ownerUserId;
/**
* 手机号
*/
private String mobile;
/**
* 电话
*/
private String telephone;
/**
* 电子邮箱
*/
private String email;
/**
* QQ
*/
private Long qq;
/**
* 微信
*/
private String wechat;
/**
* 所在地
*
* 关联 {@link cn.iocoder.yudao.framework.ip.core.Area#getId()} 字段
*/
private Integer areaId;
/**
* 详细地址
*/
private String detailAddress;
/**
* 性别
*
* 枚举 {@link cn.iocoder.yudao.module.system.enums.common.SexEnum}
*/
private Integer sex;
/**
* 是否关键决策人
*/
private Boolean master;
/**
* 职位
*/
private String post;
/**
* 直属上级
*
* 关联 {@link CrmContactDO#id}
*/
private Long parentId;
/**
* 备注
*/
private String remark;
} }

View File

@ -63,11 +63,10 @@ public interface CrmContactMapper extends BaseMapperX<CrmContactDO> {
return selectJoinPage(pageReqVO, CrmContactDO.class, query); return selectJoinPage(pageReqVO, CrmContactDO.class, query);
} }
default List<CrmContactDO> selectBatchIds(Collection<Long> ids, Long userId) { default List<CrmContactDO> selectBatchIds(Collection<Long> ids, Long ownerUserId) {
MPJLambdaWrapperX<CrmContactDO> query = new MPJLambdaWrapperX<>(); MPJLambdaWrapperX<CrmContactDO> query = new MPJLambdaWrapperX<>();
// 拼接数据权限的查询条件 // 拼接数据权限的查询条件
CrmQueryWrapperUtils.appendPermissionCondition(query, CrmBizTypeEnum.CRM_CONTACT.getType(), ids, userId); CrmQueryWrapperUtils.appendPermissionCondition(query, CrmBizTypeEnum.CRM_CONTACT.getType(), ids, ownerUserId);
// 拼接自身的查询条件
query.selectAll(CrmContactDO.class).in(CrmContactDO::getId, ids).orderByDesc(CrmContactDO::getId); query.selectAll(CrmContactDO.class).in(CrmContactDO::getId, ids).orderByDesc(CrmContactDO::getId);
return selectJoinList(CrmContactDO.class, query); return selectJoinList(CrmContactDO.class, query);
} }

View File

@ -11,6 +11,9 @@ import jakarta.validation.Valid;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
/** /**
* CRM 联系人 Service 接口 * CRM 联系人 Service 接口
@ -88,7 +91,17 @@ public interface CrmContactService {
* @param ids 编号 * @param ids 编号
* @return 联系人列表 * @return 联系人列表
*/ */
List<CrmContactDO> getContactListByIds(Collection<Long> ids); List<CrmContactDO> getContactList(Collection<Long> ids);
/**
* 获得联系人 Map
*
* @param ids 编号
* @return 联系人 Map
*/
default Map<Long, CrmContactDO> getContactMap(Collection<Long> ids) {
return convertMap(getContactList(ids), CrmContactDO::getId);
}
/** /**
* 获得联系人列表 * 获得联系人列表

View File

@ -218,7 +218,7 @@ public class CrmContactServiceImpl implements CrmContactService {
} }
@Override @Override
public List<CrmContactDO> getContactListByIds(Collection<Long> ids) { public List<CrmContactDO> getContactList(Collection<Long> ids) {
if (CollUtil.isEmpty(ids)) { if (CollUtil.isEmpty(ids)) {
return ListUtil.empty(); return ListUtil.empty();
} }

View File

@ -264,7 +264,6 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
.updateCustomerNames(new ArrayList<>()).failureCustomerNames(new LinkedHashMap<>()).build(); .updateCustomerNames(new ArrayList<>()).failureCustomerNames(new LinkedHashMap<>()).build();
importCustomers.forEach(importCustomer -> { importCustomers.forEach(importCustomer -> {
// 校验判断是否有不符合的原因 // 校验判断是否有不符合的原因
// TODO @puhui999可以用 ValidationUtils 做参数校验可能要封装一个方法返回 message这样的话就可以在 CrmCustomerImportExcelVO 写需要校验的参数啦
try { try {
validateCustomerForCreate(importCustomer); validateCustomerForCreate(importCustomer);
} catch (ServiceException ex) { } catch (ServiceException ex) {