桌面端密炼计划、胶料快检调整
This commit is contained in:
@@ -14,7 +14,6 @@ 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()
|
||||
@@ -28,54 +27,20 @@ public class RubberQuickTestOperationService : IRubberQuickTestOperationService,
|
||||
IHttpClientFactory httpClientFactory,
|
||||
IConfiguration configuration,
|
||||
INetworkMonitor networkMonitor,
|
||||
IMixingProductionPlanService mixingProductionPlanService,
|
||||
ILoggerService logger)
|
||||
{
|
||||
_httpClientFactory = httpClientFactory;
|
||||
_configuration = configuration;
|
||||
_networkMonitor = networkMonitor;
|
||||
_mixingProductionPlanService = mixingProductionPlanService;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
private string BaseUrl => (_configuration.GetValue<string>("JeecgIntegration:BaseUrl") ?? "http://localhost:8080/jeecg-boot").TrimEnd('/');
|
||||
private int DefaultTenantId => (int?)_configuration.GetValue<long?>("JeecgIntegration:DefaultTenantId") ?? 1002;
|
||||
|
||||
public async Task<List<MesXslMixingProductionPlan>> GetMixingProductionPlansAsync(CancellationToken ct = default)
|
||||
{
|
||||
var result = await _mixingProductionPlanService.GetAllCachedAsync(ct).ConfigureAwait(false);
|
||||
_logger.Information($"[快检记录] 加载密炼生产计划 {result.Count} 条");
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<MesXslRubberQuickTestStd?> GetStdByRubberMaterialNameAsync(string rubberMaterialName, CancellationToken ct = default)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(rubberMaterialName))
|
||||
return null;
|
||||
if (!_networkMonitor.IsOnline)
|
||||
throw new InvalidOperationException("网络未连接,无法加载实验标准");
|
||||
|
||||
var encoded = Uri.EscapeDataString(rubberMaterialName.Trim());
|
||||
var url = $"{BaseUrl}/xslmes/mesXslRubberQuickTestStd/anon/queryByRubberMaterialName?rubberMaterialName={encoded}";
|
||||
using var client = _httpClientFactory.CreateClient("JeecgApi");
|
||||
var resp = await client.GetAsync(url, ct).ConfigureAwait(false);
|
||||
var json = await resp.Content.ReadAsStringAsync(ct).ConfigureAwait(false);
|
||||
using var doc = JsonDocument.Parse(json);
|
||||
if (!doc.RootElement.TryGetProperty("success", out var successEl) || !successEl.GetBoolean())
|
||||
{
|
||||
var msg = doc.RootElement.TryGetProperty("message", out var msgEl) ? msgEl.GetString() : "查询实验标准失败";
|
||||
_logger.Warning($"[快检记录] 实验标准查询失败: {msg}");
|
||||
return null;
|
||||
}
|
||||
if (!doc.RootElement.TryGetProperty("result", out var resultEl) || resultEl.ValueKind == JsonValueKind.Null)
|
||||
return null;
|
||||
return resultEl.Deserialize<MesXslRubberQuickTestStd>(_jsonOpts);
|
||||
}
|
||||
|
||||
public async Task<string?> SaveRecordAsync(MesXslRubberQuickTestRecord record, CancellationToken ct = default)
|
||||
{
|
||||
if (!_networkMonitor.IsOnline)
|
||||
throw new InvalidOperationException("网络未连接,无法保存快检记录");
|
||||
throw new InvalidOperationException("网络未连接,无法保存胶料快检记录");
|
||||
|
||||
var url = $"{BaseUrl}/xslmes/mesXslRubberQuickTestRecord/anon/add";
|
||||
using var client = _httpClientFactory.CreateClient("JeecgApi");
|
||||
@@ -89,7 +54,19 @@ public class RubberQuickTestOperationService : IRubberQuickTestOperationService,
|
||||
var msg = doc.RootElement.TryGetProperty("message", out var msgEl) ? msgEl.GetString() : "保存失败";
|
||||
throw new InvalidOperationException(msg ?? "保存失败");
|
||||
}
|
||||
_logger.Information($"[快检记录] 保存成功 recordNo={record.RecordNo}");
|
||||
return doc.RootElement.TryGetProperty("message", out var m) ? m.GetString() : "保存成功";
|
||||
|
||||
string? recordNo = null;
|
||||
if (doc.RootElement.TryGetProperty("result", out var resultEl))
|
||||
{
|
||||
if (resultEl.ValueKind == JsonValueKind.String)
|
||||
recordNo = resultEl.GetString();
|
||||
else if (resultEl.ValueKind == JsonValueKind.Object
|
||||
&& resultEl.TryGetProperty("recordNo", out var noEl))
|
||||
recordNo = noEl.GetString();
|
||||
}
|
||||
recordNo ??= record.RecordNo;
|
||||
record.RecordNo = recordNo;
|
||||
_logger.Information($"[胶料快检记录] 保存成功 recordNo={recordNo}");
|
||||
return recordNo;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user