|
|
@@ -1,4 +1,5 @@
|
|
|
using Admin.NET.Plugin.AiDOP.Dto.S0.Warehouse;
|
|
|
+using Admin.NET.Plugin.AiDOP.Entity.S0.Sales;
|
|
|
using Admin.NET.Plugin.AiDOP.Entity.S0.Supply;
|
|
|
using Admin.NET.Plugin.AiDOP.Entity.S0.Warehouse;
|
|
|
using Admin.NET.Plugin.AiDOP.Infrastructure;
|
|
|
@@ -16,13 +17,16 @@ public class AdoS0BarcodeRulesController : ControllerBase
|
|
|
{
|
|
|
private readonly SqlSugarRepository<AdoS0BarCodeNbr> _rep;
|
|
|
private readonly SqlSugarRepository<AdoS0SuppMaster> _suppRep;
|
|
|
+ private readonly SqlSugarRepository<AdoS0CustMaster> _custRep;
|
|
|
|
|
|
public AdoS0BarcodeRulesController(
|
|
|
SqlSugarRepository<AdoS0BarCodeNbr> rep,
|
|
|
- SqlSugarRepository<AdoS0SuppMaster> suppRep)
|
|
|
+ SqlSugarRepository<AdoS0SuppMaster> suppRep,
|
|
|
+ SqlSugarRepository<AdoS0CustMaster> custRep)
|
|
|
{
|
|
|
_rep = rep;
|
|
|
_suppRep = suppRep;
|
|
|
+ _custRep = custRep;
|
|
|
}
|
|
|
|
|
|
[HttpGet]
|
|
|
@@ -48,7 +52,7 @@ public class AdoS0BarcodeRulesController : ControllerBase
|
|
|
.Take(q.PageSize)
|
|
|
.ToListAsync();
|
|
|
|
|
|
- await ApplySuppNameAsync(list, tenantId);
|
|
|
+ await ApplyPartyNameAsync(list, tenantId);
|
|
|
|
|
|
return Ok(new { total, page = q.Page, pageSize = q.PageSize, list });
|
|
|
}
|
|
|
@@ -59,7 +63,7 @@ public class AdoS0BarcodeRulesController : ControllerBase
|
|
|
if (!AdoS0TenantScope.TryResolveRequired(out var tenantId, out var tenantError)) return tenantError!;
|
|
|
var item = await _rep.AsQueryable().Where(x => x.Id == id && x.TenantId == tenantId).FirstAsync();
|
|
|
if (item == null) return NotFound();
|
|
|
- await ApplySuppNameAsync(new List<AdoS0BarCodeNbr> { item }, tenantId);
|
|
|
+ await ApplyPartyNameAsync(new List<AdoS0BarCodeNbr> { item }, tenantId);
|
|
|
return Ok(item);
|
|
|
}
|
|
|
|
|
|
@@ -155,28 +159,51 @@ public class AdoS0BarcodeRulesController : ControllerBase
|
|
|
e.FirmString12 = dto.FirmString12; e.FirmStringLen12 = dto.FirmStringLen12; e.FirmString12Note = dto.FirmString12Note;
|
|
|
}
|
|
|
|
|
|
- private async Task ApplySuppNameAsync(List<AdoS0BarCodeNbr> rules, long tenantId)
|
|
|
+ /// <summary>
|
|
|
+ /// 补显「客户/供应商名称」。
|
|
|
+ ///
|
|
|
+ /// legacy 字段兼容:BarCodeNbr.Customer 的列描述即「客户/供应商编码」,
|
|
|
+ /// 同一字段既可能存客户编码、也可能存供应商编码,本批不改 schema、不引入 OwnerType。
|
|
|
+ /// 因此按 CustMaster → SuppMaster 依次解析:
|
|
|
+ /// 仅命中客户 → 客户简称;仅命中供应商 → 供应商简称;
|
|
|
+ /// 两边都命中 → 客户优先(当前无 Type 层面的 owner 语义证据,不做静默猜测);
|
|
|
+ /// 两边都不命中 → 留空,不造值。
|
|
|
+ ///
|
|
|
+ /// 两次批量查询(各一次),按 code 建字典,无 N+1;均显式限定当前租户。
|
|
|
+ /// PartyName 为新语义字段;SuppName 保留旧值以兼容既有引用。
|
|
|
+ /// </summary>
|
|
|
+ private async Task ApplyPartyNameAsync(List<AdoS0BarCodeNbr> rules, long tenantId)
|
|
|
{
|
|
|
if (rules.Count == 0) return;
|
|
|
|
|
|
- var customerCodes = rules
|
|
|
+ var partyCodes = rules
|
|
|
.Select(r => r.Customer)
|
|
|
.Where(c => !string.IsNullOrWhiteSpace(c))
|
|
|
+ .Select(c => c!)
|
|
|
.Distinct()
|
|
|
.ToList();
|
|
|
|
|
|
- if (customerCodes.Count == 0) return;
|
|
|
+ if (partyCodes.Count == 0) return;
|
|
|
+
|
|
|
+ // 客户关联限定当前租户
|
|
|
+ var custs = await _custRep.AsQueryable()
|
|
|
+ .Where(c => c.TenantId == tenantId && partyCodes.Contains(c.Cust))
|
|
|
+ .ToListAsync();
|
|
|
|
|
|
// 供应商关联限定当前租户,避免同编码供应商跨租户补错简称
|
|
|
var supps = await _suppRep.AsQueryable()
|
|
|
- .Where(s => s.TenantId == tenantId && customerCodes.Contains(s.Supp))
|
|
|
+ .Where(s => s.TenantId == tenantId && partyCodes.Contains(s.Supp))
|
|
|
.ToListAsync();
|
|
|
|
|
|
foreach (var rule in rules)
|
|
|
{
|
|
|
if (string.IsNullOrWhiteSpace(rule.Customer)) continue;
|
|
|
+
|
|
|
+ var cust = custs.Find(c => string.Equals(c.Cust, rule.Customer, StringComparison.OrdinalIgnoreCase));
|
|
|
var supp = supps.Find(s => string.Equals(s.Supp, rule.Customer, StringComparison.OrdinalIgnoreCase));
|
|
|
+
|
|
|
rule.SuppName = supp?.SortName;
|
|
|
+ rule.PartyName = cust?.SortName ?? supp?.SortName;
|
|
|
}
|
|
|
}
|
|
|
}
|