|
|
@@ -151,7 +151,7 @@ public class AdoS0ProductStructuresController : ControllerBase
|
|
|
var err = AdoS0ProductStructureRules.ValidateUpsert(dto);
|
|
|
if (err != null) return BadRequest(new { message = err });
|
|
|
|
|
|
- var fkErr = await ValidateMaterialRefsAsync(dto.CompanyRefId, dto.FactoryRefId, dto.ParentMaterialId, dto.ComponentMaterialId);
|
|
|
+ var fkErr = await ValidateMaterialRefsAsync(dto.ParentMaterialId, dto.ComponentMaterialId);
|
|
|
if (fkErr != null) return BadRequest(new { message = fkErr });
|
|
|
|
|
|
var (parentItem, componentItem, itemErr) = await ResolveItemNumsAsync(dto.ParentMaterialId, dto.ComponentMaterialId);
|
|
|
@@ -186,7 +186,7 @@ public class AdoS0ProductStructuresController : ControllerBase
|
|
|
var existing = await _masterRep.GetByIdAsync(id);
|
|
|
if (existing == null) return NotFound();
|
|
|
|
|
|
- var fkErr = await ValidateMaterialRefsAsync(dto.CompanyRefId, dto.FactoryRefId, dto.ParentMaterialId, dto.ComponentMaterialId);
|
|
|
+ var fkErr = await ValidateMaterialRefsAsync(dto.ParentMaterialId, dto.ComponentMaterialId);
|
|
|
if (fkErr != null) return BadRequest(new { message = fkErr });
|
|
|
|
|
|
var (parentItem, componentItem, itemErr) = await ResolveItemNumsAsync(dto.ParentMaterialId, dto.ComponentMaterialId);
|
|
|
@@ -317,12 +317,15 @@ public class AdoS0ProductStructuresController : ControllerBase
|
|
|
return (parentItem, componentItem, null);
|
|
|
}
|
|
|
|
|
|
- private async Task<string?> ValidateMaterialRefsAsync(long companyRefId, long factoryRefId, long parentId, long componentId)
|
|
|
+ // 物料引用只校验 Id 真实存在:物料主数据用 legacy 数值 org 域(如 1000/8010),而标准 BOM 表单
|
|
|
+ // 公司/工厂来自 SysOrg 雪花 id(如 1329900200001),两域直接强比较恒不成立、会误拦截真实物料引用。
|
|
|
+ // 对齐货源清单 srm 的"引用真实存在即可保存"口径,不再比较物料 CompanyRefId/FactoryRefId。
|
|
|
+ private async Task<string?> ValidateMaterialRefsAsync(long parentId, long componentId)
|
|
|
{
|
|
|
- var count = await _materialRep.AsQueryable()
|
|
|
- .Where(m => (m.Id == parentId || m.Id == componentId)
|
|
|
- && m.CompanyRefId == companyRefId && m.FactoryRefId == factoryRefId)
|
|
|
+ var ids = parentId == componentId ? new[] { parentId } : new[] { parentId, componentId };
|
|
|
+ var existingCount = await _materialRep.AsQueryable()
|
|
|
+ .Where(m => ids.Contains(m.Id))
|
|
|
.CountAsync();
|
|
|
- return count == 2 ? null : "存在无效的物料主数据引用(公司/工厂或 Id 不匹配)";
|
|
|
+ return existingCount == ids.Length ? null : "存在无效的物料主数据引用(公司/工厂或 Id 不匹配)";
|
|
|
}
|
|
|
}
|