混单支持组件同步materialIds结构

This commit is contained in:
gaoqr
2026-08-05 18:19:59 +08:00
parent ed4123f502
commit 1c9a8bd42e
2 changed files with 111 additions and 1 deletions
@@ -1768,6 +1768,8 @@ public class PlanServiceImpl implements PlanService {
Set<Long> orderIdSet = new HashSet<>(); Set<Long> orderIdSet = new HashSet<>();
Set<Long> allGoodsIds = new HashSet<>(); Set<Long> allGoodsIds = new HashSet<>();
Map<Long, List<String>> mixedSourceMaterialIdsByGoodsId =
loadMixedSourceMaterialIds(planActualGoodsLists);
long sort = System.currentTimeMillis(); long sort = System.currentTimeMillis();
@@ -1825,7 +1827,8 @@ public class PlanServiceImpl implements PlanService {
planDOS.add(planDO); planDOS.add(planDO);
producingMaterialGroupByPlanId.put(planId, producingMaterialGroupByPlanId.put(planId,
toProducingMaterialGroup(planId, f.getPlanActualGoodsModelDO(), toProducingMaterialGroup(planId, f.getPlanActualGoodsModelDO(),
collectSourceMaterialIds(goodsItemList, f.getIds()))); collectSourceMaterialIds(
mixedSourceMaterialIdsByGoodsId, f.getIds())));
} }
// 统计更新order_goods的数量和面积 // 统计更新order_goods的数量和面积
computePlatePlanAndComputeOrderGoodsInfo(allGoodsIds); computePlatePlanAndComputeOrderGoodsInfo(allGoodsIds);
@@ -2144,6 +2147,56 @@ public class PlanServiceImpl implements PlanService {
.toList(); .toList();
} }
/**
* 根据混单分组中的 {@code order_goods.id} 一次性加载组件来源材料 ID。
*
* <p>该数据仅用于组装组件系统的 {@code customMaterialGroupList.materialIds}
* 不参与原有混单分组、排单和板件处理。</p>
*/
private Map<Long, List<String>> loadMixedSourceMaterialIds(
List<PlanActualGoodsList> planActualGoodsLists) {
if (CollUtil.isEmpty(planActualGoodsLists)) {
return Collections.emptyMap();
}
List<Long> 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<String> collectSourceMaterialIds(
Map<Long, List<String>> sourceMaterialIdsByGoodsId,
Collection<Long> 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();
}
/** /**
* 生成对方接口必填的材质分组名称。 * 生成对方接口必填的材质分组名称。
*/ */
@@ -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<PlanActualGoodsList> groups = List.of(
PlanActualGoodsList.builder().ids(List.of(101L, 102L)).build());
Map<Long, List<String>> materialIdsByGoodsId = ReflectionTestUtils.invokeMethod(
planService, "loadMixedSourceMaterialIds", groups);
List<String> 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<String> sourceMaterialIds) {
GoodsDO goods = new GoodsDO();
goods.setId(id);
goods.setSourceMaterialIds(sourceMaterialIds);
return goods;
}
}