|
|
@@ -195,15 +195,31 @@ public class AdoS0SrmPurchasesController : ControllerBase
|
|
|
{
|
|
|
if (rows.Count == 0) return;
|
|
|
|
|
|
- var itemIds = rows.Select(x => x.IcitemId).Where(id => id > 0).Distinct().ToList();
|
|
|
- var items = itemIds.Count == 0
|
|
|
+ // 物料编码直接取 srm_purchase.number(历史迁移已回填,100% 有值)。
|
|
|
+ // 旧平台 icitem_id 为雪花 ID,与本地 ItemMaster.RecID 不同域、匹配为 0,故辅助展示字段
|
|
|
+ // (规格/单位/物料类型)改按 number == ItemMaster.ItemNum 关联补齐;未匹配行仅缺辅助字段。
|
|
|
+ var numbers = rows.Select(x => x.Number)
|
|
|
+ .Where(n => !string.IsNullOrWhiteSpace(n))
|
|
|
+ .Distinct()
|
|
|
+ .ToList();
|
|
|
+ var items = numbers.Count == 0
|
|
|
? new List<AdoS0ItemMaster>()
|
|
|
- : await _itemRep.AsQueryable().Where(it => itemIds.Contains(it.Id)).ToListAsync();
|
|
|
+ : await _itemRep.AsQueryable().Where(it => numbers.Contains(it.ItemNum)).ToListAsync();
|
|
|
+
|
|
|
+ // MySQL 默认 ci 排序,用大小写不敏感字典对齐旧 SQL 的 number=ItemNum 关联语义。
|
|
|
+ var itemByNum = new Dictionary<string, AdoS0ItemMaster>(StringComparer.OrdinalIgnoreCase);
|
|
|
+ foreach (var it in items)
|
|
|
+ {
|
|
|
+ if (!string.IsNullOrWhiteSpace(it.ItemNum) && !itemByNum.ContainsKey(it.ItemNum))
|
|
|
+ itemByNum[it.ItemNum] = it;
|
|
|
+ }
|
|
|
|
|
|
foreach (var sp in rows)
|
|
|
{
|
|
|
- var it = items.Find(i => i.Id == sp.IcitemId);
|
|
|
- sp.MaterialCode = it?.ItemNum;
|
|
|
+ AdoS0ItemMaster? it = null;
|
|
|
+ if (!string.IsNullOrWhiteSpace(sp.Number))
|
|
|
+ itemByNum.TryGetValue(sp.Number, out it);
|
|
|
+ sp.MaterialCode = sp.Number;
|
|
|
sp.Model = it?.Descr1;
|
|
|
sp.Unit = it?.UM;
|
|
|
sp.ItemTypeLabel = string.IsNullOrWhiteSpace(it?.ItemType) ? "原材料" : it!.ItemType;
|