| | |
| | | import cn.iocoder.yudao.module.crm.service.customer.CrmCustomerService; |
| | | 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; |
| | |
| | | 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; |
| | |
| | | private CrmBusinessStatusService businessStatusService; |
| | | @Resource |
| | | private MdmItemApi mdmItemApi; |
| | | @Resource |
| | | private MdmUnitMeasureApi mdmUnitMeasureApi; |
| | | |
| | | @Resource |
| | | private AdminUserApi adminUserApi; |
| | |
| | | List<CrmBusinessProductDO> businessProducts = businessService.getBusinessProductListByBusinessId(businessVO.getId()); |
| | | 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(itemMap, businessProductVO.getItemId(), |
| | | item -> businessProductVO.setItemName(item.getName()) |
| | | .setItemCode(item.getCode()).setItemUnitId(item.getUnitMeasureId())))); |
| | | .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; |
| | | } |
| | | |