feat(wms): 新增调拨单明细物料匹配或创建功能

- 在IWmsTransferOrderItemService接口中添加matchOrCreateMaterial方法
- 在WmsTransferOrderItemController中添加/matchOrCreate接口端点
- 实现matchOrCreateMaterial业务逻辑,支持根据itemId和itemType匹配或新增物料
- 添加从原料到产品的转换匹配逻辑
- 添加从产品到原料的转换匹配逻辑
- 集成WmsRawMaterialMapper和WmsProductMapper数据访问层
- 实现基于名称、规格、制造商等字段的精确匹配机制
- 支持itemType参数区分原料(material)和成品(product)处理流程
This commit is contained in:
2026-03-27 16:32:32 +08:00
parent 0d3bde95f3
commit c294149274
3 changed files with 105 additions and 0 deletions

View File

@@ -96,4 +96,14 @@ public class WmsTransferOrderItemController extends BaseController {
@PathVariable Long[] itemIds) {
return toAjax(iWmsTransferOrderItemService.deleteWithValidByIds(Arrays.asList(itemIds), true));
}
/**
* 根据itemId和itemType匹配或新增物料
* itemType: raw_material-原料, product-成品
*/
@GetMapping("/matchOrCreate")
public R<Long> matchOrCreateMaterial(@NotNull(message = "itemId不能为空") Long itemId,
@NotNull(message = "itemType不能为空") String itemType) {
return R.ok(iWmsTransferOrderItemService.matchOrCreateMaterial(itemId, itemType));
}
}

View File

@@ -46,4 +46,10 @@ public interface IWmsTransferOrderItemService {
* 校验并批量删除调拨单明细信息
*/
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
/**
* 根据itemId和itemType匹配或新增物料
* itemType: "raw_material"-原料, "product"-成品
*/
Long matchOrCreateMaterial(Long itemId, String itemType);
}

View File

@@ -11,12 +11,21 @@ import org.springframework.stereotype.Service;
import com.klp.domain.bo.WmsTransferOrderItemBo;
import com.klp.domain.vo.WmsTransferOrderItemVo;
import com.klp.domain.WmsTransferOrderItem;
import com.klp.domain.WmsRawMaterial;
import com.klp.domain.WmsProduct;
import com.klp.mapper.WmsTransferOrderItemMapper;
import com.klp.mapper.WmsRawMaterialMapper;
import com.klp.mapper.WmsProductMapper;
import com.klp.service.IWmsTransferOrderItemService;
import java.util.List;
import java.util.Map;
import java.util.Collection;
import java.util.Objects;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.klp.common.utils.StringUtils;
/**
* 调拨单明细Service业务层处理
@@ -29,6 +38,8 @@ import java.util.Collection;
public class WmsTransferOrderItemServiceImpl implements IWmsTransferOrderItemService {
private final WmsTransferOrderItemMapper baseMapper;
private final WmsRawMaterialMapper rawMaterialMapper;
private final WmsProductMapper productMapper;
/**
* 查询调拨单明细
@@ -112,4 +123,82 @@ public class WmsTransferOrderItemServiceImpl implements IWmsTransferOrderItemSer
}
return baseMapper.deleteBatchIds(ids) > 0;
}
/**
* 根据itemId和itemType匹配或新增物料
* itemType: raw_material-原料, product-成品
*/
@Override
public Long matchOrCreateMaterial(Long itemId, String itemType) {
if (Objects.equals(itemType, "raw_material")) {
return matchOrCreateFromRawMaterial(itemId);
} else if (Objects.equals(itemType, "product")) {
return matchOrCreateFromProduct(itemId);
}
throw new IllegalArgumentException("无效的itemType: " + itemType);
}
private Long matchOrCreateFromRawMaterial(Long itemId) {
WmsRawMaterial rawMaterial = rawMaterialMapper.selectById(itemId);
if (rawMaterial == null) {
throw new IllegalArgumentException("原料不存在: " + itemId);
}
LambdaQueryWrapper<WmsProduct> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(WmsProduct::getProductName, rawMaterial.getRawMaterialName())
.eq(WmsProduct::getSpecification, rawMaterial.getSpecification())
.eq(WmsProduct::getManufacturer, rawMaterial.getManufacturer())
.eq(WmsProduct::getMaterial, rawMaterial.getMaterial())
.eq(WmsProduct::getSurfaceTreatmentDesc, rawMaterial.getSurfaceTreatmentDesc())
.eq(WmsProduct::getZincLayer, rawMaterial.getZincLayer())
.last("LIMIT 1");
WmsProduct existProduct = productMapper.selectOne(wrapper);
if (existProduct != null) {
return existProduct.getProductId();
}
WmsProduct newProduct = new WmsProduct();
newProduct.setProductName(rawMaterial.getRawMaterialName());
newProduct.setSpecification(rawMaterial.getSpecification());
newProduct.setManufacturer(rawMaterial.getManufacturer());
newProduct.setMaterial(rawMaterial.getMaterial());
newProduct.setSurfaceTreatmentDesc(rawMaterial.getSurfaceTreatmentDesc());
newProduct.setZincLayer(rawMaterial.getZincLayer());
newProduct.setDelFlag(0);
productMapper.insert(newProduct);
return newProduct.getProductId();
}
private Long matchOrCreateFromProduct(Long itemId) {
WmsProduct product = productMapper.selectById(itemId);
if (product == null) {
throw new IllegalArgumentException("产品不存在: " + itemId);
}
LambdaQueryWrapper<WmsRawMaterial> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(WmsRawMaterial::getRawMaterialName, product.getProductName())
.eq(WmsRawMaterial::getSpecification, product.getSpecification())
.eq(WmsRawMaterial::getManufacturer, product.getManufacturer())
.eq(WmsRawMaterial::getMaterial, product.getMaterial())
.eq(WmsRawMaterial::getSurfaceTreatmentDesc, product.getSurfaceTreatmentDesc())
.eq(WmsRawMaterial::getZincLayer, product.getZincLayer())
.last("LIMIT 1");
WmsRawMaterial existRawMaterial = rawMaterialMapper.selectOne(wrapper);
if (existRawMaterial != null) {
return existRawMaterial.getRawMaterialId();
}
WmsRawMaterial newRawMaterial = new WmsRawMaterial();
newRawMaterial.setRawMaterialName(product.getProductName());
newRawMaterial.setSpecification(product.getSpecification());
newRawMaterial.setManufacturer(product.getManufacturer());
newRawMaterial.setMaterial(product.getMaterial());
newRawMaterial.setSurfaceTreatmentDesc(product.getSurfaceTreatmentDesc());
newRawMaterial.setZincLayer(product.getZincLayer());
newRawMaterial.setDelFlag(0);
rawMaterialMapper.insert(newRawMaterial);
return newRawMaterial.getRawMaterialId();
}
}