|
|
@@ -15,10 +15,36 @@ namespace Admin.NET.Plugin.AiDOP.Controllers.S0.Manufacturing;
|
|
|
public class AdoS0MfgProductionLinesController : ControllerBase
|
|
|
{
|
|
|
private readonly SqlSugarRepository<AdoS0LineMaster> _rep;
|
|
|
+ private readonly AdoS0ReferenceChecker _refChecker;
|
|
|
|
|
|
- public AdoS0MfgProductionLinesController(SqlSugarRepository<AdoS0LineMaster> rep)
|
|
|
+ public AdoS0MfgProductionLinesController(SqlSugarRepository<AdoS0LineMaster> rep, AdoS0ReferenceChecker refChecker)
|
|
|
{
|
|
|
_rep = rep;
|
|
|
+ _refChecker = refChecker;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// B1-9:LineMaster 6 个 Location 变体的统一 existence check。
|
|
|
+ /// 全部复用 AdoS0ReferenceChecker.LocationExistsAsync,空值放行。
|
|
|
+ /// </summary>
|
|
|
+ private async Task<IActionResult?> ValidateLocationReferencesAsync(AdoS0LineMasterUpsertDto dto)
|
|
|
+ {
|
|
|
+ var checks = new (string? Value, string Label)[]
|
|
|
+ {
|
|
|
+ (dto.Location, "主库位"),
|
|
|
+ (dto.VLocation, "虚拟库位"),
|
|
|
+ (dto.Location2, "辅助库位2"),
|
|
|
+ (dto.Location3, "辅助库位3"),
|
|
|
+ (dto.PickingLocation, "拣料库位"),
|
|
|
+ (dto.MidLocation, "中间库位"),
|
|
|
+ };
|
|
|
+ foreach (var (value, label) in checks)
|
|
|
+ {
|
|
|
+ if (!await _refChecker.LocationExistsAsync(value))
|
|
|
+ return AdoS0ApiErrors.InvalidReference(AdoS0ErrorCodes.ReferenceNotFound,
|
|
|
+ $"{label}编码 '{value}' 不存在于库位主数据");
|
|
|
+ }
|
|
|
+ return null;
|
|
|
}
|
|
|
|
|
|
[HttpGet]
|
|
|
@@ -85,6 +111,9 @@ public class AdoS0MfgProductionLinesController : ControllerBase
|
|
|
[HttpPost]
|
|
|
public async Task<IActionResult> CreateAsync([FromBody] AdoS0LineMasterUpsertDto dto)
|
|
|
{
|
|
|
+ var locErr = await ValidateLocationReferencesAsync(dto);
|
|
|
+ if (locErr != null) return locErr;
|
|
|
+
|
|
|
var now = DateTime.Now;
|
|
|
var entity = new AdoS0LineMaster
|
|
|
{
|
|
|
@@ -115,6 +144,9 @@ public class AdoS0MfgProductionLinesController : ControllerBase
|
|
|
[HttpPut("{id:long}")]
|
|
|
public async Task<IActionResult> UpdateAsync(long id, [FromBody] AdoS0LineMasterUpsertDto dto)
|
|
|
{
|
|
|
+ var locErr = await ValidateLocationReferencesAsync(dto);
|
|
|
+ if (locErr != null) return locErr;
|
|
|
+
|
|
|
var entity = await _rep.GetByIdAsync(id);
|
|
|
if (entity == null) return NotFound();
|
|
|
|