From 1c9a8bd42ed4e714e2864fa1b313cd19ec5a3f32 Mon Sep 17 00:00:00 2001 From: gaoqr <13665037151@163.com> Date: Wed, 5 Aug 2026 18:19:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=B7=E5=8D=95=E6=94=AF=E6=8C=81=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E5=90=8C=E6=AD=A5materialIds=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/plan/PlanServiceImpl.java | 55 +++++++++++++++++- .../PlanServiceImplMixedMaterialTest.java | 57 +++++++++++++++++++ 2 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 cf-module-prod-executor/cf-module-prod-executor-biz/src/test/java/com/cf/imes/module/executor/service/plan/PlanServiceImplMixedMaterialTest.java diff --git a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/plan/PlanServiceImpl.java b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/plan/PlanServiceImpl.java index e20d7a972..3c66edf3f 100644 --- a/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/plan/PlanServiceImpl.java +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/main/java/com/cf/imes/module/executor/service/plan/PlanServiceImpl.java @@ -1768,6 +1768,8 @@ public class PlanServiceImpl implements PlanService { Set orderIdSet = new HashSet<>(); Set allGoodsIds = new HashSet<>(); + Map> mixedSourceMaterialIdsByGoodsId = + loadMixedSourceMaterialIds(planActualGoodsLists); long sort = System.currentTimeMillis(); @@ -1825,7 +1827,8 @@ public class PlanServiceImpl implements PlanService { planDOS.add(planDO); producingMaterialGroupByPlanId.put(planId, toProducingMaterialGroup(planId, f.getPlanActualGoodsModelDO(), - collectSourceMaterialIds(goodsItemList, f.getIds()))); + collectSourceMaterialIds( + mixedSourceMaterialIdsByGoodsId, f.getIds()))); } // 统计更新order_goods的数量和面积 computePlatePlanAndComputeOrderGoodsInfo(allGoodsIds); @@ -2144,6 +2147,56 @@ public class PlanServiceImpl implements PlanService { .toList(); } + /** + * 根据混单分组中的 {@code order_goods.id} 一次性加载组件来源材料 ID。 + * + *

该数据仅用于组装组件系统的 {@code customMaterialGroupList.materialIds}, + * 不参与原有混单分组、排单和板件处理。

+ */ + private Map> loadMixedSourceMaterialIds( + List planActualGoodsLists) { + if (CollUtil.isEmpty(planActualGoodsLists)) { + return Collections.emptyMap(); + } + List orderGoodsIds = planActualGoodsLists.stream() + .filter(Objects::nonNull) + .map(PlanActualGoodsList::getIds) + .filter(CollUtil::isNotEmpty) + .flatMap(Collection::stream) + .filter(Objects::nonNull) + .distinct() + .toList(); + if (CollUtil.isEmpty(orderGoodsIds)) { + return Collections.emptyMap(); + } + return goodsMapper.selectBatchIds(orderGoodsIds).stream() + .filter(Objects::nonNull) + .collect(Collectors.toMap( + GoodsDO::getId, + goods -> Optional.ofNullable(goods.getSourceMaterialIds()) + .orElseGet(Collections::emptyList), + (first, ignored) -> first)); + } + + /** + * 按当前混单分组的 {@code order_goods.id} 汇总组件来源材料 ID。 + */ + private List collectSourceMaterialIds( + Map> sourceMaterialIdsByGoodsId, + Collection selectedGoodsIds) { + if (CollUtil.isEmpty(sourceMaterialIdsByGoodsId) + || CollUtil.isEmpty(selectedGoodsIds)) { + return Collections.emptyList(); + } + return selectedGoodsIds.stream() + .map(sourceMaterialIdsByGoodsId::get) + .filter(CollUtil::isNotEmpty) + .flatMap(Collection::stream) + .filter(StringUtils::isNotBlank) + .distinct() + .toList(); + } + /** * 生成对方接口必填的材质分组名称。 */ diff --git a/cf-module-prod-executor/cf-module-prod-executor-biz/src/test/java/com/cf/imes/module/executor/service/plan/PlanServiceImplMixedMaterialTest.java b/cf-module-prod-executor/cf-module-prod-executor-biz/src/test/java/com/cf/imes/module/executor/service/plan/PlanServiceImplMixedMaterialTest.java new file mode 100644 index 000000000..094859000 --- /dev/null +++ b/cf-module-prod-executor/cf-module-prod-executor-biz/src/test/java/com/cf/imes/module/executor/service/plan/PlanServiceImplMixedMaterialTest.java @@ -0,0 +1,57 @@ +package com.cf.imes.module.executor.service.plan; + +import com.cf.imes.module.executor.controller.admin.plan.vo.PlanActualGoodsList; +import com.cf.imes.module.executor.dal.dataobject.goods.GoodsDO; +import com.cf.imes.module.executor.dal.mysql.goods.GoodsMapper; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.test.util.ReflectionTestUtils; + +import java.util.List; +import java.util.Map; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.anyList; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +@ExtendWith(MockitoExtension.class) +class PlanServiceImplMixedMaterialTest { + + @Mock + private GoodsMapper goodsMapper; + + @InjectMocks + private PlanServiceImpl planService; + + @Test + void shouldLoadMixedMaterialIdsFromOrderGoodsIds() { + GoodsDO firstGoods = goods(101L, List.of("material-1", "material-common")); + GoodsDO secondGoods = goods(102L, List.of("material-common", "material-2")); + when(goodsMapper.selectBatchIds(anyList())) + .thenReturn(List.of(firstGoods, secondGoods)); + + List groups = List.of( + PlanActualGoodsList.builder().ids(List.of(101L, 102L)).build()); + + Map> materialIdsByGoodsId = ReflectionTestUtils.invokeMethod( + planService, "loadMixedSourceMaterialIds", groups); + List materialIds = ReflectionTestUtils.invokeMethod( + planService, "collectSourceMaterialIds", + materialIdsByGoodsId, groups.get(0).getIds()); + + assertThat(materialIds) + .containsExactly("material-1", "material-common", "material-2"); + verify(goodsMapper).selectBatchIds(List.of(101L, 102L)); + } + + private GoodsDO goods(Long id, List sourceMaterialIds) { + GoodsDO goods = new GoodsDO(); + goods.setId(id); + goods.setSourceMaterialIds(sourceMaterialIds); + return goods; + } +}