add:增加物料主数据同步
This commit is contained in:
@@ -45,7 +45,7 @@ public class SapConstant {
|
||||
public static final String SRC_SYSTEM = "WMS5";
|
||||
public static final String DEST_SYSTEM = "SAP";
|
||||
|
||||
public static final String MM064_SRC_SYSTEM = "WMS";
|
||||
public static final String MM064_SRC_SYSTEM = "WMS5";
|
||||
/** 生产入库默认工厂 */
|
||||
public static final String WERKS = "1060";
|
||||
|
||||
|
||||
@@ -71,7 +71,8 @@ import static org.nl.wms.warehouse_manage.enums.IOSEnum.LOCK_TYPE;
|
||||
@Service
|
||||
public class InboundPdaServiceImpl implements InboundPdaService {
|
||||
|
||||
|
||||
/** 物料未维护计量单位时的默认单位名称(md_pb_measureunit.unit_name='PCS',注意其 unit_code 为 '602') */
|
||||
private static final String DEFAULT_UNIT_NAME = "PCS";
|
||||
|
||||
@Autowired
|
||||
private ApplicationEventPublisher eventPublisher;
|
||||
@@ -234,7 +235,7 @@ public class InboundPdaServiceImpl implements InboundPdaService {
|
||||
throw new BadRequestException("组盘失败:"+item.getSku_code() + "组盘数量超过单据数量");
|
||||
}
|
||||
MdMeMaterialbase materDao = iMdMeMaterialbaseService.getByCode(item.getSku_code());
|
||||
MdPbMeasureunit unitDao = iMdPbMeasureunitService.getById(materDao.getQty_unit_id());
|
||||
MdPbMeasureunit unitDao = resolveMeasureUnit(materDao);
|
||||
|
||||
GroupPlate groupDao = GroupPlate.builder()
|
||||
.group_id(IdUtil.getStringId())
|
||||
@@ -268,6 +269,9 @@ public class InboundPdaServiceImpl implements InboundPdaService {
|
||||
throw new BadRequestException("获取单据失败:参数为空");
|
||||
}
|
||||
String mblnr = code.trim();
|
||||
if (code.contains("#")) {
|
||||
mblnr = code.split("#")[0].trim();
|
||||
}
|
||||
MaterialDocument document = documentMapper.selectOne(
|
||||
new LambdaQueryWrapper<MaterialDocument>()
|
||||
.eq(MaterialDocument::getMblnr, mblnr)
|
||||
@@ -357,7 +361,7 @@ public class InboundPdaServiceImpl implements InboundPdaService {
|
||||
}
|
||||
}
|
||||
MdMeMaterialbase materDao = iMdMeMaterialbaseService.getByCode(item.getSku_code());
|
||||
MdPbMeasureunit unitDao = iMdPbMeasureunitService.getById(materDao.getQty_unit_id());
|
||||
MdPbMeasureunit unitDao = resolveMeasureUnit(materDao);
|
||||
//组盘
|
||||
GroupPlate plateDao = GroupPlate.builder()
|
||||
.group_id(IdUtil.getStringId())
|
||||
@@ -391,6 +395,64 @@ public class InboundPdaServiceImpl implements InboundPdaService {
|
||||
this.submitGroupPlateInbound(groupPlateInboundDto, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析物料的基本计量单位,逐级兜底,避免单位未维护时抛 NPE。
|
||||
* <p>
|
||||
* 顺序:① 按物料 qty_unit_id 直查 → ② 有单位名称时按 unit_code/unit_name 反查 → ③ 默认单位 PCS。
|
||||
* 都取不到才抛业务异常(属于数据未维护,提示维护而非空指针)。
|
||||
*/
|
||||
private MdPbMeasureunit resolveMeasureUnit(MdMeMaterialbase materDao) {
|
||||
if (materDao == null) {
|
||||
throw new BadRequestException("入库失败:物料信息为空,无法解析计量单位");
|
||||
}
|
||||
String unitId = materDao.getQty_unit_id();
|
||||
String unitName = materDao.getQty_unit_name();
|
||||
// ① 正常路径:按物料维护的单位标识直查
|
||||
if (StrUtil.isNotBlank(unitId)) {
|
||||
MdPbMeasureunit unit = iMdPbMeasureunitService.getById(unitId);
|
||||
if (unit != null) {
|
||||
return unit;
|
||||
}
|
||||
}
|
||||
// ② 兜底一:单位标识缺失/失效时,用物料单位名称反查计量单位
|
||||
if (StrUtil.isNotBlank(unitName)) {
|
||||
MdPbMeasureunit unit = findMeasureUnit(unitName);
|
||||
if (unit != null) {
|
||||
return unit;
|
||||
}
|
||||
}
|
||||
// ③ 兜底二:统一使用默认计量单位 PCS(md_pb_measureunit.unit_name = 'PCS')
|
||||
MdPbMeasureunit defaultUnit = findMeasureUnit(DEFAULT_UNIT_NAME);
|
||||
if (defaultUnit != null) {
|
||||
log.warn("物料{}未维护有效计量单位(unit_id={}, unit_name={}),使用默认单位{}兜底",
|
||||
materDao.getMaterial_code(), unitId, unitName, defaultUnit.getUnit_name());
|
||||
return defaultUnit;
|
||||
}
|
||||
throw new BadRequestException("入库失败:物料" + materDao.getMaterial_code()
|
||||
+ "未维护计量单位,且默认单位" + DEFAULT_UNIT_NAME + "在计量单位表中不存在,请先维护");
|
||||
}
|
||||
|
||||
/**
|
||||
* 按「单位编码」或「单位名称」查计量单位,优先匹配编码。
|
||||
* <p>
|
||||
* 注意:PCS 这条基础数据的 unit_code='602'、unit_name='PCS',
|
||||
* 因此只按 unit_code 匹配会查不到,必须同时支持按 unit_name 匹配。
|
||||
*/
|
||||
private MdPbMeasureunit findMeasureUnit(String unit) {
|
||||
if (StrUtil.isBlank(unit)) {
|
||||
return null;
|
||||
}
|
||||
String val = unit.trim();
|
||||
MdPbMeasureunit one = iMdPbMeasureunitService.getOne(new LambdaQueryWrapper<MdPbMeasureunit>()
|
||||
.eq(MdPbMeasureunit::getUnit_code, val).last("limit 1"));
|
||||
if (one != null) {
|
||||
return one;
|
||||
}
|
||||
// unit_code 匹配不上再按名称匹配(忽略大小写,兼容 PCS/Pcs)
|
||||
return iMdPbMeasureunitService.getOne(new LambdaQueryWrapper<MdPbMeasureunit>()
|
||||
.apply("UPPER(unit_name) = {0}", val.toUpperCase()).last("limit 1"));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void submitGroupPlateInbound(GroupPlateInboundDto groupPlateInboundDto, Boolean subTask) {
|
||||
@@ -673,7 +735,7 @@ public class InboundPdaServiceImpl implements InboundPdaService {
|
||||
}
|
||||
}
|
||||
MdMeMaterialbase materDao = iMdMeMaterialbaseService.getByCode(item.getSku_code());
|
||||
MdPbMeasureunit unitDao = iMdPbMeasureunitService.getById(materDao.getQty_unit_id());
|
||||
MdPbMeasureunit unitDao = resolveMeasureUnit(materDao);
|
||||
//组盘
|
||||
GroupPlate plateDao = GroupPlate.builder()
|
||||
.group_id(IdUtil.getStringId())
|
||||
|
||||
Reference in New Issue
Block a user