桌面端原材料入场记录完善

This commit is contained in:
2026-07-31 14:27:46 +08:00
parent 67f3acfd43
commit ef28b93909
13 changed files with 531 additions and 75 deletions

View File

@@ -159,7 +159,14 @@ public class RawMaterialEntryService : IRawMaterialEntryService, ISingletonDepen
try
{
var ok = await RemoteAddAsync(local, ct).ConfigureAwait(false);
if (ok) { UpsertLocalCache(local); return true; }
if (ok)
{
//update-begin---author:jiangxh ---date:20260731 for【原料入场】新增后回写Id/条码,避免保存并打印空引用-----------
CopyGeneratedFieldsToEntry(entry, local);
UpsertLocalCache(local);
return true;
//update-end---author:jiangxh ---date:20260731 for【原料入场】新增后回写Id/条码,避免保存并打印空引用-----------
}
return false;
}
catch (Exception ex)
@@ -169,8 +176,21 @@ public class RawMaterialEntryService : IRawMaterialEntryService, ISingletonDepen
}
EnqueuePendingOperation(new EntryPendingOperation { OpType = EntryOpType.Add, EntryId = local.Id, Entry = local, CreatedAt = DateTime.UtcNow });
//update-begin---author:jiangxh ---date:20260731 for【原料入场】新增后回写Id/条码,避免保存并打印空引用-----------
CopyGeneratedFieldsToEntry(entry, local);
UpsertLocalCache(local);
return true;
//update-end---author:jiangxh ---date:20260731 for【原料入场】新增后回写Id/条码,避免保存并打印空引用-----------
}
/// <summary>把 Clone 上生成的主键/条码/批次写回调用方 Entry供保存并打印继续使用。</summary>
private static void CopyGeneratedFieldsToEntry(MesXslRawMaterialEntry entry, MesXslRawMaterialEntry local)
{
if (entry == null || local == null) return;
entry.Id = local.Id;
entry.Barcode = local.Barcode;
entry.BatchNo = local.BatchNo;
entry.TenantId = local.TenantId;
}
public async Task<bool> EditAsync(MesXslRawMaterialEntry entry, CancellationToken ct = default)
@@ -586,7 +606,51 @@ public class RawMaterialEntryService : IRawMaterialEntryService, ISingletonDepen
var url = $"{BaseUrl}/xslmes/mesXslRawMaterialEntry/anon/add?tenantId={DefaultTenantId}";
var payload = Clone(entry);
if (IsLocalTempId(payload.Id)) payload.Id = null;
return await PostJsonAsync(url, payload, ct).ConfigureAwait(false);
//update-begin---author:jiangxh ---date:20260731 for【原料入场】新增后回写服务端主键-----------
var (ok, serverId) = await PostJsonForAddAsync(url, payload, ct).ConfigureAwait(false);
if (ok && !string.IsNullOrWhiteSpace(serverId))
{
entry.Id = serverId.Trim();
}
return ok;
//update-end---author:jiangxh ---date:20260731 for【原料入场】新增后回写服务端主键-----------
}
/// <summary>新增接口:解析 Result.OK(msg, id) 的 result 主键。</summary>
private async Task<(bool Ok, string? ServerId)> PostJsonForAddAsync(string url, object body, CancellationToken ct)
{
var content = new StringContent(JsonSerializer.Serialize(body, _jsonOpts), Encoding.UTF8, "application/json");
using var client = CreateClient();
var resp = await client.PostAsync(url, content, ct).ConfigureAwait(false);
if (!resp.IsSuccessStatusCode) return (false, null);
try
{
var json = await resp.Content.ReadAsStringAsync(ct).ConfigureAwait(false);
using var doc = JsonDocument.Parse(json);
var root = doc.RootElement;
var codeOk = true;
if (root.TryGetProperty("code", out var codeEl))
codeOk = codeEl.GetInt32() == 200;
else if (root.TryGetProperty("success", out var successEl))
codeOk = successEl.GetBoolean();
if (!codeOk) return (false, null);
string? serverId = null;
if (root.TryGetProperty("result", out var resultEl))
{
serverId = resultEl.ValueKind switch
{
JsonValueKind.String => resultEl.GetString(),
JsonValueKind.Object when resultEl.TryGetProperty("id", out var idEl) => idEl.GetString(),
_ => resultEl.ToString()
};
}
return (true, string.IsNullOrWhiteSpace(serverId) ? null : serverId);
}
catch
{
return (true, null);
}
}
private async Task<(bool Ok, bool IsVersionConflict)> RemoteEditAsync(MesXslRawMaterialEntry entry, CancellationToken ct)