From dddc473c582e983674913163dd4e93f840effbdb Mon Sep 17 00:00:00 2001
From: liu <2021943741@qq.com>
Date: 星期一, 26 十月 2026 10:54:55 +0800
Subject: [PATCH] fix(search): 修复多处搜索条件未生效的问题
---
yudao-module-crm/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/business/CrmBusinessController.java | 95 ++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 84 insertions(+), 11 deletions(-)
diff --git a/yudao-module-crm/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/business/CrmBusinessController.java b/yudao-module-crm/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/business/CrmBusinessController.java
index 33e8d84..2051fdd 100644
--- a/yudao-module-crm/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/business/CrmBusinessController.java
+++ b/yudao-module-crm/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/business/CrmBusinessController.java
@@ -14,11 +14,13 @@
import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessStatusDO;
import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessStatusTypeDO;
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.CrmBusinessService;
import cn.iocoder.yudao.module.crm.service.business.CrmBusinessStatusService;
import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerService;
-import cn.iocoder.yudao.module.crm.service.product.CrmProductService;
+import cn.iocoder.yudao.module.mdm.api.item.MdmItemApi;
+import cn.iocoder.yudao.module.mdm.api.item.dto.MdmItemRespDTO;
+import cn.iocoder.yudao.module.mdm.api.unit.MdmUnitMeasureApi;
+import cn.iocoder.yudao.module.mdm.api.unit.dto.MdmUnitMeasureRespDTO;
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;
@@ -34,9 +36,7 @@
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.*;
import java.util.stream.Stream;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
@@ -62,7 +62,9 @@
@Resource
private CrmBusinessStatusService businessStatusService;
@Resource
- private CrmProductService productService;
+ private MdmItemApi mdmItemApi;
+ @Resource
+ private MdmUnitMeasureApi mdmUnitMeasureApi;
@Resource
private AdminUserApi adminUserApi;
@@ -117,12 +119,42 @@
CrmBusinessRespVO businessVO = buildBusinessDetailList(Collections.singletonList(business)).get(0);
// 鎷兼帴浜у搧椤�
List<CrmBusinessProductDO> businessProducts = businessService.getBusinessProductListByBusinessId(businessVO.getId());
- Map<Long, CrmProductDO> productMap = productService.getProductMap(
- convertSet(businessProducts, CrmBusinessProductDO::getProductId));
+ Map<Long, MdmItemRespDTO> itemMap = mdmItemApi.getItemMap(
+ convertSet(businessProducts, CrmBusinessProductDO::getItemId));
+ // 鏀堕泦鎵�鏈夐渶瑕佹煡璇㈢殑鍗曚綅ID锛堜富鍗曚綅 + 杈呭崟浣�1 + 杈呭崟浣�2锛�
+ Set<Long> unitIds = new HashSet<>();
+ unitIds.addAll(convertSet(businessProducts, CrmBusinessProductDO::getItemUnitId));
+ itemMap.values().forEach(item -> {
+ if (item.getUnitMeasureId2() != null) {
+ unitIds.add(item.getUnitMeasureId2());
+ }
+ if (item.getUnitMeasureId3() != null) {
+ unitIds.add(item.getUnitMeasureId3());
+ }
+ });
+ Map<Long, MdmUnitMeasureRespDTO> unitMap = mdmUnitMeasureApi.getUnitMeasureMap(unitIds);
businessVO.setProducts(BeanUtils.toBean(businessProducts, CrmBusinessRespVO.Product.class, businessProductVO ->
- MapUtils.findAndThen(productMap, businessProductVO.getProductId(),
- product -> businessProductVO.setProductName(product.getName())
- .setProductNo(product.getNo()).setProductUnit(product.getUnit()))));
+ MapUtils.findAndThen(itemMap, businessProductVO.getItemId(),
+ item -> businessProductVO.setItemName(item.getName())
+ .setItemCode(item.getCode())
+ .setBarCode(item.getBarCode())
+ .setItemSpecification(item.getSpecification()))));
+ // 濉厖鍗曚綅鍚嶇О锛堜富鍗曚綅 + 杈呭崟浣�1 + 杈呭崟浣�2锛�
+ businessVO.getProducts().forEach(product -> {
+ MapUtils.findAndThen(unitMap, product.getItemUnitId(),
+ unit -> product.setItemUnitName(unit.getName()));
+ // 濉厖杈呭崟浣嶅悕绉�
+ MapUtils.findAndThen(itemMap, product.getItemId(), item -> {
+ if (item.getUnitMeasureId2() != null) {
+ MapUtils.findAndThen(unitMap, item.getUnitMeasureId2(),
+ unit -> product.setItemUnitName2(unit.getName()));
+ }
+ if (item.getUnitMeasureId3() != null) {
+ MapUtils.findAndThen(unitMap, item.getUnitMeasureId3(),
+ unit -> product.setItemUnitName3(unit.getName()));
+ }
+ });
+ });
return businessVO;
}
@@ -136,6 +168,26 @@
return success(convertList(pageResult.getList(), business -> // 鍙繑鍥� id銆乶ame 瀛楁
new CrmBusinessRespVO().setId(business.getId()).setName(business.getName())
.setCustomerId(business.getCustomerId())));
+ }
+
+ @GetMapping("/list-by-customer")
+ @Operation(summary = "鑾峰緱鍟嗘満鍒楄〃锛屽熀浜庢寚瀹氬鎴�")
+ @Parameter(name = "customerId", description = "瀹㈡埛缂栧彿", required = true)
+ @PreAuthorize("@ss.hasPermission('crm:business:query')")
+ public CommonResult<List<CrmBusinessRespVO>> getBusinessListByCustomer(@RequestParam("customerId") Long customerId) {
+ List<CrmBusinessDO> list = businessService.getBusinessListByCustomerId(customerId);
+ return success(convertList(list, business -> // 鍙繑鍥� id銆乶ame 瀛楁
+ new CrmBusinessRespVO().setId(business.getId()).setName(business.getName())
+ .setCustomerId(business.getCustomerId())));
+ }
+
+ @GetMapping("/list-by-contact")
+ @Operation(summary = "鑾峰緱鍟嗘満鍒楄〃锛屽熀浜庢寚瀹氳仈绯讳汉")
+ @Parameter(name = "contactId", description = "鑱旂郴浜虹紪鍙�", required = true)
+ @PreAuthorize("@ss.hasPermission('crm:business:query')")
+ public CommonResult<List<CrmBusinessRespVO>> getBusinessListByContact(@RequestParam("contactId") Long contactId) {
+ List<CrmBusinessDO> list = businessService.getBusinessListByContact(contactId);
+ return success(buildBusinessDetailList(list));
}
@GetMapping("/page")
@@ -177,6 +229,27 @@
buildBusinessDetailList(list));
}
+ @GetMapping("/get-import-template")
+ @Operation(summary = "鑾峰緱瀵煎叆鍟嗘満妯℃澘")
+ public void importTemplate(HttpServletResponse response) throws IOException {
+ // 鎵嬪姩鍒涘缓瀵煎嚭 demo
+ List<CrmBusinessImportExcelVO> list = Arrays.asList(
+ CrmBusinessImportExcelVO.builder().name("绀轰緥鍟嗘満").customerName("绀轰緥瀹㈡埛")
+ .dealTime(null).totalProductPrice(null).discountPercent(null).totalPrice(null).remark("").build()
+ );
+ // 杈撳嚭
+ ExcelUtils.write(response, "鍟嗘満瀵煎叆妯℃澘.xls", "鍟嗘満鍒楄〃", CrmBusinessImportExcelVO.class, list);
+ }
+
+ @PostMapping("/import")
+ @Operation(summary = "瀵煎叆鍟嗘満")
+ @PreAuthorize("@ss.hasPermission('crm:business:import')")
+ public CommonResult<CrmBusinessImportRespVO> importExcel(@Valid CrmBusinessImportReqVO importReqVO)
+ throws Exception {
+ List<CrmBusinessImportExcelVO> list = ExcelUtils.read(importReqVO.getFile(), CrmBusinessImportExcelVO.class);
+ return success(businessService.importBusinessList(list, importReqVO));
+ }
+
public List<CrmBusinessRespVO> buildBusinessDetailList(List<CrmBusinessDO> list) {
if (CollUtil.isEmpty(list)) {
return Collections.emptyList();
--
Gitblit v1.9.3