优化桌面端无用菜单和地磅数据可手动功能。
This commit is contained in:
@@ -197,12 +197,12 @@ public class WeightRecordService : IWeightRecordService, ISingletonDependency
|
||||
|
||||
public async Task<bool> AddAsync(MesXslWeightRecord entity, CancellationToken ct = default)
|
||||
{
|
||||
SanitizeWeightsBeforePersist(entity);
|
||||
if (!entity.TenantId.HasValue || entity.TenantId.Value <= 0)
|
||||
entity.TenantId = DefaultTenantId;
|
||||
if (string.IsNullOrWhiteSpace(entity.BillNo))
|
||||
entity.BillNo = GenerateBillNo();
|
||||
if (string.IsNullOrWhiteSpace(entity.BillType))
|
||||
entity.BillType = ResolveBillType(entity);
|
||||
entity.BillType = ResolveBillType(entity);
|
||||
|
||||
var local = Clone(entity);
|
||||
if (string.IsNullOrWhiteSpace(local.Id))
|
||||
@@ -246,21 +246,41 @@ public class WeightRecordService : IWeightRecordService, ISingletonDependency
|
||||
|
||||
/// <summary>
|
||||
/// 根据称重数据推导单据类型:仅毛重=已称毛重;仅皮重=已称皮重;毛重+皮重=称重完成。
|
||||
/// 注意:皮重/毛重为 0 时按「未称」处理(避免 NumericUpDown/JSON 占位 0 误判为称重完成)。
|
||||
/// </summary>
|
||||
private static string? ResolveBillType(MesXslWeightRecord entity)
|
||||
{
|
||||
if (entity.GrossWeight.HasValue && entity.TareWeight.HasValue) return "2";
|
||||
if (entity.GrossWeight.HasValue) return "1";
|
||||
if (entity.TareWeight.HasValue) return "3";
|
||||
var g = HasEffectiveWeighKg(entity.GrossWeight);
|
||||
var t = HasEffectiveWeighKg(entity.TareWeight);
|
||||
if (g && t) return "2";
|
||||
if (g) return "1";
|
||||
if (t) return "3";
|
||||
return null;
|
||||
}
|
||||
|
||||
private static bool HasEffectiveWeighKg(double? kg) => kg.HasValue && kg.Value > 0;
|
||||
|
||||
/// <summary>
|
||||
/// 将 ≤0 的重量视为未录入并清空净重,防止上传 payload 带 0 误判。
|
||||
/// </summary>
|
||||
private static void SanitizeWeightsBeforePersist(MesXslWeightRecord entity)
|
||||
{
|
||||
if (entity.GrossWeight.HasValue && entity.GrossWeight.Value <= 0)
|
||||
entity.GrossWeight = null;
|
||||
if (entity.TareWeight.HasValue && entity.TareWeight.Value <= 0)
|
||||
entity.TareWeight = null;
|
||||
if (HasEffectiveWeighKg(entity.GrossWeight) && HasEffectiveWeighKg(entity.TareWeight))
|
||||
entity.NetWeight = Math.Round(entity.GrossWeight!.Value - entity.TareWeight!.Value, 2);
|
||||
else
|
||||
entity.NetWeight = null;
|
||||
}
|
||||
|
||||
public async Task<bool> EditAsync(MesXslWeightRecord entity, CancellationToken ct = default)
|
||||
{
|
||||
SanitizeWeightsBeforePersist(entity);
|
||||
if (!entity.TenantId.HasValue || entity.TenantId.Value <= 0)
|
||||
entity.TenantId = DefaultTenantId;
|
||||
if (string.IsNullOrWhiteSpace(entity.BillType))
|
||||
entity.BillType = ResolveBillType(entity);
|
||||
entity.BillType = ResolveBillType(entity);
|
||||
|
||||
var local = Clone(entity);
|
||||
if (IsLocalTempId(local.Id))
|
||||
|
||||
Reference in New Issue
Block a user