桌面端新增密炼计划获取

This commit is contained in:
2026-06-17 17:52:31 +08:00
parent 816af5df6e
commit 372dc10be2
23 changed files with 1335 additions and 92 deletions

View File

@@ -14,6 +14,7 @@ public class RubberQuickTestOperationService : IRubberQuickTestOperationService,
private readonly IHttpClientFactory _httpClientFactory;
private readonly IConfiguration _configuration;
private readonly INetworkMonitor _networkMonitor;
private readonly IMixingProductionPlanService _mixingProductionPlanService;
private readonly ILoggerService _logger;
private static readonly JsonSerializerOptions _jsonOpts = new()
@@ -27,11 +28,13 @@ public class RubberQuickTestOperationService : IRubberQuickTestOperationService,
IHttpClientFactory httpClientFactory,
IConfiguration configuration,
INetworkMonitor networkMonitor,
IMixingProductionPlanService mixingProductionPlanService,
ILoggerService logger)
{
_httpClientFactory = httpClientFactory;
_configuration = configuration;
_networkMonitor = networkMonitor;
_mixingProductionPlanService = mixingProductionPlanService;
_logger = logger;
}
@@ -40,32 +43,7 @@ public class RubberQuickTestOperationService : IRubberQuickTestOperationService,
public async Task<List<MesXslMixingProductionPlan>> GetMixingProductionPlansAsync(CancellationToken ct = default)
{
if (!_networkMonitor.IsOnline)
throw new InvalidOperationException("网络未连接,无法加载密炼生产计划");
var result = new List<MesXslMixingProductionPlan>();
int pageNo = 1;
const int pageSize = 500;
while (true)
{
var url = $"{BaseUrl}/xslmes/mesXslMixingProductionPlan/anon/list?pageNo={pageNo}&pageSize={pageSize}&tenantId={DefaultTenantId}";
using var client = _httpClientFactory.CreateClient("JeecgApi");
var resp = await client.GetAsync(url, ct).ConfigureAwait(false);
resp.EnsureSuccessStatusCode();
var json = await resp.Content.ReadAsStringAsync(ct).ConfigureAwait(false);
using var doc = JsonDocument.Parse(json);
if (!doc.RootElement.TryGetProperty("result", out var resultEl)) break;
if (resultEl.TryGetProperty("records", out var recordsEl))
{
var page = recordsEl.Deserialize<List<MesXslMixingProductionPlan>>(_jsonOpts);
if (page != null) result.AddRange(page);
}
long total = 0;
if (resultEl.TryGetProperty("total", out var totalEl)) total = totalEl.GetInt64();
if (result.Count >= total || (resultEl.TryGetProperty("records", out var r2) && r2.GetArrayLength() < pageSize)) break;
pageNo++;
}
var result = await _mixingProductionPlanService.GetAllCachedAsync(ct).ConfigureAwait(false);
_logger.Information($"[快检记录] 加载密炼生产计划 {result.Count} 条");
return result;
}