客户要求的更改

This commit is contained in:
2026-05-15 17:17:08 +08:00
parent add4308b91
commit 7dabeddde4
23 changed files with 248 additions and 102 deletions

View File

@@ -207,5 +207,92 @@ namespace FATrace.Com
return result;
}
/// <summary>
/// 兼容解析条码(用于 OEMApp 这类流程后段应用:现场可能存在历史 6 段条码)。
/// 新条码7段RawCode,Batch,SolidBeveBatch,Weight,ShelfLife,Region,DayCount
/// 旧条码6段RawCode,Batch,Weight,ShelfLife,Region,DayCount不包含 SolidBeveBatch
/// </summary>
public static ParsedCodeInfo ParseCodeFullCompat(string code)
{
var result = new ParsedCodeInfo();
if (string.IsNullOrWhiteSpace(code)) return result;
result.Code = code;
try
{
var parts = SplitCodeParts(code);
if (parts.Length != 7 && parts.Length != 6)
{
return result;
}
result.RawCode = parts.Length > 0 ? parts[0] : string.Empty;
if (parts.Length > 1)
{
var digits = new string(parts[1].Where(char.IsDigit).ToArray());
result.Batch = digits.Length >= 8 ? digits.Substring(0, 8) : digits;
}
var isNew7 = parts.Length == 7;
if (isNew7)
{
// 新条码7段第3段为固体饮料批次
result.SolidBeveBatch = parts[2];
}
else
{
// 旧条码6段不包含固体饮料批次
result.SolidBeveBatch = string.Empty;
}
var weightIndex = isNew7 ? 3 : 2;
if (parts.Length > weightIndex)
{
var digits = new string(parts[weightIndex].Where(char.IsDigit).ToArray());
string weightStr = string.Empty;
if (digits.Length >= 2)
{
weightStr = string.Concat(digits.AsSpan(0, digits.Length - 1), ".", digits.AsSpan(digits.Length - 1));
}
else if (digits.Length == 1)
{
weightStr = "0." + digits;
}
if (!string.IsNullOrWhiteSpace(weightStr))
{
if (decimal.TryParse(weightStr, NumberStyles.Any, CultureInfo.InvariantCulture, out var w))
result.Weight = w;
}
}
var shelfLifeIndex = isNew7 ? 4 : 3;
if (parts.Length > shelfLifeIndex)
{
var digits = new string(parts[shelfLifeIndex].Where(char.IsDigit).ToArray());
if (int.TryParse(digits, out var m)) result.ShelfLifeMonths = m;
}
var regionIndex = isNew7 ? 5 : 4;
if (parts.Length > regionIndex)
{
var digits = new string(parts[regionIndex].Where(char.IsDigit).ToArray());
result.RegionCode = digits;
result.RegionName = digits == "01" ? "国内" : (digits == "02" ? "日本" : "未知");
}
var countIndex = isNew7 ? 6 : 5;
if (parts.Length > countIndex)
{
var digits = new string(parts[countIndex].Where(char.IsDigit).ToArray());
if (int.TryParse(digits, out var c)) result.Count = c;
}
}
catch { }
return result;
}
}
}