From 53badfc3673d97beb6ee7dafa7bdc78659e202ca Mon Sep 17 00:00:00 2001 From: puhui999 Date: Sat, 3 Feb 2024 20:49:13 +0800 Subject: [PATCH] =?UTF-8?q?CRM-CONTRACT:=20=E5=AE=8C=E5=96=84=E5=90=88?= =?UTF-8?q?=E5=90=8C=E7=BC=96=E8=BE=91=E5=9B=9E=E6=98=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/business/CrmBusinessController.java | 4 +- .../admin/clue/CrmClueController.java | 4 +- .../admin/contact/CrmContactController.java | 10 ++--- .../admin/contract/CrmContractController.java | 45 +++++++++++++------ .../admin/contract/vo/CrmContractRespVO.java | 16 +++++-- .../admin/customer/CrmCustomerController.java | 4 +- .../followup/CrmFollowUpRecordController.java | 2 +- .../convert/contract/CrmContractConvert.java | 17 ++++--- .../service/contact/CrmContactService.java | 4 +- .../contact/CrmContactServiceImpl.java | 4 +- 10 files changed, 70 insertions(+), 40 deletions(-) diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/business/CrmBusinessController.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/business/CrmBusinessController.java index 90b00dd48..85fe5b3f3 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/business/CrmBusinessController.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/business/CrmBusinessController.java @@ -166,10 +166,10 @@ public class CrmBusinessController { return CrmBusinessConvert.INSTANCE.convertPage(pageResult, customerList, statusTypeList, statusList); } - @PutMapping("/transfer") + @PutMapping("/transfer-business") @Operation(summary = "商机转移") @PreAuthorize("@ss.hasPermission('crm:business:update')") - public CommonResult transfer(@Valid @RequestBody CrmBusinessTransferReqVO reqVO) { + public CommonResult transferBusiness(@Valid @RequestBody CrmBusinessTransferReqVO reqVO) { businessService.transferBusiness(reqVO, getLoginUserId()); return success(true); } diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/clue/CrmClueController.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/clue/CrmClueController.java index dca364cba..a2ddf3742 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/clue/CrmClueController.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/clue/CrmClueController.java @@ -88,10 +88,10 @@ public class CrmClueController { ExcelUtils.write(response, "线索.xls", "数据", CrmClueRespVO.class, datas); } - @PutMapping("/transfer") + @PutMapping("/transfer-clue") @Operation(summary = "线索转移") @PreAuthorize("@ss.hasPermission('crm:clue:update')") - public CommonResult transfer(@Valid @RequestBody CrmClueTransferReqVO reqVO) { + public CommonResult transferClue(@Valid @RequestBody CrmClueTransferReqVO reqVO) { clueService.transferClue(reqVO, getLoginUserId()); return success(true); } 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 e3998834d..c00d57a6c 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 @@ -102,7 +102,7 @@ public class CrmContactController { List customerList = customerService.getCustomerList( Collections.singletonList(contact.getCustomerId())); // 3. 直属上级 - List parentContactList = contactService.getContactList( + List parentContactList = contactService.getContactListByIds( Collections.singletonList(contact.getParentId()), getLoginUserId()); return success(CrmContactConvert.INSTANCE.convert(contact, userMap, customerList, parentContactList)); } @@ -112,7 +112,7 @@ 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.getContactList(ids, getLoginUserId()), CrmContactRespVO.class)); + return success(BeanUtils.toBean(contactService.getContactListByIds(ids, getLoginUserId()), CrmContactRespVO.class)); } @GetMapping("/simple-all-list") @@ -170,15 +170,15 @@ public class CrmContactController { Map userMap = adminUserApi.getUserMap(convertListByFlatMap(contactList, contact -> Stream.of(NumberUtils.parseLong(contact.getCreator()), contact.getOwnerUserId()))); // 3. 直属上级 - List parentContactList = contactService.getContactList( + List parentContactList = contactService.getContactListByIds( convertSet(contactList, CrmContactDO::getParentId), getLoginUserId()); return CrmContactConvert.INSTANCE.convertPage(pageResult, userMap, crmCustomerDOList, parentContactList); } - @PutMapping("/transfer") + @PutMapping("/transfer-contact") @Operation(summary = "联系人转移") @PreAuthorize("@ss.hasPermission('crm:contact:update')") - public CommonResult transfer(@Valid @RequestBody CrmContactTransferReqVO reqVO) { + public CommonResult transferContact(@Valid @RequestBody CrmContactTransferReqVO reqVO) { contactService.transferContact(reqVO, getLoginUserId()); return success(true); } 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 e6180d83d..43bd49ea2 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 @@ -10,11 +10,15 @@ 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.contract.vo.*; import cn.iocoder.yudao.module.crm.convert.contract.CrmContractConvert; +import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessDO; import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessProductDO; +import cn.iocoder.yudao.module.crm.dal.dataobject.contact.CrmContactDO; import cn.iocoder.yudao.module.crm.dal.dataobject.contract.CrmContractDO; import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO; import cn.iocoder.yudao.module.crm.dal.dataobject.product.CrmProductDO; import cn.iocoder.yudao.module.crm.service.business.CrmBusinessProductService; +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.contract.CrmContractService; import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerService; import cn.iocoder.yudao.module.crm.service.product.CrmProductService; @@ -26,11 +30,13 @@ import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.annotation.Resource; import jakarta.servlet.http.HttpServletResponse; import jakarta.validation.Valid; +import org.springframework.context.annotation.Lazy; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import java.io.IOException; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.stream.Stream; @@ -52,6 +58,11 @@ public class CrmContractController { @Resource private CrmCustomerService customerService; @Resource + private CrmContactService contactService; + @Resource + private CrmBusinessService businessService; + @Resource + @Lazy private CrmBusinessProductService businessProductService; @Resource private CrmProductService productService; @@ -89,7 +100,8 @@ public class CrmContractController { @PreAuthorize("@ss.hasPermission('crm:contract:query')") public CommonResult getContract(@RequestParam("id") Long id) { CrmContractDO contract = contractService.getContract(id); - CrmContractRespVO respVO = BeanUtils.toBean(contract, CrmContractRespVO.class); + List respVOList = buildContractDetail(Collections.singletonList(contract)); + CrmContractRespVO respVO = respVOList.getFirst(); List businessProductList = businessProductService.getBusinessProductListByContractId(id); Map businessProductMap = convertMap(businessProductList, CrmBusinessProductDO::getProductId); List productList = productService.getProductListByIds(convertSet(businessProductList, CrmBusinessProductDO::getProductId)); @@ -108,15 +120,15 @@ public class CrmContractController { @PreAuthorize("@ss.hasPermission('crm:contract:query')") public CommonResult> getContractPage(@Valid CrmContractPageReqVO pageVO) { PageResult pageResult = contractService.getContractPage(pageVO, getLoginUserId()); - return success(buildContractDetailPage(pageResult)); + return success(BeanUtils.toBean(pageResult, CrmContractRespVO.class).setList(buildContractDetail(pageResult.getList()))); } @GetMapping("/page-by-customer") - @Operation(summary = "获得联系人分页,基于指定客户") + @Operation(summary = "获得合同分页,基于指定客户") public CommonResult> getContractPageByCustomer(@Valid CrmContractPageReqVO pageVO) { Assert.notNull(pageVO.getCustomerId(), "客户编号不能为空"); PageResult pageResult = contractService.getContractPageByCustomerId(pageVO); - return success(buildContractDetailPage(pageResult)); + return success(BeanUtils.toBean(pageResult, CrmContractRespVO.class).setList(buildContractDetail(pageResult.getList()))); } @GetMapping("/export-excel") @@ -132,23 +144,28 @@ public class CrmContractController { } /** - * 构建详细的合同分页结果 + * 构建详细的合同结果 * - * @param pageResult 简单的合同分页结果 - * @return 详细的合同分页结果 + * @param contractList 原始合同信息 + * @return 细的合同结果 */ - private PageResult buildContractDetailPage(PageResult pageResult) { - List contactList = pageResult.getList(); - if (CollUtil.isEmpty(contactList)) { - return PageResult.empty(pageResult.getTotal()); + private List buildContractDetail(List contractList) { + if (CollUtil.isEmpty(contractList)) { + return Collections.emptyList(); } // 1. 获取客户列表 List customerList = customerService.getCustomerList( - convertSet(contactList, CrmContractDO::getCustomerId)); + convertSet(contractList, CrmContractDO::getCustomerId)); // 2. 获取创建人、负责人列表 - Map userMap = adminUserApi.getUserMap(convertListByFlatMap(contactList, + Map userMap = adminUserApi.getUserMap(convertListByFlatMap(contractList, contact -> Stream.of(NumberUtils.parseLong(contact.getCreator()), contact.getOwnerUserId()))); - return CrmContractConvert.INSTANCE.convertPage(pageResult, userMap, customerList); + // 3. 获取联系人 + Map contactMap = convertMap(contactService.getContactListByIds(convertSet(contractList, + CrmContractDO::getContactId)), CrmContactDO::getId); + // 4. 获取商机 + Map businessMap = convertMap(businessService.getBusinessList(convertSet(contractList, + CrmContractDO::getBusinessId)), CrmBusinessDO::getId); + return CrmContractConvert.INSTANCE.convertList(contractList, userMap, customerList, contactMap, businessMap); } @PutMapping("/transfer-contract") diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contract/vo/CrmContractRespVO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contract/vo/CrmContractRespVO.java index 9e6c39a3a..238789794 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contract/vo/CrmContractRespVO.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/contract/vo/CrmContractRespVO.java @@ -29,10 +29,16 @@ public class CrmContractRespVO { @Schema(description = "客户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "18336") @ExcelProperty("客户编号") private Long customerId; + @Schema(description = "客户名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "18336") + @ExcelProperty("客户名称") + private String customerName; @Schema(description = "商机编号", example = "10864") @ExcelProperty("商机编号") private Long businessId; + @Schema(description = "商机名称", example = "10864") + @ExcelProperty("商机名称") + private String businessName; @Schema(description = "工作流编号", example = "1043") @ExcelProperty("工作流编号") @@ -77,10 +83,16 @@ public class CrmContractRespVO { @Schema(description = "联系人编号", example = "18546") @ExcelProperty("联系人编号") private Long contactId; + @Schema(description = "联系人编号", example = "18546") + @ExcelProperty("联系人编号") + private String contactName; @Schema(description = "公司签约人", example = "14036") @ExcelProperty("公司签约人") private Long signUserId; + @Schema(description = "公司签约人", example = "14036") + @ExcelProperty("公司签约人") + private String signUserName; @Schema(description = "最后跟进时间") @ExcelProperty("最后跟进时间") @@ -104,10 +116,6 @@ public class CrmContractRespVO { @ExcelProperty("创建人名字") private String creatorName; - @Schema(description = "客户名字", example = "test") - @ExcelProperty("客户名字") - private String customerName; - @Schema(description = "负责人", example = "test") @ExcelProperty("负责人") private String ownerUserName; diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/CrmCustomerController.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/CrmCustomerController.java index 09057fd78..d8c2f0289 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/CrmCustomerController.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/CrmCustomerController.java @@ -232,10 +232,10 @@ public class CrmCustomerController { return success(customerService.importCustomerList(list, updateSupport, getLoginUserId())); } - @PutMapping("/transfer") + @PutMapping("/transfer-customer") @Operation(summary = "转移客户") @PreAuthorize("@ss.hasPermission('crm:customer:update')") - public CommonResult transfer(@Valid @RequestBody CrmCustomerTransferReqVO reqVO) { + public CommonResult transferCustomer(@Valid @RequestBody CrmCustomerTransferReqVO reqVO) { customerService.transferCustomer(reqVO, getLoginUserId()); return success(true); } 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 735f2e887..f0b726353 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.getContactList( + Map contactMap = convertMap(contactService.getContactListByIds( 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/contract/CrmContractConvert.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/convert/contract/CrmContractConvert.java index 599d998a6..c9247e6a5 100644 --- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/convert/contract/CrmContractConvert.java +++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/convert/contract/CrmContractConvert.java @@ -1,9 +1,10 @@ package cn.iocoder.yudao.module.crm.convert.contract; -import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.CrmContractRespVO; import cn.iocoder.yudao.module.crm.controller.admin.contract.vo.CrmContractTransferReqVO; +import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessDO; +import cn.iocoder.yudao.module.crm.dal.dataobject.contact.CrmContactDO; import cn.iocoder.yudao.module.crm.dal.dataobject.contract.CrmContractDO; import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO; import cn.iocoder.yudao.module.crm.service.permission.bo.CrmPermissionTransferReqBO; @@ -31,17 +32,21 @@ public interface CrmContractConvert { @Mapping(target = "bizId", source = "reqVO.id") CrmPermissionTransferReqBO convert(CrmContractTransferReqVO reqVO, Long userId); - default PageResult convertPage(PageResult pageResult, Map userMap, - List customerList) { - PageResult voPageResult = BeanUtils.toBean(pageResult, CrmContractRespVO.class); + default List convertList(List contractList, Map userMap, + List customerList, Map contactMap, + Map businessMap) { + List respVOList = BeanUtils.toBean(contractList, CrmContractRespVO.class); // 拼接关联字段 Map customerMap = convertMap(customerList, CrmCustomerDO::getId); - voPageResult.getList().forEach(contract -> { + respVOList.forEach(contract -> { findAndThen(userMap, contract.getOwnerUserId(), user -> contract.setOwnerUserName(user.getNickname())); findAndThen(userMap, Long.parseLong(contract.getCreator()), user -> contract.setCreatorName(user.getNickname())); + findAndThen(userMap, contract.getSignUserId(), user -> contract.setSignUserName(user.getNickname())); findAndThen(customerMap, contract.getCustomerId(), customer -> contract.setCustomerName(customer.getName())); + findAndThen(contactMap, contract.getContactId(), contact -> contract.setContactName(contact.getName())); + findAndThen(businessMap, contract.getBusinessId(), business -> contract.setBusinessName(business.getName())); }); - return voPageResult; + return respVOList; } } 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 a43ed2e65..d7688b8fb 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 @@ -80,7 +80,7 @@ public interface CrmContactService { * @param userId 用户编号 * @return 联系人列表 */ - List getContactList(Collection ids, Long userId); + List getContactListByIds(Collection ids, Long userId); /** * 获得联系人列表 @@ -88,7 +88,7 @@ public interface CrmContactService { * @param ids 编号 * @return 联系人列表 */ - List getContactList(Collection ids); + List getContactListByIds(Collection ids); /** * 获得联系人列表 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 4c1a7fd95..08ce78b81 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 @@ -210,7 +210,7 @@ public class CrmContactServiceImpl implements CrmContactService { } @Override - public List getContactList(Collection ids, Long userId) { + public List getContactListByIds(Collection ids, Long userId) { if (CollUtil.isEmpty(ids)) { return ListUtil.empty(); } @@ -218,7 +218,7 @@ public class CrmContactServiceImpl implements CrmContactService { } @Override - public List getContactList(Collection ids) { + public List getContactListByIds(Collection ids) { if (CollUtil.isEmpty(ids)) { return ListUtil.empty(); }