增加固体饮料批号初版
This commit is contained in:
@@ -13,6 +13,31 @@ namespace FATrace.Com
|
||||
/// </summary>
|
||||
public class NVRCom
|
||||
{
|
||||
private static string[] SplitCodeParts(string code)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(code)) return Array.Empty<string>();
|
||||
|
||||
var normalized = code.Trim()
|
||||
.Replace(',', ',')
|
||||
.Replace(';', ',')
|
||||
.Replace(';', ',');
|
||||
|
||||
// 优先使用逗号分隔,避免 SolidBeveBatch 中包含空格导致被错误切分
|
||||
if (normalized.Contains(','))
|
||||
{
|
||||
return normalized
|
||||
.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
|
||||
.Select(p => p.Trim())
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
// 无逗号时回退到按空白分隔
|
||||
return normalized
|
||||
.Split((char[]?)null, StringSplitOptions.RemoveEmptyEntries)
|
||||
.Select(p => p.Trim())
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取视频名称
|
||||
/// </summary>
|
||||
@@ -65,15 +90,13 @@ namespace FATrace.Com
|
||||
|
||||
try
|
||||
{
|
||||
// 标准化分隔符并切分:支持 英文逗号/中文逗号/分号/空格
|
||||
var normalized = Code.Trim()
|
||||
.Replace(',', ',')
|
||||
.Replace(';', ',')
|
||||
.Replace(';', ',');
|
||||
var parts = normalized
|
||||
.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries)
|
||||
.Select(p => p.Trim())
|
||||
.ToArray();
|
||||
var parts = SplitCodeParts(Code);
|
||||
|
||||
// 新二维码固定 7 段:RawCode,Batch,SolidBeveBatch,Weight,ShelfLife,Region,DayCount
|
||||
if (parts.Length != 7)
|
||||
{
|
||||
return (string.Empty, string.Empty, string.Empty);
|
||||
}
|
||||
|
||||
string rawCode = parts.Length > 0 ? parts[0] : string.Empty;
|
||||
|
||||
@@ -88,9 +111,10 @@ namespace FATrace.Com
|
||||
|
||||
// 重量:3/4 位数字,最后一位为小数位(例:802 => 80.2g)。
|
||||
string weight = string.Empty;
|
||||
if (parts.Length > 2)
|
||||
var weightIndex = 3;
|
||||
if (parts.Length > 3)
|
||||
{
|
||||
var digits = new string(parts[2].Where(char.IsDigit).ToArray());
|
||||
var digits = new string(parts[weightIndex].Where(char.IsDigit).ToArray());
|
||||
if (digits.Length >= 2)
|
||||
{
|
||||
// 在最后一位前插入小数点,如 802 => 80.2,1234 => 123.4
|
||||
@@ -118,14 +142,13 @@ namespace FATrace.Com
|
||||
|
||||
try
|
||||
{
|
||||
var normalized = code.Trim()
|
||||
.Replace(',', ',')
|
||||
.Replace(';', ',')
|
||||
.Replace(';', ',');
|
||||
var parts = normalized
|
||||
.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries)
|
||||
.Select(p => p.Trim())
|
||||
.ToArray();
|
||||
var parts = SplitCodeParts(code);
|
||||
|
||||
// 新二维码固定 7 段:RawCode,Batch,SolidBeveBatch,Weight,ShelfLife,Region,DayCount
|
||||
if (parts.Length != 7)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
result.RawCode = parts.Length > 0 ? parts[0] : string.Empty;
|
||||
|
||||
@@ -135,9 +158,13 @@ namespace FATrace.Com
|
||||
result.Batch = digits.Length >= 8 ? digits.Substring(0, 8) : digits;
|
||||
}
|
||||
|
||||
if (parts.Length > 2)
|
||||
// 新二维码(7段)第3段为固体饮料批次
|
||||
result.SolidBeveBatch = parts[2];
|
||||
|
||||
var weightIndex = 3;
|
||||
if (parts.Length > 3)
|
||||
{
|
||||
var digits = new string(parts[2].Where(char.IsDigit).ToArray());
|
||||
var digits = new string(parts[weightIndex].Where(char.IsDigit).ToArray());
|
||||
string weightStr = string.Empty;
|
||||
if (digits.Length >= 2)
|
||||
{
|
||||
@@ -154,22 +181,25 @@ namespace FATrace.Com
|
||||
}
|
||||
}
|
||||
|
||||
if (parts.Length > 3)
|
||||
var shelfLifeIndex = 4;
|
||||
if (parts.Length > 4)
|
||||
{
|
||||
var digits = new string(parts[3].Where(char.IsDigit).ToArray());
|
||||
var digits = new string(parts[shelfLifeIndex].Where(char.IsDigit).ToArray());
|
||||
if (int.TryParse(digits, out var m)) result.ShelfLifeMonths = m;
|
||||
}
|
||||
|
||||
if (parts.Length > 4)
|
||||
var regionIndex = 5;
|
||||
if (parts.Length > 5)
|
||||
{
|
||||
var digits = new string(parts[4].Where(char.IsDigit).ToArray());
|
||||
var digits = new string(parts[regionIndex].Where(char.IsDigit).ToArray());
|
||||
result.RegionCode = digits;
|
||||
result.RegionName = digits == "01" ? "国内" : (digits == "02" ? "日本" : "未知");
|
||||
}
|
||||
|
||||
if (parts.Length > 5)
|
||||
var countIndex = 6;
|
||||
if (parts.Length > 6)
|
||||
{
|
||||
var digits = new string(parts[5].Where(char.IsDigit).ToArray());
|
||||
var digits = new string(parts[countIndex].Where(char.IsDigit).ToArray());
|
||||
if (int.TryParse(digits, out var c)) result.Count = c;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user