hsy
4 天以前 bb0b80bd7ca7c1f979ab0125ae01f3faa1d14f4b
yudao-module-crm/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/quotation/CrmSaleQuotationController.java
@@ -13,7 +13,9 @@
import cn.iocoder.yudao.module.crm.controller.admin.quotation.vo.CrmSaleQuotationSaveReqVO;
import cn.iocoder.yudao.module.crm.dal.dataobject.quotation.CrmSaleQuotationDO;
import cn.iocoder.yudao.module.crm.dal.dataobject.quotation.CrmSaleQuotationProductDO;
import cn.iocoder.yudao.module.crm.dal.dataobject.business.CrmBusinessDO;
import cn.iocoder.yudao.module.crm.dal.dataobject.customer.CrmCustomerDO;
import cn.iocoder.yudao.module.crm.service.business.CrmBusinessService;
import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerService;
import cn.iocoder.yudao.module.crm.service.quotation.CrmSaleQuotationService;
import cn.iocoder.yudao.module.mdm.api.item.MdmItemApi;
@@ -66,6 +68,8 @@
    private MdmUnitMeasureApi mdmUnitMeasureApi;
    @Resource
    private CrmCustomerService customerService;
    @Resource
    private CrmBusinessService businessService;
    @Resource
    private StorageAttachmentApi storageAttachmentApi;
@@ -157,9 +161,14 @@
        // 1. 构建物料明细
        if (CollUtil.isNotEmpty(productList)) {
            Map<Long, MdmItemRespDTO> itemMap = mdmItemApi.getItemMap(convertSet(productList, CrmSaleQuotationProductDO::getItemId));
            java.util.Set<Long> unitIds = new java.util.HashSet<>(convertSet(productList, CrmSaleQuotationProductDO::getItemUnitId));
            itemMap.values().forEach(item -> {
                if (item.getUnitMeasureId2() != null) {
                    unitIds.add(item.getUnitMeasureId2());
                }
            });
            Map<Long, MdmUnitMeasureRespDTO> unitMap = convertMap(
                    mdmUnitMeasureApi.getUnitMeasureList(
                            convertSet(productList, CrmSaleQuotationProductDO::getItemUnitId)).getCheckedData(),
                    mdmUnitMeasureApi.getUnitMeasureList(unitIds).getCheckedData(),
                    MdmUnitMeasureRespDTO::getId);
            respVO.setItems(BeanUtils.toBean(productList, CrmSaleQuotationRespVO.Item.class, item -> {
                MdmItemRespDTO mdmItem = itemMap.get(item.getItemId());
@@ -167,8 +176,13 @@
                    item.setItemCode(mdmItem.getCode());
                    item.setItemName(mdmItem.getName());
                    item.setItemBarCode(mdmItem.getBarCode());
                    item.setItemSpecification(mdmItem.getSpecification());
                    item.setItemUnitId2(mdmItem.getUnitMeasureId2());
                    item.setItemUnitId3(mdmItem.getUnitMeasureId3());
                }
                MapUtils.findAndThen(unitMap, item.getItemUnitId(), unit -> item.setItemUnitName(unit.getName()));
                MapUtils.findAndThen(unitMap, item.getItemUnitId2(), unit -> item.setItemUnitName2(unit.getName()));
                MapUtils.findAndThen(unitMap, item.getItemUnitId3(), unit -> item.setItemUnitName3(unit.getName()));
            }));
        }
        // 2. 填充客户名称
@@ -176,6 +190,13 @@
            CrmCustomerDO customer = customerService.getCustomer(saleQuotation.getCustomerId());
            if (customer != null) {
                respVO.setCustomerName(customer.getName());
            }
        }
        // 2.1 填充商机名称
        if (saleQuotation.getBusinessId() != null) {
            CrmBusinessDO business = businessService.getBusiness(saleQuotation.getBusinessId());
            if (business != null) {
                respVO.setBusinessName(business.getName());
            }
        }
        // 3. 填充关联信息
@@ -195,6 +216,15 @@
        Map<Long, List<CrmSaleQuotationProductDO>> productMap = convertMultiMap(productList, CrmSaleQuotationProductDO::getQuotationId);
        // 1.2 物料信息
        Map<Long, MdmItemRespDTO> itemMap = mdmItemApi.getItemMap(convertSet(productList, CrmSaleQuotationProductDO::getItemId));
        java.util.Set<Long> unitIds = new java.util.HashSet<>(convertSet(productList, CrmSaleQuotationProductDO::getItemUnitId));
        itemMap.values().forEach(item -> {
            if (item.getUnitMeasureId2() != null) {
                unitIds.add(item.getUnitMeasureId2());
            }
        });
        Map<Long, MdmUnitMeasureRespDTO> unitMap = convertMap(
                mdmUnitMeasureApi.getUnitMeasureList(unitIds).getCheckedData(),
                MdmUnitMeasureRespDTO::getId);
        // 1.3 客户信息
        Map<Long, CrmCustomerDO> customerMap = customerService.getCustomerMap(
                convertSet(pageResult.getList(), CrmSaleQuotationDO::getCustomerId));
@@ -204,15 +234,29 @@
        // 1.5 部门信息
        Map<Long, DeptRespDTO> deptMap = deptApi.getDeptMap(
                convertSet(pageResult.getList(), CrmSaleQuotationDO::getOwnerUserId));
        // 1.6 商机信息(过滤 null,businessId 为可选字段)
        Map<Long, CrmBusinessDO> businessMap = businessService.getBusinessMap(
                convertSet(pageResult.getList(), CrmSaleQuotationDO::getBusinessId, vo -> vo.getBusinessId() != null));
        // 2. 开始拼接
        return BeanUtils.toBean(pageResult, CrmSaleQuotationRespVO.class, vo -> {
            vo.setItems(BeanUtils.toBean(productMap.get(vo.getId()), CrmSaleQuotationRespVO.Item.class,
                    item -> MapUtils.findAndThen(itemMap, item.getItemId(), mdmItem -> item.setItemCode(mdmItem.getCode())
                            .setItemName(mdmItem.getName()).setItemBarCode(mdmItem.getBarCode()))));
                    item -> {
                        MapUtils.findAndThen(itemMap, item.getItemId(), mdmItem -> item
                                .setItemCode(mdmItem.getCode())
                                .setItemName(mdmItem.getName())
                                .setItemBarCode(mdmItem.getBarCode())
                                .setItemSpecification(mdmItem.getSpecification())
                                .setItemUnitId2(mdmItem.getUnitMeasureId2())
                                .setItemUnitId3(mdmItem.getUnitMeasureId3()));
                        MapUtils.findAndThen(unitMap, item.getItemUnitId(), unit -> item.setItemUnitName(unit.getName()));
                        MapUtils.findAndThen(unitMap, item.getItemUnitId2(), unit -> item.setItemUnitName2(unit.getName()));
                        MapUtils.findAndThen(unitMap, item.getItemUnitId3(), unit -> item.setItemUnitName3(unit.getName()));
                    }));
            MapUtils.findAndThen(customerMap, vo.getCustomerId(), customer -> vo.setCustomerName(customer.getName()));
            MapUtils.findAndThen(userMap, vo.getOwnerUserId(), user -> vo.setOwnerUserName(user.getNickname()));
            MapUtils.findAndThen(deptMap, vo.getOwnerUserId(), dept -> vo.setOwnerUserDeptName(dept.getName()));
            MapUtils.findAndThen(businessMap, vo.getBusinessId(), business -> vo.setBusinessName(business.getName()));
        });
    }
@@ -243,4 +287,4 @@
        }
    }
}
}