mirror of
http://192.168.1.205:9980/cf_devdept2/cf_imes_server.git
synced 2026-08-12 12:52:07 +08:00
1、组件拆单反同步材质数据调整;2、组件创建排单实际板材同步数据调整;
This commit is contained in:
+8
@@ -86,6 +86,14 @@ public class SavePlanPlateList {
|
||||
@Schema(description = "纹理")
|
||||
private Boolean texture;
|
||||
|
||||
/**
|
||||
* 组件生产系统来源材料 ID 列表。
|
||||
*
|
||||
* <p>创建排单时由后端根据 {@code order_goods.id}重新加载,不信任前端传值。</p>
|
||||
*/
|
||||
@Schema(description = "组件生产系统materials[type=1].id列表", accessMode = Schema.AccessMode.READ_ONLY)
|
||||
private List<String> sourceMaterialIds;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+7
-1
@@ -1,17 +1,19 @@
|
||||
package com.cf.imes.module.executor.dal.dataobject.goods;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
|
||||
import com.cf.imes.framework.mybatis.core.dataobject.BaseDO;
|
||||
import lombok.*;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 订单商品 DO
|
||||
*
|
||||
* @author 晨丰科技
|
||||
*/
|
||||
@TableName("order_goods")
|
||||
@TableName(value = "order_goods", autoResultMap = true)
|
||||
@KeySequence("order_goods_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@@ -41,6 +43,10 @@ public class GoodsDO extends BaseDO {
|
||||
* 商品 ID
|
||||
*/
|
||||
private String goodsId;
|
||||
|
||||
/** 组件生产系统 {@code materials[type=1].id} 列表。 */
|
||||
@TableField(value = "source_material_ids", typeHandler = JacksonTypeHandler.class)
|
||||
private List<String> sourceMaterialIds;
|
||||
/**
|
||||
* 排单 ID
|
||||
*/
|
||||
|
||||
+69
-16
@@ -192,16 +192,20 @@ public class PlanServiceImpl implements PlanService {
|
||||
|
||||
SavePlanPlateList savePlanPlateList = Optional.ofNullable(createReqVO.getSavePlanPlateList()).orElseThrow(()-> new ServiceException(PLAN_PLATE_DATA_ERROR));
|
||||
|
||||
List<SavePlanPlateList.PlateItemList> plateItemList = Optional.ofNullable(
|
||||
savePlanPlateList.getPlateItemList()).orElseThrow(
|
||||
() -> new ServiceException(PLAN_PLATE_DATA_ERROR));
|
||||
List<SavePlanPlateList.GoodsItemList> goodsItemList = Optional.ofNullable(
|
||||
savePlanPlateList.getGoodsItemList()).orElseThrow(
|
||||
() -> new ServiceException(PLAN_PLATE_DATA_ERROR));
|
||||
loadSourceMaterialIds(goodsItemList);
|
||||
|
||||
|
||||
if (savePlanPlateList.getMixConfig() != null && Boolean.TRUE.equals(savePlanPlateList.getMixConfig().getIsMixed())) {
|
||||
|
||||
// 混单时走的逻辑
|
||||
Integer mixedType = Optional.ofNullable(savePlanPlateList.getMixConfig().getMixedType()).orElse(MixConfigTypeEnum.SAMEMATERIALANDTHICKNESS.getType());
|
||||
|
||||
List<SavePlanPlateList.PlateItemList> plateItemList = Optional.ofNullable(savePlanPlateList.getPlateItemList()).orElseThrow(()-> new ServiceException(PLAN_PLATE_DATA_ERROR));
|
||||
|
||||
List<SavePlanPlateList.GoodsItemList> goodsItemList = Optional.ofNullable(savePlanPlateList.getGoodsItemList()).orElseThrow(()-> new ServiceException(PLAN_PLATE_DATA_ERROR));
|
||||
|
||||
List<PlanActualGoodsList> planActualGoodsLists = Optional.ofNullable(createReqVO.getPlanActualGoodsListList()).orElse(new ArrayList<>());
|
||||
|
||||
// 混单时判断是否进行板材对应并创建排单
|
||||
@@ -212,9 +216,6 @@ public class PlanServiceImpl implements PlanService {
|
||||
} else {
|
||||
|
||||
// 非混单
|
||||
List<SavePlanPlateList.PlateItemList> plateItemList = Optional.ofNullable(savePlanPlateList.getPlateItemList()).orElseThrow(()-> new ServiceException(PLAN_PLATE_DATA_ERROR));
|
||||
|
||||
List<SavePlanPlateList.GoodsItemList> goodsItemList = Optional.ofNullable(savePlanPlateList.getGoodsItemList()).orElseThrow(()-> new ServiceException(PLAN_PLATE_DATA_ERROR));
|
||||
// 查找材质和厚度和颜色相同的大板
|
||||
Map<String, List<Long>> grouped = groupByMaterialAndThicknessAndColorAndBrand(goodsItemList);
|
||||
|
||||
@@ -1673,7 +1674,7 @@ public class PlanServiceImpl implements PlanService {
|
||||
if(CollUtil.isNotEmpty(planActualGoodsLists)) {
|
||||
|
||||
// 有选实际大板的小板加大板创建排单
|
||||
getCreatePlanMultipleGoodsList(planActualGoodsLists, plateItemList, planDOS,
|
||||
getCreatePlanMultipleGoodsList(planActualGoodsLists, plateItemList, goodsItemList, planDOS,
|
||||
producingMaterialGroupByPlanId, processId, processName, loginUser);
|
||||
|
||||
|
||||
@@ -1758,6 +1759,7 @@ public class PlanServiceImpl implements PlanService {
|
||||
|
||||
private void getCreatePlanMultipleGoodsList(List<PlanActualGoodsList> planActualGoodsLists,
|
||||
List<SavePlanPlateList.PlateItemList> plateItemList,
|
||||
List<SavePlanPlateList.GoodsItemList> goodsItemList,
|
||||
List<PlanDO> planDOS,
|
||||
Map<Long, ProducingPlanOrderMaterialGroup> producingMaterialGroupByPlanId,
|
||||
Long processId,
|
||||
@@ -1822,7 +1824,8 @@ public class PlanServiceImpl implements PlanService {
|
||||
|
||||
planDOS.add(planDO);
|
||||
producingMaterialGroupByPlanId.put(planId,
|
||||
toProducingMaterialGroup(planId, f.getPlanActualGoodsModelDO()));
|
||||
toProducingMaterialGroup(planId, f.getPlanActualGoodsModelDO(),
|
||||
collectSourceMaterialIds(goodsItemList, f.getIds())));
|
||||
}
|
||||
// 统计更新order_goods的数量和面积
|
||||
computePlatePlanAndComputeOrderGoodsInfo(allGoodsIds);
|
||||
@@ -1902,7 +1905,8 @@ public class PlanServiceImpl implements PlanService {
|
||||
.filter(goods -> value.contains(goods.getId()))
|
||||
.findFirst()
|
||||
.ifPresent(goods -> producingMaterialGroupByPlanId.put(planId,
|
||||
toProducingMaterialGroup(planId, goods)));
|
||||
toProducingMaterialGroup(planId, goods,
|
||||
collectSourceMaterialIds(goodsItemList, value))));
|
||||
}
|
||||
// 统计更新order_goods的数量和面积
|
||||
computePlatePlanAndComputeOrderGoodsInfo(allGoodsIds);
|
||||
@@ -2057,15 +2061,16 @@ public class PlanServiceImpl implements PlanService {
|
||||
* 根据普通排单使用的材质属性构建组件生产系统自定义材质分组。
|
||||
*/
|
||||
private ProducingPlanOrderMaterialGroup toProducingMaterialGroup(
|
||||
Long planId, SavePlanPlateList.GoodsItemList goods) {
|
||||
Long planId, SavePlanPlateList.GoodsItemList goods,
|
||||
List<String> sourceMaterialIds) {
|
||||
return ProducingPlanOrderMaterialGroup.builder()
|
||||
.id(goods.getGoodsId())
|
||||
.name(buildProducingMaterialGroupName(
|
||||
planId, null, goods.getMaterial(), goods.getColor(), goods.getThickness()))
|
||||
.type(1)
|
||||
.type(4)
|
||||
.thickness(goods.getThickness())
|
||||
.hasWave(goods.getTexture())
|
||||
.materialIds(Collections.emptyList())
|
||||
.materialIds(sourceMaterialIds)
|
||||
.brand(goods.getBrand())
|
||||
.material(goods.getMaterial())
|
||||
.color(goods.getColor())
|
||||
@@ -2076,21 +2081,69 @@ public class PlanServiceImpl implements PlanService {
|
||||
* 根据混单选择的实际大板属性构建组件生产系统自定义材质分组。
|
||||
*/
|
||||
private ProducingPlanOrderMaterialGroup toProducingMaterialGroup(
|
||||
Long planId, PlanActualGoodsModelDO goods) {
|
||||
Long planId, PlanActualGoodsModelDO goods,
|
||||
List<String> sourceMaterialIds) {
|
||||
return ProducingPlanOrderMaterialGroup.builder()
|
||||
.id(goods.getGoodsId())
|
||||
.name(buildProducingMaterialGroupName(
|
||||
planId, goods.getGoodsName(), goods.getMaterial(),
|
||||
goods.getColor(), goods.getThickness()))
|
||||
.type(1)
|
||||
.type(4)
|
||||
.thickness(goods.getThickness())
|
||||
.materialIds(Collections.emptyList())
|
||||
.materialIds(sourceMaterialIds)
|
||||
.brand(goods.getBrand())
|
||||
.material(goods.getMaterial())
|
||||
.color(goods.getColor())
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据本次排单提交的订单商品 ID 一次性加载来源材料数组。
|
||||
*
|
||||
* <p>来源材料关系以数据库为准,避免前端遗漏或伪造对方材料 ID。</p>
|
||||
*/
|
||||
private void loadSourceMaterialIds(List<SavePlanPlateList.GoodsItemList> goodsItems) {
|
||||
if (CollUtil.isEmpty(goodsItems)) {
|
||||
return;
|
||||
}
|
||||
List<Long> goodsIds = goodsItems.stream()
|
||||
.map(SavePlanPlateList.GoodsItemList::getId)
|
||||
.filter(Objects::nonNull)
|
||||
.distinct()
|
||||
.toList();
|
||||
if (CollUtil.isEmpty(goodsIds)) {
|
||||
return;
|
||||
}
|
||||
Map<Long, List<String>> sourceMaterialIdsByGoodsId = goodsMapper.selectBatchIds(goodsIds)
|
||||
.stream()
|
||||
.collect(Collectors.toMap(GoodsDO::getId,
|
||||
goods -> Optional.ofNullable(goods.getSourceMaterialIds())
|
||||
.orElseGet(Collections::emptyList)));
|
||||
goodsItems.forEach(goods -> goods.setSourceMaterialIds(
|
||||
new ArrayList<>(sourceMaterialIdsByGoodsId.getOrDefault(
|
||||
goods.getId(), Collections.emptyList()))));
|
||||
}
|
||||
|
||||
/**
|
||||
* 汇总一个排单材质组内所有订单板材的对方材料 ID,并保持首次出现顺序。
|
||||
*/
|
||||
private List<String> collectSourceMaterialIds(
|
||||
List<SavePlanPlateList.GoodsItemList> goodsItems,
|
||||
Collection<Long> selectedGoodsIds) {
|
||||
if (CollUtil.isEmpty(goodsItems) || CollUtil.isEmpty(selectedGoodsIds)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
Set<Long> selected = new HashSet<>(selectedGoodsIds);
|
||||
return goodsItems.stream()
|
||||
.filter(goods -> selected.contains(goods.getId()))
|
||||
.map(SavePlanPlateList.GoodsItemList::getSourceMaterialIds)
|
||||
.filter(CollUtil::isNotEmpty)
|
||||
.flatMap(Collection::stream)
|
||||
.filter(StringUtils::isNotBlank)
|
||||
.distinct()
|
||||
.toList();
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成对方接口必填的材质分组名称。
|
||||
*/
|
||||
|
||||
+2
-2
@@ -25,7 +25,7 @@ public class ProducingPlanOrderMaterialGroup {
|
||||
/** 物料名称。 */
|
||||
private String name;
|
||||
|
||||
/** 物料类型,1 表示板材。 */
|
||||
/** 自定义材质分组类型,组件生产排单固定传4。 */
|
||||
private Integer type;
|
||||
|
||||
/** 板材宽度。 */
|
||||
@@ -40,7 +40,7 @@ public class ProducingPlanOrderMaterialGroup {
|
||||
/** 是否有纹路。 */
|
||||
private Boolean hasWave;
|
||||
|
||||
/** 分组下的物料 ID 列表,当前按接口约定暂不填充。 */
|
||||
/** 分组所包含的对方 {@code materials[type=1].id} 去重列表。 */
|
||||
private List<String> materialIds;
|
||||
|
||||
/** 备注。 */
|
||||
|
||||
+5
-3
@@ -47,10 +47,10 @@ class ProducingPlanOrderClientTest {
|
||||
ProducingPlanOrderMaterialGroup.builder()
|
||||
.id("goods-1")
|
||||
.name("颗粒板-白色-18")
|
||||
.type(1)
|
||||
.type(4)
|
||||
.thickness(new java.math.BigDecimal("18"))
|
||||
.hasWave(true)
|
||||
.materialIds(List.of())
|
||||
.materialIds(List.of("source-material-2366", "source-material-2367"))
|
||||
.brand("测试品牌")
|
||||
.material("颗粒板")
|
||||
.color("白色")
|
||||
@@ -82,8 +82,10 @@ class ProducingPlanOrderClientTest {
|
||||
JsonNode materialBody = createBody.get("customMaterialGroupList").get(0);
|
||||
assertThat(materialBody.get("id").textValue()).isEqualTo("goods-1");
|
||||
assertThat(materialBody.get("name").textValue()).isEqualTo("颗粒板-白色-18");
|
||||
assertThat(materialBody.get("type").intValue()).isEqualTo(4);
|
||||
assertThat(materialBody.get("materialIds").isArray()).isTrue();
|
||||
assertThat(materialBody.get("materialIds").isEmpty()).isTrue();
|
||||
assertThat(materialBody.get("materialIds").toString())
|
||||
.isEqualTo("[\"source-material-2366\",\"source-material-2367\"]");
|
||||
assertThat(materialBody.get("material").textValue()).isEqualTo("颗粒板");
|
||||
assertThat(objectMapper.readTree(requests.get(1).body())
|
||||
.get("appendBlockIds").get(0).textValue()).isEqualTo("source-3");
|
||||
|
||||
+12
-2
@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.annotation.KeySequence;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
|
||||
import com.cf.imes.framework.mybatis.core.dataobject.BaseDO;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
@@ -14,13 +15,14 @@ import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 订单商品 DO
|
||||
*
|
||||
* @author 晨丰科技
|
||||
*/
|
||||
@TableName("order_goods")
|
||||
@TableName(value = "order_goods", autoResultMap = true)
|
||||
@KeySequence("order_goods_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@@ -50,6 +52,14 @@ public class GoodsDO extends BaseDO {
|
||||
* 商品 ID
|
||||
*/
|
||||
private String goodsId;
|
||||
|
||||
/**
|
||||
* 组件生产系统材料 ID 列表。
|
||||
*
|
||||
* <p>多个对方 {@code materials[type=1].id} 可以映射并复用同一条订单板材。</p>
|
||||
*/
|
||||
@TableField(value = "source_material_ids", typeHandler = JacksonTypeHandler.class)
|
||||
private List<String> sourceMaterialIds;
|
||||
/**
|
||||
* 排单 ID
|
||||
*/
|
||||
@@ -137,4 +147,4 @@ public class GoodsDO extends BaseDO {
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
private boolean exist;
|
||||
}
|
||||
}
|
||||
|
||||
+42
-3
@@ -614,6 +614,20 @@ public class ProducingOrderImportFactory {
|
||||
}
|
||||
));
|
||||
|
||||
// selectMaps 的聚合结果不会应用 JSON 类型处理器,再按选中的 order_goods.id
|
||||
// 加载已有来源材料数组,确保重复导入及多来源材料映射时只追加、不覆盖。
|
||||
if (MapUtil.isNotEmpty(materialMap)) {
|
||||
Map<Long, List<String>> sourceMaterialIdsByGoodsId = goodsMapper.selectBatchIds(
|
||||
materialMap.values().stream().map(GoodsDO::getId).toList())
|
||||
.stream()
|
||||
.collect(Collectors.toMap(GoodsDO::getId,
|
||||
goods -> goods.getSourceMaterialIds() == null
|
||||
? new ArrayList<>()
|
||||
: new ArrayList<>(goods.getSourceMaterialIds())));
|
||||
materialMap.values().forEach(goods -> goods.setSourceMaterialIds(
|
||||
sourceMaterialIdsByGoodsId.getOrDefault(goods.getId(), new ArrayList<>())));
|
||||
}
|
||||
|
||||
for (ProducingImportMaterial materialReqVO : materialReqVOS) {
|
||||
String plateGoodsGoodsId = materialReqVO.getGoodsId();
|
||||
|
||||
@@ -629,6 +643,7 @@ public class ProducingOrderImportFactory {
|
||||
.orderId(orderId)
|
||||
.rawGoodsId(String.valueOf(rawGoodsId))
|
||||
.goodsId(plateGoodsGoodsId)
|
||||
.sourceMaterialIds(new ArrayList<>())
|
||||
.goodsName(materialReqVO.getName())
|
||||
.material(materialReqVO.getMaterial())
|
||||
.texture(materialReqVO.getTexture())
|
||||
@@ -657,14 +672,36 @@ public class ProducingOrderImportFactory {
|
||||
// 缓存goodCode和orderGoodsId的对应关系
|
||||
materialMap.put(plateGoodsGoodsId, goodsDO);
|
||||
}
|
||||
if (StringUtils.isNotEmpty(plateGoodsGoodsId)) {
|
||||
GoodsDO orderGoods = materialMap.get(plateGoodsGoodsId);
|
||||
mergeSourceMaterialId(orderGoods, materialReqVO.getSourceMaterialId());
|
||||
if (StringUtils.isNotEmpty(materialReqVO.getSourceMaterialId())) {
|
||||
externalMaterialMap.putIfAbsent(
|
||||
plateGoodsGoodsId,
|
||||
materialReqVO.getSourceMaterialId(),
|
||||
toExternalBlockMaterial(materialReqVO));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将本次对方板材 ID 去重追加到订单板材的来源材料数组。
|
||||
*
|
||||
* @param orderGoods 本次生成或复用的订单板材
|
||||
* @param sourceMaterialId 对方 {@code materials[type=1].id}
|
||||
*/
|
||||
private void mergeSourceMaterialId(GoodsDO orderGoods, String sourceMaterialId) {
|
||||
if (orderGoods == null || StringUtils.isEmpty(sourceMaterialId)) {
|
||||
return;
|
||||
}
|
||||
List<String> sourceMaterialIds = orderGoods.getSourceMaterialIds();
|
||||
if (sourceMaterialIds == null) {
|
||||
sourceMaterialIds = new ArrayList<>();
|
||||
orderGoods.setSourceMaterialIds(sourceMaterialIds);
|
||||
}
|
||||
if (!sourceMaterialIds.contains(sourceMaterialId)) {
|
||||
sourceMaterialIds.add(sourceMaterialId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 缓存加工组类型
|
||||
*
|
||||
@@ -2257,7 +2294,7 @@ public class ProducingOrderImportFactory {
|
||||
private ProducingExternalMaterial toExternalBlockMaterial(
|
||||
ProducingImportMaterial material) {
|
||||
return ProducingExternalMaterial.builder()
|
||||
.id(material.getId())
|
||||
.id(material.getGoodsId())
|
||||
.type(1)
|
||||
.name(material.getName())
|
||||
.remark(getEmpty(material.getRemark()))
|
||||
@@ -3125,6 +3162,8 @@ public class ProducingOrderImportFactory {
|
||||
.eq(GoodsDO::getOrganId, organId)
|
||||
.eq(GoodsDO::getVersion, updateDo.getVersion())
|
||||
.set(GoodsDO::getPlateNum, updateDo.getPlateNum())
|
||||
.setSql("source_material_ids = {0}",
|
||||
JsonUtils.toJsonString(updateDo.getSourceMaterialIds()))
|
||||
.set(GoodsDO::getVersion, updateDo.getVersion() + 1));
|
||||
if (updated == 0) {
|
||||
throw new ServiceException(ErrorCodeConstants.WEBCAD_ORDER_IMPORT_GOODS_UPDATE_CONCURRENCY_ERROR, updateDo.getId());
|
||||
|
||||
+4
-3
@@ -32,9 +32,10 @@ public class ProducingOrderExtraSyncRequest {
|
||||
private Map<String, String> parts = new LinkedHashMap<>();
|
||||
|
||||
/**
|
||||
* iMES 物料标识到板材库/配件物料对象的映射。板材(type=1)使用
|
||||
* {@code order_goods.goods_id} 作为 key,配件和封边条(type=2/3)使用对方
|
||||
* {@code materials.id} 作为 key。
|
||||
* 对方 {@code materials.id} 到 iMES 板材库/配件物料对象的映射。
|
||||
*
|
||||
* <p>type=1 对象的 {@code id} 使用 iMES 板材库商品编号;type=2/3 对象的
|
||||
* {@code id} 使用本次生成或复用的 iMES 配件 ID。</p>
|
||||
*/
|
||||
@Builder.Default
|
||||
private Map<String, ProducingExternalMaterial> externalMaterialMapping =
|
||||
|
||||
+4
-3
@@ -29,9 +29,10 @@ public class ProducingOrderItemSerialNoUpdateRequest {
|
||||
private Map<String, String> parts = new LinkedHashMap<>();
|
||||
|
||||
/**
|
||||
* iMES 物料标识到板材库/配件物料对象的映射。板材(type=1)使用
|
||||
* {@code order_goods.goods_id} 作为 key,配件和封边条(type=2/3)使用对方
|
||||
* {@code materials.id} 作为 key。
|
||||
* 对方 {@code materials.id} 到 iMES 板材库/配件物料对象的映射。
|
||||
*
|
||||
* <p>type=1 对象的 {@code id} 使用 iMES 板材库商品编号;type=2/3 对象的
|
||||
* {@code id} 使用本次生成或复用的 iMES 配件 ID。</p>
|
||||
*/
|
||||
private Map<String, ProducingExternalMaterial> externalMaterialMapping =
|
||||
new LinkedHashMap<>();
|
||||
|
||||
Reference in New Issue
Block a user