diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/CrmContactController.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/CrmContactController.java index 766adb02d..161f10299 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/CrmContactController.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/CrmContactController.java @@ -2,24 +2,24 @@ package cn.iocoder.yudao.module.crm.controller.admin.contact; import cn.hutool.core.collection.CollUtil; 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.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.object.BeanUtils; 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.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.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.CrmContactService; 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.dto.AdminUserRespDTO; -import com.google.common.collect.Lists; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; @@ -37,12 +37,13 @@ import java.util.List; import java.util.Map; 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.PageParam.PAGE_SIZE_NONE; 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.security.core.util.SecurityFrameworkUtils.getLoginUserId; +import static java.util.Collections.singletonList; @Tag(name = "管理后台 - CRM 联系人") @RestController @@ -60,6 +61,8 @@ public class CrmContactController { @Resource private AdminUserApi adminUserApi; + @Resource + private DeptApi deptApi; @PostMapping("/create") @Operation(summary = "创建联系人") @@ -92,19 +95,14 @@ public class CrmContactController { @PreAuthorize("@ss.hasPermission('crm:contact:query')") public CommonResult getContact(@RequestParam("id") Long id) { CrmContactDO contact = contactService.getContact(id); + return success(buildContactDetail(contact)); + } + + private CrmContactRespVO buildContactDetail(CrmContactDO contact) { if (contact == null) { - throw exception(ErrorCodeConstants.CONTACT_NOT_EXISTS); + return null; } - // 1. 获取用户名 - Map userMap = adminUserApi.getUserMap(CollUtil.removeNull(Lists.newArrayList( - NumberUtil.parseLong(contact.getCreator()), contact.getOwnerUserId()))); - // 2. 获取客户信息 - List customerList = customerService.getCustomerList( - Collections.singletonList(contact.getCustomerId())); - // 3. 直属上级 - List parentContactList = contactService.getContactListByIds( - Collections.singletonList(contact.getParentId()), getLoginUserId()); - return success(CrmContactConvert.INSTANCE.convert(contact, userMap, customerList, parentContactList)); + return buildContactDetailList(singletonList(contact)).get(0); } @GetMapping("/list-by-ids") @@ -112,7 +110,8 @@ public class CrmContactController { @Parameter(name = "ids", description = "编号", required = true, example = "[1024]") @PreAuthorize("@ss.hasPermission('crm:contact:query')") public CommonResult> getContactListByIds(@RequestParam("ids") List ids) { - return success(BeanUtils.toBean(contactService.getContactListByIds(ids, getLoginUserId()), CrmContactRespVO.class)); + List list = contactService.getContactListByIds(ids, getLoginUserId()); + return success(BeanUtils.toBean(list, CrmContactRespVO.class)); } @GetMapping("/simple-all-list") @@ -129,7 +128,7 @@ public class CrmContactController { @PreAuthorize("@ss.hasPermission('crm:contact:query')") public CommonResult> getContactPage(@Valid CrmContactPageReqVO pageVO) { PageResult pageResult = contactService.getContactPage(pageVO, getLoginUserId()); - return success(buildContactDetailPage(pageResult)); + return success(new PageResult<>(buildContactDetailList(pageResult.getList()), pageResult.getTotal())); } @GetMapping("/page-by-customer") @@ -137,7 +136,7 @@ public class CrmContactController { public CommonResult> getContactPageByCustomer(@Valid CrmContactPageReqVO pageVO) { Assert.notNull(pageVO.getCustomerId(), "客户编号不能为空"); PageResult pageResult = contactService.getContactPageByCustomerId(pageVO); - return success(buildContactDetailPage(pageResult)); + return success(new PageResult<>(buildContactDetailList(pageResult.getList()), pageResult.getTotal())); } @GetMapping("/export-excel") @@ -147,32 +146,39 @@ public class CrmContactController { public void exportContactExcel(@Valid CrmContactPageReqVO exportReqVO, HttpServletResponse response) throws IOException { exportReqVO.setPageNo(PAGE_SIZE_NONE); - PageResult pageResult = contactService.getContactPage(exportReqVO, getLoginUserId()); - ExcelUtils.write(response, "联系人.xls", "数据", CrmContactRespVO.class, - buildContactDetailPage(pageResult).getList()); + List list = contactService.getContactPage(exportReqVO, getLoginUserId()).getList(); + ExcelUtils.write(response, "联系人.xls", "数据", CrmContactRespVO.class, buildContactDetailList(list)); } - /** - * 构建详细的联系人分页结果 - * - * @param pageResult 简单的联系人分页结果 - * @return 详细的联系人分页结果 - */ - private PageResult buildContactDetailPage(PageResult pageResult) { - List contactList = pageResult.getList(); + private List buildContactDetailList(List contactList) { if (CollUtil.isEmpty(contactList)) { - return PageResult.empty(pageResult.getTotal()); + return Collections.emptyList(); } - // 1. 获取客户列表 - List crmCustomerDOList = customerService.getCustomerList( + // 1.1 获取客户列表 + Map customerMap = customerService.getCustomerMap( convertSet(contactList, CrmContactDO::getCustomerId)); - // 2. 获取创建人、负责人列表 + // 1.2 获取创建人、负责人列表 Map userMap = adminUserApi.getUserMap(convertListByFlatMap(contactList, contact -> Stream.of(NumberUtils.parseLong(contact.getCreator()), contact.getOwnerUserId()))); - // 3. 直属上级 - List parentContactList = contactService.getContactListByIds( - convertSet(contactList, CrmContactDO::getParentId), getLoginUserId()); - return CrmContactConvert.INSTANCE.convertPage(pageResult, userMap, crmCustomerDOList, parentContactList); + Map deptMap = deptApi.getDeptMap(convertSet(userMap.values(), AdminUserRespDTO::getDeptId)); + // 1.3 直属上级 Map + Map parentContactMap = contactService.getContactMap( + 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") @@ -183,7 +189,7 @@ public class CrmContactController { return success(true); } - // ================== 关联/取关联系人 =================== + // ================== 关联/取关商机 =================== @PostMapping("/create-business-list") @Operation(summary = "创建联系人与商机的关联") diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/vo/CrmContactRespVO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/vo/CrmContactRespVO.java index d99ea703c..b2b1e8384 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/vo/CrmContactRespVO.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/vo/CrmContactRespVO.java @@ -20,29 +20,36 @@ public class CrmContactRespVO { @Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "3167") private Long id; - @Schema(description = "姓名", example = "芋艿") - @ExcelProperty(value = "姓名", order = 1) + @Schema(description = "联系人姓名", example = "芋艿") + @ExcelProperty(value = "联系人姓名", order = 1) private String name; @Schema(description = "客户编号", example = "10795") private Long customerId; + @ExcelProperty(value = "客户名称", order = 2) + @Schema(description = "客户名字", example = "test") + private String customerName; - @Schema(description = "性别") - @ExcelProperty(value = "性别", converter = DictConvert.class, order = 3) - @DictFormat(cn.iocoder.yudao.module.system.enums.DictTypeConstants.USER_SEX) - private Integer sex; + @Schema(description = "最后跟进时间") + @ExcelProperty(value = "最后跟进时间", order = 6) + private LocalDateTime contactLastTime; - @Schema(description = "职位") - @ExcelProperty(value = "职位", order = 3) - private String post; + @Schema(description = "最后跟进内容") + @ExcelProperty(value = "最后跟进内容", order = 6) + private String contactLastContent; - @Schema(description = "是否关键决策人") - @ExcelProperty(value = "是否关键决策人", converter = DictConvert.class, order = 3) - @DictFormat(DictTypeConstants.BOOLEAN_STRING) - private Boolean master; + @Schema(description = "下次联系时间") + @ExcelProperty(value = "下次联系时间", order = 6) + private LocalDateTime contactNextTime; - @Schema(description = "直属上级", example = "23457") - private Long parentId; + @Schema(description = "负责人编号") + private Long ownerUserId; + @Schema(description = "负责人名字", example = "25682") + @ExcelProperty("负责人名字") + private String ownerUserName; + @Schema(description = "负责人部门") + @ExcelProperty("负责人部门") + private String ownerUserDeptName; @Schema(description = "手机号", example = "1387171766") @ExcelProperty(value = "手机号", order = 4) @@ -52,6 +59,10 @@ public class CrmContactRespVO { @ExcelProperty(value = "电话", order = 4) private String telephone; + @Schema(description = "电子邮箱", example = "1111@22.com") + @ExcelProperty(value = "邮箱", order = 4) + private String email; + @Schema(description = "QQ", example = "197272662") @ExcelProperty(value = "QQ", order = 4) private Long qq; @@ -60,53 +71,52 @@ public class CrmContactRespVO { @ExcelProperty(value = "微信", order = 4) private String wechat; - @Schema(description = "电子邮箱", example = "1111@22.com") - @ExcelProperty(value = "邮箱", order = 4) - private String email; - @Schema(description = "地区编号", example = "20158") private Integer areaId; + @Schema(description = "地区名", example = "上海上海市浦东新区") + @ExcelProperty(value = "地区", order = 5) + private String areaName; @Schema(description = "地址") @ExcelProperty(value = "地址", order = 5) private String detailAddress; - @Schema(description = "备注", example = "你说的对") - @ExcelProperty(value = "备注", order = 6) - private String remark; + @Schema(description = "性别") + @ExcelProperty(value = "性别", converter = DictConvert.class, order = 3) + @DictFormat(cn.iocoder.yudao.module.system.enums.DictTypeConstants.USER_SEX) + private Integer sex; - @Schema(description = "负责人用户编号", example = "14334") - private Long ownerUserId; + @Schema(description = "是否关键决策人") + @ExcelProperty(value = "是否关键决策人", converter = DictConvert.class, order = 3) + @DictFormat(DictTypeConstants.BOOLEAN_STRING) + private Boolean master; - @Schema(description = "最后跟进时间") - @ExcelProperty(value = "最后跟进时间", order = 6) - private LocalDateTime contactLastTime; - - @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 = "职位") + @ExcelProperty(value = "职位", order = 3) + private String post; + @Schema(description = "直属上级", example = "23457") + private Long parentId; @Schema(description = "直属上级名", example = "芋头") @ExcelProperty(value = "直属上级", order = 4) private String parentName; - @Schema(description = "地区名", example = "上海上海市浦东新区") - @ExcelProperty(value = "地区", order = 5) - private String areaName; + @Schema(description = "备注", example = "你说的对") + @ExcelProperty(value = "备注", order = 6) + 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; } diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/vo/CrmContactSaveReqVO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/vo/CrmContactSaveReqVO.java index 299b1fbbb..68dcd1be5 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/vo/CrmContactSaveReqVO.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contact/vo/CrmContactSaveReqVO.java @@ -13,7 +13,6 @@ import org.springframework.format.annotation.DateTimeFormat; 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_HOUR_MINUTE_SECOND; @Schema(description = "管理后台 - CRM 联系人创建/更新 Request VO") @Data @@ -31,21 +30,15 @@ public class CrmContactSaveReqVO { @DiffLogField(name = "客户", function = CrmCustomerParseFunction.NAME) private Long customerId; - @Schema(description = "性别") - @DiffLogField(name = "性别", function = SysSexParseFunction.NAME) - private Integer sex; + @Schema(description = "下次联系时间") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY) + @DiffLogField(name = "下次联系时间") + private LocalDateTime contactNextTime; - @Schema(description = "职位") - @DiffLogField(name = "职位") - private String post; - - @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 = "14334") + @NotNull(message = "负责人不能为空") + @DiffLogField(name = "负责人", function = SysAdminUserParseFunction.NAME) + private Long ownerUserId; @Schema(description = "手机号", example = "1387171766") @Mobile @@ -78,25 +71,26 @@ public class CrmContactSaveReqVO { @DiffLogField(name = "地址") 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 = "你说的对") @DiffLogField(name = "备注") 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") private Long businessId; // 注意:该字段用于在【商机】详情界面「新建联系人」时,自动进行关联 diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contract/CrmContractController.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contract/CrmContractController.java index 3951d1ebd..ef0aa849a 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contract/CrmContractController.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contract/CrmContractController.java @@ -168,7 +168,7 @@ public class CrmContractController { Map userMap = adminUserApi.getUserMap(convertListByFlatMap(contractList, contact -> Stream.of(NumberUtils.parseLong(contact.getCreator()), contact.getOwnerUserId()))); // 3. 获取联系人 - Map contactMap = convertMap(contactService.getContactListByIds(convertSet(contractList, + Map contactMap = convertMap(contactService.getContactList(convertSet(contractList, CrmContractDO::getContactId)), CrmContactDO::getId); // 4. 获取商机 Map businessMap = convertMap(businessService.getBusinessList(convertSet(contractList, diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/followup/CrmFollowUpRecordController.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/followup/CrmFollowUpRecordController.java index f0b726353..735f2e887 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/followup/CrmFollowUpRecordController.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/followup/CrmFollowUpRecordController.java @@ -75,7 +75,7 @@ public class CrmFollowUpRecordController { public CommonResult> getFollowUpRecordPage(@Valid CrmFollowUpRecordPageReqVO pageReqVO) { PageResult pageResult = followUpRecordService.getFollowUpRecordPage(pageReqVO); /// 拼接数据 - Map contactMap = convertMap(contactService.getContactListByIds( + Map contactMap = convertMap(contactService.getContactList( convertSetByFlatMap(pageResult.getList(), item -> item.getContactIds().stream())), CrmContactDO::getId); Map businessMap = convertMap(businessService.getBusinessList( convertSetByFlatMap(pageResult.getList(), item -> item.getBusinessIds().stream())), CrmBusinessDO::getId); diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/convert/contact/CrmContactConvert.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/convert/contact/CrmContactConvert.java index 5fd2afa67..77f4dec93 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/convert/contact/CrmContactConvert.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/convert/contact/CrmContactConvert.java @@ -1,25 +1,16 @@ 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.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.CrmContactTransferReqVO; 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.permission.bo.CrmPermissionTransferReqBO; -import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.factory.Mappers; 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 @@ -31,42 +22,9 @@ public interface CrmContactConvert { CrmContactConvert INSTANCE = Mappers.getMapper(CrmContactConvert.class); - CrmContactRespVO convert(CrmContactDO bean); - @Mapping(target = "bizId", source = "reqVO.id") CrmPermissionTransferReqBO convert(CrmContactTransferReqVO reqVO, Long userId); - default PageResult convertPage(PageResult pageResult, Map userMap, - List customerList, List parentContactList) { - PageResult voPageResult = BeanUtils.toBean(pageResult, CrmContactRespVO.class); - // 拼接关联字段 - Map parentContactMap = convertMap(parentContactList, CrmContactDO::getId); - Map 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 userMap, - List customerList, List parentContactList) { - CrmContactRespVO contactVO = convert(contactDO); - setUserInfo(contactVO, userMap); - Map customerMap = CollectionUtils.convertMap(customerList, CrmCustomerDO::getId); - Map 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 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") CrmContactDO convert(CrmUpdateFollowUpReqBO reqBO); diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/dataobject/contact/CrmContactDO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/dataobject/contact/CrmContactDO.java index c2dec247d..5a891eb9c 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/dataobject/contact/CrmContactDO.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/dataobject/contact/CrmContactDO.java @@ -29,77 +29,16 @@ public class CrmContactDO extends BaseDO { */ @TableId private Long id; + /** + * 联系人姓名 + */ + private String name; /** * 客户编号 * * 关联 {@link CrmCustomerDO#getId()} */ 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; + /** + * 负责人用户编号 + * + * 关联 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; + } diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/contact/CrmContactMapper.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/contact/CrmContactMapper.java index c35df47d3..c254601d0 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/contact/CrmContactMapper.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/dal/mysql/contact/CrmContactMapper.java @@ -63,11 +63,10 @@ public interface CrmContactMapper extends BaseMapperX { return selectJoinPage(pageReqVO, CrmContactDO.class, query); } - default List selectBatchIds(Collection ids, Long userId) { + default List selectBatchIds(Collection ids, Long ownerUserId) { MPJLambdaWrapperX 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); return selectJoinList(CrmContactDO.class, query); } diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contact/CrmContactService.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contact/CrmContactService.java index d7688b8fb..978986180 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contact/CrmContactService.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contact/CrmContactService.java @@ -11,6 +11,9 @@ import jakarta.validation.Valid; import java.util.Collection; import java.util.List; +import java.util.Map; + +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; /** * CRM 联系人 Service 接口 @@ -88,7 +91,17 @@ public interface CrmContactService { * @param ids 编号 * @return 联系人列表 */ - List getContactListByIds(Collection ids); + List getContactList(Collection ids); + + /** + * 获得联系人 Map + * + * @param ids 编号 + * @return 联系人 Map + */ + default Map getContactMap(Collection ids) { + return convertMap(getContactList(ids), CrmContactDO::getId); + } /** * 获得联系人列表 diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contact/CrmContactServiceImpl.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contact/CrmContactServiceImpl.java index 08ce78b81..db7fe90bf 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contact/CrmContactServiceImpl.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/contact/CrmContactServiceImpl.java @@ -218,7 +218,7 @@ public class CrmContactServiceImpl implements CrmContactService { } @Override - public List getContactListByIds(Collection ids) { + public List getContactList(Collection ids) { if (CollUtil.isEmpty(ids)) { return ListUtil.empty(); } diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerServiceImpl.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerServiceImpl.java index d98edce24..06c58386b 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerServiceImpl.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerServiceImpl.java @@ -264,7 +264,6 @@ public class CrmCustomerServiceImpl implements CrmCustomerService { .updateCustomerNames(new ArrayList<>()).failureCustomerNames(new LinkedHashMap<>()).build(); importCustomers.forEach(importCustomer -> { // 校验,判断是否有不符合的原因 - // TODO @puhui999:可以用 ValidationUtils 做参数校验;可能要封装一个方法,返回 message;这样的话,就可以在 CrmCustomerImportExcelVO 写需要校验的参数啦; try { validateCustomerForCreate(importCustomer); } catch (ServiceException ex) {