修改SI回执解析,处理多页取箱信息不完整的问题

master
jianghaiqing 5 months ago
parent 885671d7de
commit 9bfd819683

@ -17,6 +17,7 @@ using Microsoft.Extensions.Logging;
using DAJYun.Application.TaskManagePlatDomain;
using Furion.Logging;
using System.IO;
using Microsoft.CodeAnalysis.Operations;
namespace DAJYun.Application
{
@ -295,15 +296,61 @@ namespace DAJYun.Application
//这里不知道为什么取不到表格信息了,改用文本获取
string currTxt = doc.Pages[pageIndex].ExtractText();
string noTableCtnRegex = "(\\bNumber\\b)\\s+\\w+\\s+(\\bPackages\\b)\\s+\\w+\\s+(Cargo\\s+Weight)\\s+(\\w|\\s)+(\\bVolume\\b)\\s+(\\w|\\s)+(\\bVGM\\b)\\s+(\\w|\\s)+(VGM\\s+Method)\\s+(\\w|\\s|')+(Carrier\\s+seal)\\s+\\w+";
if(!string.IsNullOrWhiteSpace(currTxt))
{
currTxt = Regex.Replace(currTxt, "\\r\\n", " ");
}
string noTableCtnRegex = "(Number)\\s+\\w+\\s+(Packages)\\s+\\w+\\s+(Cargo\\s+Weight)\\s+(\\w|\\s)+(Volume)\\s+(\\w|\\s|(m.))+(VGM)\\s+(\\w|\\s)+(VGM\\s+Method)\\s+(\\w|\\s|')+(Carrier\\s+seal)\\s+\\w+";
if (Regex.IsMatch(currTxt, noTableCtnRegex, RegexOptions.IgnoreCase))
{
var currMatches = Regex.Matches(currTxt, noTableCtnRegex, RegexOptions.IgnoreCase);
foreach(var cMatch in currMatches)
foreach (Match cMatch in currMatches)
{
string currStr = cMatch.Value;
string number = Regex.Match(currStr, "(?<=Number)\\s+\\w+(?=\\s)", RegexOptions.IgnoreCase).Value?.Trim();
string package = Regex.Match(currStr, "(?<=Packages)\\s+\\w+(?=\\s)", RegexOptions.IgnoreCase).Value?.Trim();
string cargoWeight = Regex.Match(currStr, "(?<=Cargo\\sWeight)\\s+(\\w|\\s)+(?=Volume\\s)", RegexOptions.IgnoreCase).Value?.Trim();
string volume = Regex.Match(currStr, "(?<=Volume)\\s+(\\w|\\s|(m.))+(?=VGM\\s[^Method])", RegexOptions.IgnoreCase).Value?.Trim();
string vgm = Regex.Match(currStr, "(?<=VGM)\\s+(\\w|\\s)+(?=VGM\\s+Method\\s)", RegexOptions.IgnoreCase).Value?.Trim();
string vgmMethod = Regex.Match(currStr, "(?<=VGM\\sMethod)\\s+(\\w|\\s|')+(?=Carrier\\s+seal\\s)", RegexOptions.IgnoreCase).Value?.Trim();
if (!string.IsNullOrWhiteSpace(vgmMethod))
vgmMethod = Regex.Replace(vgmMethod, "\\s{2,}", " ");
string seal = Regex.Match(currStr, "(?<=Carrier\\sseal)\\s+\\w+", RegexOptions.IgnoreCase).Value?.Trim();
if (ds.Tables != null && ds.Tables.Count > 0)
{
for (int i = 0; i < ds.Tables.Count; i++)
{
if(ds.Tables[i].Columns.OfType<DataColumn>().Any(x => x.ColumnName.Equals("Number", StringComparison.OrdinalIgnoreCase)
|| x.ColumnName.Equals("Packages", StringComparison.OrdinalIgnoreCase)))
{
var newTable = ds.Tables[i].Copy();
newTable.TableName = $"Table{ds.Tables.Count + 1}";
newTable.Columns[1].ColumnName = number;
newTable.Columns[3].ColumnName = package;
newTable.Rows[0][1] = cargoWeight;
newTable.Rows[0][3] = volume;
newTable.Rows[1][1] = vgm;
newTable.Rows[1][3] = vgmMethod;
newTable.Rows[2][1] = seal;
ds.Tables.Add(newTable);
break;
}
}
}
}
}
}

Loading…
Cancel
Save